T09 · Insecure Skill Coding Practices
- Location
scripts/configure_backup.sh:290- Finding
Arbitrary Command Execution Through Sourced Backup Configuration
- Content
View full analysis
Vulnerability Details
File Location:
scripts/configure_backup.sh:75-78, 290-303;scripts/manage_backup.sh:68-72, 134-138, 176-180, 205-209, 235-239
Vulnerability Type: Shell command injection through executable configuration
Risk Level: HighVulnerable Code
bash if [ -f "$CONFIG_FILE" ]; then source "$CONFIG_FILE" fibash cat > "$CONFIG_FILE" << EOF BACKUP_REPO_PATH=$BACKUP_PATH BACKUP_REMOTE_URL=$REMOTE_URL BACKUP_ENABLED=true LAST_BACKUP_TIME=$(get_beijing_time) EOFThe same writable configuration is repeatedly executed by the management script:
bash source "$CONFIG_FILE"Technical Analysis
The configuration wizard accepts a user-controlled backup path and repository URL, writes those values into a shell script without safe serialization, and later loads the file using
source.A sourced file is executable shell code, not passive configuration data. Consequently, shell syntax persisted in
BACKUP_REPO_PATHorBACKUP_REMOTE_URLwill be interpreted when the configuration is loaded. Quoting variables when they are subsequently used does not mitigate execution that already occurred duringsource.For example, a backup path containing a literal command substitution can result in a generated assignment equivalent to:
bash BACKUP_REPO_PATH=$(attacker_command)The command runs the next time
configure_backup.shormanage_backup.shsources the file.Attack Path
- An attacker or untrusted input channel supplies a custom backup path or repository URL containing shell syntax.
configure_backup.shaccepts the value and writes it into.backup_configas an unquoted shell assignment.- The user later invokes configuration or backup-management functionality.
- The script executes
source "$CONFIG_FILE". - Bash interprets the injected syntax and executes the attacker-selected command with the privileges of the Agen ...[truncated 667 chars]
- Remediation
View remediation
Remediation Suggestions
- Replace the shell configuration file with a non-executable format such as JSON.
- Parse individual fields with
jq; never load writable configuration usingsource,., oreval. - Validate backup paths as absolute paths under an explicitly approved parent directory.
- Reject control characters, newlines, shell metacharacters, command substitutions, and unsupported URL schemes.
- Write configuration atomically with restrictive permissions such as
0600. - If a shell-compatible format is temporarily unavoidable, serialize every value with
printf '%q'; this should be an interim measure rather than a substitute for structured parsing. - Treat existing
.backup_configfiles as potentially unsafe and migrate them without sourcing their contents.
