26.07.2018 Views

hacking-the-art-of-exploitation

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>the</strong> two addressing schemes. In <strong>the</strong> <strong>of</strong>fice, post <strong>of</strong>fice mail sent to an<br />

employee at <strong>the</strong> <strong>of</strong>fice’s address goes to <strong>the</strong> appropriate desk. In E<strong>the</strong>rnet,<br />

<strong>the</strong> method is known as Address Resolution Protocol (ARP).<br />

This protocol allows “seating ch<strong>art</strong>s” to be made to associate an IP address<br />

with a piece <strong>of</strong> hardware. There are four different types <strong>of</strong> ARP messages, but<br />

<strong>the</strong> two most important types are ARP request messages and ARP reply messages.<br />

Any packet’s E<strong>the</strong>rnet header includes a type value that describes <strong>the</strong> packet.<br />

This type is used to specify whe<strong>the</strong>r <strong>the</strong> packet is an ARP-type message or an<br />

IP packet.<br />

An ARP request is a message, sent to <strong>the</strong> broadcast address, that contains<br />

<strong>the</strong> sender’s IP address and MAC address and basically says, “Hey, who has<br />

this IP? If it’s you, please respond and tell me your MAC address.” An ARP<br />

reply is <strong>the</strong> corresponding response that is sent to <strong>the</strong> requester’s MAC address<br />

(and IP address) saying, “This is my MAC address, and I have this IP address.”<br />

Most implementations will temporarily cache <strong>the</strong> MAC/IP address pairs<br />

received in ARP replies, so that ARP requests and replies aren’t needed for<br />

every single packet. These caches are like <strong>the</strong> inter<strong>of</strong>fice seating ch<strong>art</strong>.<br />

For example, if one system has <strong>the</strong> IP address 10.10.10.20 and MAC<br />

address 00:00:00:aa:aa:aa, and ano<strong>the</strong>r system on <strong>the</strong> same network has<br />

<strong>the</strong> IP address 10.10.10.50 and MAC address 00:00:00:bb:bb:bb, nei<strong>the</strong>r<br />

system can communicate with <strong>the</strong> o<strong>the</strong>r until <strong>the</strong>y know each o<strong>the</strong>r’s MAC<br />

addresses.<br />

ARP request<br />

Source MAC: 00:00:00:aa:aa:aa<br />

Dest MAC: ff:ff:ff:ff:ff:ff<br />

“Who has 10.10.10.50?”<br />

First system<br />

IP: 10.10.10.20<br />

MAC: 00:00:00:aa:aa:aa<br />

Second system<br />

IP: 10.10.10.50<br />

MAC: 00:00:00:bb:bb:bb<br />

ARP reply<br />

Source MAC: 00:00:00:bb:bb:bb<br />

Dest MAC: 00:00:00:aa:aa:aa<br />

“10.10.10.50 is at 00:00:00:bb:bb:bb.”<br />

If <strong>the</strong> first system wants to establish a TCP connection over IP to <strong>the</strong><br />

second device’s IP address <strong>of</strong> 10.10.10.50, <strong>the</strong> first system will first check its<br />

ARP cache to see if an entry exists for 10.10.10.50. Since this is <strong>the</strong> first time<br />

<strong>the</strong>se two systems are trying to communicate, <strong>the</strong>re will be no such entry, and<br />

an ARP request will be sent out to <strong>the</strong> broadcast address, saying, “If you are<br />

10.10.10.50, please respond to me at 00:00:00:aa:aa:aa.” Since this request<br />

uses <strong>the</strong> broadcast address, every system on <strong>the</strong> network sees <strong>the</strong> request, but<br />

only <strong>the</strong> system with <strong>the</strong> corresponding IP address is meant to respond. In this<br />

case, <strong>the</strong> second system responds with an ARP reply that is sent directly back<br />

to 00:00:00:aa:aa:aa saying, “I am 10.10.10.50 and I’m at 00:00:00:bb:bb:bb.”<br />

The first system receives this reply, caches <strong>the</strong> IP and MAC address pair in its<br />

ARP cache, and uses <strong>the</strong> hardware address to communicate.<br />

Networking 219

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!