writeups

A collection of CTF challenge writeups.

View on GitHub

lambdastic

I heard you liked monads.

This was my 2nd favorite challenge out of this CTF. There may be some personal bias going on, as I am a huge fan of FP and Haskell in particular. I wouldn’t say this challenge was a walk in the park, but I can’t say I’ve struggled with it.

What the F are monads!?

Ah yes, the age old question no one can actually explain. I am not going to attempt it either, sorry. But no need to worry, the challenge itself isn’t actually that difficult. So let’s dive in!

First impressions

Once you open the binary in dnSpy and head over to the Main method, you will see that the program expects you to input some number, then it runs through this… blackbox Wait wtf is this? Let’s just ignore that for now and assume this is some sort of “black box”. So after the input ran through that, it is used as an AES key to decrypt some data, which is probably the flag.

decrypt

Uncovering the mystery

Looking at the “stuff” in the Lambdastic.Monads.* namespaces, we can see that there 4 “categories”, we are going to break them down in the order of easiest to hardest:

Unit

There is nothing special about this. It is basically like void, except it can be used as a “value” (in other words, it can be used as an expression).

Taste

Spice

This is just a list implementation, but not an ordinary one. It is pretty much copied from Haskell, where lists are fully immutable and are “built from” heads and tails (they are more comparable to linked lists, than arrays). But again, I might have recognized this pretty quickly based on the name of the parameters of a helper method, but not everyone is familiar with FP.

head & tail

So let’s break this down, shall we?

Fruit

This is a bit more complex, represents expressions. There are 5 types in this namespace, so let’s break it down;

Whew, where were we?

Ah right, let’s now dissect the “black box”!