Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


April 17, 2006

Auditing IIS Security with Log Parser


RSS
Subscribe to Windows IT Pro | See More Security Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Log Parser is a free command-line utility that harnesses the power of SQL querying and database mining to search through the log files that Windows Server 2003, Exchange Server, SQL Server, and ISA Server 2004 generate. If you're running Microsoft Internet Information Services (IIS) 6.0 on Windows 2003, you can use Log Parser to perform security auditing to monitor anomalies in the logs that might signal that an intruder is trying to compromise your Web server. Log Parser won't come straight out and tell you that an intruder has successfully attacked your server, but if you ask the right questions, it can provide you with some pretty conclusive evidence. I'll show you how to use Log Parser to generate statistics from IIS 6.0, check error status codes, locate unusual verbs in HTTP requests, and trace Web site activity.

Before we begin, you might want to read previously published Windows IT Security articles that will help you understand some of Log Parser's operating fundamentals. Although you don't need to read any of these articles to follow what I'm going to walk you through, you might find the background useful for a deeper understanding of Log Parser. In particular, see "LogParser," May 2004, InstantDoc ID 42174; "Access Denied: Using Log Parser to Audit Domain Logons," July 2004, InstantDoc ID 42812; "Targeting Failed Logons," September 2004, InstantDoc ID 43450; and "Filter for Security," October 2004, InstantDoc ID 43827. The ultimate resource for Log Parser is Gabriele Giuseppini and Mark Burnett, Microsoft Log Parser Toolkit (Syngress, 2005). Ready to go? Let's get started.

Generating Data
Before you can begin to analyze the IIS log files, you need to make sure you have the right data to analyze. To generate the appropriate data, configure the audit policy on your Web server for IIS logging. At a minimum, configure the policy to audit the following events for success and failure: logon, object access, and privilege use. Auditing logon events lets you see how accounts are being used to access information over the network via the Web server. Enabling auditing of object access on the appropriate folders of your Web site lets you build a record of access to the objects. Be careful about auditing object access: Overzealous auditing can lead to performance degradation due to server overload. Auditing privilege use can help you track down intruders who use privilege escalation to gain elevated access rights. I don't cover privilege escalation per se in this article, but you'll get an idea of how to use Log Parser to tease relevant privilege escalation details out of the audit log.

For IIS logging, select the W3C Extended log file format in IIS 6.0 and log as many fields as possible. Although Log Parser can use any of the IIS log formats, the W3C Extended log file format can record the greatest variety of information. Having the largest amount of information possible is useful when you need to look for unusual details as you investigate an auditing anomaly.

Configure logging by selecting the Enable Logging check box in the Web site properties. Use the drop-down menu to select the W3C Extended log file format, then click the Logging Properties button. On the Advanced tab, make sure that a check mark exists in each field's check box.

Log Parser Query Files and Output
To write Log Parser commands, I prefer to put the SQL queries inside a text file, then call that text file as an argument that uses the Log Parser executable. The advantage to this system is that it lets me save complex queries so that I can reuse them. Writing a query in Notepad rather than directly at the command prompt makes syntax corrections easier. To use a query file with Log Parser, use the following format, where query.sql contains your Log Parser SQL query:

logparser file:query.sql 
  -o:DATAGRID -RTP:-1 

I also prefer to output in a DataGrid, rather than directly to the command prompt. DataGrid formatting is helpful if you find command-line output confusing. The -RTP:-1 switch specifies that all output be displayed in the window, rather than only the first 10 rows of output, which is the default display limit. Figure 1 shows DataGrid output for a simple query.

Log Parser has many output options besides DataGrid. If the Microsoft Office Web Components are installed on your system, you can output Log Parser results to formats ranging from bar graphs to pie charts. In this article, I refer to DataGrid exclusively because I think it's the most accessible format for new Log Parser users.

Important Log File Fields
You need to be familiar with several important W3C Extended log file format fields when performing a security audit of your IIS logs. Although I recommend that you configure the IIS logs to record all possible data, the fields that Table 1 shows are the best entry points into the logs. Logging all possible data, even though you're likely to use only a few fields, is a simple basic precaution. Any field can contain something that turns out to be extremely useful in determining what an intruder has done when compromising your IIS server. You can find a full list of W3C Extended log file format fields by examining the extended logging options on the Advanced tab of the Logging Properties dialog in the Web site properties.

Pulling Basic Statistics from IIS 6.0
You can use Log Parser to quickly generate basic statistics for IIS 6.0 Web sites. The following query lists the targeted site's most-requested files:

---PAGEHITS.SQL---
SELECT cs-uri-stem, COUNT(*)
FROM <77038354> 
GROUP BY cs-uri-stem 
ORDER BY COUNT(*) DESC   
---PAGEHITS.SQL---

where <77038354> represents the site's unique identifier. The default Web site on IIS 6.0 always has an identifier of <1>. Unlike earlier versions of IIS, IIS 6.0 doesn't number additional sites sequentially, so you need to do some exploring to find a site's number if you aren't using the default Web site. If you run multiple Web sites, you can locate this number either by looking on the Microsoft Management Console (MMC) IIS Manager snap-in or by running the Iisweb /query command from the command prompt. With its powerful query engine and varied output formats, Log Parser is an excellent tool for performing detailed analyses of FTP, WWW, and SMTP traffic on your IIS server.

Finding Anomalies
One way to start looking for anomalies in your event logs is to check error status codes. Particular status codes, specifically those between 400 and 424, can indicate that some type of attack has occurred and that evidence of it exists within your Web server's logs. The following query will provide you with a list of error codes according to IP address:

---STATUSIPADDRESS.SQL---
SELECT c-ip, cs-uri-stem,
  sc-status, sc-substatus, 
  COUNT(*) 
from <77038354> 
WHERE (sc-status BETWEEN 400 
  and 424)
GROUP BY c-ip, sc-status, 
  sc-substatus, cs-uri-stem 
ORDER BY COUNT(*) DESC   
---STATUSIPADDRESS.SQL---

This query's output will provide a list of recorded errors between 400 (Bad Request) and 424 (Failed Dependency). These errors signal that something hasn't gone right, and although they don't necessarily mean that your server has been hacked, they do mean that you need to investigate the issue further. Once you have an idea of the frequency of unique error status codes, you can begin planning the best way to use Log Parser to drill down into the logs for more information.

   Previous  [1]  2  Next 


Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

The Desktop tab is missing from the Display Properties in Windows XP?

...

Are You an Ultimate Microsoft Customer ... Or Just a Good One?

Microsoft's trend toward making available multiple product editions has recently reached into surprising areas. ...


Security Whitepapers Anti-Virus Is Dead: The Advent of the Graylist Approach to Computer Protection

Getting the Job Done: Comparing Approaches for Desktop Software Lockdown

Instant Messaging, VoIP, P2P, and games in the workplace: How to take back control

Related Events Check out our list of Free Email Newsletters!

Security eBooks Spam Fighting and Email Security for the 21st Century

Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

Related Security Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

WinConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

Deploying SharePoint! In-Person Event Series – 8 Cities
Discover best practices and tips for deploying the perfect SharePoint infrastructure. Early Bird Price of $99 extended till Sept. 15th.

Find a new job now on the all new IT Job Hound!
Search jobs, post your resume, and set up job e-mail alerts!

Master SharePoint with 3 eLearning Seminars
Learn how to build a better SharePoint infrastructure and enable powerful collaboration with MVPs Dan Holme and Michael Noel. Register today!

Top Tools for Virtualization Disaster Recovery & Replication
View this web seminar on August 14th to learn about two tools that will result in faster backup and restore with P2V disaster recovery.

SharePointConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

VMworld 2008 - Sign Up Today!
Join your peers on September 15-18 at The Venetian Hotel in Las Vegas as VMware hosts VMworld 2008, the leading Virtualization event.



When managing just VMware isn’t enough
Plan/Manage/Secure – NetIQ VMware management. Download whitepaper.

What’s up with your network? Find out with ipMonitor
Availability monitoring for servers, applications and networks – FREE trial

Microsoft® Tech•Ed EMEA 2008 IT Professionals
Advance your thinking with new ideas and practical real-world solutions at Microsoft’s FIVE day technical infrastructure conference 3-7 Nov., 2008. Register before 26 September 2008 to save €300.

Order Your Fundamentals CD Today!
Gain an introduction to Exchange, learn server security requirements, and understand how unified communications can play a role in your messaging strategies with this free Exchange CD.

Are You Really Compliant with Software Regulations?
View this web seminar that will help you with compliance best practices and check out a management solution to assure that you won’t be in jeopardy of an audit.

Virtualization Congress Oct. 14-16 in London
Don't miss Virtualization Congress, the premiere EMEA conference dedicated to hardware, OS and application virtualization. Oct. 14-16 in London.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technical Resources Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing