Profile

머리정리하는곳

c2w2m2

[Protostar] heap1

힙 공부하다가 많이 부족한거 같아서 다시 처음부터 protostar 힙을 풀어보려 한다.


0 은 쉬우니 패쓰 하고 1 부터


#include <stdlib.h> #include <unistd.h> #include <string.h> #include <stdio.h> #include <sys/types.h> struct internet { int priority; char *name; }; void winner() { printf("and we have a winner @ %d\n", time(NULL)); } int main(int argc, char **argv) { struct internet *i1, *i2, *i3; i1 = malloc(sizeof(struct internet)); i1->priority = 1; i1->name = malloc(8); i2 = malloc(sizeof(struct internet)); i2->priority = 2; i2->name = malloc(8); strcpy(i1->name, argv[1]); strcpy(i2->name, argv[2]); printf("and that's a wrap folks!\n"); 

}



코드가 이런식이다. 힙안에 힙을 할당하는 꼴이 되게된다. 힙 구조를 보자.




이런 식으로 할당이 되어있는데,



엌.... 그림이 이상한데 0x00000011 이 heap size 가 되겠고 0x00000001 과 0x00000002 가 각각 i1, i2 의 id 가 된다.


그리고 파랑색과 빨강색으로 나타내서 화살표 그어준게 name 에서 malloc 된 것이다.


고로 이 문제를 풀기 위해선 heap overflow를 기반으로 한 got overwrite 가 될것이고,


printf@got 를 winner 로 덮어버리면 끝날듯 싶다.



는 그래서 삽질하고있었는데 최적화 떄문에 puts 로 바뀌었었다고 카더라....




후욱 힙 어렵다....ㅎㅎ


'Pwnable' 카테고리의 다른 글

[Protostar] heap2  (1) 2017.09.20
[CodeGate] BabyMisc  (0) 2017.09.15
<asis ctf> mary_morton  (0) 2017.09.11
Pwnable.kr -dragon  (1) 2017.09.09
[Defcon2017] Smash me  (1) 2017.09.09