WINXP下如何屏蔽ctrl+alt+del(200分)

  • 主题发起人 主题发起人 bilk1
  • 开始时间 开始时间
B

bilk1

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,要求有代码
 
找以前的帖子啊!
 
Win2K/NT下屏蔽Ctrl+Alt+Del的响应<br><br>大家知道,Ctrl+Alt+Del是Win2k/NT操作系统默认的系统登录/注销组合键序列,系统级别很高。在应用程序中,想要屏蔽掉该键序列的响应或得到这个"按下"事件,难度是相当大的。本文介绍了一种简单易行的方法,实现在用户登录成功后,按下Ctrl+Alt+Del不再弹出"Windows安全"对话框。<br><br>关键词:GINA(Graphical Identification aNd Authentication)<br>SAS(Secure Attention Sequence)<br><br>一. 开发原理<br>首先介绍一下Winlogon。Windows 2000/NT有三种系统状态:没有用户登录状态、用户成功登录状态以及工作站锁定状态。Winlogon是Windows 2000/NT操作系统提供交互式登录支持的组件。Winlogon有三个组成部分:可执行文件winlogon.exe,提供图形界面认证功能的动态库Gina Dll,以及一些网络服务提供动态库Network Provider Dll。参考模型如下:<br>&nbsp;<br>winlogon.exe处理一些下层导出的接口函数,而认证策略是在Gina Dll中是独立设计的。在系统启动时,Gina Dll被winlogon.exe装载。Microsoft提供了一个默认的Gina Dll--Winnt/system32/msgina.dll,提供了标准的用户名、密码认证模式。Gina Dll是可替换的,用户可以设计自己的Gina Dll,以提供其他如智能卡、视网膜、指纹或其他一些认证机制。<br>开发自定义的Gina Dll。必须实现并导出与winlogon.exe交互的18个标准函数接口,包括WlxNegotiate、WlxInitialize、WlxLoggedOnSAS等(其他函数接口请参考Msdn)。其中WlxNegotiate是winlogon.exe调用的第一个接口函数,进行必要的版本判断,随后调用的是WlxInitialize,主要完成winlogon.exe特定版本的函数分派表向Gina Dll的传递。笔者还要说明的是WlxLoggedOnSAS函数,这个函数主要的功能是,当winlogon在登录成功状态下,接收到SAS事件,于是调用这个函数进行SAS事件的识别以及进行各事件的相应处理。<br>自定义Gina Dll的使用。比如开发的Gina Dll文件名为MyGina.dll。将该文件放到以下路径:Winnt/system32。并修改注册表,如下:<br>Key Name: /HKEY_LOCAL_MACHINE/Software/Microsoft/Windows NT/CurrentVersion/ Winlogon <br>Value Name: GinaDLL <br>Value Type: [REG_SZ]<br>Value: MyGina.dll<br>重新启动计算机MyGina.dll即投入使用。<br><br>二. 应用实例<br>应用要求:在用户登录成功状态下,按下Ctrl+Alt+Del时系统不再弹出"Widows安全"对话框。由于并不需要改变用户名、密码这种标准的认证模式,所以可以仍然使用msgina.dll中导出的函数接口,而对WlxLoggedOnSAS函数的实现进行必要的改变。<br>开发环境:Windows 2000,PII 400<br>开发工具:Microsoft Visual C++ 6.0<br>开发步骤:<br>1.新建项目,选择MFC AppWizard(dll),项目名输入为MyGina。按下"OK"后,选择Regular DLL with MFC statically linked,按下"Finish"。<br>2.使用View-&gt;ClassWizard为CmyGinaApp增加InitInstance和ExitInstance两个函数的覆盖。注意在Stdafx.h中加入#include &lt;Winwlx.h&gt;。<br>3.由于要导入msgina.dll的接口函数,所以在MyGina.h中定义接口函数变量类型,如下:<br>typedef (WINAPI * NEGOTIATE) &nbsp; &nbsp; &nbsp; (DWORD,PDWORD);<br>typedef (WINAPI * INITIALIZE) &nbsp; &nbsp; &nbsp;(LPWSTR,HANDLE,PVOID,PVOID,PVOID *);<br>typedef (WINAPI * ACTIVATE_USHELL) (PVOID,PWSTR,PWSTR,PVOID);<br>typedef (WINAPI * PARAM_PVOID) &nbsp; &nbsp; (PVOID);<br>typedef (WINAPI * DISP_STATUS) &nbsp; &nbsp; (PVOID,HDESK,DWORD,PWSTR,PWSTR);<br>typedef (WINAPI * GET_STATUS) &nbsp; &nbsp; &nbsp;(PVOID,DWORD *,PWSTR,DWORD);<br>typedef (WINAPI * LOGON_SAS) &nbsp; &nbsp; &nbsp; (PVOID,DWORD,PVOID);<br>typedef (WINAPI * LOGOUT_SAS) &nbsp; &nbsp; &nbsp;(PVOID,DWORD,PLUID,PSID,PDWORD, PHANDLE,WLX_MPR_NOTIFY_INFO,PVOID *);<br>typedef (WINAPI * NETWORK_LOAD) &nbsp; &nbsp;(PVOID,PWLX_MPR_NOTIFY_INFO);<br>typedef (WINAPI * SCR_SAVER) &nbsp; &nbsp; &nbsp; (PVOID,BOOL &nbsp;*);<br>typedef (WINAPI * SHUT_DOWN) &nbsp; &nbsp; &nbsp; (PVOID,DWORD);<br>typedef (WINAPI * START_APP) &nbsp; &nbsp; &nbsp; (PVOID,PWSTR,PVOID,PWSTR);<br>typedef (WINAPI * LOCKED_SAS) &nbsp; &nbsp; &nbsp;(PVOID,DWORD);<br>并在类CmyGinaApp中定义成员变量,如下:<br>private:<br> HMODULE &nbsp; hMsDll;<br>public:<br> NEGOTIATE &nbsp; &nbsp; &nbsp; &nbsp; MyWlxNegotiate;<br> INITIALIZE &nbsp; &nbsp; &nbsp; &nbsp;MyWlxInitialize;<br> ACTIVATE_USHELL &nbsp; MyWlxActivateUserShell;<br> PARAM_PVOID &nbsp; &nbsp; &nbsp; MyWlxDisplayLockedNotice;<br> PARAM_PVOID &nbsp; &nbsp; &nbsp; MyWlxDisplaySASNotice;<br> DISP_STATUS &nbsp; &nbsp; &nbsp; MyWlxDisplayStatusMessage;<br> GET_STATUS &nbsp; &nbsp; &nbsp; &nbsp;MyWlxGetStatusMessage;<br> PARAM_PVOID &nbsp; &nbsp; &nbsp; MyWlxIsLockOk;<br> PARAM_PVOID &nbsp; &nbsp; &nbsp; MyWlxIsLogoffOk;<br> LOGON_SAS &nbsp; &nbsp; &nbsp; &nbsp; MyWlxLoggedOnSAS;<br> LOGOUT_SAS &nbsp; &nbsp; &nbsp; &nbsp;MyWlxLoggedOutSAS;<br> PARAM_PVOID &nbsp; &nbsp; &nbsp; MyWlxLogoff;<br> NETWORK_LOAD &nbsp; &nbsp; &nbsp;MyWlxNetworkProviderLoad;<br> PARAM_PVOID &nbsp; &nbsp; &nbsp; MyWlxRemoveStatusMessage;<br> SCR_SAVER &nbsp; &nbsp; &nbsp; &nbsp; MyWlxScreenSaverNotify;<br> SHUT_DOWN &nbsp; &nbsp; &nbsp; &nbsp; MyWlxShutdown;<br> START_APP &nbsp; &nbsp; &nbsp; &nbsp; MyWlxStartApplication;<br> LOCKED_SAS &nbsp; &nbsp; &nbsp; &nbsp;MyWlxWkstaLockedSAS;<br>注意在MyGina.h中说明extern CMyGinaApp theApp;以便于程序其他地方对theApp的引用。<br>4.在MyGina.cpp中,实现InitInstance如下:<br> // 得到默认的gina dll<br> if (hMsDll == NULL)<br> {<br> hMsDll = ::LoadLibrary("msgina.dll");<br> }<br> // 导入各个接口函数<br> if (hMsDll != NULL)<br> {<br> MyWlxNegotiate = (NEGOTIATE) &nbsp; &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxNegotiate");<br> MyWlxInitialize = (INITIALIZE) &nbsp; &nbsp; &nbsp;GetProcAddress(hMsDll,"WlxInitialize");<br> MyWlxActivateUserShell=(ACTIVATE_USHELL) GetProcAddress(hMsDll,"WlxActivateUserShell");<br> MyWlxDisplayLockedNotice=(PARAM_PVOID) GetProcAddress(hMsDll,"WlxDisplayLockedNotice");<br> MyWlxDisplaySASNotice &nbsp;= (PARAM_PVOID) &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxDisplaySASNotice");<br> MyWlxDisplayStatusMessage=(DISP_STATUS) &nbsp; GetProcAddress(hMsDll,"WlxDisplayStatusMessage");<br> MyWlxGetStatusMessage &nbsp; &nbsp;= (GET_STATUS) &nbsp; &nbsp; &nbsp;GetProcAddress(hMsDll,"WlxGetStatusMessage");<br> MyWlxIsLockOk &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = (PARAM_PVOID) &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxIsLockOk");<br> MyWlxIsLogoffOk &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = (PARAM_PVOID) &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxIsLogoffOk");<br> MyWlxLoggedOnSAS &nbsp; &nbsp; &nbsp; &nbsp;= (LOGON_SAS) &nbsp; &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxLoggedOnSAS");<br> MyWlxLoggedOutSAS &nbsp; &nbsp; &nbsp; = (LOGOUT_SAS) &nbsp; &nbsp; &nbsp;GetProcAddress(hMsDll,"WlxLoggedOutSAS");<br> MyWlxLogoff &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = (PARAM_PVOID) &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxLogoff");<br> MyWlxNetworkProviderLoad=(NETWORK_LOAD)GetProcAddress(hMsDll,"WlxNetworkProviderLoad");<br> MyWlxRemoveStatusMessage=(PARAM_PVOID) GetProcAddress(hMsDll,"WlxRemoveStatusMessage");<br> MyWlxScreenSaverNotify = (SCR_SAVER) &nbsp; &nbsp;GetProcAddress(hMsDll,"WlxScreenSaverNotify");<br> MyWlxShutdown &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = (SHUT_DOWN) &nbsp; &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxShutdown");<br> MyWlxStartApplication &nbsp; &nbsp; = (START_APP) &nbsp; &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxStartApplication");<br> MyWlxWkstaLockedSAS &nbsp; = (LOCKED_SAS) &nbsp; &nbsp; GetProcAddress(hMsDll,"WlxWkstaLockedSAS");<br> }<br>实现ExitInstance如下:<br> // 卸载dll<br> if (hMsDll != NULL)<br> {<br> ::FreeLibrary(hMsDll);<br> hMsDll = NULL;<br> }<br>5.实现接口函数。由于本应用仍然保持msgina.dll的大部分操作,所以MyGina.dll的接口函数的实现较为简单。重点需要注意的是WlxLoggedOnSAS函数的实现。当在成功登录状态下,不管接收到什么SAS事件,该函数直接返回WLX_SAS_ACTION_NONE而不做其他处理。由于实现的函数较多(必须的18个),笔者仅列出代表性的五个,其余的依理类推。<br>// Winlogon.exe调用的gina dll中的第一个函数<br>// 使gina dll确认是否支持当前版本的Winlogon.exe<br>// 传递给winlogon.exe需要那个版本的接口函数<br>BOOL WINAPI WlxNegotiate(DWORD dwWinLogonVersion, PDWORD pdwDllVersion)<br>{<br>// 直接调用从msgina.dll中导入的函数<br> return theApp.MyWlxNegotiate(dwWinLogonVersion,pdwDllVersion);<br>}<br>// 初始化,winlogon.exe向gina dll传递需要版本的接口函数分配表<br>BOOL WINAPI WlxInitialize(LPWSTR &nbsp; &nbsp;lpWinsta,<br> &nbsp;HANDLE &nbsp; &nbsp;hWlx,<br> &nbsp;PVOID &nbsp; &nbsp; pvReserved,<br> &nbsp;PVOID &nbsp; &nbsp; pWinlogonFunctions,<br> &nbsp;PVOID * &nbsp; pWlxContext<br> &nbsp;)<br>{<br>// 直接调用从msgina.dll中导入的函数<br> return theApp.MyWlxInitialize(lpWinsta,hWlx,pvReserved,pWinlogonFunctions,pWlxContext);<br>}<br>// 当系统处于锁定状态时,Winlogon.exe调用该函数<br>// 显示一些信息,如锁定者、锁定时间等<br>VOID WINAPI WlxDisplayLockedNotice(PVOID pWlxContext)<br>{<br> theApp.MyWlxDisplayLockedNotice(pWlxContext);<br>}<br>// 在系统关闭之前,Winlogon.exe调用该函数<br>// 允许gina dll处理一些系统关闭前的处理<br>VOID WINAPI WlxShutdown(PVOID pWlxContext, DWORD ShutdownType)<br>{<br> theApp.MyWlxShutdown(pWlxContext,ShutdownType);<br>}<br>// 当系统处于登陆成功,没有锁定的状态下<br>// Winlogon接收到SAS事件,于是调用该函数<br>// 现屏蔽所有事件,直接返回<br>int WINAPI WlxLoggedOnSAS(PVOID pWlxContext,<br> &nbsp;DWORD dwSasType,<br> &nbsp;PVOID pReserved)<br>{<br> return WLX_SAS_ACTION_NONE;<br>}<br>6.将MyGina.dll中实现的所有接口函数,在MyGina.def中定义导出。<br><br><br><br><br><br><br>前言<br>在WINDOWS 9X环境中我们可以使用SystemParametersInfo (SPI_SCREENSAVERRUNNING, 1,NULL, 0);来屏蔽CTRL+ALT+DEL,但在NT/2000环境下却行不通,即使使用WH_KEYBOARD_LL这个低级的键盘hook也无法拦截!笔者通过替换GINA DLL的方式很好地实现了在NT/2000下屏蔽CTRL+ALT+DEL的功能。<br><br>下载源代码 6K<br><br>一、原理<br>在NT/2000中交互式的登陆支持是由WinLogon调用GINA DLL实现的,GINA DLL提供了一个交互式的界面为用户登陆提供认证请求。在WinLogon初始化时,就向系统注册截获CTRL+ALT+DEL消息,所以其他程序就无法得到CTRL+ALT+DEL的消息。<br>WinLogon会和GINA DLL进行交互,缺省是MSGINA.DLL(在System32目录下)。微软同时也为我们提供的接口,自己<br>可以编GINA DLL来代替MSGINA.DLL。<br><br>WinLogon初始化时会创建3个桌面:<br>(1)、winlogon桌面:主要显示window 安全等界面,如你按下CTRL+ALT+DEL,登陆的界面等<br>(2)、应用程序桌面:我们平时见到的那个有我的电脑的界面<br>(3)、屏幕保护桌面:屏幕保护显示界面。<br><br>在用户登陆以后,按下CTRL+ALT+DEL键的时候,WinLogon回调用GINA DLL的输出函数:WlxLoggedOnSAS,<br>这时正处于winlogon桌面,我们只要直接将他转向应用程序桌面,系统就不会显示Windows安全那个界面,换一种说法<br>也就是用户按下CTRL+ALT+DEL后,不会起什么作用。当是我们在切换桌面的时候会出现屏幕闪动!<br><br>二、程序实现<br>GINA DLL要输出下列函数(winlogon会调用)<br>WlxActivateUserShell<br>WlxDisplayLockedNotice<br>WlxDisplaySASNotice<br>WlxDisplayStatusMessage<br>WlxGetStatusMessage<br>WlxInitialize<br>WlxIsLockOk<br>WlxIsLogoffOk<br>WlxLoggedOnSAS<br>WlxLoggedOutSAS<br>WlxLogoff<br>WlxNegotiate<br>WlxNetworkProviderLoad<br>WlxRemoveStatusMessage<br>WlxScreenSaverNotify<br>WlxShutdown<br>WlxStartApplication<br>WlxWkstaLockedSAS<br>为了简化编程,我们从MSGINA.DLL中动态获取上诉函数,在自定义的DLL中(以下称为NoReboot.DLL)中直接调用MSGINA.DLL<br>的函数即可。现在我们要处理的就是WlxLoggedOnSAS函数:<br><br><br>int WINAPI WlxLoggedOnSAS (<br>&nbsp; &nbsp; &nbsp; &nbsp; PVOID pWlxContext,<br>&nbsp; &nbsp; &nbsp; &nbsp; DWORD dwSasType,<br>&nbsp; &nbsp; &nbsp; &nbsp; PVOID pReserved)<br>&nbsp; &nbsp; &nbsp; &nbsp; { <br>&nbsp; &nbsp; &nbsp; &nbsp; HANDLE hMutex;<br>&nbsp; &nbsp; &nbsp; &nbsp; WriteInfo("WlxLoggedOnSAS /r/n"); //用于记录信息<br>&nbsp;if (dwSasType == WLX_SAS_TYPE_CTRL_ALT_DEL){ //屏蔽CTRL_ALT_DEL,也可以根据特定条件来决定是否要屏蔽<br>&nbsp; &nbsp; &nbsp; &nbsp; //我采用了Mutex来控制是否屏蔽,(注意:要用unicode)<br>&nbsp; &nbsp; &nbsp; &nbsp; hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, L"_ac952_z_cn_CTRL_ALT_DEL");<br>&nbsp; &nbsp; &nbsp; &nbsp; if (hMutex){<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hMutex);<br>&nbsp; &nbsp; &nbsp; &nbsp; WriteInfo("disble CTRL+ALT+DEL /r/n");<br>&nbsp; &nbsp; &nbsp; &nbsp; return WLX_SAS_ACTION_NONE; //将屏幕切换到应用程序桌面,屏蔽掉CTRL+ALT+DEL<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; WriteInfo("not disble CTRL+ALT+DEL /r/n");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; return prcWlxLoggedOnSAS ( //这是我从MSGINA.DLL中获取的函数。<br>&nbsp; &nbsp; &nbsp; &nbsp; pWlxContext,<br>&nbsp; &nbsp; &nbsp; &nbsp; dwSasType,<br>&nbsp; &nbsp; &nbsp; &nbsp; pReserved);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>我们要在自己的程序中调用hMutex = CreateMutex(NULL, FALSE, "_ac952_z_cn_CTRL_ALT_DEL");就可屏蔽CTRL+ALT+DEL。<br><br>三、安装和注意事项:<br><br>在编写GIAN DLL中要注意,GINA DLL使用的是unicode。<br><br>GINA DLL的安装:<br>键名 : /HKEY_LOCAL_MACHINE/Software/Microsoft/Windows NT/CurrentVersion/Winlogon <br>变量名 : GinaDLL <br>变量类型 : [REG_SZ] <br>内容 : "你的GINA DLL的名称" 如:"NoReboot.DLL:<br><br>将你的GINA DLL(NoReboot.dll)拷贝到系统目录下(system32),重启机器,你的GINA DLL(NoReboot.dll)就会运行。<br>如果出现进不了你的系统,那你进入DOS后,将msgina.dll拷贝成你的GINA DLL(NoReboot.dll)就可进入了,或者进入<br>安全模式,删除掉那个键值。
 
后退
顶部