Tags: misc miscellaneous 

Rating:

Looking at the data we get:

```
(dp0
I1
S'D'
p1
sI2
S'UCTF'
p2
sI3
S'{'
p3
sI4
I112
sI5
S'}'
p4
sI24
S"I know that the intelligence agency's are onto me so now i'm using ways to evade them: I am just glad that you know how to use pickle. Anyway the flag is "
p5
s.
```

So it looks like the middle bits between the `S'{'` and `S'}'` were about where the flag would sit. We weren’t sure what to do with this, but with the line `how to use pickle` and the obfuscation note from the challenge description, we did some Googling around obfuscation and `pickle`.

[`pickle` is a Python library](https://docs.python.org/3/library/pickle.html) used to (de-)serialize Python objects, where the objects are turned into bytestreams and vice-versa. However, this didn’t really help us until we found [this StackOverflow question](https://stackoverflow.com/questions/41005412/how-to-turn-pickle-output-into-an-unreadable-format)

>Heres [sic] a snippet from a save file i created with pickle (it’s a game):

>S’Strength'

>p4

>I5

>sS

>’Health'

>p8

>I100

Where the data was structured almost exactly like ours! That’s when we realised we’d been data that had been pickled, i.e. been the result of `pickle.dumps()`, which means all we had to do was run the reverse:

```
import pickle

with open('data', 'r') as f:
read_data = f.read()
print(pickle.loads(bytes(read_data, 'utf-8')))
```

This then spat out:

```
{1: 'D', 2: 'UCTF', 3: '{', 4: 112, 5: 49, 6: 99, 7: 107, 8: 108, 9: 51,
10: 95, 11: 121, 12: 48, 13: 117, 14: 82, 15: 95, 16: 109, 17: 51, 18: 53,
19: 53, 20: 52, 21: 103, 22: 51, 23: '}', 24: "I know that the
intelligence agency's are onto me so now i'm using ways to evade them: I
am just glad that you know how to use pickle. Anyway the flag is "}
```
Which strings together:

`DUCTF{112499910710851951214811784951095153535210351}`
Which is still not really the flag. Using [an ASCII table](http://www.asciitable.com/) for reference, we can then reference the ASCII values and convert each letter to create the flag.

**Flag**: `DUCTF{p1ckl3_y0uR_m3554g3}`
**Tools**: Python (`pickle`), [ASCII table](http://www.asciitable.com/)

Original writeup (https://joyce.fyi/posts/ductf-2020/#in-a-pickle).