How to Spy on Your "Buddy's" Network Traffic: An Intro to Wireshark and the OSI Model « Null Byte :: WonderHowTo

Wouldn't it be nice to just sit at your buddy's house, plug into his network, and see exactly what he's doing? What if itwasas easy as that? What makes packet sniffers likeWiresharksuch potent tools is that a majority of local area networks (LANs) are based on the shared Ethernet notion.In a shared Ethernet, you can think of all of the computers in a LAN as being plugged into the same wire, and all of the traffic that travels through it can be captured. Packet sniffers are more formally known as network analyzers and protocol analyzers. But what traffic are we talking about?Everything. Grantedencrypted datawill be unreadable to you, you can still see it, and anything that is sent plain text (not encrypted) can be grabbed very easily. This includes passwords, logins, instant messaging conversations, emails, etc.Everything.For example, assume thatyournetwork card picks up a packet fromsomeone else'snetwork. Normally, once the packet is handed off, the operating system must determine exactly what type of packet it is. To do so, it strips off the Ethernet header of the packet and looks at the next layer. Perhaps it's an IP packet.. Well, the OS must now strip of the IP header and determine which type of IP packet it is. Finally, let's say it's determined that the packet is aUDPpacket. The UDP header is stripped off and the packet payload (the data) is handed over to the application that the packet was sent to.Now, thisisan oversimplified version of what really goes on, but I'm trying to illustrate a point. Packet capture allows us to intercept any packet that is seen by the network device, and grab it in its entirety, headers and all. Regardless of which port is being sent to, or even which host, for that matter.Before we get into grabbing frames and causing mayhem for lulz, we need to explain what a packet is and the concept of a frame. I believe knowing how something works is much better than just learning to do it, so let's dive into some networking!The Open Source Interconnection (OSI) ModelThe OSI model is a layered model that describes how information moves from an application running on one networked computer to an application running on another networked computer. Think of it this way, the OSI model describes the steps to be used to transfer data from one networked device to another. Easy.The model is divided into seven layers, as shown below. If you are serious about learning networking and information security, my advice is to memorize this image. I know it looks long and complicated at first, and trust me it is. But the more you use this (and you will) the faster it will come to you.The reason for using a layered networking approach is that a layered model takes a task, such as data communications, and breaks it into a series of tasks, activities or components, each of which is defined and developed independently. OSI layers also allow extensibility. New protocols and other network services are generally easier to add to a layered architecture.The basic idea behind the OSI reference model is this—Each layer is in charge of some kind of processing and each layer only talks to the layers immediately below and above it.For example, the sixth layer will only talk to the seventh and fifth layers, and never directly with the first layer. Remember this and it gets easy.When your computer is transmitting data to the network, one given layer will receive data from the layer above, process what it received, add some control information to the data that this particular layer is in charge of, and send the new data with this new control information added to the layer below.When your computer is receiving data, the contrary process will occur. One given layer will receive data from the layer below, process what it received, remove control information from the data that this particular layer is in charge of, and send the new data without the control information to the layer above.What's important to keep in mind is that each layer will add or remove control information that it is in charge of. An acronym to help remember the model from bottom to top is "Please Do Not Throw Sausage Pizza Away."Layer 1: PhysicalThe physical layer describes the physical medium that data travels through. ThinkEthernet cables,Network Interface Controllers, and things of the like. It also provides the interface between network and network communication devices.Layer 2: DatalinkThe datalink layer is where the network packets are translated into raw bits (00110101) to be transmitted on the physical layer. This is also a layer that uses the most basic addressing scheme,MediaAccessControladdresses. Think of a MAC address like a diver's license number—it's just a number that is unique from anyone else's.Now, think of an IP address like a person's mailing address. The mailing address groups people into zones by using the zip code, city, state, and street identifiers.Summary of Layer 1 and 2When a network card receives a stream of bits over the network, it receives the data from the wires (the first layer), then the second layer is responsible for making sense of these 1s and 0s. The second layer first checks the destination MAC address in the frame to make sure the data was intended for that computer. If the destination MAC address matches the MAC address of the network card, it carries on.Layer 3: NetworkThe network layer determines how data transmits between network devices. It also translates the logical address into the physical address (computer name into MAC address). It's also responsible for defining the route, managing network problems, and addressing. Routers also work on the network layer.The most important part of understanding this third layer is knowing that routers make decisions based on layer three's information. Routers are machines that decide how to send information from one logical network to another. Routers understand the Internet Protocol (IP) and base routing decisions on that information.Layer 4: TransportThe transport layer accepts data from the session layer and breaks it into packets and delivers these packets to the network layer. It's the responsibility of the transport layer to guarantee successful arrival of data at the destination device.Transport Layer Securityalso runs on this layer.Layer 5: SessionThe session layer manages the setting up and taking down of the association between two communicating end points, called a connection. A connection is maintained while the two end points are communicating back and forth.Another way to look at it—picture your computer. You're browsing the web, downloading from anFTP server, streaming some music, and who knows what else, all at the same time. All that data is coming into your computer, but it would make little sense if the FTP data was being sent to yourPandoratab, wouldn't it? It's in this layer thatportsare used and that data is properly directed.Layer 6: PresentationThe presentation layer resolves differences in data representation by translating from application to network format, and vice versa. It works to transform data into the form that the application layer can accept. Remember, each layer can only 'talk' to the layer above and below it.This layer is mainly concerned with the syntax and semantics of the information transmitted. For outgoing messages, it converts data into a generic format for the transmission. For the incoming messages, it converts the data to a format understandable to the receiving application. This layer also formats and encrypts data to be sent across a network, providing freedom from compatibility problems and issues.Layer 7: ApplicationThe application layer is the top layer of the model. It provides a set of interfaces for applications to obtain access to networked services. This layer also provides application access security checking and information validation.Common services that will seem familiar include streaming music, email, and online games. When you think of the application layer, think of just that—applications.Let's Steal Some Data!Now that we have a grasp on the OSI model, we want to get intoWireshark. If you're runningBackTrack, you already have this set up in your /pentest directory. Otherwise, let's go ahead and grab the packages. If you want the latest version of 1.6.5, you must download and compile the source code. If you don't mind the older 1.6.2 version, you can use the repositories. In this case, I recommend the repos if you feel shy about compiling from source and handling dependencies. If you want the bleeding edge, grab the source. As of this writing, it's a small difference.Free BSDusers can type:$ sudo pkg_add -r wiresharkDebian-based systems can type:$ sudo apt-get install wiresharkArchusers can type:$ sudo pacman -S wireshark-gtkIf you do wish to compile from source, follow along below:Step1Get All The Required PackagesMake a new temporary directory, because we're going to download some files. Wireshark also requireslibpcap,glib, andGTK+as dependencies. Backtrack users should again be good to go, but others might need to get these packages first.Download the source code withWgetand compile it up.$ wget http://www.tcpdump.org/release/libpcap-1.2.1.tar.gz$ wget http://ftp.gnome.org/pub/gnome/sources/glib/2.30/glib-2.30.2.tar.bz2$ wget http://ftp.gnome.org/pub/gnome/sources/gtk+/3.2/gtk+-3.2.2.tar.bz2Windows users can grab the32-bitand64-bitversions of Wireshark. Linux users can simply retrieve the source code by typing:$ wget http://wiresharkdownloads.riverbed.com/wireshark/src/wireshark-1.6.5.tar.bz2Step2Build and Install the DependenciesUntar each package you downloaded, then move into the new expanded directory and type the following for each:$ ./configure$ sudo make$ sudo make installStep3Build and Install WiresharkNow we can get to installing our network protocol analyzer, Wireshark. If you have any issues or problems at this stage with dependencies, check out thishelpful link.To get started, let's type:$ tar xvjf wireshark-1.6.5.tar.bz2 && cd wireshark-1.6.5$ ./configure$ sudo make$ sudo make installStep4Configure, Capture and ConquerNow that we have everything up and running, let's go ahead and fire up Wireshark. We should be greeted with the following screen:You'll see a section titledCapture Help—I highly encourage first time users to give it a whirl. Also notice that if you had captured packets on another computer, you could import that file into Wireshark for analysis, as well.UnderCapture, it lists all the interfaces on your system Wireshark can use to listen in on. /dev/eth1 is my wireless interface, so let's click on that.Here, we listened in on the interface only for a few seconds and picked up 24 packets. The first column lists thepacket number, ordered in how they were received. The next column lists the time in seconds, which began when Wireshark started that session.Source and DestinationTheSourceandDestinationcolumns list the addresses contained in the header. You will notice packets that are addressed for you will show your internal IP address. This is because right now we are listening to the wireless traffic inside a network and as such, are behind the router. Packets coming to the receiving computer have already been stripped of the network IP address by the router. Remember how each layer of the OSI model can only talk to the layers above and below? That's because as the data travels up and down the layers, the control info is added to it, and stripped off as it passes.Next to that lists theProtocolof the packets received. Notice in the image where it saysTLSv1andEncrypted Alertin the info status? TLS stands for Transport Layer Security and if you remember from above, it runs on the transport layer.Packet OverviewUnder that lies an overview of the packet, giving you details such as size and what ports it was addressed to. Click on one of the entries and move your keyboard arrows up and down. See how the highlighted block of jumbled letters and numbers moves along with it? All those jumbled letters and numbers are actuallyhexadecimalcode, and next to it is a quick decoded overview of the data. If items are being transmitted encrypted, then this won't be enough yet, but anything sent plain text will show up here.In ActionHere, I opened my browser and typed www.google.com into the bar. As I briefly explained in mydarknet article, your computer sends a request to aDNS serverto find out the IP associated with google.com. The server then returns the address back to you and your browser connects to it. We can see this in action by sniffing the traffic as it happens.Here you can see the protocol isDNS. The first packet is querying the server and the second packet is responding.In ClosingWhew, that was a long read, but hopefully it was full of good knowledge. Sniffing traffic is useful for a multitude of reasons, from protecting your network from leaks by testing it out, to peeking at data that was not meant for your eyes. Next week, we'll get into advanced capturing of wireless packets, and dig into Wireshark a little more deeper.More importantly than that, you have a good intro to the OSI Model in your mind. I cannot stress enough that understanding this concept will help you later on down the road.Do you have questions? Comments? Concerns? Leave a comment, shoot mea message, orvisit our forum!Want to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicenseImages byEukHost,IebMedia,escotal,technobitez,paidContentRelatedHacker Fundamentals:A Tale of Two StandardsHow To:Spy on Traffic from a Smartphone with WiresharkHow To:Intercept Images from a Security Camera Using WiresharkNetworking Foundations:Exploring UDP via Wireshark(Part 1)Hacking macOS:How to Sniff Passwords on a Mac in Real Time, Part 2 (Packet Analysis)Hacker Fundamentals:The Everyman's Guide to How Network Packets Are Routed Across the WebMac for Hackers:How to Set Up a MacOS System for Wi-Fi Packet CapturingHack Like a Pro:Digital Forensics for the Aspiring Hacker, Part 2 (Network Forensics)How To:Securely Sniff Wi-Fi Packets with SniffglueHack Like a Pro:How to Spy on Anyone, Part 3 (Catching a Terrorist)How To:Intercept Security Camera Footage Using the New Hak5 Plunder BugHow To:Stealthfully Sniff Wi-Fi Activity Without Connecting to a Target RouterHow To:Hunt Down Wi-Fi Devices with a Directional AntennaHack Like a Pro:Digital Forensics for the Aspiring Hacker, Part 10 (Identifying Signatures of a Port Scan & DoS Attack)How To:Advanced System Attacks - Total GuideHow To:Play the intro to "That'll Be the Day" without a capoHow To:Identify Antivirus Software Installed on a Target's Windows 10 PCHow To:Use & Abuse the Address Resolution Protocol (ARP) to Locate Hosts on a NetworkNews:How to Study for the White Hat Hacker Associate Certification (CWA)How To:Use Wireshark to Steal Your Own Local PasswordsNews:8 Wireshark Filters Every Wiretapper Uses to Spy on Web Conversations and Surfing HabitsHow To:Get Free Wi-Fi from Hotels & MoreHow To:Spy on the Web Traffic for Any Computers on Your Network: An Intro to ARP PoisoningHow To:Networking Basics for the Aspiring HackerNews:Network Admin? You Might Become a Criminal SoonNews:Cool Runescape Buddy guyNews:Happy Birthday WakeupNews:Anonymity, Darknets and Staying Out of Federal Custody, Part Two: Onions and DaggersNull Byte:Never Let Us DieREVIEW:The EagleWeekend Homework:How to Become a Null Byte Contributor (2/24/2012)How To:Create an SSH Tunnel Server and Client in Linux