A walkthrough of the Bit Puzzle challenge from picoCTF.

My code

This is a challenge where you are suppose to reverse the equations applied to the supplied input and figure out what the original input should be.

However, if you do not feel like doing math, you can use angr to solve it for you using symbolic execution. Here is my python script that solves it in less than a minute.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python

import angr

def basic_symbolic_execution():
    p = angr.Project('bitpuzzle')
    
    main = 0x80484e4
    find = 0x80486ab
    avoid = list((0x8048562, 0x80486c1))
    
    init = p.factory.blank_state(addr=main)
    
    print("Launching exploration")
    pg = p.factory.path_group(init, threads=8)
    ex = pg.explore(find=find, avoid=avoid)

    # Get stdout
    final = ex.found[0].state
    flag = final.posix.dumps(0)
    print("Flag: {0}".format(flag))
    

def test():
    pass    

if __name__ == '__main__':
    basic_symbolic_execution()

enjoy