如何将多个 Frida JS files/functions 导入运行时 CLI?
How to import multiple Frida JS files/functions into the runtime CLI?
我正在为同事组装一个 Frida 测试台,我不熟悉 JavaScript 和 Node.JS。我想创建一个单独的 JS 文件来导入其他几个 JS 文件,每个文件都有几个功能。但是当我对一些导入其他函数的 Node.JS 代码使用 frida-compile 时,REPL 解释器不会将 functions/variables 拉入范围。所以,例如:
我有一个包含 3 个 JavaScript 个文件的平面目录:
in1.js:
'use strict';
var a = 'test';
function b() { console.log("function b"); };
in2.js:
'use strict';
var c = 'test2';
var d = function () { console.log("function d"); };
in3.js:
'use strict';
require('./in1.js');
require('./in2.js');
然后我 运行 frida-compile,在 Windows 10 + Python 3.6 + Node.JS 9.5:
frida-compile in3.js -o out.js
结果如下:
(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
'use strict';
var a = 'test';
function b() {
console.log("function b");
};
},{}],2:[function(require,module,exports){
'use strict';
var c = 'test2';
var d = function () {
console.log("function d");
};
},{}],3:[function(require,module,exports){
'use strict';
require('./in1.js');
require('./in2.js');
},{"./in1.js":1,"./in2.js":2}]},{},[3])
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJpbjEuanMiLCJpbjIuanMiLCJpbjMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTs7QUFDQSxJQUFJLElBQUksTUFBUjtBQUNBLElBQUksSUFBSSxZQUFZO0FBQUUsVUFBUSxHQUFSLENBQVksWUFBWjtBQUE0QixDQUFsRDs7O0FDRkE7O0FBQ0EsSUFBSSxJQUFJLE9BQVI7QUFDQSxJQUFJLElBQUksWUFBWTtBQUFFLFVBQVEsR0FBUixDQUFZLFlBQVo7QUFBNEIsQ0FBbEQ7OztBQ0ZBOztBQUNBLFFBQVEsVUFBUjtBQUNBLFFBQVEsVUFBUiIsImZpbGUiOiJnZW5lcmF0ZWQuanMiLCJzb3VyY2VSb290IjoiIn0=
最后,当我尝试将它导入 Frida CLI 时,以 OWASP iGoat 项目为例,我无法访问任何这些功能:
frida -R -f com.swaroop.iGoat -l out.js
____
/ _ | Frida 10.6.52 - A world-class dynamic instrumentation toolkit
| (_| |
> _ | Commands:
/_/ |_| help -> Displays the help system
. . . . object? -> Display information about 'object'
. . . . exit/quit -> Exit
. . . .
. . . . More info at http://www.frida.re/docs/home/
Spawned `com.swaroop.iGoat`. Use %resume to let the main thread start executing!
[Remote::com.swaroop.iGoat]-> %resume
[Remote::com.swaroop.iGoat]-> a
ReferenceError: identifier 'a' undefined
[Remote::com.swaroop.iGoat]-> b
ReferenceError: identifier 'b' undefined
[Remote::com.swaroop.iGoat]-> c
ReferenceError: identifier 'c' undefined
[Remote::com.swaroop.iGoat]-> d
ReferenceError: identifier 'd' undefined
[Remote::com.swaroop.iGoat]-> module
ReferenceError: identifier 'module' undefined
[Remote::com.swaroop.iGoat]-> require
ReferenceError: identifier 'require' undefined
[Remote::com.swaroop.iGoat]-> exports
ReferenceError: identifier 'exports' undefined
[Remote::com.swaroop.iGoat]->
我错过了什么...如何在 Frida CLI 中访问 a、b、c 和 d?
我认为您无法从脚本中直接访问任何变量。
阅读 Frida 源代码(特别是来自 frida-gum repo 的 bindings/gumjs/runtime/core.js),他们将属性添加到变量 global
,这似乎表现为全局对象(一个对象充当所有全局变量的存储,如浏览器中的 window
)用于 REPL 中执行的 JS。
事实上,脚本中的这种代码:
global.test = "success";
在 REPL 中定义一个新变量:
[iPhone::Foo]-> test
"success"
(也感谢您向我介绍 frida-compile
,它让我现在的生活轻松多了。)
我正在为同事组装一个 Frida 测试台,我不熟悉 JavaScript 和 Node.JS。我想创建一个单独的 JS 文件来导入其他几个 JS 文件,每个文件都有几个功能。但是当我对一些导入其他函数的 Node.JS 代码使用 frida-compile 时,REPL 解释器不会将 functions/variables 拉入范围。所以,例如:
我有一个包含 3 个 JavaScript 个文件的平面目录:
in1.js:
'use strict';
var a = 'test';
function b() { console.log("function b"); };
in2.js:
'use strict';
var c = 'test2';
var d = function () { console.log("function d"); };
in3.js:
'use strict';
require('./in1.js');
require('./in2.js');
然后我 运行 frida-compile,在 Windows 10 + Python 3.6 + Node.JS 9.5:
frida-compile in3.js -o out.js
结果如下:
(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
'use strict';
var a = 'test';
function b() {
console.log("function b");
};
},{}],2:[function(require,module,exports){
'use strict';
var c = 'test2';
var d = function () {
console.log("function d");
};
},{}],3:[function(require,module,exports){
'use strict';
require('./in1.js');
require('./in2.js');
},{"./in1.js":1,"./in2.js":2}]},{},[3])
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJpbjEuanMiLCJpbjIuanMiLCJpbjMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTs7QUFDQSxJQUFJLElBQUksTUFBUjtBQUNBLElBQUksSUFBSSxZQUFZO0FBQUUsVUFBUSxHQUFSLENBQVksWUFBWjtBQUE0QixDQUFsRDs7O0FDRkE7O0FBQ0EsSUFBSSxJQUFJLE9BQVI7QUFDQSxJQUFJLElBQUksWUFBWTtBQUFFLFVBQVEsR0FBUixDQUFZLFlBQVo7QUFBNEIsQ0FBbEQ7OztBQ0ZBOztBQUNBLFFBQVEsVUFBUjtBQUNBLFFBQVEsVUFBUiIsImZpbGUiOiJnZW5lcmF0ZWQuanMiLCJzb3VyY2VSb290IjoiIn0=
最后,当我尝试将它导入 Frida CLI 时,以 OWASP iGoat 项目为例,我无法访问任何这些功能:
frida -R -f com.swaroop.iGoat -l out.js
____
/ _ | Frida 10.6.52 - A world-class dynamic instrumentation toolkit
| (_| |
> _ | Commands:
/_/ |_| help -> Displays the help system
. . . . object? -> Display information about 'object'
. . . . exit/quit -> Exit
. . . .
. . . . More info at http://www.frida.re/docs/home/
Spawned `com.swaroop.iGoat`. Use %resume to let the main thread start executing!
[Remote::com.swaroop.iGoat]-> %resume
[Remote::com.swaroop.iGoat]-> a
ReferenceError: identifier 'a' undefined
[Remote::com.swaroop.iGoat]-> b
ReferenceError: identifier 'b' undefined
[Remote::com.swaroop.iGoat]-> c
ReferenceError: identifier 'c' undefined
[Remote::com.swaroop.iGoat]-> d
ReferenceError: identifier 'd' undefined
[Remote::com.swaroop.iGoat]-> module
ReferenceError: identifier 'module' undefined
[Remote::com.swaroop.iGoat]-> require
ReferenceError: identifier 'require' undefined
[Remote::com.swaroop.iGoat]-> exports
ReferenceError: identifier 'exports' undefined
[Remote::com.swaroop.iGoat]->
我错过了什么...如何在 Frida CLI 中访问 a、b、c 和 d?
我认为您无法从脚本中直接访问任何变量。
阅读 Frida 源代码(特别是来自 frida-gum repo 的 bindings/gumjs/runtime/core.js),他们将属性添加到变量 global
,这似乎表现为全局对象(一个对象充当所有全局变量的存储,如浏览器中的 window
)用于 REPL 中执行的 JS。
事实上,脚本中的这种代码:
global.test = "success";
在 REPL 中定义一个新变量:
[iPhone::Foo]-> test
"success"
(也感谢您向我介绍 frida-compile
,它让我现在的生活轻松多了。)