Skip to content

Commit 2b4441c

Browse files
committed
Added jit in my pants writeup
1 parent 9f7a86e commit 2b4441c

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Jit in my pants (reversing, 3 points, 38 solves)
2+
Because reversing an obfuscated jit'ed virtual machine for 3 points is fun!
3+
4+
In this task we got an ELF binary. Looking at it's disassembly was really hard - lots
5+
of obfuscated code was put there - I thought that for 3 points we were supposed to use
6+
something easier.
7+
8+
Tracing the binary, we notice a lot of `gettimeofday` calls. This was a function checking
9+
current time - something which should not be present in legitimate key checking code.
10+
I created a simple replacement function (`tofd.c`), which I then LD_PRELOAD'ed to achieve
11+
deterministic execution.
12+
13+
In my solution, I used instruction counting to get the flag. The idea is, that the code
14+
checks flag characters one by one, exitting early if a character is wrong. We can exploit
15+
this - when we supply a good prefix of the flag, the binary will execute slightly longer
16+
than with a wrong one. Using `doit.py` and Intel's pin, we brute forced the solution
17+
one char at a time in around an hour (this could take shorter time, but I wanted to stay
18+
on the safer side and used `string.printable` as the character set).
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import subprocess, string, sys, os
2+
3+
alphabet=string.printable
4+
5+
def get_ic(s):
6+
subprocess.check_output(["/bin/bash", "ins", s]) # ins is my alias for intel pin's instructioon counting tool.
7+
return int(open("inscount.out").read()[5:])
8+
9+
key="BKPCTF{"
10+
while True:
11+
longest=0
12+
longest_for=""
13+
for c in alphabet:
14+
print repr(c),
15+
sys.stdout.flush()
16+
n=get_ic(key+c)
17+
if n>longest:
18+
longest=n
19+
longest_for=c
20+
print "!!!",
21+
key=key+longest_for
22+
print key
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
struct timeval{
2+
long long tv_sec;
3+
int tv_usec;
4+
};
5+
struct timezone{};
6+
int gettimeofday(struct timeval *tv, struct timezone *tz){
7+
static int x=0;
8+
static int y=0;
9+
tv->tv_sec=x++;
10+
tv->tv_usec=y++;
11+
return 0;
12+
}

0 commit comments

Comments
 (0)