ssh -p 2223 leviathan6@leviathan.labs.overthewire.org
pw: UgaoFee4li
현재 디렉터리에서 정보를 확인한다.
leviathan6@leviathan:~$ ls -al
total 28
drwxr-xr-x 2 root root 4096 Aug 26 2019 .
drwxr-xr-x 10 root root 4096 Aug 26 2019 ..
-rw-r--r-- 1 root root 220 May 15 2017 .bash_logout
-rw-r--r-- 1 root root 3526 May 15 2017 .bashrc
-r-sr-x--- 1 leviathan7 leviathan6 7452 Aug 26 2019 leviathan6
-rw-r--r-- 1 root root 675 May 15 2017 .profile
leviathan6@leviathan:~$ file leviathan6
leviathan6: setuid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=30bfe37691e013d638a271635abbb3ade6b5d20b, not stripped
leviathan6@leviathan:~$
현재 디렉터리를 확인해보니 leviathan6 바이너리 파일이 있다.
해당 바이너리 파일을 실행시켜보자
leviathan6@leviathan:~$ ./leviathan6
usage: ./leviathan6 <4 digit code>
leviathan6@leviathan:~$ ./leviathan6 1234
Wrong
leviathan6@leviathan:~$
해당 바이너리를 실행 시켰을 때 인자값으로 4자리 숫자를 입력하라고 나오고, 4자리 숫자를 인자값으로 넘겨줬을 때 Wrong이라는 문자가 출력됐다.
아마 특정 4자리 숫자를 입력해야되는 것 같다.
일단 ltrace를 사용하여 바이너리를 실행시켜보자
ltrace 명령어를 사용해도 어떤 숫자가 맞는 숫자인지 나오지 않는다.
gdb 툴을 사용하여 바이너리가 어떤 값을 비교하는지 확인해보자
leviathan6@leviathan:/tmp/test6$ gdb -q leviathan6
Reading symbols from leviathan6...(no debugging symbols found)...done.
(gdb) disas main
Dump of assembler code for function main:
0x0804853b <+0>: lea 0x4(%esp),%ecx
0x0804853f <+4>: and $0xfffffff0,%esp
0x08048542 <+7>: pushl -0x4(%ecx)
0x08048545 <+10>: push %ebp
0x08048546 <+11>: mov %esp,%ebp
0x08048548 <+13>: push %ebx
0x08048549 <+14>: push %ecx
0x0804854a <+15>: sub $0x10,%esp
0x0804854d <+18>: mov %ecx,%eax
0x0804854f <+20>: movl $0x1bd3,-0xc(%ebp)
0x08048556 <+27>: cmpl $0x2,(%eax)
0x08048559 <+30>: je 0x804857b <main+64>
0x0804855b <+32>: mov 0x4(%eax),%eax
0x0804855e <+35>: mov (%eax),%eax
0x08048560 <+37>: sub $0x8,%esp
0x08048563 <+40>: push %eax
---Type <return> to continue, or q <return> to quit---
0x08048564 <+41>: push $0x8048660
0x08048569 <+46>: call 0x80483b0 <printf@plt>
0x0804856e <+51>: add $0x10,%esp
0x08048571 <+54>: sub $0xc,%esp
0x08048574 <+57>: push $0xffffffff
0x08048576 <+59>: call 0x80483f0 <exit@plt>
0x0804857b <+64>: mov 0x4(%eax),%eax
0x0804857e <+67>: add $0x4,%eax
0x08048581 <+70>: mov (%eax),%eax
0x08048583 <+72>: sub $0xc,%esp
0x08048586 <+75>: push %eax
0x08048587 <+76>: call 0x8048420 <atoi@plt>
0x0804858c <+81>: add $0x10,%esp
0x0804858f <+84>: cmp -0xc(%ebp),%eax
0x08048592 <+87>: jne 0x80485bf <main+132>
0x08048594 <+89>: call 0x80483c0 <geteuid@plt>
0x08048599 <+94>: mov %eax,%ebx
---Type <return> to continue, or q <return> to quit---
0x0804859b <+96>: call 0x80483c0 <geteuid@plt>
0x080485a0 <+101>: sub $0x8,%esp
0x080485a3 <+104>: push %ebx
0x080485a4 <+105>: push %eax
0x080485a5 <+106>: call 0x8048400 <setreuid@plt>
0x080485aa <+111>: add $0x10,%esp
0x080485ad <+114>: sub $0xc,%esp
0x080485b0 <+117>: push $0x804867a
0x080485b5 <+122>: call 0x80483e0 <system@plt>
0x080485ba <+127>: add $0x10,%esp
0x080485bd <+130>: jmp 0x80485cf <main+148>
0x080485bf <+132>: sub $0xc,%esp
0x080485c2 <+135>: push $0x8048682
0x080485c7 <+140>: call 0x80483d0 <puts@plt>
0x080485cc <+145>: add $0x10,%esp
0x080485cf <+148>: mov $0x0,%eax
0x080485d4 <+153>: lea -0x8(%ebp),%esp
---Type <return> to continue, or q <return> to quit---
0x080485d7 <+156>: pop %ecx
0x080485d8 <+157>: pop %ebx
0x080485d9 <+158>: pop %ebp
0x080485da <+159>: lea -0x4(%ecx),%esp
0x080485dd <+162>: ret
End of assembler dump.
(gdb)
gdb 툴을 사용하여 leviathan6을 실행시킨 후 main 함수를 disassembly 시켰을 때 아래와 같이 main+27 부근해서 인자값과 특정 값을 비교하고 있다.
0x0804854f <+20>: movl $0x1bd3,-0xc(%ebp)
0x08048556 <+27>: cmpl $0x2,(%eax)
0x08048559 <+30>: je 0x804857b <main+64>
main+27에 breakpoint를 건 후에 %ebp-0xc에 들어있는 값을 확인해보자
(gdb) b *main+27
Breakpoint 1 at 0x8048556
(gdb) r 1234
Starting program: /tmp/test6/leviathan6 1234
Breakpoint 1, 0x08048556 in main ()
(gdb) info reg ebp
ebp 0xffffd688 0xffffd688
(gdb) x/10xw 0xffffd688-0xc
0xffffd67c: 0x00001bd3 0xffffd6a0 0x00000000 0x00000000
0xffffd68c: 0xf7e2a286 0x00000002 0xf7fc5000 0x00000000
0xffffd69c: 0xf7e2a286 0x00000002
(gdb) p 0x1bd3
$1 = 7123
(gdb)
leviathan6 에서는 7123과 인자값을 비교하고 있다. 이제 다시 leviathan6의 인자값으로 7123을 넘겨보자
leviathan6@leviathan:~$ ./leviathan6 7123
$ id
uid=12007(leviathan7) gid=12006(leviathan6) groups=12006(leviathan6)
$
바이너리에 7123를 넘긴 후 실행시켰더니 쉘을 획득했다. /etc/leviathan_pass/leviathan7 파일을 확인해보자
$ cat /etc/leviathan_pass/leviathan7
ahy7MaeBo9
$
password를 획득했다.
id: leviathan7
pw: ahy7MaeBo9