26.07.2018 Views

hacking-the-art-of-exploitation

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

typedef struct libnet_dns_hdr DNShdr;<br />

typedef struct libnet_e<strong>the</strong>rnet_hdr ETHERhdr;<br />

typedef struct libnet_icmp_hdr ICMPhdr;<br />

typedef struct libnet_igmp_hdr IGMPhdr;<br />

typedef struct libnet_ip_hdr IPhdr;<br />

The nemesis_arp() function calls a series <strong>of</strong> o<strong>the</strong>r functions from this file:<br />

arp_initdata(), arp_cmdline(), arp_validatedata(), and arp_verbose(). You can<br />

probably guess that <strong>the</strong>se functions initialize data, process command-line arguments,<br />

validate data, and do some sort <strong>of</strong> verbose reporting. The arp_initdata()<br />

function does exactly this, initializing values in statically declared data<br />

structures.<br />

The arp_initdata() function, shown below, sets various elements <strong>of</strong> <strong>the</strong><br />

header structures to <strong>the</strong> appropriate values for an ARP packet.<br />

From nemesis-arp.c<br />

static void arp_initdata(void)<br />

{<br />

/* defaults */<br />

e<strong>the</strong>rhdr.e<strong>the</strong>r_type = ETHERTYPE_ARP; /* E<strong>the</strong>rnet type ARP */<br />

memset(e<strong>the</strong>rhdr.e<strong>the</strong>r_shost, 0, 6); /* E<strong>the</strong>rnet source address */<br />

memset(e<strong>the</strong>rhdr.e<strong>the</strong>r_dhost, 0xff, 6); /* E<strong>the</strong>rnet destination address */<br />

arphdr.ar_op = ARPOP_REQUEST; /* ARP opcode: request */<br />

arphdr.ar_hrd = ARPHRD_ETHER; /* hardware format: E<strong>the</strong>rnet */<br />

arphdr.ar_pro = ETHERTYPE_IP; /* protocol format: IP */<br />

arphdr.ar_hln = 6; /* 6 byte hardware addresses */<br />

arphdr.ar_pln = 4; /* 4 byte protocol addresses */<br />

memset(arphdr.ar_sha, 0, 6); /* ARP frame sender address */<br />

memset(arphdr.ar_spa, 0, 4); /* ARP sender protocol (IP) addr */<br />

memset(arphdr.ar_tha, 0, 6); /* ARP frame target address */<br />

memset(arphdr.ar_tpa, 0, 4); /* ARP target protocol (IP) addr */<br />

pd.file_mem = NULL;<br />

pd.file_s = 0;<br />

return;<br />

}<br />

Finally, <strong>the</strong> nemesis_arp() function calls <strong>the</strong> function buildarp() with<br />

pointers to <strong>the</strong> header data structures. Judging from <strong>the</strong> way <strong>the</strong> return value<br />

from buildarp() is handled here, buildarp() builds <strong>the</strong> packet and injects it.<br />

This function is found in yet ano<strong>the</strong>r source file, nemesis-proto_arp.c.<br />

From nemesis-proto_arp.c<br />

int buildarp(ETHERhdr *eth, ARPhdr *arp, FileData *pd, char *device,<br />

int reply)<br />

{<br />

int n = 0;<br />

u_int32_t arp_packetlen;<br />

static u_int8_t *pkt;<br />

struct libnet_link_int *l2 = NULL;<br />

/* validation tests */<br />

246 0x400

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

Saved successfully!

Ooh no, something went wrong!