【问题标题】:Frida: spawn a Windows/Linux process with command-line argumentsFrida:使用命令行参数生成一个 Windows/Linux 进程
【发布时间】:2022-07-08 17:35:30
【问题描述】:

启动 frida 时,您可以提供 frida 应该执行并附加到它的可执行文件的路径:

frida -l myscript.js process_to_spawn.exe

我有一个可执行文件需要使用附加参数启动,否则它会直接终止。有没有办法启动一个新的可执行文件并为新启动的进程提供命令行参数?

我已经试过了

frida -l myscript.js process_to_spawn.exe --argForProcess
frida -l myscript.js "process_to_spawn.exe --argForProcess"

但两种变体都不起作用。 Frida 试图解释所有参数,因此无法将参数传递给生成的进程。第二个变种也不起作用,因为 frida 无法找到要启动的可执行文件。

有没有办法通过 frida 在本地操作系统(例如 Windows 或 Linux)上生成可执行文件并提供命令行参数?

我无法附加到正在运行的进程,因为我要挂钩的函数只在启动后直接执行一次,所以我必须使用 frida 生成进程。

【问题讨论】:

    标签: linux windows frida


    【解决方案1】:

    问题似乎是参数以- 开头。对于不以 - 开头的常规参数,使用 frida 选项 -f 有效:

    frida -l myscript.js -f process_to_spawn.exe argForProcess
    

    但由于我需要参数--argForProcess,我发现的唯一方法是挂钩处理命令行参数并在调用 main 之前修改参数的 main 方法。

    以下代码适用于 Windows 10,它似乎将参数作为 wchar/"Unicode"/UTF-16 字符串传递。它将mainargcargv 参数从一个参数(可执行文件本身)更改为两个(可执行文件加上一个参数)。

    let mainPointer = DebugSymbol.fromName("main").address;
    Interceptor.attach(mainPointer, {
        onEnter(args) {
            // args[0] = int argc
            // args[1] = wchar *argv[]
    
            let myarg1 = Memory.allocUtf16String("Myexecutable.exe");
            let myarg2 = Memory.allocUtf16String("--argumentX");
            let newArgv = Memory.alloc(2 * Process.pointerSize); // allocate space for the two argument pointers
            newArgv.writePointer(myarg1);
            newArgv.add(Process.pointerSize).writePointer(myarg2);
    
            // save all created memory blocks so they don't get garbage collected before main method is completed
            this.myarg1 = myarg1; 
            this.myarg2 = myarg2;
            this.newArgs = newArgv;
            
            // Overwrite the argument counter and the argument char**
            args[0] = ptr(2);
            args[1] = newArgs;
            
            console.log("main(" + args[0] + ", " + args[1].readPointer().readUtf16String() + ", " + args[1].add(Process.pointerSize).readPointer().readUtf16String() + ")");
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      相关资源
      最近更新 更多