使用Perl LWP欺骗IP

时间:2012-09-13 17:31:26

标签: perl testing networking ip spoofing

我需要编写一小段代码来模拟来自不同源IP地址的流量,我想知道是否可以通过使用Perl欺骗地址来完成这项工作?

我尝试过Net :: RAWIP,但是我需要发送一些更复杂的HTTP流量(即POST数据),并且无法使用RAWIP

使用LWP我尝试使用ua> local_address,但我得到了这个回复:

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.

这是我正在使用的代码:

#!/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();

1 个答案:

答案 0 :(得分:2)

如果您从不属于您的地址发送,则无法获得回复。这意味着您所能做的就是发送请求。您已经表明可以进行发送,因此您只需要发送请求即可。这很容易。

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();

输出:

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--