본문 바로가기

system

c library hook, atexit Memory Allocation Hooks The GNU C Library lets you modify the behavior of malloc, realloc, and free by specifying appropriate hook functions. You can use these hooks to help you debug programs that use dynamic memory allocation void *(*__malloc_hook) (size_t SIZE, const void *CALLER); void *(*__realloc_hook) (void *PTR, size_t SIZE, const void *CALLER); void (*__free_hook) (void *PTR, const void.. 더보기
[how2heap translation] unsafe_unlink.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #include #include #include #include uint64_t *chunk0_ptr; int main() { printf("Welcome to unsafe unlink 2.0!\n"); printf("Tested in Ubuntu 14.04/16.04 64bit.\n"); printf("This technique can be used when you have a pointer at a known loc.. 더보기
[how2heap translation] unsorted_bin_attack.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #include #include int main(){ printf("이 파일은 large unsigned long 값을 스택에 작성함으로써 unsorted bin attack 을 보여준다.\n"); printf("실제로 unsorted bin attack 은 일반적으로 fastbin attack 을 발생시키기 위해 libc 안에 전역 변수 global_max_fast 를 다시 쓰는 것과 같이 fastbin attack 을 유발한다.\n\n"); // global max fast : to check size of fastbin on your .. 더보기
[how2heap translation] fastbin_dup_into_stack.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include #include int main() { printf("이 파일은 fastbin_dup.c 에서 확장되어 malloc의 return address를 컨트롤(이 경우에서는 스택)할 수 있도록 한다.\n") unsigned long long stack_var; printf("우리가 원하는 malloc의 return address는 %p 이다..\n", 8+(char *)&stack_var); printf("먼저 세 개의 버퍼를 할당한다.\n");.. 더보기
[how2heap translation] fastbin_dup.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include #include int main() { printf("이 파일은 fastbin에서의 간단한 double-free attack 을 보여준다.\n"); printf("세 개의 버퍼를 할당한다.\n"); int *a = malloc(8); int *b = malloc(8); int *c = malloc(8); printf("1st malloc(8): %p\n", a); printf("2nd malloc(8): %p\n", b); printf("3rd malloc(8): %p\n", c); printf("첫 번째 청크를 프리한.. 더보기
MP3 CD Converter Exploit SEH Overflow를 이용해 MP3 CD Converter 프로그램을 Exploit 해보도록 하겠다. + SafeSEH 우회 먼 옛날의 SafeSEH 가 걸려있지 않은 경우 Handler의 주소만 쉘코드가 위치한 주소로 바꾸면 되겠지만... 요즘에는 여러가지 보안 메커니즘이 적용되어있기 때문에 힘들다.. 여기서는 SafeSEH 를 우회하여 Exploit 해보도록 하겠다. SEH Oerflow Windows 에서 GS(Security Cookie)로 인해 일반적인 BOF 공격이 힘들다. 이를 극복하기 위해 *Next, *Handler 까지의 값을 덮어씌우고 인위적으로 예외를 발생시켜 덮어씌운 Handler 가 실행되도록 유도할 수 있다. 환경 OS : Windows XP Service Pack 2 취약.. 더보기
SEH(Structured Exception Handler) SEH(Structured Exception Handler) 는 windows 운영체제의 예외 처리 메커니즘이다. 보통 예외가 발생하면 windows 에서는 어플리케이션을 강제로 종료한다. 하지만 C, C++ 과 같은 컴파일러에서 프로그래머에게 __try, __except, catch, throw 와 같은 예외 처리에 대해 컨트롤 할 수 있도록 제공하고 있다. 하지만 온전히 컴파일러의 힘만으로는 힘들고.. 결국은 windows 운영체제에서 이러한 예외를 처리해주어야 한다. 예외는 하드웨어 예외와 소프트웨어 예외로 나뉘는데, 주로 zero divide, Acess violation, integer overflow 와 같은 예외가 하드웨어 예외에 해당한다. 소프트웨어 예외는 개발자가 작성한 프로그램과 운영체.. 더보기
Use-After-Free 취약점 UAF(Use-After_free) 취약점이란 무엇인가? : UAF 취약점이란, 프로그래머가 Heap 영역을 잘못 다룰 때 발생하는 취약점으로, 가령 우리가 Heap 영역을 사용한 후 Free 하고 재사용(reallocation) 할 경우 일어나는 취약점이다. 간단하게 소스코드를 보자. #include #include int main() { int *one, *two; one = malloc(120); printf("input value : "); scanf("%d", one); printf("one's address : %p\n", one); printf("one's value : %d\n", *one); free(one); two = malloc(120); printf("\n"); printf("tw.. 더보기
Back(` `) , Single(' '), Double(" ") Quotes, Blackslash(\) Back Qutoes : 백 쿼터의 경우 실행 결과를 다시 입력으로 바꾸는 기능을 가지고 있다. # uname Linux # name=`uname` # echo $name Linux Single Qutoes : 변환이나 해석없이 문자 그대로 인식하는 기능을 가지고 있다. # name=`uname` # echo $name Linux # echo '$name' $name Double Qutoes : 문자열 중간에 공백이 있을 때 하나의 인수가 둘로 인식되는 것을 막을 수 있다. 그리고 특수 문자들을 보호하는 기능을 가지고 있다. # mkdir Linux Power # ls -al total 16 drwxr-xr-x 4 woosunbi woosunbi 4096 Nov 4 01:58 . drwxr-xr-x 15.. 더보기
stdin 임시버퍼 fget() 함수에서 사용자 입력을 받을 때 stdin 임시버퍼에 입력 값을 받아주게 된다. memset() 같은 함수로 버퍼를 초기화하더라도 stdin 임시버퍼에는 값이 남아있다. 이러한 점을 이용하여 우리는 exploit 에 이용할 수 있다. fgets(buffer, 256, stdin); 를 gdb로 분석하면 다음과 같다. 0x804871a : mov %eax,%ds:0x8049a3c // stdin 0x804871f : push %eax 0x8048720 : push 0x100 // 256byte 0x8048725 : lea %eax,[%ebp-40] 0x8048728 : push %eax // buffer address 0x8048729 : call 0x8048408 (gdb) x/x 0x080.. 더보기