用于使用perl登录的表单提交

时间:2013-07-13 12:01:21

标签: perl login mechanize

我安装了DVWA并继续尝试挑战(所有数据库/配置都正确完成),localhost上的登录信息是admin:password。当我尝试手动登录时,这些工作。

我想编写一个perl脚本来强制执行暴力破解登录挑战,但是我无法访问该页面。

我使用以下代码登录login.php,但它不起作用。我正在使用Mechanize(之前使用过UserAgent pm但是失败了,所以在无休止的谷歌搜索之后转移到了这个)

1 #! /usr/bin/perl
2 
3 use WWW::Mechanize ;
4 
5 my $mech = WWW::Mechanize->new(autocheck =>1);
6 $mech->credentials('admin'=>'password');
7 $mech->get('http://localhost/dvwa/login.php');
8 print $mech->content();

第8行打印登录页面的内容。我的代码有什么问题,我该怎么做才能访问主页面?我应该在登录后手动重定向到它吗?

1 个答案:

答案 0 :(得分:1)

credentials方法用于HTTP身份验证。这是表单提交,因此您需要先填写表单。

#!/usr/bin/perl
# ^ no space between #! and the perl binary

# always include these or I will hunt you down in your sleep:
use strict;
use warnings;

use WWW::Mechanize;

my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->get( 'http://localhost/dvwa/login.php' );

# you'll need to look at the login page HTML to get the actual field names
$mech->field( username => 'admin' );
$mech->field( password => 'password' );

$mech->submit;

print $mech->decoded_content;   # instead of ->content

如果该页面上有多个表单,您可能需要使用fieldsubmit方法更具体;看到优秀的Mechanize form-handling documentation