Ticket #21225: patch-arpspoof.c.diff
File patch-arpspoof.c.diff, 4.6 KB (added by hsivank@…, 15 years ago) |
---|
-
arpspoof.c
old new 14 14 #include <sys/types.h> 15 15 #include <sys/param.h> 16 16 #include <netinet/in.h> 17 #include <netinet/if_ether.h> 17 18 18 19 #include <stdio.h> 19 20 #include <string.h> … … 25 26 #include "arp.h" 26 27 #include "version.h" 27 28 28 extern char *ether_ntoa(struct ether_addr *);29 //extern char *ether_ntoa(struct ether_addr *); 29 30 30 static struct libnet_link_int *llif;31 static libnet_t *l; 31 32 static struct ether_addr spoof_mac, target_mac; 32 33 static in_addr_t spoof_ip, target_ip; 33 34 static char *intf; … … 41 42 } 42 43 43 44 static int 44 arp_send( struct libnet_link_int *llif, char *dev,45 in t op, u_char *sha, in_addr_t spa, u_char*tha, in_addr_t tpa)45 arp_send(libnet_t *l, int op, u_int8_t *sha, 46 in_addr_t spa, u_int8_t *tha, in_addr_t tpa) 46 47 { 47 char ebuf[128]; 48 u_char pkt[60]; 49 48 int retval; 49 50 50 if (sha == NULL && 51 (sha = (u_ char *)libnet_get_hwaddr(llif, dev, ebuf)) == NULL) {51 (sha = (u_int8_t *)libnet_get_hwaddr(l)) == NULL) { 52 52 return (-1); 53 53 } 54 54 if (spa == 0) { 55 if ((spa = libnet_get_ipaddr (llif, dev, ebuf)) == 0)55 if ((spa = libnet_get_ipaddr4(l)) == -1) 56 56 return (-1); 57 spa = htonl(spa); /* XXX */58 57 } 59 58 if (tha == NULL) 60 59 tha = "\xff\xff\xff\xff\xff\xff"; 61 60 62 libnet_build_ethernet(tha, sha, ETHERTYPE_ARP, NULL, 0, pkt); 61 libnet_autobuild_arp(op, sha, (u_int8_t *)&spa, 62 tha, (u_int8_t *)&tpa, l); 63 libnet_build_ethernet(tha, sha, ETHERTYPE_ARP, NULL, 0, l, 0); 63 64 64 libnet_build_arp(ARPHRD_ETHER, ETHERTYPE_IP, ETHER_ADDR_LEN, 4,65 op, sha, (u_char *)&spa, tha, (u_char *)&tpa,66 NULL, 0, pkt + ETH_H);67 68 65 fprintf(stderr, "%s ", 69 66 ether_ntoa((struct ether_addr *)sha)); 70 67 71 68 if (op == ARPOP_REQUEST) { 72 69 fprintf(stderr, "%s 0806 42: arp who-has %s tell %s\n", 73 70 ether_ntoa((struct ether_addr *)tha), 74 libnet_ host_lookup(tpa, 0),75 libnet_ host_lookup(spa, 0));71 libnet_addr2name4(tpa, LIBNET_DONT_RESOLVE), 72 libnet_addr2name4(spa, LIBNET_DONT_RESOLVE)); 76 73 } 77 74 else { 78 75 fprintf(stderr, "%s 0806 42: arp reply %s is-at ", 79 76 ether_ntoa((struct ether_addr *)tha), 80 libnet_ host_lookup(spa, 0));77 libnet_addr2name4(spa, LIBNET_DONT_RESOLVE)); 81 78 fprintf(stderr, "%s\n", 82 79 ether_ntoa((struct ether_addr *)sha)); 83 80 } 84 return (libnet_write_link_layer(llif, dev, pkt, sizeof(pkt)) == sizeof(pkt)); 81 retval = libnet_write(l); 82 if (retval) 83 fprintf(stderr, "%s", libnet_geterror(l)); 84 85 libnet_clear_packet(l); 86 87 return retval; 85 88 } 86 89 87 90 #ifdef __linux__ … … 119 122 /* XXX - force the kernel to arp. feh. */ 120 123 arp_force(ip); 121 124 #else 122 arp_send(l lif, intf, ARPOP_REQUEST, NULL, 0, NULL, ip);125 arp_send(l, ARPOP_REQUEST, NULL, 0, NULL, ip); 123 126 #endif 124 127 sleep(1); 125 128 } … … 136 139 if (arp_find(spoof_ip, &spoof_mac)) { 137 140 for (i = 0; i < 3; i++) { 138 141 /* XXX - on BSD, requires ETHERSPOOF kernel. */ 139 arp_send(l lif, intf, ARPOP_REPLY,140 (u_ char*)&spoof_mac, spoof_ip,141 (target_ip ? (u_ char*)&target_mac : NULL),142 arp_send(l, ARPOP_REPLY, 143 (u_int8_t *)&spoof_mac, spoof_ip, 144 (target_ip ? (u_int8_t *)&target_mac : NULL), 142 145 target_ip); 143 146 sleep(1); 144 147 } … … 151 154 { 152 155 extern char *optarg; 153 156 extern int optind; 154 char ebuf[PCAP_ERRBUF_SIZE]; 157 char pcap_ebuf[PCAP_ERRBUF_SIZE]; 158 char libnet_ebuf[LIBNET_ERRBUF_SIZE]; 155 159 int c; 156 160 157 161 intf = NULL; … … 163 167 intf = optarg; 164 168 break; 165 169 case 't': 166 if ((target_ip = libnet_name _resolve(optarg, 1)) == -1)170 if ((target_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1) 167 171 usage(); 168 172 break; 169 173 default: … … 176 180 if (argc != 1) 177 181 usage(); 178 182 179 if ((spoof_ip = libnet_name _resolve(argv[0], 1)) == -1)183 if ((spoof_ip = libnet_name2addr4(l, argv[0], LIBNET_RESOLVE)) == -1) 180 184 usage(); 181 185 182 if (intf == NULL && (intf = pcap_lookupdev( ebuf)) == NULL)183 errx(1, "%s", ebuf);186 if (intf == NULL && (intf = pcap_lookupdev(pcap_ebuf)) == NULL) 187 errx(1, "%s", pcap_ebuf); 184 188 185 if ((l lif = libnet_open_link_interface(intf, ebuf)) == 0)186 errx(1, "%s", ebuf);189 if ((l = libnet_init(LIBNET_LINK, intf, libnet_ebuf)) == NULL) 190 errx(1, "%s", libnet_ebuf); 187 191 188 192 if (target_ip != 0 && !arp_find(target_ip, &target_mac)) 189 193 errx(1, "couldn't arp for host %s", 190 libnet_ host_lookup(target_ip, 0));194 libnet_addr2name4(target_ip, LIBNET_DONT_RESOLVE)); 191 195 192 196 signal(SIGHUP, cleanup); 193 197 signal(SIGINT, cleanup); 194 198 signal(SIGTERM, cleanup); 195 199 196 200 for (;;) { 197 arp_send(l lif, intf, ARPOP_REPLY, NULL, spoof_ip,198 (target_ip ? (u_ char*)&target_mac : NULL),201 arp_send(l, ARPOP_REPLY, NULL, spoof_ip, 202 (target_ip ? (u_int8_t *)&target_mac : NULL), 199 203 target_ip); 200 204 sleep(2); 201 205 }