-
Notifications
You must be signed in to change notification settings - Fork 0
/
processquery.php
181 lines (149 loc) · 4.71 KB
/
processquery.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
include_once "include.inc.php";
$con = db_connect($_POST["level"]);
switch($_POST["level"]){
//Level 1 - No Protection
case '1':{
if(isset($_POST["username"])){
$user = $_POST["username"];
$pass = md5($_POST["password"]);
$sql = "SELECT * FROM NoProtection WHERE username = '$user' AND password = '$pass';";
$result = mysqli_query($con, $sql);
if(!$result){
$return = array("state" => 1,
"sqlQuery" => $sql,
"message" => mysqli_error($con));
echo json_encode($return);
return;
}
$return = array();
$return["state"] = 0;
$return["sqlQuery"] = $sql;
$queryresult = array();
while($row = mysqli_fetch_assoc($result)){
$queryresult[] = $row;
}
$return["queryRes"] = $queryresult;
echo json_encode($return);
}
break;
}
case '2':{//EscapeQuery
if(isset($_POST["username"])){
//Read POST vars into easier to use variables and
//Escape all special characters to prevent anyone from performing SQLI
$user = mysqli_real_escape_string($con, $_POST["username"]);
$pass = mysqli_real_escape_string($con, md5($_POST["password"]));
$yob = mysqli_real_escape_string($con, $_POST["yob"]);
//Create SQL query string
$sql = "SELECT * FROM EscapeQuery WHERE username = '$user' AND password = '$pass' AND yob = $yob;";
$result = mysqli_query($con, $sql);
if(!$result){
$return = array("state" => 1,
"sqlQuery" => $sql,
"message" => mysqli_error($con));
echo json_encode($return);
return;
}
$return = array();
$return["state"] = 0;
$return["sqlQuery"] = $sql;
$queryresult = array();
while($row = mysqli_fetch_assoc($result)){
$queryresult[] = $row;
}
$return["queryRes"] = $queryresult;
echo json_encode($return);
}
break;
}
case '3':{//Cookies
if(!isset($_COOKIE["SQLITraining"])){
$cookieVal = base64_encode("username=bob&password=".md5("I like apples"));
setrawcookie('SQLITraining', $cookieVal);
$return = array("state" => 1,
"sqlQuery" => "None",
"message" => "No cookie was received, cookie has now been set");
echo json_encode($return);
return;
}
$cookie = explode("&",base64_decode($_COOKIE["SQLITraining"]));
$user = explode("=", $cookie[0])[1];
$pass = explode("=", $cookie[1])[1];
$sql = "SELECT * FROM Cookies WHERE username = '$user' AND password = '$pass';";
$result = mysqli_query($con, $sql);
if(!$result){
$return = array("state" => 1,
"sqlQuery" => $sql,
"message" => mysqli_error($con));
echo json_encode($return);
return;
}
$return = array();
$return["state"] = 0;
$return["sqlQuery"] = $sql;
$queryresult = array();
$newCookie = "";
while($row = mysqli_fetch_assoc($result)){
$queryresult[] = $row;
$newCookie .= "username=".$row["Username"]."&password=".$row["Password"];
}
setrawcookie('SQLITraining', base64_encode($newCookie));
$return["queryRes"] = $queryresult;
echo json_encode($return);
break;
}
case '4':{//ServerVariables
if(isset($_SERVER["HTTP_USER_AGENT"])){
$title = mysqli_real_escape_string($con,$_POST["title"]);
$message = mysqli_real_escape_string($con,$_POST["message"]);
$useragent = $_SERVER["HTTP_USER_AGENT"];
$ip = $_SERVER["REMOTE_ADDR"];
$sql = "INSERT INTO ServerVariables (title, message, userip, useragent, verified) VALUES ('$title', '$message', '$ip', '$useragent', false);";
$result = mysqli_query($con, $sql);
if(!$result){
$return = array("state" => 1,
"sqlQuery" => $sql,
"message" => mysqli_error($con));
echo json_encode($return);
return;
}
$return = array();
$return["state"] = 0;
$return["sqlQuery"] = $sql;
//$return["queryRes"] = "Executed Successfully";
$sql = "SELECT * FROM ServerVariables WHERE verified = true AND userip = '$ip' or userip = '127.0.0.1'";
$result = mysqli_query($con, $sql);
if(!$result){
$return = array("state" => 1,
"sqlQuery" => $sql,
"message" => mysqli_error($con));
echo json_encode($return);
return;
}
$queryresult = array();
while($row = mysqli_fetch_assoc($result)){
$queryresult[] = $row;
}
$return["queryRes"] = $queryresult;
if(count($queryresult) > 1){
echo json_encode($return);
}
}
break;
}
case '5':{
if(isset($_POST["name"])){
$sql = "SELECT * FROM BlindBasic WHERE name = '".$_POST["name"]."';";
mysqli_query($con, $sql);
$return = array("state" => 1,
"sqlQuery" => "Not telling",
"message" => "Received query @ ". date('H:i:s'));
echo json_encode($return);
return;
}
break;
}
}
mysqli_close($con);
?>