Skip to content
Account takeover Write-up Intermediate

$10,000 Bounty: How I Chained Weak APK Encryption and a JWT Cookie for Full Admin Access

An Android app hid an encrypted client ID and secret in its code, protected only by weak XOR encryption that could be brute-forced. Using the recovered credentials, the researcher obtained an admin JWT from the API and then reused that same token as a cookie to log into the separate admin dashboard.

DarkyOS Follow

Published on medium.com

Bug Bounty

Ahmed Ghadban, 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 an Android mobile application backed by what the author describes as a complex backend. The application shipped with an encrypted client_id and client_secret embedded in its own code. Alongside the mobile API at api.prod.target.com, the production environment also exposed an administrative web dashboard at admin.prod.target.com.

The chain described here starts with static analysis of the APK, moves to the API, and ends on the dashboard. The author reports a $10,000 bounty, rates the severity as Critical, and lists the vulnerabilities as hardcoded encrypted secrets, weak cryptography (XOR) and an insecure authentication implementation.

Setup

The work was done from a downloaded copy of the APK. The author decompiled and unpacked it and inspected the .smali files, looking for hardcoded API keys, Firebase credentials or hidden endpoints. A short Python script was used for the decryption step, and requests were intercepted during the dynamic phase to monitor application traffic and to modify requests to both hosts. The report does not name the proxy, the decompiler or any version numbers.

The precondition for the whole chain is that the mobile application contains the credentials needed to obtain an admin-level token, and that the same token is accepted by a second, web-facing component.

Finding it

Inside the application logic, the author found an encrypted client_id and client_secret. The developers had XOR-encrypted these credentials before compiling the app. The author's judgement is that XOR is weak when the key space is small or when the ciphertext can be easily manipulated, so the obfuscation was treated as a hurdle rather than a control.

Rather than reverse-engineering the exact key generation routine from the Smali code by hand, the author chose to brute-force the key. The ciphertext was extracted and a Python script iterated over the possible key space.

Exploitation

Step 1: Extract the ciphertext from the APK

After decompiling the APK, the encrypted client_id and client_secret were pulled out of the Smali. The report shows the two ciphertext values only as placeholders:

Python
ciphertext_id = [...] ciphertext_secret = [...]

Step 2: Brute-force the XOR key

The script tries every key in the range 0 to 65535, XORs each byte of the ciphertext with the candidate key, and checks whether the result contains an expected prefix. On a match it prints the key and the decrypted client ID and stops:

Python
for key in range(65536):    decrypted_id = ''.join([chr(b ^ key) for b in ciphertext_id])    if "expected_prefix" in decrypted_id:         print(f"[+] Key found: {key}")        print(f"[+] Client ID: {decrypted_id}")                break

After exactly 65,000 iterations the script produced the plaintext client_id and client_secret. The single-byte key space is what makes this cheap: 65,536 candidates is trivial to test, and the known prefix gives a reliable way to recognise the correct plaintext.

Step 3: Obtain an admin JWT from the API

With the plaintext credentials, the author moved to dynamic analysis. Monitoring the application traffic identified the main API endpoint at api.prod.target.com. A request to the authentication endpoint using the decrypted credentials returned an admin-level JWT:

HTTP
HTTP/1.1 200 OKContent-Type: application/json
JSON
{  "access_token": "[redacted]..[REDACTED]",  "token_type": "Bearer",  "expires_in": 3600}

The token payload contains a role of admin, and the response tells the client to present it as a Bearer token. Injecting it into subsequent API requests as Authorization: Bearer <JWT> worked, and the author had access to a few administrative API endpoints. The features exposed on that API subdomain were relatively minor, so the author judged that reporting this alone would likely have been triaged as Medium severity.

Step 4: Try the token against the dashboard

Reconnaissance was expanded to web interfaces in the production environment, and the main administrative interface was found at admin.prod.target.com. The author navigated to the dashboard and attempted to bypass the login portal with the admin JWT, intercepting the dashboard requests and injecting the standard authorization headers:

  • Authorization: Bearer <JWT> gave 401 Unauthorized
  • Authorization: Basic <JWT> gave 401 Unauthorized

At that point the token appeared to be scoped strictly to api.prod.target.com and invalid for the dashboard.

Step 5: Move the token into a cookie

Before giving up, the author reviewed the exact JSON response from the token endpoint, {"access_token": "<JWT>"}, and reasoned that web applications frequently rely on cookies for session management rather than authorization headers. The hypothesis was that the dashboard's authentication middleware was looking for a specific cookie parameter instead of a header.

The Authorization header was stripped, a Cookie header was added, and the parameter name was set to match the JSON key from the API response:

HTTP
GET /admin/dashboard HTTP/1.1Host: admin.prod.target.comCookie: access_token=[redacted]..[REDACTED]

HTTP/1.1 200 OK

The response size changed drastically and the dashboard loaded completely. Using the API-generated token as an access_token cookie bypassed the dashboard authentication entirely.

From the original on medium.com

Root cause

The author identifies three developer mistakes behind the chain.

  1. Security by obscurity. Basic XOR encryption was used to hide highly privileged client secrets inside the APK. Hardcoded secrets will always be extracted, and a single-byte XOR key is recoverable by brute force.
  2. Cross-domain token reusability. The JWT generated for the mobile API was valid and accepted by the web administrative dashboard, with no proper audience (aud) or scope restriction separating the two.
  3. Inconsistent authentication middleware. The API expected a Bearer header, while the dashboard silently accepted the exact same token via an access_token cookie. That difference let the token be moved between infrastructure components.

Impact

The cookie manipulation granted full Super Admin privileges over admin.prod.target.com. According to the author, this meant complete control over the entire application ecosystem, user data and configurations.

The impact depends on two conditions holding together: the client credentials in the APK must be sufficient to mint an admin-level token, and the dashboard must accept that token from a cookie. The author also notes that the API-only access, without the dashboard pivot, would likely have been rated Medium.

Fix

The report does not say what the vendor changed. Based on the mistakes it lists, the fixes it points to are: stop shipping privileged client secrets in the APK, and if a secret must be embedded, do not rely on XOR or any other reversible obfuscation to protect it; restrict tokens by audience and scope so a token minted for the mobile API is rejected by the dashboard; and make authentication middleware consistent across components, so the same token is validated the same way whether it arrives in a header or a cookie.

Variants to test

  • Single-byte XOR over embedded secrets. Extract ciphertext from a decompiled APK and try all 256 single-byte keys, then extend to 16-bit keys as in the script above. A positive result is readable plaintext containing a recognisable prefix such as a client ID pattern.
  • Credential reuse across services. Take a token minted by one service and replay it against sibling hosts (admin, dashboard, internal APIs) in both Authorization and Cookie headers. A positive result is a 200 with a materially larger body than the unauthenticated response.
  • Cookie name matching the JSON key. When a token endpoint returns a field such as access_token, try that exact name as a cookie parameter on other hosts. A positive result is an authenticated session where the header form returned 401.
  • Audience and scope checks. Decode the JWT payload and look for aud, scope or iss claims. If they are absent, or present but not enforced, replay the token against a different host and watch for acceptance.
  • Role claims from client credentials. Request a token with the extracted client credentials and inspect the resulting role claim. A positive result is an administrative role issued to a client that should only have mobile API access.

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

What happened, in plain words

A security researcher found a way to take over the administration panel of a company's production system. The company had an Android app, and inside that app's code were two secret passwords (a client_id and a client_secret) that the app used to talk to its backend. The developers had tried to hide these passwords by scrambling them with a very simple maths trick called XOR encryption. The researcher unpacked the app, found the scrambled values, and wrote a small program that tried every possible key until the scramble came undone. With the real passwords in hand, he asked the company's API for a login token, and the API handed him one that said he was an administrator.

That token worked on the API, but only gave access to a few minor features. He then found the company's admin dashboard on a different web address and tried the same token there. Sent in the normal Authorization header, it was rejected with 401 Unauthorized. But when he put the same token into a cookie named access_token, the dashboard let him straight in with full Super Admin rights. The report lists a $10,000 bounty and rates the issue Critical.

This article walks through the whole chain from the beginning, explaining every term as it comes up. You only need to know how to use a browser and a computer to follow it.

The pieces involved

Before the steps, here is what each part of the system is, in everyday terms.

  • The Android app (APK). An APK is the file you install on an Android phone. It is a bit like a sealed cardboard box: inside are the app's pictures, its code, and any data it ships with. Anyone who has the box can open it. The app in this story was the mobile front end of a larger service.
  • The backend. The app does not hold all the data itself. It talks over the internet to servers run by the company. Those servers are the backend, and they hold the user accounts, the settings and the business data.
  • The API. An API (Application Programming Interface) is the counter where one program asks another program to do something. Think of a restaurant: the app is the customer, the API is the waiter, and the backend is the kitchen. The customer does not walk into the kitchen; they tell the waiter what they want, and the waiter brings it back. In this story the mobile API lived at api.prod.target.com.
  • The dashboard. A dashboard is a website with buttons and screens for staff, usually administrators, to manage the service. Here it lived at admin.prod.target.com. It is a separate web address from the API, but it belongs to the same company and the same production environment.
  • Credentials. A client_id and a client_secret are a username and password pair for a program rather than a person. The app uses them when requesting a token from the API. If someone else gets hold of them, they can pretend to be the app.
  • A token (JWT). When the app logs in with its credentials, the API replies with a token. A JWT (JSON Web Token) is a long string of characters that acts like a stamped wristband at an event: once you have it, you can walk through doors without showing your ticket again. The token contains information about who you are and what you are allowed to do, and it is signed. The API response in this story told the app to present the token as a Bearer token, which simply means "the person holding this is the bearer of these rights".
  • A header. When your browser or an app sends a request to a server, it attaches small labelled notes called headers. One header says which web address you want, another says what kind of browser you use. Authorization is a header used to carry proof of who you are.
  • A cookie. A cookie is a small note that a website asks your browser to keep and to send back on every later request to that site. It is how most websites remember that you are logged in. Instead of carrying your password on every page, your browser carries the cookie.
  • XOR encryption. XOR is a simple operation on numbers: it compares two values bit by bit and produces a third. If you XOR a piece of text with a key, you get scrambled text; XOR the scrambled text with the same key again and you get the original back. It is like a lock that opens with the same motion that closed it. That makes it reversible, and reversible scrambling is not real encryption when the key is short enough to guess.
  • Brute force. Trying every possible answer until one works. Like working through every combination on a suitcase lock instead of picking it.
  • Static analysis. Examining a program without running it, by opening its files and reading the code. The opposite, watching the program while it runs and talking to the network, is dynamic analysis.

Phase 1: Opening the app and finding secrets

The first step in mobile testing is static analysis. The researcher downloaded the APK, unpacked it and decompiled it. Decompiling means turning the compiled code back into something a human can read. Android apps compile down to a form called Smali, which is a low-level, assembly-like language. It is not friendly to read, but it is readable enough to search.

He searched the .smali files for the usual suspects: hardcoded API keys, Firebase credentials, or hidden endpoints. "Hardcoded" means written directly into the program's code instead of being fetched from a safe place at runtime. It is like taping your house key to the front door: convenient, but anyone who walks up can take it.

Deep inside the application logic he found something more interesting: an encrypted client_id and client_secret. The developers had tried to protect these by XOR-encrypting them before compiling the app. The researcher's view was that XOR is notoriously weak when the key space is small, or when the scrambled text can be easily manipulated. So he treated the scrambling as a hurdle, not as a real lock.

Why this step matters: if the app carries the keys to the backend, then anyone who can open the app can eventually get those keys. The only question is how much work it takes.

Phase 2: Cracking the XOR scrambling

Instead of spending hours manually reverse-engineering the exact key generation routine from the Smali code, the researcher chose brute force. He pulled the scrambled values out of the app and wrote a short Python script to try every possible key.

First, the scrambled values themselves. The report shows them only as placeholders:

Python
ciphertext_id = [...] ciphertext_secret = [...]

Line by line:

  • ciphertext_id = [...] stores the scrambled form of the client ID in a variable called ciphertext_id. "Ciphertext" is the scrambled text; the original is called plaintext. The [...] is a placeholder standing in for the actual bytes, which are not shown.
  • ciphertext_secret = [...] does the same for the scrambled client secret.

Then the cracking loop:

Python
for key in range(65536):    decrypted_id = ''.join([chr(b ^ key) for b in ciphertext_id])    if "expected_prefix" in decrypted_id:         print(f"[+] Key found: {key}")        print(f"[+] Client ID: {decrypted_id}")                break

Line by line:

  • for key in range(65536): starts a loop that runs once for every number from 0 to 65,535. Each number is a candidate key. 65,536 is two to the power of sixteen, so this covers every possible 16-bit key. That is the "key space": the set of all keys that could have been used. A small key space is what makes brute force practical.
  • decrypted_id = ''.join([chr(b ^ key) for b in ciphertext_id]) takes each byte b of the scrambled client ID, XORs it with the candidate key, turns the result into a character with chr, and glues all the characters together into a string. If the key is right, the result is readable text; if it is wrong, the result is garbage.
  • if "expected_prefix" in decrypted_id: checks whether the result contains a known starting pattern. This is the trick that makes brute force reliable: you need a way to recognise the correct answer among 65,536 wrong ones. A client ID usually has a recognisable shape, so the researcher looked for that shape.
  • print(f"[+] Key found: {key}") prints the winning key.
  • print(f"[+] Client ID: {decrypted_id}") prints the decrypted client ID.
  • break stops the loop, because there is no need to keep trying once the key is found.

After exactly 65,000 iterations, the script hit the jackpot and printed the plaintext client_id and client_secret. The reason this was cheap: 65,536 candidates is a tiny number for a computer, and the known prefix gave a dependable way to spot the right plaintext.

Phase 3: Getting an admin token from the API

With the real credentials in hand, the researcher moved to dynamic analysis. He monitored the app's network traffic and identified the main API endpoint at api.prod.target.com. An endpoint is a specific address on a server that does a specific job, like a particular counter in a large office.

He sent a request to the authentication endpoint using the decrypted credentials. Authentication is the process of proving who you are; the endpoint is the login desk. The server replied with an admin-level JWT:

HTTP
HTTP/1.1 200 OKContent-Type: application/json

Line by line:

  • HTTP/1.1 200 OK is the status line. HTTP is the language browsers and servers speak. 200 OK means the request succeeded. Other numbers you will meet later, like 401, mean something went wrong.
  • Content-Type: application/json is a header telling the reader that the body of the response is JSON, a text format for structured data. JSON looks like a set of labelled boxes: a name, a colon, a value.

Then the body:

JSON
{  "access_token": "[redacted]..[REDACTED]",  "token_type": "Bearer",  "expires_in": 3600}

Line by line:

  • "access_token": "eyJ..." is the token itself. The long string is a JWT. The first part, before the first dot, is a header describing how the token is signed. The middle part is the payload, which carries claims, meaning statements about the holder. This payload decodes to a role of admin. The rest is cut off and marked [REDACTED].
  • "token_type": "Bearer" tells the client how to present the token: as a Bearer token, in the Authorization header.
  • "expires_in": 3600 says the token is valid for 3,600 seconds, which is one hour. After that it stops working, so the holder has to ask for a new one.

The researcher then intercepted his own subsequent API requests and injected the token into the headers as Authorization: Bearer <JWT>. Intercepting means putting a tool between the app and the server so you can read and change the traffic in flight, like opening letters at the post office before they are delivered.

It worked. He had access to a few administrative API endpoints. But the features exposed on that particular API subdomain were relatively minor. Reporting only this would likely have been triaged as Medium severity. Triaged means the company's security team reviews the report and assigns it a priority. Medium is respectable but not the top of the scale, so the researcher kept digging.

Phase 4: Trying the token on the dashboard

He widened his reconnaissance to look for web interfaces connected to the production environment. Reconnaissance is the surveying phase: finding out what exists before attacking anything. Shortly after, he found the main administrative interface at admin.prod.target.com.

He opened the dashboard and tried to get past the login screen using the admin JWT he had generated from the API. He intercepted the dashboard's requests and injected the standard authorization headers:

  • Authorization: Bearer <JWT> gave 401 Unauthorized
  • Authorization: Basic <JWT> gave 401 Unauthorized

What these mean:

  • Authorization: Bearer <JWT> is the way the API itself had told him to present the token. 401 Unauthorized means the server did not accept the proof of identity.
  • Authorization: Basic <JWT> is a different scheme, where the value is normally a username and password encoded together. It was a reasonable thing to try, and it also failed.

At this point it looked like the token was scoped strictly to api.prod.target.com and was invalid for the dashboard. "Scoped" means limited to a particular place or purpose. A staff discount card that only works in one branch is scoped to that branch.

Phase 5: Moving the token into a cookie

Before giving up, the researcher went back and read the exact JSON response he had received when generating the token: {"access_token": "<JWT>"}. He reasoned that web applications frequently rely on cookies for session management rather than authorization headers. A session is the period during which a website remembers you are logged in. The hypothesis was that the dashboard's authentication middleware was looking for a specific cookie parameter instead of a header. Middleware is the layer of software that sits in front of the application and checks requests before they reach it, like a doorman.

So he stripped the Authorization header, added a Cookie header, and set the parameter name to match the JSON key from the API response:

HTTP
GET /admin/dashboard HTTP/1.1Host: admin.prod.target.comCookie: access_token=[redacted]..[REDACTED]

Line by line:

  • GET /admin/dashboard HTTP/1.1 is the request line. GET means "give me this page". /admin/dashboard is the path on the server. HTTP/1.1 is the version of the protocol.
  • Host: admin.prod.target.com tells the server which website the request is for. One server can host many sites, so this header picks the right one.
  • Cookie: access_token=eyJ... is the key change. It sends the token as a cookie named access_token, exactly matching the field name in the API's JSON response. The name matters: the dashboard's doorman was apparently checking for a cookie with that name.

The response was:

HTTP/1.1 200 OK

The response size changed drastically and the dashboard loaded completely. By using the API-generated token as an access_token cookie, he bypassed the dashboard authentication entirely. Bypassed means got around, like walking through a side door that was left unlocked while the front door was bolted.

From the original on medium.com

Why it worked

The researcher identifies three developer mistakes behind the chain.

  1. Security by obscurity. Basic XOR encryption was used to hide highly privileged client secrets inside the APK. Obscurity means hiding something and hoping nobody looks. Hardcoded secrets will always be extracted, and a single-byte XOR key is recoverable by brute force. The lock was made of paper.
  2. Cross-domain token reusability. The JWT generated for the mobile API was valid and accepted by the web administrative dashboard, with no proper audience (aud) or scope restriction separating the two. The aud claim in a JWT is meant to say which service the token is for, like a ticket that says "valid for screen 3 only". Without it, or without anyone checking it, the ticket works on every screen.
  3. Inconsistent authentication middleware. The API expected a Bearer header, while the dashboard silently accepted the exact same token via an access_token cookie. That difference let the token be moved between infrastructure components. Two doormen, two different rulebooks.

Impact

The cookie manipulation granted full Super Admin privileges over admin.prod.target.com. According to the researcher, this meant complete control over the entire application ecosystem, user data and configurations. In plain terms: the keys to the building, the filing cabinets and the settings panel.

The impact depends on two conditions holding together: the client credentials in the APK must be sufficient to mint an admin-level token, and the dashboard must accept that token from a cookie. Mint here means issue or create. The researcher also notes that the API-only access, without the dashboard pivot, would likely have been rated Medium.

Fix

The report does not say what the vendor changed. Based on the mistakes it lists, the fixes it points to are:

  • Stop shipping privileged client secrets in the APK. If a secret must be embedded, do not rely on XOR or any other reversible obfuscation to protect it.
  • Restrict tokens by audience and scope, so a token minted for the mobile API is rejected by the dashboard.
  • Make authentication middleware consistent across components, so the same token is validated the same way whether it arrives in a header or in a cookie.

Variants to test

If you are learning, these are the same ideas applied in slightly different ways.

  • Single-byte XOR over embedded secrets. Extract ciphertext from a decompiled APK and try all 256 single-byte keys, then extend to 16-bit keys as in the script above. A positive result is readable plaintext containing a recognisable prefix such as a client ID pattern.
  • Credential reuse across services. Take a token minted by one service and replay it against sibling hosts (admin, dashboard, internal APIs) in both Authorization and Cookie headers. A positive result is a 200 with a materially larger body than the unauthenticated response.
  • Cookie name matching the JSON key. When a token endpoint returns a field such as access_token, try that exact name as a cookie parameter on other hosts. A positive result is an authenticated session where the header form returned 401.
  • Audience and scope checks. Decode the JWT payload and look for aud, scope or iss claims. If they are absent, or present but not enforced, replay the token against a different host and watch for acceptance.
  • Role claims from client credentials. Request a token with the extracted client credentials and inspect the resulting role claim. A positive result is an administrative role issued to a client that should only have mobile API access.

Glossary

  • APK: the installable file format of an Android app; a package containing the app's code, resources and bundled data.
  • API: a defined way for one program to ask another program to do something, usually over the network.
  • API endpoint: a specific address on a server that performs a specific function, such as logging in or fetching a list.
  • Audience (aud): a claim inside a token stating which service the token is intended for.
  • Authentication: the process of proving who you are, for example with a password or a token.
  • Authorization header: an HTTP header used to carry proof of identity, such as a token or encoded credentials.
  • Backend: the servers and software behind an app or website that store data and do the real work.
  • Bearer token: a token presented on the understanding that whoever holds it gets the rights it carries.
  • Bypass: getting around a control, such as a login screen, without satisfying it as intended.
  • Ciphertext: text that has been scrambled; the opposite of plaintext.
  • Claim: a statement inside a token, such as a role or an expiry time.
  • Client ID / client secret: a username and password pair used by a program, rather than a person, to identify itself to a service.
  • Cookie: a small piece of data a website asks a browser to store and send back with later requests, commonly used to keep you logged in.
  • Credentials: the information used to prove identity, such as a username and password or a client ID and secret.
  • Cross-domain: spanning more than one web address or service.
  • Dashboard: a website with screens and controls for managing a service, usually for staff or administrators.
  • Decompile: turn compiled program code back into a more human-readable form.
  • Dynamic analysis: examining a program while it runs, for example by watching its network traffic.
  • Encryption: scrambling data so that only someone with the right key can read it.
  • Endpoint: see API endpoint.
  • Hardcoded: written directly into a program's code rather than supplied from outside at runtime.
  • Header: a labelled note attached to an HTTP request or response, carrying metadata such as the host or the content type.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • HTTP 200 OK: the status code meaning a request succeeded.
  • HTTP 401 Unauthorized: the status code meaning the server did not accept the proof of identity.
  • Intercepting proxy: a tool placed between a client and a server that can read and modify traffic in flight.
  • JSON: a text format for structured data, made of names and values.
  • JWT (JSON Web Token): a signed string carrying claims about the holder, commonly used as a login token.
  • Key space: the set of all possible keys; a small key space makes brute force practical.
  • Middleware: software that sits in front of an application and inspects requests before they reach it.
  • Obfuscation: making something harder to understand, without actually securing it.
  • Plaintext: readable, unscrambled text.
  • Production environment: the live systems that real users and staff use, as opposed to test systems.
  • Reconnaissance: the surveying phase of a test, finding out what systems and addresses exist.
  • Role: a claim describing what a user is allowed to do, such as admin.
  • Scope: the limits on where or for what a token or credential is valid.
  • Security by obscurity: relying on hiding something rather than on a real control.
  • Session: the period during which a website remembers that you are logged in.
  • Smali: the low-level, assembly-like code that Android apps compile to, readable after decompilation.
  • Static analysis: examining a program without running it, by reading its files and code.
  • Super Admin: the highest level of administrative privilege.
  • Token: a string issued after login that stands in for your credentials on later requests.
  • Triaged: reviewed and prioritised by a security team.
  • XOR: a simple reversible operation on numbers, often used to scramble data; reversible scrambling with a short key is not real encryption.

More by DarkyOS

View all

1 more disclosed report, best first.

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.