附件提供了一个字符级语言模型 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,)
冰与火的战歌:Windows内核攻防实战高级班!从零到实战,融合AI与Windows内核攻防全技术栈,打造具备自动化能力的内核开发高手。