T09 · Insecure Skill Coding Practices
- Location
scripts/thunderlink.py:14- Finding
Terminal Escape-Sequence Injection Through Decoded Link Output
- Content
View full analysis
Vulnerability Details
File Location:
scripts/thunderlink.py, lines 14–15 and 38
Vulnerability Type: Unsanitized terminal output
Risk Level: MediumVulnerable Code
python def _b64decode(data: str) -> str: pad = -len(data) % 4 return base64.b64decode(data + "=" * pad).decode("utf-8", "replace")python try: print(decode(value) if action == "decode" else encode(value)) except Exception as e: print(f"错误: {e}", file=sys.stderr) sys.exit(2)Technical Analysis
The Base64 content of a
thunder://,qqdl://, orflashget://link is attacker-controlled. The decoder converts arbitrary decoded bytes into a string and prints that string directly to standard output without filtering terminal control characters or verifying that the result is a valid URL.Consequently, a malicious payload can contain ANSI CSI sequences, OSC sequences, or other C0/C1 control characters. When the command runs in a compatible interactive terminal, the terminal may interpret those characters as commands rather than display them as inert text.
The Thunder wrapper check does not prevent exploitation because an attacker can place control sequences between the expected
AAandZZmarkers. The QQDL decoder has no wrapper requirement, while the FlashGet decoder only removes occurrences of[FLASHGET].Attack Path
- An attacker constructs a string containing a terminal escape sequence, optionally embedded in text resembling a URL.
- The attacker adds the format-specific wrapper where needed and Base64-encodes the string.
- The attacker distributes the resulting
thunder://,qqdl://, orflashget://link. - A user or agent invokes
python3 scripts/thunderlink.py decode '<crafted-link>', consistent with the documented workflow. _b64decode()converts the hostile bytes into a Python string.main()sends the decoded string directly to standard output with ...[truncated 824 chars]
- Remediation
View remediation
Remediation Suggestions
- Validate decoded results against an explicit allowlist of supported URL schemes, such as
http,https,ftp, or another deliberately supported set. - Reject decoded strings containing C0 or C1 control characters, including
ESC, except for any characters explicitly required by the accepted format. - Reject carriage returns and line feeds if each invocation is expected to produce exactly one URL.
- Preserve the format wrappers strictly:
- Require
AA...ZZfor Thunder links instead of returning unwrapped data. - Require exact
[FLASHGET]... [FLASHGET]framing rather than globally replacing marker text.
- Require
- If arbitrary decoded data must remain supported, render unsafe characters in an escaped form, such as
\x1b, instead of printing them literally. - Add tests covering ANSI CSI sequences, OSC sequences, embedded newlines, null bytes, malformed wrappers, and non-URL decoded values.
- Validate decoded results against an explicit allowlist of supported URL schemes, such as
