zoukankan      html  css  js  c++  java
  • tshark 使用说明

     yum install -y wireshark
    
    最近才发现,原来wireshark也提供有Linux命令行工具-tshark。tshark不仅有抓包的功能,还带了解析各种协议的能力。下面我们以两个实例来介绍tshark工具。
    
    tshark -s 512 -i eth0 -n -f 'tcp dst port 3306' -R 'mysql.query' -T fields -e mysql.query
    
    -s 512 :只抓取前512个字节数据
    -s   捕获快照长度
    
    
    设置默认的快照长度来使用 当捕获实时数据。 顶多每个网络包的快照长度字节会被读入到内存或者保存到磁盘。
    
    
    一个值为65536,那么整个包会被捕获 这是默认的
    
    
    
    这个选项可以发生很多次, 
    
    
    -n  禁用网络对象名字解析(比如主机名,TCP和UDP 端口名字)  
    
    
    
    -f  <capture filter>
    
    Set the capture filter expression.  设置捕获过滤器表达式
    
    -f 'tcp dst port 3306' :只捕捉协议为tcp,目的端口为3306的数据包
    
    
    tshark -i eth1 -n -f 'tcp dst port 3306' -R 'mysql.query' -T fields -e mysql.query
    
    
    -R 'mysql.query' :过滤出mysql.query
    
    -T fields -e mysql.query :打印mysql查询语句
    
    
    -e 字段
    
    增加一个字段到字段的列表来显示 如果 -F 字段是选择的,这个选项可以使用多次在命令行 至少一个字段是必须提供的
    
    
    
    
    
    tshark -s 65536 -n -i eth0 -R 'mysql.query' -T fields -e "ip.src" -e "mysql.query"
    
    
    tshark -s 65536 -n -i eth1 -R 'mysql.query' -T fields -e "ip.src" -e "mysql.query"
    
    
    
    
    zabbix:/root#  tshark -s 65536 -n -i eth1 -f 'tcp dst port 3306' -R 'mysql.query||mysql.user' -T fields -e ip.addr -e tcp.port -e frame.time -e mysql.user -e mysql.query
    
    
    
    
    
    
    
    tshark -i eth1 -n -f 'tcp dst port 3306' -R 'mysql.query  matches "^(?!(?i)select).*" || mysql.user' -T fields -e ip.addr -e tcp.port -e frame.time -e mysql.user -e mysql.query 
    
    
    
     tshark -s 65536 -n -i eth1 -f 'tcp dst port 3306' -R 'mysql  matches  "delete|DELETE|Delete|UPDATE|update|Update|insert|INSERT|Insert"' -T fields -e ip.addr -e tcp.port -e frame.time -e mysql.user -e mysql.query 
    
    
    
    
    
    抓包:
    
    Vsftp:/data02/audit#  tshark -s 65536 -n -i eth1 -f 'tcp dst port 3306' -R 'mysql  matches  "delete|DELETE|Delete|UPDATE|update|Update|insert|INSERT|Insert"' -T fields -e ip.addr -e tcp.port -e frame.time -e mysql.user -e mysql.query
    Running as user "root" and group "root". This could be dangerous.
    Capturing on eth1
    
    192.168.11.185,192.168.11.187	47677,3306	Dec  7, 2016 15:21:24.751464505		delete from t1
    192.168.11.185,192.168.11.187	47677,3306	Dec  7, 2016 15:21:25.302466232		delete from t1
    192.168.11.185,192.168.11.187	47677,3306	Dec  7, 2016 15:21:25.767454007		delete from t1
    
    mysql 5.6版本有源IP和源端口
    
    
    
    但是mysql 5.1 版本就比较特殊:
    
    192.168.5.17	3306	Dec  7, 2016 15:25:12.290737000		delete from async_message where id=598756
    192.168.5.17	3306	Dec  7, 2016 15:25:12.291717000		UPDATE real_time_room_sta SET is_live='F' WHERE hotel_group_id=1 and hotel_id=555 
    192.168.5.17	3306	Dec  7, 2016 15:25:12.294355000		UPDATE real_time_room_sta SET is_live='T' WHERE hotel_group_id=1 and hotel_id=555 AND rmno IN('201','202','209','223','225','237','253','255','269') 
    504 packets captured
    [root@pms-db-bf audit]#  tshark -s 65536 -n -i eth0 -f 'tcp dst port 3306' -R 'mysql  matches  "(?i)delete|update|insert"' -T fields -e ip.addr -e tcp.port -e frame.time -e mysql.user -e mysql.query
    
    
    就抓不到源端口和源IP
    
     tshark -s 65536 -n -i eth1 -f 'tcp dst port 3306' -R 'mysql  matches  "(?i)delete|update|insert"' -T fields -e ip.addr -e tcp.port -e frame.time -e mysql.user -e mysql.query
    
    原因 tshark 版本不同:
    
    Vsftp:/data02/audit# tshark -version
    TShark 1.8.10 (SVN Rev Unknown from unknown)
    
    
    [root@pms-db-bf sbin]# tshark -version
    TShark 1.0.15
    
    
    CentOS 5.8 升级tshark
    
    
    Vsftp:/data02/audit# rpm -qa | grep wireshark
    wireshark-1.8.10-17.el6.x86_64
    
    
    [root@pms-db-bf sbin]# rpm -qa | grep wireshark
    wireshark-1.0.15-7.el5_11

  • 相关阅读:
    378. Kth Smallest Element in a Sorted Matrix
    387. First Unique Character in a String
    230. Kth Smallest Element in a BST
    384. Shuffle an Array(随机排序)
    454. 4Sum II
    627. Swap Salary
    166. Fraction to Recurring Decimal
    763. Partition Labels(贪心)
    496. Next Greater Element I
    766. Toeplitz Matrix
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349977.html
Copyright © 2011-2022 走看看