forked from OWASP/Vulnerable-Web-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql5.php
71 lines (61 loc) · 1.83 KB
/
sql5.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<title>SQL Injection</title>
<link rel="shortcut icon" href="../Resources/hmbct.png" />
</head>
<body>
<div style="background-color:#c9c9c9;padding:15px;">
<button type="button" name="homeButton" onclick="location.href='../homepage.html';">Home Page</button>
<button type="button" name="mainButton" onclick="location.href='sqlmainpage.html';">Main Page</button>
</div>
<div align="center">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" >
<p>Give me book's number and I give you book's name in my library.</p>
Book's number : <input type="text" name="number">
<input type="submit" name="submit" value="Submit">
<!--<p>You hacked me again?
But I updated my code
</p>
-->
</form>
</div>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "1ccb8097d0e9ce9f154608be60224c7c";
// Create connection
$conn = new mysqli($servername, $username, $password,$db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
if(isset($_POST["submit"])){
$number = $_POST['number'];
//You hacked me again?
//I updated my code
if(strchr($number,"'")){
echo "What are you trying to do?<br>";
echo "Awesome hacking skillzz<br>";
echo "But you can't hack me anymore!";
exit;
}
$query = "SELECT bookname,authorname FROM books WHERE number =".'$number';
$result = mysqli_query($conn,$query);
if (!$result) { //Check result
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
while ($row = mysqli_fetch_assoc($result)) {
echo "<hr>";
echo $row['bookname']." ----> ".$row['authorname'];
}
if(mysqli_num_rows($result) <= 0)
echo "0 result";
}
?>
</body>
</html>