1

我有一些 250MB pcap。我可以使用 tcpreplay 更改 MAC 和 IP 地址,但我还需要修改数据包有效负载中的一些字段。如果我通过读取二进制文件来更改字段,则 ip 有效负载的校验和将失败。是否有允许我修改某些字段并更新校验和的模块?

4

1 回答 1

0

您可以使用 Net::PCap 解析此类文件:http ://search.cpan.org/~kcarnut/Net-Pcap-0.05/Pcap.pm

这是一个例子:http ://hype-free.blogspot.co.uk/2010/03/parsing-pcap-files-with-perl.html

use Net::TcpDumpLog;
use NetPacket::Ethernet;
use NetPacket::IP;
use NetPacket::TCP;
use strict;
use warnings;

my $log = Net::TcpDumpLog->new(); 
$log->read("foo.pcap");

foreach my $index ($log->indexes) { 
  my ($length_orig, $length_incl, $drops, $secs, $msecs) = $log->header($index); 
  my $data = $log->data($index);

  my $eth_obj = NetPacket::Ethernet->decode($data);    
  next unless $eth_obj->{type} == NetPacket::Ethernet::ETH_TYPE_IP;

  my $ip_obj = NetPacket::IP->decode($eth_obj->{data});
  next unless $ip_obj->{proto} == NetPacket::IP::IP_PROTO_TCP;

  my $tcp_obj = NetPacket::TCP->decode($ip_obj->{data});
  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs + $msecs/1000);
  print sprintf("%02d-%02d %02d:%02d:%02d.%d", 
    $mon, $mday, $hour, $min, $sec, $msecs), 
    " ", $eth_obj->{src_mac}, " -> ", 
    $eth_obj->{dest_mac}, "\n";    
  print "\t", $ip_obj->{src_ip}, ":", $tcp_obj->{src_port}, 
    " -> ", 
    $ip_obj->{dest_ip}, ":", $tcp_obj->{dest_port}, "\n";
}
于 2013-03-01T13:15:05.670 回答