T05 · Unauthorized Access and Privilege Escalation
- Location
examples/ssh-key-sharing.md:167- Finding
Remote Account Creation and Passwordless Sudo Delegation
- Content
View full analysis
&1 | grep "Wormhole code is:" | cut -d' ' -f4) # 4. Add public key to server print_status "Adding public key to server..." ssh root@$SERVER "mkdir -p /home/$USERNAME/.ssh && chmod 700 /home/$USERNAME/.ssh && echo '$(cat $TEMP_DIR/$USERNAME-key.pub)' > /home/$USERNAME/.ssh/authorized_keys && chmod 600 /home/$USERNAME/.ssh/authorized_keys && chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh" # 5. Grant sudo access (optional) print_status "Granting sudo access..." ssh root@$SERVER "echo '$USERNAME ALL=(ALL) NOPASSWD:/usr/bin/apt-get' >> /etc/sudoers.d/$USERNAME" ``` ### Technical Analysis The workflow does substantially more than transfer an SSH key. It connects to a remote server as `root`, creates a persistent login account, replaces that account's `authorized_keys`, and unconditionally installs a passwordless sudo rule. Although the comment calls sudo access optional, the command is executed without an option, confirmation prompt, or policy check. Allowing passwordless execution of `apt-get` as root is especially dangerous because package-manager invocation can commonly be adapted to execute arbitrary commands or package installation hooks with root p ...[truncated 1100 chars]- Remediation
View remediation
