Hack this repository: The EkoParty 2020 GitHub CTF challenges | GitHub Security Lab
skip to content Resources Open Source Community Enterprise / Security Lab Research Advisories CodeQL Wall of Fame Resources Open Source Community Enterprise Events Get Involved The GitHub Security Lab recently contributed a set of challenges to the main Capture The Flag for EkoParty 2020. EkoParty is a popular LATAM information security conference and its CTF always draws the attention of many teams from across the world.
This year was no exception, and there were almost 400 active teams participating in the EkoParty CTF, which ran from September 24 to 26. If you’re not familiar with CTF competitions, they are hacking competitions in which teams of players race each other to complete a set of security-related challenges. These challenges can vary wildly but generally revolve around binary exploitation, cryptanalysis, logic issues, and web application vulnerabilities.
Solving a challenge unlocks a unique flag, which can then be claimed for points with the CTF organizer. The team that submits all the flags first, or has the most points at the completion of the competition, wins. For this year’s EkoParty CTF, GitHub sponsored the first prize of $1,000USD, and the winning team also received five tickets to the next edition of EkoParty. Missed the CTF? No problem. In this post we will run through the three GitHub-developed challenges and their solutions, as well as examine some of the lessons learned.
When designing the GitHub challenges, we wanted the player to experience a storyline that was reality-based and exposed them to a variety of GitHub platform features and associated security considerations. Through the challenges, we wanted to tell a story that involved commit attestation, branch protection, GitHub deploy keys, GitHub secret scanning, GitHub Actions, and issue comment edit histories. The GitHub challenges consisted of three interconnected stages named Leak, Docs, and Env.
Out of the hundreds of active teams, 35 were able to solve all three challenges. Stage 1 - Git history repeats itself As an entry point to the game, players were presented with a single external GitHub repository at https://github.com/ekoparty2020. This account was created by the GitHub Security Lab team and presented itself as an EkoParty organizers’ (@mattareal) git repository. We carefully crafted a git commit history using @mattareal’s GitHub email address, which was obtained from their public commit history on their actual account.
The GitHub UI will resolve which GitHub user account to display for commits, based on data provided by the committer. As such, it is fairly straightforward to forge a visually convincing commit history that involves arbitrary GitHub accounts. This isn’t intrinsic to GitHub but rather an artifact of how git itself works. GitHub faithfully renders and displays git commit histories for a given repository but does not control that history itself.
This is why we recommend that GitHub users sign their commits . However, even with signed commits, one could e.g. set the author to be an arbitrary account while retaining a visual verification based on the committer information and signature which you also control. In this case, the commit would appear to be stacked between your legitimate committer account that provides the signing key and the spoofed author account, while still retaining the “verified” mark.
This is, again, simply an artifact of how git works, since it treats authors and committers as separate data points. The main takeaway from this is that git history is entirely malleable. It is not a source of absolute truth. If someone has write privileges on a repo, they can reshape history in any way they see fit. From a security perspective, you can not depend on git histories alone for verification of who originally contributed code or when they did it.
By taking a closer look at this forged commit history, a player would be able to see a commit marked “oops”. This commit contained a leaked secret in the form of a read-only SSH deploy key . On careful examination, the user@host part of the SSH public key contained a base64 encoded string. When decoded, this string revealed the first flag of the challenge. Stage 2: Always read the docs! Having obtained the leaked SSH deploy-key, the player is presented with an interesting conundrum.
What does this key give them access to? Players may be tempted to try and use the SSH key to commit directly into the publicly exposed repository, but quickly come to the conclusion that this key does not have write access, or even read access, to the public repo. Several players attempted to then queue a PR into the public repository in the hopes that they would be automatically merged as part of the game but, unbeknownst to the player, branch protection was enabled for all repositories under the ekoparty2020 account, which prevented any PR’s from being merged without review.
However, by carefully examining the contents of the public repository as well as the README.md the player would be able to observe various references to a second repository, ekoparty-internal . This reference was a clue for the player to attempt to clone this internal repository using the leaked SSH deploy-key. The deploy-key only provided read access, so this limited the player from taking any further action beyond cloning the internal repository.
By using the GIT_SSH_COMMAND environment variable the player could set an SSH command that would use the obtained SSH private key to clone the internal repository. GIT_SSH_COMMAND = "ssh -o IdentitiesOnly=true -i /tmp/leaked_id_rsa" git clone git@github.com:ekoparty2020/ekoparty-internal.git The player now obtained a clone of the private repo. When examining its contents they found two things: a .github/workflows directory containing the code for a github action, and a README.md which contained the stage 2 flag.
This is where things got interesting on our end. When verifying that the game was working well right before launch, we received a notification that our leaked deploy-key had been disabled. This is a feature of GitHub’s secret scanning , which continuously checks repositories across the GitHub platform for leaked secrets. In our case, secret scanning had picked up the leaked SSH deploy-key when we took the game live by making the game repo public, and it proactively disabled the key.
Luckily (for us) GitHub allows you to explicitly re-enable the key verification in case of a false positive, so we were able to keep the game up and running without further issue. It was great to see secret scanning work so rapidly! Stage 3: An environmental call to action! The third and final stage of the challenge revolved around GitHub Actions . GitHub Actions places powerful, flexible automation directly into the developer workflow, enabling teams to automate nearly everything, including software builds, testing, and deployment.
GitHub Actions are run on ephemeral Virtual Machines with API access to the GitHub repository that triggered the Action. Actions can be triggered by a variety of repo events . The Action VM environment contains an API token (GITHUB_TOKEN) that allows it to interact with your repository via the GitHub API. This token is valid for the runtime of the Action. You can also populate the Action environment with additional custom secrets using repo encrypted secrets .
The GitHub Marketplace contains a wide collection of Actions that provide all sorts of CI/CD functionality. Because Actions runners are essentially VMs with the runner application running your code, writing your own actions is pretty straightforward. You are not constrained to any specific language or tooling ecosystem, and while a lot of users prefer to use e.g. NodeJS based actions, as supported by the official GitHub Action API , you are free to implement Actions in whatever way you see fit.
Because Actions juggle repository secrets, you should carefully consider any third-party Actions that you decid
The rest of this page is on the live site.