網絡抓包、分析、重放


一、網絡抓包

tcpdump

Usage: tcpdump [-aAbdDefhHIJKlLnNOpqStuUvxX#] [ -B size ] [ -c count ]
        [ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]
        [ -i interface ] [ -j tstamptype ] [ -M secret ] [ --number ]
        [ -Q in|out|inout ]
        [ -r file ] [ -s snaplen ] [ --time-stamp-precision precision ]
        [ --immediate-mode ] [ -T type ] [ --version ] [ -V file ]
        [ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z postrotate-command ]
        [ -Z user ] [ expression ]

 

簡單選項

-A  以ASCII碼方式顯示每一個數據包(不會顯示數據包中鏈路層頭部信息). 在抓取包含網頁數據的數據包時, 可方便查看數據(nt: 即Handy for capturing web pages).

-c  count
    tcpdump將在接受到count個數據包后退出.

-C  file-size (nt: 此選項用於配合-w file 選項使用)
    該選項使得tcpdump 在把原始數據包直接保存到文件中之前, 檢查此文件大小是否超過file-size. 如果超過了, 將關閉此文件,另創一個文件繼續用於原始數據包的記錄. 新創建的文件名與-w 選項指定的文件名一致, 但文件名后多了一個數字.該數字會從1開始隨着新創建文件的增多而增加. file-size的單位是百萬字節(nt: 這里指1,000,000個字節,並非1,048,576個字節, 后者是以1024字節為1k, 1024k字節為1M計算所得, 即1M=102410241,048,576)

-d  以容易閱讀的形式,在標准輸出上打印出編排過的包匹配碼, 隨后tcpdump停止.(nt | rt: human readable, 容易閱讀的,通常是指以ascii碼來打印一些信息. compiled, 編排過的. packet-matching code, 包匹配碼,含義未知, 需補充)

-dd 以C語言的形式打印出包匹配碼.

-ddd 以十進制數的形式打印出包匹配碼(會在包匹配碼之前有一個附加的'count'前綴).

-D  打印系統中所有tcpdump可以在其上進行抓包的網絡接口. 每一個接口會打印出數字編號, 相應的接口名字, 以及可能的一個網絡接口描述. 其中網絡接口名字和數字編號可以用在tcpdump 的-i flag 選項(nt: 把名字或數字代替flag), 來指定要在其上抓包的網絡接口.

    此選項在不支持接口列表命令的系統上很有用(nt: 比如, Windows 系統, 或缺乏 ifconfig -a 的UNIX系統); 接口的數字編號在windows 2000 或其后的系統中很有用, 因為這些系統上的接口名字比較復雜, 而不易使用.

    如果tcpdump編譯時所依賴的libpcap庫太老,-D 選項不會被支持, 因為其中缺乏 pcap_findalldevs()函數.

-e  每行的打印輸出中將包括數據包的數據鏈路層頭部信息

-E  spi@ipaddr algo:secret,...

    可通過spi@ipaddr algo:secret 來解密IPsec ESP包(nt | rt:IPsec Encapsulating Security Payload,IPsec 封裝安全負載, IPsec可理解為, 一整套對ip數據包的加密協議, ESP 為整個IP 數據包或其中上層協議部分被加密后的數據,前者的工作模式稱為隧道模式; 后者的工作模式稱為傳輸模式 . 工作原理, 另需補充).

    需要注意的是, 在終端啟動tcpdump 時, 可以為IPv4 ESP packets 設置密鑰(secret).

    可用於加密的算法包括des-cbc, 3des-cbc, blowfish-cbc, rc3-cbc, cast128-cbc, 或者沒有(none).默認的是des-cbc(nt: des, Data Encryption Standard, 數據加密標准, 加密算法未知, 另需補充).secret 為用於ESP 的密鑰, 使用ASCII 字符串方式表達. 如果以 0x 開頭, 該密鑰將以16進制方式讀入.

    該選項中ESP 的定義遵循RFC2406, 而不是 RFC1827. 並且, 此選項只是用來調試的, 不推薦以真實密鑰(secret)來使用該選項, 因為這樣不安全: 在命令行中輸入的secret 可以被其他人通過ps 等命令查看到.

    除了以上的語法格式(nt: 指spi@ipaddr algo:secret), 還可以在后面添加一個語法輸入文件名字供tcpdump 使用(nt:即把spi@ipaddr algo:secret,... 中...換成一個語法文件名). 此文件在接受到第一個ESP 包時會打開此文件, 所以最好此時把賦予tcpdump 的一些特權取消(nt: 可理解為, 這樣防范之后, 當該文件為惡意編寫時,不至於造成過大損害).

-f  顯示外部的IPv4 地址時(nt: foreign IPv4 addresses, 可理解為, 非本機ip地址), 采用數字方式而不是名字.(此選項是用來對付Sun公司的NIS服務器的缺陷(nt: NIS, 網絡信息服務, tcpdump 顯示外部地址的名字時會用到她提供的名稱服務): 此NIS服務器在查詢非本地地址名字時,常常會陷入無盡的查詢循環).

    由於對外部(foreign)IPv4地址的測試需要用到本地網絡接口(nt: tcpdump 抓包時用到的接口)及其IPv4 地址和網絡掩碼. 如果此地址或網絡掩碼不可用, 或者此接口根本就沒有設置相應網絡地址和網絡掩碼(nt: linux 下的 'any' 網絡接口就不需要設置地址和掩碼, 不過此'any'接口可以收到系統中所有接口的數據包), 該選項不能正常工作.

-F  file
    使用file 文件作為過濾條件表達式的輸入, 此時命令行上的輸入將被忽略.

-i  interface

    指定tcpdump 需要監聽的接口.  如果沒有指定, tcpdump 會從系統接口列表中搜尋編號最小的已配置好的接口(不包括 loopback 接口).一但找到第一個符合條件的接口, 搜尋馬上結束.

    在采用2.2版本或之后版本內核的Linux 操作系統上, 'any' 這個虛擬網絡接口可被用來接收所有網絡接口上的數據包(nt: 這會包括目的是該網絡接口的, 也包括目的不是該網絡接口的). 需要注意的是如果真實網絡接口不能工作在'混雜'模式(promiscuous)下,則無法在'any'這個虛擬的網絡接口上抓取其數據包.

    如果 -D 標志被指定, tcpdump會打印系統中的接口編號,而該編號就可用於此處的interface 參數.

-l  對標准輸出進行行緩沖(nt: 使標准輸出設備遇到一個換行符就馬上把這行的內容打印出來).在需要同時觀察抓包打印以及保存抓包記錄的時候很有用. 比如, 可通過以下命令組合來達到此目的:
    ``tcpdump  -l  |  tee dat'' 或者 ``tcpdump  -l   > dat  &  tail  -f  dat''.(nt: 前者使用tee來把tcpdump 的輸出同時放到文件dat和標准輸出中, 而后者通過重定向操作'>', 把tcpdump的輸出放到dat 文件中, 同時通過tail把dat文件中的內容放到標准輸出中)

-L  列出指定網絡接口所支持的數據鏈路層的類型后退出.(nt: 指定接口通過-i 來指定)

-m  module
    通過module 指定的file 裝載SMI MIB 模塊(nt: SMI,Structure of Management Information, 管理信息結構MIB, Management Information Base, 管理信息庫. 可理解為, 這兩者用於SNMP(Simple Network Management Protoco)協議數據包的抓取. 具體SNMP 的工作原理未知, 另需補充).

    此選項可多次使用, 從而為tcpdump 裝載不同的MIB 模塊.

-M  secret  如果TCP 數據包(TCP segments)有TCP-MD5選項(在RFC 2385有相關描述), 則為其摘要的驗證指定一個公共的密鑰secret.

-n  不對地址(比如, 主機地址, 端口號)進行數字表示到名字表示的轉換.

-N  不打印出host 的域名部分. 比如, 如果設置了此選現, tcpdump 將會打印'nic' 而不是 'nic.ddn.mil'.

-O  不啟用進行包匹配時所用的優化代碼. 當懷疑某些bug是由優化代碼引起的, 此選項將很有用.

-p  一般情況下, 把網絡接口設置為非'混雜'模式. 但必須注意 , 在特殊情況下此網絡接口還是會以'混雜'模式來工作; 從而, '-p' 的設與不設, 不能當做以下選現的代名詞:'ether host {local-hw-add}''ether broadcast'(nt: 前者表示只匹配以太網地址為host 的包, 后者表示匹配以太網地址為廣播地址的數據包).

-q  快速(也許用'安靜'更好?)打印輸出. 即打印很少的協議相關信息, 從而輸出行都比較簡短.

-R  設定tcpdump 對 ESP/AH 數據包的解析按照 RFC1825而不是RFC1829(nt: AH, 認證頭, ESP, 安全負載封裝, 這兩者會用在IP包的安全傳輸機制中). 如果此選項被設置, tcpdump 將不會打印出'禁止中繼'域(nt: relay prevention field). 另外,由於ESP/AH規范中沒有規定ESP/AH數據包必須擁有協議版本號域,所以tcpdump不能從收到的ESP/AH數據包中推導出協議版本號.

-r  file
    從文件file 中讀取包數據. 如果file 字段為 '-' 符號, 則tcpdump 會從標准輸入中讀取包數據.

-S  打印TCP 數據包的順序號時, 使用絕對的順序號, 而不是相對的順序號.(nt: 相對順序號可理解為, 相對第一個TCP 包順序號的差距,比如, 接受方收到第一個數據包的絕對順序號為232323, 對於后來接收到的第2個,第3個數據包, tcpdump會打印其序列號為1, 2分別表示與第一個數據包的差距為1 和 2. 而如果此時-S 選項被設置, 對於后來接收到的第2個, 第3個數據包會打印出其絕對順序號:232324, 232325).

-s  snaplen
    設置tcpdump的數據包抓取長度為snaplen, 如果不設置默認將會是68字節(而支持網絡接口分接頭(nt: NIT, 上文已有描述,可搜索'網絡接口分接頭'關鍵字找到那里)的SunOS系列操作系統中默認的也是最小值是96).68字節對於IP, ICMP(nt: Internet Control Message Protocol,因特網控制報文協議), TCP 以及 UDP 協議的報文已足夠, 但對於名稱服務(nt: 可理解為dns, nis等服務), NFS服務相關的數據包會產生包截短. 如果產生包截短這種情況, tcpdump的相應打印輸出行中會出現''[|proto]''的標志(proto 實際會顯示為被截短的數據包的相關協議層次). 需要注意的是, 采用長的抓取長度(nt: snaplen比較大), 會增加包的處理時間, 並且會減少tcpdump 可緩存的數據包的數量, 從而會導致數據包的丟失. 所以, 在能抓取我們想要的包的前提下, 抓取長度越小越好.把snaplen 設置為0 意味着讓tcpdump自動選擇合適的長度來抓取數據包.

-T  type
    強制tcpdump按type指定的協議所描述的包結構來分析收到的數據包.  目前已知的type 可取的協議為:
    aodv (Ad-hoc On-demand Distance Vector protocol, 按需距離向量路由協議, 在Ad hoc(點對點模式)網絡中使用),
    cnfp (Cisco  NetFlow  protocol),  rpc(Remote Procedure Call), rtp (Real-Time Applications protocol),
    rtcp (Real-Time Applications con-trol protocol), snmp (Simple Network Management Protocol),
    tftp (Trivial File Transfer Protocol, 碎文件協議), vat (Visual Audio Tool, 可用於在internet 上進行電
    視電話會議的應用層協議), 以及wb (distributed White Board, 可用於網絡會議的應用層協議).

-t     在每行輸出中不打印時間戳

-tt    不對每行輸出的時間進行格式處理(nt: 這種格式一眼可能看不出其含義, 如時間戳打印成1261798315)

-ttt   tcpdump 輸出時, 每兩行打印之間會延遲一個段時間(以毫秒為單位)

-tttt  在每行打印的時間戳之前添加日期的打印

-u     打印出未加密的NFS 句柄(nt: handle可理解為NFS 中使用的文件句柄, 這將包括文件夾和文件夾中的文件)

-U    使得當tcpdump在使用-w 選項時, 其文件寫入與包的保存同步.(nt: 即, 當每個數據包被保存時, 它將及時被寫入文件中,而不是等文件的輸出緩沖已滿時才真正寫入此文件)

      -U 標志在老版本的libcap庫(nt: tcpdump 所依賴的報文捕獲庫)上不起作用, 因為其中缺乏pcap_cump_flush()函數.

-v    當分析和打印的時候, 產生詳細的輸出. 比如, 包的生存時間, 標識, 總長度以及IP包的一些選項. 這也會打開一些附加的包完整性檢測, 比如對IP或ICMP包頭部的校驗和.

-vv   產生比-v更詳細的輸出. 比如, NFS回應包中的附加域將會被打印, SMB數據包也會被完全解碼.

-vvv  產生比-vv更詳細的輸出. 比如, telent 時所使用的SB, SE 選項將會被打印, 如果telnet同時使用的是圖形界面,
      其相應的圖形選項將會以16進制的方式打印出來(nt: telnet 的SB,SE選項含義未知, 另需補充).

-w    把包數據直接寫入文件而不進行分析和打印輸出. 這些包數據可在隨后通過-r 選項來重新讀入並進行分析和打印.

-W    filecount
      此選項與-C 選項配合使用, 這將限制可打開的文件數目, 並且當文件數據超過這里設置的限制時, 依次循環替代之前的文件, 這相當於一個擁有filecount 個文件的文件緩沖池. 同時, 該選項會使得每個文件名的開頭會出現足夠多並用來占位的0, 這可以方便這些文件被正確的排序.

-x    當分析和打印時, tcpdump 會打印每個包的頭部數據, 同時會以16進制打印出每個包的數據(但不包括連接層的頭部).總共打印的數據大小不會超過整個數據包的大小與snaplen 中的最小值. 必須要注意的是, 如果高層協議數據沒有snaplen 這么長,並且數據鏈路層(比如, Ethernet層)有填充數據, 則這些填充數據也會被打印.(nt: so for link  layers  that pad, 未能銜接理解和翻譯, 需補充 )

-xx   tcpdump 會打印每個包的頭部數據, 同時會以16進制打印出每個包的數據, 其中包括數據鏈路層的頭部.

-X    當分析和打印時, tcpdump 會打印每個包的頭部數據, 同時會以16進制和ASCII碼形式打印出每個包的數據(但不包括連接層的頭部).這對於分析一些新協議的數據包很方便.

-XX   當分析和打印時, tcpdump 會打印每個包的頭部數據, 同時會以16進制和ASCII碼形式打印出每個包的數據, 其中包括數據鏈路層的頭部.這對於分析一些新協議的數據包很方便.

-y    datalinktype
      設置tcpdump 只捕獲數據鏈路層協議類型是datalinktype的數據包

-Z    user
      使tcpdump 放棄自己的超級權限(如果以root用戶啟動tcpdump, tcpdump將會有超級用戶權限), 並把當前tcpdump的用戶ID設置為user, 組ID設置為user首要所屬組的ID(nt: tcpdump 此處可理解為tcpdump 運行之后對應的進程)

      此選項也可在編譯的時候被設置為默認打開.(nt: 此時user 的取值未知, 需補充) 

二、cap文件查看

wireshark

tshark

tcpdump

三、pcap修改

分割、合並

Usage: editcap [options] ... <infile> <outfile> [ <packet#>[-<packet#>] ... ]

<infile> and <outfile> must both be present.
A single packet or a range of packets can be selected.

Packet selection:
  -r                     keep the selected packets; default is to delete them.
  -A <start time>        only output packets whose timestamp is after (or equal
                         to) the given time (format as YYYY-MM-DD hh:mm:ss).
  -B <stop time>         only output packets whose timestamp is before the
                         given time (format as YYYY-MM-DD hh:mm:ss).

Duplicate packet removal:
  --novlan               remove vlan info from packets before checking for duplicates.
  -d                     remove packet if duplicate (window == 5).
  -D <dup window>        remove packet if duplicate; configurable <dup window>.
                         Valid <dup window> values are 0 to 1000000.
                         NOTE: A <dup window> of 0 with -v (verbose option) is
                         useful to print MD5 hashes.
  -w <dup time window>   remove packet if duplicate packet is found EQUAL TO OR
                         LESS THAN <dup time window> prior to current packet.
                         A <dup time window> is specified in relative seconds
                         (e.g. 0.000001).
           NOTE: The use of the 'Duplicate packet removal' options with
           other editcap options except -v may not always work as expected.
           Specifically the -r, -t or -S options will very likely NOT have the
           desired effect if combined with the -d, -D or -w.
  --skip-radiotap-header skip radiotap header when checking for packet duplicates.
                         Useful when processing packets captured by multiple radios
                         on the same channel in the vicinity of each other.

Packet manipulation:
  -s <snaplen>           truncate each packet to max. <snaplen> bytes of data.
  -C [offset:]<choplen>  chop each packet by <choplen> bytes. Positive values
                         chop at the packet beginning, negative values at the
                         packet end. If an optional offset precedes the length,
                         then the bytes chopped will be offset from that value.
                         Positive offsets are from the packet beginning,
                         negative offsets are from the packet end. You can use
                         this option more than once, allowing up to 2 chopping
                         regions within a packet provided that at least 1
                         choplen is positive and at least 1 is negative.
  -L                     adjust the frame (i.e. reported) length when chopping
                         and/or snapping.
  -t <time adjustment>   adjust the timestamp of each packet.
                         <time adjustment> is in relative seconds (e.g. -0.5).
  -S <strict adjustment> adjust timestamp of packets if necessary to ensure
                         strict chronological increasing order. The <strict
                         adjustment> is specified in relative seconds with
                         values of 0 or 0.000001 being the most reasonable.
                         A negative adjustment value will modify timestamps so
                         that each packet's delta time is the absolute value
                         of the adjustment specified. A value of -0 will set
                         all packets to the timestamp of the first packet.
  -E <error probability> set the probability (between 0.0 and 1.0 incl.) that
                         a particular packet byte will be randomly changed.
  -o <change offset>     When used in conjunction with -E, skip some bytes from the
                         beginning of the packet. This allows one to preserve some
                         bytes, in order to have some headers untouched.
  --seed <seed>          When used in conjunction with -E, set the seed to use for
                         the pseudo-random number generator. This allows one to
                         repeat a particular sequence of errors.
  -I <bytes to ignore>   ignore the specified number of bytes at the beginning
                         of the frame during MD5 hash calculation, unless the
                         frame is too short, then the full frame is used.
                         Useful to remove duplicated packets taken on
                         several routers (different mac addresses for
                         example).
                         e.g. -I 26 in case of Ether/IP will ignore
                         ether(14) and IP header(20 - 4(src ip) - 4(dst ip)).
  -a <framenum>:<comment> Add or replace comment for given frame number

Output File(s):
  -c <packets per file>  split the packet output to different files based on
                         uniform packet counts with a maximum of
                         <packets per file> each.
  -i <seconds per file>  split the packet output to different files based on
                         uniform time intervals with a maximum of
                         <seconds per file> each.
  -F <capture type>      set the output file type; default is pcapng.
                         An empty "-F" option will list the file types.
  -T <encap type>        set the output file encapsulation type; default is the
                         same as the input file. An empty "-T" option will
                         list the encapsulation types.
  --inject-secrets <type>,<file>  Insert decryption secrets from <file>. List
                         supported secret types with "--inject-secrets help".
  --discard-all-secrets  Discard all decryption secrets from the input file
                         when writing the output file.  Does not discard
                         secrets added by "--inject-secrets" in the same
                         command line.

Miscellaneous:
  -h                     display this help and exit.
  -v                     verbose output.
                         If -v is used with any of the 'Duplicate Packet
                         Removal' options (-d, -D or -w) then Packet lengths
                         and MD5 hashes are printed to standard-error.

合並

Usage: mergecap [options] -w <outfile>|- <infile> [<infile> ...]

Output:
  -a                concatenate rather than merge files.
                    default is to merge based on frame timestamps.
  -s <snaplen>      truncate packets to <snaplen> bytes of data.
  -w <outfile>|-    set the output filename to <outfile> or '-' for stdout.
  -F <capture type> set the output file type; default is pcapng.
                    an empty "-F" option will list the file types.
  -I <IDB merge mode> set the merge mode for Interface Description Blocks; default is 'all'.
                    an empty "-I" option will list the merge modes.

Miscellaneous:
  -h                display this help and exit.
  -v                verbose output.

 tcpprep

tcpprep (tcpprep) - Create a tcpreplay cache cache file from a pcap file.
Usage:  tcpprep [ -<flag> [<val>] | --<name>[{=| }<val>] ]...

   -a, --auto=str             Auto-split mode
                - prohibits these options:
                cidr
                port
                regex
                mac
   -c, --cidr=str             CIDR-split mode
                - prohibits these options:
                auto
                port
                regex
                mac
   -r, --regex=str            Regex-split mode
                - prohibits these options:
                auto
                port
                cidr
                mac
   -p, --port                 Port-split mode
                - prohibits these options:
                auto
                regex
                cidr
                mac
   -e, --mac=str              Source MAC split mode
                - prohibits these options:
                auto
                regex
                cidr
                port
       --reverse              Matches to be client instead of server
   -C, --comment=str          Embedded cache file comment
       --no-arg-comment       Do not embed any cache file comment
   -x, --include=str          Include only packets matching rule
                - prohibits the option 'exclude'
   -X, --exclude=str          Exclude any packet matching this rule
                - prohibits the option 'include'
   -o, --cachefile=str        Output cache file
   -i, --pcap=str             Input pcap file to process
   -P, --print-comment=str    Print embedded comment in the specified cache file
   -I, --print-info=str       Print basic info from the specified cache file
   -S, --print-stats=str      Print statistical information about the specified cache file
   -s, --services=str         Load services file for server ports
                - requires the option 'port'
   -N, --nonip                Send non-IP traffic out server interface
   -R, --ratio=str            Ratio of client to server packets
                - requires the option 'auto'
   -m, --minmask=num          Minimum network mask length in auto mode
                - requires the option 'auto'
                - it must be in the range:
                  0 to 32
   -M, --maxmask=num          Maximum network mask length in auto mode
                - requires the option 'auto'
                - it must be in the range:
                  0 to 32
   -v, --verbose              Print decoded packets via tcpdump to STDOUT
   -A, --decode=str           Arguments passed to tcpdump decoder
                - requires the option 'verbose'
   -V, --version              Print version information
   -h, --less-help            Display less usage information and exit
   -H, --help                 display extended usage information and exit
   -!, --more-help            extended usage information passed thru pager
       --save-opts[=arg]      save the option state to a config file
       --load-opts=str        load options from a config file
                - disabled as '--no-load-opts'
                - may appear multiple times

Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.
tcpprep is a 'pcap(3)' file pre-processor which creates a cache file which
provides "rules" for 'tcprewrite(1)' and 'tcpreplay(1)' on how to process
and send packets.

The following option preset mechanisms are supported:
 - reading file /usr/bin/.tcppreprc
The basic operation of tcpreplay is to resend all packets from the input
file(s) out a single file.  Tcpprep processes a pcap file and applies a set
of user-specified rules to create a cache file which tells tcpreplay
whether or not to send each packet and which interface the packet should be
sent out of.

For more details, please see the Tcpreplay Manual at:
http://tcpreplay.appneta.com

Please send bug reports to:  <tcpreplay-users@lists.sourceforge.net>

 

tcprewrite

tcprewrite error:  The infile option is required
tcprewrite (tcprewrite) - Rewrite the packets in a pcap file.
Usage:  tcprewrite [ -<flag> [<val>] | --<name>[{=| }<val>] ]...

   -r, --portmap=str          Rewrite TCP/UDP ports
   -s, --seed=num             Randomize src/dst IPv4/v6 addresses w/ given seed
   -N, --pnat=str             Rewrite IPv4/v6 addresses using pseudo-NAT
   -S, --srcipmap=str         Rewrite source IPv4/v6 addresses using pseudo-NAT
   -D, --dstipmap=str         Rewrite destination IPv4/v6 addresses using pseudo-NAT
   -e, --endpoints=str        Rewrite IP addresses to be between two endpoints
       --tcp-sequence=num     Change TCP Sequence (and ACK) numbers /w given seed
   -b, --skipbroadcast        Skip rewriting broadcast/multicast IPv4/v6 addresses
   -C, --fixcsum              Force recalculation of IPv4/TCP/UDP header checksums
   -m, --mtu=num              Override default MTU length (1500 bytes)
       --mtu-trunc            Truncate packets larger then specified MTU
   -E, --efcs                 Remove Ethernet checksums (FCS) from end of frames
       --ttl=str              Modify the IPv4/v6 TTL/Hop Limit
       --tos=num              Set the IPv4 TOS/DiffServ/ECN byte
       --tclass=num           Set the IPv6 Traffic Class byte
       --flowlabel=num        Set the IPv6 Flow Label
   -F, --fixlen=str           Pad or truncate packet data to match header length
       --fuzz-seed=num        Fuzz 1 in X packets.  Edit bytes, length, or emulate packet drop
       --fuzz-factor=num      Set the Fuzz 1 in X packet ratio (default 1 in 8 packets)
       --skipl2broadcast      Skip rewriting broadcast/multicast Layer 2 addresses
       --dlt=str              Override output DLT encapsulation
       --enet-dmac=str        Override destination ethernet MAC addresses
       --enet-smac=str        Override source ethernet MAC addresses
       --enet-subsmac=str     Substitute MAC addresses
       --enet-mac-seed=num    Randomize MAC addresses
       --enet-mac-seed-keep-bytes=num Randomize MAC addresses
       --enet-vlan=str        Specify ethernet 802.1q VLAN tag mode
       --enet-vlan-tag=num    Specify the new ethernet 802.1q VLAN tag value
       --enet-vlan-cfi=num    Specify the ethernet 802.1q VLAN CFI value
       --enet-vlan-pri=num    Specify the ethernet 802.1q VLAN priority
       --hdlc-control=num     Specify HDLC control value
       --hdlc-address=num     Specify HDLC address
       --user-dlt=num         Set output file DLT type
       --user-dlink=str       Rewrite Data-Link layer with user specified data
   -i, --infile=str           Input pcap file to be processed
   -o, --outfile=str          Output pcap file
   -c, --cachefile=str        Split traffic via tcpprep cache file
   -v, --verbose              Print decoded packets via tcpdump to STDOUT
   -A, --decode=str           Arguments passed to tcpdump decoder
       --fragroute=str        Parse fragroute configuration file
       --fragdir=str          Which flows to apply fragroute to: c2s, s2c, both
       --skip-soft-errors     Skip writing packets with soft errors
   -V, --version              Print version information
   -h, --less-help            Display less usage information and exit
   -H, --help                 display extended usage information and exit
   -!, --more-help            extended usage information passed thru pager
       --save-opts[=arg]      save the option state to a config file
       --load-opts=str        load options from a config file

 

 

四、pcap重放

tcpreplay

Warning: May need to run as root to get access to all network interfaces.
tcpreplay (tcpreplay) - Replay network traffic stored in pcap files
Usage:  tcpreplay [ -<flag> [<val>] | --<name>[{=| }<val>] ]... <pcap_file(s)>

   -q, --quiet                Quiet mode
   -T, --timer=str            Select packet timing mode: select, ioport, gtod, nano
       --maxsleep=num         Sleep for no more then X milliseconds between packets
   -v, --verbose              Print decoded packets via tcpdump to STDOUT
   -A, --decode=str           Arguments passed to tcpdump decoder
                - requires the option 'verbose'
   -K, --preload-pcap         Preloads packets into RAM before sending
   -c, --cachefile=str        Split traffic via a tcpprep cache file
                - requires the option 'intf2'
                -- and prohibits the option 'dualfile'
   -2, --dualfile             Replay two files at a time from a network tap
                - requires the option 'intf2'
                -- and prohibits the option 'cachefile'
   -i, --intf1=str            Client to server/RX/primary traffic output interface
   -I, --intf2=str            Server to client/TX/secondary traffic output interface
       --listnics             List available network interfaces and exit
   -l, --loop=num             Loop through the capture file X times
                - it must be in the range:
                  greater than or equal to 0
       --loopdelay-ms=num     Delay between loops in milliseconds
                - requires the option 'loop'
                - it must be in the range:
                  greater than or equal to 0
       --pktlen               Override the snaplen and use the actual packet len
   -L, --limit=num            Limit the number of packets to send
                - it must be in the range:
                  greater than or equal to 1
       --duration=num         Limit the number of seconds to send
                - it must be in the range:
                  greater than or equal to 1
   -x, --multiplier=str       Modify replay speed to a given multiple
                - prohibits these options:
                pps
                mbps
                oneatatime
                topspeed
   -p, --pps=str              Replay packets at a given packets/sec
                - prohibits these options:
                multiplier
                mbps
                oneatatime
                topspeed
   -M, --mbps=str             Replay packets at a given Mbps
                - prohibits these options:
                multiplier
                pps
                oneatatime
                topspeed
   -t, --topspeed             Replay packets as fast as possible
                - prohibits these options:
                mbps
                multiplier
                pps
                oneatatime
   -o, --oneatatime           Replay one packet at a time for each user input
                - prohibits these options:
                mbps
                pps
                multiplier
                topspeed
       --pps-multi=num        Number of packets to send for each time interval
                - requires the option 'pps'
                - it must be in the range:
                  greater than or equal to 1
       --unique-ip            Modify IP addresses each loop iteration to generate unique flows
                - requires the option 'loop'
       --unique-ip-loops=str  Number of times to loop before assigning new unique ip
                - requires the option 'unique-ip'
       --no-flow-stats        Suppress printing and tracking flow count, rates and expirations
       --flow-expiry=num      Number of inactive seconds before a flow is considered expired
                - prohibits the option 'no-flow-stats'
                - it must be in the range:
                  greater than or equal to 0
   -P, --pid                  Print the PID of tcpreplay at startup
       --stats=num            Print statistics every X seconds, or every loop if '0'
                - it must be in the range:
                  greater than or equal to 0
   -V, --version              Print version information
   -h, --less-help            Display less usage information and exit
   -H, --help                 display extended usage information and exit
   -!, --more-help            extended usage information passed thru pager
       --save-opts[=arg]      save the option state to a config file
       --load-opts=str        load options from a config file
                - disabled as '--no-load-opts'
                - may appear multiple times

Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.
tcpreplay is a tool for replaying network traffic from files saved with
tcpdump or other tools which write pcap(3) files.

The following option preset mechanisms are supported:
 - reading file /usr/bin/.tcpreplayrc
The basic operation of tcpreplay is to resend all packets from the input
file(s) at the speed at which they were recorded, or a specified data rate,
up to as fast as the hardware is capable.

Optionally, the traffic can be split between two interfaces, written to
files, filtered and edited in various ways, providing the means to test
firewalls, NIDS and other network devices.

For more details, please see the Tcpreplay Manual at:
http://tcpreplay.appneta.com

Please send bug reports to:  <tcpreplay-users@lists.sourceforge.net>

 

 

參考資料:

1.Linux tcpdump命令詳解

2.http://otsuka752.github.io/wiki/tcprewrite.html

3.https://github.com/appneta/tcpreplay

4.http://tcpreplay.appneta.com/wiki/tcpprep

5.http://tcpreplay.appneta.com/wiki/tcprewrite.html

6.http://tcpreplay.appneta.com/wiki/tcpreplay.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM