[Day 1] 6. TCPdump
1. About TCPDump
- TCPDump is a command-line packet capturing tool.
- It is considered the father of Wireshark but lacks a GUI.
Basic Commands in TCPDump
- : install
sudo apt-get install tcpdump.tcpdump - : Start capturing traffic on the default interface.
sudo tcpdump - : List available interfaces.
sudo tcpdump -D - : Capture packets on a specific interface (e.g.,
sudo tcpdump -i <interface>).ens33
2. Commands with Filters
TCPDump has only capture filters for limiting the type of packets being captured.
Common Filters:
-
Capture TCP packets:
bashsudo tcpdump -i ens33 tcp -
Capture UDP packets:
bashsudo tcpdump -i ens33 udp -
Capture a specific number of packets (e.g., 2):
bashsudo tcpdump -c 2 -
Capture packets without resolving names of the protocol:
bashsudo tcpdump -c 2 -n -
Write captured packets to a file:
bashsudo tcpdump -c 2 -w packets.txt -
Read packets from a file:
bashsudo tcpdump -r packets.txt
Advanced Filters:
-
Filter by host IP (both incoming and outgoing):
bashsudo tcpdump host <host_ip> -
Filter packets going to a specific destination IP:
bashsudo tcpdump dst <destination_ip> or sudo tcpdump dst host <destination_ip> -
Filter packets coming from a specific source IP:
bashsudo tcpdump src <source_ip> or sudo tcpdump src host <source_ip> -
Filter packets based on port:
bashsudo tcpdump port 22-
Source port only:
bashsudo tcpdump src port 22 -
Destination port only:
bashsudo tcpdump dst port 22
-
Complex Filters:
-
Capture TCP packets on port
with destination IPs80or192.168.1.254:192.168.1.200bashsudo tcpdump -i eth1 '((tcp) and (port 80) and ((dst host 192.168.1.254) or (dst host 192.168.1.200)))'
3. Snapshot Length (Snaplen)
-
Snapshot Length: is the amount of data for each frame that is actually captured by the network capturing tool and stored into the CaptureFile. This is sometimes called Packet Slicing.
-
Example Command:
bashsudo tcpdump -c 2 -xxe -s 4- : Displays packet headers and data in hexadecimal format.
-xx - : Prints link-level headers (e.g., MAC addresses).
-e - : Specifies the snapshot length.
-s <length>
4. Linux Commands
which
Command
which-
Used to check if a package is installed on the system.
-
Example:
bashwhich tcpdump
-
-
Important: Works on both Debian-based and RedHat-based distributions, unlike
, which is RedHat-specific.rpm
APT Configuration File: /etc/apt/sources.list
/etc/apt/sources.list-
Purpose: Stores configuration for APT (Debian package manager).
-
To add a local server repository:
textdeb [trusted=1] http://sunbeam.shuharilabs.com/sw/repo/deb12/ bookworm main- Explanation:
- : Indicates a Debian binary package repository.
deb - : Trusts the source to avoid signature verification errors.
[trusted=1] - : URL of the package repository.
http://sunbeam.shuharilabs.com/sw/repo/deb12/ - : Codename for the Debian distribution.
bookworm - : Category of the software.
main
- Explanation:
-
After modifying the file, update the APT catalog:
bashsudo apt-get updateThis needs to be done every time you make changes in the configuration file.
Debian Version Codes
- Debian releases are named with version codes (e.g., for Debian 12,
bookwormfor Debian 11).bullseye
5. Notes on Interfaces
- The default interface name () is now replaced with newer naming conventions like
eth0.ens33 - Use to specify your interface.
sudo tcpdump -i <interface> - Check the interfaces using this command first and then use the one you want:
shellsudo tcpdump -D
Read Next
[Day 1] 7. Extra
1. **Ping Command Behavior** - Using the `-c` flag in the `ping` command to limit the number of packets sent to the target IP. - In **Linux*...
[Day 2] 1. Overview of SNORT
### **Introduction to Intrusion Detection System (IDS)** - An **Intrusion Detection System (IDS)** monitors network traffic and allows only authori...