
[DreamHack System Hacking] Linux Library exploit > _rtld_global
2022. 9. 20. 20:52
DreamHack/SystemHacking
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฝ๋๋ฅผ ๋ถ์ํ๋ฉด์ ์ด๋ค ๋ฐฉ์์ผ๋ก ํ๋ก์ธ์ค๋ฅผ ์ข
๋ฃํ๋์ง ์์๋ณด์. _rtld_global ์ค์ต ์์ // Name: rtld.c // Compile: gcc -o rtld rtld.c int main() { return 0; } ๋ค์์ ์ฝ๋๋ ์ข
๋ฃํ๋ ๊ณผ์ ์ ์์๋ณด๊ธฐ ์ํ ์์ ์ฝ๋์ด๋ค. _rtld_global __Gl_exit ์์ ์ปดํ์ผ ํ ์์ ์ฝ๋๋ ๋ณ๋ค๋ฅธ ์ฝ๋๋ฅผ ์คํํ์ง ์๊ณ ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํ๋ค. ๋๋ฒ๊น
์ ํตํด ๋ ์์ธํ ์์๋ณด์. main ํจ์ ๋ด์ ๋ฆฌํดํ๋ ๋ช
๋ น์ด์ ๋ธ๋ ์ดํฌ ํฌ์ธํธ๋ฅผ ์ค์ ํ๋ค. step into (si)๋ฅผ ํตํด ๋ค์ ์ฝ๋๋ฅผ ํ์ธํ๋ค. ๋๋ฒ๊น
๊ฒฐ๊ณผ๋ฅผ ํ์ธํด๋ณด๋ฉด, main ํจ์ ๋ด์์ ๋ฆฌํด ๋ช
๋ น์ด๋ฅผ ์คํํ์ ๋ ์คํ ์ต์๋จ์ ์๋ __libc_start_main+231 ..

[DreamHack System Hacking] master_canary
2022. 9. 19. 22:05
DreamHack/SystemHacking
๋ฌธ์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค. // gcc -o master master.c -pthread #include #include #include #include #include char *global_buffer; 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(60); } void get_shell() { system("/bin/sh"); } void *thread_routine() { char buf[256]; global_buffer = b..

[DreamHack System Hacking] Master Canary - (2)
2022. 9. 19. 21:54
DreamHack/SystemHacking
๋ฌธ์ ์ฝ๋ // Name: mc_thread.c // Compile: gcc -o mc_thread mc_thread.c -pthread -no-pie #include #include #include #include void giveshell() { execve("/bin/sh", 0, 0); } void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } int read_bytes (char *buf, int len) { int idx = 0; int read_len = 0; for (idx = 0; idx < len; idx++) { int ret; ret = read(0, buf+idx, 1); if (ret < 0) { return rea..

[DreamHack System Hacking] Master Canary - (1)
2022. 9. 19. 18:44
DreamHack/SystemHacking
์ค์ต ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค. // Name: mc_thread.c // Compile: gcc -o mc_thread mc_thread.c -pthread -no-pie #include #include #include #include void giveshell() { execve("/bin/sh", 0, 0); } void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } void thread_routine() { char buf[256]; int size = 0; printf("Size: "); scanf("%d", &size); printf("Data: "); read(0, buf, size); } int main() { pthread_..

[DreamHack System Hacking] Master Canary
2022. 9. 19. 17:06
DreamHack/SystemHacking
Thread Local Storage Thread Local Storage (TLS)๋ ๋ช
์นญ ๊ทธ๋๋ก ์ค๋ ๋์ ์ ์ฅ ๊ณต๊ฐ์ ์๋ฏธํ๋ค. ELF ๋ฐ์ด๋๋ฆฌ๋ฅผ ์ดํด๋ณด๋ฉด, ๊ฐ๊ฐ์ ๋ชฉ์ ์ ๊ฐ์ง ์น์
์์ ๋ฐ์ดํฐ๋ฅผ ๊ด๋ฆฌํ๋ค. ์ฝ๋๋ฅผ ์คํํ๊ธฐ ์ํ .text, ์ด๊ธฐํ๋์ง ์์ ์ ์ญ ๋ณ์๋ฅผ ์ํ .data๋ฑ์ ์์๋ก ๋ค ์ ์๋ค. TLS ์์ญ์ ์ด์ ๋ฌ๋ฆฌ ์ค๋ ๋์ ์ ์ญ ๋ณ์๋ฅผ ์ ์ฅํ๊ธฐ ์ํ ๊ณต๊ฐ์ผ๋ก, ๋ก๋(Loader)์ ์ํด ํ ๋น๋๋ค. ๋ค์์ ๋ก๋์์ TLS ์์ญ์ ํ ๋นํ๊ณ ์ด๊ธฐํํ๋ ํจ์์ธ init_tls์ ์ฝ๋์ด๋ค. static void * init_tls (void) { /* Construct the static TLS block and the dtv for the initial thread. For some pla..

[System Hacking] 2์ฃผ์ฐจ dreamhack stage 12 - (5)
2022. 5. 1. 22:46
DreamHack/SystemHacking
[ํผ์์ค์ต] Double Free Bug tcache_dup ์ฃผ์ด์ง c์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค // gcc -o tcache_dup tcache_dup.c -no-pie #include #include #include #include char *ptr[10]; void alarm_handler() { exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(60); } int create(int cnt) { int size; if(cnt > 10) { return -1; } printf("Size: "); scanf("%d"..

[System Hacking] 2์ฃผ์ฐจ dreamhack stage 12 - (4)
2022. 5. 1. 20:24
DreamHack/SystemHacking
[ํผ์์ค์ต] Double Free Bug Tcache_dup2 ์ฃผ์ด์ง c ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค. #include #include #include #include char *ptr[7]; void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); } void create_heap(int idx) { size_t size; if( idx >= 7 ) exit(0); printf("Size: "); scanf("%ld", &size); ptr[idx] = malloc(size); if(!ptr[idx]) exit(0); printf("Data: "); read(0, ptr[idx], size-1); } void mo..

[System Hacking] 2์ฃผ์ฐจ dreamhack stage 12 - (3)
2022. 4. 30. 19:40
DreamHack/SystemHacking
Tcache Poisoning ์ฃผ์ด์ง c ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค. // Name: tcache_poison.c // Compile: gcc -o tcache_poison tcache_poison.c -no-pie -Wl,-z,relro,-z,now #include #include #include int main() { void *chunk = NULL; unsigned int size; int idx; setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); while (1) { printf("1. Allocate\n"); printf("2. Free\n"); printf("3. Print\n"); printf("4. Edit\n"); scanf("%d", &idx); sw..