通过钩子禁止资源管理器(explore)的运行,钩住的方法是什么样的?

horace331 2007-02-14 11:48:37

通过钩子禁止资源管理器(explore)的运行,钩住的方法是什么样的?

HHOOK SetWindowsHookEx()详细的参数是什么样?
...全文
557 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuwedo2003 2007-02-16
  • 打赏
  • 举报
回复
你的想法很有新意。
ATField 2007-02-16
  • 打赏
  • 举报
回复
并不是用SetWindowsHookEx就ok了。你可能有些误解了,SetWindowsHookEx不能直接用来Hook API,而是用来Hook别的东西的,如键盘,消息,鼠标,等等。而且,API Hook中用到SetWindowsHookEx不是为了Hook 消息,而是为了把自己写的API的替换代码的DLL插入到其他进程中用的,这是SetWindowsHookEx的一个“副作用”(但是有一定局限性,比如无法挂接Console程序)。如果要做 API Hook,还要修改目标EXE/DLL的IAT,使之指向自己的API代码。
详情请参考我写的这篇文章http://blog.csdn.net/ATField/archive/2007/02/10/1507122.aspx和里面所列的一些参考文献,你所要的信息基本上都在里面了。
horace331 2007-02-16
  • 打赏
  • 举报
回复
to ATField(field);
你好,非常感谢你写了这么详细的思路,我会按这个思路尝试一下,有能实现预想的功能就最好了,也可以和大家分享一下成果。



还有一个问题,如果想钩住createFile这个函数,是用什么?HHOOK SetWindowsHookEx?参数是怎么样的?我试了几次都不对。
ATField 2007-02-15
  • 打赏
  • 举报
回复
关于Hook你可以看看我写的这篇Blog:http://blog.csdn.net/ATField/archive/2007/02/10/1507122.aspx
要禁止程序运行(启动新的进程)可以Hook CreateProcess, ShellExecute等API。
有一个考虑的问题是,不能完全禁止Explorer运行,因为Explorer也负责TaskBar和桌面,所以要禁止新的Explorer进程。不过有一个设置关系到每次开新的打开Explorer窗口是否是开新的进程,如果这个设置成不开新进程的话,那么Hook API 就很难起作用。

其实你要做的倒不一定必须Hook API,修改Group Policy之类或者注册表之类的可能更加简单。

horace331 2007-02-15
  • 打赏
  • 举报
回复
to sz_04022
HOOK CreateProcess()?
这个我不明白,能不能稍微说详细点?
horace331 2007-02-15
  • 打赏
  • 举报
回复
to cimil(国货==垃圾)
能不能详细点。我对hook不太了解。
挂钩住对文件读写的API,是指那些消息?HHOOK SetWindowsHookEx()吗?参数是怎样的?
东文-桑晨 2007-02-15
  • 打赏
  • 举报
回复
HOOK CreateProcess()
cimil 2007-02-15
  • 打赏
  • 举报
回复
挂钩住对文件读写的API,用自己的代理函数即可。
namehzf 2007-02-15
  • 打赏
  • 举报
回复
我 也 想知道 呵呵
horace331 2007-02-15
  • 打赏
  • 举报
回复
我想实现的功能是;在我的程序启动后,不能打开“资源管理器”“我的电脑”之内的可以对window文件直接操作的工具,所以想禁止explore再启动新的任务。通过钩子禁止资源管理器(explore)的运行,这样有可能实现吗?
ATField 2007-02-15
  • 打赏
  • 举报
回复
我没有试过,大致的思路应该是这样:
1. 修改目录的权限控制可以这样做:
a. InitializeSecurityDescriptor初始化新的Security Descriptor
b. InitializeAcl初始化ACL
c. LookupAccountName获得操作的User Account的SID
d. 调用AddAccessAllowedAce把允许特权User的访问的ACE加到ACL中
e. 调用AddAccessDeniedAce把阻止其他User的访问加到ACL中
f. 调用SetSecurityDescriptorDacl把ACL加到Security Descriptor中
g. 如果目录是你自己创建的话,那么你只需要调用CreateDirectory,参数用到上面生成的Security Descriptor就可以了。否则,需要用OpenFile打开目录获得句柄,然后用SetSecurityInfo修改目录的Owner和ACL
2. Impersonate可以这样做:
a. 调用LogonUser让具有特权的User Logon
b. 调用ImpersonateLoggedOnUser使得线程获得该User的Security Context
c. 访问目录
d. 当不用访问目录的时候,可以调用RevertToSelf恢复到启动该Process的User的Security Context。注意LogonUser和ImpersonateLoggedOnUser都需要一定的特权,普通账户无法执行。
jingzhongrong 2007-02-15
  • 打赏
  • 举报
回复
我觉得在用户态下面很难能够完全实现阻止某一个程序执行
最好能用驱动去hook ZwCreateProcess之类的函数
WingForce 2007-02-15
  • 打赏
  • 举报
回复
如果是为了防止访问某个特定的目录
是不是可以不用阻止explorer运行,改成hook CreateFile,然后控制文件访问
explorer访问文件应该也用该函数
horace331 2007-02-15
  • 打赏
  • 举报
回复
to ATField(field);
非常感谢你的回复。
我觉得你提的方案很好,我尝试一下。
现在的问题就是如何实现了。
请问有关于Impersonate的资料吗?这个我没有听过,而且在csdn上也没有搜索出文章。
ATField 2007-02-15
  • 打赏
  • 举报
回复
哦,知道你的目的就好了。我觉得你的这个要求可以用加密或者权限的方式解决。加密就不说了,权限方式可以在这个目录上面限制其他所有访问者的权限,包括管理员,只允许某个特殊用户,只有你的程序知道这个用户的密码,然后你的程序再Impersonate这个特殊用户,来访问这个目录,这样别的程序/用户都无法访问你这个目录,除了你的程序。为了安全起见,这个密码最好是动态生成的然后加密保存起来。我觉得这么做最简单和稳定。
horace331 2007-02-15
  • 打赏
  • 举报
回复
to ATField(field)
谢谢你的文章。
关于你的建议“其实你要做的倒不一定必须Hook API,修改Group Policy之类或者注册表之类的可能更加简单。”,我也想过,但是修改Group Policy后,那不是连本身的这个程序也不能fang问这个目录了吗。
我的目的是防止除了本身这个程序以外的途径访问指定目录。
有什么好的建议吗?
蒋晟 2007-02-14
  • 打赏
  • 举报
回复
这个exe是你的程序的父进程吧,在你的程序启动之前你怎么能禁止它运行呢
东文-桑晨 2007-02-14
  • 打赏
  • 举报
回复
HHOOK SetWindowsHookEx( int idHook,
HOOKPROC lpfn,
HINSTANCE hMod,
DWORD dwThreadId
);
Parameters

idHook
[in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values.
WH_CALLWNDPROC
Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more information, see the CallWndProc hook procedure.
WH_CALLWNDPROCRET
Installs a hook procedure that monitors messages after they have been processed by the destination window procedure. For more information, see the CallWndRetProc hook procedure.
WH_CBT
Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application. For more information, see the CBTProc hook procedure.
WH_DEBUG
Installs a hook procedure useful for debugging other hook procedures. For more information, see the DebugProc hook procedure.
WH_FOREGROUNDIDLE
Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the ForegroundIdleProc hook procedure.
WH_GETMESSAGE
Installs a hook procedure that monitors messages posted to a message queue. For more information, see the GetMsgProc hook procedure.
WH_JOURNALPLAYBACK
Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. For more information, see the JournalPlaybackProc hook procedure.
WH_JOURNALRECORD
Installs a hook procedure that records input messages posted to the system message queue. This hook is useful for recording macros. For more information, see the JournalRecordProc hook procedure.
WH_KEYBOARD
Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
WH_KEYBOARD_LL
Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.
WH_MOUSE
Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
WH_MOUSE_LL
Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.
WH_MSGFILTER
Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. For more information, see the MessageProc hook procedure.
WH_SHELL
Installs a hook procedure that receives notifications useful to shell applications. For more information, see the ShellProc hook procedure.
WH_SYSMSGFILTER
Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the same desktop as the calling thread. For more information, see the SysMsgProc hook procedure.
lpfn
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
hMod
[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧