Skip to content
Leaked secrets Write-up Intermediate

How I was able to Take over a support chat using leaked Keys

The developer version of the site exposed Twilio API credentials in its JavaScript, allowing an attacker to access the Twilio account. This let the attacker read internal doctor messages and call records, and send or delete messages and calls.

Pliskin Follow

Published on medium.com

Bounty$1,000 View original

Hello Everyone. First, let me introduce myself.

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

Context

The target was a TeleHealth website where you can have a virtual appointment with a doctor. It was a private program, so the author refers to it as www.site.com. The feature that mattered in the end was not the appointment flow itself but the communications infrastructure behind it: the site used Twilio for voice, video and email communications, and the credentials for that account were sitting in client-side JavaScript.

Setup

The work was done with Burp running in front of the browser while the author walked through every available feature of the site. Two accounts were created on the target so that cross-account access could be tested. No special tooling beyond Burp, a browser and curl was needed.

Finding it

While testing authentication, the author found a bug that allowed changing the user ID. After changing it and logging in, the user ID in the JWT was changed as well. With two accounts in hand, the user ID of account 1 was changed to the user ID of account 2 to see whether account 2's data became reachable.

After login the page was blank. The author searched for an explanation and concluded that there might be some client-side or server-side verification. Response manipulation and disabling JavaScript before the data was fetched were both tried, and neither worked. The working assumption was that the site checks the username against the user ID after authentication, which would block the swap.

The next idea was to test multiple endpoints, on the theory that some of them might check only the user ID and not the user ID together with the username. Searching across subdomains turned up dev.site.com, which served the same page as the main website. The author understood it to be the same application, used by the dev team to test changes before they reach the main site.

Logging in there to see whether the account takeover would succeed did not work either.

Later, while on a call, the author decided to look at the JavaScript. Comparing the main JS file of the main website with the dev one showed that the dev file is much larger. Filtering it with CTRL+F for Key, token and similar terms surfaced this line:

JavaScript
twillioAuthToken=”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,twillioAuthSSID=”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”.

A search showed that Twilio is an API used for voice, video and email communications. The author notes that one reason for writing the report was to show the impact of leaked Twilio keys, having not seen a write-up about it.

Exploitation

Step 1: verify the credentials

After reading about the auth token and SSID and how they can be used, the author used this command to check whether the credentials work:

The request authenticates with HTTP basic auth, using the account SID as the username and the auth token as the password, against the Accounts resource. The result listed the account's available resources:

Text
Addresses /2010–04–01/Accounts/$SSID/Addresses.json
Conferences /2010–04–01/Accounts/$SSID/Conferences.json
Signing_keys /2010–04–01/Accounts/$SSID/SigningKeys.json
Transcriptions /2010–04–01/Accounts/$SSID/Transcriptions.json
Connect_apps /2010–04–01/Accounts/$SSID/ConnectApps.json
Sip /2010–04–01/Accounts/$SSID/SIP.json
Authorized_connect_apps /2010–04–01/Accounts/$SSID/AuthorizedConnectApps.json
usage /2010–04–01/Accounts/$SSID/Usage.json
keys /2010–04–01/Accounts/$SSID/Keys.json
applications /2010–04–01/Accounts/$SSID/Applications.json
recordings /2010–04–01/Accounts/$SSID/Recordings.json
short_codes /2010–04–01/Accounts/$SSID/SMS/ShortCodes.json
calls /2010–04–01/Accounts/$SSID/Calls.json
notifications /2010–04–01/Accounts/$SSID/Notifications.json
incoming_phone_numbers /2010–04–01/Accounts/$SSID/IncomingPhoneNumbers.json
queues /2010–04–01/Accounts/$SSID/Queues.json
messages /2010–04–01/Accounts/$SSID/Messages.json
outgoing_caller_ids /2010–04–01/Accounts/$SSID/OutgoingCallerIds.json
available_phone_numbers /2010–04–01/Accounts/$SSID/AvailablePhoneNumbers.json
balance /2010–04–01/Accounts/$SSID/Balance.json

Step 2: read the message history

The author then ran:

This returned the messages between internal doctors. The history exposes the number a message comes from, the destination, the body of the message and the media that were sent.

Step 3: read the call history

The author also reports being able to see the history of calls with:

That response gives information about each call, such as the phone number of the caller and the destination, the duration of the call, and the records, notifications, streams and payments related to the call. Note that the command as written in the report points at the Messages resource, the same URL as the previous step.

Step 4: send a message

Viewing resources was not the limit. With the message history in hand, a message can be sent from any chosen number to any destination. The author describes sending a phishing message from a doctor to another doctor with:

Bash
curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json \
 — data-urlencode “Body=This will be the body of the new message” \
 — data-urlencode “From=[redacted]” \
 — data-urlencode “To=[redacted]” \
 -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

The Body parameter carries the text, From is the sender number and To is the destination, with the same SID and token used for basic auth.

Step 5: delete a message

Deletion works the same way:

Bash
curl -X DELETE https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages/MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json \
 -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

The message is addressed by its MM... identifier in the path. The author notes that deletion and creation can also be done to calls and to all the available resources, and that other resources were left out of the report to keep it short. Among the things that can be done with them are getting records, SIP configuration and listing Authorized Apps.

From the original on medium.com

Root cause

The Twilio account SID and auth token were embedded in the JavaScript of the dev site. Anyone who loaded the dev application could read the credentials from the bundle. The dev build was larger than the main site's bundle, and it carried the credentials.

Because the leaked values were the account-level SID and auth token, they authenticate against the Twilio REST API directly, with no application-side check in between. The account takeover attempts against the site's own login were blocked, likely by the username and user ID check the author suspected, but that defence is irrelevant to a credential that talks to a third-party API.

Impact

The leaked credentials gave access to the Twilio account's resources. An attacker could read the message history between internal doctors, including sender, destination, body and media, and read call history with caller and destination numbers, call duration and the related records, notifications, streams and payments. Beyond reading, the attacker could send messages from any chosen number to any destination, which the author frames as sending a phishing message from one doctor to another, and could delete messages, calls and other resources. The author states that the bounty was 1000 USD, the maximum for this target.

Fix

The report does not describe what the program changed. The obvious remediation is to remove the Twilio SID and auth token from any client-side bundle, including dev builds, and to rotate the credentials that were exposed. Dev environments that serve the same application should not be publicly reachable with production secrets in them.

Variants to test

  1. Compare production and development JavaScript bundles for the same application. A positive result is a dev bundle that is larger and contains configuration strings, keys or tokens absent from production.
  2. Search bundles for third-party provider names and credential-looking identifiers (Key, token, Auth, SSID, SID). A positive result is a hard-coded credential that authenticates against the provider's API.
  3. Enumerate subdomains of the target and check whether any of them serve the same application. A positive result is a dev or staging host with the same pages but different client-side code.
  4. When a user ID swap is blocked on login, test other endpoints that may validate only the user ID. A positive result is an endpoint that returns another account's data with the swapped identifier.
  5. Take any leaked third-party credential and verify it against the provider's account endpoint before assuming impact. A positive result is an authenticated listing of the account's resources.

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

What happened, in plain words

A security researcher was testing a TeleHealth website where you can have a virtual appointment with a doctor. While looking around, he found something much more serious than the website itself: the login details for the service the site used for voice, video and email communications were sitting in the dev site's JavaScript. With those details he could read messages between doctors, read call records, send messages pretending to be a doctor, and delete things. He was paid 1000 USD, the maximum bounty for that target.

This article walks through the same steps he did, explaining each idea from scratch. You only need a browser and a computer to follow the story; the commands are shown exactly as he ran them.

I added this pic to be the preview image ( still better than that meme XD ) From the original on medium.com

The author added this picture as the preview image for his post.

Some words you will meet

Before we start, a few everyday comparisons for terms that come up again and again.

  • A website is like a shop. Your browser is the customer; the shop's server is the building in the back that holds the stock.
  • JavaScript is the code that runs inside your browser to make a page interactive (menus that open, forms that check what you typed). Because your browser has to download it to run it, anyone can read it. Think of it as the shop's instruction leaflet, handed to every visitor.
  • An API is a way for one computer program to talk to another, like a waiter taking your order to the kitchen. You ask for something in a fixed format, and the kitchen sends back an answer.
  • A token or key is like a password that a program uses instead of a human. If someone else gets it, they can pretend to be that program.
  • curl is a small command-line tool that sends requests to a server and prints the answer. It is the browser's cousin without the pictures.
  • Burp (Burp Suite) is a program that sits between your browser and the website and lets you watch and change every request. Think of a postman who opens every letter, reads it, and can rewrite it before delivery.
  • Account takeover (ATO) means logging in as somebody else, or using their account as if it were yours.
  • JWT (JSON Web Token) is a small signed note that a website gives your browser after you log in, saying who you are. The site checks the note on each request instead of asking for your password again.
  • Subdomain is a prefix on a domain name, like dev in dev.site.com. Companies often use one for a test copy of the site.
  • Phishing is a message that pretends to come from someone you trust, to trick you into doing something (clicking a link, sending information).

The target and the setup

The target was a TeleHealth website where you can have a virtual appointment with a doctor. It was a private bug bounty program, so the author refers to it as www.site.com instead of the real name. A bug bounty program is a company saying: if you find a security problem in our systems and tell us responsibly, we will pay you.

The author started Burp and visited the website, then tested all the available features. He also created two accounts on the target, so he could check whether one account could reach the other's data. That is the whole toolkit: Burp, a browser and curl.

Finding it

The user ID swap

While testing authentication (the login part), he found a bug that allowed him to change his user ID. A user ID is the internal number a site uses to tell accounts apart. After changing it and logging in, he could see that the user ID inside the JWT had changed too.

With two accounts in hand, he changed the user ID of account 1 to the user ID of account 2, to see whether account 2's data became reachable. This is the classic account takeover test: if the site trusts whatever ID you present, you become the other person.

After login the page was blank. He searched online for an explanation and concluded that there might be some client-side or server-side verification. In plain words: the site probably noticed that the username and the user ID did not match, and refused to show anything. He tried response manipulation (editing the server's answer in Burp before the browser sees it) and disabling JavaScript before the data was fetched. Neither worked. His working assumption was that the site checks the username against the user ID after authentication, which blocks the swap.

Looking at other endpoints

The next idea was to test multiple endpoints, on the theory that some of them might check only the user ID and not the user ID together with the username. An endpoint is one specific address on a server, like one counter in a large office: the same building can have a counter for passports and another for driving licences, each with its own rules.

To try this, he searched across subdomains and found dev.site.com, which served the same page as the main website. He understood it to be the same application, used by the dev team to test changes before they reach the main site. A development copy is like a rehearsal stage: same play, but the crew tries new things there first.

Logging in there to see whether the account takeover would succeed did not work either.

The JavaScript comparison

Later, while on a call, he decided to look at the JavaScript. He compared the main JS file of the main website with the dev one and saw that the dev file is much larger.

He filtered the file with CTRL+F for Key, token and similar terms, and found this line:

JavaScript
twillioAuthToken=”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,twillioAuthSSID=”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”.

Line by line: twillioAuthToken is a variable name (the author spells the company name with a double l) holding a long string of characters, the auth token. twillioAuthSSID holds another long string, the account SID. The x characters stand for the real values, which are not reproduced here. Both are written directly into the file, which means every visitor's browser downloads them.

A search showed that Twilio is an API used for voice, video and email communications. In other words, the site does not build its own communications system; it uses Twilio, and these two strings are the keys to that account. The author notes that one reason for writing the report was to show the impact of leaked Twilio keys, having not seen a write-up about it.

Exploitation

Step 1: verify the credentials

After reading about the auth token and SSID and how they can be used, he ran this command to check whether the credentials work:

What each part does:

  • curl is the command-line tool sending the request.
  • -X GET says "fetch something", the same kind of request your browser makes when you open a page.
  • The URL points at Twilio's API, at the Accounts resource. The 2010-04-01 part is the version of the API.
  • -u ACCOUNT_SID:AUTH_TOKEN supplies a username and password in one go. Here the username is the account SID and the password is the auth token. This is called HTTP basic auth: the two values are joined with a colon and sent with the request.

If the credentials are wrong, the server says no. If they are right, the server answers with a list of what the account can do. The result listed the account's available resources:

Text
Addresses /2010–04–01/Accounts/$SSID/Addresses.json
Conferences /2010–04–01/Accounts/$SSID/Conferences.json
Signing_keys /2010–04–01/Accounts/$SSID/SigningKeys.json
Transcriptions /2010–04–01/Accounts/$SSID/Transcriptions.json
Connect_apps /2010–04–01/Accounts/$SSID/ConnectApps.json
Sip /2010–04–01/Accounts/$SSID/SIP.json
Authorized_connect_apps /2010–04–01/Accounts/$SSID/AuthorizedConnectApps.json
usage /2010–04–01/Accounts/$SSID/Usage.json
keys /2010–04–01/Accounts/$SSID/Keys.json
applications /2010–04–01/Accounts/$SSID/Applications.json
recordings /2010–04–01/Accounts/$SSID/Recordings.json
short_codes /2010–04–01/Accounts/$SSID/SMS/ShortCodes.json
calls /2010–04–01/Accounts/$SSID/Calls.json
notifications /2010–04–01/Accounts/$SSID/Notifications.json
incoming_phone_numbers /2010–04–01/Accounts/$SSID/IncomingPhoneNumbers.json
queues /2010–04–01/Accounts/$SSID/Queues.json
messages /2010–04–01/Accounts/$SSID/Messages.json
outgoing_caller_ids /2010–04–01/Accounts/$SSID/OutgoingCallerIds.json
available_phone_numbers /2010–04–01/Accounts/$SSID/AvailablePhoneNumbers.json
balance /2010–04–01/Accounts/$SSID/Balance.json

Each line is one drawer in the account's filing cabinet: messages, calls, recordings, phone numbers, the balance, and so on. $SSID is a placeholder for the account SID. Seeing this list is the proof that the keys are live: the server accepted them and told us what they open.

Step 2: read the message history

He then ran:

This is the same request as before, but pointed at the Messages drawer instead of the account overview. It returned the messages between internal doctors. The history exposes the number a message comes from, the destination, the body of the message and the media that were sent. In everyday terms: he could read the doctors' text conversations, including photos and other attachments.

Step 3: read the call history

He also reports being able to see the history of calls with:

That response gives information about each call, such as the phone number of the caller and the destination, the duration of the call, and the records, notifications, streams and payments related to the call. Note that the command as written in the report points at the Messages resource, the same URL as the previous step; the call information is what he describes getting from the account.

Step 4: send a message

Viewing resources was not the limit. With the message history in hand, a message can be sent from any chosen number to any destination. He describes sending a phishing message from a doctor to another doctor with:

Bash
curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json \
 — data-urlencode “Body=This will be the body of the new message” \
 — data-urlencode “From=[redacted]” \
 — data-urlencode “To=[redacted]” \
 -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Line by line:

  • -X POST means "create something", as opposed to GET, which only reads.
  • The URL is again the Messages resource, but this time we are adding a new message to it.
  • --data-urlencode "Body=..." carries the text of the message. The --data-urlencode part makes sure special characters are sent safely.
  • --data-urlencode "From=[redacted]" is the sender number. Because the account owns numbers, the sender can be chosen.
  • --data-urlencode "To=[redacted]" is the destination.
  • -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN authenticates with the same SID and token as before.

Why this matters: the message arrives from a real number the doctors recognise, so the recipient has no easy way to tell it is not from their colleague. That is exactly what phishing relies on.

Step 5: delete a message

Deletion works the same way:

Bash
curl -X DELETE https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages/MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json \
 -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
  • -X DELETE means "remove this".
  • The URL now ends with a specific message identifier, MM..., instead of the general Messages.json. The X characters stand for the real identifier, which is not reproduced here. It is like naming one letter in the filing cabinet rather than the whole drawer.
  • The same SID and token authenticate the request.

He notes that deletion and creation can also be done to calls and to all the available resources, and that other resources were left out of the report to keep it short. Among the things that can be done with them are getting records, SIP configuration and listing Authorized Apps. SIP is the standard protocol for setting up phone calls over the internet; Authorized Apps are the applications allowed to use the account.

From the original on medium.com

Why it worked

The Twilio account SID and auth token were embedded in the JavaScript of the dev site. Anyone who loaded the dev application could read the credentials from the bundle. The dev build was larger than the main site's bundle, and it carried the credentials.

Because the leaked values were the account-level SID and auth token, they authenticate against the Twilio REST API directly, with no application-side check in between. The account takeover attempts against the site's own login were blocked, likely by the username and user ID check the author suspected, but that defence is irrelevant to a credential that talks to a third-party API. The site's front door was locked; the keys to the back office were lying on the pavement.

What an attacker could do

The leaked credentials gave access to the Twilio account's resources. An attacker could read the message history between internal doctors, including sender, destination, body and media, and read call history with caller and destination numbers, call duration and the related records, notifications, streams and payments. Beyond reading, the attacker could send messages from any chosen number to any destination, which the author frames as sending a phishing message from one doctor to another, and could delete messages, calls and other resources. The author states that the bounty was 1000 USD, the maximum for this target.

How to fix it

The report does not describe what the program changed. The obvious remediation is to remove the Twilio SID and auth token from any client-side bundle, including dev builds, and to rotate the credentials that were exposed. Rotating means replacing them with new ones, so the old ones stop working. Dev environments that serve the same application should not be publicly reachable with production secrets in them.

Things to try yourself

  1. Compare production and development JavaScript bundles for the same application. A positive result is a dev bundle that is larger and contains configuration strings, keys or tokens absent from production.
  2. Search bundles for third-party provider names and credential-looking identifiers (Key, token, Auth, SSID, SID). A positive result is a hard-coded credential that authenticates against the provider's API.
  3. Enumerate subdomains of the target and check whether any of them serve the same application. A positive result is a dev or staging host with the same pages but different client-side code.
  4. When a user ID swap is blocked on login, test other endpoints that may validate only the user ID. A positive result is an endpoint that returns another account's data with the swapped identifier.
  5. Take any leaked third-party credential and verify it against the provider's account endpoint before assuming impact. A positive result is an authenticated listing of the account's resources.

Glossary

  • API: a fixed way for one program to ask another for something, like a waiter carrying orders to a kitchen.
  • Account SID: the identifier of a Twilio account, used as the username when authenticating.
  • Auth token: the secret half of a Twilio credential pair, used as the password.
  • Account takeover (ATO): gaining access to someone else's account, or acting as them.
  • Basic auth: a way of sending a username and password together with a request, joined by a colon.
  • Bug bounty program: a scheme where a company pays researchers for reporting security problems responsibly.
  • Burp Suite: a tool that sits between browser and website so you can watch and modify requests.
  • Client-side: code that runs in your browser, which means anyone can read it.
  • curl: a command-line tool for sending requests to servers and printing the answers.
  • DELETE: an HTTP method meaning "remove this resource".
  • Endpoint: one specific address on a server that handles one kind of request.
  • GET: an HTTP method meaning "fetch this resource".
  • HTTP: the language browsers and servers use to exchange requests and answers.
  • JavaScript: the code that makes web pages interactive; it is downloaded and readable by every visitor.
  • JWT (JSON Web Token): a signed note a site gives your browser after login, saying who you are.
  • Phishing: a message pretending to come from someone trusted, to trick the recipient.
  • POST: an HTTP method meaning "create something".
  • Response manipulation: editing a server's answer before the browser sees it, to test how the page reacts.
  • Rotate (credentials): replace a secret with a new one so the old one stops working.
  • Server-side: code that runs on the server, which visitors cannot read.
  • SIP: the standard protocol for setting up phone calls over the internet.
  • Subdomain: a prefix on a domain name, such as dev in dev.site.com.
  • Token: a secret string a program uses in place of a password.
  • Twilio: a service that provides voice, video and email communications through an API.
  • User ID: the internal number a site uses to tell accounts apart.
  • Verification (client-side or server-side): a check that the data you present is consistent, done either in the browser or on the server.

Similar reports

View all

Same bug class and techniques, clearest first.

Leaked secrets and credentials

The lesson behind this report.

Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.