bof - 5 pt

Nana told me that buffer overflow is one of the most common software vulnerability. Is that true?

Download : http://pwnable.kr/bin/bof Download : http://pwnable.kr/bin/bof.c

Running at : nc pwnable.kr 9000

bof.c 파일 내용은 아래와 같다.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
	char overflowme[32];
	printf("overflow me : ");
	gets(overflowme);	// smash me!
	if(key == 0xcafebabe){
		system("/bin/sh");
	}
	else{
		printf("Nah..\n");
	}
}
int main(int argc, char* argv[]){
	func(0xdeadbeef);
	return 0;
}

bof 파일의 func() 를 gdb로 분석하면 아래와 같다.

4개의 call 이 있는데, 각각 printf() , gets() , system(), printf() 라고 추측하였다.

이를 통해 overflowmekey 의 위치를 알 수 있다.

아래 코드를 통해 overflowmeebp - 0x2c 에 위치함을 알 수 있다.

아래 코드를 통해 keyebp + 0x08 에 위치함을 알 수 있다.

0x08은 dec으로 8이고, 0x2c는 dec으로 44이므로 52byte의 패딩으로 overflow가 가능하다.

Last updated

Was this helpful?