Amazon AWS Bastion - Logger Bypass
The AWS bastion host used a read-only PROMPT_COMMAND in /etc/bashrc to log commands, but several techniques allowed a user to bypass this logging and execute commands without being recorded. An attacker with access to the bastion could therefore run commands undetected.
Published on pulsesecurity.co.nz
The AWS bastion host (https://github.com/aws-quickstart/quickstart-linux-bastion) is intended to provide command logging for all users. These command logs are stored both on the bastion host itself, and forwarded to Cloudwatch.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the logging relied on a shell configuration file and environment variable that the user could circumvent by starting a different shell, changing the PATH, or running commands non-interactively.
Impact
A user with access to the bastion could execute commands without them being logged, defeating the audit trail; the SSH non-interactive bypass was mitigated when harden_ssh_security was enabled.
What the attacker needed
Access to the bastion host as a user
The fix
The issues were fixed by switching to the Linux auditing framework to log all execve system calls, so a bypass would now require root access to disable the rules.
How it was found
- Log in to the bastion host as a normal user.
- Start a bash shell with the --posix flag to cause PROMPT_COMMAND parsing to fail.
- Unset PROMPT_COMMAND so subsequent commands are not logged.
- Alternatively, create a fake logger executable in the current directory and prepend it to PATH.
- Alternatively, start a new bash with --norc --noprofile and unset PROMPT_COMMAND.
- Alternatively, upload a different shell (e.g., dash) and run it interactively, or execute a command directly over SSH.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A bastion host is a server you log into first before reaching other systems, and it is supposed to record every command you type. The logging was set up in a way that could be turned off or avoided, so someone with an account could run commands without them appearing in the log.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.