Skip to content
Account takeover Write-up Intermediate

How I hacked Facebook: Part Two

The application used ASPXAUTH cookies with default machine keys, allowing an attacker to forge a valid cookie for any admin username and log in. The attacker then used the admin panel's API trigger feature to send arbitrary requests to internal Facebook hosts, achieving SSRF.

Alaa Abdulridha Follow

Published on infosecwriteups.com

Bounty$54,580 View original

In part one I have found Account takeover by an unsecured API which allowed me to change the password of any admin account with no user interaction, and I got rewarded 7500$ by the Facebook security team, In part two I have found account takeover using cookies manipulation and chained it with Internal SSRF I got…

Alaa Abdulridha, on infosecwriteups.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. 8 min read.

Context

This is the second part of a two-part account of vulnerabilities found in a Facebook application. Part one covered an account takeover through an unsecured API that allowed the password of any admin account to be changed with no user interaction, and was rewarded with $7,500. Part two covers a second account takeover, this time through cookie manipulation, chained with an internal SSRF. The combined payout across both parts came to $54,800.

The application in question is an ASP.NET application that issues an ASPXAUTH cookie. The researcher describes it as a panel used by a legal department, with features for building forms and an "API trigger" option. The account takeover gave access to admin accounts in that panel; the API trigger is what led to the SSRF.

The author notes that the article was revised by multiple parties before release and that written permission was required to publish it, so some names and information may have been changed at the request of Facebook and its partners.

Setup

The work was done against Facebook infrastructure, with the researcher in an ongoing report thread from part one. The tools mentioned are Burp Suite, used to read the history of the earlier testing and to intercept requests, and a script uploaded to the application's editor. No versions are given.

The preconditions for the cookie attack are unusual and worth stating plainly: the researcher did not have the application's validationKey, decryptionMethod, decryptionIV or decryptionKey. The approach depends on finding a second website running the same application with the same encryption keys, where registration is active, and on knowing the username of a Facebook admin.

Finding it

After the part one vulnerability was mitigated, the researcher went back through the Burp Suite history to understand how the application worked.

From the original on infosecwriteups.com

The screenshot shows the cookies in the captured traffic. The relevant one is ASPXAUTH, marked as item 1 in blue. Seeing ASPXAUTH was the trigger for the whole line of reasoning: the researcher treats it as an indicator that the application is likely vulnerable, roughly "80%" in their words, but notes that exploiting it properly requires four pieces of configuration:

  • validationKey (string): hex-encoded key to use for signature validation.
  • decryptionMethod (string): (default "AES").
  • decryptionIV (string): hex-encoded initialization vector (defaults to a vector of zeros).
  • decryptionKey (string): hex-encoded key to use for decryption.

These are the parameters of the .NET MachineKey class, which the article links to. Without them the cookie cannot simply be forged. The researcher's observation is that most applications using ASPXAUTH put only the email or username in the encrypted cookie along with the encryption keys and an expiration time, and that this same method had worked on other bounty programme websites many times before.

Exploitation

Step 1: find a second site on the same application

Since the keys were unknown, the researcher searched for other websites that used the same application, on the assumption that one of them might share the same encryption keys. The plan was then to use the correct admin username against the Facebook instance.

A site was found where the same application was running and registration was active. The researcher registered there using a username that is used by the Facebook admin, intercepted the registration request, took the ASPXAUTH issued by that site, and replaced it with the expired Facebook ASPXAUTH.

From the original on infosecwriteups.com

The screenshots show the result: the researcher was back inside the panel. The screenshots show the result: the researcher was back inside the panel, after swapping the expired Facebook cookie in place of the one the second site issued.

Step 2: what the ASP.NET mistake is

The researcher frames the root problem as a set of mistakes developers should avoid:

  • The ASPXAUTH must be stored in the database and the application must check if it's valid.
  • The ASPXAUTH sometimes must contains more than the username as further validation.
  • The Encryption and decryption keys must be different from site to site (must change the default keys).

In the researcher's assessment the complexity of this vulnerability is very low and the impact is high. Reported alone, they estimate it would have been worth $7,500, as in part one, but they wanted more.

Step 3: spot the API trigger and ask for permission

Inside the panel the researcher noticed an option for making forms and another option called API trigger. That combination suggested an SSRF with no limits at all. Rather than test it silently, the researcher wrote to the Facebook Security Team explaining the suspicion that there was almost certainly a critical SSRF in the application and asking for permission to test it.

From the original on infosecwriteups.com

The reply is shown in the screenshot. At that point the researcher was still in contact with the team in the part one report, because these vulnerabilities were reported a week after the first one. The team still thought the researcher was claiming another auth bypass and SSRF even after the explanations and proofs, which the researcher reads as a green light to test the SSRF.

Step 4: upload a request script

The researcher wrote a small script and uploaded it to the application's editor. The script allowed sending any request with any data, using GET, POST, PUT, PATCH, HEAD or OPTIONS, to any URL, internal or external.

From the original on infosecwriteups.com

From the script backend the request method and the sent data could be changed. At this point the researcher believed the vulnerability could be escalated to RCE or LFI with more work, but is explicit that they are not 100% sure: they later asked Facebook for permission to reverse engineer the app, which was not granted, and Facebook's position was that escalation would not be possible.

Step 5: hit the canary

To confirm internal access, the researcher tried to reach the Facebook canary script.

From the original on infosecwriteups.com

The canary token came back. With that confirmation, the next step was a new report with full details, including the scripts and PoC as the team had asked.

In the researcher's summary, writing a script to send custom-crafted requests produced an internal SSRF and access to the Facebook internal network. Complexity is rated low and impact critical.

Root cause

The account takeover comes from shared ASP.NET machine keys across separate installations of the same application. Because the ASPXAUTH cookie is encrypted and signed with keys that were not unique per site, a cookie minted by one installation was accepted by the Facebook one. The researcher's recommendations suggest the cookie should be validated against a server-side store and carry more than the username. The researcher's three recommendations map directly onto this: validate the cookie against the database, include more than the username in the cookie, and use per-site keys rather than defaults.

The SSRF came from a script the researcher uploaded to the application's editor, which could send requests to any URL, internal or external, with any method and data.

Impact

Using the chain, the researcher states they were able to:

  • access any Facebook employee account in the legal department panel;
  • use the SSRF to access the Facebook internal network (intern.our.facebook.com);
  • with a little more effort, in their belief, escalate to scanning the internal network and servers.

The SSRF was not rate limited, and the content type and request method could be edited freely. The researcher quotes the general SSRF impact: unauthorised actions or access to data within the internal network, either in the vulnerable application or on back-end systems it can reach, and in some situations arbitrary command execution. An SSRF that reaches external third-party systems can also produce onward attacks that appear to originate from the organisation hosting the vulnerable application, with legal and reputational consequences.

Fix

Facebook mitigated the issues. The timeline in the report is:

Date Event
Wednesday, September 9, 2020 Vulnerabilities reported
Monday, October 26, 2020 Facebook asked for a new report; mitigation applied
Monday, October 26, 2020 Report triaged
Thursday, February 25, 2021 Fixed and rewarded
Friday, March 5, 2021 Bonus of $5,300 rewarded

The report does not describe the specific code changes. The researcher's stated recommendations are the three ASP.NET points above.

Bounty

Facebook's SSRF payout guidelines, as cited in the article, put this at $40,000 with a $5,000 bonus if the request content type and request method can be edited. The researcher received $40,000 plus a $2,000 bonus, not the full $5,000 control bonus.

From the original on infosecwriteups.com

When asked why the full control bonus of $5,000 was not paid, the answer was:

From the original on infosecwriteups.com

The total with the first vulnerability is $54,800.

Variants to test

  1. Shared machine keys across installations. When you see ASPXAUTH, look for other sites running the same application with registration open. Register with the target admin's username, capture the cookie that site issues, and swap in the target's expired cookie. A positive result is being logged in to the target as that admin.
  2. Username-only cookies. If the cookie carries only a username and no server-side validity check, try cookies for other known usernames. A positive result is access to another account without credentials.
  3. Default or reused encryption keys. Where the four MachineKey values are guessable or shared, forge a cookie directly. A positive result is a cookie the target accepts.
  4. User-controlled outbound requests. Any feature that fetches a URL on your behalf, such as a form builder or API trigger, is a candidate. Point it at an internal hostname and at a canary you control. A positive result is a callback from the target's network or a response from an internal service.
  5. Method and content type control. If the fetcher lets you choose the HTTP method and content type, try PUT, PATCH and unusual content types against internal endpoints. A positive result is a state change or a response the default method could not produce.
  6. Rate limiting on the fetcher. Send a burst of requests through the feature. A positive result is no throttling, which turns the SSRF into a usable internal scanner.

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

This is the story of two bugs found in a Facebook application, told by the researcher who found them. The first bug was covered in an earlier article and let the researcher change the password of any admin account without the admin doing anything. Facebook paid $7,500 for it. This article is about the second bug, which let the researcher log in as any admin by reusing a login cookie from a different website, and then use a feature of the application to make the Facebook server send requests to places on Facebook's own internal network. Facebook paid $40,000 plus a $2,000 bonus for the second bug, and the two payouts together came to $54,800.

Before going further, a few words about the pieces involved, because the rest of the article depends on them.

An application here means a piece of software running on a website. This particular one is built with a Microsoft technology called ASP.NET, and it is described in the article as a panel used by a legal department, with features for building forms and an option called API trigger.

A cookie is a small piece of text that a website asks your browser to store and send back with every later request. It is how a website remembers that you are logged in: after you sign in, the site hands your browser a cookie, and on each following page your browser shows that cookie, so the site knows who you are without asking for your password again. Think of it like a cloakroom ticket: you hand in your coat, you get a ticket, and later the ticket is enough to get the coat back. If someone else can copy or forge your ticket, they can collect your coat.

A token is a similar idea: a value that stands in for proof of identity or permission. In this article the cookie itself is the token.

An API (Application Programming Interface) is a way for one piece of software to talk to another, usually by sending requests to specific addresses and getting data back. Think of it as a service counter: you ask for something in a defined way, and you get a defined answer. The first article's bug was in an API.

SSRF stands for Server-Side Request Forgery. Normally, when you visit a page, your browser makes requests. In an SSRF, the attacker makes the server do the requesting instead. The server sits inside the company's network, so it can reach machines that the outside world cannot. It is like convincing a receptionist to make a phone call on your behalf to an internal extension you are not allowed to dial yourself.

Account takeover means getting into someone else's account without their permission. RCE (Remote Code Execution) means running your own commands on someone else's machine. LFI (Local File Inclusion) means making a server read files from its own disk that it should not show you. Burp Suite is a tool that sits between your browser and a website and records every request and response, so you can look at them afterwards and change them before they are sent.

The author also says the article was revised by several parties before release and that written permission was needed to publish it, so some names and details may have been changed at the request of Facebook and its partners.

Setup

The work was done against Facebook's systems. The researcher was still in an open report thread from the first article, so there was already a conversation with Facebook's security team going on. The tools mentioned are Burp Suite, used to read the history of the earlier testing and to intercept requests, and a script that the researcher uploaded into the application's editor. No versions of anything are given.

There is one precondition that is worth stating plainly, because it is unusual. To forge an ASPXAUTH cookie properly, you need four pieces of configuration from the application:

  • validationKey (string): hex-encoded key to use for signature validation.
  • decryptionMethod (string): (default "AES").
  • decryptionIV (string): hex-encoded initialization vector (defaults to a vector of zeros).
  • decryptionKey (string): hex-encoded key to use for decryption.

These are the settings of a .NET class called MachineKey, which the article links to. In plain terms: the cookie is scrambled (encrypted) and stamped with a signature so the site can tell it was made by the site itself. The decryptionKey is the secret used to unscramble it, the validationKey is the secret used to check the stamp, decryptionMethod says which scrambling algorithm is used, and decryptionIV is an extra starting value for the scrambling. Without these, you cannot simply make your own valid cookie from scratch.

The researcher did not have any of the four. So the plan had to work around that.

Finding it

After the first vulnerability was mitigated, the researcher went back through the Burp Suite history to understand how the application worked.

From the original on infosecwriteups.com

The screenshot shows the cookies in the captured traffic. The one that matters is ASPXAUTH, marked as item 1 in blue. Seeing ASPXAUTH is what set off the whole line of thinking: the researcher treats it as a sign that the application is probably vulnerable, roughly "80%" in their words, but notes that exploiting it properly needs the four configuration values above.

The researcher's observation is that most applications using ASPXAUTH put only the email or username inside the encrypted cookie, along with the encryption keys and an expiration time. In other words, the cookie says "this is user X" and is sealed with the site's secret, but the site does not check with its database whether that particular cookie is still valid. The same method had worked on other bounty programme websites many times before, which is why it was worth trying here.

Exploitation

Step 1: find a second site on the same application

Since the keys were unknown, the researcher searched for other websites that used the same application, on the assumption that one of them might share the same encryption keys. The idea is that if two installations of the same software were set up with the same default secrets, then a cookie made by one will be accepted by the other, because each side checks the stamp with the same secret. It is like two buildings using the same master key for their cloakroom tickets.

A site was found where the same application was running and registration was open. The researcher registered there using a username that is used by the Facebook admin. Why that username? Because the cookie only carries the username, so the cookie has to name the account you want to become. Then the researcher intercepted the registration request, took the ASPXAUTH issued by that site, and replaced it with the expired Facebook ASPXAUTH.

From the original on infosecwriteups.com

The screenshots show the result: the researcher was back inside the panel. The screenshots show the result: the researcher was back inside the panel, after swapping the expired Facebook cookie in place of the one the second site issued.

Step 2: what the ASP.NET mistake is

The researcher frames the root problem as a set of mistakes developers should avoid:

  • The ASPXAUTH must be stored in the database and the application must check if it's valid.
  • The ASPXAUTH sometimes must contains more than the username as further validation.
  • The Encryption and decryption keys must be different from site to site (must change the default keys).

In plain words: the site should keep a record of which cookies it actually issued and refuse any it does not recognise; the cookie should carry more than just a username, so that knowing a username is not enough; and each installation should use its own secrets rather than a shared or default one. In the researcher's assessment the complexity of this vulnerability is very low and the impact is high. Reported alone, they estimate it would have been worth $7,500, as in the first article, but they wanted more.

Step 3: spot the API trigger and ask for permission

Inside the panel the researcher noticed an option for making forms and another option called API trigger. A form builder lets a user design a form; an API trigger is another option in the panel, which the researcher suspected could send requests to arbitrary addresses. That combination suggested an SSRF with no limits at all: if the application will send a request to whatever address a user supplies, then a user can point it at internal machines.

Rather than test it silently, the researcher wrote to the Facebook Security Team explaining the suspicion that there was almost certainly a critical SSRF in the application and asking for permission to test it.

From the original on infosecwriteups.com

The reply is shown in the screenshot. At that point the researcher was still in contact with the team in the first article's report, because these vulnerabilities were reported a week after the first one. The team still thought the researcher was claiming another auth bypass and SSRF even after the explanations and proofs, which the researcher reads as a green light to test the SSRF.

Step 4: upload a request script

The researcher wrote a small script and uploaded it to the application's editor. The script allowed sending any request with any data, using GET, POST, PUT, PATCH, HEAD or OPTIONS, to any URL, internal or external.

From the original on infosecwriteups.com

A quick word on those method names, since they appear throughout. An HTTP method is the verb of a request: GET asks for something, POST sends data to create something, PUT and PATCH update something, HEAD asks for the headers only, and OPTIONS asks what is allowed. The content type is a label on the request saying what kind of data is inside, for example whether it is a form, JSON or a file. Being able to choose the method and the content type matters because some internal services only respond to particular combinations.

From the script backend the request method and the sent data could be changed. At this point the researcher believed the vulnerability could be escalated to RCE or LFI with more work, but is explicit that they are not 100% sure: they later asked Facebook for permission to reverse engineer the app, which was not granted, and Facebook's position was that escalation would not be possible.

Step 5: hit the canary

To confirm internal access, the researcher tried to reach the Facebook canary script.

From the original on infosecwriteups.com

A canary is a small, harmless marker placed somewhere that should not be reachable from outside. If you can make a request reach it and see the marker come back, you have proof that your request travelled where it should not have. The canary token came back. With that confirmation, the next step was a new report with full details, including the scripts and proof of concept as the team had asked.

In the researcher's summary, writing a script to send custom-crafted requests produced an internal SSRF and access to the Facebook internal network. Complexity is rated low and impact critical.

Root cause

The account takeover comes from shared ASP.NET machine keys across separate installations of the same application. Because the ASPXAUTH cookie is encrypted and signed with keys that were not unique per site, a cookie minted by one installation was accepted by the Facebook one. The researcher's recommendations suggest the cookie should be validated against a server-side store and carry more than the username. The researcher's three recommendations map directly onto this: validate the cookie against the database, include more than the username in the cookie, and use per-site keys rather than defaults.

The SSRF came from a script the researcher uploaded to the application's editor, which could send requests to any URL, internal or external, with any method and data.

Impact

Using the chain, the researcher states they were able to:

  • access any Facebook employee account in the legal department panel;
  • use the SSRF to access the Facebook internal network (intern.our.facebook.com);
  • with a little more effort, in their belief, escalate to scanning the internal network and servers.

The SSRF was not rate limited, and the content type and request method could be edited freely. The researcher quotes the general SSRF impact: unauthorised actions or access to data within the internal network, either in the vulnerable application or on back-end systems it can reach, and in some situations arbitrary command execution. An SSRF that reaches external third-party systems can also produce onward attacks that appear to originate from the organisation hosting the vulnerable application, with legal and reputational consequences.

Fix

Facebook mitigated the issues. The timeline in the report is:

Date Event
Wednesday, September 9, 2020 Vulnerabilities reported
Monday, October 26, 2020 Facebook asked for a new report; mitigation applied
Monday, October 26, 2020 Report triaged
Thursday, February 25, 2021 Fixed and rewarded
Friday, March 5, 2021 Bonus of $5,300 rewarded

The report does not describe the specific code changes. The researcher's stated recommendations are the three ASP.NET points above.

Bounty

Facebook's SSRF payout guidelines, as cited in the article, put this at $40,000 with a $5,000 bonus if the request content type and request method can be edited. The researcher received $40,000 plus a $2,000 bonus, not the full $5,000 control bonus.

From the original on infosecwriteups.com

When asked why the full control bonus of $5,000 was not paid, the answer was:

From the original on infosecwriteups.com

The total with the first vulnerability is $54,800.

Variants to test

  1. Shared machine keys across installations. When you see ASPXAUTH, look for other sites running the same application with registration open. Register with the target admin's username, capture the cookie that site issues, and swap in the target's expired cookie. A positive result is being logged in to the target as that admin.
  2. Username-only cookies. If the cookie carries only a username and no server-side validity check, try cookies for other known usernames. A positive result is access to another account without credentials.
  3. Default or reused encryption keys. Where the four MachineKey values are guessable or shared, forge a cookie directly. A positive result is a cookie the target accepts.
  4. User-controlled outbound requests. Any feature that fetches a URL on your behalf, such as a form builder or API trigger, is a candidate. Point it at an internal hostname and at a canary you control. A positive result is a callback from the target's network or a response from an internal service.
  5. Method and content type control. If the fetcher lets you choose the HTTP method and content type, try PUT, PATCH and unusual content types against internal endpoints. A positive result is a state change or a response the default method could not produce.
  6. Rate limiting on the fetcher. Send a burst of requests through the feature. A positive result is no throttling, which turns the SSRF into a usable internal scanner.

Glossary

  • API: a defined way for one piece of software to talk to another, usually by sending requests to specific addresses and getting structured answers back.
  • API trigger: a feature of the application that makes it send a request somewhere when something happens; here, the feature that allowed arbitrary outbound requests.
  • ASP.NET: a Microsoft framework for building web applications, which issues the ASPXAUTH cookie.
  • ASPXAUTH: the name of the login cookie used by ASP.NET applications; it holds the user's identity, encrypted and signed with the site's keys.
  • Account takeover: gaining access to someone else's account without their permission.
  • Auth bypass: getting past a login or permission check without valid credentials.
  • Burp Suite: a tool that sits between your browser and a website, records requests and responses, and lets you change them before sending.
  • Canary: a harmless marker placed somewhere that should not be reachable from outside, used to prove that a request reached it.
  • Content type: a label on an HTTP request or response saying what kind of data it carries, such as a form, JSON or a file.
  • Cookie: a small piece of text a website asks your browser to store and send back on later requests, commonly used to remember that you are logged in.
  • Decryption key: the secret value used to unscramble encrypted data.
  • Decryption method: the algorithm used to scramble and unscramble data, for example AES.
  • Decryption IV: an extra starting value used alongside the decryption key when scrambling data.
  • Encryption: scrambling data so that only someone with the right key can read it.
  • HTTP method: the verb of a request, such as GET, POST, PUT, PATCH, HEAD or OPTIONS, saying what kind of action is wanted.
  • Internal network: the private set of machines inside an organisation that the outside world cannot reach directly.
  • LFI (Local File Inclusion): making a server read files from its own disk that it should not show you.
  • MachineKey: the .NET class that holds the keys and settings used to encrypt and sign cookies such as ASPXAUTH.
  • Mitigation: a change made to reduce or remove a vulnerability.
  • PoC (proof of concept): a small demonstration showing that a vulnerability really works.
  • RCE (Remote Code Execution): running your own commands on someone else's machine.
  • Rate limiting: a cap on how many requests a system will accept in a period of time.
  • Reverse engineering: taking software apart to understand how it works internally.
  • SSRF (Server-Side Request Forgery): making a server send a request on your behalf, often to machines inside its own network that you cannot reach yourself.
  • Token: a value that stands in for proof of identity or permission.
  • Triaged: reviewed and accepted as a valid report by the security team.
  • Validation key: the secret value used to check that signed data, such as a cookie, really came from the site.

More by Alaa Abdulridha

View all

1 more disclosed report, 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.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.