T09 · Insecure Skill Coding Practices
- Location
deploy.sh:25- Finding
Arbitrary Local Code Execution Through Python Source Injection
- Content
View full analysis
/dev/null; then echo "Error: Invalid JSON in template file" exit 1 fi # Read and optionally rename workflow WORKFLOW_JSON=$(cat "$TEMPLATE_FILE") if [[ -n "$WORKFLOW_NAME" ]]; then WORKFLOW_JSON=$(echo "$WORKFLOW_JSON" | python3 -c "import json,sys; d=json.load(sys.stdin); d['name']='$WORKFLOW_NAME'; print(json.dumps(d))") fi ``` ### Technical Analysis The script interpolates the attacker-influenced `TEMPLATE_FILE` and `WORKFLOW_NAME` values directly into source code passed to `python3 -c`. Shell quoting does not make these values safe inside the resulting Python program. Single quotes included in either argument become Python syntax and can terminate the intended string literal. An attacker can then append arbitrary Python statements, including calls to `os.system`, `subprocess`, or APIs for reading and transmitting local files. The template filename issue requires the crafted filename to refer to an existing file because the script checks it with `[[ -f "$TEMPLATE_FILE" ]]`. However, an attacker who can create or supply a template file can choose a filename containing Python metacharacters. The workflow-name argument is directly exploitable without that constraint. ### Attack Path 1. An attacker creates a valid workflow JSON file or convinces the user to deploy an attacker-supplied template. 2. The attacker supplies a workflow name containing a single quote and injected Python statements, or provides an existing template whose filename contains a Python injection payload. 3. The script embeds the malicious value in the `python3 -c` source string. 4. The injected statement executes when Python processes the generated program. 5. The malicious code run ...[truncated 1086 chars]- Remediation
View remediation
