user2896215 user2896215 - 17 days ago 7
Perl Question

Using Perl's Net::Frame::Simple module to rewrite ethernet header

I am using below code (copied from http://search.cpan.org/~gomor/Net-Frame-Simple-1.06/lib/Net/Frame/Simple.pm) to rewrite the ethernet src and dst mac information but its generating bad IP packet.

#!/usr/bin/perl

use Net::Frame::Simple;
use Net::Frame::Layer::IPv4;
use Net::Frame::Layer::TCP;
use Net::Frame::Layer::ETH;
use Net::Frame::Device;
use Net::Write::Layer3;
use Net::Frame::Dump::Online;
use Net::Write::Layer2;


my $src = '100.1.1.39';
my $target = '200.2.2.97';
my $port = 22;


my $eth = Net::Frame::Layer::ETH->new(src => "00:0c:29:d1:03:06", dst => "03:03:03:03:03:03");
my $ip4 = Net::Frame::Layer::IPv4->new(src => $src,dst => $target);
my $tcp = Net::Frame::Layer::TCP->new(dst => $port, options => "\x02\x04\x54\x0b",payload => 'test');

my $oSimple = Net::Frame::Simple->new(layers => [$eth,$ip4,$tcp],);

# Now, the frame is ready to be send to the network
# We open a sender object, and a retriever object

my $oWrite = Net::Write::Layer2->new(dev => 'eth0');
$oWrite = Net::Write::Layer3->new(dst => $target);
#my $oDump = Net::Frame::Dump::Online->new(dev => $oDevice->dev);
#$oDump->start;
$oWrite->open;

# We send the frame
$oSimple->send($oWrite);


If i remove the ethernet part ($eth) when defining layers in $oSimple, it works.
Any suggestions what i am missing or doing wrong?

Answer

I was able to make it work For anyone's reference, if remove the line "Net::Write::Layer3" and just do the writing at layer 2 (Net::Write::Layer2) in above code, you can change the src and dst MACs.