Back to skill

Security audit

MT5 Headless Automation

Security checks for vulnerabilities and agentic risk

Overview

This skill is mostly transparent about MT5 automation, but it requests unrelated Telegram credential/network access and uses broad automatic MT5 process restarts that could disrupt trading sessions.

Review carefully before installing. Use only on an isolated VPS or dedicated account, remove the unused Telegram permission unless you explicitly add alerting, test with demo or read-only accounts first, and replace broad pkill restarts with PID- or service-scoped control before using it around real trading sessions.

Vulnerability Patterns
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
Findings (5)

T05 · Unauthorized Access and Privilege Escalation

Warning
Location
SKILL.md:4
Finding

Unnecessary Access to Telegram Credentials and External Network Endpoint

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, line 4
Vulnerability Type: Excessive file and network permissions
Risk Level: Medium

Vulnerable Code

yaml
metadata: {"mt5-headless-automation": {"requires": {"bins": ["wine", "xvfb", "xdotool", "tesseract", "scrot", "sudo"], "files": ["~/.config/tg-alert.env"], "env": ["MT5_ACCOUNT", "MT5_PASSWORD"]}, "permissions": {"exec": ["bash", "wine", "xvfb-run", "xdotool", "import", "tesseract", "sudo"], "network": ["api.telegram.org"], "files": ["/tmp", "~/.config/tg-alert.env"], "notes": "GUI automation (xdotool) sends keystrokes to the MT5 window — verify the correct window has focus before running. Screenshots (import -window root) capture the ENTIRE display and may contain trading data, account details or other sensitive on-screen content — treat as sensitive artifacts: they are written to a private mktemp dir and auto-removed on exit. Keep keys scoped and never log them."}}}

Technical Analysis

The skill requests access to ~/.config/tg-alert.env and outbound connectivity to api.telegram.org, but none of the supplied scripts reads this configuration file or communicates with Telegram. These capabilities are unrelated to EA attachment, deployment, compilation, heartbeat monitoring, or MT5 restart operations.

The configuration therefore violates the principle of least privilege. A Telegram environment file commonly contains a bot token, chat identifier, or related credentials. Combining access to that file with access to the Telegram API creates a potential credential-use or data-exfiltration channel.

No supplied script currently performs the exfiltration step, so this finding concerns the excessive authorization boundary rather than confirmed transmission of data.

Attack Path

  1. The skill is installed or authorized using the permissions declared in its metadata.
  2. The runtime grants the skill access to ~/.config/tg-alert.env.
  3. The runtime a ...[truncated 744 chars]
Remediation
View remediation

Remediation Suggestions

  • Remove ~/.config/tg-alert.env from both the required files and permitted files lists.
  • Remove api.telegram.org from the network permissions.
  • If Telegram alerting is added later, isolate it as an optional, separately reviewed feature.
  • Grant access only after explicit user consent and only while the alert feature is enabled.
  • Use a narrowly scoped bot token and a dedicated destination chat.
  • Never expose the token through command-line arguments, logs, screenshots, or world-readable files.

T05 · Unauthorized Access and Privilege Escalation

Warning
Location
scripts/attach_ea.sh:10
Finding

Full Virtual Display Captured for Limited OCR Operation

Content
View full analysis

Vulnerability Details

File Location: scripts/attach_ea.sh, lines 10–12
Vulnerability Type: Excessive collection of sensitive display content
Risk Level: Medium

Vulnerable Code

bash
TMPD=$(mktemp -d /tmp/mt5ea.XXXXXX); export TMPD
trap "rm -rf "$TMPD"" EXIT
import -window root "$TMPD/nav.png" 2>/dev/null

The subsequent OCR code only needs the left portion of that screenshot:

python
img = Image.open(os.environ['TMPD'] + '/nav.png')
crop = img.crop((0,0,400,720)).resize((1200,2160), Image.LANCZOS)
crop.save(os.environ['TMPD'] + '/nav_big.png')

Technical Analysis

import -window root captures the entire X root display even though the OCR operation only processes a 400-by-720 region. The captured image may contain MT5 account information, trading positions, credentials displayed by another application, terminal output, or other sensitive content sharing the X display.

mktemp -d appropriately creates a private temporary directory under normal conditions. However, the full screenshot remains on disk until the script exits. The EXIT trap does not execute after SIGKILL, a system crash, or abrupt host termination. The trap also uses fragile nested double quoting:

bash
trap "rm -rf "$TMPD"" EXIT

This expands the path when the trap is registered rather than safely preserving a quoted cleanup command. Although the generated path does not normally contain spaces, robust cleanup should avoid this construction.

No code was found that transmits the screenshot externally.

Attack Path

  1. A user runs attach_ea.sh on an X display containing sensitive information.
  2. The script captures the complete root display into /tmp/mt5ea.XXXXXX/nav.png.
  3. The process is terminated with SIGKILL, the machine crashes, or cleanup otherwise does not run.
  4. The full screenshot remains on disk.
  5. A process or user with sufficient host privileges locates and reads the ...[truncated 479 chars]
Remediation
View remediation

Remediation Suggestions

  • Capture only the MT5 Navigator window or the precise required screen geometry rather than the root display.
  • Resolve and validate the intended MT5 window identifier before taking the screenshot.
  • Perform cropping in memory where practical, avoiding storage of the original full-display image.
  • Register cleanup with robust quoting, for example:
    bash
    trap 'rm -rf -- "$TMPD"' EXIT HUP INT TERM
    
  • Explicitly set restrictive permissions with umask 077.
  • Validate that the selected display and window belong to the expected MT5 session before capturing content.
  • Consider storing temporary artifacts in a private runtime directory instead of a shared /tmp hierarchy.

T09 · Insecure Skill Coding Practices

Error
Location
scripts/deploy_ea.sh:16
Finding

Deployment Terminates All Matching MT5 Processes

Content
View full analysis

Vulnerability Details

File Location: scripts/deploy_ea.sh, line 16
Vulnerability Type: Overbroad process termination
Risk Level: High

Vulnerable Code

bash
echo "3) Genstart MT5"
pkill -f "terminal64.exe"; sleep 3
wine "$MT5/terminal64.exe" /portable & sleep 20

Technical Analysis

pkill -f matches the supplied pattern against complete process command lines. The generic pattern terminal64.exe is not constrained to the expected executable path, Wine prefix, deployment instance, or recorded process identifier.

Consequently, the command can terminate every matching MT5 process available to the invoking user. A host running multiple MT5 terminals can therefore lose unrelated trading sessions when one EA is deployed. The project documentation recognizes the danger of pkill -f self-matching but does not address collateral termination of legitimate processes.

Attack Path

  1. One or more unrelated MT5 instances run under the same operating-system account.
  2. An operator or automation invokes deploy_ea.sh.
  3. The script executes pkill -f "terminal64.exe".
  4. Every accessible process whose full command line contains terminal64.exe receives the termination signal.
  5. Unrelated MT5 sessions stop, potentially detaching EAs or interrupting trading operations.

An attacker able to trigger the deployment script could use this behavior as a denial-of-service mechanism against same-user MT5 sessions.

Impact Assessment

The command does not elevate operating-system privileges; it is limited to processes the invoking identity is permitted to signal. Within that boundary, it can terminate unrelated trading terminals and disrupt multiple strategies, accounts, or sessions. Potential consequences include monitoring gaps, detached automation, missed actions, and financial loss.

Remediation
View remediation

Remediation Suggestions

  • Record the PID of the MT5 instance when it is launched and terminate only that validated PID.
  • Before sending a signal, verify /proc/$PID/exe, the command line, process owner, expected Wine prefix, and expected installation path.
  • Prefer a dedicated service manager unit for the intended MT5 instance.
  • Use graceful termination before escalating to stronger signals.
  • Run separate trading instances under distinct service identities or isolated Wine prefixes.
  • Abort deployment if the script cannot uniquely identify its managed process.

T09 · Insecure Skill Coding Practices

Error
Location
scripts/watchdog.sh:7
Finding

Watchdog Can Terminate Unrelated MT5 Sessions

Content
View full analysis

Vulnerability Details

File Location: scripts/watchdog.sh, lines 7–13
Vulnerability Type: Overbroad automated process termination
Risk Level: High

Vulnerable Code

bash
[ ! -f "$HB" ] && { echo "HB mangler — genstarter"; pkill -f "terminal64.exe"; wine "$MT5/terminal64.exe" & sleep 25; bash "$(dirname "$0")/attach_ea.sh" "$EA"; exit; }
AGE=$(( $(date +%s) - $(stat -c %Y "$HB") ))
if [ "$AGE" -gt 90 ]; then
  echo "HB forældet ($AGE s) — genstarter MT5 + re-attach"
  pkill -f "terminal64.exe"; sleep 3
  wine "$MT5/terminal64.exe" & sleep 25
  bash "$(dirname "$0")/attach_ea.sh" "$EA"

Technical Analysis

The watchdog automatically invokes pkill -f "terminal64.exe" whenever the heartbeat is missing or older than 90 seconds. The process pattern is not tied to a PID, executable path, Wine prefix, or specific EA instance.

This is more hazardous than the equivalent deployment behavior because the watchdog is intended for repeated unattended execution. A missing heartbeat caused by filesystem latency, an incorrect EA name, a path mismatch, temporary startup delay, or an actual EA fault can initiate collateral termination of all same-user MT5 instances.

Attack Path

  1. Multiple MT5 instances run under the same operating-system identity.
  2. The monitored heartbeat file is absent or becomes older than 90 seconds.
  3. The watchdog executes pkill -f "terminal64.exe".
  4. All accessible matching MT5 processes are terminated, including unrelated instances.
  5. The watchdog starts only the configured terminal and attempts to attach one EA, leaving other sessions offline.

If an attacker can delete, rename, or prevent updates to the heartbeat file, the attacker can repeatedly trigger this denial-of-service behavior.

Impact Assessment

The affected privilege scope is the set of processes signalable by the watchdog's operating-system identity. Within that scope, multiple ...[truncated 183 chars]

Remediation
View remediation

Remediation Suggestions

  • Associate each heartbeat with a specific recorded and validated MT5 PID.
  • Terminate only the process proven to own the monitored EA instance.
  • Use a per-instance service manager unit and restart that unit instead of pattern-matching process names.
  • Require multiple failed heartbeat checks before restarting.
  • Distinguish a missing heartbeat caused by startup, filesystem, configuration, and process failures.
  • Add restart-rate limits and lock files to prevent concurrent watchdog executions or restart loops.
  • Log the validated PID, executable path, Wine prefix, and restart reason for incident review.

T09 · Insecure Skill Coding Practices

Error
Location
scripts/deploy_ea.sh:9
Finding

Deployment Can Report Success While Reusing a Stale EA Artifact

Content
View full analysis

Vulnerability Details

File Location: scripts/deploy_ea.sh, lines 9–24
Vulnerability Type: Failure masking and inadequate artifact verification
Risk Level: High

Vulnerable Code

bash
echo "1) Kopiér kildekode → MT5"
cp "$SRC"/*.mq5 "$SRC"/*.mqh "$MT5/MQL5/Experts/" 2>/dev/null

echo "2) Kompilér (MetaEditor)"
wine "$MT5/metaeditor64.exe" /compile:"$MT5/MQL5/Experts/$EA.mq5" /log 2>/dev/null | tail -1
grep -q "0 errors" "$MT5/MQL5/Experts/$EA.log" 2>/dev/null || { echo "KOMPILERINGSFEJL"; exit 1; }

echo "3) Genstart MT5"
pkill -f "terminal64.exe"; sleep 3
wine "$MT5/terminal64.exe" /portable & sleep 20

echo "4) ⚠️ Attach EA'en MANUELT (auto-attach svigter!)"
bash "$(dirname "$0")/attach_ea.sh" "$EA"

echo "5) Verificér"
echo "HB: $(stat -c '%y' "$MT5/MQL5/Files/${EA}_HB.txt" 2>/dev/null | cut -d. -f1)"
echo "ex5: $(md5sum "$MT5/MQL5/Experts/$EA.ex5" | cut -d' ' -f1)"

Technical Analysis

The script does not enable set -e or set -o pipefail. As a result:

  • Source-copy failures are suppressed with 2>/dev/null and do not stop deployment.
  • Shell globs can fail to match expected files while execution continues.
  • The compiler command is piped to tail, so without pipefail the pipeline status is generally the status of tail, not necessarily the compiler.
  • The existing compiler log is not removed before compilation.
  • Verification only searches for the text 0 errors; it does not establish that the log was generated by the current invocation.
  • The EX5 checksum is printed but never compared against a trusted or workspace artifact.
  • The heartbeat timestamp is printed without enforcing freshness or proving that it belongs to the newly compiled binary.

A failed copy or compilation can therefore be followed by validation against stale files. The terminal may restart and attach a previously existing EA while the deployment appears successful.

Attack Path

...[truncated 1165 chars]

Remediation
View remediation

Remediation Suggestions

  • Start the script with:
    bash
    set -euo pipefail
    
  • Validate that the source and destination directories exist and have expected ownership and permissions.
  • Use an explicit file list or find rather than relying on potentially unmatched globs.
  • Do not suppress copy or compiler errors; preserve diagnostic output in a deployment-specific log.
  • Remove or archive the old compiler log and output artifact before compilation.
  • Capture and validate the MetaEditor process exit status.
  • Require the compilation log and EX5 artifact to have timestamps newer than the deployment start time.
  • Compile into a staging directory and atomically replace the production artifact only after all checks pass.
  • Compare a modern digest such as SHA-256 against the expected build artifact instead of merely printing an MD5 value.
  • Validate that the post-restart heartbeat is fresh and was produced after deployment.
  • Abort before restarting MT5 if any copy, compile, hash, or freshness verification fails.
Vulnerability Patterns
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (4)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
70% confidence
Finding

Without declared permissions the skill's intent is opaque and cannot be validated.

Content

No source excerpt is available for this finding.

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
91% confidence
Finding

The skill explicitly requires sudo and system-level command execution, which creates a substantial attack surface if the skill, its scripts, or dependent commands are modified or misused. In this context the danger is amplified because the skill also handles credentials and can install packages, terminate processes, and manipulate a GUI session, so compromise could affect the host and expose secrets.

Content

Scanner excerpt · SKILL.md (reported line 3)May include surrounding context.

md
---
name: "mt5-headless-automation"
description: "Run MetaTrader 5 (MT5) fully headless on Linux/VPS: Wine + Xvfb + xdotool + OCR. Install, log in, attach EAs, deploy experts, monitor heartbeat and auto-restart. Built from real production experience (Vantage, 17 symbols, DRT-Axe EA). Perfect for traders who want to run EAs 24/7 without a screen. ⚠️ WARNING: runs system-level commands (wine, Xvfb, sudo apt), can restart MT5/terminate processes, and handles broker login credentials."
metadata: {"mt5-headless-automation": {"requires": {"bins": ["wine", "xvfb", "xdotool", "tesseract", "scrot", "sudo"], "files": ["~/.config/tg-alert.env"], "env": ["MT5_ACCOUNT", "MT5_PASSWORD"]}, "permissions": {"exec": ["bash", "wine", "xvfb-run", "xdotool", "import", "tesseract", "sudo"], "network": ["api.telegram.org"], "files": ["/tmp", "~/.config/tg-alert.env"], "notes": "GUI automation (xdotool) sends keystrokes to the MT5 window — verify the correct window has focus before running. Screenshots (import -window root) capture the ENTIRE display and may contain trading data, account details or other sensitive on-screen content — treat as sensitive artifacts: they are written to a private mktemp dir and auto-removed on exit. Keep keys scoped and never log them."}}}
---

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
89% confidence
Finding

This section confirms the skill performs privileged package installation and process control, including restarting MT5 and terminating processes. Even though the behavior is disclosed, granting elevated execution to automation that also manages broker credentials and GUI keystrokes is inherently risky because mistakes or abuse can damage the system, interrupt trading, or leak sensitive data.

Content

Scanner excerpt · SKILL.md (reported line 13)May include surrounding context.

md
## ⚠️ Important (read first)

- **System-level actions:** this skill installs packages (sudo apt), starts Xvfb/Wine, and runs shell scripts. Review before running on production.
- **Restarts can interrupt trading:** the watchdog auto-restarts MT5 and may terminate EA processes during active sessions — this can detach strategies or affect open positions.
- **Credentials:** broker login (terminal64.exe via Wine) uses your MT5 account/password. They are entered into the terminal and may appear in process arguments or logs — store them in env vars or a protected file, never in scripts committed to git. Use a read-only/demo account for testing.
- **Built from production experience** — but backtest/production results are historical and not guaranteed.

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
90% confidence
Finding

The quick-start example instructs users to run sudo apt install directly, normalizing privileged shell execution as part of the skill workflow. While common for setup, this increases risk because users may execute the instructions without adequate review, and any later expansion of the command set or substitution in surrounding scripts could lead to host compromise or unsafe package installation.

Content

Scanner excerpt · SKILL.md (reported line 31)May include surrounding context.

bash
# 1) Environment
sudo apt install wine xvfb xdotool tesseract-ocr scrot
Xvfb :99 -screen 0 1280x720x24 &
export DISPLAY=:99