在谷歌浏览器中使用pydbg钩子

1 投票
1 回答
2377 浏览
提问于 2025-04-17 09:53

我正在学习使用pyDbg,并且在Firefox上设置了一个软连接。

这是代码的一部分:

dbg = pydbg()
hooks = utils.hook_container()


for (pid,name) in dbg.enumerate_processes():
    if name == "firefox.exe":
        dbg.attach(pid)

hook_address = dbg.func_resolve_debuggee("nspr4.dll","PR_Write")

hooks.add( dbg, hook_address, 2, sniff, None )

dbg.run()

现在我该如何在谷歌浏览器上设置软连接呢?

抱歉我的英语不好,谢谢!

1 个回答

0

你可以用完全相同的方法,只是函数的名字会不同,而且你需要连接到那个名字和你Chrome实例匹配的进程。

另外,你也可以使用pydbgload()函数自己启动一个Chrome实例并进行调试。在这种情况下,你还需要处理LOAD_DLL_DEBUG_EVENT,这样才能在DLL加载后设置断点。具体细节见下文。

关键是你需要有调试符号(在Windows上就是.pdb文件),这些符号要和你的Chrome版本匹配。这可能就是你现在缺少的东西。

import sys
try:
    from pydbg import *
    from pydbg.defines import *
    from utils import hooking
except:
    print "ERROR: you need pydbg and utils.hooking from PAIMEI."
    sys.exit(-1)

hooks = None # needed in handler_load_dll()

def entry_SomeChromeFunction(dbg, args):
    """ This is where you end up when the function got called """
    # Do whatever you like in here
    return DBG_CONTINUE

def handler_load_dll(dbg):
    last_dll = dbg.get_system_dll(-1)
    # Wait for the DLL we're looking for ...
    if "some-chrome.dll".lower() == last_dll.name.lower():
        # Now resolve the address of the function (see note: requires debug symbols)
        funcaddr = dbg.func_resolve(last_dll.name,"SomeChromeFunction")
        # Add the hook
        hooks.add(dbg, funcaddr, 2, entry_SomeChromeFunction, None) # <- last one is for breakpoint on exit of the function
    return DBG_CONTINUE

dbg = pydbg()
hooks = utils.hook_container()
dbg.load("chrome.exe"); # assuming that is the name of the binary
# you can also use a full path above and pass the command line as parameter
dbg.set_callback(LOAD_DLL_DEBUG_EVENT, handler_load_dll)
dbg.run()

注意:我觉得可以直接分配函数的地址,而不需要调用func_resolve_debuggee()。不过我从来没有需要这样做过。

另外注意:我最开始的代码有个bug。dbg.func_resolve_debuggee()不应该在LOAD_DLL处理程序中使用,现在已经修正了。

编辑:我看到你原来的示例实际上是firefox_hook.py的简化版,来自Gray Hat Python。这个示例相当不错,但它假设你知道自己在做什么——包括需要有调试符号。

撰写回答