Buffer Overflow to call a function

3

I'm new to c and have been learning a small bit about buffer overflow, I have been trying to buffer overflow to call a function but can't see to get it to work.

void secret()
{
    printf("well done");

 }

int main(int argc, char **argv)
{
  char buffer[40];

   gets(buffer);
   printf( "Your input is:" );
   printf( buffer );

} 

disass secret
Dump of assembler code for function secret:
   0x0000054d <+0>:     push   ebp
   0x0000054e <+1>:     mov    ebp,esp
   0x00000550 <+3>:     push   ebx
   0x00000551 <+4>:     call   0x5b5 <__x86.get_pc_thunk.ax>
   0x00000556 <+9>:     add    eax,0x1a7e
   0x0000055b <+14>:    lea    edx,[eax-0x1994]
   0x00000561 <+20>:    push   edx
   0x00000562 <+21>:    mov    ebx,eax
   0x00000564 <+23>:    call   0x3d0 <printf@plt>
   0x00000569 <+28>:    add    esp,0x4
   0x0000056c <+31>:    nop
   0x0000056d <+32>:    mov    ebx,DWORD PTR [ebp-0x4]
   0x00000570 <+35>:    leave  
   0x00000571 <+36>:    ret

so starting address on function 2 is 0x0000054d so i can use :

run $(python -c 'print "C"*20 + "\x4d\x05"')

but my problem is how do i figure out how to buffer override by input to return address of secret function.

c
assembly
buffer-overflow
exploit
shellcode
asked on Stack Overflow Oct 15, 2019 by John • edited Oct 15, 2019 by Peter Cordes

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0