Security
The House of Force
The House of Force
2017.08.15The House of Forcehttps://github.com/shellphish/how2heap/blob/master/house_of_force.c 존내 큰 chunk를 할당해버린다! top chunk size를 ``c -1``로 만들어 ``c mmap()`` 호출을 방지하고,target addr이 있는 곳 까지의 차 만큼의 커다란 chunk를 할당하면그 다음 ``c malloc()`` 때 target 위치에 chunk를 할당 및 반환하게 된다.```c*top_ptr = -1;difference = (target_addr - 2*sizeof(void*)) - top_ptr;malloc(difference); // target 직전 까지 할당target = malloc(); // return chun..
[UNDEAD] The House of Mind
[UNDEAD] The House of Mind
2017.08.15The House of Mindhttp://phrack.org/issues/66/10.htmlhttps://gbmaster.wordpress.com/2015/06/15/x86-exploitation-101-house-of-mind-undead-and-loving-it/ unlink와 반대로, chunk가 free되면서 bins와 link하는 과정에서 발생하는 쓰기를 이용하는 방식이다.[free] unsorted bin link```cbck = unsorted_chunks(av); // == &av->bins[0]fwd = bck->fd;if (__glibc_unlikely (fwd->bk != bck)) // DEAD{ errstr = "free(): corrupted unsorted chunks"; g..
unsorted bin attack
unsorted bin attack
2017.08.15https://github.com/shellphish/how2heap/blob/master/unsorted_bin_attack.c unsorted bin에 있는 chunk가 할당될 때, 역시 unsorted bin에서 chunk를 제거하기 위해 unlink가 일어난다.단, 여기서는 unlink macro를 사용하지 않고 처리한다. [malloc] unsorted bin size check [malloc] unsorted bin unlink```cfor (;; ){ int iters = 0; while ((victim = unsorted_chunks (av)->bk) != unsorted_chunks (av)) { bck = victim->bk; if (__builtin_expect (chunksize_n..
[UNDEAD] unlink
[UNDEAD] unlink
2017.08.15unlink`` unlink``는 consolidate가 발생할 때 연결되어 있던 bins list에서 chunk를 제거하기 위해 호출된다.`` PREV_INUSE``를 체크해 호출하기 때문에 fastbin chunk에 `` PREV_INUSE`` unset한다고 해서 회피할 수 있는 것이 아니다. glibc 2.25's unlink macro```c#define unlink(AV, P, BK, FD) { if (__builtin_expect (chunksize(P) != prev_size (next_chunk(P)), 0)) malloc_printerr (check_action, "corrupted size vs. prev_size", P, AV); FD= P->fd; BK= P->bk; if (__b..
The House of Lore
The House of Lore
2017.08.15The House of Lorefree'd small/fast chunk의 bk를 `` fake_chunk`` addr로 overwrite. https://github.com/umbum/pwn/blob/master/how2heap/house_of_lore_fast.chttps://github.com/umbum/pwn/blob/master/how2heap/house_of_lore_small.c fastbin도 결국 large request가 들어오면 smallbin으로 옮겨지기 때문에 이 경우 small과 똑같이 동작한다.``c mov_to_small=malloc(large)``를 호출하지 않으면 차이가 발생한다. ( limitation #2 ) smallbins bk check & unlink```c e..
fastbin attack / fastbin_dup
fastbin attack / fastbin_dup
2017.08.15fastbin attackfree'd fast chunk의 fd를 `` fake_chunk`` addr로 overwrite.다음 ``c malloc(fast)`` 때 overwrited fast chunk가 반환되면서 fastbin에 `` fake_chunk`` addr이 추가되므로, 그 다음 반환 chunk는 `` fake_chunk``. ```cfake_chunk[1] = FAST; // bypass check hptr = malloc(FAST);victim = malloc(FAST);free(victim);strcpy(hptr, argv[1]); // vulnerability ( overflow, uaf, overlap, fastbin_dup... ) victim = malloc(FAST); // ..
The House of Spirit
The House of Spirit
2017.08.15The House of Spiritstack overflow로 stack에 있는 포인터 변수 hptr을 `` fake_chunk`` addr로 overwrite.이후 ``c free(hptr)``하면 fastbin에는 ``c fake_chunk`` addr이 추가되므로, 그 다음 반환 chunk는 `` fake_chunk`` ```c/* set fake_chunk */fake_chunk[1] = arbitrary_size;/* set next chunk size */... void *hptr = malloc(SIZE);char buf[4];strcpy(buf, argv[1]); // stack overflow free(hptr) // fake chunk is added in fastbinfake = ma..
Poison null byte
Poison null byte
2017.08.15https://github.com/umbum/pwn/blob/master/how2heap/poison_null_byte.c malloc'ed region에 off-by-one error가 발생할 때, next chunk size의 LSB를 `` 0``으로 만들어 size를 속이는 방법.결과적으로 d chunk 내부에 b2 chunk가 위치하게 되므로 d chunk에 접근해 b2 chunk를 변경할 수 있다. null byte off-by-one error는 종종 발생하기 때문에 많은 경우에 사용할 수 있는 테크닉이라는 점은 장점. b2 chunk는 heap에만 존재할 수 있기 때문에 b2 chunk가 function pointer 등 유용한 데이터를 저장하고 있을 경우나, overlap을 이용한 leak..
overlapping chunk
overlapping chunk
2017.08.15overlap technique으로 fastbin attack을 이용해도 되겠지만, 이게 더 간단하다.Poison null byte와 동일하게 off-by-one error만 발생하는 환경에서도 사용할 수 있다. 다만 overflow 되는 것이 null byte 뿐 이라면 사용할 수 없으므로 이 경우 poison null byte를 사용해야 한다. Case 1https://github.com/shellphish/how2heap/blob/master/overlapping_chunks.c먼저 ``c free(chunk)``하고 `` chunk.size``를 변경1. free(p2) and then change p2.sizep1 prev_size 0x111 p2 prev_size0x111 → 0x1a1 p3p..
one_gadget / libc-database
one_gadget / libc-database
2017.08.13one_gadgetobjdump나, one_gadget으로 구한 offset은 library mapping 시작 주소에 +하면된다.constraints 를 확인한다. https://github.com/david942j/one_gadgethttps://david942j.blogspot.kr/2017/02/project-one-gadget-in-glibc.html 어떤 식으로 동작하는지 나와있다.```bashgem install one_gadget```one_gadget으로 나온 결과는 잘 되는지 꼭 테스트해봐야 한다. 에러가 발생하는 경우도 있기 때문.```bashjump *base+offset```바이너리가 컴파일된 시스템의 libc 버전과, 바이너리를 실행하는 현재 시스템의 libc 버전이 다른 경우o..
pwntools
pwntools
2017.08.13https://github.com/Gallopsled/pwntoolshttps://docs.pwntools.com/en/stable/intro.htmlhttps://docs.pwntools.com/en/stable/globals.htmlhttp://docs.pwntools.com/en/stable/tubes.html 32bit에서도 돌아가기는 하나 정식으로 지원하지는 않음.canary break같은 brute force는 threading이나 asyncio를 사용해야 하는데 threading의 경우 될 때도 있고 안될 때도 있음. 직접 짠건 잘 되는걸로 보아 시스템 상태에 더 민감하게 반응하는 듯? 그래서 이런 경우 직접 코딩하는게 낫다. debug 기능이 아주 이상하기 때문에 그냥 안쓰는게 낫다. ``..
[MCSC2014] tinypwn - SROP
[MCSC2014] tinypwn - SROP
2017.08.10`` 0x3``번 system call을 호출하는데, 이는 ``c read()``다.그리고 곧바로 read 결과 처음 4byte로 return하기 때문에 아주 심플한 바이너리다. ASLR과 NX가 적용되어 있기 때문에 shellcode로 리턴하는 것은 불가능.libc.so가 매핑되지 않는, 단일 바이너리이기 때문에 RTL도 불가능하다. ``` 0x8048107 : int 0x80 0x8048109 : ret `````c int 0x80`` instruction이 있기 때문에 ROP chain을 구성해 파라미터를 푸시하고 system call할 수 있다. ``c read()``는 읽은 byte 수를 eax로 리턴하기 때문에, 이를 이용해 eax를 적당히 설정하고 ``c int 0x80``으로 리턴하면 sy..