update: userprog (tee, tsh, sleep, hex2bin)

This commit is contained in:
2026-01-01 04:22:30 +00:00
parent cf722d75ff
commit 79f46aa971
22 changed files with 1196 additions and 47 deletions
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
as -o free.o free.s
ld -s -o free free.o
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
as --32 -o free32.o free32.s
ld -m elf_i386 -s -N -o free32 free32.o
+5
View File
@@ -0,0 +1,5 @@
.global _start
_start:
mov $60, %rax # sys_exit (64-bit)
mov $0, %rdi # status 0
syscall
+5
View File
@@ -0,0 +1,5 @@
.global _start
_start:
xor %ebx, %ebx
mov $1, %eax
int $0x80
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
as --32 -o vuln.o vuln.s
# -N 옵션을 줘서 코드 섹션도 읽기/쓰기 가능하게 하면 쉘코드 실습도 가능하지만,
# 지금은 RET Overwrite만 할 거라 기본 옵션도 상관없음.
ld -m elf_i386 -s -N -o vuln vuln.o
rm vuln.o
+62
View File
@@ -0,0 +1,62 @@
.section .data
msg_normal: .ascii "Normal exit.\n"
msg_secret: .ascii "SUCCESS! Secret function executed!\n"
.section .text
.global _start
# --------------------------------------------------------
# [타겟 함수] 정상적인 흐름으로는 절대 호출되지 않음
# --------------------------------------------------------
secret_function:
# "SUCCESS! ..." 출력
mov $4, %eax # sys_write
mov $1, %ebx # stdout
mov $msg_secret, %ecx
mov $35, %edx # length
int $0x80
# 즉시 종료
xor %ebx, %ebx
mov $1, %eax # sys_exit
int $0x80
# --------------------------------------------------------
# [취약한 함수] 4바이트 버퍼에 100바이트를 들이부음
# --------------------------------------------------------
vuln_func:
# 스택 프레임 확보 (겨우 4바이트)
sub $4, %esp
# sys_read(stdin, buffer=esp, len=100)
mov $3, %eax # sys_read
xor %ebx, %ebx # stdin (0)
mov %esp, %ecx # buffer (현재 스택 포인터 위치)
mov $100, %edx # [취약점] 4바이트 방에 100명을 초대함!
int $0x80
# 스택 정리
add $4, %esp
# [여기가 핵심]
# 스택에서 리턴 주소(RET)를 꺼내서 점프하는데,
# 위에서 오버플로우로 RET가 조작되었다면? -> 펑!
ret
# --------------------------------------------------------
# [메인 진입점]
# --------------------------------------------------------
_start:
call vuln_func
# 정상 종료 메시지 출력 (익스플로잇 실패 시 여기로 옴)
mov $4, %eax
mov $1, %ebx
mov $msg_normal, %ecx
mov $13, %edx
int $0x80
# 종료
xor %ebx, %ebx
mov $1, %eax
int $0x80
+2 -1
View File
@@ -1,3 +1,4 @@
#!/bin/sh
g++ -m32 -c -o free.o free.cpp -ffreestanding && ld -m elf_i386 -o free free.o
g++ -m32 -c -o free.o free.cpp -ffreestanding -nostdlib
ld -m elf_i386 -o free free.o
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
gcc -m32 -c -o free.o free.cpp -ffreestanding -nostdlib
ld -m elf_i386 -o free free.o