2013-07-13 38 views
1

我安裝DVWA上了車嘗試挑戰(所有的數據庫/ CONFIGS都做得正確),並在本地主機上登錄creds登錄爲admin:密碼。這些工作,當我試圖手動登錄。表單提交的用Perl

我想編寫一個Perl腳本來猜解的暴力破解登錄的挑戰,但是我不能進入該頁面。

我用下面的代碼中的login.php登陸,但它不工作。我使用機械化(以前使用的UserAgent點但失敗了,太感動了這一個經過不斷的谷歌搜索)

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號線打印登錄頁面的內容。我的代碼出了什麼問題,應該怎麼做才能訪問主頁面?我應該在登錄後手動重定向到它?

+0

您可能需要更改帖子的標題以反映您的問題,而不是您要完成的任務。 –

+0

好的建議! – Dio

回答

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

+0

不行,仍然不會登錄。雖然這是一個非常有用的澄清!儘管我設法使用UserAgent來登錄它! – Dio

+0

WWW :: Mechanize是LWP :: UserAgent的一個子類。它可以做任何UserAgent可以做的事情。 – friedo

+0

我知道,我只是暗示我最初的實施工作。現在我面臨着從響應頭中的位置字段獲取重定向頁面的問題,這是index.php(正確!) – Dio