GitHub RCE by Environment variable injection Bug Bounty writeup
The SSH front-end for GitHub allowed a user to inject environment variables by including newlines in their username. By setting variables such as LD_PRELOAD and SSH_ASKPASS, an attacker could make the SSH client execute an arbitrary program, leading to remote code execution as the git user.
gist.github.com
Published on gist.github.com
Clone this repository at <script src="https://gist.github.com/joernchen/a7c031b6b8df5d5d0b61.js"></script> - Save joernchen/a7c031b6b8df5d5d0b61 to your computer and use it in GitHub Desktop.
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 SSH front-end did not sanitise the username before using it in a context where newlines were interpreted as environment variable assignments.
Impact
An attacker could execute arbitrary commands as the git user on GitHub's back-end server.
What the attacker needed
SSH access to github.com; ability to set a username with newlines
How it was found
- Connect to github.com over SSH with a username containing newline characters and environment variable assignments.
- The injected variables are passed to the forked SSH process that connects to the back-end server.
- Set LD_PRELOAD to a library that makes SSH believe it is root, and set SSH_ASKPASS and DISPLAY so SSH invokes the askpass program.
- Use /usr/bin/ex as the askpass program and, when it runs, execute a shell command to obtain a shell as the git user.
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.
When you connect to GitHub over SSH, a program checks your username and passes it to other programs. The bug was that the username could contain newlines, which let an attacker sneak in extra settings called environment variables. One of those settings made the SSH program run a different program chosen by the attacker, giving them a shell on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.