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.

data structures for <strong>the</strong> packet header information. The nemesis_arp() function<br />

shown below is called in nemesis.c to build and inject an ARP packet.<br />

From nemesis-arp.c<br />

static ETHERhdr e<strong>the</strong>rhdr;<br />

static ARPhdr arphdr;<br />

...<br />

void nemesis_arp(int argc, char **argv)<br />

{<br />

const char *module= "ARP/RARP Packet Injection";<br />

nemesis_maketitle(title, module, version);<br />

if (argc > 1 && !strncmp(argv[1], "help", 4))<br />

arp_usage(argv[0]);<br />

arp_initdata();<br />

arp_cmdline(argc, argv);<br />

arp_validatedata();<br />

arp_verbose();<br />

if (got_payload)<br />

{<br />

if (builddatafromfile(ARPBUFFSIZE, &pd, (const char *)file,<br />

(const u_int32_t)PAYLOADMODE) < 0)<br />

arp_exit(1);<br />

}<br />

}<br />

if (buildarp(&e<strong>the</strong>rhdr, &arphdr, &pd, device, reply) < 0)<br />

{<br />

printf("\n%s Injection Failure\n", (rarp == 0 ? "ARP" : "RARP"));<br />

arp_exit(1);<br />

}<br />

else<br />

{<br />

printf("\n%s Packet Injected\n", (rarp == 0 ? "ARP" : "RARP"));<br />

arp_exit(0);<br />

}<br />

The structures ETHERhdr and ARPhdr are defined in <strong>the</strong> file nemesis.h (shown<br />

below) as aliases for existing libnet data structures. In C, typedef is used to alias<br />

a data type with a symbol.<br />

From nemesis.h<br />

typedef struct libnet_arp_hdr ARPhdr;<br />

typedef struct libnet_as_lsa_hdr ASLSAhdr;<br />

typedef struct libnet_auth_hdr AUTHhdr;<br />

typedef struct libnet_dbd_hdr DBDhdr;<br />

Networking 245

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

Saved successfully!

Ooh no, something went wrong!