LWP Authentication - Negotiation
I have tried many solutions but have not received an answer yet. I am trying to access an xml webpage from a server using authentication. it's either kerberos or NTLM, but I'm having trouble not understanding which one (I tried both of them). I have used LWP but I keep getting unauthorized 401 error.
I have used wireshark to see the difference between the browser title and the title I generated by the script and they are not the same. credentials appear in different places.
I tried many ways and this is my current attempt:
use FindBin;
use lib "$FindBin::Bin/lib";
use File::Basename;
use POSIX qw(strftime);
use LWP::UserAgent;
use LWP::Debug qw(+);
use HTTP::Headers;
use HTTP::Request::Common;
use Authen::NTLM;
#use HTML::TableExtract;
use HTML::Form;
use HTML::Template;
#use MIME::Entity;
my $Options = {
user => "Citrix",
host => "<ip>",
password => "Rel0aded1",
domain => "lyncent.com",
timeout => 30,
protocol => "http",
AuthMethod => "Negotiate",
BrowserAgent => "MSIE 6.0; Windows NT 5.0",
RequestMethod => "GET",
DataDir => "/tmp",
};
my $browser = LWP::UserAgent->new(
agent=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
keep_alive=>'1'
);
my $url = "http://<ip>/Citrix/Monitor/OData/v1/Methods/";
ntlm_domain($Options->{'domain'});
ntlm_user($Options->{'user'});
ntlm_password($Options->{'password'});
my $Authorization = Authen::NTLM::ntlm();
my $header = HTTP::Headers->new(
Content_Type => 'text/html',
'WWW-Authenticate' => $Options->{'AuthMethod'}
);
$header->header('Authorization' => "NTLM $Authorization");
my $request = HTTP::Request->new($Options->{'RequestMethod'} => $url, $header);
my $res = $browser->request( $request );
# Second stage of authentication
print Dumper $res;
print $res->request->as_string();
my $Challenge = $res->header('WWW-Authenticate');
$Challenge =~ s/^NTLM //g;
$browser->credentials('192.168.100.41:80', 'LYNCENT', "lyncent.com\\Citrix", 'Rel0aded1');
ntlm_domain($Options->{'domain'});
ntlm_user($Options->{'user'});
ntlm_password($Options->{'password'});
#$Authorization = Authen::NTLM::ntlm($Challenge);
$Authorization = Authen::NTLM::ntlm(
host => $Options->{'host'},
user => $Options->{'user'},
domain => $Options->{'domain'},
password => $Options->{'password'},
version => 1,
);
$Authorization -> challenge($Challenge);
$header->header('Authorization' => "NTLM $Authorization");
$header->header('User' => $Options->{'user'});
$header->header('Password' => $Options->{'password'});
$header->header('Domain' => $Options->{'domain'});
$request = HTTP::Request->new($Options->{'RequestMethod'} => $url, $header);
$res = $browser->request($request);
print Dumper $res;
print $res->request->as_string();
#
# ntlm needs to be resetted after second stage
#
ntlm_reset();
if($res->is_success) {
print "$Options->{'DataDir'}/test_url" . $res->content;
}
else {
print "not working:". $res->code ." and " . $res->status_line ."\n";
}
}
these are the headers of my prints:
GET http: link Authorization: NTLM TlRMTVNTUAABAAAAB7IAAAYABgAgAAAACwALACYAAABDaXRyaXhseW5jZW50LmNvbQ == User-Agent: Mozilla / 4.0 (compatible, MSIE 6.0, Windows NT 5.0) WWW-Authentication: text / html-negotiation
GET http: 'link' Authorization: NTLM TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAAAAAAwAAAADAAMAHAAAAAMAAwAfAAAAAAAAABIAAAAAAAAAMzMtTg4NEGeGv0QgPZbp9YSENlLZZSqlvbV1ohNAOQV0uJR + lLaaFCEhvYCPPNyUMAaQB0AHIA EMAaQB0AHIAaQB4AA == User-Agent: Mozilla / 4.0 (compatible, MSIE 6.0, Windows NT 5.0) WWW-Authentication: negotiations Content-Type: text / html Domain: lyncent.com Password : Rel0aded1 User: Citrix
does not work: 401 and 401 Unauthorized
source to share
No one has answered this question yet
Check out similar questions: