CodeShell.kr - Relay

Challenge

一封正文空掉的邮件,题面说消息没走完。难度在于载荷在 Received 头的 id 字段里,而且顺序要按投递方向而不是文件顺序。

An empty message

一条空消息。

1
https://codeshell.kr/challenges/misc-relay/

Solution

附件是一封正文只有一句 "The body did not make the trip." 的邮件。

Step 1:正文没有载荷,信息在头部:四个 Received 头各带一个 2 字母的 with SMTP id

1
2
3
4
Received: ... with SMTP id ACK   (最新)
Received: ... with SMTP id TR
Received: ... with SMTP id CK
Received: ... with SMTP id BA (最旧)

Step 2:Received 头在文件里由新到旧排列,而投递顺序是由旧到新,所以倒序读:

1
BA CK TR ACK -> BACKTRACK

Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python3
"""CodeShell.kr — Relay (Misc, 50p) solver.

The .eml body is empty; the payload is the 2-letter `with SMTP id` of each
Received header. Received headers are listed newest-first, so reading them
oldest-first spells the answer.

Usage: uv run python solvers/relay.py
"""

import email
import re
from pathlib import Path

EML = "assets/challenge-files/misc-relay.eml"


def main():
msg = email.message_from_bytes(Path(EML).read_bytes())
ids = [re.search(r"with SMTP id ([A-Za-z0-9]+)", v).group(1) for v in msg.get_all("Received", [])]
print("received top-down", ids)
print("oldest-first ", "".join(reversed(ids)))


if __name__ == "__main__":
main()
CodeShell{BACKTRACK}