Challenge Description
Category: Network Forensics / Legacy Systems
Difficulty: 🟠 Medium-Hard
Four unusual TCP sessions on port 3270 were captured between a legacy IBM System/38 used by the water plant and an unregistered workstation. The contractor called the payload a garbled TLS negotiation and closed the ticket. Confirm or reject that conclusion.
We get four tiny packet captures:
billing_frag_01.pcap
billing_frag_02.pcap
billing_frag_03.pcap
billing_frag_04.pcap
This was my favourite challenge in the CTF.
It was not the largest binary or the most complicated protocol implementation. It was better than that: every layer changed what I thought I was looking at. The traffic begins as apparent binary noise, becomes readable legacy terminal text, turns into shuffled C source code, and ends with a small reversing problem.
The contractor’s TLS explanation is believable for about thirty seconds. That is exactly long enough to be useful misdirection.
TL;DR
- All four captures contain one complete TCP session with exactly ten packets
- The unregistered workstation is
10.11.126.20; the System/38 service is10.11.126.10:3270 - Frames
1–3establish TCP, frame4carries a request, and frame6carries the response - The first request begins with
d9 c5 e3 d9 40, which cannot be a TLS record header - Decoding the payload as IBM EBCDIC code page 037 turns it into
RETR 1\r\n - The four server responses contain
PART 3,PART 1,PART 4, andPART 2 - Correct source order is therefore capture
02 → 04 → 01 → 03 - The reconstructed C code contains an encrypted byte array and the operation
e[i] ^= 0x42 - The exact program output is
flag{ascii_f0r_th3_w1nn}
First Pass: Four Very Small Sessions
I moved the captures into a dedicated directory before doing anything else:
Set-Location C:\Users\caralho\Desktop\a-glimpse-of-the-past
Get-ChildItem .\billing_frag_*.pcap | Select-Object Name,Length
Name Length
---- ------
billing_frag_01.pcap 926
billing_frag_02.pcap 993
billing_frag_03.pcap 928
billing_frag_04.pcap 1074
The files are so small that there is no reason to begin with statistics or flow aggregation. Opening any one of them shows the entire exchange immediately.
Before decoding them, I recorded hashes so that every later result could be tied back to the supplied evidence:
Get-ChildItem .\billing_frag_*.pcap | ForEach-Object {
Get-FileHash $_.FullName -Algorithm SHA256
}
| Capture | SHA-256 |
|---|---|
billing_frag_01.pcap |
3A76666BF9BAB10BB366B7A64FDD688870990EE7C5F71842B01D50C12ABE686E |
billing_frag_02.pcap |
4A94FAED33D602EF407F1EEC1595E8C5A638832B560A4734055C13A81473704E |
billing_frag_03.pcap |
4CEF497F0A097F91A94502DDE87F6D31EFB29FEF1C1779AFBFB4C54594AC326E |
billing_frag_04.pcap |
24C100CD553D0ECB5AF5A37C091380F46B19144AFB9A52AA78A03A4847E108FB |
Nothing in the solve requires modifying the captures. The parser, decoder, and reassembler all operate read-only and write their results to standard output.
A useful Wireshark display filter is:
tcp.port == 3270 && tcp.len > 0
That reduces every capture to two packets: frame 4 and frame 6. I also wrote a small standard-library parser so that the extraction could be reproduced without depending on Wireshark or Scapy. The important offsets are the IPv4 header length and the TCP data offset; everything after both headers, up to the IP total length, is application data.
ip = 14 # Ethernet header
ihl = (raw[ip] & 0x0f) * 4
total_length = struct.unpack_from("!H", raw, ip + 2)[0]
tcp = ip + ihl
tcp_length = (raw[tcp + 12] >> 4) * 4
payload = raw[tcp + tcp_length : ip + total_length]
The first session has a very regular shape:
1–3 TCP three-way handshake
4 workstation -> System/38, 8 bytes
5 ACK
6 System/38 -> workstation, 58 bytes
7 ACK
8–10 orderly FIN teardown
The other three captures use the same ten-packet pattern. The session roles and packet positions remain fixed; the timestamps, workstation source port, request digit, response content, and response length change.
There is a small directionality detail worth recording. 10.11.126.20 sends the SYN, so the unregistered workstation is the TCP client. 10.11.126.10 listens on port 3270 and returns the suspicious data. The server response is outbound from the System/38, but the workstation initiates each retrieval.
That distinction matters when reconstructing intent: this does not look like a scheduled billing push. It looks like a workstation asking the legacy host for numbered records.
The timing reinforces that interpretation. Each connection lasts less than two milliseconds from SYN to final ACK, and the four requests are spaced roughly four seconds apart. These are short, scripted retrievals,not a human terminal session left open while an operator navigates screens.
Rejecting the TLS Explanation
Calling arbitrary binary-looking traffic “probably TLS” is tempting, but TLS records are not arbitrary.
A conventional TLS handshake record starts with a five-byte header:
16 03 xx LL LL
│ │ └──── record length
│ └────────── TLS major/minor version
└───────────── handshake content type
The first application payload in billing_frag_01.pcap is:
d9 c5 e3 d9 40 f1 0d 25
That is not a TLS record header. It does not begin with a valid TLS content type, there is no 03 xx protocol version, and there is no ClientHello or ServerHello anywhere before the connection closes.
The server’s first application bytes are equally un-TLS-like:
7b 7b 40 d7 c1 d9 e3 40 f3 40 7b 7b 25
Four sessions repeat the same request/response structure without a single TLS handshake. The contractor’s conclusion can be rejected from framing alone.
There is also no entropy argument needed here. People sometimes treat “looks random in the packet bytes pane” as evidence of encryption and then start measuring randomness. The record header already disproves TLS, while the repeated prefixes suggest structured data. The first four request bytes are identical in every capture; byte six advances from EBCDIC 1 through 4. Four ClientHello records would not form that application-level request pattern.
The number 3270 provides the next clue because it evokes IBM 3270 terminals, and the challenge places the service on a System/38. That makes EBCDIC, IBM’s legacy character encoding family, worth testing. This is challenge context rather than an IANA service identification: standard TN3270 normally rides Telnet on TCP port 23, or port 992 for TLS-protected TN3270.
It does not prove that this is a complete standards-compliant TN3270 conversation. There are no Telnet IAC negotiation bytes (ff), no DO/WILL exchange, and no terminal-type negotiation. What we have is a tiny custom request/response service using port 3270 and EBCDIC records. The port is contextual evidence, not a substitute for looking at the bytes.
The EBCDIC Turn
Viewing the request as ASCII gives exactly the sort of output that caused the bad initial diagnosis:
....@..%
The same eight bytes decoded with Python’s IBM EBCDIC US/Canada codec are unambiguous:
payload.decode("cp037")
RETR 1\r\n
The individual byte mapping makes the result easier to trust:
| Hex | CP037 character |
|---|---|
d9 |
R |
c5 |
E |
e3 |
T |
d9 |
R |
40 |
space |
f1 |
1 |
0d 25 |
\r\n |
The response header behaves the same way:
7b 7b 40 d7 c1 d9 e3 40 f3 40 7b 7b 25
becomes:
## PART 3 ##\n
This is the moment the whole capture changes character. The payload is not damaged, compressed, encrypted, or partially captured. The analyst was simply looking at an IBM character set through an ASCII lens.
CP037 is a good fit because the decoded punctuation produces valid C source. A wrong EBCDIC code page can still make letters look convincing while mapping braces, brackets, or punctuation differently. Here the complete response,not just the word PART,decodes into coherent source code, which is a much stronger validation than spotting one readable token.
Another useful check is the line ending. The request terminates with bytes 0d 25. Under CP037 those are carriage return and line feed. The apparent encoding explains the words, spaces, digits, punctuation, and record delimiter at once. That is the point where EBCDIC stops being a plausible guess and becomes the demonstrated encoding.
Extracting Every Application Record
Using the tcp_payloads() helper from the complete solver below, the two data-bearing packets from the first capture can be decoded directly:
for frame, payload in tcp_payloads(Path("billing_frag_01.pcap")):
print(f"frame {frame}")
print("hex: ", payload.hex(" "))
print("cp037:", repr(payload.decode("cp037")))
Running the equivalent extraction across all four captures produces this table:
| Capture | Client port | Request packet | Request | Response packet | Response length | Embedded label |
|---|---|---|---|---|---|---|
billing_frag_01.pcap |
50278 |
4 |
RETR 1 |
6 |
58 |
PART 3 |
billing_frag_02.pcap |
50290 |
4 |
RETR 2 |
6 |
125 |
PART 1 |
billing_frag_03.pcap |
53288 |
4 |
RETR 3 |
6 |
60 |
PART 4 |
billing_frag_04.pcap |
53290 |
4 |
RETR 4 |
6 |
206 |
PART 2 |
At first I concatenated the decoded responses in capture order. That gives fragments 3, 1, 4, 2, which is obviously not a valid C program: the XOR loop appears before the byte array it modifies, and the function prologue sits in the middle.
That failed attempt is useful because it reveals the second deliberate trick. The request number is not the source-fragment number. The authoritative ordering is inside each response.
PART 1 <- billing_frag_02.pcap
PART 2 <- billing_frag_04.pcap
PART 3 <- billing_frag_01.pcap
PART 4 <- billing_frag_03.pcap
The correct capture order for reassembly is therefore:
02 -> 04 -> 01 -> 03
It is worth looking at what each piece contributes before joining them:
PART 1 / frag 02: include, maintenance credentials, main() opening
PART 2 / frag 04: encrypted byte array and NUL terminator
PART 3 / frag 01: XOR loop using key 0x42
PART 4 / frag 03: printf(), return, and closing brace
This gives two independent ordering checks. The numeric headers say 1 → 2 → 3 → 4, and C syntax says declaration before use, function body before return, then closing brace. A correct reconstruction satisfies both.
Reassembling the Source
After sorting on the number in ## PART n ##, the four bodies form one complete C program:
#include <stdio.h>
/* WTP-7 HMI maintenance login
* user: wtp7_admin
* pass: maint3nance
*/
int main(void) {
unsigned char e[] = {
0x24,0x2e,0x23,0x25,0x39,0x23,0x31,0x21,
0x2b,0x2b,0x1d,0x24,0x72,0x30,0x1d,0x36,
0x2a,0x71,0x1d,0x35,0x73,0x2c,0x2c,0x3f,
0x00
};
for (int i = 0; e[i]; i++) e[i] ^= 0x42;
printf("%s\n", (char *)e);
return 0;
}
The comment exposes a maintenance account:
user: wtp7_admin
pass: maint3nance
That is significant incident evidence, but it is not the final answer. The program below the comment tells us exactly how to recover the flag.
In a real investigation I would preserve those credentials as a separate finding. They explain why extracting the source matters beyond the CTF flag and may indicate another access path into the HMI. I would not, however, try them against a live system during evidence review. The packet data already establishes that they were disclosed; authentication testing would be a different, explicitly authorized action.
There are 25 values in e: 24 encrypted bytes followed by 0x00. The loop condition checks e[i] before performing XOR, so the terminator is never transformed. This is important if the extraction is rewritten in Python. XORing all 25 bytes would turn the NUL into 0x42, adding a stray B to the output.
The C semantics are:
for each nonzero byte:
plaintext_byte = encrypted_byte XOR 0x42
stop at 0x00
The first five values provide an immediate crib:
0x24 ^ 0x42 = 0x66 'f'
0x2e ^ 0x42 = 0x6c 'l'
0x23 ^ 0x42 = 0x61 'a'
0x25 ^ 0x42 = 0x67 'g'
0x39 ^ 0x42 = 0x7b '{'
flag{ appears before the entire array is decoded. At this point there is no reason to compile unknown source; reproducing the loop directly is enough.
The rest of the plaintext remains printable ASCII, the last byte becomes }, and there are no bytes after the C terminator. Those are useful validation properties. A wrong key might produce one or two plausible characters by accident, but it is very unlikely to produce a correctly delimited flag across all 24 bytes.
One Reproducible Solver
This is the self-contained version of the solver I used. It relies only on Python’s standard library and does not hardcode the fragment permutation, XOR key, encrypted array, or flag. Those values are all derived from the packet data and reconstructed source.
from dataclasses import dataclass
from pathlib import Path
import re
import struct
@dataclass
class Fragment:
capture: str
part: int
body: str
def tcp_payloads(path: Path) -> list[tuple[int, bytes]]:
"""Return (frame number, TCP payload) pairs from a little-endian Ethernet PCAP."""
data = path.read_bytes()
if data[:4] != b"\xd4\xc3\xb2\xa1":
raise ValueError(f"{path.name}: unsupported PCAP format")
records = []
offset = 24
frame = 0
while offset < len(data):
frame += 1
_, _, captured, _ = struct.unpack_from("<IIII", data, offset)
offset += 16
raw = data[offset : offset + captured]
offset += captured
if len(raw) < 54 or raw[12:14] != b"\x08\x00":
continue
ip = 14
ihl = (raw[ip] & 0x0F) * 4
if raw[ip + 9] != 6:
continue
total_length = struct.unpack_from("!H", raw, ip + 2)[0]
tcp = ip + ihl
tcp_length = (raw[tcp + 12] >> 4) * 4
payload = raw[tcp + tcp_length : ip + total_length]
if payload:
records.append((frame, payload))
return records
def extract(path: Path) -> Fragment:
records = tcp_payloads(path)
if len(records) != 2:
raise ValueError(f"{path.name}: expected two data packets")
response = records[1][1].decode("cp037").replace("\r", "")
match = re.fullmatch(r"## PART (\d+) ##\n(.*)", response, re.DOTALL)
if not match:
raise ValueError(f"{path.name}: missing PART header")
return Fragment(path.name, int(match.group(1)), match.group(2))
fragments = [extract(path) for path in sorted(Path(".").glob("billing_frag_*.pcap"))]
source = "".join(fragment.body for fragment in sorted(fragments, key=lambda item: item.part))
key = int(re.search(r"\^=\s*0x([0-9a-fA-F]{2})", source).group(1), 16)
array = re.search(
r"unsigned char e\[\]\s*=\s*\{(.*?)\};",
source,
re.DOTALL,
).group(1)
values = bytes(int(item, 16) for item in re.findall(r"0x([0-9a-fA-F]{2})", array))
ciphertext = values.split(b"\x00", 1)[0]
plaintext = bytes(byte ^ key for byte in ciphertext)
print(f"XOR key: 0x{key:02X}")
print(plaintext.decode("ascii"))
The final two output lines are:
XOR key: 0x42
flag{ascii_f0r_th3_w1nn}
The challenge’s example format uses Flag{...}, but the recovered bytes contain lowercase flag. I kept the exact case emitted by the evidence rather than changing it to match the prose.
Independent sanity checks
I used four small checks before treating the result as final:
- Transport: each capture contains one complete, orderly TCP conversation with no missing application segments.
- Encoding: CP037 explains every request and every response, including spaces and line endings.
- Reassembly: ordering by the embedded labels produces syntactically coherent C with no missing braces or incomplete statements.
- Decode: the reconstructed operation,
XOR 0x42 until NUL, produces a fully printable flag with the expected delimiters.
No single one of those checks is the proof. Together they form a chain from packet bytes to final plaintext without an unexplained jump.
Flag
flag{ascii_f0r_th3_w1nn}
Why This Was the Best Challenge
Most packet challenges ask one question: find the odd flow, follow it, and read the answer. This one makes the representation itself part of the investigation.
The traffic is visible from the start. Nothing is buried in a million packets, and no key is hidden in metadata. The difficulty comes from a modern analyst’s assumptions:
- Binary-looking application data is not automatically encrypted data
- A familiar port is a direction, not proof of a protocol
- ASCII is not the only text encoding that can appear on a network
- File order is not necessarily reconstruction order
- Readable credentials can still be a waypoint rather than the final answer
The best clue is byte 0x40. In ASCII it is @, which makes the request look even stranger. In EBCDIC CP037 it is a space, and it appears exactly where a space belongs in both RETR 1 and ## PART 3 ##. Once that mapping clicks, the “garbled” payload becomes ordinary source code almost instantly.
I also liked that the legacy clue survives a more precise reading. The captures use the number 3270 and EBCDIC, but they do not contain a real TN3270 negotiation, and TCP port 3270 is not the normal TN3270 service port. Treating a suggestive port number as the complete answer would be the same category of mistake as calling the payload TLS because it is not readable in ASCII. In both cases, the bytes deserve the final word.
The final XOR is intentionally simple. By that point the work has already been done: reject the contractor’s theory, recognize the old character set, extract the records, and notice the permutation. The program is less a cipher than a receipt proving that the reconstruction is correct.
That is why this was the challenge that made me stop and think, “damn, this was good.” It rewards protocol discipline, legacy knowledge, and a little reversing in one small set of captures, and every step can be verified directly from the evidence.