我安装了 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/