Created
April 25, 2019 12:41
-
-
Save terjanq/dc911bb71b9f85b87d3427949ff4eedd to your computer and use it in GitHub Desktop.
DOM Validator - angstrom CTF 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checksum (element) { | |
var string = '' | |
string += (element.attributes ? element.attributes.length : 0) + '|' | |
for (var i = 0; i < (element.attributes ? element.attributes.length : 0); i++) { | |
string += element.attributes[i].name + ':' + element.attributes[i].value + '|' | |
} | |
string += (element.childNodes ? element.childNodes.length : 0) + '|' | |
for (var i = 0; i < (element.childNodes ? element.childNodes.length : 0); i++) { | |
string += checksum(element.childNodes[i]) + '|' | |
} | |
return CryptoJS.SHA512(string).toString(CryptoJS.enc.Hex) | |
} | |
var request = new XMLHttpRequest() | |
request.open('GET', location.href, false) | |
request.send(null) | |
if (checksum((new DOMParser()).parseFromString(request.responseText, 'text/html')) !== document.doctype.systemId) { | |
document.documentElement.remove() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment