Back to skill

Security audit

smb-auto-mount

Security checks for vulnerabilities and agentic risk

Overview

The skill does what it claims, but it needs review because it uses root access to make persistent SMB mount changes and has unsafe handling of user-supplied mount fields and temporary credentials.

Install only if you are comfortable giving the scripts sudo access to change system mount configuration and store SMB credentials on disk. Review and harden the scripts first for shared or automated use: validate all mount fields, add cleanup traps for temporary credential files, back up /etc/fstab, and remove stale /etc/smb-creds-* files when no longer needed.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
add-to-fstab.sh:39
Finding

Unvalidated SMB target fields allow persistent /etc/fstab injection

Content
View full analysis
> /etc/fstab ``` ### Technical Analysis The script validates `LOCAL_NAME`, but does not validate `IP` or `SHARE` before incorporating them into a root-owned `/etc/fstab` entry. Replacing spaces in `SHARE` with `\040` does not neutralize tabs, newlines, carriage returns, backslashes, or other characters with structural meaning in an fstab file. Shell quoting prevents ordinary shell command injection, but it does not prevent configuration injection. A newline embedded in `IP` or `SHARE` remains present when `echo` appends `FSTAB_ENTRY`. An attacker who can influence arguments supplied to this privileged script can therefore terminate the intended record and introduce additional fstab records. The result is persistent because `/etc/fstab` is processed across reboots and the script subsequently reloads systemd. The declared persistent automount feature is legitimate, but accepting unvalidated data when constructing its privileged configuration exceeds safe implementation requirements. `USERNAME` is also written without validation to a credentials file. Embedded line breaks could alter that file's directive structure, although the more severe persistent system configuration issue is caused by `IP` and `SHARE`. ### Attack Path 1. ...[truncated 1428 chars]
Remediation
View remediation

T09 · Insecure Skill Coding Practices

Warning
Location
mount-smb.sh:22
Finding

Failed one-time mounts leave plaintext SMB credentials in a temporary file

Content
View full analysis
"$CREDS_FILE" # Get UID/GID dynamically (fallback to 1000/1000) USER_ID=${SUDO_UID:-1000} GROUP_ID=${SUDO_GID:-1000} mount -t cifs "//$IP/$SHARE" "$MOUNTPOINT" -o "credentials=$CREDS_FILE,uid=$USER_ID,gid=$GROUP_ID,file_mode=0755,dir_mode=0755,iocharset=utf8" rm -f "$CREDS_FILE" ``` The script also enables immediate error termination at line 2: ```bash set -e ``` ### Technical Analysis The script stores the SMB username and password in plaintext in a file created by `mktemp`. The file is restricted to mode `600`, which appropriately prevents access by ordinary unprivileged users when the script is run as root. However, cleanup occurs only after the `mount` command succeeds. Because `set -e` is active, any nonzero exit status from `mount` terminates the script before `rm -f "$CREDS_FILE"` executes. Interruptions or termination signals can produce the same result because no cleanup trap is registered. Consequently, a failed mount can leave a root-readable plaintext credential file in the temporary directory for an indefinite period, or until external temporary-file cleanup occurs. ### Attack Path 1. A user runs `mount-smb.sh` and enters valid SMB credentials. 2. The CIFS mount fails because the server is unavailable, the share is invalid, authentication fails, the destination is unsuitable, or another mount error occurs. 3. `mount` returns a nonzero status. 4. `set -e` immediately terminates the script. 5. The cleanup statement is skipped, leaving the temporary file containing the username and password on disk. 6. A later root-level process, privileged user, backup operation, diagnostic collection process, or compromised pri ...[truncated 762 chars]
Remediation
View remediation
"$CREDS_FILE" mount -t cifs "//$IP/$SHARE" "$MOUNTPOINT" \ -o "credentials=$CREDS_FILE,uid=$USER_ID,gid=$GROUP_ID,file_mode=0755,dir_mode=0755,iocharset=utf8" ``` Additional hardening should include: 1. Set `umask 077` before creating any secret-bearing temporary resource. 2. Verify that `mktemp` succeeds before writing credentials. 3. Clear the shell password variable after it is no longer needed: ```bash unset PASSWORD ``` 4. Keep the credential file open for the shortest possible period. 5. Apply equivalent trap-based cleanup to `list-shares.sh`, which also uses a temporary plaintext credential file and could otherwise retain it if the process is interrupted before its final `rm`. ]]>
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Rogue AgentSelf-Modification, Session Persistence
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (15)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 27)May include surrounding context.

bash
# Backup fstab before using add-to-fstab.sh
sudo cp /etc/fstab /etc/fstab.backup.$(date +%Y%m%d)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 36)May include surrounding context.

bash
# Backup fstab before using add-to-fstab.sh
sudo cp /etc/fstab /etc/fstab.backup.$(date +%Y%m%d)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 58)May include surrounding context.

bash
# Backup fstab before using add-to-fstab.sh
sudo cp /etc/fstab /etc/fstab.backup.$(date +%Y%m%d)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 67)May include surrounding context.

bash
# Backup fstab before using add-to-fstab.sh
sudo cp /etc/fstab /etc/fstab.backup.$(date +%Y%m%d)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 105)May include surrounding context.

bash
# Backup fstab before using add-to-fstab.sh
sudo cp /etc/fstab /etc/fstab.backup.$(date +%Y%m%d)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 115)May include surrounding context.

bash
# Backup fstab before using add-to-fstab.sh
sudo cp /etc/fstab /etc/fstab.backup.$(date +%Y%m%d)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 124)May include surrounding context.

bash
# Backup fstab before using add-to-fstab.sh
sudo cp /etc/fstab /etc/fstab.backup.$(date +%Y%m%d)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 62)May include surrounding context.

md
Enter SMB Password: [hidden input]

# 2. Persistent automount (mounts on first access)
sudo ./add-to-fstab.sh 192.168.2.3 workspace my-work Administrator
Enter SMB Password: [hidden input]
ls /mnt/smb/my-work    # triggers mount

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · SKILL.md (reported line 119)May include surrounding context.

md
Enter SMB Password: [hidden input]

# 2. Persistent automount (mounts on first access)
sudo ./add-to-fstab.sh 192.168.2.3 workspace my-work Administrator
Enter SMB Password: [hidden input]
ls /mnt/smb/my-work    # triggers mount

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The script stores the SMB username and password in a root-readable credentials file under /etc without clearly informing the user that their password will be persisted on disk. Although permissions are restricted, persistent credential storage increases exposure if the host is later compromised, backed up insecurely, or the file is left behind after the share is no longer needed.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The script appends a new entry to /etc/fstab, which is a persistent system configuration change affecting future boots and mount behavior, but it does so without an explicit confirmation or warning to the user. In an agent-skill context, silent persistence is security-relevant because it can surprise users, create unwanted automount behavior, and make recovery harder if the entry is malformed or maliciously influenced.

Content

No source excerpt is available for this finding.

Session Persistence

Medium
Category
Rogue Agent
Confidence
89% confidence
Finding

Enabling a systemd automount unit creates persistent behavior that survives beyond the current session, causing the share to be automatically mounted on future access. In a skill context, this increases risk because it establishes ongoing system behavior without an explicit opt-in, and if combined with bad parameters or compromised network shares it broadens long-term exposure.

Content

Scanner excerpt · add-to-fstab.sh (reported line 52)May include surrounding context.

sh
echo "$FSTAB_ENTRY" >> /etc/fstab
systemctl daemon-reload
systemctl enable "$(systemd-escape -p "$MOUNTPOINT").automount" 2>/dev/null || true

echo "Added: $LOCAL_NAME -> $MOUNTPOINT (uid=$USER_ID, gid=$GROUP_ID)"

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
80% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · add-to-fstab.sh (reported line 39)May include surrounding context.

sh
# Use temp credentials file to avoid password in ps
CREDS=$(mktemp)
chmod 600 "$CREDS"
printf '%s\n' "username=$USER" "password=$PASSWORD" > "$CREDS"

smbclient -L "$IP" -A "$CREDS" 2>&1 | grep -E '^\s+[A-Za-z]' | grep -v Sharename || true

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
80% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · list-shares.sh (reported line 21)May include surrounding context.

sh
# Use temp credentials file to avoid password in ps
CREDS=$(mktemp)
chmod 600 "$CREDS"
printf '%s\n' "username=$USER" "password=$PASSWORD" > "$CREDS"

smbclient -L "$IP" -A "$CREDS" 2>&1 | grep -E '^\s+[A-Za-z]' | grep -v Sharename || true

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
80% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · mount-smb.sh (reported line 27)May include surrounding context.

sh
# Use temp credentials file to avoid password in ps
CREDS=$(mktemp)
chmod 600 "$CREDS"
printf '%s\n' "username=$USER" "password=$PASSWORD" > "$CREDS"

smbclient -L "$IP" -A "$CREDS" 2>&1 | grep -E '^\s+[A-Za-z]' | grep -v Sharename || true