Finding Output

For this challenge we'll be exploring until a state has a certain string in stdin. The binary is 02_angr_find_condition. We'll start by opening the binary and running some basic analysis.

shell@shell:~/github/r2angr/docs/challenges$ r2 02_angr_find_condition 
 -- Check your IO plugins with 'r2 -L'
[0x08048450]> aa
[x] Analyze all flags starting with sym. and entry0 (aa)
[0x08048450]> s main
[0x080485c8]>

The CFG for the main function is, once again, very large, so I recommend you avoid graph mode. We can see from scrolling through the function in visual mode that again it gets user input from stdin, calls sym.complex_function, and then there is a large branching structure with various success/fail prints. Without investigating much futher, we already know we want it to print "Good Job.", so let's try exploring until we find that. First though, let's add hooks to all functions that print a debug statement so we can trace what's happening during exploration. We can add the hooks as shown below.

[0x08048778]> Mhf
[R2ANGR] Importing angr
[R2ANGR] Loading r2angr
[R2ANGR] Initialized r2angr at entry point
[HOOKS] Hooking function: entry0 at 0x8048450
[HOOKS] Hooking import: sym.imp.__libc_start_main at 0x8048420
[HOOKS] Hooking function: sym.deregister_tm_clones at 0x8048490
[HOOKS] Hooking function: sym.register_tm_clones at 0x80484c0
[HOOKS] Hooking function: sym.__do_global_dtors_aux at 0x8048500
[HOOKS] Hooking function: entry.init0 at 0x8048520
[HOOKS] Hooking function: sym.__libc_csu_fini at 0x804d2f0
[HOOKS] Hooking function: sym.__x86.get_pc_thunk.bx at 0x8048480
[HOOKS] Hooking function: sym.complex_function at 0x8048569
[HOOKS] Hooking function: sym._fini at 0x804d2f4
[HOOKS] Hooking function: sym.__libc_csu_init at 0x804d290
[HOOKS] Hooking function: main at 0x80485c8
[HOOKS] Hooking function: sym.print_msg at 0x804854b
[HOOKS] Hooking import: sym.imp.printf at 0x80483e0
[HOOKS] Hooking function: sym._init at 0x8048394
[HOOKS] Hooking import: sym.imp.strcmp at 0x80483d0
[HOOKS] Hooking import: sym.imp.__stack_chk_fail at 0x80483f0
[HOOKS] Hooking import: sym.imp.puts at 0x8048400
[HOOKS] Hooking import: sym.imp.exit at 0x8048410
[HOOKS] Hooking import: sym.imp.__isoc99_scanf at 0x8048430
[0x08048450]>

Then we can explore until a state has "Good Job" in stdout as shown below.

Our hooks give us some idea of what was happening during this exploration. We can then list the remaining states with the Msl command.

We have two active states, let's see what is in stdout for each one using the Mso command.

Looks like the first one failed, we'll kill it with the Msk command.

Now we'll list the stdin for the final state as shown below.

Let's try this password on the binary.

Last updated

Was this helpful?