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.

0x0020 8018 438a 4c8c 0000 0101 080a 0007 1feb ..C.L...........<br />

0x0030 000e 10d1 3233 3020 5573 6572 206c 6565 ....230.User.lee<br />

0x0040 6368 206c 6f67 6765 6420 696e 2e0d 0a ch.logged.in...<br />

Data transmitted over <strong>the</strong> network by services such as telnet, FTP, and<br />

POP3 is unencrypted. In <strong>the</strong> preceding example, <strong>the</strong> user leech is seen logging<br />

into an FTP server using <strong>the</strong> password l8@nite. Since <strong>the</strong> au<strong>the</strong>ntication process<br />

during login is also unencrypted, usernames and passwords are simply<br />

contained in <strong>the</strong> data portions <strong>of</strong> <strong>the</strong> transmitted packets.<br />

tcpdump is a wonderful, general-purpose packet sniffer, but <strong>the</strong>re are<br />

specialized sniffing tools designed specifically to search for usernames and<br />

passwords. One notable example is Dug Song’s program, dsniff, which is<br />

sm<strong>art</strong> enough to parse out data that looks important.<br />

reader@<strong>hacking</strong>:~/booksrc $ sudo dsniff -n<br />

dsniff: listening on eth0<br />

-----------------<br />

12/10/02 21:43:21 tcp 192.168.0.193.32782 -> 192.168.0.118.21 (ftp)<br />

USER leech<br />

PASS l8@nite<br />

-----------------<br />

12/10/02 21:47:49 tcp 192.168.0.193.32785 -> 192.168.0.120.23 (telnet)<br />

USER root<br />

PASS 5eCr3t<br />

0x441<br />

Raw Socket Sniffer<br />

So far in our code examples, we have been using stream sockets. When<br />

sending and receiving using stream sockets, <strong>the</strong> data is neatly wrapped in a<br />

TCP/IP connection. Accessing <strong>the</strong> OSI model <strong>of</strong> <strong>the</strong> session (5) layer, <strong>the</strong><br />

operating system takes care <strong>of</strong> all <strong>of</strong> <strong>the</strong> lower-level details <strong>of</strong> transmission,<br />

correction, and routing. It is possible to access <strong>the</strong> network at lower layers<br />

using raw sockets. At this lower layer, all <strong>the</strong> details are exposed and must be<br />

handled explicitly by <strong>the</strong> programmer. Raw sockets are specified by using<br />

SOCK_RAW as <strong>the</strong> type. In this case, <strong>the</strong> protocol matters since <strong>the</strong>re are multiple<br />

options. The protocol can be IPPROTO_TCP, IPPROTO_UDP, or IPPROTO_ICMP. The<br />

following example is a TCP sniffing program using raw sockets.<br />

raw_tcpsniff.c<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include "<strong>hacking</strong>.h"<br />

int main(void) {<br />

int i, recv_length, sockfd;<br />

226 0x400

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

Saved successfully!

Ooh no, something went wrong!