Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spoof IP with Perl LWP

I need to write a little piece of code to simulate traffic from different source IP addresses and I'm wondering if that can be done by spoofing the addresses with Perl?

I tried Net::RAWIP and that worked, but I need to send some more complex HTTP traffic (namely POST data) and was unable to do so with RAWIP

With LWP I tried using ua->local_address but I get this response:

Can't connect to 10.x.x.x:8080

LWP::Protocol::http::Socket: Cannot assign requested address at /usr/lib/perl5/site_perl/5.10.0/LWP/Protocol/http.pm line 51.

This is the code I'm using:

#!/usr/bin/perl -w

use strict ;
use warnings ;
use LWP::UserAgent ;
use URI::URL ;

my $path = 'http://142.133.114.130:8080' ;
my $url = new URI::URL $path;
my $ua       = LWP::UserAgent->new();

$ua->local_address('10.121.132.112');
$ua->env_proxy ;
my $effing = 'blaj.jpg' ;
my $response = $ua->post( $url,
                        'Content-Type' => "multipart/form-data",
                        'Content' => [ userfile => ["$effing" ]],
                        'Connection' => 'keep-alive' ) ;
print $response->decoded_content();
like image 952
blackbird Avatar asked Nov 03 '22 16:11

blackbird


1 Answers

You can't get a response if you send from an address that's not yours. That means all you can do is send the request. You've indicated you can do the sending, so all you need is the request to send. That's easy.

use strict;
use warnings;

use HTTP::Request::Common qw( POST );

my $req = POST('http://www.example.org/',
   'Content-Type' => "multipart/form-data",
   'Content'      => [ userfile => [ $0 ]],
   'Connection'   => 'keep-alive',
);

print $req->as_string();

Output:

POST http://www.example.org/
Connection: keep-alive
Content-Length: 376
Content-Type: multipart/form-data; boundary=xYzZY

--xYzZY
Content-Disposition: form-data; name="userfile"; filename="x.pl"
Content-Type: text/plain

use strict;
use warnings;

use HTTP::Request::Common qw( POST );

my $req = POST('http://www.example.org/',
   'Content-Type' => "multipart/form-data",
   'Content'      => [ userfile => [ $0 ]],
   'Connection'   => 'keep-alive',
);

print $req->as_string();

--xYzZY--
like image 81
ikegami Avatar answered Nov 15 '22 07:11

ikegami