Skip to content
Subdomain takeover Write-up Beginner

Sub-domain Takeover on api.techprep.fb.com (AWS Elastic Beanstalk)!

A subdomain of fb.com had a dangling CNAME record pointing to an AWS Elastic Beanstalk URL that no longer existed. An attacker with an AWS account could register that Elastic Beanstalk name and gain control over the subdomain.

Binit Ghimire Follow

Published on publish.whoisbinit.me

Bounty$500 View original

·Feb 16, 2021·

Binit Ghimire (@WHOISbinit), on publish.whoisbinit.me

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

Context

fb.com is in scope of Facebook's Bug Bounty Program. The target of this report is api.techprep.fb.com, a subdomain of fb.com that was pointed, through CNAME records, at the AWS Elastic Beanstalk endpoint techprep-backend.us-east-1.elasticbeanstalk.com. Elastic Beanstalk gives each application environment a DNS name derived from the environment name and the AWS region, so an environment called techprep-backend in us-east-1 is reachable at exactly that hostname. When the environment is deleted, the hostname stops resolving, but any DNS record elsewhere that still points at it remains in place.

That is the situation described here: Facebook had created the Elastic Beanstalk environment and pointed the subdomain at it, then removed the environment while leaving the CNAME behind. The result is a dangling CNAME, and because Elastic Beanstalk hostnames are first come, first served within a region, anyone with an AWS account who can create an environment with the same name in the same region can claim the hostname and, through the CNAME, serve content on the Facebook subdomain.

Setup

Anyone with an AWS account with privileges to create Elastic Beanstalk instances in the North Virginia (us-east-1) region could have claimed the endpoint. No other account, role or credential is described. The discovery workflow was fully automated with Bash scripting, using Assetfinder, Subfinder, Sublist3r and Amass for subdomain enumeration, dig for DNS lookups and Nmap for port scanning and resolution checks. The Nmap output in the report shows version 7.91SVN.

Finding it

The researcher states that no manual work went into finding the vulnerability; the workflow was fully automated. The enumeration collected subdomains of fb.com from four sources, merged and de-duplicated them, then checked each name with dig +short for a CNAME pointing at elasticbeanstalk. Any name that matched was written to a results file for follow-up.

Exploitation

Step 1: Confirm the CNAME

Perform a DNS lookup on api.techprep.fb.com. It resolves, through CNAME records, to techprep-backend.us-east-1.elasticbeanstalk.com.

Step 2: Check whether the target resolves

Scan all open ports and check whether techprep-backend.us-east-1.elasticbeanstalk.com resolves at all. It does not. The report gives this command and output as the reference for this step:

Bash
nmap -sV -O techprep-backend.us-east-1.elasticbeanstalk.com -Pn
Text
Starting Nmap 7.91SVN ( https://nmap.org/ ) at 2020-12-20 00:08 +0545
Failed to resolve "techprep-backend.us-east-1.elasticbeanstalk.com".
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 20.34 seconds

The -sV flag requests service and version detection, -O requests operating system detection and -Pn skips host discovery so the scan proceeds even if the host does not answer pings. The important line is Failed to resolve: the Elastic Beanstalk hostname no longer exists in DNS, which, combined with the CNAME from step 1, shows dangling DNS records at the subdomain.

Step 3: Claim the endpoint

Because the hostname is free, an attacker can create an Elastic Beanstalk instance in us-east-1 named techprep-backend. That claims the instance URL. Content hosted on the new environment then appears on api.techprep.fb.com, because the Facebook subdomain still points at the claimed hostname.

The automation that surfaced the target

The report includes a shortened version of the script, keeping only the part that found this vulnerability:

Bash
    echo "Checking with Assetfinder!";
    assetfinder -subs-only fb.com >> ~/results/fb.com/subs/assetfinder.txt;
    echo "Checking with Subfinder!";
    subfinder -d fb.com -recursive -silent -all -t 500 -o ~/results/fb.com/subs/subfinder.txt;
    echo "Checking with Sublist3r!";
    sublist3r -d fb.com -n -t 500 -o ~/results/fb.com/subs/sublist3r.txt;
    echo "Checking with Amass!";
    amass enum -passive -norecursive -noalts -d fb.com -o ~/results/fb.com/subs/amass.txt;

    cat ~/results/fb.com/subs/*.txt > ~/results/fb.com/subs.txt;

    rm -rf ~/results/fb.com/subs;

    sort -u ~/results/fb.com/subs.txt -o ~/results/fb.com/subs.txt

while IFS= read -r domain; do
    if dig +short $domain | grep elasticbeanstalk; then echo $domain | tee -a ~/results/fb.com/elasticbeanstalk.txt; fi;
done < ~/results/fb.com/subs.txt

The four tools write their results into separate files under ~/results/fb.com/subs/. Those files are concatenated into subs.txt, the per-tool directory is removed, and sort -u de-duplicates the combined list in place. The while loop reads one name at a time, runs dig +short on it, and greps the answer for elasticbeanstalk; a match prints the name and appends it to elasticbeanstalk.txt with tee -a. The Nmap scan shown above is not part of this script.

Root cause

The issue is a dangling DNS record. Facebook had previously done two things: pointed api.techprep.fb.com at the Elastic Beanstalk URL techprep-backend.us-east-1.elasticbeanstalk.com, and created an Elastic Beanstalk instance named techprep-backend in the us-east-1 region. At the time of reporting, Facebook appeared to have reverted the second step by deleting the instance, but the CNAME remained. Elastic Beanstalk hostnames are not reserved after deletion, so the name was available to anyone who could create an environment with that name in that region.

Impact

If the endpoint was claimed by an AWS user, that user would have gained full control over api.techprep.fb.com and could host their own content there, which would then appear on the Facebook subdomain. The report frames this as a dangling DNS issue that could be escalated to a subdomain takeover by registering the techprep-backend Elastic Beanstalk instance in us-east-1. The bounty was $500, and the team's note while rewarding it said: "The payout amount reflects the fact that fb.com domain is predominantly used for microsites and static content."

Fix

The report lists three acceptable resolutions for Facebook:

  1. Change the CNAME records of api.techprep.fb.com to the Elastic Beanstalk instance URL that Facebook currently owns.
  2. Delete the CNAME records.
  3. Re-claim the Elastic Beanstalk instance URL before anyone else does in the us-east-1 region.

A simpler mitigation mentioned earlier in the report is to change or remove the CNAME records from the target subdomain. The timeline records a patched response on Tuesday, January 12, 2021, and the researcher's patch confirmation the same day, but the report does not say which of the three options was applied.

Responsible disclosure timeline

Event Date and time
Report submitted Sunday, December 20, 2020 at 12:11 AM
First response from the team Tuesday, December 22, 2020 at 2:07 AM
Researcher's response Tuesday, December 22, 2020 at 2:28 AM
Triaged (sent to the appropriate product team) Monday, January 11, 2021 at 10:28 PM
Researcher's response Monday, January 11, 2021 at 10:29 PM
Patched response Tuesday, January 12, 2021 at 9:05 PM
Researcher's patch confirmation Tuesday, January 12, 2021 at 9:29 PM
Researcher's response Thursday, January 21, 2021 at 10:18 PM
Researcher's response Sunday, February 14, 2021 at 8:33 AM
Rewarded $500 Tuesday, February 16, 2021 at 9:43 PM
Researcher's response Tuesday, February 16, 2021 at 10:36 PM

Variants to test

  • Other Elastic Beanstalk CNAMEs. Run the same dig +short plus grep elasticbeanstalk check over a full subdomain list. A positive result is a name whose CNAME points at an *.elasticbeanstalk.com host that no longer resolves, as in the Nmap output above.
  • Other cloud hostnames with the same first-come behaviour. The pattern generalises to any provider that hands out a hostname derived from an account-chosen name and releases it on deletion. A positive result is a CNAME to such a hostname that fails to resolve while the record still exists.
  • Confirm the claim is possible. For a candidate hostname, check that an environment with that name can be created in the matching region under your own account.
  • Check for stale records after deletions. A positive result is a record that still points at the removed resource.

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 researcher found that one of Facebook's web addresses, api.techprep.fb.com, was still pointing at a piece of Amazon cloud infrastructure that Facebook had already deleted. Because of how Amazon names that kind of infrastructure, anyone with an Amazon Web Services (AWS) account could recreate it under the same name and, in doing so, take control of the Facebook web address. Facebook fixed it, and the researcher was paid $500.

This article walks through the whole thing from the beginning, assuming you have never done any security work. You only need to know how to use a browser and a computer. Every technical term is explained the first time it appears, and there is a glossary at the end.

Some background you need first

What a domain and a subdomain are

A domain is the part of a web address that identifies an organisation, like fb.com. A subdomain is a name placed in front of it to point at a specific service, like api.techprep.fb.com. Think of the domain as a company's main switchboard number and subdomains as the individual extensions for different departments.

What DNS and a CNAME record are

DNS (Domain Name System) is the internet's address book. Humans type names like fb.com; computers need numeric addresses. DNS translates one into the other.

A CNAME record (Canonical Name record) is a special entry in that address book that says "this name is really just another name for that name over there." It is like a mail-forwarding note on a letter: "I have moved, please send all post to my new address." When you look up api.techprep.fb.com, DNS follows the CNAME and hands you back whatever the other name resolves to.

What AWS Elastic Beanstalk is

AWS (Amazon Web Services) is Amazon's cloud platform: you rent computers and services over the internet instead of buying your own. Elastic Beanstalk is one of those services. You give it an application, it sets up the servers for you, and it gives you a web address to reach them.

Crucially, Elastic Beanstalk builds that web address out of two things you choose: the name of your application environment and the AWS region (the physical part of the world where the servers live). So an environment called techprep-backend in the region us-east-1 (Amazon's name for North Virginia) is reachable at exactly:

Text
techprep-backend.us-east-1.elasticbeanstalk.com

This is the key fact of the whole story. The name is not random and it is not secret. It is predictable from the environment name and the region, and it is handed out on a first come, first served basis. If you delete your environment, the name is released, and someone else can create an environment with the same name in the same region and get the same address.

What a dangling DNS record is

A dangling DNS record is a CNAME (or similar record) that still points at something that no longer exists. It is like a mail-forwarding note that sends letters to a house that has been demolished. The note is still there, but the destination is gone. If someone builds a new house on that plot, your post starts arriving at their door.

What a subdomain takeover is

A subdomain takeover is what happens when an attacker claims the abandoned destination and, because the victim's DNS record still points at it, ends up serving their own content on the victim's subdomain. Visitors who trust the victim's domain see the attacker's pages.

The target and the setup

fb.com is in scope of Facebook's Bug Bounty Program. A bug bounty program is a scheme where a company pays independent researchers to find and report security problems in its systems, instead of punishing them. "In scope" means the company has said this particular domain is fair game to test.

The target of this report is api.techprep.fb.com, a subdomain of fb.com. Through CNAME records it was pointed at the Elastic Beanstalk endpoint techprep-backend.us-east-1.elasticbeanstalk.com.

Here is the situation the researcher found: Facebook had created the Elastic Beanstalk environment and pointed the subdomain at it, then removed the environment while leaving the CNAME behind. The result is a dangling CNAME. Because Elastic Beanstalk hostnames are first come, first served within a region, anyone with an AWS account who can create an environment with the same name in the same region can claim the hostname and, through the CNAME, serve content on the Facebook subdomain.

Anyone with an AWS account with privileges to create Elastic Beanstalk instances in the North Virginia (us-east-1) region could have claimed the endpoint. No other account, role or credential is described. The discovery workflow was fully automated with Bash scripting. Bash is the command language used in the terminal on Linux and macOS; a script is just a text file of commands run in order. The tools used were:

  • Assetfinder, Subfinder, Sublist3r and Amass: four programs that each try to discover subdomains of a domain from different sources.
  • dig: a command-line tool for asking DNS questions, such as "what does this name point to?"
  • Nmap: a tool for scanning a host to see which network ports are open and what services are running. A port is a numbered channel on a computer; web servers usually listen on port 80 or 443.

The Nmap output in the report shows version 7.91SVN.

Finding it

The researcher states that no manual work went into finding the vulnerability; the workflow was fully automated. The enumeration collected subdomains of fb.com from four sources, merged and de-duplicated them, then checked each name with dig +short for a CNAME pointing at elasticbeanstalk. Any name that matched was written to a results file for follow-up.

Why this approach? A large company has thousands of subdomains, and checking them by hand is impossible. The script does the boring part: gather every name it can find, then filter for the one pattern that matters here, a CNAME to an Elastic Beanstalk address.

Exploitation

Step 1: Confirm the CNAME

Perform a DNS lookup on api.techprep.fb.com. It resolves, through CNAME records, to techprep-backend.us-east-1.elasticbeanstalk.com.

This step answers the question "where does this Facebook name actually send visitors?" The answer is an Amazon address, not a Facebook server. That is normal for cloud-hosted services, but it is the first half of the problem.

Step 2: Check whether the target resolves

Scan all open ports and check whether techprep-backend.us-east-1.elasticbeanstalk.com resolves at all. It does not. The report gives this command and output as the reference for this step:

Bash
nmap -sV -O techprep-backend.us-east-1.elasticbeanstalk.com -Pn
Text
Starting Nmap 7.91SVN ( https://nmap.org/ ) at 2020-12-20 00:08 +0545
Failed to resolve "techprep-backend.us-east-1.elasticbeanstalk.com".
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 20.34 seconds

Line by line:

  • The command runs Nmap against the Elastic Beanstalk hostname.
  • -sV asks Nmap to detect which service and version is running on each open port.
  • -O asks Nmap to try to detect the operating system.
  • -Pn tells Nmap to skip the usual "is the host alive?" ping check and go straight to scanning, so the scan proceeds even if the host does not answer pings.
  • The first output line is just Nmap announcing itself and the time.
  • Failed to resolve is the important line: DNS could not turn the hostname into an address, because the hostname no longer exists.
  • WARNING: No targets were specified, so 0 hosts scanned. and the final line confirm that nothing was scanned, because there was nothing to scan.

Why this step matters: step 1 showed the Facebook name points at the Amazon name. Step 2 shows the Amazon name is dead. Put together, the Facebook name points at nothing. That is the definition of a dangling record, and it is the proof the researcher needed before reporting.

Step 3: Claim the endpoint

Because the hostname is free, an attacker can create an Elastic Beanstalk instance in us-east-1 named techprep-backend. That claims the instance URL. Content hosted on the new environment then appears on api.techprep.fb.com, because the Facebook subdomain still points at the claimed hostname.

In everyday terms: the forwarding note still says "send post to 12 Example Street", the house at 12 Example Street has been knocked down, and anyone who builds a new house there starts receiving Facebook's post.

The automation that surfaced the target

The report includes a shortened version of the script, keeping only the part that found this vulnerability:

Bash
    echo "Checking with Assetfinder!";
    assetfinder -subs-only fb.com >> ~/results/fb.com/subs/assetfinder.txt;
    echo "Checking with Subfinder!";
    subfinder -d fb.com -recursive -silent -all -t 500 -o ~/results/fb.com/subs/subfinder.txt;
    echo "Checking with Sublist3r!";
    sublist3r -d fb.com -n -t 500 -o ~/results/fb.com/subs/sublist3r.txt;
    echo "Checking with Amass!";
    amass enum -passive -norecursive -noalts -d fb.com -o ~/results/fb.com/subs/amass.txt;

    cat ~/results/fb.com/subs/*.txt > ~/results/fb.com/subs.txt;

    rm -rf ~/results/fb.com/subs;

    sort -u ~/results/fb.com/subs.txt -o ~/results/fb.com/subs.txt

while IFS= read -r domain; do
    if dig +short $domain | grep elasticbeanstalk; then echo $domain | tee -a ~/results/fb.com/elasticbeanstalk.txt; fi;
done < ~/results/fb.com/subs.txt

Line by line, in plain words:

  • echo "Checking with Assetfinder!"; prints a message so the person running the script can see progress. The semicolon just ends the command.
  • assetfinder -subs-only fb.com >> ~/results/fb.com/subs/assetfinder.txt; runs Assetfinder on fb.com, asking only for subdomains (-subs-only), and appends (>>) the results to a file. Appending means adding to the end rather than overwriting.
  • The next three blocks do the same job with Subfinder, Sublist3r and Amass, each writing to its own file. The flags differ per tool: -d fb.com sets the domain, -recursive and -all ask for more thorough searching, -silent suppresses extra output, -t 500 sets a thread count, -o sets the output file, -n and -passive and -norecursive and -noalts are tool-specific options that limit or shape the search. The point is the same: four independent sources of subdomain names.
  • cat ~/results/fb.com/subs/*.txt > ~/results/fb.com/subs.txt; joins all four files into one combined list. cat prints file contents and > writes the output to a new file.
  • rm -rf ~/results/fb.com/subs; deletes the per-tool folder now that its contents have been merged. rm -rf removes a folder and everything inside it.
  • sort -u ~/results/fb.com/subs.txt -o ~/results/fb.com/subs.txt sorts the combined list and removes duplicates (-u for unique), writing the result back to the same file. Four tools will have found many of the same names, so this step keeps the list clean.
  • while IFS= read -r domain; do starts a loop that reads the combined list one line at a time, putting each line into a variable called domain.
  • if dig +short $domain | grep elasticbeanstalk; then asks DNS for the short answer for that name (dig +short) and pipes the answer into grep, which searches text for a pattern. If the answer contains the word elasticbeanstalk, the condition is true. The pipe symbol | passes the output of one command as input to the next.
  • echo $domain | tee -a ~/results/fb.com/elasticbeanstalk.txt; prints the matching name and also appends it to a results file. tee -a does both at once.
  • fi; closes the if, and done < ~/results/fb.com/subs.txt closes the loop and feeds it the combined list as input.

The Nmap scan shown above is not part of this script; it was run separately to confirm the finding.

Root cause

The issue is a dangling DNS record. Facebook had previously done two things: pointed api.techprep.fb.com at the Elastic Beanstalk URL techprep-backend.us-east-1.elasticbeanstalk.com, and created an Elastic Beanstalk instance named techprep-backend in the us-east-1 region. At the time of reporting, Facebook appeared to have reverted the second step by deleting the instance, but the CNAME remained. Elastic Beanstalk hostnames are not reserved after deletion, so the name was available to anyone who could create an environment with that name in that region.

In short: two things that had to stay in sync (the DNS record and the cloud environment) drifted apart, and only one of them was cleaned up.

Impact

If the endpoint was claimed by an AWS user, that user would have gained full control over api.techprep.fb.com and could host their own content there, which would then appear on the Facebook subdomain. The report frames this as a dangling DNS issue that could be escalated to a subdomain takeover by registering the techprep-backend Elastic Beanstalk instance in us-east-1.

Why does that matter? Visitors, and possibly automated systems, trust anything served from a Facebook-owned name. An attacker hosting content there could serve their own pages from a Facebook-owned name. The bounty was $500, and the team's note while rewarding it said: "The payout amount reflects the fact that fb.com domain is predominantly used for microsites and static content." In other words, the amount was set with the low sensitivity of that particular domain in mind.

Fix

The report lists three acceptable resolutions for Facebook:

  1. Change the CNAME records of api.techprep.fb.com to the Elastic Beanstalk instance URL that Facebook currently owns.
  2. Delete the CNAME records.
  3. Re-claim the Elastic Beanstalk instance URL before anyone else does in the us-east-1 region.

A simpler mitigation mentioned earlier in the report is to change or remove the CNAME records from the target subdomain. The timeline records a patched response on Tuesday, January 12, 2021, and the researcher's patch confirmation the same day, but the report does not say which of the three options was applied.

Responsible disclosure timeline

Responsible disclosure means telling the owner privately and giving them time to fix the problem before saying anything publicly. The dates below are from the report.

Event Date and time
Report submitted Sunday, December 20, 2020 at 12:11 AM
First response from the team Tuesday, December 22, 2020 at 2:07 AM
Researcher's response Tuesday, December 22, 2020 at 2:28 AM
Triaged (sent to the appropriate product team) Monday, January 11, 2021 at 10:28 PM
Researcher's response Monday, January 11, 2021 at 10:29 PM
Patched response Tuesday, January 12, 2021 at 9:05 PM
Researcher's patch confirmation Tuesday, January 12, 2021 at 9:29 PM
Researcher's response Thursday, January 21, 2021 at 10:18 PM
Researcher's response Sunday, February 14, 2021 at 8:33 AM
Rewarded $500 Tuesday, February 16, 2021 at 9:43 PM
Researcher's response Tuesday, February 16, 2021 at 10:36 PM

Triaged means the company accepted the report as valid and passed it to the team responsible for the affected product.

Variants to test

Each one is a way of asking the same question: is there a name that still points at something that no longer exists?

  • Other Elastic Beanstalk CNAMEs. Run the same dig +short plus grep elasticbeanstalk check over a full subdomain list. A positive result is a name whose CNAME points at an *.elasticbeanstalk.com host that no longer resolves, as in the Nmap output above.
  • Other cloud hostnames with the same first-come behaviour. The pattern generalises to any provider that hands out a hostname derived from an account-chosen name and releases it on deletion. A positive result is a CNAME to such a hostname that fails to resolve while the record still exists.
  • Confirm the claim is possible. For a candidate hostname, check that an environment with that name can be created in the matching region under your own account.
  • Check for stale records after deletions. When a target removes infrastructure, re-run the enumeration and resolution checks against the old hostnames. A positive result is a record that still points at the removed resource.

Glossary

  • API: Application Programming Interface; a way for one piece of software to talk to another. Here it is just part of the subdomain name api.techprep.fb.com.
  • AWS (Amazon Web Services): Amazon's cloud platform, where you rent computers and services over the internet.
  • Bash: the command language used in the terminal on Linux and macOS; a script is a file of Bash commands run in order.
  • Bug bounty program: a scheme where a company pays independent researchers to find and report security problems.
  • CNAME record: a DNS entry saying one name is an alias for another name.
  • Dangling DNS record: a DNS record that still points at a destination that no longer exists.
  • dig: a command-line tool for asking DNS questions.
  • DNS (Domain Name System): the internet's address book, translating names into numeric addresses.
  • Domain: the part of a web address identifying an organisation, like fb.com.
  • Elastic Beanstalk: an AWS service that sets up servers for your application and gives you a web address built from your environment name and region.
  • Enumeration: systematically listing things, here subdomains, so they can be checked.
  • In scope: declared by a company as fair game to test under its bug bounty program.
  • Nmap: a tool for scanning a host to see which ports are open and what services are running.
  • Port: a numbered channel on a computer; web servers usually listen on 80 or 443.
  • Region: the physical part of the world where cloud servers live; us-east-1 is Amazon's name for North Virginia.
  • Responsible disclosure: telling the owner privately and giving them time to fix the problem before going public.
  • Subdomain: a name placed in front of a domain to point at a specific service, like api.techprep.fb.com.
  • Subdomain takeover: claiming an abandoned destination so that the victim's DNS record ends up serving the attacker's content.
  • Triaged: accepted as valid by the company and passed to the responsible team.

More by Binit Ghimire

View all

4 more disclosed reports, best first.

More from Meta

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Subdomain takeover

The lesson behind this report.

A company's DNS still points at a cloud service it no longer uses, so anyone can claim it and serve content on the company's domain.