Perl to get http page with LWP NTLM authentication


1. Make sure the correct Authen::NTLM module written byMark Bush installed.

2. Make sure the module named MIME::base64 & LWP::Authen::Negotiate installed.

You can run: perl -e 'print join "\n", @INC' to know perl modules located and check if these modules are installed.


3. Have manually following patch:

    $domain = substr($c_info->{buffer}, 0, $c_info->{domain}{len});

    replacing to

    $domain = &unicode($domain);


I got below sample code worked.

#!/usr/bin/perl

use LWP::UserAgent;
use HTTP::Request::Common;
use LWP::Debug qw(+);
use strict;
use warnings;

my $url = "http://10.1.1.1";

my $ua = new LWP::UserAgent(keep_alive => 1);

$ua->credentials('10.1.1.1:80', '', 'domain\user', 'password');
my $req = GET $url; 
print "--Peforming request now...---------\n";
my $res = $ua->request($req);
print "--Done with request ...---------\n";

# check the outcome
if ($res->is_success) {
    print $res->content;
} else {
    print "Error: " . $res->status_line . "\n";
}

exit 0;

Now the next problem is happening - it redirects to 10.1.1.2?

Neccessarily modules installation history -


Installing /usr/local/share/perl/5.10.1/Encode/Locale.pm
Installing /usr/local/man/man3/Encode::Locale.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/HTTP-Date-6.00$ sudo make install
Installing /usr/local/share/perl/5.10.1/HTTP/Date.pm
Installing /usr/local/man/man3/HTTP::Date.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/File-Listing-6.03$ sudo make install
Installing /usr/local/share/perl/5.10.1/File/Listing.pm
Installing /usr/local/man/man3/File::Listing.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


Installing /usr/lib/perl/5.10/auto/Compress/Raw/Bzip2/Bzip2.bs
Installing /usr/lib/perl/5.10/auto/Compress/Raw/Bzip2/Bzip2.so
Installing /usr/lib/perl/5.10/auto/Compress/Raw/Bzip2/autosplit.ix
Installing /usr/lib/perl/5.10/Compress/Raw/Bzip2.pm
Installing /usr/share/man/man3/Compress::Raw::Bzip2.3pm
tied@tied-laptop:~/netcrack/Compress-Raw-Bzip2-2.037$ 


tied@tied-laptop:~/netcrack/Compress-Raw-Zlib-2.037$ sudo make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /usr/lib/perl/5.10/auto/Compress/Raw/Zlib/Zlib.so
Installing /usr/lib/perl/5.10/auto/Compress/Raw/Zlib/Zlib.bs
Installing /usr/lib/perl/5.10/auto/Compress/Raw/Zlib/autosplit.ix
Installing /usr/lib/perl/5.10/Compress/Raw/Zlib.pm
Installing /usr/share/man/man3/Compress::Raw::Zlib.3pm


tied@tied-laptop:~/netcrack/IO-Compress-2.037$ sudo make install
Installing /usr/lib/perl/5.10/Compress/Zlib.pm
Installing /usr/lib/perl/5.10/File/GlobMapper.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/AnyUncompress.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/RawInflate.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/AnyInflate.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/Unzip.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/Base.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/Gunzip.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/Bunzip2.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/Inflate.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/Adapter/Identity.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/Adapter/Bunzip2.pm
Installing /usr/lib/perl/5.10/IO/Uncompress/Adapter/Inflate.pm
Installing /usr/lib/perl/5.10/IO/Compress/RawDeflate.pm
Installing /usr/lib/perl/5.10/IO/Compress/Bzip2.pm
Installing /usr/lib/perl/5.10/IO/Compress/Zip.pm
Installing /usr/lib/perl/5.10/IO/Compress/Base.pm
Installing /usr/lib/perl/5.10/IO/Compress/Deflate.pm
Installing /usr/lib/perl/5.10/IO/Compress/Gzip.pm
Installing /usr/lib/perl/5.10/IO/Compress/Gzip/Constants.pm
Installing /usr/lib/perl/5.10/IO/Compress/Base/Common.pm
Installing /usr/lib/perl/5.10/IO/Compress/Adapter/Bzip2.pm
Installing /usr/lib/perl/5.10/IO/Compress/Adapter/Identity.pm
Installing /usr/lib/perl/5.10/IO/Compress/Adapter/Deflate.pm
Installing /usr/lib/perl/5.10/IO/Compress/Zlib/Extra.pm
Installing /usr/lib/perl/5.10/IO/Compress/Zlib/Constants.pm
Installing /usr/lib/perl/5.10/IO/Compress/Zip/Constants.pm
Installing /usr/share/man/man3/File::GlobMapper.3pm
Installing /usr/share/man/man3/IO::Compress::Bzip2.3pm
Installing /usr/share/man/man3/IO::Uncompress::Bunzip2.3pm
Installing /usr/share/man/man3/IO::Uncompress::Unzip.3pm
Installing /usr/share/man/man3/IO::Compress::Zip.3pm
Installing /usr/share/man/man3/IO::Uncompress::Base.3pm
Installing /usr/share/man/man3/IO::Uncompress::AnyInflate.3pm
Installing /usr/share/man/man3/IO::Uncompress::Gunzip.3pm
Installing /usr/share/man/man3/Compress::Zlib.3pm
Installing /usr/share/man/man3/IO::Compress::Gzip.3pm
Installing /usr/share/man/man3/IO::Compress::Base.3pm
Installing /usr/share/man/man3/IO::Compress::RawDeflate.3pm
Installing /usr/share/man/man3/IO::Uncompress::AnyUncompress.3pm
Installing /usr/share/man/man3/IO::Compress::Deflate.3pm
Installing /usr/share/man/man3/IO::Uncompress::RawInflate.3pm
Installing /usr/share/man/man3/IO::Uncompress::Inflate.3pm
tied@tied-laptop:~/netcrack/IO-Compress-2.037$ 


tied@tied-laptop:~/netcrack/LWP-MediaTypes-6.01$ sudo make install
Installing /usr/local/share/perl/5.10.1/LWP/media.types
Installing /usr/local/share/perl/5.10.1/LWP/MediaTypes.pm
Installing /usr/local/man/man3/LWP::MediaTypes.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/HTTP-Message-6.02$ sudo make install
Installing /usr/local/share/perl/5.10.1/HTTP/Status.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Request.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Headers.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Response.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Message.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Config.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Request/Common.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Headers/Auth.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Headers/ETag.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Headers/Util.pm
Installing /usr/local/man/man3/HTTP::Headers.3pm
Installing /usr/local/man/man3/HTTP::Message.3pm
Installing /usr/local/man/man3/HTTP::Headers::Util.3pm
Installing /usr/local/man/man3/HTTP::Config.3pm
Installing /usr/local/man/man3/HTTP::Response.3pm
Installing /usr/local/man/man3/HTTP::Status.3pm
Installing /usr/local/man/man3/HTTP::Request.3pm
Installing /usr/local/man/man3/HTTP::Request::Common.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


Installing /usr/local/share/perl/5.10.1/HTTP/Cookies.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Cookies/Microsoft.pm
Installing /usr/local/share/perl/5.10.1/HTTP/Cookies/Netscape.pm
Installing /usr/local/man/man3/HTTP::Cookies.3pm
Installing /usr/local/man/man3/HTTP::Cookies::Microsoft.3pm
Installing /usr/local/man/man3/HTTP::Cookies::Netscape.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod
tied@tied-laptop:~/netcrack/HTTP-Cookies-6.00$ 


tied@tied-laptop:~/netcrack/HTTP-Daemon-6.00$ sudo make install
[sudo] password for tied: 
Installing /usr/local/share/perl/5.10.1/HTTP/Daemon.pm
Installing /usr/local/man/man3/HTTP::Daemon.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/HTTP-Negotiate-6.00$ sudo make install
Installing /usr/local/share/perl/5.10.1/HTTP/Negotiate.pm
Installing /usr/local/man/man3/HTTP::Negotiate.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/Net-HTTP-6.01$ sudo make install
Installing /usr/local/share/perl/5.10.1/Net/HTTPS.pm
Installing /usr/local/share/perl/5.10.1/Net/HTTP.pm
Installing /usr/local/share/perl/5.10.1/Net/HTTP/NB.pm
Installing /usr/local/share/perl/5.10.1/Net/HTTP/Methods.pm
Installing /usr/local/man/man3/Net::HTTP::NB.3pm
Installing /usr/local/man/man3/Net::HTTP.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/WWW-RobotRules-6.01$ sudo make install
Installing /usr/local/share/perl/5.10.1/WWW/RobotRules.pm
Installing /usr/local/share/perl/5.10.1/WWW/RobotRules/AnyDBM_File.pm
Installing /usr/local/man/man3/WWW::RobotRules.3pm
Installing /usr/local/man/man3/WWW::RobotRules::AnyDBM_File.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/libwww-perl-6.02$ sudo make install
[sudo] password for tied: 
Installing /usr/local/share/perl/5.10.1/lwptut.pod
Installing /usr/local/share/perl/5.10.1/LWP.pm
Installing /usr/local/share/perl/5.10.1/lwpcook.pod
Installing /usr/local/share/perl/5.10.1/LWP/MemberMixin.pm
Installing /usr/local/share/perl/5.10.1/LWP/DebugFile.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol.pm
Installing /usr/local/share/perl/5.10.1/LWP/Debug.pm
Installing /usr/local/share/perl/5.10.1/LWP/RobotUA.pm
Installing /usr/local/share/perl/5.10.1/LWP/Simple.pm
Installing /usr/local/share/perl/5.10.1/LWP/ConnCache.pm
Installing /usr/local/share/perl/5.10.1/LWP/UserAgent.pm
Installing /usr/local/share/perl/5.10.1/LWP/Authen/Basic.pm
Installing /usr/local/share/perl/5.10.1/LWP/Authen/Digest.pm
Installing /usr/local/share/perl/5.10.1/LWP/Authen/Ntlm.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/data.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/nntp.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/ftp.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/file.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/loopback.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/cpan.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/mailto.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/GHTTP.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/nogo.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/gopher.pm
Installing /usr/local/share/perl/5.10.1/LWP/Protocol/http.pm
Installing /usr/local/man/man1/lwp-request.1p
Installing /usr/local/man/man1/lwp-download.1p
Installing /usr/local/man/man1/lwp-dump.1p
Installing /usr/local/man/man1/lwp-mirror.1p
Installing /usr/local/man/man3/LWP::MemberMixin.3pm
Installing /usr/local/man/man3/LWP::UserAgent.3pm
Installing /usr/local/man/man3/LWP::ConnCache.3pm
Installing /usr/local/man/man3/lwptut.3pm
Installing /usr/local/man/man3/LWP::Debug.3pm
Installing /usr/local/man/man3/LWP.3pm
Installing /usr/local/man/man3/LWP::Protocol.3pm
Installing /usr/local/man/man3/LWP::Authen::Ntlm.3pm
Installing /usr/local/man/man3/LWP::RobotUA.3pm
Installing /usr/local/man/man3/LWP::Simple.3pm
Installing /usr/local/man/man3/lwpcook.3pm
Installing /usr/local/bin/lwp-download
Installing /usr/local/bin/lwp-request
Installing /usr/local/bin/lwp-mirror
Installing /usr/local/bin/lwp-dump
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/Digest-HMAC-1.03$ sudo make install
Installing /usr/local/share/perl/5.10.1/Digest/HMAC_SHA1.pm
Installing /usr/local/share/perl/5.10.1/Digest/HMAC.pm
Installing /usr/local/share/perl/5.10.1/Digest/HMAC_MD5.pm
Installing /usr/local/man/man3/Digest::HMAC.3pm
Installing /usr/local/man/man3/Digest::HMAC_MD5.3pm
Installing /usr/local/man/man3/Digest::HMAC_SHA1.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/NTLM-1.09$ sudo make install
make[1]: Entering directory `/home/tied/netcrack/NTLM-1.09/DES'
make[1]: Leaving directory `/home/tied/netcrack/NTLM-1.09/DES'
make[1]: Entering directory `/home/tied/netcrack/NTLM-1.09/MD4'
make[1]: Leaving directory `/home/tied/netcrack/NTLM-1.09/MD4'
Installing /usr/local/share/perl/5.10.1/Authen/NTLM.pm
Installing /usr/local/share/perl/5.10.1/Authen/NTLM/DES.pm
Installing /usr/local/share/perl/5.10.1/Authen/NTLM/MD4.pm
Installing /usr/local/man/man3/Authen::NTLM.3pm
Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod


tied@tied-laptop:~/netcrack/MIME-Base64-3.13$ sudo make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /usr/lib/perl/5.10/auto/MIME/Base64/Base64.bs
Installing /usr/lib/perl/5.10/auto/MIME/Base64/Base64.so
Installing /usr/lib/perl/5.10/MIME/Base64.pm
Installing /usr/lib/perl/5.10/MIME/QuotedPrint.pm
Installing /usr/share/man/man3/MIME::QuotedPrint.3pm
Installing /usr/share/man/man3/MIME::Base64.3pm


========================================================================


reference to http://www.innovation.ch/personal/ronald/ntlm.html

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭