Fu Challenge #1 taken apart h4z4rd [memearser@yahoo.com] 0x1 [intro] 0x2 [quick_hack] 0x3 [decompilation] 0x4 [analysis] 0x5 [conclusion] 0x1 [intro] In Fu#1 we got a binary and are supposed to make it print "Hurray! You win!", and it was up to us to decide how to do it. I decided it would be a good idea to decompile binary and to see how it looks like in C because it would give me better understanding of the algorithm used to generate hash, and could reuse the code for decryptor. Plus it will be a good excersise ;) Tools used to solve this challange where lida, gdb, ht, ida, and calculator. 0x2 [quick_hack] The fastest method to solve this level is to patch the binary. One of the best places to patch it would be at the end of main where it checks if the return value of function is 1 and prints the string or jumps to exit. (gdb) x/5i 0x804880b 0x804880b: test %eax,%eax 0x804880d: je 0x804881b *** < nop out 0x804880f: movl $0x80489a5,(%esp) 0x8048816: call 0x8048338 0x804881b: leave *** 0x804881c: ret So what we do is just replace that jump with nops, and whatever the result from function is it will print Hurray. We patch it with ht and observer the result: [hazard: 1]$ ./edited h4z4rd 6070;<8<;<6<08 Hurray! You win! So lets move on to the c00l part. 0x3 [decompilation] The decompilation proces was done in three steps. First quick analysis with lida to see roughly what is happening. Second was commenting gdb asm dump of executable. And third was rewriting executable in C. Second step is not necessary but allows for quickier recovery of source, because everything is allready written in pseudo code, and it just has to be translated into C. Decompilation process will not be explained in detail because it will take too much time, and there are some good tutorials on that topic on the internet. Libc functions were identified with the help of ida. They were strcpy (for someone to exploit the program), printf and exit. User defined functions were given names function 1-5. First four functions are used to mutate user string, and last one is used to compare user sting with the hardcoded one. Source code is locatet at the end of the article. If you didn't understand some asm portiton of code well you can extract it from source and study. 0x4 [analysis] The program has 3 buffers used to store mutated strings each used for different computation. Function1 is the first one to perform mutation of user string. It first substracts 0x20 from each character, then it adds hardcoded value 0x2a, then it substracts from character (((((buf1[i]/0x2)*0xaf)/0x100)/0x20)*0x5e)). This line is very interesting because it gave me some troubles when reversing crypto algorithm. In some cases it will have value greater than 255 (1byte) and thus go into negative. So in the decrypt function looks like this: for(i=0;i #include #include void function1(char *buf1, int len, int num) { int i; for(i=0;i> 0x4)& 0xf)+ 0x30); } buf2[len*2+1]=0x0; } void decrypt(char *str, int len) { int i=0,j=0,k=0; char buf[50], buf2[50]; unsigned char tmp1, tmp2; unsigned char a,b,c; memset(buf,0,sizeof(buf)); memset(buf2,0,sizeof(buf2)); for(i=0;i\n",argv[0]); exit(0); } strcpy(buffer1,argv[1]); function1(buffer1, strlen(buffer1), 0x2a); function2(buffer1, strlen(buffer1)); function3(buffer1, buffer2, strlen(buffer1), 0x3); function4(buffer2, buffer3, strlen(buffer2)); printf("%s\n",buffer3); decrypt(pass, strlen(pass)); decrypt(name, strlen(name)); if (function5(buffer3, string, strlen(buffer3))) printf("Hurray! You win!\n"); }