hi@hectortoral.com

6 min read

Tcpdump

CommandDescription
tcpdump --versionPrints the tcpdump and libpcap version strings then exits.
tcpdump -hPrints the help and usage information.
tcpdump -DPrints a list of usable network interfaces from which tcpdump can capture.
tcpdump -i (interface name or #)Executes tcpdump and utilizes the interface specified to capture on.
tcpdump -i (int) -w file.pcapRuns a capture on the specified interface and writes the output to a file.
tcpdump -r file.pcapTCPDump will read the output from a specified file.
`tcpdump -r/-w file.pcap -l \grep ‘string’`
tcpdump -i (int) host (ip)TCPDump will start a capture on the interface specified at (int) and will only capture traffic originating from or destined to the IP address or hostname specified after host.
tcpdump -i (int) port (#)Will filter the capture for anything sourcing from or destined to port (#) and discard the rest.
tcpdump -i (int) proto (#)Will filter the capture for any protocol traffic matching the (#). For example, (6) would filter for any TCP traffic and discard the rest.
tcpdump -i (int) (proto name)Will utilize a protocols common name to filter the traffic captured. TCP/UDP/ICMP as examples.

Tcpdump Common Switches and Filters

Switch/FilterDescription
DWill display any interfaces available to capture from.
iSelects an interface to capture from. ex. -i eth0
nDo not resolve hostnames.
nnDo not resolve hostnames or well-known ports.
eWill grab the ethernet header along with upper-layer data.
XShow Contents of packets in hex and ASCII.
XXSame as X, but will also specify ethernet headers. (like using Xe)
v, vv, vvvIncrease the verbosity of output shown and saved.
cGrab a specific number of packets, then quit the program.
sDefines how much of a packet to grab.
Schange relative sequence numbers in the capture display to absolute sequence numbers. (13248765839 instead of 101)
qPrint less protocol information.
r file.pcapRead from a file.
w file.pcapWrite into a file
hostHost will filter visible traffic to show anything involving the designated host. Bi-directional
src / destsrc and dest are modifiers. We can use them to designate a source or destination host or port.
netnet will show us any traffic sourcing from or destined to the network designated. It uses / notation.
protowill filter for a specific protocol type. (ether, TCP, UDP, and ICMP as examples)
portport is bi-directional. It will show any traffic with the specified port as the source or destination.
portrangePortrange allows us to specify a range of ports. (0-1024)
less / greater "< >"less and greater can be used to look for a packet or protocol option of a specific size.
and / &&and && can be used to concatenate two different filters together. for example, src host AND port.
oror Or allows for a match on either of two conditions. It does not have to meet both. It can be tricky.
notnot is a modifier saying anything but x. For example, not UDP.

TShark

CommandDescription
tshark -hPrints the help menu.
tshark -DList available interfaces to capture from.
tshark -i (int)Capture on a selected interface. Replace (int) with the interface name or number.
tshark -i eth0 -f "host (ip)"apply a filter with (-f) looking for a specific host while utilizing tshark
DWill display any interfaces available to capture from and then exit out.
LWill list the Link-layer mediums you can capture from and then exit out. (ethernet as an example)
ichoose an interface to capture from. (-i eth0)
fpacket filter in libpcap syntax. Used during capture.
cGrab a specific number of packets, then quit the program. Defines a stop condition.
aDefines an autostop condition. It can be after a duration, specific file size, or after a certain number of packets.
r (pcap-file)Read from a file.
W (pcap-file)Write into a file using the pcapng format.
PWill print the packet summary while writing into a file (-W)
xwill add Hex and ASCII output into the capture.
hSee the help menu

WireShark

Capture FilterDescription
host x.x.x.xCapture only traffic pertaining to a certain host
net x.x.x.x/24Capture traffic to or from a specific network (using slash notation to specify the mask)
src/dst net x.x.x.x/24Using src or dst net will only capture traffic sourcing from the specified network or destined to the target network
port #will filter out all traffic except the port you specify
notwill capture everything except the variable specified. ex. not port 80
andAND will concatenate your specified ports. ex. host 192.168.1.1 and port 80
portrange x-xPortrange will grab traffic from all ports within the range only
ip / ether / tcpThese filters will only grab traffic from specified protocol headers.
broadcast / multicast / unicastGrabs a specific type of traffic. one to one, one to many, or one to all.
Display FilterDescription
ip.addr == x.x.x.xCapture only traffic pertaining to a certain host. This is an OR statement.
ip.addr == x.x.x.x/24Capture traffic pertaining to a specific network. This is an OR statement.
ip.src/dst == x.x.x.xCapture traffic to or from a specific host.
dns / tcp / ftp / arp / ipfilter traffic by a specific protocol. There are many more options.
tcp.port == xfilter by a specific tcp port.
src.port / dst.port ==xwill capture everything except the port specified.
and / or / notAND will concatenate, OR will find either of two options, NOT will exclude your input option.
tcp.stream eq #Allows us to follow a tcp session in which we captured the entire stream. Replace (#) with the session to reassemble.
httpWill filter for any traffic matching the http protocol.
http && image-jfifThis filter will display any packet with a jpeg image file.
ftpFilters for the ftp protocol.
ftp.request.commandWill filter for any control commands sent over ftp control channel.
ftp-dataWill show any objects transfered over ftp.

Misc Commands

CommandDescription
sudo *Sudo will run the command that proceeds it with elevated privileges.
which (application)Utilizes which to determine if (application) is installed on the host. Replace the application with what you are looking for. ex. which tcpdump
sudo apt install (application)Uses elevated privileges to install an application package if it does not exist on the host. ex. sudo apt install wireshark
man (application)Displays the manual pages for an application. ex. man tcpdump.

Common Ports and Protocols

Port NumberProtocolDescription
20FTP-DataData channel for passing FTP files.
21FTP-CommandControl channel for issuing commands to an FTP server.
22SSHSecure Shell Service port. Provides secure remote communications
23TelnetTelnet service provides cleartext communications between hosts.
25SMTPSimple Mail Transfer protocol. Utilized for email transmissions between servers.
53DNSDomain Name Services. Provides name resolution with multiple protocols
69TFTPTrivial File Transfer Protocol. A lightweight, minimal-function transfer protocol.
80HTTPHyperText Transfer Protocol. Provides dynamic web services
88KerberosProviding cryptographic network authentication
110POP3Mail service utilized by clients to retrieve email from a server.
111RPCRemote Procedure Call. Remote service for managing network file systems.
115SFTPSSH File Transfer Protocol. An extension of SSH providing secure and reliable FTP services.
123NTPNetwork Time Protocol. Provides timing and sync services for network devices.
137Netbios-NSLocal network name resolution.
139Netbios-SSNProvides session services for data transfer. Services like SMB can utilize it.
179BGPBorder Gateway Protocol. BGP is a protocol for exchanging routing info with autonomous systems worldwide.
389LDAPLightweight Directory Access Protocol. System agnostic authentication and authorization services.
443HTTPSHyperText Transfer Protocol Secure. An extension of HTTP utilizing SSL/TLS for encrypting the communications.
445SMBServer Message Block. SMB allows for the sharing of services, files, networking ports, and printers between hosts.