Packet Sniffing and Spoofing Lab - Final
Packet Sniffing and Spoofing Lab - Final
2) Initialize Sniffing.
Here in this step, after setting up a device for sniffing , sniffer Initialize PCAP and tell it to sniff on a particular device to create an environment for sniffing called as a session. Even sniffing on multiple devices or interfaces or even multiple sniffing on a single device is possible and are managed as sessions for sniffing, One for each device.
3) Traffic Filtering.
For every session of sniffing you create you have to define any desire or rule, upon which packets are to be sniffed and analyzed. For example if you want to sniff HTTP traffic on a specific Interface of your computer , you will sniff TCP port 80 traffic on that interface (since http traffic uses port80), you will write your requirement in filter string and then compile it to apply the rule. This is called filtering and it is possible to use a blank filter but in that case it will be sniffing all packets and will be analyzing all fields.
Problem 2:
Why do you need the root privilege to run sniffex? Where does the program fail if executed without the root privilege?
Solution:
Pcap_lookupdev() function needs root access because it wants to access network interfaces and it is impossible without root access in linux. Sniffer programs need raw sockets that allow direct sending of packets by the applications bypassing all applications in network software of operating system. And we need to be a root to create raw socket as we cant discover NIC until we are root.
Problem 3:
Please turn on and turn off the promiscuous mode in the sniffer program. Can you demonstrate the difference when this mode is on and off? Please describe how you demonstrate this.
Solution:
In really simple words promiscuous mode is one in which all the packets are sent to a computer or
sniffed by sniffer and not only those which are addressed to it whereas in a non promiscuous mode only those packets are send to the computer or sniffed by sniffer which are addressed to it. For demonstration lets consider a scenario where we have twovirtual machines, say A and B , with sniffex running on A and B tries to ping a random IP address. Now in non promiscuous mode I found that no packet is sniffed at A other then those with destination address of A as shown below.
Now for the promiscuous mode, when I did same that is pinged a random IP from B , I could see some packets being received at A which were not meant for A. this could be clear from the pictures
Problem 4:
Please write filter expressions to capture each of the followings. In your lab reports, you need to include screen dumps to show the results of applying each of these filters. _ Capture the ICMP packets between two specific hosts. _ Capture the TCP packets that have a destination port range from to port 10 - 100.
Solution:
A. To Capture the ICMP packets between two specific hosts I used following filter expression.
B -To Capture the TCP packets that have a destination port range from to port 10 100.
To capture Packets within TCP port range from 10-100, I applied following filter
Problem 5:
Please show how you can use sniffex to capture the password when somebody is using telneton the network that you are monitoring. You may need to modify the sniffex.c a little bitif needed. You also need to start the telnetd server on your VM if you have not done so as alreadyinstructed above.
Solution:
Here we take two machines say A and B, when say A try to telnet to B on port 23, B asked A for login credentials. Now for connecting to B, when machine A enters login and password they can be captured with the help of a sniffer in the Network... sign at the end shows the password is completely sent now. Below figure shows that when B asked A to enter password it was sent character by character and was caught by the sniffer in the middle.
Solution:
Four necessary library calls in spoofing are 1. 2. 3. 4. Create a raw socket. Set socket opinion. Construct the packet. Send out the packet through the raw socket.
1 Creating Raw sockets and setting socket options Raw sockets are sockets that allow direct sending of packets by the applications bypassing all applications in network software of operating system. For spoofing the first and most important step is creating raw sockets that would help the program in injecting packets in the network. The basic concept of low level sockets is to send a single packet at one time, with all the protocol headers filled in by the program (instead of the kernel). UNIX provides two kinds of sockets that permit direct access to the network. One is SOCK_PACKET, which receives and sends data on the device link layer. This means, the NIC specific header is included in the data that will be written or read. For most networks, this is the Ethernet header. Of course, all subsequent protocol headers will also be included in the data. The socket type we'll be using, however, is SOCK_RAW, which includes the IP headers and all subsequent protocol headers and data. The (simplified) link layer model looks like this: Physical layer -> Device layer (Ethernet protocol) -> Network layer (IP) Transport layer (TCP, UDP, ICMP) -> Session layer (application specific data) Now to some practical stuff. A standard command to create a datagram socket is: socket (PF_INET, SOCK_RAW, and IPPROTO_UDP); from the moment that it is created, we can send any IP packets over it, and receive any IP packets that the host received after that socket was created if we read () from it. Note that even though the socket is an interface to the IP header, it is transport layer specific. That means, for listening to TCP, UDP and ICMP traffic, we have to create 3 separate raw sockets, using IPPROTO_TCP,IPPROTO_UDP and IPPROTO_ICMP (the protocol numbers are 0 or 6 for TCP, 17 for UDP and 1 for ICMP). 2 Constructing the header for the different protocols IP, ICMP, TCP and UDP To inject our own packets, all we need to know is the structures of the protocols that need to be included. Below defined structures of IP, ICMP, TCP and UDP headers. The data types/sizes we need to use are: Unsigned char - 1 byte (8 bits), unsigned short int - 2 bytes (16 bits) and unsigned int - 4 bytes (32 bits).
Problem 7:
Why do you need the root privilege to run the programs that use raw sockets? Where does the program fail if executed without the root privilege?
Solution:
Generally, you need root permissions to receive raw packets on an interface. This restriction is a security precaution, because a process that receives raw packets gains access to communications of all other processes and users using that interface. When a normal user sends out a packet, operating systems usually do not allow the user to set all the fields in the protocol headers (such as TCP, UDP, and IP headers). OSes will set most of the fields, while only allowing users to set a few fields, such as the destination IP address, and the destination port number, etc. However, if the user has the root privilege, he/she can set any arbitrary field in the packet headers. This is essentially packet spoofing, and it can be done through raw sockets. A normal no-privileged user cannot create sockets whereas for spoofing purposes we not only need to create data packets but need raw sockets for the purpose of injecting our created packets into the network and these raw sockets are to be created by us. So this is the point where the program will fail if we run it as a non privileged user because we wont be able to create raw sockets using the program. Thus we need root access for running this program as spoofing is impossible without raw sockets and these raw sockets are impossible without root privileges.
Solution:
Here is a ping program which ping's a host and a sniffing program with spoofing facility. Basically my spoof program sniff an ICMP request packet on the network and make a ICMP reply packetand send it to the source of the ICMP request packet. My spoof program given below:
"Sniffex" "Sniffer example using libpcap" "Copyright (c) 2005 The Tcpdump Group"
#define APP_COPYRIGHT
/*#include <pcap.h>*/ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <linux/ip.h> #include <linux/icmp.h> #include <string.h> #include <unistd.h>