master_canary
·
Wargame/Dreamhack
1. intro 2. code 및 분석 2.1 code // 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]; g..
Master Canary
·
Wargame/Dreamhack
1. intro 2. code & 분석 // 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 <..
보호 기법 및 공격 시나리오 요약
·
Tips & theory
Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled ASLR 개념 흔히들 말하는 random stack. 즉, heap, stack 영역의 base address를 랜덤하게 바꾸는 방법. 공격 방법 최선은 memory leak이며, 특정 memory address를 알 수 있다면 각 변수나 함수의 address는 offset 만큼 떨어진 곳에 위치하기에 이를 통해 exploit이 가능해진다. brute force, 즉 될때까지 시도해보는 방법. 32bit던 64bit던 특정 함수나 변수의 위치가 어느정도 고정되어있기에 이를 기반으로 지속적으로 시도해보는 방법이며, nop sled와 함께 성공률..
Return to Library
·
Wargame/Dreamhack
// Name: rtl.c // Compile: gcc -o rtl rtl.c -fno-PIE -no-pie #include #include const char* binsh = "/bin/sh"; int main() { char buf[0x30]; setvbuf(stdin, 0, _IONBF, 0); setvbuf(stdout, 0, _IONBF, 0); // Add system function to plt's entry system("echo 'system@plt"); // Leak canary printf("[1] Leak Canary\n"); printf("Buf: "); read(0, buf, 0x100); printf("Buf: %s\n", buf); // Overwrite return addr..
Return to Shellcode
·
Wargame/Dreamhack
#include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } int main() { char buf[0x50]; init(); printf("Address of the buf: %p\n", buf); printf("Distance between buf and $rbp: %ld\n", (char*)__builtin_frame_address(0) - buf); printf("[1] Leak the canary\n"); printf("Input: "); fflush(stdout); read(0, buf, 0x100); printf("Your input is '%s'\n", buf); puts("[2] Overwrite ..
ssp_001
·
Wargame/Dreamhack
이번 문제는 SSP 방어기법, 즉 canary가 보호기법으로 걸려있는 문제이다. 이를 우회하기위해서는 memory leak이 발생한다면 이를 활용해서 canary를 확인하는 방법이 최선이며, 그게 아니라면 브루트포싱해야한다. 코드를 조금 분석해보자. #include #include #include #include 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 get_shell() { system("/bin/sh");..