zoukankan      html  css  js  c++  java
  • 1.tcpdump、wireshark常用用法

    一、tcpdump常用选项

    参考:https://www.cnblogs.com/maifengqiang/p/3863168.html

    1、tcpdump关键字

    第一种是关于类型的关键字,主要包括host,net,port, 例如 host 210.27.48.2,指明 210.27.48.2是一台主机,net 202.0.0.0 指明 202.0.0.0是一个网络地址,port 23 指明端口号是23。如果没有指定类型,缺省的类型是host.

    第二种是确定传输方向的关键字,主要包括src , dst ,dst or src, dst and src ,这些关键字指明了传输的方向。举例说明,src 210.27.48.2 ,指明ip包中源地址是210.27.48.2 , dst net 202.0.0.0 指明目的网络地址是202.0.0.0 。如果没有指明方向关键字,则缺省是src or dst关键字。

    第三种是协议的关键字,主要包括fddi,ip,arp,rarp,tcp,udp等类型。Fddi指明是在FDDI(分布式光纤数据接口网络)上的特定 的网络协议,实际上它是"ether"的别名,fddi和ether具有类似的源地址和目的地址,所以可以将fddi协议包当作ether的包进行处理和 分析。其他的几个关键字就是指明了监听的包的协议内容。如果没有指定任何协议,则tcpdump将会监听所有协议的信息包。

      除了这三种类型的关键字之外,其他重要的关键字如下:gateway, broadcast,less,greater,还有三种逻辑运算,取非运算是 'not ' '! ', 与运算是'and','&&;或运算 是'or' ,'||';

    2、例

    tcpdump命令格式:
    # tcpdump option filter 
    option 举例 -n, -i any 等
    filter 是过滤包的条件,举例: tcp, portrange 1-1000, src port 58895, host www.xxx.com

    例:

    # tcpdump tcp -i eth1 -t -s 0 -c 100 and dst port ! 22 and src net 192.168.1.0/24 -w ./target.cap
    (1)tcp: ip icmp arp rarp 和 tcp、udp、icmp这些选项等都要放到第一个参数的位置,用来过滤数据报的类型
    (2)-i eth1 : 只抓经过接口eth1的包,不指定tcpdump只会监视第一个网络接口,一般是eth0
    (3)-t : 不显示时间戳
    (4)-s 0 : 抓取数据包时默认抓取长度为68字节。加上-s 0 后可以抓到完整的数据包
    (5)-c 100 : 只抓取100个数据包
    (6)dst port ! 22 : 不抓取目标端口是22的数据包
    (7)src net 192.168.1.0/24 : 数据包的源网络地址为192.168.1.0/24
    (8)-w ./target.cap : 保存成cap文件,方便用ethereal(即wireshark)分析
    (9) -n 以数字显示主机及端口
     #tcpdump -X 以十六进制以及ASCII的形式打印数据内容
     #tcpdump -x 除了打印出header外,还打印packet里面的数据(十六进制的形式)
    监视指定主机的数据包
    # tcpdump -i eth0 host  52.9.137.165
     抓取HTTP协议的包
    # tcpdump  -XvvennSs 0 -i eth0 tcp[20:2]=0x4745 or tcp[20:2]=0x4854 -w out.pcap
    0x4745"GET"前两个字母"GE",0x4854"HTTP"前两个字母"HT"
    查看HTTP GET请求
    # tcpdump -s 0 -A 'tcp dst port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'
    查看HTTP POST请求
    # tcpdump -s 0 -A 'tcp dst port 80 and (tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354)'
    查看HTTP请求响应头以及数据
    # tcpdump -X -s 0 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -w a.pcap

    二、wireshark常用filter

    过滤IP:
     ip.src eq 192.168.1.107 or ip.dst eq 192.168.1.107  或 ip.addr eq 192.168.1.107 // 都能显示来源IP和目标IP
    过滤端口:
    tcp.port eq 80 // 不管端口是来源的还是目标的都显示
    tcp.port == 80
    tcp.port eq 80 or udp.port eq 80
    tcp.dstport == 80 // 只显tcp协议的目标端口80
    tcp.srcport == 80 // 只显tcp协议的来源端口80
    udp.port eq 15000
    tcp.port >= 1 and tcp.port <= 80    过滤端口范围

    过滤协议:

    tcp  udp  arp  icmp  http smtp  ftp dns msnms ip ssl  bootp(dhcp)
    过滤Mac:
    eth.dst == A0:00:00:04:C5:84 // 过滤目标mac
    eth.src eq A0:00:00:04:C5:84 // 过滤来源mac
    eth.dst==A0:00:00:04:C5:84
    eth.dst==A0-00-00-04-C5-84
    eth.addr eq A0:00:00:04:C5:84 // 过滤来源MAC和目标MAC都等于A0:00:00:04:C5:84的
    http模式过滤:
    http.request.method == “GET”
    http.request.method == “POST”
    http.request.uri == “/img/logo-edu.gif”
    http contains “GET”
    http contains “HTTP/1.”
    // GET包
    http.request.method == “GET” && http contains “Host: “
    http.request.method == “GET” && http contains “User-Agent: “
    // POST包
    http.request.method == “POST” && http contains “Host: “
    http.request.method == “POST” && http contains “User-Agent: “
    // 响应包
    http contains “HTTP/1.1 200 OK” && http contains “Content-Type: “
    http contains “HTTP/1.0 200 OK” && http contains “Content-Type: “
  • 相关阅读:
    python 基于os模块的常用操作
    python 文件的读写
    Spring Boot 2.0(五):Docker Compose + Spring Boot + Nginx + Mysql 实践
    Docker(四):Docker 三剑客之 Docker Compose
    Docker(三):Dockerfile 命令详解
    Docker(二):Dockerfile 使用介绍
    Docker(一):Docker入门教程
    虚拟机vmware centos7 扩展磁盘空间
    那些年我们遇到的坑(1)-Description Resource Path Location Type Archive for required library
    RPM安装命令总结
  • 原文地址:https://www.cnblogs.com/cmxu/p/12357063.html
Copyright © 2011-2022 走看看