Level2
Link: https://xss-game.appspot.com/level2Solution
<img src="noimage" onerror="alert('xss')">
Result
Analysis
I posted mypost' and shared my status. This is what I get.Whatever I typedin simply appeared in the page right after I click Share status! Lets see the source.
The text I posted seems directly put inside a <blockquote> tage. So even a simple <script> tage we used in Level1 should work here. BUT IT WILL NOT!.
Let us exmine the code to understand why. Toggle to the code view of the game and exmine the index.html page and see how the text is added to the HTML page.
Important part is line 32 highlighted in the above code. The generated html fragement (html variable in the above code) is added to the mail html using the innerHTML method. So when the browser parsing this html fragment (html variable in the above code), it will not execute any script tag define withing that html fragment.
Conclution
HTML parser will not execute a <script> tag when it parses htmls added via the innerHTML method. Hence, injecting a <script> won't work here.Solution is to use events. Events will execute the defined javascripts.
In the above injection we are loading an image that doesnt exist, which causes to trigger an onerror event. In onerror event will execute our alert method.
HTML events list: https://www.w3schools.com/jsref/dom_obj_event.asp
(y) clear explanation
ReplyDeletefor me #lol#
DeleteVimeo | Best Vimeo Videos, Movies and Stock Photos - Video
ReplyDeleteDiscover the best Vimeo video on Vimeo, the home download youtube videos to mp3 for high quality original videos produced using Vimeo's collection of high quality high quality high