목록Hack/DreamHack(로드맵) (94)
CIDY

int main() { return 0; } 간단한 코드를 디버깅해보자. 리턴하기전에 브레이크 걸고 ret내부로 들어가봤다. 당연하게도 거기엔 __libc_start_main이 있다. 그리고 __GI_exit가 있는데, 그 안으로 또 가 보면 __exit_func라는 함수를 호출한다. void attribute_hidden __run_exit_handlers (int status, struct exit_function_list **listp, bool run_list_atexit, bool run_dtors) { const struct exit_function *const f = &cur->fns[--cur->idx]; switch (f->flavor) { void (*atfct) (void); void..

// 64-bit, canary, nx, partial relro #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 read_len; } read_len ++; } return read_len; } void ..

#define THREAD_COPY_STACK_GUARD(descr) \ ((descr)->header.stack_guard \ = THREAD_GETMEM (THREAD_SELF, header.stack_guard)) int __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) { ... #ifdef THREAD_COPY_STACK_GUARD THREAD_COPY_STACK_GUARD (pd); #endif /* Copy the pointer guard value. */ #ifdef THREAD_COPY_POINTER_GUARD THREAD_COPY_..

// gcc -o master master.c -pthread // 64-bit, canary, nx, partial relro #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[2..
SSP에 대해서는 진작 배웠고 그걸 이용한 다양한 문제도 풀어보았다. 근데 기초만 배운 거였다고 한다. 스택 카나리의 값은 Thread Local Storage (TLS)에 존재한다. 여기서는 TLS, 그리고 카나리가 언제 어디서 할당되는지 알아보도록 하자. *Tread Local Storage TLS는 스레드의 저장공간이다. text영역, data영역, bss영역 등 목적에 의해 할당된 섹션들에서 데이터를 관리함을 알 것이다. 이와는 달리 TLS영역은 스레드의 전역 변수를 저장하기 위한 공간으로, 로더에 의해 할당된다. static void * init_tls (void) { /* Construct the static TLS block and the dtv for the initial thread. F..

// gcc -o seccomp seccomp.cq // 64-bit, canary, nx, partial relro #include #include #include #include #include #include #include #include #include #include #include #include int mode = SECCOMP_MODE_STRICT; 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); } int sys..

#include #include #include #include #include #include #include #include #include #include #include #define DENY_SYSCALL(name) \ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __NR_##name, 0, 1), \ BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_KILL) #define MAINTAIN_PROCESS BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW) #define syscall_nr (offsetof(struct seccomp_data, nr)) #define arch_nr (offsetof(struct seccomp_da..

*Bypass SECCOMP 개발자가 모든 시스템 콜울 숙지하고 있는 것은 아니기에, 보안은 완벽할 수 없고 상황에 따라 여러 우회 방법이 존재한다. -타 시스템 콜 호출 : open을 막아뒀다면, 같은 기능을 수행하는 openat를 이용할 수 있음 -Application Binary Interface (ABI) : 아키텍쳐별로 명령어 세트와 기능, 크기 등이 다르고 시스템 콜 번호도 다르다. -> 서로 다른 아키텍쳐를 호환하기 위한 코드를 이용해 우회할 수 있다. // 64-bit, nx, pie, full relro #include #include #include #include #include #include #include #include void init() { setvbuf(stdin, 0, ..