<script type="text/javascript">
<!--
var _eval = eval;
eval = function(s) {
if (confirm("eval被调用\n\n调用函数\n" + eval.caller + "\n\n调用参数\n" + s)) {
_eval(s);
}
}
//-->
</script>
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--
function test() {
var a = "alert(1)";
eval(a);
}
function t() {
test();
}
t();
//-->
</script>
</body>
</html>
通过js函数劫持中断函数执行,并显示参数和函数调用者代码,来看一个完整例子的效果:
>help
debug commands:
bp <function name> - set a breakpoint on a function, e.g. "bp window.alert".
bl - list all breakpoints.
bc <breakpoint number> - remove a breakpoint by specified number, e.g. "bc 0".
help - help information.
>bp window.alert
* breakpoint on function "window.alert" added successfully.
>bl
* 1 breakpoints:
0 - window.alert
>bc 0
* breakpoint on function "window.alert" deleted successfully.
function createIframe(w) {
var d = w.document;
var newIframe = d.createElement("iframe");
newIframe.style.width = 0;
newIframe.style.height = 0;
d.body.appendChild(newIframe);
newIframe.contentWindow.document.write("<html><body></body></html>");
return newIframe;
}
function injectScriptIntoIframe(f, proc) {
var d = f.contentWindow.document;
var s = "<script>\n(" + proc.toString() + ")();\n</script>";
d.write(s);
}
把你的payload封装进一个函数,然后调用这两个方法来在iframe里执行:
function payload() {
// your code goes here
}
var f = createIframe(top);
injectScriptIntoIframe(f, payload);
/*
FileName: js_inline_debugger.js
Author: luoluo
Contact: luoluonet_at_yahoo.cn
Date: 2007-6-27
Version: 0.1
Usage:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<script language="javascript" type="text/javascript" src="js_inline_debugger.js"></script>
</body>
</html>
Instruction:
It is a simple javascript inline debugger. You must add xhtml1-transitional dtd to your
html document if you wanna to use the script.
*/
// 判断一个数组中是否存在相同的元素
Array.prototype.search = function(o) {
for (var i = 0; i < this.length; i ++) {
if (this[i] == o) {
return i;
}
}
return -1;
}
// html编码
function htmlEncode(s) {
s = s.replace(/&/g, "&");
s = s.replace(/</g, "<");
s = s.replace(/>/g, ">");
s = s.replace(/\"/g, """);
s = s.replace(/\'/g, """);
return s;
}
// js编码
function jsEncode(s) {
s = s.replace(/\\/g, "\\\\");
s = s.replace(/\n/g, "\\n");
s = s.replace(/\"/g, "\\\"");
s = s.replace(/\'/g, "\\\'");
return s;
}
//--------------------------------------------------------------------------//
// 内联调试器类
//--------------------------------------------------------------------------//
function InlineDebugger() {
var bpList = new Array();
var id_eval;
// 设置断点
var bp = function(funcName) {
// 检查eval是否被hook
if ((new String(eval)).indexOf("[native code]") < 0) {
return "error: eval function was hooked by other codes in the front.\n";
}
// 保存未被hooked的eval
id_eval = eval;
var re = /^[a-zA-Z0-9_\.]+$/i;
if (! re.test(funcName)) {
return "error: bad argument of command bp \"" + funcName + "\".\n";
}
if (obj == undefined) {
return "error: the argument of command bp \"" + funcName + "\" is not a function object.\n";
}
if ((new String(obj)).indexOf("function") < 0) {
return "error: the argument of command bp \"" + funcName + "\" is a property, a function is required.\n";
}
if (bpList.search(funcName) >= 0) {
return "error: there is a breakpoint on function \"" + funcName + "\"\n";
}
// 帮助
var help = function() {
var s = "debug commands:\n\n" +
"bp <function name> - set a breakpoint on a function, e.g. \"bp window.alert\".\n" +
"bl - list all breakpoints.\n" +
"bc <breakpoint number> - remove a breakpoint by specified number, e.g. \"bc 0\".\n" +
"help - help information.\n"
"\n";
return s;
}
// 处理命令
this.exeCmd = function(cmd) {
cmd = cmd.trim();
var cmdParts = cmd.split(/\s+/g);
var cmdName;
var cmdArg;
switch (cmdName) {
case "bp":
if (cmdArg == undefined) {
return "error: bp command requires an argument.\n";
} else {
return bp(cmdArg);
}
break;
case "bl":
return bl();
break;
case "bc":
if (cmdArg == undefined) {
return "error: bc command requires an argument \"number of breakpoint\".\n";
} else {
return bc(cmdArg);
}
break;
case "help":
return help();
break;
default: return "error: command \"" + cmdName + "\" not found, you can get information by \"help\" command.\n";
break;
}
}
}
//-----------------------------------------------------------------------------//
// 主过程
//-----------------------------------------------------------------------------//
/*try {
debugger;
} catch (e) {}*/
var id = new InlineDebugger();
var console = new Console(document.body, function(s, printProc){printProc(id.exeCmd(s));});