T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:67
- Finding
- Persistent Plaintext SMB Credentials at a Predictable Root-Owned Path<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:67-72` **Vulnerability Type**: Plaintext credential storage and unsafe fixed file usage **Risk Level**: Medium ### Vulnerable Code ```bash # 1. Create credential file echo "username=$USERNAME" | sudo tee /root/.smbcredentials echo "password=$PASSWORD" | sudo tee -a /root/.smbcredentials sudo chmod 600 /root/.smbcredentials # 2. Mount sudo mount.cifs //SERVER_IP/share ~/mount_name -o credentials=/root/.smbcredentials,uid=1000,gid=1000 ``` ### Technical Analysis The workflow writes an SMB username and password in plaintext to the fixed path `/root/.smbcredentials`. Although the final permissions are set to mode `600`, the sensitive data remains persistently stored after the mount operation. The documented checklist only recommends deleting the file “if sensitive,” but all password-containing credential files are sensitive, and no cleanup command is supplied. The first `tee` invocation truncates `/root/.smbcredentials` if it already exists. Consequently, following this workflow can destroy credentials or configuration maintained by another process. Using a predictable global path also prevents safe isolation between concurrent or sequential mount operations. The password is passed through the standard input of `sudo tee`, rather than being included directly in the command-line arguments. This reduces shell-history exposure but does not address persistent plaintext storage, command logging by an executing Agent, or the risk of overwriting an existing file. ### Attack Path 1. A user requests an SMB mount and supplies a username and password. 2. The Agent substitutes the credentials into the documented commands. 3. `sudo tee /root/.smbcredentials` truncates any existing file at that path and writes the new username. 4. The password is appended in plaintext. 5. The SMB share is mounted using the credential file. 6. No mandatory cleanup operation removes the file after mounting, unmounting, or fa ...[truncated 876 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Create a unique credential file with `sudo mktemp` instead of using `/root/.smbcredentials`. - Establish restrictive permissions before writing any secret, rather than correcting permissions afterward. - Check that the destination does not already exist and never truncate a shared credential path. - Register a cleanup trap before writing the password so the temporary file is removed after success, failure, interruption, and unmounting. - Avoid displaying or recording the substituted command when it contains a password. - Prefer a protected existing credential provider, secret manager, or interactive mechanism when supported. - Make credential cleanup mandatory rather than conditional. - If persistent mounts are required, explicitly tell the user that credentials will remain on disk and obtain confirmation for that separate persistence decision. ]]>
