목록전체 글 (243)
CIDY

// Name: ow_rtld.c // Compile: gcc -o ow_rtld ow_rtld.c // 64-bit, canary, nx, pie, full relro #include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } int main() { long addr; long data; int idx; init(); printf("stdout: %p\n", stdout); while (1) { printf("> "); scanf("%d", &idx); switch (idx) { case 1: printf("addr: "); scanf("%ld", &addr); printf("data: "); scanf("%l..

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..