1
0

patch-arpspoof_c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. --- dsniff-2.4.orig/arpspoof.c 2001-03-15 09:32:58.000000000 +0100
  2. +++ dsniff-2.4/arpspoof.c 2009-12-11 13:14:45.000000000 +0100
  3. @@ -14,6 +14,7 @@
  4. #include <sys/types.h>
  5. #include <sys/param.h>
  6. #include <netinet/in.h>
  7. +#include <netinet/if_ether.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. @@ -25,9 +26,9 @@
  11. #include "arp.h"
  12. #include "version.h"
  13. -extern char *ether_ntoa(struct ether_addr *);
  14. +//extern char *ether_ntoa(struct ether_addr *);
  15. -static struct libnet_link_int *llif;
  16. +static libnet_t *l;
  17. static struct ether_addr spoof_mac, target_mac;
  18. static in_addr_t spoof_ip, target_ip;
  19. static char *intf;
  20. @@ -41,47 +42,49 @@ usage(void)
  21. }
  22. static int
  23. -arp_send(struct libnet_link_int *llif, char *dev,
  24. - int op, u_char *sha, in_addr_t spa, u_char *tha, in_addr_t tpa)
  25. +arp_send(libnet_t *l, int op, u_int8_t *sha,
  26. + in_addr_t spa, u_int8_t *tha, in_addr_t tpa)
  27. {
  28. - char ebuf[128];
  29. - u_char pkt[60];
  30. -
  31. + int retval;
  32. +
  33. if (sha == NULL &&
  34. - (sha = (u_char *)libnet_get_hwaddr(llif, dev, ebuf)) == NULL) {
  35. + (sha = (u_int8_t *)libnet_get_hwaddr(l)) == NULL) {
  36. return (-1);
  37. }
  38. if (spa == 0) {
  39. - if ((spa = libnet_get_ipaddr(llif, dev, ebuf)) == 0)
  40. + if ((spa = libnet_get_ipaddr4(l)) == -1)
  41. return (-1);
  42. - spa = htonl(spa); /* XXX */
  43. }
  44. if (tha == NULL)
  45. tha = "\xff\xff\xff\xff\xff\xff";
  46. - libnet_build_ethernet(tha, sha, ETHERTYPE_ARP, NULL, 0, pkt);
  47. + libnet_autobuild_arp(op, sha, (u_int8_t *)&spa,
  48. + tha, (u_int8_t *)&tpa, l);
  49. + libnet_build_ethernet(tha, sha, ETHERTYPE_ARP, NULL, 0, l, 0);
  50. - libnet_build_arp(ARPHRD_ETHER, ETHERTYPE_IP, ETHER_ADDR_LEN, 4,
  51. - op, sha, (u_char *)&spa, tha, (u_char *)&tpa,
  52. - NULL, 0, pkt + ETH_H);
  53. -
  54. fprintf(stderr, "%s ",
  55. ether_ntoa((struct ether_addr *)sha));
  56. if (op == ARPOP_REQUEST) {
  57. fprintf(stderr, "%s 0806 42: arp who-has %s tell %s\n",
  58. ether_ntoa((struct ether_addr *)tha),
  59. - libnet_host_lookup(tpa, 0),
  60. - libnet_host_lookup(spa, 0));
  61. + libnet_addr2name4(tpa, LIBNET_DONT_RESOLVE),
  62. + libnet_addr2name4(spa, LIBNET_DONT_RESOLVE));
  63. }
  64. else {
  65. fprintf(stderr, "%s 0806 42: arp reply %s is-at ",
  66. ether_ntoa((struct ether_addr *)tha),
  67. - libnet_host_lookup(spa, 0));
  68. + libnet_addr2name4(spa, LIBNET_DONT_RESOLVE));
  69. fprintf(stderr, "%s\n",
  70. ether_ntoa((struct ether_addr *)sha));
  71. }
  72. - return (libnet_write_link_layer(llif, dev, pkt, sizeof(pkt)) == sizeof(pkt));
  73. + retval = libnet_write(l);
  74. + if (retval)
  75. + fprintf(stderr, "%s", libnet_geterror(l));
  76. +
  77. + libnet_clear_packet(l);
  78. +
  79. + return retval;
  80. }
  81. #ifdef __linux__
  82. @@ -113,13 +116,13 @@ arp_find(in_addr_t ip, struct ether_addr
  83. int i = 0;
  84. do {
  85. - if (arp_cache_lookup(ip, mac) == 0)
  86. + if (arp_cache_lookup(ip, mac, intf) == 0)
  87. return (1);
  88. #ifdef __linux__
  89. /* XXX - force the kernel to arp. feh. */
  90. arp_force(ip);
  91. #else
  92. - arp_send(llif, intf, ARPOP_REQUEST, NULL, 0, NULL, ip);
  93. + arp_send(l, ARPOP_REQUEST, NULL, 0, NULL, ip);
  94. #endif
  95. sleep(1);
  96. }
  97. @@ -136,9 +139,9 @@ cleanup(int sig)
  98. if (arp_find(spoof_ip, &spoof_mac)) {
  99. for (i = 0; i < 3; i++) {
  100. /* XXX - on BSD, requires ETHERSPOOF kernel. */
  101. - arp_send(llif, intf, ARPOP_REPLY,
  102. - (u_char *)&spoof_mac, spoof_ip,
  103. - (target_ip ? (u_char *)&target_mac : NULL),
  104. + arp_send(l, ARPOP_REPLY,
  105. + (u_int8_t *)&spoof_mac, spoof_ip,
  106. + (target_ip ? (u_int8_t *)&target_mac : NULL),
  107. target_ip);
  108. sleep(1);
  109. }
  110. @@ -151,7 +154,8 @@ main(int argc, char *argv[])
  111. {
  112. extern char *optarg;
  113. extern int optind;
  114. - char ebuf[PCAP_ERRBUF_SIZE];
  115. + char pcap_ebuf[PCAP_ERRBUF_SIZE];
  116. + char libnet_ebuf[LIBNET_ERRBUF_SIZE];
  117. int c;
  118. intf = NULL;
  119. @@ -163,7 +167,7 @@ main(int argc, char *argv[])
  120. intf = optarg;
  121. break;
  122. case 't':
  123. - if ((target_ip = libnet_name_resolve(optarg, 1)) == -1)
  124. + if ((target_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
  125. usage();
  126. break;
  127. default:
  128. @@ -176,26 +180,26 @@ main(int argc, char *argv[])
  129. if (argc != 1)
  130. usage();
  131. - if ((spoof_ip = libnet_name_resolve(argv[0], 1)) == -1)
  132. + if ((spoof_ip = libnet_name2addr4(l, argv[0], LIBNET_RESOLVE)) == -1)
  133. usage();
  134. - if (intf == NULL && (intf = pcap_lookupdev(ebuf)) == NULL)
  135. - errx(1, "%s", ebuf);
  136. + if (intf == NULL && (intf = pcap_lookupdev(pcap_ebuf)) == NULL)
  137. + errx(1, "%s", pcap_ebuf);
  138. - if ((llif = libnet_open_link_interface(intf, ebuf)) == 0)
  139. - errx(1, "%s", ebuf);
  140. + if ((l = libnet_init(LIBNET_LINK, intf, libnet_ebuf)) == NULL)
  141. + errx(1, "%s", libnet_ebuf);
  142. if (target_ip != 0 && !arp_find(target_ip, &target_mac))
  143. errx(1, "couldn't arp for host %s",
  144. - libnet_host_lookup(target_ip, 0));
  145. + libnet_addr2name4(target_ip, LIBNET_DONT_RESOLVE));
  146. signal(SIGHUP, cleanup);
  147. signal(SIGINT, cleanup);
  148. signal(SIGTERM, cleanup);
  149. for (;;) {
  150. - arp_send(llif, intf, ARPOP_REPLY, NULL, spoof_ip,
  151. - (target_ip ? (u_char *)&target_mac : NULL),
  152. + arp_send(l, ARPOP_REPLY, NULL, spoof_ip,
  153. + (target_ip ? (u_int8_t *)&target_mac : NULL),
  154. target_ip);
  155. sleep(2);
  156. }