1
0

patch-dnsspoof_c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. --- dsniff-2.4.orig/dnsspoof.c 2001-03-15 09:33:03.000000000 +0100
  2. +++ dsniff-2.4/dnsspoof.c 2009-12-11 12:41:53.000000000 +0100
  3. @@ -38,7 +38,7 @@ SLIST_HEAD(, dnsent) dns_entries;
  4. pcap_t *pcap_pd = NULL;
  5. int pcap_off = -1;
  6. -int lnet_sock = -1;
  7. +libnet_t *l;
  8. u_long lnet_ip = -1;
  9. static void
  10. @@ -90,19 +90,18 @@ static void
  11. dns_init(char *dev, char *filename)
  12. {
  13. FILE *f;
  14. - struct libnet_link_int *llif;
  15. + libnet_t *l;
  16. + char libnet_ebuf[LIBNET_ERRBUF_SIZE];
  17. struct dnsent *de;
  18. char *ip, *name, buf[1024];
  19. - if ((llif = libnet_open_link_interface(dev, buf)) == NULL)
  20. - errx(1, "%s", buf);
  21. + if ((l = libnet_init(LIBNET_LINK, dev, libnet_ebuf)) == NULL)
  22. + errx(1, "%s", libnet_ebuf);
  23. - if ((lnet_ip = libnet_get_ipaddr(llif, dev, buf)) == -1)
  24. - errx(1, "%s", buf);
  25. + if ((lnet_ip = libnet_get_ipaddr4(l)) == -1)
  26. + errx(1, "%s", libnet_geterror(l));
  27. - lnet_ip = htonl(lnet_ip);
  28. -
  29. - libnet_close_link_interface(llif);
  30. + libnet_destroy(l);
  31. SLIST_INIT(&dns_entries);
  32. @@ -180,7 +179,7 @@ dns_lookup_ptr(const char *name)
  33. static void
  34. dns_spoof(u_char *u, const struct pcap_pkthdr *pkthdr, const u_char *pkt)
  35. {
  36. - struct libnet_ip_hdr *ip;
  37. + struct libnet_ipv4_hdr *ip;
  38. struct libnet_udp_hdr *udp;
  39. HEADER *dns;
  40. char name[MAXHOSTNAMELEN];
  41. @@ -189,7 +188,7 @@ dns_spoof(u_char *u, const struct pcap_p
  42. in_addr_t dst;
  43. u_short type, class;
  44. - ip = (struct libnet_ip_hdr *)(pkt + pcap_off);
  45. + ip = (struct libnet_ipv4_hdr *)(pkt + pcap_off);
  46. udp = (struct libnet_udp_hdr *)(pkt + pcap_off + (ip->ip_hl * 4));
  47. dns = (HEADER *)(udp + 1);
  48. p = (u_char *)(dns + 1);
  49. @@ -212,7 +211,7 @@ dns_spoof(u_char *u, const struct pcap_p
  50. if (class != C_IN)
  51. return;
  52. - p = buf + IP_H + UDP_H + dnslen;
  53. + p = buf + dnslen;
  54. if (type == T_A) {
  55. if ((dst = dns_lookup_a(name)) == -1)
  56. @@ -234,38 +233,38 @@ dns_spoof(u_char *u, const struct pcap_p
  57. anslen += 12;
  58. }
  59. else return;
  60. -
  61. - libnet_build_ip(UDP_H + dnslen + anslen, 0, libnet_get_prand(PRu16),
  62. - 0, 64, IPPROTO_UDP, ip->ip_dst.s_addr,
  63. - ip->ip_src.s_addr, NULL, 0, buf);
  64. -
  65. - libnet_build_udp(ntohs(udp->uh_dport), ntohs(udp->uh_sport),
  66. - NULL, dnslen + anslen, buf + IP_H);
  67. - memcpy(buf + IP_H + UDP_H, (u_char *)dns, dnslen);
  68. + memcpy(buf, (u_char *)dns, dnslen);
  69. - dns = (HEADER *)(buf + IP_H + UDP_H);
  70. + dns = (HEADER *)buf;
  71. dns->qr = dns->ra = 1;
  72. if (type == T_PTR) dns->aa = 1;
  73. dns->ancount = htons(1);
  74. dnslen += anslen;
  75. +
  76. + libnet_clear_packet(l);
  77. + libnet_build_udp(ntohs(udp->uh_dport), ntohs(udp->uh_sport),
  78. + LIBNET_UDP_H + dnslen, 0,
  79. + (u_int8_t *)buf, dnslen, l, 0);
  80. +
  81. + libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_UDP_H + dnslen, 0,
  82. + libnet_get_prand(LIBNET_PRu16), 0, 64, IPPROTO_UDP, 0,
  83. + ip->ip_dst.s_addr, ip->ip_src.s_addr, NULL, 0, l, 0);
  84. - libnet_do_checksum(buf, IPPROTO_UDP, UDP_H + dnslen);
  85. -
  86. - if (libnet_write_ip(lnet_sock, buf, IP_H + UDP_H + dnslen) < 0)
  87. + if (libnet_write(l) < 0)
  88. warn("write");
  89. fprintf(stderr, "%s.%d > %s.%d: %d+ %s? %s\n",
  90. - libnet_host_lookup(ip->ip_src.s_addr, 0), ntohs(udp->uh_sport),
  91. - libnet_host_lookup(ip->ip_dst.s_addr, 0), ntohs(udp->uh_dport),
  92. + libnet_addr2name4(ip->ip_src.s_addr, 0), ntohs(udp->uh_sport),
  93. + libnet_addr2name4(ip->ip_dst.s_addr, 0), ntohs(udp->uh_dport),
  94. ntohs(dns->id), type == T_A ? "A" : "PTR", name);
  95. }
  96. static void
  97. cleanup(int sig)
  98. {
  99. - libnet_close_raw_sock(lnet_sock);
  100. + libnet_destroy(l);
  101. pcap_close(pcap_pd);
  102. exit(0);
  103. }
  104. @@ -276,6 +275,7 @@ main(int argc, char *argv[])
  105. extern char *optarg;
  106. extern int optind;
  107. char *p, *dev, *hosts, buf[1024];
  108. + char ebuf[LIBNET_ERRBUF_SIZE];
  109. int i;
  110. dev = hosts = NULL;
  111. @@ -306,7 +306,7 @@ main(int argc, char *argv[])
  112. strlcpy(buf, p, sizeof(buf));
  113. }
  114. else snprintf(buf, sizeof(buf), "udp dst port 53 and not src %s",
  115. - libnet_host_lookup(lnet_ip, 0));
  116. + libnet_addr2name4(lnet_ip, LIBNET_DONT_RESOLVE));
  117. if ((pcap_pd = pcap_init(dev, buf, 128)) == NULL)
  118. errx(1, "couldn't initialize sniffing");
  119. @@ -314,10 +314,10 @@ main(int argc, char *argv[])
  120. if ((pcap_off = pcap_dloff(pcap_pd)) < 0)
  121. errx(1, "couldn't determine link layer offset");
  122. - if ((lnet_sock = libnet_open_raw_sock(IPPROTO_RAW)) == -1)
  123. + if ((l = libnet_init(LIBNET_RAW4, dev, ebuf)) == NULL)
  124. errx(1, "couldn't initialize sending");
  125. - libnet_seed_prand();
  126. + libnet_seed_prand(l);
  127. signal(SIGHUP, cleanup);
  128. signal(SIGINT, cleanup);