본문 바로가기

전체 글

(71)
[함께 실습] Hook Overwrite 개념 1) Full RELRO(O) 이더라도 -> libc의 데이터 영역에는 쓰기 권한(O) 2) malloc 함수 -> __malloc_hook 변수의 값이 NULL이 아닌지 검사 -> NULL(X) -> __malloc_hook이 가리키는 함수를 먼저 실행. -> 이때, malloc 함수의 인자는 훅 함수에 전달된다. 위의 내용은 훅 변수를 사용하는 free, realloc도 마찬가지 3) 위의 함수(malloc, free, realloc)들은 libc.so에 정의돼있음. $ readelf -s /lib/x86_64-linux-gnu/libc-2.27.so | grep -E "__malloc_hook|__free_hook|__realloc_hook" 를 통해 확인해보면 __free_hook, __ma..
PIE & RELRO PIE [PIE(Position-Independent Executable)]: ASLR이 코드 영역에도 적용되게 해주는 기술. 무작위 주소에 매핑돼도 실행 가능한 실행 파일 -ASLR 환경에서 PIE가 적용된 바이너리 -> 실행될 때마다 다른 주소에 적재된다. 따라서, 코드 영역의 가젯을 사용하거나, 데이터 영역에 접근하려면 -> 바이너리가 적재된 주소를 알아야 한다. [ELF]: 실행 파일 or 공유 오브젝트(ex. libc.so) [PIE 우회] a) 코드 베이스 구하기 b) Partial Overwrite: **** 키워드 **** -상대 참조(Relative Addressing): 어떤 값을 기준으로 다른 주소를 지정하는 방식 -Position Independent Code (PIC): 어떤 주소..
bof [소스코드] #include #include #include void func(int key){ char overflowme[32]; printf("overflow me : "); gets(overflowme); // smash me! if(key == 0xcafebabe){ system("/bin/sh"); } else{ printf("Nah..\n"); } } int main(int argc, char* argv[]){ func(0xdeadbeef); return 0; } (1) main함수에서 인자로 0xdeadbeef를 주며 func함수를 호출한다. (2) func함수에선 gets를 이용해 값을 입력받아 overflowme에 저장하고 (3) 인자인 key와 0xcafebabe를 비교하여 일치하면 ..
collision [소스코드] #include #include unsigned long hashcode = 0x21DD09EC; unsigned long check_password(const char* p){ int* ip = (int*)p; int i; int res=0; for(i=0; i
fd [소스코드] #include #include #include char buf[32]; int main(int argc, char* argv[], char* envp[]){ if(argc
basic_rop_x86 [소스코드] #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); } int main(int argc, char *argv[]) { char buf[0x40] = {}; initialize(); read(0, buf, 0x400); write(1, buf, sizeof(buf)); return 0; } [exploit] *유념할 점: x64 아키텍처에서는 함수의 인자를 레..
basic_rop_x64 [소스코드] #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); } int main(int argc, char *argv[]) { char buf[0x40] = {}; initialize(); read(0, buf, 0x400); write(1, buf, sizeof(buf)); return 0; } [exploit] from pwn import * arch p = pr..
[함께 실습] Return Oriented Programming [Remind] 1) plt에는 got엔트리의 주소가 적혀있고 got에는 해당 함수의 실제 주소가 적혀있다. 2) ASLR이 적용되면 실행할 때마다 스택, 힙, libc_base의 주소가 바뀐다 [소스 코드] #include #include int main() { char buf[0x30]; setvbuf(stdin, 0, _IONBF, 0); setvbuf(stdout, 0, _IONBF, 0); // Leak canary puts("[1] Leak Canary"); write(1, "Buf: ", 5); read(0, buf, 0x100); printf("Buf: %s\n", buf); // Do ROP puts("[2] Input ROP payload"); write(1, "Buf: ", 5); r..