tengucon 3.0 badge hunt

this year, Jonathan Black and i built the badge for TENGUCON 3.0, which ran on November 19-20 at Akihabara UDX in Tokyo. it is a small handheld: colour screen, full keyboard, LoRa, IR, a strip of RGB LEDs and an SD card slot, all on an ESP32-S3. the firmware is Rust on top of ESP-IDF.

the black badge, front

we also hid the con’s scavenger hunt in it. the website announced the hunt, and that the black badge pictured there was the prize. the badge’s About screen (pictured above) says “Want a black badge? Type TENGU in menu.” so we type tengu on the main menu:

the main menu

and we get a box that says “Enter code:”, and nothing else:

the hunt’s code box

eight codes later, you get a finish screen.

the con is over, so let’s look at the solutions !

the black badge, back

every stage works the same way: you type a code, and the badge gives you a new prompt. the prompt tells you where the next code is, and what it looks like:

the prompt after the first code

1. the badge never shuts up

there is no hint for the first one.

if we plug the badge into a laptop over USB-C and open the serial port, we get the boot log. the board has no USB-UART chip, it uses the ESP32-S3’s native USB, so the baud rate does not matter. at the end of the log, one line keeps coming back every 10 seconds:

the badge’s serial output

if you have done any CTF ever, you know what that is.

$ echo eWFtYWJ1c2hpLWJvb3RzLWI2bWhtNzN3 | base64 -d
yamabushi-boots-b6mhm73w

this is our first code: yamabushi-boots-b6mhm73w

2. the blinking LED

The next code is blinking. Format: 4 words with spaces.

nine LEDs run up the left edge of the badge. the bottom eight breathe in random colours. the top one blinks white, and it has been blinking this message since you turned the badge on.

it is Morse. we can film it, play it back slowly and count frames. one unit is 200 ms: a dot is 1 unit, a dash is 3, the gap between letters is 3 and the gap between words is 7. after the message there is a long pause, then it starts over:

LONG NOSE BLINKS HW6WGQ

this is our second code: long nose blinks hw6wgq. and yes, you type the spaces.

3. look inside the flash

The next code sits in my flash, NVS namespace hunt. Format: word-word-word-8 chars.

NVS is where ESP-IDF keeps its key-value settings, in its own partition of the flash. the badge has no flash encryption and no secure boot, so we can read the flash over USB with esptool.

first, we need to know where NVS is. the partition table is always at 0x8000:

the partition table

NVS starts at 0x9000 and is 24K (0x6000) long. we dump that, and parse it with nvs_tool.py, which ships with ESP-IDF:

the hunt namespace in the NVS dump

the hunt namespace has two blobs. flag is 26 bytes of what looks like garbage. gift starts with .ELF, we keep that one for stage 4.

the flag blob is XORed with the board’s name. every badge gets a name made from its MAC address, so every badge has a different blob. the name is in the boot log, and in the top right corner of the main menu:

the board name in the boot log

this badge is RustyKaiju24. XOR the blob with it:

XORing the flag with the board name

this is our third code: hauchiwa-in-flash-h6jk7pqk

4. the crackme

The next code is hidden as a gift in my flash, same namespace. Crack it. Format: word-word-8 chars. Keep it, it opens a door.

first we pull the gift blob out of the dump. nvs_tool.py only prints hex, so here is a small script that turns its output back into files:

import re, sys

blobs, name = {}, None
for line in open(sys.argv[1]):
    if m := re.match(r"(\S+) - Type: Blob .* Size: (\d+)", line):
        name, size = m[1], int(m[2])
        blobs[name] = b""
    elif name and (m := re.match(r"\s+0x[0-9a-f]+\s+(.{47})  (.{47})", line)):
        blobs[name] = (blobs[name] + bytes.fromhex(m[1] + m[2]))[:size]

for name, data in blobs.items():
    open(name.replace(":", "_") + ".bin", "wb").write(data)
    print(name, len(data))
$ python $IDF_PATH/components/nvs_flash/nvs_partition_tool/nvs_tool.py -d blobs nvs.bin > blobs.txt
$ python3 extract.py blobs.txt
hunt:flag 26
hunt:gift 4372
$ mv hunt_gift.bin gift.elf

it is an app for the badge’s app loader: Xtensa, stripped, and it only imports the badge’s own drawing and keyboard functions.

the gift ELF

copy it to the SD card and open it from Files, and you get a big red LOCKED screen. the arrows and A add a move, DEL removes one, OK submits. a wrong answer shows nope for over a second and wipes your input.

so we open it in Ghidra. it is a position-independent ELF, and Ghidra does not apply its R_XTENSA_RELATIVE relocations, so every call shows up as a call into the ELF header. adding the load base (0x10000) to each relocated pointer fixes that. after that, and a few renames, the main loop is easy to read. every move goes through a function that reads an opcode byte and a register byte, then does something with them:

the VM step function in Ghidra

that is a virtual machine. 0x1f loads a 32-bit constant, 0x3d jumps if a register is zero, and everything else goes to a second function:

the VM ALU in Ghidra

so 8 instructions in total:

op does
0x1f set r, imm32 load a constant
0x87 add, 0x21 mul, 0xd4 xor, 0xae and, 0x96 shr r_dst = r_dst op r_src
0xc7 load r, r r_dst = MAZE[r_src % 64]
0x3d jz r, target jump if zero

the program bytes are not read directly. each one is XORed with a value computed from its address (-0x5ef951d7 is 0xa106ae29):

the VM fetch function in Ghidra

the program is 150 bytes at offset 0xd08 of the ELF, and the 64-byte table is at 0xda0. the table is masked too, so we just emulate the VM.

once we do, the table turns out to be an 8x8 maze. the low 4 bits of each cell are walls (up, down, left, right), the high 4 bits are a checkpoint number. arrows move you one square if there is no wall. A only counts if you stand on the next checkpoint, in order. hit all four and you’re done.

the decoded maze, with the shortest path

here is a solver: the VM from Ghidra, plus a breadth-first search over (cell, checkpoints done).

import sys, collections

elf = open(sys.argv[1], "rb").read()
PROGRAM, MAZE = elf[0xd08:0xd08 + 150], elf[0xda0:0xda0 + 64]

OPS = {0x1f: "set", 0x87: "add", 0x21: "mul", 0xd4: "xor", 0xae: "and", 0x96: "shr", 0xc7: "load", 0x3d: "jz"}
CELL, PROGRESS, MOVE = 2, 7, 6
M32 = 0xFFFFFFFF

def fetch(pc):
    return PROGRAM[pc] ^ (((pc * 0xa106ae29 + 0x66caaa4c) & M32) >> 24)

def step(cell, progress, move):
    r, pc = [0] * 8, 0
    r[CELL], r[PROGRESS], r[MOVE] = cell, progress, move
    while pc < len(PROGRAM):
        op, regs = OPS[fetch(pc)], fetch(pc + 1)
        d, s = regs & 7, regs >> 4 & 7
        pc += 2
        if op == "set":
            r[d] = int.from_bytes(bytes(fetch(pc + i) for i in range(4)), "little"); pc += 4
        elif op == "jz":
            pc = pc + 1 if r[d] else fetch(pc)
        else:
            a, b = r[d], r[s]
            r[d] = {"add": a + b, "mul": a * b, "xor": a ^ b, "and": a & b,
                    "shr": a >> (b & 31), "load": MAZE[b % 64]}[op] & M32
    return r[CELL], r[PROGRESS]

start = (0, 0)
prev, queue = {start: None}, collections.deque([start])
while queue:
    state = queue.popleft()
    if state[1] == 4:
        break
    for move, key in enumerate("UDLRA"):
        nxt = step(*state, move)
        if nxt not in prev:
            prev[nxt] = (state, key)
            queue.append(nxt)

path = ""
while prev[state]:
    state, key = prev[state]
    path = key + path
print(path, len(path))

running the solver

we type the 35 keys, press OK, and the badge shows our fourth code: kurama-dojo-mpp3esnn

patching the check does not work. every move makes a 32-bit word in the VM, the words get hashed together, and the result goes through 2^21 rounds of a 64-bit mixer. that value is checked against a stored tag, and it is also the key that decrypts the answer. patch the check and you decrypt garbage.

5. the Wi-Fi fox hunt

A hidden network, TENGU-HUNT, keeps shouting. Listen, then find who shouts. The next code is what you hear plus what is written on it. Format: word-6 chars-14 chars.

“Keep it, it opens a door”: the crackme code is the WPA2 password of a hidden network.

in Wi-Fi, we pick “hidden network…”, type TENGU-HUNT, then kurama-dojo-mpp3esnn. once connected, the badge listens on UDP port 31337 and shows the last message it heard, plus the signal strength in dBm. somewhere in the venue, a little box broadcasts this every few seconds:

next code: sojobo-fcq9dc- and 14 more chars. they are on me.

the Wi-Fi screen, listening on TENGU-HUNT

so now it is a fox hunt. the closer the dBm number gets to zero, the warmer you are. find the box, read the sticker, and leave it there for the next team.

the fox hunt box, sticker and all

this is our fifth code: sojobo-fcq9dc-xqlg74y6nvbabz

6. make some friends

The next code needs 5 friends. Format: word-word-word-6 chars.

open Badge swap and point the IR end of your badge at other people’s badges. they don’t need to be there at the same time, but keep the swap screen open: the list lives in RAM, and a reboot clears it.

the badge swap screen with 5 badges found

anyone can use the swap screen, but the code only shows up if your badge accepted the stage 5 code. we also kept 5 badges running on the swap screen at the desk.

this is our sixth code: six-long-noses-48w3bh

7. the remote and the shrine

One remote in the IR blaster is not like the others. It holds a token. At Kanda Myojin, the coin detective has a stone. Next code: token-name of the friend next to him.

after stage 6, a new remote called Myojin shows up in the IR blaster. it has 4 buttons, 01 to 04, and pressing them does nothing you can see. we need a second badge: fire the buttons from one, and catch them on the other with IR blaster > Learn. each one decodes as a NEC code:

NEC 746F:6B65    t o k e
NEC 6E3D:7064    n = p d
NEC 6B79:3866    k y 8 f
NEC 7537:7920    u 7 y _

IR Learn catching the first Myojin button

read as ASCII, that is token=pdky8fu7y. every 4 bytes of text became one NEC code, the first two as the address and the last two as the command.

then you go for a walk. Kanda Myojin is a shrine a short walk from UDX. on the grounds there is a stone for Zenigata Heiji, a fictional Edo-period detective who throws coins at criminals. near it is a stone for his sidekick, Hachigoro (also called Garappachi).

this is our seventh code: pdky8fu7y-hachigoro. the badge also takes pdky8fu7y-hachigorou and pdky8fu7y-garappachi, because i was not going to argue about romanization.

8. mAAch ecute Kanda Manseibashi

Last stop: mAAch ecute Manseibashi. Two old stairs are named after years. Go up one, come down the other. Next code: bvhrcnsexa-year of the one you came down.

mAAch ecute is the red-brick viaduct of the old Manseibashi station, on the Kanda River, a few minutes on foot from UDX. the station closed in 1943 and the viaduct is now shops and cafés, but the old platform is still up there, with Chuo Line trains running right past you. two old staircases go up to it: the 1912 stairs, from when the station opened, and the 1935 stairs, built for the railway museum that moved into the station building. each one has a sign with its name.

this is our last code: bvhrcnsexa-1935

the badge then shows the finish screen:

the finish screen

the code is the first 4 bytes of sha256("finish" + answer + board_name), with the answer and name lowercased, shown as uppercase hex.

cheat sheet

stage where code
1 USB serial, base64 yamabushi-boots-b6mhm73w
2 Morse on a white LED long nose blinks hw6wgq
3 NVS hunt/flag, XOR with board name hauchiwa-in-flash-h6jk7pqk
4 crackme ELF in NVS hunt/gift kurama-dojo-mpp3esnn
5 Wi-Fi fox hunt sojobo-fcq9dc-xqlg74y6nvbabz
6 IR badge swap with 5 badges six-long-noses-48w3bh
7 IR remote token + Kanda Myojin pdky8fu7y-hachigoro
8 mAAch ecute Kanda Manseibashi bvhrcnsexa-1935

final words

a tengu, because of course

thanks to Lily, Damien, Jojo, Amanda and James, who did a lot of the heavy lifting to make this con happen, to the sponsors, and to every team that spent their con staring at a blinking LED or walking around Akihabara with a badge in their hand.

if you played, tell me what you thought. i am curious which stage was the most annoying.

see you next year :)~

djnn.sh

offensive security & software engineering


scavenger hunt solutions !

2026-11-23