T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/check_domains.sh:56
- Finding
- Terminal and Log Output Injection in the Bash Domain Checker<![CDATA[ ## Vulnerability Details **File Location**: `scripts/check_domains.sh:56-74, 78-95` **Vulnerability Type**: Improper neutralization of terminal control and backslash escape sequences **Risk Level**: Medium ### Vulnerable Code ```bash # --- Cross-verify and decide --- if [ -n "$created" ]; then # whois shows creation date = definitely taken printf "${RED}❌ %-30s TAKEN %s${NC}\n" "$domain" "$created" elif [ -n "$not_found" ] && [ -z "$ns" ]; then # whois says not found AND no NS records = very likely available printf "${GREEN}✅ %-30s AVAILABLE${NC}\n" "$domain" elif [ -n "$not_found" ] && [ -n "$ns" ]; then # whois says not found but has NS = conflicting signals, likely taken printf "${YELLOW}⚠️ %-30s LIKELY TAKEN (has NS: %s)${NC}\n" "$domain" "$ns" elif [ -n "$ns" ] || [ -n "$a_record" ]; then # No whois creation date but has DNS records = likely taken printf "${YELLOW}⚠️ %-30s LIKELY TAKEN (has DNS records)${NC}\n" "$domain" else # No whois data, no DNS = unknown (whois may have failed) printf "${YELLOW}❓ %-30s UNKNOWN (whois returned no data — check manually)${NC}\n" "$domain" fi ``` ```bash # Read domains from args or stdin domains=() if [ $# -gt 0 ]; then domains=("$@") else while IFS= read -r line; do for word in $line; do domains+=("$word") done done fi # ... for d in "${domains[@]}"; do result=$(check_one "$d") echo -e "$result" ``` ### Technical Analysis The script accepts arbitrary command-line or standard-input values without validating that they are syntactically valid domain names. The value is included in a formatted verdict and stored in `result`. The statement `echo -e "$result"` then interprets backslash escape sequences contained in the attacker-controlled value. For example, textual sequences representing newlines, carriage returns, or terminal escape characters can be converted into control characters when the result is displayed. Literal terminal control characters are also n ...[truncated 1598 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Validate every input before performing WHOIS or DNS operations. Reject whitespace, control characters, escape characters, leading hyphens, empty labels, labels longer than 63 characters, and names longer than 253 characters. 2. Permit only normalized DNS syntax appropriate for the tool, such as ASCII letters, digits, hyphens, and dots, with hyphens prohibited at label boundaries. 3. Replace escape-interpreting output: ```bash echo -e "$result" ``` with literal output: ```bash printf '%s\n' "$result" ``` 4. Keep terminal color sequences separate from user-controlled data and use constant format strings. 5. Protect external commands from option injection where their implementations support an option delimiter: ```bash whois -- "$domain" dig +short -- "$domain" NS ``` If a utility does not support `--` in that position, strict rejection of leading-hyphen inputs is required. 6. Return structured verdict data from `check_one` rather than capturing preformatted terminal output and parsing it with `grep`. 7. Add regression tests covering textual `\n` and `\033` sequences, literal ESC bytes, carriage returns, leading hyphens, malformed labels, and oversized names. ]]>
