【问题标题】:Spoof IP with Perl LWP使用 Perl LWP 欺骗 IP
【发布时间】:2012-09-13 17:31:25
【问题描述】:

我需要编写一小段代码来模拟来自不同源 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();

【问题讨论】:

    标签: perl testing networking ip spoofing


    【解决方案1】:

    如果您从不属于您的地址发送,您将无法收到回复。这意味着您所能做的就是发送请求。你已经表明你可以发送,所以你只需要发送请求。这很容易。

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

    【讨论】:

    • 发送文件没有问题,它改变了请求的源IP。我在局域网上,我可以控制路由和监听服务器,所以没关系
    • 您说您已经可以使用 Net::RAWIP 做到这一点。 Net::RAWIP 唯一不能做的就是格式化请求,我向你展示了如何做到这一点。
    • 设置对象后打印语句是否真的发送数据? RAWIP 使用 send() 方法,但它不接受数据参数。而构造函数中的数据字段只接受字符串
    • 不,它将它发送到 STDOUT。显然,替换它。
    猜你喜欢
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-21
    • 2013-04-22
    • 1970-01-01
    相关资源
    最近更新 更多