当前位置: 首页 > news >正文

tcpdump速查表

tcpdump 速查表

-D 列出网络设备

~]$ sudo tcpdump -D1.eth02.nflog (Linux netfilter log (NFLOG) interface)3.nfqueue (Linux netfilter queue (NFQUEUE) interface)4.any (Pseudo-device that captures on all interfaces)5.lo [Loopback]

-i 指定网卡

前面列出的设备可以用 -i dev 来指定抓对应网卡的数据包

-c 指定抓包数量

~]$ sudo tcpdump -i eth0 -c 3tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes03:38:41.388895 IP 13.248.125.132.37196 > ip-10-31-1-74.ap-southeast-1.compute.internal.10012: Flags [.], ack 3665636334, win 2014, options [nop,nop,TS val 1083056799 ecr 1675755283], length 003:38:41.389146 IP 99.82.173.66.58088 > ip-10-31-1-74.ap-southeast-1.compute.internal.10012: Flags [.], ack 978012266, win 2014, options [nop,nop,TS val 1031202901 ecr 3469957515], length 003:38:41.390227 IP 13.248.115.61.61524 > ip-10-31-1-74.ap-southeast-1.compute.internal.10012: Flags [P.], seq 2332145948:2332146170, ack 3523970401, win 2014, options [nop,nop,TS val 1454561556 ecr 1165926638], length 2223 packets captured100 packets received by filter9 packets dropped by kernel

-n 将域名解析为 IP

~]$ sudo tcpdump -i eth0 -c 3 -ntcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes03:41:34.332790 IP 13.248.98.123.58200 > 10.31.1.74.10012: Flags [P.], seq 106251671:106251871, ack 1748469091, win 2014, options [nop,nop,TS val 1392634401 ecr 817044617], length 20003:41:34.332957 IP 10.31.1.74.10012 > 13.248.98.121.9842: Flags [P.], seq 2880652137:2880652336, ack 1075202655, win 850, options [nop,nop,TS val 1486636778 ecr 1393164829], length 19903:41:34.332965 IP 10.31.1.74.10012 > 13.248.98.123.58200: Flags [P.], seq 420:619, ack 200, win 613, options [nop,nop,TS val 817044728 ecr 1392634401], length 1993 packets captured38 packets received by filter0 packets dropped by kernel

可以看到 ip-10-31-1-74.ap-southeast-1.compute.internal 这个域名被展示为 IP 10.31.1.74

-nn 可以将端口也展示为数字,默认情况下是会把端口展示为协议名称,例如 80 端口显示为 http

-s 限定抓包大小(capture size)

注意,这里不是筛选包大小,而是无论数据包多大,只截取指定的长度,单位是字节(bytes)。举例一个场景,如果只想看 header,就可以只要前 64 字节长度:

~]$ sudo tcpdump -i eth0 -c 3 -s 64tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on eth0, link-type EN10MB (Ethernet), capture size 64 bytes03:52:13.605359 IP 13.248.125.130.61304 > ip-10-31-1-74.ap-southeast-1.compute.internal.10012: Flags [.], ack 2139160988, win 2014, options [nop,nop,TS[|tcp]>03:52:13.609252 IP 13.248.98.123.remote-winsock > ip-10-31-1-74.ap-southeast-1.compute.internal.10012: Flags [.], ack 4105886282, win 2014, options [nop,nop,TS[|tcp]>03:52:13.609334 IP 13.248.115.67.9258 > ip-10-31-1-74.ap-southeast-1.compute.internal.10012: Flags [.], ack 3359161493, win 2014, options [nop,nop,TS[|tcp]>3 packets captured49 packets received by filter0 packets dropped by kernel

-w 另存为文件

b]$ sudo tcpdump -i eth0 -n -c 3 tcp "port 10012" -w 10012.pcaptcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes3 packets captured41 packets received by filter0 packets dropped by kernel

另存为 .pcap 文件,可以用 WireShark 打开,也可以直接用 tcpdump -r 打开。

当然,不想用 .pcap 格式的话,直接 > capture.txt 重定向到纯文本文件也是可以的。

筛选语法

host IP 筛选主机

~]$ sudo tcpdump -i eth0 -n -c 3 "host 10.31.1.8"
src host IP 筛选源主机
~]$ sudo tcpdump -i eth0 -n -c 3 "src host 10.31.1.8"
dst host IP 筛选目标主机
~]$ sudo tcpdump -i eth0 -n -c 3 "dst host 10.31.1.8"

注意,是 dst host 不是 dest host

net CIDR 筛选网络区间

源、目标网络依次类推

~]$ sudo tcpdump -i eth0 -n -c 3 "net 10.31.0.0/16"~]$ sudo tcpdump -i eth0 -n -c 3 "src net 10.31.0.0/16"~]$ sudo tcpdump -i eth0 -n -c 3 "dst net 10.31.0.0/16"

port PORT 筛选端口

源、目标端口依次类推

~]$ sudo tcpdump -i eth0 -n -c 3 "port 10012"~]$ sudo tcpdump -i eth0 -n -c 3 "src port 10012"~]$ sudo tcpdump -i eth0 -n -c 3 "dst port 10012"

tcp udp 筛选协议

~]$ sudo tcpdump -i eth0 -nn -c 3 tcp "port 10012"~]$ sudo tcpdump -i eth0 -n -c 3 udp

ip6 筛选 IPv6

~]$ sudo tcpdump -i eth0 -n -c 3 ip6tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes06:18:17.504845 IP6 fe80::48b:8dff:fe41:c1ce.dhcpv6-client > ff02::1:2.dhcpv6-server: dhcp6 solicit06:20:12.584991 IP6 fe80::48b:8dff:fe41:c1ce.dhcpv6-client > ff02::1:2.dhcpv6-server: dhcp6 solicit06:22:16.652850 IP6 fe80::48b:8dff:fe41:c1ce.dhcpv6-client > ff02::1:2.dhcpv6-server: dhcp6 solicit3 packets captured49 packets received by filter0 packets dropped by kernel

and or not 组合使用

~]$ sudo tcpdump -i eth0 -n -c 3 "src net 10.31.0.0/16 and (port 10012 or port 10013)"

参考资料

https://www.redhat.com/sysadmin/tcpdump-part-one

https://www.redhat.com/sysadmin/tcpdump-part-2

https://www.redhat.com/sysadmin/tcpdump-part-3

http://www.lryc.cn/news/348094.html

相关文章:

  • 单元测试与集成测试:软件质量的双重保障
  • 孙宇晨对话大公网:香港Web3政策友好环境示范意义重大
  • Python运维之多线程!!
  • milvus插入数据时,明明不超长,但总是报长度错误?
  • 怎么把图片大小缩小到1M?教你几招图片你压缩
  • python数据分析常见命令
  • 等保测评技术方案(五)
  • Redis缓存的基本概念和使用
  • MATLAB模拟退火算法、遗传算法、蚁群算法、粒子群算法
  • git自用随笔
  • CorelDRAW2024设计界的隐藏宝藏
  • 【JAVA】递归
  • MacOS java多版本安装与管理
  • NSSCTF | [LitCTF 2023]我Flag呢?
  • PostgreSQL-常用函数和操作符
  • 河南大学大礼堂火灾事故引发安防监控对智能分析技术应用的思考
  • 自动化中遇到的问题归纳总结
  • UE4_照亮环境_不同雾效的动态切换
  • 【解决】Android APK文件安装时 已包含数字签名相同APP问题
  • layui的treeTable组件,多层级上传按钮失效的问题解决
  • HashMap在JDK1.8的优化
  • Kotlin标准函数和静态方法
  • RabbitMQ(四种使用模式)
  • 【UE5 C++】基础学习笔记——01 UObject的创建与使用
  • TCP及IP协议
  • 运筹系列92:vrp算法包VROOM
  • 【Spring Security注解详解】
  • C++学习笔记3
  • 基于SpringBoot的酒店(预约)客房管理系统的设计与实现+毕业论文
  • Rust 中的声明可见性