如何通过挂钩kernel32.dll来进行文件过滤

时间:2012-11-30 20:03:22

标签: python file winapi hook hide

我是挂钩的新手。我正在搜索一个python程序,它可以隐藏文件或通过使用win API hooking过滤其中一些来过滤结果来阻止它。我已经读过,还有另一种方法可以使用文件系统过滤驱动程序,或使用内核模式API挂钩,我从here得到了这个想法。

无论如何,我是python的家伙,所以我希望它在python中,搜索我到达PyBox。这是我可以将某些DLL注入应用程序然后可以运行它的地方。

以下是执行此操作的代码:

 if kernel32.CreateProcessA(self.exe,
                                   None,
                                   None,
                                   None,
                                   None,
                                   creation_flags,
                                   None,
                                   None,
                                   byref(startupinfo),
                                   byref(process_information)):
            self.pid = process_information.dwProcessId
            self.tid = process_information.dwThreadId
            self.h_process = process_information.hProcess
            self.h_thread = process_information.hThread
            print "Process successfully launched with PID %d." % self.pid
            return True
        else:
            print "Process could not be launched!"
            raise WinError()
            return False

这会以暂停模式创建进程,然后:

def resume(self):
        if (kernel32.ResumeThread(self.h_thread) == 0):
            print "Process could note be resumed!"
            raise WinError()
            return False
        else:
            print "Process resumed."
            return True

此函数在注入DLL后恢复进程。我想知道两件事:

  1. 为什么不如果我可以阻止该过程而不是恢复它。这将阻止应用程序运行。但是我应该调用kernel32的哪个函数?
  2. 如何在此处实现ntQueryDirectoryfile functionzwQueryDirectoryfile function,以便我可以向文件添加过滤器而不是阻止它。那么DLL会对过滤器产生任何影响吗?

1 个答案:

答案 0 :(得分:0)

顺便说一句。 我现在猜测kernel32.dll需要内核模式挂钩,这远远不是python的。

WINDDKVS(Visual Studio)提供内核调试器和环境来创建可以调用exe的.sys文件。

只需使用WIN32HLP

中定义的函数即可

现在我只是想知道这个exe是否可以用python制作(顺便提一下)/