Wednesday, July 23, 2014

Capturing network packets using "tcpdump"

tcpdump is used for packet analyzer which allows the user to intercept and display TCP/IP and other packets being transmitted or received over a network to which the computer is attached.

Installation of tcpdump on Solaris/Linux:
   pkgutil is similar utility for Solaris compared to yum in Linux and apt-get in Ubuntu.
First let's install pkgutil using following command:
   /usr/sfw/bin/wget http://mirror.opencsw.org/opencsw/pkgutil.pkg
   pkgutil install at /opt/csw/bin/pkgutil on Solaris

Use below command to install tcpdump on Solaris:
pkgutil -i coreutils [This installs tcpdump at /usr/sbin/tcpdump]


Usage of tcpdump:
    tcpdump -w [output-file]  -i  [physical-interface] port [port]
    I noticed that capturing of the packets is only limited to 96 bytes. Checking manual of tcpdump I found that there is an option to disable the 96 bytes limitation by using the option "-s 0".  
Use the following command to capture 65535 bytes of packets.
    tcpdump -w [output-file] -i [physical-interface] port [port] -s 0

Example: tcpdump -w p001.pcap -i eth0 port 8080 -s 0
The above command captures any packet transfered on "physical-interface" on port 8080.

Analysis:
   The output file can be analyzed using "Wireshark" GUI application available for free.