Tuesday, December 23, 2008

Outlook Web Access Log Analysis

Hello Reader,
In this entry I’d like to discuss log analysis on Outlook Web Access servers. I’ve successfully used OWA log analysis in the past to quickly determine who has been reading mailboxes other than their own. Two pieces of information in the logs that exist by default in the OWA creation process allow this to occur. The first is that OWA uses NTLM authentication for web mail users who log in and the domain and username authenticated is stored in the logs in the cs-username field with format “domain\username”, remember this field will only be populated if the user successfully authenticated otherwise it will be filled with “-“. The second is that the mailbox accessed is stored in the cs-uri-query field in the logs and will look something like “isnewwindow=0&mailbox=username”. By comparing the authenticated NTLM username to the username of the mailbox requested we can write some pretty easy code to determine who has been accessing the mailboxes of other users, or attempting to.

First things first, we need the OWA logs themselves. They should be located in the “%systemroot%\system32\logfiles” directory usually in W3SVC1 if it’s the first default web created. Once we have them we need to either copy or export the log files in that directory from the image. Our first bit of code reads the content of the directory:

opendir(IMD, $dirtoget) die("Cannot open directory");

foreach $file

print "my file: $file\n";
open(FILE, "$file");

Next we need to do something with these files. We want to parse each line looking for people accessing mailboxes:


if ($_ =~ m/^([0-9\-]+
[0-9:]+) ([0-9.]+) ([^ ]+) [^ ]+ [^ ]+ [0-9.]+
[0-9]+ (GETPOST) ([^ ]+)
isnewwindow=0&mailbox=([^ ]+) ([1-3][0-9][0-9]) [0-9] [0-9]+ [0-9]+
9]+ HTTP.+ [^ ]+ ([^ ]+) ([^ ]+) (.+)$/i)

my ($access, $ip, $username, $method, $url, $query,
$useragent, $cookie, $referer) = ($1, $2, $3, $4, $5, $6, $7, $8,

Next we want to see if the username they have authenticated with matches the username of the mailbox they have requested. If it does, move on and print a . to the screen so we can see some activity. If it does not print a ! to the screen and write the resulting access to a separate file.

if ($username !~ m/$query/i )


print OUTFILE "$access, $ip, $username, $query,

print "!";






We can also store a unique list of these users in a hash so we can get a list of offenders to review. Additionally you could store all of this in a database table in larger cases so you can begin to run queries in time periods, users affected and start breaking out what messages, attachments, tasks and calendar items have been accessed.

I have posted the raw perl code and the windows compiled executable for this. For the windows executable I made it just search the same directory the executable is in, so just copy it into the directory with the logs and run it. Load up the report.csv file and find out who your suspects are.

Raw Code

Windows Executable


  1. Would this type of parsing work on Exchange 2007 OWA logs ?

  2. Looks like the code link is broken :/

  3. Cool post :-)

    Just to let you know though: the link to the raw code seems to be broken.

    Looking forward to more!

  4. Sorry for the long delay,
    We've been working on the second edition of the book which is moving now into the technical review phase. I'll fix the links and have more cool tips and perl up soon.

  5. du212 I don't see why this wouldn't work on Outlook 2007 unless they've changed their logging defaults.

  6. Some time ago in one search machine I found good tool-corrupt pst,I had problems with mails and it helped me,also my friend had advised it for me,it pleased him,program has free status as far as I know,it can decrypt OST files and convert it to a files with PST extension, it can be opened offline with Outlook or any other mail client, compatible with this program,will easily correct pst file and restore files with *.pst extension and convert it to an operative PST file or just unpack it as separate files with *.vcf, *.txt and *.eml formats,retrieve data from corrupt pst and look for other data recovery services, when Outlook.pst corrupt in MS Outlook,program includes several unique algorithms, that permit to extract more data from corrupted mailboxes,program is very easy either for beginners or for professionals, mailbox recovery is divided into several simple steps, so, it is very difficult to make an error, when corrupt pst file or Microsoft Outlook pst file corrupted,will simulate the view of your mailbox, you can preview all messages in their appropriate folders

  7. Does the OWA log store information relating to which IP addresses have been used to access accounts, in the event that people have been viewing colleagues mailboxes after they have left the company? For example, does it just store the login user details or does it store the user login and the IP address they have logged in from to access the mailbox / OWA screen?

  8. Yes the OWA logs the ip address and other typical web log data you woulf expect to see.

    To answer your question fully: Yes it logs both the user logged in, the ip address used to access owa and the mailbox the user accessed. It also records each message, attachment, etc... accessed by that user.

  9. Know one nice tool which recover mails and may be more...It is free as is known-opening a .pst file.Besides that it helped my good friend in serious situation.It can works under Windows 98, Windows Me, Windows NT 4.0, Windows 2000, Windows XP, Windows 2003, Windows Vista and all supported versions of Microsoft Outlook.

  10. Your link for executable is not working?

  11. Can I get a copy of the executable file, the link does not work.

    1. I'd be happy to anonymous, just need to know where to send it. In the mean time I need to update this and relink it.

  12. Hi David

    This sounds like it could be very handy indeed! Probably shouldn't post this on here, but any chance you could send this to adrovmat@hotmail.com so I can check it out?

    Many thanks

  13. Hi David

    This looks fantastic. Just wondering if you're close to relinking, as I'm really interested to see if this would work for me.


  14. I have sent a mail(its totally a personal mail, with no attachments) using owa from my company pc, by mistake. Can they track me down. There is only one log file availabe in the sys32 path. naming ex130313.log. please tell me..(the domain I used was blocked initially and since there was a change in the url, its started working)

  15. hi
    is the reporter exe you created still available?
    link seems to be broken?

  16. I'm actually trying to download the tool and the link is still broken. Any chance you can update the link? Thanks again.