Skip to content
Account takeover Write-up Intermediate

IDOR and weak encryption led to a Full account takeover.

The password reset token was an encrypted and compressed string containing the profile ID, and the server did not verify a 32-character transaction token that was appended to it. An attacker could forge a token for any user and reset their password, leading to full account takeover.

Mayank Pandey Follow

Published on mayank-01.medium.com

Hello, my fellow hackers. I am Mayank Pandey, a Bug Hunter, and an Aspiring Red Teamer.

Mayank Pandey, on mayank-01.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

This is a write-up by Mayank Pandey (@mayank_pandey01) of a full account takeover in a password reset function. The company is referred to throughout as "example.com". The affected feature is the password reset flow at example.com/php/login_or_password_forgotten, where a user requests a reset by entering their profile ID and name, and receives a reset link by email.

The bug was a combination of IDOR, a bit of cryptography, and a lot of directory fuzzing. The researcher states that the takeover required no interaction from the victim user.

From the original on mayank-01.medium.com

Setup

The researcher had a few private invites pending, accepted one, and started looking for account takeovers. He used two accounts of his own: one whose reset token he could observe, and a second account whose password he wanted to change. The tools mentioned are CyberChef for decoding the token, the site's JavaScript files for reading client-side logic, directory brute forcing against /php/user, and a Python script to automate the exploit because the relevant value changes on every page refresh.

From the original on mayank-01.medium.com

Finding it

The normal reset flow

  1. The user goes to example.com/php/login_or_password_forgotten and requests a password reset by entering their profile ID and name.
  2. The profile ID and name are validated and a STATE parameter is generated:
Text
STATE=[redacted]%[redacted]%[redacted]%[redacted]%[redacted]%[redacted]%2BAyFQSHrlfOdidJbyO%2F4CvKKcYg%3D%[redacted]
  1. A password reset link is sent to the user's registered email address, and it looks like this:
HTTP
https://example.com/php/login_or_password_forgotten?k=[redacted]
  1. The user can then change their password from the dashboard after clicking the link.

The suspicious parameter

The ?k parameter looked suspicious, so the researcher copied it into CyberChef to see whether it was an encrypted string. It turned out to be an encrypted and compressed string.

From the original on mayank-01.medium.com

It was first Zlib-deflated and then the deflated string was encrypted back using Hex. The token

Text
[redacted]

decrypts back to

Text
a:2:{s:9:"timestamp";i:1614104013;s:10:"profile_id";s:8:"40884692";}

The decrypted string is a PHP-serialised array with two variables: profile_id and timestamp. Seeing this, the researcher immediately forged the token for his second account and used it to change the password:

Text
[redacted]

But the link was not valid.

From the original on mayank-01.medium.com

The twist

Comparing the original and the forged token closely, they differ in length: the difference is 32 characters. The server was not accepting any junk value in place of those 32 characters, yet both tokens decrypted to the same value:

Text
a:2:{s:9:"timestamp";i:1614104013;s:10:"profile_id";s:8:"40884692";}
From the original on mayank-01.medium.com

After searching for more information about Zlib compression and posting the query on Reddit, the researcher learned that Zlib includes an ADLER32 checksum. Calling the Adler-32 checksum function after inflating gives BC89137A, and that checksum is present in the original token. In Zlib, everything after this checksum is not part of the compression stream and is therefore ignored, which explains why both tokens give the same result despite the difference in length.

The remaining challenge was to find the 32-bit string. Since all the token-related work happened on the client side, the researcher was fairly sure something would be in the JavaScript files. After a few hours of looking, he found an endpoint /php/user. He brute forced the directory and found https://example.com/php/user/example/, which contained a string named Transction_Token. That was the last piece.

From the original on mayank-01.medium.com

Exploitation

Step 1: Request a reset and capture the token

Request a password reset for the first account through example.com/php/login_or_password_forgotten by submitting the profile ID and name. The server validates them, generates the STATE parameter, and emails a link containing the ?k token.

Step 2: Decode the token

Zlib-inflate the token and hex-decode the result. The plaintext is the PHP-serialised array shown above, exposing profile_id and timestamp.

Step 3: Forge a token for the second account

Re-serialise the array with the second account's profile_id and compress and encode it again:

Text
[redacted]

This link was rejected. The forged token was 32 characters shorter than the original, and the server would not accept a value without those characters.

Step 4: Understand the 32 characters

The original token carries an ADLER32 checksum (BC89137A) inside the Zlib stream. Everything after the checksum is ignored by the decompressor, which is why the shorter forged token still decompressed to the same plaintext but failed validation. The server would not accept any junk value in place of those 32 characters.

Step 5: Find the missing value

Reading the JavaScript files led to the endpoint /php/user. Directory brute forcing found https://example.com/php/user/example/, which returned a string named Transction_Token. This was the last piece the researcher was looking for.

Step 6: Automate and exploit

Because Transaction _Token changes every time the page is refreshed, the attack had to be precise, so the researcher wrote a Python script to automate the whole thing. He generated the token for his second account, used it to change the password, and it worked.

From the original on mayank-01.medium.com

Root cause

The reset token is a client-side artefact: a PHP-serialised array containing only profile_id and timestamp, Zlib-deflated and hex-encoded. Nothing in the token itself binds it to the requesting user beyond the profile_id it carries, so anyone who can produce a valid token for another profile ID can reset that account's password. That is the IDOR: the profile_id is attacker-controlled input.

The 32-character Transction_Token is exposed by an endpoint under /php/user/example/ and rotates on every page refresh. Because it is served to the client, it does not act as a secret; it only forces the attacker to fetch a fresh value before each attempt. The Zlib ADLER32 checksum is not an integrity control for this purpose: it is a compression checksum, and bytes after it are ignored by the decompressor, which is why the forged token decompressed correctly even though it was shorter.

Impact

An attacker who can reach the token endpoint and obtain a fresh Transction_Token can forge a reset token for another profile ID and change that account's password, resulting in a full account takeover. The researcher states that no interaction from the victim user is required. The attack depends on knowing or guessing the victim's profile ID, on the token endpoint remaining reachable, and on fetching the rotating transaction token in time for each attempt.

Fix

The report does not describe any fix or vendor response. What the design should do, based on the flaw shown, is to stop trusting client-supplied state for identity: sign the reset token server-side (for example with an HMAC over profile_id and timestamp using a server-held key), keep the reset state on the server keyed by an unguessable random value, and stop exposing the transaction token from an endpoint the client can read. The report does not say which of these, if any, was implemented.

Variants to test

  1. Decode any ?k=, ?token= or ?state= parameter in password reset and email verification links. A positive result is a readable serialised object, JSON or query string containing a user identifier, email address or timestamp.
  2. Re-encode the decoded structure with another account's identifier and submit it. A positive result is a reset form or a successful password change for the other account.
  3. Compare the length of your forged token with the original. A consistent difference, especially a fixed number of characters, suggests a checksum or an appended value the server validates separately.
  4. Look for the missing value in JavaScript files and in endpoints under paths such as /php/user, /api/user or /user/. A positive result is a token, nonce or CSRF-style string that changes on refresh and is accepted alongside the reset token.
  5. Check whether the reset token is bound to the session, the email address or a server-side record. A positive result is a token that works from a different browser, IP address or account, or after the victim's password has already been reset once.
  6. Test whether the token endpoint requires authentication. A positive result is a Transction_Token returned to an unauthenticated request.

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

What happened, in plain words

A security researcher found a way to take over anyone's account on a website by abusing the "forgot my password" feature. When you forget your password, a site usually emails you a special link that lets you set a new one. That link contains a long string of characters, called a token, which tells the site who you are. The researcher discovered that this token was not properly protected: he could decode it and read the account number inside, and after further work he could rebuild it for another account. The site would then let him set a new password for that other person's account, without the victim doing anything at all.

This write-up is by Mayank Pandey (@mayank_pandey01). The company is referred to throughout as "example.com". The affected feature is the password reset flow at example.com/php/login_or_password_forgotten, where a user requests a reset by entering their profile ID and name, and receives a reset link by email.

The bug was a combination of IDOR, a bit of cryptography, and a lot of directory fuzzing. The researcher states that the takeover required no interaction from the victim user.

From the original on mayank-01.medium.com

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

  • A token is a short piece of data that stands in for something else, like a cloakroom ticket: you hand it over and get your coat back, without the attendant needing to know your face. On the web, a reset token stands in for "this person proved they own the email address".
  • Encryption is scrambling data so that only someone with the right key can read it. Encoding is different: it changes the format of data (for example, turning bytes into letters and digits) but anyone can reverse it. A common mistake is to treat encoding as if it were encryption.
  • Compression shrinks data by finding repetition in it, like packing a suitcase tightly. Zlib is a common compression method used by web servers.
  • IDOR stands for Insecure Direct Object Reference. It means a program accepts an identifier (such as an account number) from the user and acts on it without checking that the user is allowed to touch that object. The everyday comparison: a hotel receptionist who hands out room keys to anyone who says a room number, without checking the name on the booking.
  • Account takeover means an attacker gains control of someone else's account, usually by changing its password or email address.
  • Directory fuzzing (or brute forcing) means trying many possible web addresses quickly to discover ones that are not linked anywhere, like trying every door in a corridor to see which ones open.
  • Client side means the part of a program that runs in your own browser, as opposed to the server side, which runs on the company's computers. Anything sent to the browser can be read by the person using the browser.

Setup

The researcher had a few private invites pending, accepted one, and started looking for account takeovers. He used two accounts of his own: one whose reset token he could observe, and a second account whose password he wanted to change. The tools mentioned are CyberChef for decoding the token, a browser and the site's JavaScript files for reading client-side logic, directory brute forcing against /php/user, and a Python script to automate the exploit because the relevant value changes on every page refresh.

From the original on mayank-01.medium.com

Why two accounts? Because to prove an account takeover you have to show that a token built for account A can be used to change the password of account B. Using your own two accounts keeps the test legal and safe: no real user is harmed, and you can log in afterwards to confirm the change worked.

Finding it

The normal reset flow

  1. The user goes to example.com/php/login_or_password_forgotten and requests a password reset by entering their profile ID and name.
  2. The profile ID and name are validated and a STATE parameter is generated:
Text
STATE=[redacted]%[redacted]%[redacted]%[redacted]%[redacted]%[redacted]%2BAyFQSHrlfOdidJbyO%2F4CvKKcYg%3D%[redacted]

This block is a single value, the STATE parameter, as it appears in the request. The name on the left of the equals sign is the parameter name; everything after it is the value. The value is long and looks random, which is typical of data that has been encoded or encrypted. The %2B, %2F and %3D sequences are percent-encoding: characters such as +, / and = are not allowed raw in a URL, so they are written as a percent sign followed by their character code. The trailing [redacted] is a 32-character string appended to the end.

  1. A password reset link is sent to the user's registered email address, and it looks like this:
HTTP
https://example.com/php/login_or_password_forgotten?k=[redacted]

This is the reset link. The part before the question mark is the page address; the part after it is the query string, a list of name/value pairs the page receives. Here there is one pair: the name is k and the value is the long string after the equals sign. The ? separates the address from the query string. When the user clicks the link, the browser sends this whole address to the server, and the server reads k to work out whose reset this is.

  1. The user can then change their password from the dashboard after clicking the link.

The suspicious parameter

The ?k parameter looked suspicious, so the researcher copied it into CyberChef to see whether it was an encrypted string. It turned out to be an encrypted and compressed string.

From the original on mayank-01.medium.com

CyberChef is a free website that lets you paste data and apply decoding steps to it, like a kitchen with many tools on the counter. The researcher's reasoning was simple: a token that is supposed to be secret should not be readable. If it decodes into something meaningful, the site is trusting the user with information it should have kept to itself.

It was first Zlib-deflated and then the deflated string was encrypted back using Hex. The token

Text
[redacted]

decrypts back to

Text
a:2:{s:9:"timestamp";i:1614104013;s:10:"profile_id";s:8:"40884692";}

The first block is the raw token, the value of k from the link. The second block is what you get after undoing the two steps: first hex-decoding (turning pairs of hex digits back into bytes), then Zlib-inflating (unpacking the compressed data). The result is text in a format called PHP serialisation, which is how the PHP programming language stores structured data as a string. Reading it piece by piece: a:2: means an array with two entries; s:9:"timestamp" means a string of 9 characters spelling timestamp; i:1614104013 means an integer, a Unix timestamp (a count of seconds since 1 January 1970); s:10:"profile_id" is a 10-character string naming the field; and s:8:"40884692" is an 8-character string holding the account number. So the token is nothing more than "account 40884692, issued at this moment".

The researcher immediately forged the token for his second account and used it to change the password:

Text
[redacted]

This is the forged token: the same kind of data, but with the second account's profile ID in place of the first, then compressed and hex-encoded again. The reasoning was that if the server only reads the account number out of the token, it will happily reset whichever account the token names.

But the link was not valid.

From the original on mayank-01.medium.com

The twist

Comparing the original and the forged token closely, they differ in length: the difference is 32 characters. The server was not accepting any junk value in place of those 32 characters, yet both tokens decrypted to the same value:

Text
a:2:{s:9:"timestamp";i:1614104013;s:10:"profile_id";s:8:"40884692";}
From the original on mayank-01.medium.com

This is the puzzling part. Two different strings, of different lengths, unpack to exactly the same text. If the server only cared about the unpacked text, both should work. Since one failed, the server must be checking something else, something in those extra 32 characters.

After searching for more information about Zlib compression and posting the query on Reddit, the researcher learned that Zlib includes an ADLER32 checksum. Calling the Adler-32 checksum function after inflating gives BC89137A, and that checksum is present in the original token. In Zlib, everything after this checksum is not part of the compression stream and is therefore ignored, which explains why both tokens give the same result despite the difference in length.

A checksum is a short number computed from a larger block of data, used to detect accidental corruption, like a seal on a medicine bottle that shows whether it has been opened. ADLER32 is one particular checksum used by Zlib. The key insight is that the decompressor stops reading at the checksum: any bytes after it are simply not looked at. So the forged token unpacked correctly, but the server would not accept a value without those 32 characters.

The remaining challenge was to find the 32-bit string. Since all the token-related work happened on the client side, the researcher was fairly sure something would be in the JavaScript files. After a few hours of looking, he found an endpoint /php/user. He brute forced the directory and found https://example.com/php/user/example/, which contained a string named Transction_Token. That was the last piece.

From the original on mayank-01.medium.com

An endpoint is a specific address on a server that accepts requests and returns data, like a particular counter in a large office. JavaScript files are the programs your browser downloads and runs; because they run in your browser, anyone can read them, and they often reveal addresses and logic the site never meant to advertise. The researcher's reasoning was: if the browser has to produce or check this 32-character value, the instructions for doing so must be somewhere in the code the browser downloads. Directory brute forcing then found a page under /php/user that handed out a string called Transction_Token (spelled that way in the report).

Exploitation

Step 1: Request a reset and capture the token

Request a password reset for the first account through example.com/php/login_or_password_forgotten by submitting the profile ID and name. The server validates them, generates the STATE parameter, and emails a link containing the ?k token.

This step is just the normal flow, done by the researcher on his own account. The point is to obtain a genuine token so that its structure and its extra 32 characters can be studied.

Step 2: Decode the token

Zlib-inflate the token and hex-decode the result. The plaintext is the PHP-serialised array shown above, exposing profile_id and timestamp. This confirms the token is not integrity protected in any way the researcher could see at this stage.

Integrity protection means a way of making sure data has not been altered, usually by signing it with a secret key. Without it, anyone who can read the token can also write a new one. The decoded text showed no signature, only the account number and a time.

Step 3: Forge a token for the second account

Re-serialise the array with the second account's profile_id and compress and encode it again:

Text
[redacted]

This is the same forged token as before, shown again at the moment it is submitted. "Re-serialise" means turning the structured data back into the PHP text format, with the second account's number in the profile_id field. Then the same two steps as before are applied in reverse: compress with Zlib, then hex-encode.

This link was rejected. The forged token was 32 characters shorter than the original, and the server would not accept a value without those characters.

Step 4: Understand the 32 characters

The original token carries an ADLER32 checksum (BC89137A) inside the Zlib stream. Everything after the checksum is ignored by the decompressor, which is why the shorter forged token still decompressed to the same plaintext but failed validation. The missing 32 characters are a separate value the server checks.

In other words, the token has two layers of protection, and only one of them is part of the compression format. The checksum is a property of Zlib, not a security feature. The 32 characters after it are the site's own check, and they are what the researcher still had to find.

Step 5: Find the missing value

Reading the JavaScript files led to the endpoint /php/user. Directory brute forcing found https://example.com/php/user/example/, which returned a string named Transction_Token. This was the last piece the researcher was looking for.

Why does this matter so much? Because a value that the server checks but that is handed to the browser is not a secret. It may slow an attacker down, but it cannot stop one. The researcher's reasoning was that if the page gives out the value, he can fetch it himself and attach it to his forged link.

Step 6: Automate and exploit

Because Transaction _Token changes every time the page is refreshed, the attack had to be precise, so the researcher wrote a Python script to automate the whole thing. He generated the token for his second account, used it to change the password, and it worked.

From the original on mayank-01.medium.com

A value that changes on every refresh is called rotating or one-time. It is meant to make replaying an old request useless. Here it only meant the attacker had to fetch a fresh value immediately before each attempt, which is exactly the kind of repetitive task a script is good at: fetch the current transaction token, build the forged reset token, submit both, repeat if needed. The researcher confirmed success by changing the second account's password.

Root cause

The reset token is a client-side artefact: a PHP-serialised array containing only profile_id and timestamp, Zlib-deflated and hex-encoded. Nothing in the token itself binds it to the requesting user beyond the profile_id it carries, so anyone who can produce a valid token for another profile ID can reset that account's password. That is the IDOR: the profile_id is attacker-controlled input.

The 32-character Transction_Token is exposed by an endpoint under /php/user/example/ and rotates on every page refresh. Because it is served to the client, it does not act as a secret; it only forces the attacker to fetch a fresh value before each attempt. The Zlib ADLER32 checksum is not an integrity control for this purpose: it is a compression checksum, and bytes after it are ignored by the decompressor, which is why the forged token decompressed correctly even though it was shorter.

Impact

An attacker who can reach the token endpoint and obtain a fresh Transction_Token can forge a reset token for another profile ID and change that account's password, resulting in a full account takeover. The researcher states that no interaction from the victim user is required. The attack depends on knowing or guessing the victim's profile ID, on the token endpoint remaining reachable, and on fetching the rotating transaction token in time for each attempt.

Fix

The report does not describe any fix or vendor response. What the design should do, based on the flaw shown, is to stop trusting client-supplied state for identity: sign the reset token server-side (for example with an HMAC over profile_id and timestamp using a server-held key), keep the reset state on the server keyed by an unguessable random value, and stop exposing the transaction token from an endpoint the client can read. The report does not say which of these, if any, was implemented.

An HMAC is a kind of signature made with a secret key: anyone can check it, but only someone holding the key can produce it. If the reset token carried one, changing the account number would break the signature and the server would reject the token.

Variants to test

  1. Decode any ?k=, ?token= or ?state= parameter in password reset and email verification links. A positive result is a readable serialised object, JSON or query string containing a user identifier, email address or timestamp.
  2. Re-encode the decoded structure with another account's identifier and submit it. A positive result is a reset form or a successful password change for the other account.
  3. Compare the length of your forged token with the original. A consistent difference, especially a fixed number of characters, suggests a checksum or an appended value the server validates separately.
  4. Look for the missing value in JavaScript files and in endpoints under paths such as /php/user, /api/user or /user/. A positive result is a token, nonce or CSRF-style string that changes on refresh and is accepted alongside the reset token.
  5. Check whether the reset token is bound to the session, the email address or a server-side record. A positive result is a token that works from a different browser, IP address or account, or after the victim's password has already been reset once.
  6. Test whether the token endpoint requires authentication. A positive result is a Transction_Token returned to an unauthenticated request.

Glossary

  • Account takeover: gaining control of another person's account, usually by changing its password or email address.
  • ADLER32: a checksum used inside the Zlib compression format to detect corruption; it is not a security signature.
  • API: a defined set of addresses and rules a program uses to talk to another program, like a service counter with a fixed menu of requests.
  • Checksum: a short number computed from a block of data so that accidental changes can be detected.
  • Client side: code that runs in the user's own browser, which the user can read and modify.
  • Compression: shrinking data by encoding repetition, so it takes less space.
  • CyberChef: a free web tool for applying encoding, decoding and analysis steps to data.
  • Directory brute forcing (fuzzing): trying many possible web addresses quickly to find ones that are not linked publicly.
  • Encoding: changing the format of data (for example bytes to hex digits) in a way anyone can reverse; it is not encryption.
  • Encryption: scrambling data so that only someone with the right key can read it.
  • Endpoint: a specific address on a server that accepts requests and returns data.
  • Hex encoding: writing each byte of data as two characters from 0 to 9 and A to F.
  • HMAC: a signature made with a secret key, used to prove data has not been altered.
  • IDOR (Insecure Direct Object Reference): a flaw where a program accepts an identifier from the user and acts on it without checking permission.
  • Integrity protection: any mechanism that lets a receiver detect that data has been changed, usually a signature.
  • JavaScript: the programming language browsers run; the files are downloaded by the browser and can be read by anyone.
  • Percent-encoding: writing characters that are not allowed in a URL as a percent sign followed by their code, such as %2F for /.
  • PHP serialisation: a text format used by PHP to store structured data as a string, such as a:2:{...} for an array of two entries.
  • Profile ID: the number that identifies a user's account on the site.
  • Query string: the part of a URL after the ?, made of name/value pairs.
  • Rotating (one-time) value: a value that changes on every page load or use, intended to stop old requests being replayed.
  • Server side: code that runs on the company's computers, which the user cannot see or change.
  • STATE parameter: the parameter generated during the reset request in this report, carrying encoded data.
  • Timestamp: a number recording a moment in time, here a count of seconds since 1 January 1970.
  • Token: a piece of data that stands in for proof of identity or permission, like a cloakroom ticket.
  • Transction_Token: the 32-character value served by the endpoint under /php/user/example/ in this report, spelled that way in the original.
  • Unix timestamp: a time written as the number of seconds since 1 January 1970.
  • Zlib: a common compression format, which includes an ADLER32 checksum and ignores bytes after it.

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.