bof

System Hacking Advanced

[dreamhack] Master Canary

Master Canary└─# checksec mc_thread[*] '/root/dream/Master Canary/mc_thread' Arch: amd64-64-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x400000)SSP가 적용됐다. 카나리를 bypass하는 문제라고 예상할 수 있다. 코드를 분석해보자.#include #include #include #include void giveshell() { execve("/bin/sh", 0, 0); }int main() { pthread_t thread_t; if (pthread_create(..

System Hacking Advanced

[dreamhack] sint

문제풀이#include #include #include #include void get_shell(){ system("/bin/sh");}int main(){ char buf[256]; int size; initialize(); signal(SIGSEGV, get_shell); printf("Size: "); scanf("%d", &size); if (size > 256 || size buf[256], size 선언size를 입력 받고 buf 범위를 벗어나는 size인 경우에는 exit(0) 실행범위를 벗어나지 않는 경우는 size-1 크기의 입력을 받고 buf에 저장size에 대한 검증이 존재하므로 BOF가 불가능해보인다. 진짜 불가능할까?if (size > ..

System Hacking Advanced

[dreamhack] basic_exploitation_003

문제분석void get_shell() { system("/bin/sh");}int main(int argc, char *argv[]) { char *heap_buf = (char *)malloc(0x80); char stack_buf[0x90] = {}; initialize(); read(0, heap_buf, 0x80); sprintf(stack_buf, heap_buf); printf("ECHO : %s\n", stack_buf); return 0;}read(0, heap_buf, 0x80)로 stack_buf 입력을 0x80 바이트만 받는다. 즉, stack_buf에서 BOF가 발생하지 않는다. sprintf(stack_buf, heap_buf);하지만 입..

System Hacking Advanced

[dreamhack] Return to Shellcode

checksec└─# checksec r2s[*] '/root/dream/rts/r2s' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX disabled PIE: PIE enabled RWX: Has RWX segmentsNX 보호기법이 적용되지 않았다. 따라서 쉘코드를 이용한 공격이 가능하다. 문제분석 & 풀이int main() { char buf[0x50]; init(); printf("Address of the buf: %p\n", buf); printf("Distance between buf and $rbp: %ld\n",(char*)__bu..

System Hacking Advanced

[dreamhack] ssp_001

SSP(Stack Smashing Protector) SSP(Stack Smashing Protector)SSP는 BOF를 방어하기 위한 보호기법 중 하나로 함수를 실행할 때, canary라는 랜덤 값을 스택에 추가하여 BOF로 스택 데이터가 변조됐는지 확인하는 방법이다. canary가 변조된 경우는 스택 데이터가keyme2003.tistory.com #include #include #include #include void get_shell() { system("/bin/sh");}void print_box(unsigned char *box, int idx) { printf("Element of index %d is : %02x\n", idx, box[idx]);}void menu() { ..

System Hacking Advanced

[dreamhack] Return Address Overwrite

문제분석 & 풀이void get_shell() { char *cmd = "/bin/sh"; char *args[] = {cmd, NULL}; execve(cmd, args, NULL);}int main() { char buf[0x28]; init(); printf("Input: "); scanf("%s", buf); return 0;}scanf("%s", buf)에서 길이 검증이 없다. 따라서 BOF가 발생한다. BOF 취약점을 이용해서 RET을 get_shell() 주소로 덮으면 쉘을 얻을 수 있다. gdb로 get_shell 주소를 구했다. 다음으로 buf ~ RET 거리를 구해보자. 를 보면 scanf() 호출 전에 [rbp-0x30]를 rax에 넣고 이를 rsi에 넣는다. rsi에 ..

keyme
'bof' 태그의 글 목록