Hijacking a Facebook Account with SMS
The mobile phone confirmation endpoint accepted a modified profile_id parameter, allowing an attacker to link their own phone number to any Facebook account. The attacker could then reset the victim's password via SMS and take over the account.
This post will demonstrate a simple bug which will lead to a full takeover of any Facebook account, with no user interaction.
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.
Context
Facebook lets users link a mobile number to their account. Once linked, the number can receive account updates by SMS and can be used to log in instead of an email address. The linking flow is driven by an AJAX endpoint, /ajax/settings/mobile/confirm_phone.php, which takes the verification code sent to the phone and the profile the number should be attached to.
The bug described here is a broken authorisation issue in that endpoint: the account identifier supplied by the client was trusted, so a verification code obtained for the attacker's own number could be applied to somebody else's profile. The result is a full account takeover with no interaction from the victim.
Setup
- A Facebook account controlled by the attacker, with a mobile number able to receive SMS from Facebook's UK shortcode
32665. - The target's numeric profile identifier, which is what the form submits as
profile_id. - A browser with developer tools, or an intercepting proxy, to edit the form before it is submitted.
- No action by the victim is required at any point.
Finding it
The endpoint accepts several parameters, but two matter:
| Parameter | Meaning |
|---|---|
code |
The verification code received by SMS on the attacker's phone |
profile_id |
The account the number is being linked to |
profile_id is normally populated with the logged-in user's own account. Changing it to the target's identifier did not produce an error, which is the signal that the server was not checking whether the caller was allowed to modify that profile.
Exploitation
Step 1: obtain a verification code for your own number
Send the letter F to 32665, Facebook's SMS shortcode in the UK. Facebook replies with an 8 character verification code.
Step 2: submit the code against the target's profile
Open the activation box at https://www.facebook.com/settings?tab=mobile, enter the code, and modify the profile_id element inside the fbMobileConfirmationForm form so that it points at the target account instead of your own. Submitting the request returns a 200. The __user value, which is sent with all AJAX requests, is different from the modified profile_id.
You may have to reauthenticate after submitting the request, but the password required is yours, not the target's.
Step 3: confirm the link
An SMS arrives confirming that the number has been linked. The attacker's phone number is now associated with the victim's account.
Step 4: reset the password
Initiate a password reset request against the victim's account. The reset code is delivered by SMS to the number that was just attached, so it arrives on the attacker's phone.
Step 5: set a new password
Enter the reset code into the form, choose a new password, and the account belongs to the attacker.
Root cause
The endpoint used the client-supplied profile_id to decide which account to modify, but did not verify that the authenticated caller had permission to change the phone number on that profile. The verification code proved only that the attacker controlled the number being linked, not that the attacker owned the profile it was being linked to.
Impact
Any Facebook account could be taken over in full, with no user interaction. The attack chains number linking into SMS-based password reset, so it bypasses the victim's existing password entirely. The report notes that the bounty assigned to this bug was $20,000, which it presents as a demonstration of the severity.
Fix
Facebook fixed the issue by verifying that the caller has permission to modify the phone number on the profile denoted by profile_id. The report gives the following timeline:
- 23rd May 2013: reported
- 28th May 2013: report acknowledged
- 28th May 2013: issue fixed
Variants to test
- Other endpoints that accept an object identifier alongside a secret. Look for confirmation, invitation or linking flows where a token or code is validated but the target object is taken from the request. A positive result is a 200 response where the identifier in the request differs from the authenticated user and the change is applied.
- Compare session identity with the submitted identifier. Where a request carries both a session-derived user value and a client-supplied profile or account field, try mismatching them. A positive result is the server acting on the supplied field rather than the session.
- Replay a code issued to your own account against another account. Obtain a legitimate verification code for a resource you control, then submit it with a different owner identifier. A positive result is the resource being attached to the other account.
- Chain contact-point changes into recovery flows. After any successful contact-detail change on another account, trigger a password reset and see where the code is delivered. A positive result is the reset code arriving at a channel you control.
What happened, in plain words
Facebook lets you attach a mobile phone number to your account. Once a number is linked, Facebook can text you account updates, and you can log in with that number instead of typing your email address. To link a number, Facebook sends a short code by text message, you type that code into a box on a settings page, and the server checks the code before attaching the number.
The problem was in the step where the server attaches the number. The page that handles this step is a small program on Facebook's server, and the browser sends it two important pieces of information: the code you received by text, and an identifier saying which account the number should be attached to. The server checked the code, but it never checked whether the person sending the request was allowed to change the account named in that identifier. So an attacker could get a genuine code for their own phone number, then tell the server to attach that number to somebody else's account. Once the attacker's number is attached to the victim's account, the attacker can ask Facebook to reset the victim's password, and the reset code is texted to the attacker's phone. The attacker then sets a new password and owns the account. The victim never has to click anything or do anything at all.
This kind of mistake is called a broken authorisation bug. Authorisation means deciding whether a person is allowed to do a particular thing. Authentication is the separate question of who the person is. Here the server knew who was asking (the attacker was logged in), but it did not check whether that person was allowed to modify the target account. The verification code only proved that the attacker controlled the phone number being linked. It did not prove that the attacker owned the account the number was being linked to.
Background: what the feature does
Facebook accounts can have a mobile number attached. Two things become possible once a number is linked:
- Facebook can send account updates to that number by SMS (text message).
- You can log in using the number instead of your email address.
The linking process works like this. You tell Facebook your number. Facebook texts you a short verification code. You type the code into a box on a settings page, and the browser sends it to Facebook's server. The server checks the code and, if it is correct, attaches the number to your account.
The page that receives the code is not a normal web page you look at. It is an endpoint: a specific address on the server that accepts a request and does something with it. This one lives at /ajax/settings/mobile/confirm_phone.php. AJAX is a way for a web page to talk to the server in the background, without reloading the whole page. When you click a button and something happens without the page flashing and reloading, AJAX is often how it works.
An endpoint is a bit like a service counter. You walk up to the counter, hand over some paperwork, and the clerk behind it does something. The paperwork here is a set of parameters: named values the browser sends along with the request. The endpoint takes several parameters, but two matter for this story:
| Parameter | Meaning |
|---|---|
code |
The verification code received by SMS on the attacker's phone |
profile_id |
The account the number is being linked to |
A parameter is simply a labelled piece of data in a request, like a field on a form. profile_id is the account identifier: a number that tells Facebook which account to work on. Normally the page fills it in with your own account, because normally you are linking a number to yourself.
The flaw
When the attacker changed profile_id from their own account to the target's account, the server did not complain. No error came back. That silence is the clue: the server was not checking whether the person making the request was allowed to modify the account named in profile_id.
To understand why that matters, it helps to separate two questions:
- Authentication: who is making this request? The server knew: the attacker was logged in as themselves.
- Authorisation: is this person allowed to do this particular thing to this particular account? The server never asked.
Every AJAX request also carries a value called __user, which identifies the logged-in user making the request. The request carried a __user value identifying the logged-in user, which differed from the modified profile_id. Here it did not.
What the attacker needed
- A Facebook account controlled by the attacker, with a mobile number able to receive SMS from Facebook's UK shortcode
32665. A shortcode is a short phone number that businesses use for text messaging. - The target's numeric profile identifier, which is what the form submits as
profile_id. - A browser with developer tools, or a proxy that sits between the browser and the server and lets you edit requests. Developer tools are built into browsers: you can open them, inspect the page, and change values before something is sent. A proxy is a program that sits in the middle of the connection so you can read and modify traffic.
- No action by the victim at any point.
Exploitation, step by step
Step 1: get a verification code for your own number
Send the letter F to 32665, Facebook's SMS shortcode in the UK. Facebook replies with an 8 character verification code.
Why this step: the attacker needs a genuine, valid code. The code is not stolen or guessed; it is issued legitimately to the attacker's own phone. The trick comes later, when that valid code is used against a different account.
Step 2: submit the code against the target's profile
Open the activation box at https://www.facebook.com/settings?tab=mobile, enter the code, and modify the profile_id element inside the fbMobileConfirmationForm form so that it points at the target account instead of your own.
A form on a web page is a collection of fields that get sent to the server when you submit. fbMobileConfirmationForm is the name of the form on this page. Inside it, the profile_id field holds the account identifier. Using developer tools or a proxy, the attacker changes that value before the form is submitted, so the request that leaves the browser says: here is a valid code, and please attach the number to this other account.
Submitting the request returns a 200. HTTP status code 200 means the request succeeded. The __user value, which is sent with all AJAX requests, is different from the modified profile_id, confirming that the request was made as the attacker while naming the victim's profile.
In other words, the request carried two identities: the session identity (__user, the attacker) and the target identity (profile_id, the victim). The server acted on the second one without checking it against the first.
You may have to reauthenticate after submitting the request, but the password required is yours, not the target's. Reauthenticating means logging in again, for example because the session expired. A session is the server's memory of you being logged in, usually kept alive by a cookie, which is a small piece of data the browser stores and sends back with each request. The important point is that any password prompt here asks for the attacker's own password, so the attacker can always satisfy it.
Step 3: confirm the link
An SMS arrives confirming that the number has been linked. The attacker's phone number is now associated with the victim's account.
Why this matters: the attacker now controls a recovery channel on the victim's account. Many services, including Facebook, will text a password reset code to the phone number on the account. That number now belongs to the attacker.
Step 4: reset the password
Initiate a password reset request against the victim's account. The reset code is delivered by SMS to the number that was just attached, so it arrives on the attacker's phone.
Why this works: the password reset flow trusts the phone number on the account. It has no way of knowing that the number was attached by someone other than the account owner. The victim's existing password is never needed.
Step 5: set a new password
Enter the reset code into the form, choose a new password, and the account belongs to the attacker.
At this point the attacker can log in as the victim. The victim did nothing during any of this: no link was clicked, no code was shared, no message was opened.
Why it worked
The endpoint used the profile_id supplied by the browser to decide which account to modify. It did not verify that the logged-in caller had permission to change the phone number on that profile. The verification code proved only that the attacker controlled the number being linked, not that the attacker owned the profile it was being linked to.
A useful comparison: imagine a hotel where the receptionist checks that your key card is genuine, but never checks that the room number you give belongs to you. A real key card plus someone else's room number gets you into their room.
Impact
Any Facebook account could be taken over in full, with no user interaction. The attack chains number linking into SMS-based password reset, so it bypasses the victim's existing password entirely. The report notes that the bounty assigned to this bug was $20,000, which it presents as a demonstration of the severity.
The fix
Facebook fixed the issue by verifying that the caller has permission to modify the phone number on the profile denoted by profile_id. In plain terms, the server now checks that the caller is allowed to change the phone number on that profile.
The report gives the following timeline:
- 23rd May 2013: reported
- 28th May 2013: report acknowledged
- 28th May 2013: issue fixed
Similar things to look for
These are patterns worth testing on other sites, based on the same underlying mistake.
- Other endpoints that accept an object identifier alongside a secret. Look for confirmation, invitation or linking flows where a token or code is validated but the target object is taken from the request. A positive result is a 200 response where the identifier in the request differs from the authenticated user and the change is applied.
- Compare session identity with the submitted identifier. Where a request carries both a session-derived user value and a client-supplied profile or account field, try mismatching them. A positive result is the server acting on the supplied field rather than the session.
- Replay a code issued to your own account against another account. Obtain a legitimate verification code for a resource you control, then submit it with a different owner identifier. A positive result is the resource being attached to the other account.
- Chain contact-point changes into recovery flows. After any successful contact-detail change on another account, trigger a password reset and see where the code is delivered. A positive result is the reset code arriving at a channel you control.
Glossary
- Account takeover: gaining full control of someone else's account, usually by changing its password or recovery details.
- AJAX: a technique where a web page talks to the server in the background, without reloading the whole page.
- Authentication: proving who you are, for example by logging in with a password.
- Authorisation: deciding whether an authenticated person is allowed to perform a particular action on a particular resource.
- Broken authorisation: a bug where the server does not check whether the caller is allowed to do what they are asking, even though it knows who the caller is.
- Cookie: a small piece of data a website stores in your browser and which the browser sends back with later requests, often used to keep you logged in.
- Developer tools: features built into browsers that let you inspect a page and modify values before they are sent.
- Endpoint: a specific address on a server that accepts requests and performs an action.
- Form: a collection of fields on a web page that are sent to the server when submitted.
- HTTP status code 200: the standard response meaning the request succeeded.
- Parameter: a named value sent along with a request, like a field on a form.
- Password reset flow: the process a site uses to let you set a new password, usually by sending a code to an email address or phone number on the account.
- Profile identifier (
profile_id): a number that tells Facebook which account to work on. - Proxy (intercepting proxy): a program that sits between your browser and the server so you can read and modify the traffic.
- Reauthenticate: log in again, for example after a session expires.
- Session: the server's memory that you are logged in, usually maintained through a cookie.
- Shortcode: a short phone number used by businesses for text messaging, such as
32665for Facebook in the UK. - SMS: a text message sent to a mobile phone.
__user: a value sent with Facebook AJAX requests that identifies the logged-in user making the request.- Verification code: a short code sent to a phone or email to prove that the person has access to it.