본문 바로가기

system/writeup

2016 whithat malloc

malloc

2016 whitehat malloc

Stack Leak, malloc, free, modify를 자유롭게 할 수 있다.

 

  • malloc

size <= 32라면 size만큼 malloc을 해주며

size > 32라면 malloc(32)를 해준다.

즉, size를 64로 넣으면 malloc(32)가 된다.

  • modify

33바이트만큼 buf에 입력을 받고 heap에 memcpy를 통해 복사한다. 바로 입력을 안받고 이렇게 하는 이유를 모르겠다..

 

free, list, exit는 그냥 이름대로의 기능이다.

32바이트 길이니끼니 fastbin을 떠올릴 수 있겠고 자유로운 할당과 해제가 가능하고 우리가 입력한 size 변수가 스택에 기록되니 fastbin dup into stack이 가능할 것 같다.

 

이걸 몰라서 헤매고 있었는데 이 flag를 읽어주는 함수가 존재한다.

 

fastbin dup into stack in malloc

  1. malloc(32) # A
  2. malloc(32) # B
  3. free(A)
  4. free(B) # B -> A 32byte fastbin chain
  5. modify(B) # B forward pointer change to fake heap in stack
  6. malloc(32)
  7. malloc(49) # 32(size) + 16(header) + 1(inuse_bit)
  8. change ret in the fake heap in stack

 

 

성공적으로 /bin/cat 함수를 불렀다!


'system > writeup' 카테고리의 다른 글

2014 codegate angry_doraemon  (0) 2019.01.04
2013 hdcon luckyzzang  (0) 2019.01.02
2015 codegate yocto  (0) 2018.12.31
pwnable.kr alloca - 80pt  (0) 2018.12.27
pwnable.kr loveletter - 50pt  (0) 2018.12.26