Skip to content
RCE Write-up Intermediate

Exploiting Pre-commit Hooks, A Practical Demonstration

The report demonstrates how an attacker can inject a malicious pre-commit hook into a Git repository, which executes a reverse shell when a victim clones the repository and runs pre-commit install. The attacker can then gain remote access to the victim's machine, potentially with root privileges.

medium.com

Published on medium.com

I will demonstrate how an attacker can impersonate a developer account and push malicious changes into a source code repository using pre-commit hooks. By exploiting git spoofing techniques, the attacker can make the malicious commits appear legitimate and originate from a trusted developer.

Wisesiren, on medium.com

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 lack of verification of pre-commit hook configurations and the trust placed in repository content, allowing an attacker to inject a malicious hook that executes arbitrary commands.

Impact

An attacker could gain full remote access to a victim's machine, potentially with root privileges, by tricking them into cloning a repository and installing pre-commit hooks.

What the attacker needed

Victim clones malicious repository; victim runs pre-commit install; victim makes a commit

The fix

Pre-commit hooks should be reviewed and audited before use, and repositories should be trusted only from verified sources.

How it was found

  1. Set up a development environment with Git and configure user details.
  2. Clone the target repository.
  3. Create a malicious pre-commit hook configuration that runs a reverse shell script.
  4. Commit and push the changes to the repository.
  5. On the victim machine, clone the repository and install pre-commit hooks.
  6. The victim makes a commit, triggering the reverse shell and giving the attacker access.

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.

This report shows how a seemingly harmless tool called a pre-commit hook can be abused. A pre-commit hook is a script that runs automatically before each commit. If an attacker can add a malicious hook to a repository, anyone who uses that repository and installs the hooks will run the attacker's code, giving the attacker control of their computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.