System Hacking Advanced

System Hacking Advanced

[dreamhack] Return to Library

Return to Library#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 address printf("[2] Overwrite return ..

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] basic_rop_x64

문제분석int main(int argc, char *argv[]) { char buf[0x40] = {}; initialize(); read(0, buf, 0x400); write(1, buf, sizeof(buf)); return 0;}○ 코드 분석buf[0x40] 선언read(0, buf, 0x400)buf에 0x400 크기 입력write(1, buf, sizeof(buf))buf 출력ROP 체인을 구성해서 system("/bin/sh")를 실행하는 것이 목표다. 필자는 풀이 과정에서 __libc_csu_init() 가젯을 활용할 예정이다. __libc_csu_init()에 대해서 공부하고자 해당 개념을 이용한 풀이를 작성했다. ○ JIT-ROP__libc_csu_init(..

System Hacking Advanced

[dreamhack] ssp_001

SSP 개념SSP(Stack Smashing Protector) SSP(Stack Smashing Protector)SSP는 BOF를 방어하기 위한 보호기법 중 하나로 함수를 실행할 때, canary라는 랜덤 값을 스택에 추가하여 BOF로 스택 데이터가 변조됐는지 확인하는 방법이다. canary가 변조된 경우는 스택 데이터가keyme2003.tistory.com ssp_001#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]);}voi..

System Hacking Advanced

[dreamhack] Return Address Overwrite

Return Address Overwritevoid 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에 넣고 이를 ..

System Hacking Advanced

[dreamhack] basic_exploitation_002

문제분석void get_shell() { system("/bin/sh");}int main(int argc, char *argv[]) { char buf[0x80]; initialize(); read(0, buf, 0x80); printf(buf); exit(0);}read(0, buf, 0x80)에서 길이에 대한 검증을 수행하고 있다. 따라서 일반적인 BOF는 발생하지 않는다. 그렇다면 어떤 취약점이 존재하는 것일까?printf(buf);위 코드에서 Format String Bug 취약점이 발생한다. printf 함수를 사용할 때, 포맷스트링을 지정하지 않고 buf를 1번째 인자로 사용하도록 코드를 작성한 상황이다. 이는 출력함수를 잘못된 방식으로 사용한 경우다. 포맷스..

keyme
'System Hacking Advanced' 카테고리의 글 목록 (6 Page)