Hack
-
Heap Exploit - House of ForceHack/Pwnable 2016. 10. 11. 19:31
House of Force는, 우리가 원하는 사이즈를 malloc시킬수 있어야하며, top chunk를 덮을수있어야한다. 또 추가적으로 malloc이 한번 더 호출되어야 House of Force 공격을 할 수 있다. 대충 살펴보자면, 아래와같다. 1. top chunk는 다음 malloc을 할당 할 수 있는 크기를 지정해놓는데, 이를 0xffffffff로바꾸면 이만큼 할당을 할 수 있다.2. 다음 malloc size를 컨트롤 할 수 있다면 계산해서 우리가 원하는곳에 할당시켜 다음 malloc이 호출되면 그곳에 할당해준다.3. 그리고 새로 malloc된, 우리가 원하는곳에 malloc된곳에 user data를 쓸수있다면 컨트롤이 가능하다. House Of Force 기법은 다음과 같은 코드가 있기에 정..
-
-
Use-After-Free GOT OverwriteHack/Pwnable 2016. 10. 2. 04:08
12345678910111213141516171819202122232425262728293031323334353637383940414243444546#include #include #include struct Box { int size; char *buf;}; struct Box * create_box(int size){ struct Box * box; box = malloc(sizeof(struct Box)); box-> size = size; box-> buf = malloc(size); return box;} void free_box (struct Box * box){ free (box->buf); free (box);} int main (int argc, char * argv []){ struct..
-
Heap with GDB!Hack/Pwnable 2016. 9. 15. 16:34
요즘 대회때 heap에 대한 문제가 넘나 많아서 힙에대한 지식좀 제대로 쌓아야겠다 공부한 내용이라 잘못된거 있으면 지적좀 해주세요 달게받겠습니다! 123456789101112#include int main(int argc,char *argv[]){ char* buf = (char*)malloc(256); char* buf1 = (char*)malloc(512); strcpy(buf,argv[1]); strcpy(buf1,argv[2]); printf("%s\n",buf); free(buf); free(buf1);}Colored by Color Scriptercs buf, buf1에 각각 256바이트와 512바이트를 할당하고 buf = argv[1], buf1 = argv[2]를 각각 받고 free를 해주..
-
first_fit use after freeHack/Pwnable 2016. 9. 13. 02:40
12345678910111213141516171819202122232425262728293031323334353637#include #include #include int main(){ printf("This file doesn't demonstrate an attack, but shows the nature of glibc's allocator.\n"); printf("glibc uses a first-fit algorithm to select a free chunk.\n"); printf("If a chunk is free and large enough, malloc will select this chunk.\n"); printf("This can be exploited in a use-after-f..
-
fast_dup double free attackHack/Pwnable 2016. 9. 13. 02:13
#include #include int main(){ printf("This file demonstrates a simple double-free attack with fastbins.\n"); printf("Allocating 3 buffers.\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("Freeing the first one...\n"); free(a); printf("If we free %p again, things will cras..
-
Layer CTF easy_bofHack/Pwnable 2016. 9. 5. 01:12
fsb와 bof가 같이 사용되는문제지만 fsb는 릭을 위하여 존재한다. 해당 바이너리는 PIE, SSP, NX, ASLR의 보호기법이 걸려있기때문에 쉘코드는 물론 바이너리영역내에 있는 PLT도 사용하지못하게된다.즉 ROP는 안된다는소리 우선 취약점 벡터로 가기위해서는 인티저 오버플로우가 사용된다. nbytes 변수는 %d 포맷스트링으로 정수를 입력받게되는데, nbytes는 size_t 자료형을 가지고있다. 여기까진 인티저 오버플로우가 발생하지않는다 하지만 다음 조건문을 보자 다음 조건문을 보게되면 nbytes 값을 signed int로 캐스팅하여 비교하고있다. -1을 넣어준다면 unsigned int의 최대크기만큼 입력받을 수 있기때문에 오버플로우가 발생한다. 이제 FSB를 통해 카나리만 알아낸다면 익스..
-
포맷스트링(Format String Bug) GOT OverwriteHack/Pwnable 2016. 8. 17. 23:45
ROP로 GOT Overwrite는 알고있었지만 fsb를 공부안한탓에 늦게 깨달았다 하하;; 고로 까먹을수도있기때문에 써놔야지 하하 여기서 일단 중요한건 %x, %n인데, 새로 안것은 %4$n 이런것도 있다는거를 깨달았습니다 %x%x%x%x할바에 %4$x를 쓰면됩니다 뭔가 이해되죠 %x%x%x%x%x면 %5$x를 사용하시면 됩니다. 이해 잘되죠!뒤에 x는 %x를 나타냅니다 자 이제 중요한건 fsb로 쉘따기인데 간단한 코드를 짜겠습니다 1234567891011#include int main(int argc,char *argv[]){ char buf[256]; system("echo \"\""); strcpy(buf,argv[1]); printf(buf); printf("/bin/sh"); return 0;..