OverTheWire Advent 2019 Day0 - Challenge Zero - Writeup

Posted on

On https://advent2019.overthewire.org/challenge-zero we are presented with a fireplace gif.

I first thought it’s a forensic challenge with the fireplace gif, but couldn’t find anything abnormal in the image. Then I checked the source code of the page.

    <!-- browser detected: chrome -->
    <img style="width:400px;" src="/flames.gif"><pre>Fox! Fox! Burning bright! In the forests of the night!

Hint: $ break *0x7c00</pre>

We see that the server detects our browser and responds accordingly. Which is a hint for using another browser, or no browser at all to access the page.

So I ran

curl https://advent2019.overthewire.org/challenge-zero

and got the jumping flame in text :) curl-fireplace

If we observe the flame carefully, we can see that the text constructing the flame is repeating itself. By using Shift+PageUp of our terminal emulator we are able to reconstruct the whole text from the scrollback buffer.

In the end we can construct a text file. Let’s use a simple python script to get rid of the # background.

with open('flame.txt') as f:
    data =  f.read()
data = data.replace("#", "").replace("\n", "")

data becomes


It’s clear that data is base64 encoded, so we run

import base64
base64decode_data = base64.b64decode(data)

base64decode_data is something like

begin 644 boot.bin\nM^C\'`CMB.P([0O`!\\0`^B#R#`@^#[@\\@"#R+`#R#@#0`&#[email protected]\\Z+X`[email protected]^Z\nMX1ES3;X8?>BQ`+\\`?C\'`S18\\#70:/`AU#X\'_`\'Y^[KY&?>B6`$_KY:JT#LT0\nMZ]Z!_Q!^=<\\/*`;P?0\\H\'@!^Z#0`[email protected]_O\'N!][email protected]\\X%]MT"NNSOB5]Z&0`Z_Z^\nM4\'T/*`8`[email protected]\\H\'[email protected]/``\\I\'(/&$(\'^X\'UUZ>FM`&8/[])F#^_8N^4VM\'/!Z`?V\nM\\[email protected]#SK?R$5F#W#)_P_&T!!F#^_"@#;\'?)QX\\68/[\\$X_\'0\'[email protected]\\XW-CK\nMSF8/.-W8P[0.K#1"=`8QV\\T0Z_/#[email protected])V(W,B4P(R8G)F(D,"TO8A`!=F(V\nM*BLQ8CLG(S!C0D]($B,Q,34M,"9X8D)/2`$M+R=B(",A*6(U*S8J8B-B+RTF\nM)S`[email protected]$2%V)X$D)*8DI"D)"0D)"0T(/KBQ^!OZ,P,!19EYHU$!Q"0^0^+?8=\nMLGYZ\',K_"4>\'+N_UK&=A-F;*%C\\%\\==(/3KT`Z,2Z9H#""\'!!8^[email protected];]B-X\nM,!IB!^0G^\\"KVJA;B3LZ[UWH*Z&N[\\1C>BI>!*:]<K/H%+3,";[[email protected]>;E72IV\nM>$Z%?*Q4`F_Q\'B"KDWX.2B^[email protected]$8/0MDV\'.]]_X:@#91.)"@-!%M,%Y2\n15&[email protected]+FE"I<D#2W\\[email protected]:H`\n`\nend\n

No idea what this is, but by searching the file header “begin 644” we can find out that this is uuencoded. Because the python uu.decode API requires a file input, we first write base64decode_data to a file called uuencoded_data.

with open("uuencoded_data", "wb") as f:
import uu
with open("uuencoded_data", "rb") as f:

After uu.decode(f) executes, we get a boot.bin file. Running file boot.bin tells us it contains Master Boot Record.

We can run qemu-system-x86_64 boot.bin, but we get

We upgraded from RC4 this year!

Come back with a modern CPU :P

Let’s try qemu-system-x86_64 boot.bin -cpu max (max Enables all features supported by the accelerator in the current host, see qemu-system-x86_64 -cpu help). Now it is asking for a password. We don’t know it, let’s disassemble the file by IDA.

After studying the assembly code, I added all these comments and custom function names.

ida-1 ida-2 ida-3

The idea of the program is that the user needs to type 16 chars (see 0x7C5C), which is stored in 0x7E00-0x7E0F, the predefined word xmmword_7DF0 is moved to xmm0 (see 0x7C62), the user input is moved to xmm3 (see 0x7C67), then the aes_encrypt_xmm0_as_key_xmm3_as_input function is invoked, which stores the aes encrypted result back to xmm3. The final result is compared with xmmword_7DE0. If the comparison succeeds, we jump to giving_flag_start (see 0x7C7A), which decrypts the data chunk starting from 0x7D50. Then the instruction pointer points to 0x7D50, to execute the decrypted code, which supposedly would give us the flag.

So we know the aes key is xmmword_7DF0, the aes encrypt output is xmmword_7DE0. We just need to run aes decrypt with these two values. But I actually encountered some problem there.

As can be seen in this screenshot, the xmmword displayed in IDA shows 54525E306D1134A090385136801AFEF7h and 0AA55950D36FC2D0D24970AA5B980796Dh. So I tried to run aes decrypt with these two inputs, and got some non ascii results. Even if I used


After some struggling, I looked at the actual hexdump of the boot.bin file, and found that IDA is representing the word in little endian format.

So I ran aes decrypt with the words shown in the hexdump, and successfully got the password.

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import (
    Cipher, algorithms, modes
key = bytes.fromhex("6D7980B9A50A97240D2DFC360D9555AA")
decryptor = Cipher(
pt = decryptor.update(bytes.fromhex("F7FE1A8036513890A034116D305E5254")) + decryptor.finalize()
print(' '.join('%02x' %x for x in pt))
print(' '.join("%d" %x for x in pt))
print(''.join("%c" %x for x in pt))

We get the password MiLiT4RyGr4d3MbR.

After we type these 16 characters in the emulator, we get the flag AOTW{31oct__1s__25dec}.


Yes, 512 bytes certainly is a lot of space. :)

Extra Stuff

Another way to enter the input, which was used when I was trying to enter the incorrect non-ascii values.

At one shell, we run the following script (-s is shorthand for -gdb tcp::1234, -S freezes CPU at startup, which allows us to set breakpoint before the program starts)

qemu-system-x86_64 boot.bin -cpu max -s -S

At another shell, we use gdb to debug and manipulate the memory

target remote localhost:1234
b *0x7C67 (stop when the program tries to move our input to xmm3 register)
type 16 random chars in the emulator
    We encounter breakpoint *0x7C67
    We modify the user input (0x7E00-0x7E0F) by running 
set {int}0x7E00 = 77
set {int}0x7E01 = 105
set {int}0x7E02 = 76
set {int}0x7E03 = 105
set {int}0x7E04 = 84
set {int}0x7E05 = 52
set {int}0x7E06 = 82
set {int}0x7E07 = 121
set {int}0x7E08 = 71
set {int}0x7E09 = 114
set {int}0x7E0A = 52
set {int}0x7E0B = 100
set {int}0x7E0C = 51
set {int}0x7E0D = 77
set {int}0x7E0E = 98
set {int}0x7E0F = 82

We get the flag.