T09 · Insecure Skill Coding Practices
- Location
scripts/fofa_query.py:319- Finding
FOFA API Credential Exposure Through Command-Line Arguments
- Content
View full analysis
Vulnerability Details
File Location:
scripts/fofa_query.py:319-323
Vulnerability Type: Command-line secret exposure
Risk Level: Mediumpython parser.add_argument( "--api-key", help="FOFA API 凭证(email:key 格式),不指定则从环境变量读取" )The supplied value is subsequently passed to the client:
python client = FOFAQuery(api_key=args.api_key)Technical Analysis
The script permits the FOFA email and API key to be supplied as a plaintext command-line argument, for example:
bash python scripts/fofa_query.py --api-key 'user@example.com:secret-key' -q 'domain="example.com"'Command-line arguments may be exposed through process inspection facilities, system monitoring and auditing tools, shell history, terminal logs, CI/CD logs, or Agent tool-call records. Consequently, users who select this supported authentication method may unintentionally disclose the complete FOFA credential.
The script already supports retrieving the credential from
FOFA_API_KEY, so accepting the secret through the command line is unnecessary for its declared functionality and increases the local exposure surface.The Base64 encoding at
scripts/fofa_query.py:53-56is not itself a confirmed exfiltration vulnerability. It constructs an authentication value that is placed in theAuthorizationheader and sent over HTTPS exclusively to the fixed FOFA API endpoint. The encoded credential is not written to standard output by the reviewed code.Attack Path
- A user or Agent invokes the script using the supported
--api-keyoption. - The plaintext
email:keycredential becomes part of the process command line. - The command is retained in shell history, execution logs, Agent tool-call logs, or system audit records, or is observed through local process inspection while running.
- An attacker with access to one of those data sources extracts the credential.
- The attacker reuses it to authenticate to the FOFA API.
This path requires local pro ...[truncated 687 chars]
- A user or Agent invokes the script using the supported
- Remediation
View remediation
Remediation Suggestions
- Remove the
--api-keycommand-line option and retrieve the credential exclusively fromFOFA_API_KEYor an approved secret-management system. - If interactive credential entry is required, use
getpass.getpass()so the secret is not echoed or placed in process arguments. - Explicitly document that credentials must never be supplied in shell commands, logs, query text, or Agent prompts.
- Avoid logging complete command lines in automation that invokes the Skill.
- If compatibility requires retaining
--api-key, deprecate it immediately, display a security warning, and migrate callers to environment- or secret-manager-based authentication. - Rotate any FOFA credential previously supplied through command-line arguments if command histories or execution logs may have been retained.
- Remove the
