Skip to content
RCE Write-up Intermediate

Command Injection Through BLH

A shell script in Facebook's GitHub repository referenced an S3 bucket that no longer existed, allowing an attacker to claim the bucket and host a malicious archive at the same path. When a victim ran the script, it would download and execute the attacker's file, leading to command injection.

Shankar R Follow

Published on medium.com

Hi I am Shankar Ramakrishnan (@trapp3rhat) from India. I hope you all doing good.

Shankar Ramakrishnan, 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.

I am Shankar Ramakrishnan (@trapp3r_hat), a security researcher and Lead Security Consultant at Peneto Labs Pvt Ltd. This post walks through a bug that leads to command injection on a victim's machine without the victim being aware of installing a malicious file. The bug type is Broken Link Hijacking (BLH).

Context

Almost everyone has heard of subdomain hijacking, but broken link hijacking is less familiar. The two are very similar: the major difference is that one involves a subdomain while the other involves an expired link on a page.

The target here is an official Facebook GitHub repository. That repository contains a shell file which references an Amazon S3 bucket that no longer exists. Because the bucket name is free, an attacker can register it and serve content from the same path the repository expects. The user trusts the file because it is delivered from a link inside the Facebook repository, and the attacker controls what that link now returns.

Setup

The only tooling described is GitHub search. The researcher found the broken link with a simple GitHub dork:

Text
org:facebook "s3.amazonaws.com"

The dork restricts results to repositories in the facebook organisation and to files mentioning s3.amazonaws.com. The same approach can be repeated against other services that are vulnerable to subdomain takeover, because any service pointed at by a broken link can be taken over and used against the target.

Finding it

While analysing the dork results, the researcher came across some shell files that contained a reference to an S3 bucket which does not exist anymore.

From the original on medium.com

The screenshot shows the shell file and the reference to the missing bucket. An attacker can take over that bucket and place a malicious ZIP file at the same path shown in the image, /memnn/kvmemnn/data.tar.gz.

Exploitation

Step 1: Create the bucket

Create an Amazon S3 bucket named fair-data.

Step 2: Create the first folder

Create a folder called memnn inside the bucket.

Step 3: Create the second folder

Create another folder called kvmemnn inside memnn.

Step 4: Upload the payload

Place your malicious ZIP file named data.tar.gz in that path.

From the original on medium.com

The screenshot accompanies the four steps above. Once the bucket is controlled, the link in the Facebook repository resolves to attacker-controlled content instead of failing.

Root cause

The mistake is a dangling reference: a shell file in an official Facebook GitHub repository points at an S3 bucket that no longer exists. S3 bucket names are global and first-come, first-served, so once the original owner releases the name, anyone can claim it and serve arbitrary content at exactly the path the script expects. The repository itself was not compromised; the trust users place in the repository is what makes the hijacked link dangerous.

Impact

The attacker can carry out a command injection attack on victim machines. The official Facebook GitHub repository had a broken link placed inside a bash file which is now controlled by the attacker, and the victim trusts the shell file mentioned in the Facebook repository. The Facebook response notes a limitation: making the command injection work needs some user interaction to run the file once it is downloaded, namely Setup_Processed_data.sh.

Status and response

The report was marked as fixed. The Facebook team simply removed the file Setup_Processed_Data.sh from the repository.

Facebook initially marked the report as Informative, citing the user interaction needed to run the downloaded file. The researcher notes this was his fourth Informative bug from Facebook that year.

Picture: Facebook Response From the original on medium.com

The screenshot is captioned as the Facebook response. After some analysis, the Facebook team rewarded a bounty on 17 Jan 2020.

From the original on medium.com

The report states a reward of 500$ on 16 Jan 2020, and that a bounty was rewarded on 17 Jan 2020.

Fix

The fix applied was removal of the file Setup_Processed_Data.sh from the repository.

Variants to test

  1. Run the same dork against other organisations and other storage or hosting providers referenced in code, for example other S3-style endpoints. A positive result is a file in an official repository that points at a bucket or host which no longer exists and whose name you can register.
  2. Look for install or setup scripts that download archives from external URLs. A positive result is a script that fetches an archive from a path you can control.
  3. Check documentation and README files for links to expired domains or pages. A positive result is a link whose destination you can claim and use to serve content to users who trust the repository.

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. 5 min read.

What happened, in plain words

A security researcher found that an official Facebook GitHub repository contained a shell script that downloaded a file from an Amazon S3 bucket which no longer existed. Because S3 bucket names are unique and available on a first-come, first-served basis, anyone could create a bucket with the same name and put their own file at the exact path the script expected. When a user ran the script, it would download the attacker's file, which the report describes as leading to command injection. This is a type of attack called Broken Link Hijacking (BLH). Facebook initially marked the report as "Informative" because the attack required the user to run the downloaded file, but later awarded a $500 bounty and removed the vulnerable script from the repository.

Context

Almost everyone has heard of subdomain hijacking, but broken link hijacking is less familiar. The two are very similar: the major difference is that one involves a subdomain while the other involves an expired link on a page.

The target here is an official Facebook GitHub repository. That repository contains a shell file which references an Amazon S3 bucket that no longer exists. Because the bucket name is free, an attacker can register it and serve content from the same path the repository expects. The user trusts the file because it is delivered from a link inside the Facebook repository, and the attacker controls what that link now returns.

Setup

The only tooling described is GitHub search. The researcher found the broken link with a simple GitHub dork:

Text
org:facebook "s3.amazonaws.com"

This is a search query used on GitHub. org:facebook limits the search to repositories owned by the Facebook organisation on GitHub. "s3.amazonaws.com" looks for files that contain that exact text, which is the address of Amazon's S3 storage service. So the dork finds any file in Facebook's GitHub repositories that mentions an S3 bucket. The researcher notes that the same approach can be repeated against other services that are vulnerable to subdomain takeover, because any service pointed at by a broken link can be taken over and used against the target.

Finding it

While analysing the dork results, the researcher came across some shell files that contained a reference to an S3 bucket which does not exist anymore.

From the original on medium.com

The screenshot shows the shell file and the reference to the missing bucket. An attacker can take over that bucket and place a malicious ZIP file at the same path shown in the image, /memnn/kvmemnn/data.tar.gz.

Exploitation

Step 1: Create the bucket

Create an Amazon S3 bucket named fair-data.

Step 2: Create the first folder

Create a folder called memnn inside the bucket.

Step 3: Create the second folder

Create another folder called kvmemnn inside memnn.

Step 4: Upload the payload

Place your malicious ZIP file named data.tar.gz in that path.

From the original on medium.com

The screenshot accompanies the four steps above. Once the bucket is controlled, the link in the Facebook repository resolves to attacker-controlled content instead of failing.

Root cause

The mistake is a dangling reference: a shell file in an official Facebook GitHub repository points at an S3 bucket that no longer exists. S3 bucket names are global and first-come, first-served, so once the original owner releases the name, anyone can claim it and serve arbitrary content at exactly the path the script expects. The repository itself was not compromised; the trust users place in the repository is what makes the hijacked link dangerous.

Impact

The attacker can carry out a command injection attack on victim machines. The official Facebook GitHub repository had a broken link placed inside a bash file which is now controlled by the attacker, and the victim trusts the shell file mentioned in the Facebook repository. The Facebook response notes a limitation: making the command injection work needs some user interaction to run the file once it is downloaded, namely Setup_Processed_data.sh.

Status and response

The report was marked as fixed. The Facebook team simply removed the file Setup_Processed_Data.sh from the repository.

Facebook initially marked the report as Informative, citing the user interaction needed to run the downloaded file. The researcher notes this was his fourth Informative bug from Facebook that year.

Picture: Facebook Response From the original on medium.com

The screenshot is captioned as the Facebook response. After some analysis, the Facebook team rewarded a bounty on 17 Jan 2020.

From the original on medium.com

The report states a reward of 500$ on 16 Jan 2020, and that a bounty was rewarded on 17 Jan 2020.

Fix

The fix applied was removal of the file Setup_Processed_Data.sh from the repository.

Variants to test

  1. Run the same dork against other organisations and other storage or hosting providers referenced in code, for example other S3-style endpoints. A positive result is a file in an official repository that points at a bucket or host which no longer exists and whose name you can register.
  2. Look for install or setup scripts that download archives from external URLs. A positive result is a script that fetches an archive from a path you can control.
  3. Check documentation and README files for links to expired domains or pages. A positive result is a link whose destination you can claim and use to serve content to users who trust the repository.

Glossary

  • Subdomain hijacking: Similar to BLH, but involves taking over a subdomain that points to a service that no longer exists.
  • Shell file: A script containing commands for a Unix-like operating system, often used to automate tasks.
  • Amazon S3 bucket: A cloud storage container provided by Amazon Web Services. Bucket names are globally unique and can be claimed by anyone if not already taken.
  • GitHub dork: A search query using advanced operators to find specific information on GitHub, such as files containing certain strings.
  • Command injection: A vulnerability where an attacker can execute arbitrary commands on a victim's system, often by tricking the system into running malicious code.
  • ZIP file: A compressed archive file that can contain multiple files and folders.
  • Payload: The malicious file or code that an attacker delivers to a victim.
  • Bash file: A script written for the Bash shell, a common command-line interpreter on Unix-like systems.
  • Informative: A status used by bug bounty programs indicating that the report did not meet the criteria for a reward, often because it was considered not actionable or low impact.
  • Bounty: A monetary reward given by a bug bounty program for a valid security vulnerability report.
  • Dangling reference: A link or pointer to a resource that no longer exists, which can be exploited if the resource can be claimed by an attacker.

More from Meta

View all

The newest disclosed reports for this program.

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.