본문 바로가기

PWN

(26)
FireShell CTF 2020 / FireHTTPD It is a simple web server written in c language. There is a place that looks like a stack overflow ... but as you can see it is meaningless code. FSB occurs when copying the Referer in the HTTP Header. Through this bug, leak and exploit are possible. There are annoying things like the NULL armer or canary, but it's a minor problem that is not too difficult to solve. pop rsp;ret gadget will help ..
peda, pwndbg, gef 같이 쓰기 https://medium.com/bugbountywriteup/pwndbg-gef-peda-one-for-all-and-all-for-one-714d71bf36b8
HSCTF / hard_heap keyword : stdin structure, unsorted bin attack GLIBC version : 2.23 checksec main 함수는 아래와 같다. sice에서 청크를 할당하고 값을 쓸 수 있다. Observe에서 할당한 청크에 저장된 값을 볼 수 있다. antisice에서 할당된 청크를 해제한다. void __fastcall __noreturn main(__int64 a1, char **a2, char **a3) { int *v3; // rsi int v4; // [rsp+4h] [rbp-Ch] unsigned __int64 v5; // [rsp+8h] [rbp-8h] v5 = __readfsqword(0x28u); setvbuf(stdin, 0LL, 2, 0LL); setvbuf(..
HackTM CTF 2020 / Trip_to_trick GLIBC : 2.29 checksec : file descriptor에 관한 문제이다. main 함수의 흐름은 다음과 같다. sandbox and nohack setbuf stdin stdout stderr leak system's address two chance of AAW close stdin stdout stderr int __cdecl main(int argc, const char **argv, const char **envp) { _QWORD *ptr; // [rsp+18h] [rbp-18h] __int64 value; // [rsp+20h] [rbp-10h] unsigned __int64 v6; // [rsp+28h] [rbp-8h] v6 = __readfsqword(0x28u); valu..
[CISCN 2017] BabyDriver 리눅스 커널 모듈에서 발생하는 취약점을 exploit하는 문제이다. ioctl에서 원하는 크기의 청크를 할당할 수 있다. 이때 청크의 포인터는 전역변수에 등록된다. __int64 __fastcall babyioctl(file *filp, unsigned int command, unsigned __int64 arg) { size_t v3; // rdx size_t size; // rbx __int64 result; // rax _fentry__(); size = v3; if ( command == 0x10001 ) { kfree(babydev_struct.device_buf); babydev_struct.device_buf = (char *)_kmalloc(size, 0x24000C0LL); babydev..
2019 defcon/ babyheap 전형적인 menu heap exploit 문제이다. 제공하는 기능은 다음과 같다. Malloc Free Show Exit 각각의 함수들은 전형적인 모습이고, Malloc함수 외에는 취약점이 터지는 부분이 없기 때문에 설명을 생략한다. 취약점은 Malloc에서 발생한다. 청크를 할당한 후 입력받을 때 한 글자씩 입력받는다. 이때 입력을 받은 후 size 체크를 하기 때문에 한 바이트를 더 입력할 수 있다. 따라서 off-by-one 취약점이 발생한다. signed __int64 add() { _QWORD *v0; // rax unsigned int i; // ebp __int64 size; // r12 __int64 j; // rbx __int64 *v4; // rbp char buf; // [rsp+7h..
calloc without memset 0 CTF에서 자주 나오는 glibc heap epxloit 문제에서 메모리를 할당하기 위하여 자주 사용되는 함수는 다음과 같다. malloc realloc calloc 이중 calloc은 메모리를 할당한 후 할당된 메모리를 0으로 초기화한다. 따라서 heap exploit을 할 때 중요한 정보를 leak하기 힘들어진다. 또한 청크를 할당받을 때 중요한 정보를 0으로 덮어버려 에러를 유발할 수 있다. 본 문서에서 이런 문제를 해결하기 위한 테크닉을 알아보자. 이 테크닉은 glibc 2.23, 2.27, 2.29에서 유효한 것을 확인하였다. glibc 2.29 버전의 소스코드를 보자. glibc-2.29/malloc/malloc.c:3472에 calloc에서 메모리를 0으로 초기화하는 코드가 있다. 이때 첫번..
glibc 2.29 tcache typedef struct tcache_entry { struct tcache_entry *next; /* This field exists to detect double frees. */ struct tcache_perthread_struct *key; } tcache_entry; /* There is one of these for each thread, which contains the per-thread cache (hence "tcache_perthread_struct"). Keeping overall size low is mildly important. Note that COUNTS and ENTRIES are redundant (we could have just counted the linked..