Monday, March 22, 2010

Spying on my cofee shop-mates with WireShark


Stephen Castaneda
Week 2 homework, Packet Sniffer
When I first started using Linux, if one wanted to install some software, in this case a packet sniffer, one would usually search the Internet. A Redhat user might Google “packet sniffer” filetype:rpm, go to the project's homepage to find the download and cross your fingers in hope that the software is useful, documented, and not a trojan. Now, all the major distribution families (Debian, Redhat, or Slackware) have software repositories which at least address the issues of software usefulness and trustworthiness. All code that makes it into the repositories is very well screened, but user-level documentation is still notoriously weak with most open-source software.
Possibly the best thing about the repositories is the ease with which one can install any number of softwares at the same time. I simply opened my software manager, named Synaptic, and typed “sniffer” into the search field. It returned 32 different packet sniffers, some with redundant functionality, others rather unique. For instance, darkstat runs as a background process and generates HTML reports served by a lightweight HTTP daemon, prismstumbler is for sniffing 802.11b wireless signals, and snort is a sniffer that matches traffic against known attack signatures to form a comprehensive, yet lightweight intrusion detection system. I installed a few different ones to try out, and ultimately decided on using WireShark for this lab, partly because I've heard of it's parent software, Ethereal, and because it also runs on Windows and Mac platforms.
Again, installation difficulty was zero – I simply checked the boxes next to the sniffers I wanted to install then clicked “Apply.” The software manager downloaded and installed the software then opened a window with a list of the changes from which I could even double-click to start up any of the programs. I clicked to open WireShark, but it opened with user level privileges, meaning I could pretty much only open existing logs. Users don't have the necessary raw access to the system's interfaces. I closed the software and reopened it with root privileges, and was good to go. The welcome screen presents three columns, a list of the machine's interfaces, an open/open recent scan area, and some links to the user guide, the project's web site, and some specific articles, including tips on using the software as securely as possible.
Even before reading the security wiki, I stumbled upon a security concern. When I clicked one of the web links on the welcome page, it opened a browser window as the user who started started the WireShark process, in this case root. I referenced my process list, and confirmed an instance of Firefox running as root. This is undesirable because if I were to browse onto some malware, it would have the run of the place, so to speak. I voluntarily renounced my powers, closed the browser, and re-navigated to the project's home page as a lowly user.
I'm the type who, when I get a new toy, I prefer to learn about it by playing with it, only resorting to the manual when I feel my curiosity has reached it's limits and I need to read some to unlock all the capabilities. Simply clicking an interface from the list begins capturing packets on that interface. This happened much faster than I was expecting. I found myself overloaded with data, and nearly resorted to reading the manual. But the people at WireShark have people like me covered with an enormous page full of sample captures of almost any type imaginable. I downloaded one labeled “a simple HTTP request and response,” and started nosing around.
The interface showed three horizontal windows stacked on top of each other. The top window contained a numbered list of packets ordered by increasing time, starting at t = 0, measured to microsecond precision. The list also included source and destination IP address, protocol, and an “info” field. The next horizontal window showed more detailed information on the specific packet selected from the ordered list. The info was organized in a drop-down menu format with either four or five top-level information fields. More on this in a moment. Finally, the third window showed the selected packet's raw hexadecimal data, along with the application's best effort to translate the data into readable text.
This particular conversation consisted of 43 packets. The first three showed the telltale signs of the TCP three-way handshake. The client sends a SYN packet with a seq value of x, then the server responds with a SYN-ACK with a seq value of y and an ack value (x + 1). Finally, the client responds with an ACK packet, seq = (x + 1), ack = (y + 1). The next packet is an HTTP GET from the client. Now is a good time to discuss the packet info window in depth. A TCP packet has four top-level information drop-downs. The first gives information on the packet in general, or more specifically, the frame. This is info such as arrival time, frame length, all the protocols in the frame (in this case, Ethernet, IP, and TCP), and the rule that the sniffing software used to color-code the packet in the list. In this case, the coloring rule was “HTTP” even though it wasn't technically an HTTP packet, it gets colored green like all HTTP communications. Other colors include blue for DNS packets and black for “bad” TCP packets. The following three informational drop-downs each correspond to a one of the protocols in the packet, and effectively give information on layers two, three, and four of the OSI model. First comes Ethernet info, such as MAC address (the software even attempts to look up the manufacturer). Next is IP info including, address, header length, and encapsulated protocol (TCP). Finally is the TCP data. This includes source and destination port, sequence number, the SYN/ACK/etc. flags, and header length. On HTTP packets, there is another drop-down with info specific to the HTTP communication. The client sends information like browser and operating system IDs, which media types it will accept, which human languages, and which character sets. The server sends info such as the HTTP version and the server, in this case, Apache. Finally, on the packets from the server, there is a sixth info drop-down that contains the actual data intended for the application. The lab instructs us not to look at the data, but since this is just a sample capture from the software project's website, I took a peek. It appears to be the HTML code for the WireShark download page, including all the various mirrors.
So off to intercept some real communications. Once upon a time, I would have had no problem getting on any number of unsecured wireless connections in my neighborhood. I was somewhat pleasantly surprised to find that is no longer the case. I tried moving around my house, and in different areas, I was able to pick up different networks, but none of them were unsecured. A big congratulations to my neighbors on this. So I packed up and went down to my local coffee shop. I settled in with some Joe, powered up my machine, and started capturing on my wlan0 interface.
The data that started pouring in was incredible. I figured I could snoop on someone else's DNS requests without breaching too much trust. Here was someone surfing FaceBook. Here was someone else, presumably a student, on the Colorado State University. A bit more research and I learn that person is logged into their online courses. Finally, I examined a packet that was a network time protocol update to a Macintosh. All in all, this lab was highly educational and really fun to do.

No comments: