logger.js for hunting script gadgets. More info about script gadgets: https://github.com/google/security-research-pocs/tree/master/script-gadgets (Sebastian Lekies / Eduardo Vela Nava / Krzysztof Kotowicz)
var logger = console.trace; | |
// ELEMENT | |
;(getElementByIdCopy => { | |
Element.prototype.getElementById = function(q) { | |
logger('getElementById', q, this, this.innerHTML); | |
return Reflect.apply(getElementByIdCopy, this, [q]) | |
} | |
})(Element.prototype.getElementById) | |
;(getElementsByTagNameCopy => { | |
Element.prototype.getElementsByTagName = function(q) { | |
logger('getElementsByTagName', q, this, this.innerHTML); | |
return Reflect.apply(getElementsByTagNameCopy, this, [q]) | |
} | |
})(Element.prototype.getElementsByTagName) | |
;(getAttributeCopy => { | |
Element.prototype.getAttribute = function(q) { | |
logger('getAttribute', q, this, this.innerHTML); | |
return Reflect.apply(getAttributeCopy, this, [q]) | |
} | |
})(Element.prototype.getAttribute) | |
;(querySelectorCopy => { | |
Element.prototype.querySelector = function(q) { | |
logger('querySelector', q, this, this.innerHTML); | |
return Reflect.apply(querySelectorCopy, this, [q]) | |
} | |
})(Element.prototype.querySelector) | |
;(querySelectorAllCopy => { | |
Element.prototype.querySelectorAll = function(q) { | |
logger('querySelectorAll', q, this, this.innerHTML); | |
return Reflect.apply(querySelectorAllCopy, this, [q]) | |
} | |
})(Element.prototype.querySelectorAll) | |
// DOCUMENT | |
;(getElementByIdCopy => { | |
document.getElementById = function(q) { | |
logger('document.getElementById', q); | |
return Reflect.apply(getElementByIdCopy, document, [q]) | |
} | |
})(document.getElementById) | |
;(getElementsByTagNameCopy => { | |
document.getElementsByTagName = function(q) { | |
logger('document.getElementsByTagName', q); | |
return Reflect.apply(getElementsByTagNameCopy, document, [q]) | |
} | |
})(document.getElementsByTagName) | |
;(querySelectorCopy => { | |
document.querySelector = function(q) { | |
logger('document.querySelector', q); | |
return Reflect.apply(querySelectorCopy, document, [q]) | |
} | |
})(document.querySelector) | |
;(querySelectorAllCopy => { | |
document.querySelectorAll = function(q) { | |
logger('document.querySelectorAll', q); | |
return Reflect.apply(querySelectorAllCopy, document, [q]) | |
} | |
})(document.querySelectorAll) | |
// TEST | |
console.log(document.getElementById("test")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment