목록Write-ups (27)
rsp-∞
#include #include #include #include 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 read_flag() { system("cat /flag"); } int main(int argc, char *argv[]) { char buf[0x80]; initialize(); gets(buf); return 0; } basic_exploitation_001의 c 코드 파일이다. main에서 길이를 체..
#include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } void get_shell() { char *cmd = "/bin/sh"; char *args[] = {cmd, NULL}; execve(cmd, args, NULL); } int main() { char buf[0x28]; init(); printf("Input: "); scanf("%s", buf); return 0; } rao.c 코드를 먼저 보자. buf의 크기가 0x28로 설정되어 있고, main 함수의 하단에 scanf를 사용하여 buf의 값을 입력받는다. rao.c의 취약점은 이 scanf 함수이다. 입력받는 값의 길이를 체크하지 않는 함수이..
pwndbg> disassemble phase_3 Dump of assembler code for function phase_3: 0x0000000000400f43 : sub rsp,0x18 0x0000000000400f47 : lea rcx,[rsp+0xc] 0x0000000000400f4c : lea rdx,[rsp+0x8] 0x0000000000400f51 : mov esi,0x4025cf 0x0000000000400f56 : mov eax,0x0 0x0000000000400f5b : call 0x400bf0 0x0000000000400f60 : cmp eax,0x1 0x0000000000400f63 : jg 0x400f6a 0x0000000000400f65 : call 0x40143a 0x0000..
pwndbg> disassemble phase_2 Dump of assembler code for function phase_2: 0x0000000000400efc : push rbp 0x0000000000400efd : push rbx 0x0000000000400efe : sub rsp,0x28 0x0000000000400f02 : mov rsi,rsp 0x0000000000400f05 : call 0x40145c 0x0000000000400f0a : cmp DWORD PTR [rsp],0x1 0x0000000000400f0e : je 0x400f30 0x0000000000400f10 : call 0x40143a 0x0000000000400f15 : jmp 0x400f30 0x0000000000400f..
pwndbg> disassemble phase_1 Dump of assembler code for function phase_1: 0x0000000000400ee0 : sub rsp,0x8 0x0000000000400ee4 : mov esi,0x402400 0x0000000000400ee9 : call 0x401338 0x0000000000400eee : test eax,eax 0x0000000000400ef0 : je 0x400ef7 0x0000000000400ef2 : call 0x40143a 0x0000000000400ef7 : add rsp,0x8 0x0000000000400efb : ret phase_1을 디스어셈블한다. 코드를 들여다보지 않고 그냥 run하면 입력값으로 무얼 넣어야 할지 전혀 ..

Q1. 다음 어셈블리 코드를 실행했을 때 출력되는 결과로 올바른 것은? [Code] main: push rbp mov rbp, rsp mov esi, 0xf mov rdi, 0x400500 call 0x400497 mov eax, 0x0 pop rbp ret write_n: push rbp mov rbp, rsp mov QWORD PTR [rbp-0x8],rdi mov DWORD PTR [rbp-0xc],esi xor rdx, rdx mov edx, DWORD PTR [rbp-0xc] mov rsi,QWORD PTR [rbp-0x8] mov rdi, 0x1 mov rax, 0x1 syscall pop rbp ret ================================== [Memory] 0x4005..

Q1. end로 점프하면 프로그램이 종료된다고 가정하자. 프로그램이 종료됐을 때, 0x400000 부터 0x400019까지의 데이터를 대응되는 아스키 문자로 변환하면 어느 문자열이 나오는가? [Register] rcx = 0 rdx = 0 rsi = 0x400000 ======================= [Memory] 0x400000 | 0x67 0x55 0x5c 0x53 0x5f 0x5d 0x55 0x10 0x400008 | 0x44 0x5f 0x10 0x51 0x43 0x43 0x55 0x5d 0x400010 | 0x52 0x5c 0x49 0x10 0x47 0x5f 0x42 0x5c 0x400018 | 0x54 0x11 0x00 0x00 0x00 0x00 0x00 0x00 ============..