I am attempting to write a perl script that will automatically connect to a website and post information to a form. I am currently stuck on authenticating against active directory. Does anyone have any script references on how to do this?
AD authentication
Collapse
X
-
Thank you for the link, that is a great referance for some things I will be doing later on in this project!
Although I am still not quite there. I have been attempting the following code thus far:
and alsoCode:#!/usr/bin/perl -w use LWP::UserAgent; $ua = LWP::UserAgent->new; use HTTP::Request::Common qw(POST); my $req = (POST 'http://USERNAME:PASSWORD@URL'); $request = $ua->request($req); $content = $request->content; print $ua->request($req)->as_string; exit;
Code:#!/usr/bin/perl -w use LWP::UserAgent; $ua = LWP::UserAgent->new; use HTTP::Request::Common qw(POST); $req = HTTP::Request->new(GET => 'URL'); # $req->authorization_basic('USERNAME', 'PASSWORD'); # print $ua->request($req)->as_string; exit;
However both return the following error both ways(blanked out some fields for security):
HTTP/1.1 401 (Unauthorized) Authorization Required
Connection: close
Date: DATE HERE
Server: SERVER TYPE
WWW-Authenticate: NTLM
Content-Length: 498
Content-Type: text/html; charset=iso-8859-1
Client-Date: DATE HERE
Client-Peer: IP HERE
Client-Response-Num: 1
Client-Warning: Unsupported authentication scheme 'ntlm'
Title: 401 Authorization Required
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorizati on Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<hr>
<address>Addres s server and port information goes here</address>
</body></html>
The end result of this is to authenticate to active directory, then I must authenticate to a php login, then fill out and submit a php form.Comment
-
Also tried
and returned the error 401Code:use LWP::UserAgent; use HTTP::Request::Common; my $url = 'http://WHATEVER'; # Set up the ntlm client and then the base64 encoded ntlm handshake message my $ua = new LWP::UserAgent(keep_alive=>1); $ua->credentials('WHATEVER:80', '', "DOMAIN\\USERNAME", 'PASSWORD'); $request = GET $url; print "--Performing request now...-----------\n"; $response = $ua->request($request); print "--Done with request-------------------\n"; if ($response->is_success) {print "It worked!->" . $response->code . "\n"} else {print "It didn't work->" . $response->code . "\n"}Comment
Comment