Get Autodiscover Settings for debugging

Today I had to debug the autodiscover settings of an Exchange Server. Therefore I wrote a small Perl script to facilitate this task.

#!/usr/bin/perl
# Script to get the Autodiscover Settings from an Exchange Server
# Author: Philipp Kolmann philipp@kolmann.at
# Copyright (c)2014 by Philipp Kolmann
# This software comes as is.

use LWP::UserAgent;
use HTTP::Request::Common;
my $host = "autodiscover.host.name";
my $email = 'your.email@address.domain';
my $user = "DOMAIN\\user";
my $pass = 'password';

my $url = 'https://'.$host.'/autodiscover/autodiscover.xml';
my $xml = ''.$email.'http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a';

# Set up the ntlm client and then the base64 encoded ntlm handshake message
my $ua = LWP::UserAgent->new(keep_alive=>1, ssl_opts=>{verify_hostname=>0});
$ua->credentials($host.':443', '', $user, $pass);

my $header = HTTP::Headers->new(
Content_Type => 'text/xml',
charset => 'utf-8'
);

# uncomment the following lines to get HTTP Traffic debugging
#$ua->default_header('Accept-Encoding' => scalar HTTP::Message::decodable());
#$ua->add_handler("request_send", sub { shift->dump; return });
#$ua->add_handler("response_done", sub { shift->dump; return });

my $request = HTTP::Request->new('POST', $url, $header, $xml);
print "--Performing request now...-----------\n";
$response = $ua->request($request);
print "--Done with request-------------------\n";

if ($response->is_success) {
print "It worked!->" . $response->code . "\n";
print $response->decoded_content . "\n";
} else {
print "It didn't work!->" . $response->code . "\n";
}

Just edit the host, email, user and pass variables at the top and you should be able to fetch the data.

Download here:
getAutoDiscover.pl

getAutoDiscover_DOS.pl (DOS encoded)

Leave a Reply

Your email address will not be published. Required fields are marked *