11 - Addis Ababa
There is no login function, everything is done in the main so we cannot smash the stack to control the execution. Our attack point is at 447C: here there is a call to printf for which we can forge a string format attack. Looking a few instructions ahead, we can see that, when calling the printf, at SP+2 there is the flag that is return by test_password_valid, so we need a way to modify it. Reading the specification of this printf, passing the "%n" token takes the argument as an address in which to write the number of characters already printed. Let's take a closer look to the stack:- SP+0: address of the format string (=SP+4)
- SP+2: flag (=0x00)
- SP+4: format string (=our input)
SP+2 (little endian) + %x%n
When printf is called, it will print 2 characters (those of SP+2), then it will parse %x and do nothing because SP+2 is 0x00 and finally, parsing %n, it will write 2 (the number of bytes printed) in the address specified in SP+4, that is in SP+2