T09 · Insecure Skill Coding Practices
- Location
gene-trigger.sh:30- Finding
Arbitrary Python Code Execution Through Unsafe Argument Interpolation
- Content
View full analysis
/dev/null; then echo "❌ Gene '$1' 不存在" exit 1 fi echo "=== Gene Trigger Recorder ===" echo "Gene: $1" echo "结果: $RESULT" echo "描述: $OUTCOME" echo "时间: $NOW_ISO" echo "" # 更新JSON python3 -c " import json, sys with open('$GENE_FILE', 'r') as f: data = json.load(f) gene = data['$GENE_KEY'] now = '$NOW_ISO' # 更新基础字段 gene['lastTriggered'] = now gene['triggeredCount'] = gene.get('triggeredCount', 0) + 1 if gene.get('daysSinceLastTrigger') is None: gene['daysSinceLastTrigger'] = 0 if '$RESULT' == 'success': gene['lastResult'] = {'success': True, 'outcome': '''$OUTCOME'''} gene['consecutiveFailures'] = 0 gene['status'] = 'verified' gene['lastVerified'] = now # wakeUpRate: 每次成功都算改变判断 gene['activationCount'] = gene.get('activationCount', 0) + 1 else: gene['lastResult'] = {'success': False, 'error': 'trigger_failed', 'reason': '''$OUTCOME'''} gene['consecutiveFailures'] = gene.get('consecutiveFailures', 0) + 1 gene['totalFailures'] = gene.get('totalFailures', 0) + 1 gene['lastFailure'] = now ``` ### Technical Analysis The script assigns command-line arguments to `GENE_KEY`, `RESULT`, and `OUTCOME`, then inserts those values directly into Python source passed to `python3 -c`. Shell quoting does not make these values safe inside the generated Python program. An argument containing Python quote delimiters and additional syntax can terminate its intended string literal and introduce executable Python statements. The preliminary gene-key existence check is also vulnerable because `GENE_KEY` is interpolated into this Python expression: ```python assert '$GENE_KEY' in d ``` Consequently, the check cannot ...[truncated 1729 chars]- Remediation
View remediation
