title: Malicious Go init() Function Spawning a Process via a Code-Generation Tool
id: ATR-2026-02194
rule_version: 1
status: experimental
description: |
  Detects Go source code submitted to a code-generation tool that declares a `func init()` containing a process-spawning call (os.StartProcess, exec.Command, or syscall.Exec). A Go `init()` function runs automatically the moment the package is loaded -- once this source reaches a build/compile step, the process launches with no further user action. Mined from GHSA-22cv-9jv2-6m62 (flipped-aurora/gin-vue-admin, "an AI-assisted basic development platform"): an authenticated attacker with access to the code-generation feature injects Go source via `POST /autoCode/addFunc`, then triggers `POST /autoCode/mcpStart` to rebuild and restart the generated MCP service, executing the injected `init()` (the disclosed PoC spawns `cmd.exe /c calc` via `os.StartProcess`). Generalizes beyond gin-vue-admin's two specific endpoints to any AI code-generation tool that compiles/loads attacker-supplied Go source without review. Ordinary `func init()` bodies used for benign setup (registering handlers, setting defaults, initializing maps) do not fire; only the combination with a process-spawn API does.
author: ATR Community (CVE sweep)
date: 2026/07/11
schema_version: '0.1'
detection_tier: pattern
maturity: experimental
severity: critical
references:
  cve:
    - CVE-2026-48787
  cwe:
    - CWE-94
  owasp_llm:
    - LLM05:2025
  owasp_agentic:
    - ASI02:2026
  mitre_attack:
    - T1059 - Command and Scripting Interpreter
  mitre_atlas:
    - AML.T0053 - LLM Plugin Compromise
  external:
    - https://github.com/flipped-aurora/gin-vue-admin/security/advisories/GHSA-22cv-9jv2-6m62
metadata_provenance:
  cve: human-reviewed
  cwe: human-reviewed
  owasp_llm: human-reviewed
  owasp_agentic: human-reviewed
  mitre_attack: human-reviewed
  mitre_atlas: human-reviewed
compliance:
  eu_ai_act:
    - article: '15'
      context: Article 15 (accuracy, robustness and cybersecurity) requires high-risk AI systems to resist unauthorised attempts to alter their behaviour; this rule detects a code-generation tool being weaponised with a self-executing malicious init() function.
      strength: primary
    - article: '9'
      context: Article 9 (risk management system) requires identified risks to be addressed by appropriate measures; this rule is a runtime risk-treatment control for the malicious-codegen-init-payload risk class.
      strength: secondary
  nist_ai_rmf:
    - subcategory: MG.2.3
      context: Treating a malicious auto-executing init() function injected via a code-generation tool as an identified AI risk requires active runtime countermeasures; this detection rule is the primary risk treatment implementation.
      strength: primary
    - subcategory: MP.5.1
      context: Identifying auto-executing code-generation payloads as an AI risk to be catalogued in the organizational risk register.
      strength: secondary
  iso_42001:
    - clause: '8.1'
      context: ISO/IEC 42001 Clause 8.1 (operational planning and control) is operationalised by this rule's detection of malicious code-generation payloads that execute on package load.
      strength: primary
    - clause: '8.3'
      context: ISO/IEC 42001 Clause 8.3 (AI risk treatment) is implemented via this rule's runtime detection of the injection attempt.
      strength: secondary
tags:
  category: tool-poisoning
  subcategory: malicious-codegen-init-payload
  scan_target: llm_io
  confidence: high
agent_source:
  type: llm_io
  framework:
    - any
  provider:
    - any
detection:
  condition: any
  conditions:
    - field: content
      operator: regex
      value: \bfunc\s+init\s*\(\s*\)\s*\{[\s\S]{0,40}\bos\.StartProcess\b
      description: Go func init() body directly calling os.StartProcess, spawning a process at package-load time
    - field: content
      operator: regex
      value: \bfunc\s+init\s*\(\s*\)\s*\{[\s\S]{0,40}\bexec\.Command\b
      description: Go func init() body directly calling exec.Command, spawning a process at package-load time
    - field: content
      operator: regex
      value: \bfunc\s+init\s*\(\s*\)\s*\{[\s\S]{0,40}\bsyscall\.Exec\b
      description: Go func init() body directly calling syscall.Exec, replacing the process image at package-load time
  false_positives:
    - A legitimate CLI wrapper's init() that re-execs itself under a different UID or namespace -- rare but real; still worth a human check given how uncommon and high-impact process-spawning init() functions are
    - Discussion/documentation showing this exact code pattern as a security example, without it being submitted to an actual code-generation/build tool
response:
  actions:
    - block_input
    - alert
  message_template: |
    [ATR-2026-02194] Go source submitted to a code-generation tool declares a func init() that spawns a process -- this executes automatically on package load with no further action; treat as an RCE attempt, not ordinary package initialization.
confidence: 82
