-00000028 ; D/A/* : change type (data/ascii/array) -00000028 ; N : rename -00000028 ; U : undefine -00000028 ; Use data definition commands to create local variables and function arguments. -00000028 ; Two special fields " r" and " s" represent return address and saved registers. -00000028 ; Frame size: 28; Saved regs: 4; Purge: 0 -00000028 ; -00000028 -00000028 db ? ; undefined -00000027 db ? ; undefined -00000026 db ? ; undefined -00000025 db ? ; undefined -00000024 db ? ; undefined -00000023 db ? ; undefined -00000022 db ? ; undefined -00000021 db ? ; undefined -00000020 db ? ; undefined -0000001F db ? ; undefined -0000001E db ? ; undefined -0000001D db ? ; undefined -0000001C db ? ; undefined -0000001B db ? ; undefined -0000001A db ? ; undefined -00000019 db ? ; undefined -00000018 db ? ; undefined -00000017 db ? ; undefined -00000016 db ? ; undefined -00000015 db ? ; undefined -00000014 var_14 db ? -00000013 db ? ; undefined -00000012 db ? ; undefined -00000011 db ? ; undefined -00000010 db ? ; undefined -0000000F db ? ; undefined -0000000E db ? ; undefined -0000000D db ? ; undefined -0000000C s2 dd ? ; offset -00000008 db ? ; undefined -00000007 db ? ; undefined -00000006 db ? ; undefined -00000005 db ? ; undefined -00000004 db ? ; undefined -00000003 db ? ; undefined -00000002 db ? ; undefined -00000001 db ? ; undefined +00000000 s db 4 dup(?) +00000004 r db 4 dup(?) +00000008 arg_0 dd ? +0000000C +0000000C ; end of stack variables
Variable v4 is 8 bytes, so the memcpy(&v4, &input, a1) will overflow. It can overwrite the saved registers of the stack of auth(), which is the EBP of main().
In assember, when a function return to the function caller, it will:
1 2 3
mov esp, ebp pop ebp pop eip
We can’t directly control the EIP, because the max size of input is 12, but we can construct a fake stack, then let the EBP of main() function to our fake stack. When the main() returns, it will jmp to the function we specify.
The correct() address is 0x0804925F, the input address is 0x0811EB40.
Fake stack: (The correct() will check the first 4 bytes of input, so it should be 0xdedabeef.)