{"id":771,"date":"2021-03-24T09:33:46","date_gmt":"2021-03-24T09:33:46","guid":{"rendered":"https:\/\/cas.cybercop-training.ch\/?page_id=771"},"modified":"2021-03-24T15:14:46","modified_gmt":"2021-03-24T15:14:46","slug":"xss-dom-based","status":"publish","type":"page","link":"https:\/\/cas.cybercop-training.ch\/index.php\/xss-dom-based\/","title":{"rendered":"XSS &#8211; DOM Based"},"content":{"rendered":"<h1>Exercise XSS &#8211; DOM based<\/h1>\n<h2>1. Introduction<\/h2>\n<blockquote><p>Hack and fix the DOM-based vulnerable web site.<\/p><\/blockquote>\n<p>Your goal is to find and exploit the DOM based XSS vulnerability.<\/p>\n<p>Fix the vulnerable web site using the built-in Theia Web IDE<br \/>\nIf you see something like this, you&#8217;re good:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/03\/xss_01.png\" alt=\"\" \/><\/p>\n<p>Please answer to the following questions:<\/p>\n<ol>\n<li>Explain the meaning of # in the URL<\/li>\n<li>Explain the difference between Stored XSS, Reflected XSS and DOM based XSS<\/li>\n<li>Explain the fix in the last step<\/li>\n<\/ol>\n<h2>2. Answer and solution<\/h2>\n<p>On the <code>get in touch<\/code> section where we can switch between different locations we can find the DOM based XSS vulnerability.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">start.html#&lt;script&gt;alert(1)&lt;\/script&gt;<\/pre>\n<p>The following example will show a javascript <code>alert<\/code> popup, when we add a script tag.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/03\/xss_02.png\" alt=\"\" \/><\/p>\n<ol>\n<li>In jQuery <code>#<\/code> is known as <code>id selector<\/code> and selects a single element with the given id attribute.<br \/>\nCalling <code>jQuery()<\/code> <code>(or $())<\/code> with an id selector as its argument will return a jQuery object containing a collection of either zero or one DOM element.<\/li>\n<\/ol>\n<blockquote><p>Each id value must be used only once within a document. If more than one element has been assigned the same ID, queries that use that ID will only select the first matched element in the DOM. This behavior should not be relied on, however; a document with more than one element using the same ID is invalid.<\/p><\/blockquote>\n<h3>2.1 XSS Summary<\/h3>\n<h3>Stored XSS<\/h3>\n<blockquote><p>Stored XSS, also known as persistent XSS, occurs when a malicious script is injected directly into a vulnerable web application.<\/p><\/blockquote>\n<h3>Reflected XSS<\/h3>\n<blockquote><p>Reflected XSS involves the reflecting of a malicious script off of a web application, onto a user\u2019s browser. The script is embedded into a link, and is only activated once that link is clicked on.<\/p><\/blockquote>\n<h3>DOM based XSS<\/h3>\n<blockquote><p>In DOM-based XSS, the malicious JavaScript is executed at some point after the page has loaded, as a result of the page&#8217;s legitimate JavaScript treating user input in an unsafe way<\/p><\/blockquote>\n<h2>3. Issue fix<\/h2>\n<p>The issue can be fixed if the inline html code will be displayed as text instead of html.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var loc = decodeURIComponent(location.hash.slice(1));\r\n            $('#locationName').text(loc);<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/03\/xss_03.png\" alt=\"\" \/><\/p>\n<p>Before fix:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">start.html#&lt;s&gt;Headquarters&lt;\/s&gt;<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/03\/xss_04.png\" alt=\"\" \/><\/p>\n<p>After fix:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/03\/xss_05.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Exercise XSS &#8211; DOM based 1. Introduction Hack and fix the DOM-based vulnerable web site. Your goal is to find and exploit the DOM based XSS vulnerability. Fix the vulnerable web site using the built-in Theia Web IDE If you see something like this, you&#8217;re good: Please answer to the following questions: Explain the meaning [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-771","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/pages\/771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/comments?post=771"}],"version-history":[{"count":4,"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/pages\/771\/revisions"}],"predecessor-version":[{"id":883,"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/pages\/771\/revisions\/883"}],"wp:attachment":[{"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/media?parent=771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}