-
Notifications
You must be signed in to change notification settings - Fork 476
/
sqlpwn.php
167 lines (126 loc) · 4.19 KB
/
sqlpwn.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
<?php
/*
sqlpwn by orange
Don't brute force or you will be banned !
*/
session_start();
error_reporting(0);
include "template.html";
include "config.php";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
mysql_query("SET sql_mode='strict_all_tables'");
function check_login(){
if ( !isset($_SESSION['name']) ){
exit('not login');
}
}
function escape($str){
$str = mysql_real_escape_string($str);
return $str;
}
$mode = $_GET['mode'];
if ( $mode == 'admin' ){
check_login();
if ( $_SESSION['admin'] != 1 ){
exit('not admin');
}
include getcwd() . '/' . $_GET['boom'] . "php";
} else if ( $mode == 'post' ){
check_login();
$name = $_SESSION['name'];
$titl = $_POST['title'];
$note = $_POST['note'];
$note = trim(escape($note));
$titl = trim(escape($titl));
if ( strlen($note) < 6 ){
exit('para error');
}
if ( strlen($titl) < 6 ){
exit('para error');
}
if ( strlen($note) > 128 ){
$note = substr($note, 0, 128);
}
if ( strlen($titl) > 32 ){
$titl = substr($titl, 0, 32);
}
mysql_query(sprintf("INSERT INTO notes(name, title, note) VALUES('%s', '%s', '%s')", $name, $titl, $note));
echo 'ok';
} else if ( $mode == 'show' ){
check_login();
$id = (int)$_GET['id'];
$r = mysql_query(sprintf("SELECT * FROM notes WHERE id='%d'", $id));
if ( mysql_num_rows($r) == 0 ){
exit('id not found');
}
$result = mysql_fetch_object($r);
if ( $result->name !== $_SESSION['name'] ){
exit('not posted by you');
}
$name = $_SESSION['name'];
$titl = $result->title;
$note = $result->note;
echo "title " . $titl;
echo "<br>";
echo "note " . $note;
exit();
} else if ( $mode == 'register' ) {
$name = $_POST['name'];
$pass = $_POST['pass'];
$name = trim( escape( $name ) );
$pass = trim( escape( $pass ) );
if ( strlen($name) < 6 ){
exit('para error');
}
if ( strlen($pass) < 6 ){
exit('para error');
}
$r = mysql_query(sprintf("SELECT * FROM users WHERE name='%s'", $name));
if ( mysql_num_rows($r) > 0 ){
exit('duplicated');
}
$sql = sprintf("INSERT INTO users(name, pass) VALUES('%s', '%s')", $name, md5($pass));
mysql_query($sql);
$sql = sprintf("INSERT INTO locks(name) VALUES('%s')", $name);
mysql_query($sql);
echo 'ok';
} else if ( $mode == 'login' ) {
$name = $_POST['name'];
$pass = $_POST['pass'];
$name = trim( escape( $name ) );
$pass = trim( escape( $pass ) );
$r = mysql_query(sprintf("SELECT * FROM users WHERE name='%s'", $name));
if ( mysql_num_rows($r) == 0 ){
exit('user not found');
}
$result = mysql_fetch_object($r);
if ( $result->pass !== md5($pass) ){
exit('pass incorrect');
}
$r = mysql_query(sprintf("SELECT * FROM locks WHERE name='%s'", $name));
if ( mysql_num_rows($r) > 0 ){
exit('user locked');
}
$_SESSION['id'] = $result->id;
$_SESSION['name'] = $result->name;
$_SESSION['pass'] = $result->pass;
if ( $name == 'orange' ){
$_SESSION['admin'] = 1;
}
echo 'ok';
} else if ( $mode == 'info' ){
phpinfo();
} else if ( $mode == 'flag' ){
check_login();
echo $flag;
} else {
// I am always on your top >/////<
$r = mysql_query(sprintf("SELECT * FROM notes WHERE name='orange' UNION SELECT * FROM notes ORDER BY id DESC LIMIT 100"));
while ($row = mysql_fetch_object($r)) {
$id = $row->id;
$titl = $row->title;
echo sprintf("<li><a href='./sqlpwn.php?mode=show&id=%d'>%s</a></li>\n", $id, $titl);
echo "<br>";
}
}