Tcpdump
Basic Commands
Capture packets on a specific interface:
tcpdump -i eth0Capture only a specific number of packets:
tcpdump -c 10Write capture to a file:
tcpdump -w capture.pcapRead packets from a file:
tcpdump -r capture.pcap
Filtering Options
Filter by host:
tcpdump host 192.168.1.1Filter by source IP:
tcpdump src 192.168.1.1Filter by destination IP:
tcpdump dst 192.168.1.1Filter by port:
tcpdump port 80Filter by source port:
tcpdump src port 80Filter by destination port:
tcpdump dst port 80Filter by protocol:
tcpdump tcp tcpdump udp
Advanced Filtering
Capture only TCP packets with a specific flag:
Capture packets larger than a specific size:
Capture packets with a specific string in the payload:
Display Options
Verbose output:
More verbose output:
Most verbose output:
Print in ASCII:
Print in HEX and ASCII:
Time Options
Capture packets for a specific duration:
Add timestamp to output:
Extracting Files (Images, Videos, Docs)
Capture packets and save to a file:
Use
tcpflowto reconstruct the TCP stream:This will create files in the format of
192.168.1.1.00080-192.168.1.2.12345representing the data flow between these IPs and ports.Identify and extract files:
Images: Identify JPEG, PNG, or other image file signatures (e.g., JPEG starts with
\xff\xd8and ends with\xff\xd9).Videos: Look for video file signatures (e.g., MP4 files start with
ftyp).Documents: Identify document file signatures (e.g., PDF files start with
%PDF).
Reassemble files: Use a hex editor like
xxdorblessto cut the identified bytes and save them as separate files. For example, to extract a JPEG image:Verify and open the extracted files: Open the extracted files using appropriate viewers to verify their integrity.
Additional Tools
Scapy: Python library to read, write, and manipulate pcap files.
Wireshark: GUI-based tool to analyze pcap files and extract objects directly.
Open the pcap file in Wireshark.
Go to
File -> Export Objects -> HTTP(or other relevant protocol).
By using these commands and techniques, you can effectively utilize tcpdump for network analysis and extract various types of files from captured network traffic.
Last updated
Was this helpful?