repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
account-takeover.mdMarkdown261 lines17.5 KiBsource raw download

title: "Account Takeover" section: "Web Pentesting" sectionSlug: "pentesting-web" sourcePath: "src/pentesting-web/account-takeover.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/account-takeover.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

Account Takeover#

Authorization Issue#

The email of an account should be attempted to be changed, and the confirmation process must be examined. If found to be weak, the email should be changed to that of the intended victim and then confirmed.[2]

Unicode Normalization Issue#

  1. The account of the intended victim victim@gmail.com
  2. An account should be created using Unicode
    for example: vićtim@gmail.com[2]

As explained in this talk, the previous attack could also be done abusing third party identity providers:[10]

Unicode/email parser disagreement#

Normalization bugs don't only happen in the UI. Also compare how the DB collation, the SMTP server, and any OAuth/OIDC provider interpret the same mailbox:

  1. The application looks up the attacker-controlled email using a permissive collation and matches the victim row.
  2. The reset token, magic link, or federated identity is later bound to the raw attacker-controlled Unicode address instead of the canonical email stored in the DB.
  3. The attacker receives the artifact or is logged in as the victim.

Practical checks:

For further details, refer to the document on Unicode Normalization:

Unicode Normalization

Reusing Reset Token#

Should the target system allow the reset link (or an equivalent magic link) to be reused, efforts should be made to find more reset links using tools such as gau, wayback, or scan.io.[2] Also verify whether the artifact still works after an email change or when redeemed from a second browser/device.

Pre Account Takeover#

  1. The victim's email should be used to sign up on the platform, and a password should be set (an attempt to confirm it should be made, although lacking access to the victim's emails might render this impossible).
  2. One should wait until the victim signs up using OAuth and confirms the account.
  3. It is hoped that the regular signup will be confirmed, allowing access to the victim's account.[2]

CORS Misconfiguration to Account Takeover#

If the page contains CORS misconfigurations you might be able to steal sensitive information from the user to takeover his account or make him change auth information for the same purpose:[2]

Cors Bypass

CSRF to Account Takeover#

If the page is vulnerable to CSRF, you may be able to make the user modify their password, email, or authentication settings and then access the account:[2]

Csrf Cross Site Request Forgery

XSS to Account Takeover#

If you find XSS in an application, you may be able to steal cookies, local-storage data, or page content that enables account takeover:[2]

Xss Cross Site Scripting

Same Origin + Cookies#

If you find a limited XSS or a subdomain take over, you could play with the cookies (fixating them for example) to try to compromise the victim account:[2]

Hacking With Cookies

Predictable SSO / bearer cookies and staged login replay#

Some cross-application SSO stacks treat a client-visible cookie as a bearer secret and use it directly as the server-side cache key for the authenticated identity. If the value is generated from low-entropy data such as System.currentTimeMillis(), a sequential ID, or an encoded timestamp with no MAC/signature, the attacker only needs to predict the victim's login window and replay candidate values.[8]

Quick triage:

Typical exploitation pattern:

  1. Send a request to a protected endpoint with the candidate ticket and the alternate-app tag.
  2. If the ticket resolves, the first request may only stage the victim identity in a new server-side session and return an auto-submitting login form.
  3. Replay the returned form or its equivalent auth endpoint (/j_security_check, SAML/OIDC bridge, custom login handler, etc.) because this second step often establishes the authenticated principal.
  4. Confirm the takeover with a follow-up protected request (200) versus the normal login redirect (302).
GET /protected.do HTTP/1.1
Host: target.tld
Cookie: CUSTOM_SSO_TICKET=<candidate>; CUSTOM_SSO_APP_TAG_NAME=<other-product>

Important constraints:

Safe detection tip: send an impossible historical token plus the mismatched app tag to a protected path and look for branch-specific cleanup Set-Cookie headers (forced cookie deletion / logout). That proves the cross-application SSO replay path is reachable without resolving a real victim session, but it does not prove the generator is still predictable.[9]

Attacking Password Reset Mechanism#

Reset Password

Passwordless email-login flows deserve the same scrutiny as reset-password flows:[6]

POST /api/auth/magic-link HTTP/1.1
Host: target.tld
Content-Type: application/json

{"email":"victim@target.tld","redirect_url":"https://attacker.tld/callback"}

Security-question resets that trust client-supplied usernames#

If an "update security questions" flow takes a username parameter even though the caller is already authenticated, you can overwrite any account's recovery data (including admins) because the backend typically runs UPDATE ... WHERE user_name = ? with your untrusted value. The pattern is:[4]

  1. Log in with a throwaway user and capture the session cookie.
  2. Submit the victim username plus new answers via the reset form.
  3. Immediately authenticate through the security-question login endpoint using the answers you just injected to inherit the victim's privileges.
POST /reset.php HTTP/1.1
Host: file.era.htb
Cookie: PHPSESSID=<low-priv>
Content-Type: application/x-www-form-urlencoded

username=admin_ef01cab31aa&new_answer1=A&new_answer2=B&new_answer3=C

Anything gated by the victim's $_SESSION context (admin dashboards, dangerous stream-wrapper features, etc.) is now exposed without touching the real answers.

Enumerated usernames can then be targeted via the overwrite technique above or reused against ancillary services (FTP/SSH password spraying).[4]

OAuth to Account takeover#

Oauth To Account Takeover

QR / Cross-Device Login Flows#

Desktop QR login, TV/device-code login, wallet login, and "approve on your phone" flows are now common ATO surfaces. Treat qrId, device_code, approval handles, and polling session identifiers like password-reset tokens.[7]

Common weaknesses to test:

Practical workflow:

  1. Start the flow in the attacker browser and capture the polling/status endpoint.
  2. Reuse the same qrId / device_code from a second browser or after the first login completes.
  3. Swap browser/session identifiers between two accounts and check whether approval follows the code instead of the original session.
  4. Try parallel polling/races and brute-forcing short QR identifiers.
  5. If the platform supports wallet or passkey-based cross-device login, verify whether the handoff is rejected when the QR/device code is stale, already redeemed, or replayed from the wrong context.

From the defender side, current guidance is to require short-lived one-time codes, add request-binding / extra confirmation data, and where possible prove device proximity.[7]

Host Header Injection#

  1. The Host header is modified following a password reset request initiation.
  2. The X-Forwarded-For proxy header is altered to attacker.com.
  3. The Host, Referrer, and Origin headers are simultaneously changed to attacker.com.
  4. After initiating a password reset and then opting to resend the mail, all three of the aforementioned methods are employed.[2]

Response Manipulation#

If the client reduces an authentication decision to a simple Boolean, test changing false to true as well as the status/body variants below. A secure server must enforce the decision independently of the client response.[2]

  1. Code Manipulation: The status code is altered to 200 OK.
  2. Code and Body Manipulation:
    • The status code is changed to 200 OK.
    • The response body is modified to {"success":true} or an empty object {}.

These manipulation techniques are effective in scenarios where JSON is utilized for data transmission and receipt.[2]

Change email of current session#

One disclosed workflow behaved as follows:[3]

Bypass email verification for Account Takeover#

Old Cookies#

In one disclosed case, it was possible to log in, save the authenticated cookies, log out, and then log in again. Although the second login generated different cookies, the earlier cookies became valid again.[11]

Trusted device cookies + batch API leakage#

Long-lived device identifiers that gate recovery can be stolen when a batch API lets you copy unreadable subresponses into writable sinks.[5]

POST https://graph.facebook.com/
batch=[
  {"method":"post","omit_response_on_success":0,"relative_url":"/oauth/access_token?client_id=APP_ID%26redirect_uri=REDIRECT_URI","body":"code=SINGLE_USE_CODE","name":"leaker"},
  {"method":"post","relative_url":"PAGE_ID/posts","body":"message={result=leaker:$.machine_id}"}
]
access_token=PAGE_ACCESS_TOKEN&method=post

References#