-
-
[原创]KCTF 2026 - 第九题:丑寅同墟·星海抉择 分析
-
发表于: 2026-8-22 13:55 38
-
附件提供了一个字符级语言模型 ICTFForCausalLM 及其权重。模型接受长度不超过 16 个字符的字符串,预测一个输出字符。目标是从模型代码与权重中恢复隐藏的 flag。
model_def.py 中模型结构如下:
输入 x 是长度为 16 的 one-hot 编码字符 id 向量(每个位置取 0~62 的字符 id,不足 16 位补 0)。输出 64 类 logits,其中:
加载权重后各张量形状为:
关键观察在 lm_head:
因此对任意输入,其他类的 logit 恒为 -10000,几乎不可能胜出。最终结果只在 <success> 与 <fail> 之间竞争。
令隐藏层输出为 h = ReLU(W·x + b),h 维度 21:
要让模型输出 <success>:
由 h[0] = ReLU(W0·x + 311560)(dense.bias[0] = 311560)得条件:
把字符 id 当作 16 个整数变量 x[0..15] ∈ [0, 62],上述条件全部是线性不等式,用整数线性规划(scipy milp)求解:
结果:
将字符 id 映射回字符集 "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
得到 16 字符字符串:
输出:
模型确认该输入预测为 <success>,即为正确答案。
由 AI 完成。
dense : Linear(16 -> 21) + bias
act : ReLU
lm_head: Linear(21 -> 64) + bias
class ICTFForCausalLM(PreTrainedModel):
def __init__(self, config):
super().__init__(config)
self.dense = nn.Linear(config.max_position_embeddings, config.hidden_size, bias=True)
self.act = nn.ReLU()
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=True)
dense.weight (21, 16)
dense.bias (21,)
lm_head.weight (64, 21)
lm_head.bias (64,)
[招生]科锐逆向工程师培训(2026年11月13日实地,远程教学同时开班, 第57期)
赞赏记录
参与人
雪币
留言
时间
git_99440qimingminimax
为你点赞!
2026-9-23 11:51
git_51951meggadf3df
非常支持你的观点!
2026-9-11 10:08
mb_lthgjpwj
为你点赞!
2026-8-27 15:27
huangyalei
期待更多优质内容的分享,论坛有你更精彩!
2026-8-23 14:43
赞赏
他的文章
赞赏
雪币:
留言: