Skip to content

Instantly share code, notes, and snippets.

@terjanq
Created April 25, 2019 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terjanq/dc911bb71b9f85b87d3427949ff4eedd to your computer and use it in GitHub Desktop.
Save terjanq/dc911bb71b9f85b87d3427949ff4eedd to your computer and use it in GitHub Desktop.
DOM Validator - angstrom CTF 2019
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