zoukankan      html  css  js  c++  java
  • Linux使用tcpdump命令抓包并使用wireshark分析

    Linux使用tcpdump命令抓包并使用wireshark分析

    介绍

      有时分析客户端和服务器网络交互的问题时,为了查找问题,需要分别在客户端和服务器上抓包,我们的客户端一般是windows上的,抓包比较简单,直接使用wireshark抓取即可。而服务器则是Linux,需要使用ssh远程登陆到Linux系统中,使用tcpdump命令开启抓包。

       tcpdump可以将网络中传送的数据包的“头”完全截获下来提供分析。它支持针对网络层、协议、主机、网络或端口的过滤,并提供and、or、not等逻辑语句来帮助你去掉无用的信息。

    基本使用

    默认启动

    tcpdump
    

    注意:普通情况下,直接启动tcpdump将监视第一个网络接口上所有流过的数据包,第一个网络接口就是eth0。

    监视指定网络接口的数据包

    tcpdump -i eth1
    

      

    监视指定主机的数据包(主机pc1的ip为(210.27.48.1

    例子:抓取流进和流出主机pc1的eth0的流量

    tcpdump host pc1
    或者
    tcpdump host 210.27.48.1

    指定端口或协议服务

    例子:抓取ip为210.27.48.1的icmp包
    tcpdump host 210.27.48.1 and icmp


    例子:抓取ip为210.27.48.1的80端口和110和25以外的其他端口的包 
    tcpdump host 210.27.48.1 and ! port 80 and ! port 25 and ! port 110

      

    截获主机间的通信流量

    打印helios 与 hot 或者与 ace 之间通信的数据包
    tcpdump host helios and ( hot or ace )

    截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信
    tcpdump host 210.27.48.1 and (210.27.48.2 or 210.27.48.3 )

     打印ace与任何其他主机之间通信的IP 数据包, 但不包括与helios之间的数据包.

         tcpdump ip host ace and not helios


    如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包
    tcpdump ip host 210.27.48.1 and ! 210.27.48.2

    截获主机hostname发送的所有数据
    tcpdump src host hostname


    监视所有送到主机hostname的数据包
    tcpdump dst host hostname

      

    输出

    tcpdump 的抓包保存到文件的命令参数是-w xxx.cap
    tcpdump -w /tmp/xxx.cap

    实例演示

    1.使用tcp抓包,连接ftp服务器

    测试ftp服务器ip:112.65.173.59(用户名和密码不正确,仅测试)

    测试用户名:admin

               密 码 :admin123456

     2.拷贝到物理机,使用wireshark打开

     3.手动分析数据

  • 相关阅读:
    Creating a generic Web Parts for hosting ASP.NET User Controls
    Speed Up SQL Server Apps 提高SQL Server应用程序的运行效率 (Part 1)
    How to use CreateChildContorls method inherited from System.Web.UI.Control
    How to quickly access Web Part Management Page
    SQL Script tips for MS SQL Server
    How to enable single signon service on the SPS
    A brief summary of UML & Rational Rose – Use Case Diagram, Part II
    Borland Together for Visual Studio.Net V2.0 安装问题
    Speed Up SQL Server Apps 提高SQL Server应用程序的运行效率 (Part 2)
    体验ReSharper V1.0 for VS.Net 2003 Part I
  • 原文地址:https://www.cnblogs.com/-wenli/p/10126511.html
Copyright © 2011-2022 走看看