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

标签 perl login mechanize

我安装了 DVWA 并开始尝试挑战(所有数据库/配置都正确完成),本地主机上的登录凭据是 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 行打印登录页面的内容。我的代码有什么问题,我应该怎么做才能访问主页?登录后我应该手动重定向到它吗?

最佳答案

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

如果该页面上有多个表格,您可能需要通过 field 获得更具体的信息。和 submit方法;见优Mechanize form-handling documentation .

关于perl - 使用 perl 登录的表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17629988/

相关文章:

regex - 如何仅打印 perl 中所有匹配项的捕获组?

perl - 在 Test::More 中,是否可以测试一个以 exit() 结尾的子程序?

python - 强制 python mechanize/urllib2 只使用 A 请求?

python - 单击具有特定名称的图像

perl - 如何在 Perl 中安装 Parallel::ForkManager?

codeigniter - 使用谷歌登录总是征求用户同意

Wordpress OpenID 不适用于 StackOverflow

grails - 检查用户是否登录grails Titan

ruby - 缓存获取的网页有哪些选项?

windows - 如何在 perl 中从当前工作目录后移一级