Karma on ESP8266

Earlier this year, I had wondered whether it was feasible to implement the Karma attack on a low-powered device, such as the ESP8266. It turns out this was quite simple, and you can now find a template for this on Github here.

The code is not a complete WiFi pineapple on an ESP – by design, this only implements part of the attack, it is up to the user to provide the “rogue AP host” and network back-end (but on the low-power theme, you might be able to forge this via another ESP8266). No preferred network list functionality is provided here either, but this isn’t too difficult to implement – the ESP is fairly generous in terms of resources for this.

If you want to play around this, the following video is well worth watching. The concepts discussed here are all relevant, no matter the hardware platform (though against modern devices, they have varying degrees of effectiveness – the most effective seems to be preferred network list based trickery, or good old fashioned fake beacons).

Have fun!

Posted in Bards, Computers, Jesting | Leave a comment

Writeups – Mr Reagan, Bluepill (Securityfest CTF)

This weekend, I particpated for a short while in the Securityfest CTF. During the time available, I was able to solve a few challenges – I will present the writeups for two of them here.

Mr Reagan

This challenge was presented as a binary file, which you can download here (note – this is a ~35MB file).

Strangely enough, binwalk shows nothing meaningful, but “file” identifies it as an NTFS filesystem. Running “strings” didn’t extract anything immediately meaningful. A bit of Google led to a freely available tool called “RecuperaBit” – this allowed us to recover the filesystem by ignoring an incorrect partition:

We immediately note several text files which have been deleted, which we can recover – but this does not reveal anything meaningful. Trawling through the filesystem, we see some more deleted files in EFSTMPWP/:

Each of these file parts contains 13 bytes of something that looks like base64 data. A quick Python script to brute force which order the chunks come in, quickly reveals the flag (or close enough to it):


This challenge was presented as a Linux kernel and kernel module, which you can download here.

Running the package as suggested reveals a simple busybox-based system, with one curious entry about bluepill in the dmesg output. We continue our investigation with bluepill.ko:

Thankfully, symbols are left in the binary, making our adventure a bit easier. We start by noting that the kernel object, upon loading, creates the /proc/bluepill object, and installs a write handler via proc_create – whenever we write to /proc/bluepill, pill_choice is called.

The pill_choice function then calls a function called “calc”, and memcmps the result to some hard-coded strings:

The astute reader will notice this isn’t 100% accurate, but we’ll come back to this later. The “calc” function looks complex at first, but we quickly find some magic numbers:

This tells us that the function is effectively an MD5 function, and the structure of the function checks out with a basic description of MD5.

At this point, I looked up the checksums above in crackstation.net, but this turned up nothing, indicating some manner of pre or post-processing on the source data. Going back to the “pill_choice” function, a closer inspection reveals that the MD5sum is xor’ed with the first few characters of /proc/version, which we know from the binary.

A quick Python script reveals the key we need to type into /proc/bluepill for the flag: unfortunately, this was completed after the end of the CTF event, too late to score any points.

Overall, this was an enjoyable CTF – my only regret is starting late on Friday, instead of on Thursday when it actually began in local time. See you all in Viettel Mates CTF in two weeks time.

Posted in Bards, Computers, Jesting | Leave a comment

Writeups – Numbers Game, BabyRE (RCTF – Part 2)

This post continues from my last post on. Two more writeups for RCTF are presented below.

Numbers Game

This challenge was presented as an IP and port, with the clue that we had to “guess”. This challenge ended up being a variation of “Cows and Bulls” (or, if you prefer, the Fallout hacking puzzle). We guess 4 numbers, then are told how many we have in the correct position, and how many numbers have the correct value but are in the wrong position.

A simple Python script solves this cleanly, which you can download here.

Funnily enough, from the Wikipedia article, we note that the minimal average game length is just over 5 turns:

We are provided 6: therefore, our solution must be optimal (fortunately, the solver I found off github was).


This challenge was presented as a Linux binary, which you can download here. While presented as a reverse engineering challenge, I performed only minimal reverse engineering to complete this challenge.

Initial analysis showed that this executable took in some letters and a number, followed by some arbitrary additional input. The output seemed to be a series of dword values. One of what appears to be the encoding steps is shown below:

Based on this alone, I made a few assumptions:

  • The application encoded one character at a time
  • There was no meaningful randomness, despite randomness-based functions being called
  • The order of characters didn’t matter (but this is slightly irrelevant if we have an encoding oracle)

I first tested my hypothesis by providing “test 15” as the first inputs, then encoding “abc” and “cba”. These provided the expected result: that is, one dword value corresponded to each character of input.

I then attempted to encode “RCTF”, which provided dword outputs which corresponded to the contents of the “out” file – I assumed at this point that this was the flag. Further testing confirmed that the order of characters did not matter.

From here, a little bit of Python makes this a trivial solve: we simply encode the entire alphabet, and test this against the “out” file. You can download the script I used here.

Overall, I enjoyed participating in this CTF – this showed me some serious gaps I have with webappsec and pwning. As always, I look forward to improving my skill for the next one.

See you all in “Security Fest CTF” and Faust CTF in two week’s time.

Posted in Bards, Computers, Jesting | Leave a comment

Writeups – Sign, Cpushop, Cats (RCTF – Part 1)

This weekend, I participated in the RCTF event. This was a well-paced, yet challenging CTF – I enjoyed this event, and did not encounter any hosting issues aside from a few moments when one of the web challenges went down.

I learned a few useful things from this CTF, and I will present some writeups below. In an attempt to keep these posts to a somewhat manageable length, I will split these writeups into two posts.


Cats was presented as a miscellaneous challenge: the object was to find 15 commands which were equivalent to “cat”, when “food” was provided as argv[1] (and we controlled the contents of the file “food”). A dockerfile was provided, through which we could run this challenge locally, without a Google ReCAPTCHA slowing us down.

The “check” simply ensured that “cat food” and “$input food” provided the same output and return value, so the obvious choice was to look for equivalents to cat. Initially, I browsed my CTF box, looking for promising binaries. I came up with an initial list:

tail, more, head.

“less” didn’t seem to work in the target environment, so I set this aside. I then changed the file to contain the contents “food”, so “ls” would work, and changed the file to a single line, so commands like “tac” and “shuf” would work. This allowed me a few more options:


For the remainder of the challenge, I started up a Docker environment in AWS, and listed /usr/bin, manually looking for binaries which may have not been present on my CTF box. I ended up with the following list:


Successfully giving me the flag:


This challenge was presented as a Linux executable, which you can download here. The challenge was to run the executable for the flag.

Initial analysis showed that there were a number of strange-looking imports, and structures indicating the presence of a Windows executable. I attempted to extract this Windows executable, and glued a DOS Stub from another functioning Windows executable in, to no effect:

The structures seemed somehow mangled, and the executable would not execute.

At this point, I stumbled across a PNG in the file, which showed the Wine Notepad icon, so I ran the original executable in Wine for shits and giggles:

No shit, it’s the fucking flag. Welp.


This challenge was presented as a Python file, which ran remotely. You can download this here.

Inspecting the file, we note that the application acts as an oracle: that is, you can use it to sign a pre-constructed string (via the “Order” functionality), and then test if any string has a valid signature (via the “Pay” functionality). If we are able to correctly sign a querystring with “product=Flag” and “price=<less than our monies>”, we win.

We note the signature is constructed via the following function:

sha256(key + message)

This is affected by a hash length extension attack, where we’re able to construct a new, valid signature which appends an arbitrary string to the old signature.

In this case, it doesn’t matter what we append, as long as it ends with “&product=Flag&price=4”.

The only restriction is that in order to conduct this attack, we must know the length of “key”: but fortunately, the program limits this to range(8,32), and we are able to brute force.

You can download the Python script I used for this here.

I struggled for a while to get Python to exit properly (that is, for pwntools.recvuntil() to handle cases where the target string is received, and where a flag is printed and there is no target string), so I ended up using Wireshark to grab the flag:

In the next post, I will discuss the babyre and numbers game challenges.

Posted in Bards, Computers, Jesting | Leave a comment

Writeups – ELF Crumble (DEFCON Quals)

In the past weekend, I participated in the DEFCON Quals CTF. I was able to solve three challenges, and I will present writeups for one challenge – I lost another through poor record-keeping, and the third, Eval Whitelisting, is not conductive to a writeup (the solution was to wrap ../flag in backticks in a printf).

ELF Crumble

The ELF Crumble challenge was presented as an archive file, containing pieces of an ELF executable, as well as the file “broken”, containing the executable’s “shell”. You can download the files here.

We begin our investigation with the “broken” file, as it seems to be a valid ELF executable. We can immediately see the problem:

We note that several “core” functions are like this, including f1, f2, f3 and recover_flag. Strings doesn’t reveal anything immediately obvious (and fair enough).

Fortunately, symbols are left intact in the application, giving us the (possible) length of each function. We can also make three assumptions:

  • Firstly, each function will begin with a resonable prologue, such as setting up the stack. No function will begin with some hand-crafted prologue.
  • Secondly, each function will end with a reasonable epilogue, such as a return instruction. No function will end with something odd like a jump.
  • Thirdly, the function fragments will “fit tightly” with one another. There are no overlaps, there are no overwritten sections, there are no gaps where “pop eax” is the actual instruction. This correlates with the file lengths of the chunks.

Following this guidance, we know that only one chunk can possibly fit into the first chunk, f1, and have the function look somewhat reasonable:

From here, I wrote a quick capstone-powered disassembler to show me the first few bytes of each chunk, and quickly reassembled the executable by hand, giving me the flag. You can find the Python script used to disassemble the chunks here, and the final executable here.

I’d like to thank the DEFCON CTF organisers for a well put-together and challenging CTF. Getting rekt each time in this CTF is a good reminder that there are always greater heights to climb, no matter how much we have achieved so far.

At this point, I would like to take a moment to reflect – in the past few weeks, I am delighted to see more and more talented people throwing themselves into the mix and challenging themselves in various ways – not only in CTF’ing, but in tackling various self–sought projects and tasks. With this, comes more people to discuss this work and collaborate with – this brings a modicum of heartfelt joy between the hours of 9am and 5pm.

For those of you who want to get into CTF’ing, there is no better time than now. For those of you sitting on the sidelines, know that there is no progress without sacrifice – try, try again, and never give up. For those of you who have settled and stagnated, satisfied that you know enough to do your jobs and it does not require more: may you find happiness in your own way, living your own life with whatever meaning and purpose you see fit.

Posted in Bards, Computers, Jesting | Leave a comment