AD authentication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Narsarius
    New Member
    • Dec 2006
    • 5

    AD authentication

    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?
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    http://search.cpan.org/~gaas/libwww-perl-5.805/lwpcook.pod

    Comment

    • Narsarius
      New Member
      • Dec 2006
      • 5

      #3
      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:

      Code:
      #!/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;
      and also

      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.
      Last edited by Narsarius; Dec 2 '06, 04:49 AM. Reason: corrections

      Comment

      • Narsarius
        New Member
        • Dec 2006
        • 5

        #4
        Also tried

        Code:
        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"}
        and returned the error 401

        Comment

        • Narsarius
          New Member
          • Dec 2006
          • 5

          #5
          Also i do not have to go through a proxy to access this site

          Comment

          Working...