Ravindra BagaleCourses & study guides मराठी Track your progress

41. Session Hijacking – Tokens, Cookies and Defence

Cyber Security

41.7 Detection – Logs, Concurrent Sessions, SIEM Signals

Blue cannot prevent every steal – must detect odd use:

  • Same session ID from two far cities in minutes
  • Sudden User-Agent change mid-session
  • Privilege action after long idle
  • Many 401/403 then success from new IP
  • Logout failed but cookie still accepted (invalidate bug)

Log what matters: session create, regenerate, destroy, login MFA result, IP, UA (privacy policy aware). SIEM / Wazuh / ELK – correlate; alert SOC (fictional Shahrukh) with runbook.

Red team (attacker) does Blue team (defender) detects / stops
Replays cookie from Kali while user still online Concurrent session policy; step-up MFA; kill session
Spoofs UA to match victim Combine IP+UA+behaviour; don't trust UA alone
Uses stolen session only for quiet data read DLP / access logs on exports; anomaly baselines

Ravindra Bagale's Tip

Students keep just one "login success" log line. Log the session lifecycle events – create, regenerate, destroy. These are what save you in an investigation. Got it?

Lab

Add PHP/nginx log lines on OWN app: login, regenerate, logout. From Kali replay cookie while browser still logged in. Show two IPs in log for one SID. Write alert rule pseudo: same sid + distinct /24 within 5 minutes → ticket.

Extended teaching notes

Why this lesson matters

Web flaws stay in the OWASP Top 10 because real apps still ship them. Your job is not to collect tool screenshots. It is to prevent and fix the class of bug on systems you own.

Apply the fix across stacks

Same class of bug, same idea in every language.

Java / Spring Boot

Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.

ASP.NET Core

EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.

Node.js / Express

helmet, parameterised SQL, npm audit, avoid eval and shell concat.

Python / Django / Flask / FastAPI

ORM, autoescape, pip-audit, Bandit; never shell=True with user input.

PHP / Laravel

PDO/Eloquent, Blade escaping, composer audit.

Go / Ruby

database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.

nginx / Apache / Tomcat

Hide versions, TLS, security headers, least-open ports.

MySQL / PostgreSQL / MongoDB / Redis

Private networks, auth on, least-privilege users, no 0.0.0.0/0.

AWS / Azure / GCP

Roles not long-lived keys, private data stores, cloud audit logs on.

Real examples

Global: injection and XSS still appear in breach reports and bug bounties every year. Indian company (sample): a Bengaluru SaaS team maps each OWASP item to a CI check or a code-review question so new code cannot silently reintroduce it.

Mini case study

Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.

Defender's worksheet (do this today)

  1. Write the lesson title, date and the exact lab target you are allowed to use.
  2. List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
  3. Run one safe check from the lesson on a lab system only. Paste the command and output.
  4. Write a two-sentence fix you would give a teammate.
  5. Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.

Indian workplace (sample data)

Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).

Global practice

Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.

Everyday analogy

Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.

Key terms

  • Control: a safeguard (patch, config, process, detection).
  • Finding: a weakness backed by evidence.
  • Remediation: the fix plus how you verified it.
  • Scope: systems you have written permission to touch.
  • Least privilege: only the access the task needs.
  • Defence in depth: several layers so one failure does not end the story.

Common mistakes

  • Skipping written permission "just for a quick scan".
  • Practising on hostel, office or public targets without authorisation.
  • Collecting tool output without writing the fix.
  • Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
  • Publishing screenshots that contain secrets, cookies or internal hostnames.

Recap

  • Evidence, fix, owner, date.
  • Own lab only.
  • Fix > spectacle.

Real incident: Microsoft 365 token spray – stolen sign-in sessions replayed into 79 organisations, no password needed (Oct 2026)

1. What happened

In this lesson you learnt that after you log in, the website gives you a session token (like a cookie). Whoever holds that token is "logged in". If an attacker copies it, they need no password and no MFA code.

  • On 22 October 2026, the security company Huntress reported a campaign against Microsoft 365 email accounts.
  • Between 14 July and 22 September 2026, Huntress responded to incidents at 79 organisations. It saw at least 497 successful sign-ins and more than 200,000 failed attempts from the attacker.
  • The attacker did not guess passwords. It replayed sign-in tokens stolen from victims. Huntress calls this "token spraying": like password spraying, but with stolen tokens.
  • Inside the accounts, the attacker registered at least 48 fake computers in the company directory (Microsoft Entra ID), wiped and replaced the victims' MFA methods in 19 organisations, and made hidden inbox rules.
  • In one case, the attacker sent a payroll-related email from a hacked mailbox to an outside accountant, and hid the replies. This is how business email compromise (BEC) fraud starts.
  • Strict Conditional Access rules worked: in one wave, 1,052 sign-ins were blocked, all at just four organisations. In the other organisations nothing stopped the attacker.

2. How the hack happened (public reporting only – high-level)

  1. The victim got a phishing link to a fake sign-in page. The page was a relay (adversary-in-the-middle, AiTM). It showed the real Microsoft login and the real MFA prompt.
  2. The victim typed the password and approved MFA. Microsoft gave a session token after MFA, and the relay kept a copy.
  3. Some victims were instead tricked into typing a code on Microsoft's real page (device-code phishing). That also handed tokens to the attacker.
  4. Within minutes (4 to 12 minutes in two cases Huntress timed), the attacker reused the token from rented servers. The token was made after MFA, so no MFA prompt appeared.
  5. To stay in after the token expired, the attacker added its own authenticator app and registered fake devices.
  6. It made inbox rules with short, forgettable names that deleted mail or moved it to quiet folders like RSS Feeds or Conversation History, so the owner would not see replies or warnings.
  7. It changed IP addresses between waves, so a block on one address did not stop the next wave.

3. How to stop it / defend (this lesson: detection – logs, concurrent sessions, SIEM signals)

Why: MFA protects the login. It does not protect the token made after login. So you must watch how each session is used, and kill a bad session fast.

Signals to alert on in your SIEM:

  1. A user's session used from a new country or a hosting/VPN network minutes after a normal login.
  2. The operating system or browser changes in the middle of one session (Huntress saw macOS change to Windows).
  3. MFA methods deleted and a new one added within minutes.
  4. A new device registered from a hosting network.
  5. A new inbox rule with a 1–3 character name, a rule that moves mail to RSS Feeds or Conversation History, or a rule that matches words like payroll or bank.
  6. Many Conditional Access blocks for one user. Treat this as "the password or token is valid", not as "we are safe".

Steps when you find one:

  1. Revoke all sessions of the user. A password reset alone is not enough: Huntress says an access token can still work for about 90 minutes.
  2. Reset the password.
  3. Remove unknown MFA methods and devices. A password reset leaves them in place.
  4. Delete the hidden inbox rules and warn contacts (accountant, bank) about any fake email.

The same "log out everywhere" idea in your own web app:

  • PHP: keep sessions in a database or Redis with the user id, and delete all rows for that user on password reset.
  • Node.js (express-session): use a Redis store, keep a list of session ids per user, and destroy them all on reset.
  • Java / Spring Security: use SessionRegistry.getAllSessions(user, false) and call expireNow() on each one.
  • .NET (ASP.NET Core Identity): call UpdateSecurityStampAsync(user), so old login cookies stop working at the next security-stamp check.
  • Python / Django: a password change already logs out other sessions; for a full kill, delete that user's rows from the session table.
  • JWT apps: keep access tokens short (5–15 minutes) and revoke the user's refresh tokens on the server.

4. How to take care so it won't happen again (checklist)

  • [ ] Use phishing-resistant MFA (passkeys or FIDO2 security keys) for email and admin accounts. They do not work on a fake site.
  • [ ] Turn on Conditional Access that requires MFA for all users, all apps and all client types, and allow only managed devices for staff where you can.
  • [ ] Block device-code sign-in unless a team really needs it.
  • [ ] Let only admins register devices, and stop normal users from approving new apps.
  • [ ] Every week, review new MFA methods, new devices, new inbox rules and forwarding rules.
  • [ ] Teach staff: never sign in or type a code from a link in an email. Open the app yourself.
  • [ ] Confirm any payment or bank-detail change by calling a number you already know, not one from the email.
  • [ ] Write a short runbook: revoke sessions → reset password → remove MFA methods and devices → remove rules → tell contacts.

Source: Huntress (Andrea Hatcher), "M365 Token Spray and Replay Campaign Compromises Business Email Accounts", Huntress Blog, 22 October 2026; Help Net Security, "Microsoft 365 accounts compromised at 79 organizations, no passwords needed", 23 October 2026; Infosecurity Magazine, "Widespread Token-Spraying Attacks Target Microsoft 365 Accounts", 23 October 2026.

Check if you're safe: Password Strength Checker

Real incident: Peach Aviation and Yumirulink – stolen admin sessions and a normal CSV download leaked about 9 million airline customer records (Nov 2026)

1. What happened

In this lesson you learnt how to detect a stolen session from logs. Why does this case matter? Because here the attacker used stolen sessions to download data with a normal button. It looked like a real admin at work. Only a careful look at session logs found it.

  • Peach Aviation is a low-cost airline in Japan. It sends newsletters and notice emails through Cuenote FC, an email delivery service run by a vendor called Yumirulink.
  • Yumirulink says it spotted the attack on 16 October 2026, when a staff member saw something odd on their own account. It blocked the attacker, patched the hole and shut down affected servers.
  • On 20 November 2026, Peach said 8,997,106 customer records had leaked. The data may include name, date of birth, gender, address, phone number, email address and trip details.
  • Peach said no credit card or passport details were in the leaked data, and bookings and flights were not affected. It said it had seen no misuse of the data so far.
  • Peach is not the only victim. In its 11 November report, Yumirulink said data leaked from 49 customer systems, about 47.86 million records counted in total across its customers.

2. How the hack happened (public reporting only – high-level)

  1. The attacker used a software flaw in the email service to get in. Yumirulink has not shared the technical details.
  2. Way 1: on a few servers, the attacker placed a bad program, read the database directly, and moved to other servers through the internal admin network. Yumirulink said a shared maintenance and QA account helped this spread.
  3. Way 2: using the flaw, the attacker stole the session of real users who were logged in at that time.
  4. With those stolen sessions, the attacker opened the admin screen as if they were the real user, and used the normal CSV download button to export customer lists.
  5. Way 2 needed no new program and no direct database access. So it looked like normal admin work. Yumirulink found it only after it checked the login and activity logs of all its systems, and the number of affected systems grew from 5 to 49.

3. How to stop it / defend (this lesson: detecting session misuse)

Why: a stolen session already "passed" the login and MFA. So you must watch what the session does, not only how it logged in.

What a team running a web app can do:

  1. Log every export. Who, which list, how many rows, from which IP, at what time. Big exports should send an alert.
  2. Bind the session to the device: flag the same session ID used from a new IP or new browser in a short time.
  3. Ask for MFA again (step-up) before a bulk download or any action that touches many customers.
  4. Kill shared accounts. Give each engineer their own account with MFA and only the access they need.
  5. Limit who can reach admin screens, for example only from office or VPN IP ranges. Yumirulink added this after the attack.
  6. When one sign is found, look back across all systems, not only the first broken server.

What you can do as a customer after a leak like this:

  1. Expect fake "refund", "points expiring" or "flight change" messages. Do not open links or attachments in them.
  2. Open the airline's app or type its website yourself to check anything.
  3. Never share OTP, card details or passwords over a call, SMS or email.

Example: a simple "quiet export" alert rule.

  1. Rule: one session exports more than 10,000 rows in an hour, or exports from an IP it never used before.
  2. Action: send a SIEM alert, pause the session, and ask the user to sign in again with MFA.
  3. Check: an analyst calls the real user on a known number and asks, "Did you download this list?"
  4. What it means: a normal button can still be an attack. The pattern of use tells you the truth.

4. How to take care so it won't happen again (checklist)

  • [ ] Every data export is logged and big exports raise an alert.
  • [ ] Sessions are checked for new IP or browser in the middle of use.
  • [ ] Bulk download needs a fresh MFA check.
  • [ ] No shared admin, maintenance or test accounts.
  • [ ] Admin screens are reachable only from approved networks.
  • [ ] We patch internet-facing software fast and scan for unknown programs on servers.
  • [ ] We ask our email and marketing vendors how they detect session misuse, and we send them only the data they need.

Source: Peach Aviation, "Unauthorized Access at Yumirulink Inc.: Apology and Notice Regarding the Leakage of Email Addresses and Other Personal Information", 20 November 2026; NHK News, report on the Peach personal data leak, 20 November 2026; Nikkei, report on the Peach and Yumirulink leak, 20 November 2026; Yumirulink Inc., third report on unauthorized access to its systems (stock exchange filing), 11 November 2026.

Ravindra Bagale's Tip

A stolen session does not break in. It walks in and clicks normal buttons. So log what each session does, especially exports, and alert when the pattern looks new.

Check if you're safe: Phishing Link Checker · Password Strength Checker