T09 · Insecure Skill Coding Practices
- Location
evaluate.sh:58- Finding
Terminal Output Injection Through Unsanitized Operation Description
- Content
View full analysis
Vulnerability Details
File Location:
evaluate.sh, lines 53–62; vulnerable output at line 58
Vulnerability Type: Terminal control-sequence injection
Risk Level: MediumVulnerable Code
bash # 输出结果 echo "" echo "═════════════════════════════════════════════════" echo " PC-OCS v1.0 操作风险评估结果" echo "═════════════════════════════════════════════════" echo "" echo "📋 操作描述: $OPERATION" echo "" echo -e "🔒 风险等级: ${COLOR}${LEVEL} (${NAME})\033[0m" echo "" echo "💡 建议措施: $ADVICE" echo "" echo "═════════════════════════════════════════════════"Technical Analysis
The
OPERATIONvariable originates directly from the first command-line argument and is emitted to the terminal without validation or escaping. Although the affected statement does not useecho -e, input can contain literal terminal control bytes, including ANSI escape sequences.When a compatible terminal receives these bytes, it may interpret them as commands rather than visible text. An attacker can consequently clear the screen, reposition the cursor, overwrite displayed content, manipulate terminal titles, insert misleading text, or obscure the genuine risk result.
This is terminal output injection, not shell command injection. Shell metacharacters contained in
OPERATIONare not evaluated as commands because the variable is quoted. The confirmed effect is limited to terminal presentation and any additional behavior supported by the terminal emulator.Attack Path
- An attacker prepares an operation description containing literal ANSI escape bytes or other terminal control characters.
- The attacker convinces a user or an integrating process to invoke
evaluate.shwith that description. - Line 58 expands
$OPERATIONand writes the attacker-controlled bytes to the active terminal. - The terminal interprets those bytes as control instructions.
- The attacker-controlled display can clear or overwrite authentic output and present a forged risk level or ...[truncated 745 chars]
- Remediation
View remediation
Remediation Suggestions
- Reject or encode control characters before displaying user-provided input, including C0, DEL, C1, and escape characters.
- Use
printfwith a fixed format string instead ofechofor predictable output behavior. - Preserve a separate raw value for classification if required, but use only the sanitized value for terminal presentation.
- Consider rendering non-printable bytes visibly, such as
\x1b, so users can inspect malicious input safely. - Add regression tests covering ESC, carriage return, backspace, newline, tab, and other terminal-control bytes.
A hardening approach is:
bash # Render non-printable input safely for terminal output. SAFE_OPERATION=$(printf '%s' "$OPERATION" | LC_ALL=C sed -n 'l' | sed 's/\$$//') printf '\n' printf '%s\n' '═════════════════════════════════════════════════' printf '%s\n' ' PC-OCS v1.0 Operation Risk Assessment' printf '%s\n' '═════════════════════════════════════════════════' printf '\n' printf 'Operation description: %s\n' "$SAFE_OPERATION"For stricter handling, terminate with an error when prohibited control bytes are detected rather than merely encoding them.
