Baby Website Rick

Analysis

All the references to pickles implies it's an insecure deserialization challenge. pickle is a serialization format used in python.

If we check the cookies, we get the following:

Our guess is that this is a pickled python object, and decoding the base64 seems to imply that to us too:

Unpickling

Let's immediately try to unpickle the data, which should give us a feel for how data is parsed:

The error is quite clear - there's no anti_pickle_serum variable. Let's add one in and try again.

That error is fixed, but there's another one:

Here it's throwing an error because X (anti_pickle_serum) is not a type object - so let's make it a class extending from object!

And now there's no error, and we get a response!

So the cookie is the pickled form of a dictionary with the key serum and the value of an anti_pickle_serum class! Awesome.

Exploitation

For an introduction to pickle exploitation, I highly recommend this blog post. Essentially, the __reduce__ dunder method tells pickle how to deserialize, and to do so it takes a function and a list of parameters. We can set the function to os.system and the parameters to the code to execute!

Here we create the malicious class, then serialize it as part of the dictionary as we saw before.

Huh, that looks nothing like the original cookie value (which starts with KGRwMApTJ3)... maybe we missed something with the dumps?

Checking out the dumps() documentation, there is a protocol parameter! If we read a bit deeper, this can take a value from 0 to 5. If we play around, protocol=0 looks similar to the original cookie:

Let's change the cookie to this (without the b''):

As you can see now, the value 0 was returned. This is the return value of os.system! Now we simply need to find a function that returns the result, and we'll use subprocess.check_output for that.

Now run it

And input it as the cookie.

As can now see that there is a flag_wIp1b file, so we can just read it!

While it's tempting to do

subprocess.check_output requires a list of parameters (as we see here) and the filename is a separate item in the list, like so:

And boom - we get the flag!

HTB{g00d_j0b_m0rty...n0w_I_h4v3_to_g0_to_f4m1ly_th3r4py..}

Last updated

Was this helpful?