Skip to content
XSS Write-up Beginner

Reflected XSS Injection & Permanent Open Redirection

A reflected cross-site scripting vulnerability existed in a search function, where a malicious link could execute script in a victim's browser when they searched. An attacker could steal cookies and potentially perform account takeover or fraudulent purchases.

0 day exploit Follow

Published on medium.com

Bounty$2,000 View original

Follow

0 day exploit, 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. 4 min read.

Context

The feature at the centre of the report is the site's search. When a user searches, the search term is shown in the search history. That behaviour, a value being echoed back into a page the user later sees, is what made the researcher look more closely. The report describes two issues found in that area: a reflected cross-site scripting (XSS) injection and what the author calls a permanent open redirection.

The author's own summary of the XSS is a little loose: it describes reflected (persistent) XSS as code that is permanently stored and later executed when victims visit the page. The exploitation described below is a reflected XSS delivered through a crafted link, so the payload travels in the URL rather than being stored server-side.

Setup

The report does not describe any accounts, roles, tooling versions or other preconditions. The only infrastructure mentioned is a payload script hosted on the researcher's own server, and a WAF on the target that interfered with the first attempts.

Finding it

The researcher first tried a general payload, which did not work because of the WAF. While working around that, they noticed that the search item is shown in the search history. Looking at that behaviour more closely, they found a reflected XSS: a malicious link containing the payload can be sent in the URL, and when the victim searches for anything, the XSS triggers and the attacker can obtain the victim's account cookies. The author adds that if the victim has saved credit card details, the attacker could buy e-coupons and gift cards with the account.

After some attempts, the researcher also made a script that performs an open redirect with a malicious URL.

Exploitation

Step 1: a payload that survives the WAF

The first general payload was blocked by the WAF. The payload the researcher settled on is:

This injects a button labelled CLICK ME. The onclick handler runs when the victim clicks it, and calls alert with the result of document.write, which writes an iframe pointing at https://brutelogic.com.br/xss-waf.php into the page. The iframe loads a page from brutelogic.com.br.

Step 2: the redirect script hosted on the researcher's server

The second payload is a full HTML document, hosted on the researcher's own server:

The author breaks the code down as follows:

  1. The <html> and <body> tags define the HTML structure and content of the page.
  2. The <script> tag defines a block of JavaScript executed by the browser. The language attribute specifies JavaScript, and the type attribute specifies text/javascript.
  3. The try block attempts to execute the following:
    • The variable rurl is set to https://00eth0.xss.ht?&.
    • window.top.location.replace(rurl) replaces the current page's location with the URL in rurl, redirecting the user to https://00eth0.xss.ht.
  4. If an exception is caught in the try block, the catch block runs instead. document.write() displays a message saying "This page has moved, Click here to go there." The A HREF attribute of the hyperlink points to http://ww6.gsrtc.com?&amp;&amp;jserror=1, the destination the user is redirected to if the code in the try block fails.

In short, the script tries to redirect the user to https://00eth0.xss.ht, and if that redirection fails, it falls back to http://ww6.gsrtc.com?&amp;&amp;jserror=1.

Root cause

The author's opinion is that the issue happened for three reasons:

  1. While uploading the file, the extension was not being checked.
  2. After the file was uploaded, Content-Type validation was not done.
  3. After the file was sent to the server, it was not validated by the server.

These points describe the handling of the uploaded script file. For the search reflection, the report only notes that the search term is shown in the search history and that the WAF was the obstacle to a general payload; it does not describe the server-side handling of the search value in more detail.

Impact

According to the report, an attacker can steal the authentication token of any user and can craft different attacks such as CSRF, session attacks and account takeover. The author notes that the impact depends on what kind of information was stored in localStorage.

The researcher calculated the following CVSS vector:

Text
CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N

That gives a score of 8.2 (High).

Fix

The report's mitigation advice is that the site should keep the WAF on the search and other places where a payload could be injected, and that checks should be performed to mitigate this kind of issue.

Variants to test

  • Search reflections: submit a benign marker in the search box and look for it in the search history and in any URL that renders it. A positive result is the marker appearing unencoded in an HTML context, which you can then test with a harmless proof such as an alert.
  • WAF bypasses: when a general payload is blocked, try alternative encodings, different event handlers and tag combinations. A positive result is the browser executing the handler while the WAF still returns a normal page.
  • Upload handling: upload a file with an unexpected extension and a script content type, then request it back. A positive result is the server returning the file with a content type that the browser will execute.
  • Redirect parameters: look for parameters that take a URL and redirect to it, and test whether the destination is validated. A positive result is a redirect to a domain you control.

Bounty

The reward was 2,000 USD.

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

What happened, in plain words

A security researcher found a way to make a website show and run code that the researcher wrote, instead of the ordinary content the site meant to show. This kind of trick is called cross-site scripting, usually shortened to XSS. The idea is simple: a website takes something a visitor typed, such as a search word, and later puts that same text back into a page. If the site does not clean the text first, an attacker can type something that is not really a search word but a small program, and the visitor's browser will run it as if the site itself had written it.

The researcher also found a second problem: a way to send a visitor from the site to a different website chosen by the attacker. That is called an open redirect. The word "open" means the site will forward people to any address it is given, without checking whether that address is trustworthy.

The feature involved was the site's search. When someone searches, the search term is shown in the search history. That is the key detail: the site remembers what you typed and shows it back to you. Anything a site shows back to you is a place where an attacker might be able to slip in code.

0 day exploit
0 day exploit From the original on medium.com

The report describes two issues found in that area: a reflected XSS injection and what the author calls a permanent open redirection. The author's own summary of the XSS is a little loose: it describes reflected (persistent) XSS as code that is permanently stored and later executed when victims visit the page. The exploitation described below is a reflected XSS delivered through a crafted link, so the payload travels in the URL rather than being stored on the server.

Before going further, a few everyday comparisons help.

  • A browser is the program you use to look at websites, such as Chrome, Firefox or Safari. It reads a page written in a language called HTML and draws it on your screen.
  • HTML is the language that describes what is on a page: headings, buttons, links, images. It is made of tags in angle brackets, like <button> for a button.
  • JavaScript is a programming language that browsers can run. It lets a page react to clicks, change what is shown, and much more. When a browser runs JavaScript that came from an attacker, that is the heart of XSS.
  • A payload is the piece of text or code an attacker sends to try to make something happen. Think of it as the message you put inside an envelope; the envelope is the request, the payload is the content.
  • A URL is the address of a page, the thing in the address bar at the top of your browser.
  • A WAF, short for Web Application Firewall, is a filter that sits in front of a website and inspects incoming requests. It is like a bouncer at a door who checks what people are carrying and turns away anything that looks dangerous. A WAF can block an attack, but it can also be worked around, which is what happened here.
  • A cookie is a small piece of data a website asks your browser to keep and send back with every request. It is how a site remembers that you are logged in. If an attacker can read your cookies, they may be able to act as you.
  • A token is similar in spirit: a string of characters that proves who you are, like a wristband at an event. Steal the wristband and you can walk in as someone else.
  • localStorage is a storage area inside your browser where a website can keep data on your computer. It is like a small locker the site rents in your browser. What is inside that locker matters, because if an attacker can run code on the site, they may be able to read it.
  • CSRF, short for Cross-Site Request Forgery, is a trick where an attacker makes your browser send a request to a site you are logged into, without you meaning to. It is like someone using your hand to sign a form.
  • Account takeover means an attacker gains control of someone else's account, for example by stealing their login token.
  • CVSS is a scoring system for how serious a security flaw is. It produces a number, and a vector string that describes the characteristics of the flaw.

Setup

The report does not describe any accounts, roles, tooling versions or other preconditions. The only infrastructure mentioned is a payload script hosted on the researcher's own server, and a WAF on the target that interfered with the first attempts.

"Hosted on the researcher's own server" means the researcher put a file on a computer they control, reachable on the internet, so that a browser could load it. Think of it as putting a poster on your own wall and giving people the address so they can come and look at it.

Finding it

The researcher first tried a general payload, which did not work because of the WAF. A general payload is a one-size-fits-all attempt, the kind of thing an attacker tries first on many sites. The WAF recognised it and blocked it, the way a spam filter blocks an obvious spam email.

While working around that, the researcher noticed that the search item is shown in the search history. This is the moment of discovery. The site was taking what the user typed and displaying it again later. That is not automatically a bug, but it is a place worth testing, because if the site displays the text without cleaning it, the text can contain more than words.

Looking at that behaviour more closely, the researcher found a reflected XSS: a malicious link containing the payload can be sent in the URL, and when the victim searches for anything, the XSS triggers and the attacker can obtain the victim's account cookies. "Reflected" means the payload bounces off the site and comes back to the victim in the page, rather than being saved on the server. The attacker does not need to break into the site; they just need the victim to open a link.

The author adds that if the victim has saved credit card details, the attacker could buy e-coupons and gift cards with the account. That is the practical consequence: stolen access can turn into stolen money.

After some attempts, the researcher also made a script that performs an open redirect with a malicious URL. An open redirect is a page on a trusted site that will send you to any address you name. It is like a receptionist at a trusted office who will walk you to any door you ask for, including a door the attacker built.

Exploitation

Step 1: a payload that survives the WAF

The first general payload was blocked by the WAF. The payload the researcher settled on is:

This injects a button labelled CLICK ME. The onclick handler runs when the victim clicks it, and calls alert with the result of document.write, which writes an iframe pointing at https://brutelogic.com.br/xss-waf.php into the page. The iframe loads a page from brutelogic.com.br.

Line by line, in plain words:

  • The opening characters ‘“> are there to break out of whatever HTML the site had already written around the search term. Imagine the site writes your search word inside quotation marks; these characters close the quotation marks and the tag early, so what follows is treated as new HTML rather than as text.
  • <button ...>CLICK ME</button> creates a button on the page with the label CLICK ME. The victim sees a button, which looks harmless and invites a click.
  • onclick=”...” is an attribute that tells the browser what to do when the button is clicked. It is the button's instruction card.
  • alert(...) is a JavaScript function that normally shows a pop-up box. Here it is used as a wrapper around another call.
  • document.write(...) tells the browser to write content into the page at that point. The content being written is an iframe.
  • <iframe src=https://brutelogic.com.br/xss-waf.php></iframe> is a frame that loads another web page inside the current one. The src attribute is the address of the page to load. So the browser is told to pull in a page from brutelogic.com.br.

Why this step was taken: the first, simpler payload was blocked by the WAF. The researcher needed a payload that the filter would let through but that the browser would still run. A button with a click handler is a different shape from a plain script tag. The cost is that the victim has to click, which is why the button says CLICK ME.

Step 2: the redirect script hosted on the researcher's server

The second payload is a full HTML document, hosted on the researcher's own server:

The author breaks the code down as follows:

  1. The <html> and <body> tags define the HTML structure and content of the page.
  2. The <script> tag defines a block of JavaScript executed by the browser. The language attribute specifies JavaScript, and the type attribute specifies text/javascript.
  3. The try block attempts to execute the following:
    • The variable rurl is set to https://00eth0.xss.ht?&.
    • window.top.location.replace(rurl) replaces the current page's location with the URL in rurl, redirecting the user to https://00eth0.xss.ht.
  4. If an exception is caught in the try block, the catch block runs instead. document.write() displays a message saying "This page has moved, Click here to go there." The A HREF attribute of the hyperlink points to http://ww6.gsrtc.com?&amp;&amp;jserror=1, the destination the user is redirected to if the code in the try block fails.

In short, the script tries to redirect the user to https://00eth0.xss.ht, and if that redirection fails, it falls back to http://ww6.gsrtc.com?&amp;&amp;jserror=1.

Here is the same code again, explained as if you had never seen HTML or JavaScript:

  • <html> and <body> are the outer wrapper of any web page. <html> says "a page starts here", and <body> says "the visible content starts here". They are like the cover and the first page of a booklet.
  • <script ...> starts a block of JavaScript. Everything until </script> is code for the browser to run, not text to display.
  • language=’javascript’ and type=’text/javascript’ are old-fashioned labels that tell the browser what kind of code this is. Modern browsers assume JavaScript anyway, but the labels do no harm.
  • try { ... } is a safety net. The browser attempts everything inside the curly braces. If something goes wrong, it does not crash the page; it jumps to the catch part instead. Think of it as trying a door and having a plan for what to do if it is locked.
  • var rurl = ‘https://00eth0.xss.ht?&'; creates a named box called rurl and puts a web address inside it. The name is short for "redirect URL". The address is where the attacker wants the victim to end up.
  • window.top.location.replace(rurl); is the actual redirect. window.top means the outermost browser window, not a small frame inside it. location is the address bar. replace swaps the current address for the one in the box. The effect is that the victim's browser leaves the current page and goes to the attacker's address.
  • } catch(exception) { ... } is the fallback. If the redirect fails for any reason, the code inside the catch block runs instead.
  • document.write(...) writes new content into the page. Here it writes a short message and a link.
  • <A HREF=’http://ww6.gsrtc.com?&amp;&amp;jserror=1'>Click here</A> is a hyperlink. A stands for anchor, HREF is the address the link points to, and the text between the tags is what the victim sees and clicks. The &amp;&amp; is how an ampersand is written inside HTML; the browser reads it as &&.

Why this step was taken: the first payload needed a click and only wrote an iframe. This second payload is a complete page that immediately tries to move the victim somewhere else, with a visible link as a backup if the automatic move fails. The researcher hosted it on their own server so that it could be loaded by a browser from a known address.

Root cause

Root cause means the underlying reason the bug exists, as opposed to the symptom. The author's opinion is that the issue happened for three reasons:

  1. While uploading the file, the extension was not being checked.
  2. After the file was uploaded, Content-Type validation was not done.
  3. After the file was sent to the server, it was not validated by the server.

A few terms here need unpacking. A file extension is the ending of a filename, like .jpg or .html, which tells a computer what kind of file it is. Content-Type is a label a server attaches to a file when it sends it to your browser, saying what kind of thing it is, for example text/html for a web page or image/png for a picture. The browser uses that label to decide whether to display the file or run it. If a server accepts an uploaded file without checking its extension, and then hands it back with a label that says "this is a web page", the browser will happily run any code inside it.

These points describe the handling of the uploaded script file. For the search reflection, the report only notes that the search term is shown in the search history and that the WAF was the obstacle to a general payload; it does not describe the server-side handling of the search value in more detail.

Impact

Impact means what an attacker could actually do with the bug, and how bad it could get. According to the report, an attacker can steal the authentication token of any user and can craft different attacks such as CSRF, session attacks and account takeover. The author notes that the impact depends on what kind of information was stored in localStorage.

In everyday terms: if an attacker can run their own code inside a page you are logged into, that code can read what the page can read. If your login token is stored somewhere the page can reach, the code can copy it and send it to the attacker. With that token, the attacker can act as you: read your messages, change settings, or in this case, if card details were saved, spend money through the account.

The researcher calculated the following CVSS vector:

Text
CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N

That gives a score of 8.2 (High).

A CVSS vector is a compact way of describing a flaw. Each part between slashes is a measurement. AV:N means the attack can be carried out over the network, not by someone sitting at the machine. AC:L means the attack is easy to carry out. PR:N means the attacker needs no privileges on the site. UI:R means the victim has to do something, such as click a link. S:C means the flaw can affect more than the vulnerable component. C:H means confidentiality is highly affected, so data can be read. I:L means integrity is lightly affected, so data can be changed to a limited degree. A:N means availability is not affected, so the site does not go down. The score of 8.2 is the number the scoring system produces from that combination.

Fix

Fix means what should be changed so the bug cannot happen again. The report's mitigation advice is that the site should keep the WAF on the search and other places where a payload could be injected, and that checks should be performed to mitigate this kind of issue.

In plain words, the advice is: keep the filter switched on where the search term is handled, and add checks in other places where user input ends up on a page. A WAF is a useful extra layer, but the more fundamental fix for XSS is to treat everything a user types as text, never as code, so that a search word is displayed as a search word even if it contains angle brackets.

Variants to test

Variants to test means other things worth trying if you want to look for similar bugs yourself. These are described in general terms, not as instructions to attack anyone.

  • Search reflections: submit a benign marker in the search box and look for it in the search history and in any URL that renders it. A positive result is the marker appearing unencoded in an HTML context, which you can then test with a harmless proof such as an alert. "Unencoded" means the characters appear exactly as you typed them, rather than being turned into safe stand-ins.
  • WAF bypasses: when a general payload is blocked, try alternative encodings, different event handlers and tag combinations. A positive result is the browser executing the handler while the WAF still returns a normal page.
  • Upload handling: upload a file with an unexpected extension and a script content type, then request it back. A positive result is the server returning the file with a content type that the browser will execute.
  • Redirect parameters: look for parameters that take a URL and redirect to it, and test whether the destination is validated. A positive result is a redirect to a domain you control.

Bounty

The reward was 2,000 USD. A bounty is a payment a company makes to a researcher who reports a security problem responsibly, so that it can be fixed before someone with bad intentions finds it.

Glossary

  • Account takeover: an attacker gaining control of someone else's account, often by stealing a login token.
  • API: a way for one piece of software to talk to another, like a waiter taking your order to the kitchen.
  • Attribute: an extra piece of information inside an HTML tag, such as the address a link points to.
  • Browser: the program you use to view websites, such as Chrome, Firefox or Safari.
  • Bounty: a payment made to a researcher who reports a security flaw responsibly.
  • Content-Type: a label a server attaches to a file saying what kind of file it is, which the browser uses to decide how to handle it.
  • Cookie: a small piece of data a site asks your browser to keep and send back, often used to remember that you are logged in.
  • CSRF (Cross-Site Request Forgery): a trick that makes your browser send a request to a site you are logged into, without you meaning to.
  • CVSS: a scoring system that turns the characteristics of a security flaw into a number and a vector string.
  • CVSS vector: the compact string of measurements that describes a flaw, such as attack vector and required user interaction.
  • DOM: the browser's in-memory model of the page, which scripts can read and change.
  • File extension: the ending of a filename, such as .html, that indicates the file type.
  • HTML: the language that describes the structure and content of a web page using tags.
  • Iframe: a frame that loads one web page inside another.
  • JavaScript: a programming language that browsers can run to make pages interactive.
  • localStorage: a storage area inside your browser where a website can keep data on your computer.
  • Open redirect: a page on a trusted site that will forward a visitor to any address it is given, without checking whether the address is trustworthy.
  • Payload: the piece of text or code an attacker sends to try to make something happen.
  • Reflected XSS: cross-site scripting where the malicious input bounces off the site and comes back in the page, rather than being stored on the server.
  • Root cause: the underlying reason a bug exists, as opposed to its visible symptom.
  • Session: a period during which a site remembers who you are, usually kept alive by a cookie or token.
  • Token: a string of characters that proves who you are, like a wristband at an event.
  • URL: the address of a page, as shown in your browser's address bar.
  • WAF (Web Application Firewall): a filter in front of a website that inspects incoming requests and blocks ones that look dangerous.
  • XSS (Cross-Site Scripting): a flaw where a site lets an attacker's code run in another visitor's browser.

More by 0 day exploit

View all

1 more disclosed report, 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.