Perl to get http page with LWP NTLM authentication

原创 2011年10月10日 15:30:22


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

Perl 中关于 LWP::UserAgent等模块用法

大多数perl关联http模块一般用法
  • herokoking
  • herokoking
  • 2017年06月12日 11:30
  • 1103

perl lwp 获取请求头

[root@dr-mysql01 ~]# cat getx.pl use LWP::UserAgent; $ua = LWP::UserAgent->new; @header = ( '...
  • zhaoyangjian724
  • zhaoyangjian724
  • 2016年06月30日 11:17
  • 486

HttpClient学习研究---第四章:HTTP authenticationHTTP身份验证

第四章。HTTP authenticationHTTP身份验证 HttpClient provides full support for authentication schemes d...
  • oJianDanai1234567893
  • oJianDanai1234567893
  • 2013年10月05日 17:03
  • 4657

Perl用LWP库简单发送Get/Post

有段时间没有更新日志了,刚收拾好心情,今天补上一篇,关于用Perl的LWP库来发送Get和Post信息的,也就是读取某一网址的方法。 在网上找了一些中文的帖子,感觉很杂,最后还是参考http://d...
  • lockshy
  • lockshy
  • 2013年06月03日 02:57
  • 1172

perl lwp 超时问题

lwp 超时问题: jrhmpt01:/root/async# cat a1.pl use LWP::UserAgent; use utf8; use DBI; use POSIX; use D...
  • zhaoyangjian724
  • zhaoyangjian724
  • 2016年04月16日 18:15
  • 517

perl中LWP与WEB的基本使用

取自 PerlChina.org - wikiLWP 与 WEB 的基本使用 翻 译:qiang 审 校:klaus 出 处:中国 Perl 协会 原 名:Web Ba...
  • eroswang
  • eroswang
  • 2007年09月28日 17:33
  • 8334

perl LWP 模块安装以及抓取xml内容

 因为最近可能要用到web 来交互,所以需要perl  LWP的模块来支持。总的来说,安装lwp比较麻烦,尤其是我试了n次 perl -MCPAN 的方式都没有成功后。之前都是以源码来安装的,因为看到...
  • Aylazhang
  • Aylazhang
  • 2007年07月09日 15:08
  • 2795

关于Basic,Digest and NTLM Authentication认证的问题

 本人要用Axis2 Webservice远程请求服务,而远程的服务是要通过Ntlm认证的,wsdl2java生成了一系列的代码,STUB也有,但是加上了NTLM认证,总是报以下错误: Java co...
  • minjiaren
  • minjiaren
  • 2009年08月20日 10:25
  • 912

Perl LWP::Simple 提供的方法

get($url) The get() function will fetch the document identified by the given URL and retur...
  • zhaoyangjian724
  • zhaoyangjian724
  • 2015年07月10日 23:01
  • 529

NTLM Authentication Scheme for HTTP

NTLM Authentication Scheme for HTTPIntroductionThis is an attempt at documenting the undocumented NT...
  • skywoodsky
  • skywoodsky
  • 2007年02月15日 10:52
  • 1069
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Perl to get http page with LWP NTLM authentication
举报原因:
原因补充:

(最多只允许输入30个字)