IT Lab due Saturday 10/5

Please follow instructions and let me know if you run into any problems.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

FirstResponders Guide

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

to

C

omputer Forensics:
Advanced Topics

Richard Nolan
Marie Baker
Jake Branson
Josh Hammerstein
Kris Rush
Cal Waits
Elizabeth Schweinsberg

September 2005

HANDBOOK
CMU/SEI-2005-HB-00

3

Pittsburgh, PA

1

5213-3890

First Responders Guide
to Computer Forensics:

Advanced Topics

CMU/SEI-2005-HB-003

Richard Nolan
Marie Baker
Jake Branson
Josh Hammerstein
Kris Rush
Cal Waits
Elizabeth Schweinsberg

September 2005

CERT Training and Education

Unlimited distribution subject to the copyright.

This report was prepared for the

SEI Administrative Agent
ESC/XPK
5 Eglin Street
Hanscom AFB, MA 01731-2100

The ideas and findings in this report should not be construed as an official DoD position. It is published in the interest of
scientific and technical information exchange.

FOR THE COMMANDER

Christos Scondras

Chief of Programs, XPK

This work is sponsored by the SEI FFRDC primary sponsor and the Department of Homeland Security. The Software Engi

neering Institute is a federally funded research and development center sponsored by the U.S. Department of Defense.

Copyright 2005 Carnegie Mellon University.

NO WARRANTY

THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS
FURNISHED ON AN “AS-IS” BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO,
WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED
FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF
ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.

Use of any trademarks in this report is not intended in any way to infringe on the rights of the trademark holder.

Internal use. Permission to reproduce this document and to prepare derivative works from this document for internal use is
granted, provided the copyright and “No Warranty” statements are included with all reproductions and derivative works.

External use. Requests for permission to reproduce this document or prepare derivative works of this document for external
and commercial use should be addressed to the SEI Licensing Agent.

This work was created in the performance of Federal Government Contract Number FA8721-05-C-0003 with Carnegie
Mellon University for the operation of the Software Engineering Institute, a federally funded research and development
center. The Government of the United States has a royalty-free government-purpose license to use, duplicate, or disclose the
work, in whole or in part and in any manner, and to have or permit others to do so, for government purposes pursuant to the
copyright license under the clause at 252.227-7013.

For information about purchasing paper copies of SEI reports, please visit the publications portion of our Web site
(http://www.sei.cmu.edu/publications/pubweb.html).

  • Table of Contents
  • Executive Summary
  • ……………………………………………………………………………………. xi

  • Abstract
  • ……………………………………………………………………………………………………. xiii

    1

  • Module 1: Log File Analysis
  • …………………………………………………………………..

    1

    1.1 Swatch …………………………………………………………………………………………. 3

    1.1.1 Swatch Log Monitor……………………………………………………………. 4
    1.1.2 Swatch Installation …………………………………………………………….. 5

    1.1.2.1 Installing Perl Modules……………………………………………… 5
    1.1.2.2 Installing Swatch ……………………………………………………… 6

    1.1.3 Swatch Configuration…………………………………………………………. 8
    1.1.3.1 The Configuration File Location …………………………………. 9
    1.1.3.2 Adding Rules to the Configuration File ……………………….. 9

    1.1.4 Swatch Execution …………………………………………………………….. 15
    1.1.5 Summary………………………………………………………………………….. 17

    1.2 Microsoft Log Parser 2.2 ……………………………………………………………… 18
    1.2.1 Microsoft Log Parser Features ………………………………………….. 20
    1.2.2 Log Parser Installation ……………………………………………………… 21
    1.2.3 Log Parser Input and Output …………………………………………….. 2

    2

    1.2.3.1 Input Formats………………………………………………………… 22
    1.2.3.2 Output Formats ……………………………………………………… 24

    1.2.4 Log Parser Queries…………………………………………………………… 26
    1.2.4.1 Query Examples ……………………………………………………. 27

    1.2.5 Log Parser COM Objects…………………………………………………… 29
    1.2.5.1 Creating Custom Input Formats……………………………….. 29
    1.2.5.2 Using the Log Parser COM API ……………………………….. 30

    1.2.6 Log Parser Execution ……………………………………………………….. 31
    1.2.7 Summary………………………………………………………………………….. 33

    2

  • Module 2: Process Characterization
  • ……………………………………………………. 35
    2.1 Understanding a Running Process ………………………………………………. 36

    2.1.1 Objectives………………………………………………………………………… 37
    2.1.2 Programs, Processes, and Threads…………………………………… 38
    2.1.3 Threads ……………………………………………………………………………. 39

    2.1.3.1 Displaying Threads for a Running Process………………… 39

    CMU/SEI-2005-HB-003 i

    2.1.3.2 Sysinternals Process Explorer…………………………………. 40
    2.1.4 Process Tree Structure …………………………………………………….. 43

    2.1.4.1 pstree (Linux)………………………………………………………… 44
    2.1.4.2 Linux ps –A …………………………………………………………… 44

    2.1.5 Process Descriptions ……………………………………………………….. 46
    2.1.6 Process Hashes (National Software Reference Library)……… 47
    2.1.7 Process Analysis Checklist ………………………………………………. 49
    2.1.8 Common Process Characteristics …………………………………….. 51

    2.1.8.1 Process Filenames ………………………………………………… 51
    2.1.8.2 Open Ports …………………………………………………………… 53
    2.1.8.3 Open Files ……………………………………………………………. 55
    2.1.8.4 Base Priority …………………………………………………………. 56
    2.1.8.5 Process Times and Terminated Processes………………… 58
    2.1.8.6 Location of Process Image ……………………………………… 60
    2.1.8.7 Survivable Processes …………………………………………….. 61
    2.1.8.8 Process Forensic Tasks………………………………………….. 66

    2.2 Automated Process Collection ……………………………………………………. 76
    2.2.1 Objectives………………………………………………………………………… 77
    2.2.2 First Responder Utility (FRU) ……………………………………………. 78

    2.2.2.1 First Responder Utility (FRUC) Setup ………………………. 79
    2.2.3 Forensic Server Project (FSP) …………………………………………… 82

    2.2.3.1 FSP Setup ……………………………………………………………. 82
    2.2.3.2 Testing FRUC ……………………………………………………….. 83
    2.2.3.3 Output of FRUC …………………………………………………….. 84

    3

  • Module 3: Image Management
  • …………………………………………………………….. 87
    3.1 Slice and Dice with dd…………………………………………………………………. 88

    4

  • Module 4: Capturing a Running Process
  • …………………………………………… 101
    4.1.1 Hedons and Dolors…………………………………………………………. 103
    4.1.2 Capturing a Process on a Windows System …………………….. 104

    5

  • Module 5: Understanding Spoofed Email
  • …………………………………………….113
    5.1 Objectives ………………………………………………………………………………….114
    5.2 Identifying Spoofed Email …………………………………………………………..115

    5.2.1 Definition of the Problem ………………………………………………….116
    5.2.2 Understanding the Process of Sending and Receiving

    Email ……………………………………………………………………………….117
    5.2.2.1 The Life Cycle of an Email………………………………………117
    5.2.2.2 Overview of the Simple Mail Transfer Protocol…………..119

    5.2.3 Understanding Email Headers…………………………………………. 123
    5.2.3.1 Interpreting Email Headers ……………………………………. 123

    5.2.4 How Spoofed Email Is Sent …………………………………………….. 127

    ii CMU/SEI-2005-HB-003

    5.2.4.1 Open Mail Relay ………………………………………………….. 127
    5.2.4.2 Compromised Machines ……………………………………….. 129
    5.2.4.3 Self-Owned Mail Servers ………………………………………. 129
    5.2.4.4 Temporary Accounts …………………………………………….. 129
    5.2.4.5 Hijacked Accounts ……………………………………………….. 129

    5.2.5 How to Identify Spoofed Email ………………………………………… 130
    5.2.5.1 Carefully Examine the “Received” Headers……………… 130
    5.2.5.2 Look Out for Spoofed Headers ………………………………. 132
    5.2.5.3 Comparing Timestamps ………………………………………… 133

    5.3 Tracing the Origins of a Spoofed Email………………………………………. 135
    5.3.1 nslookup ………………………………………………………………………… 136
    5.3.2 whois……………………………………………………………………………… 139

    5.3.2.1 IP Block Identification……………………………………………. 139
    5.3.2.2 WHOIS Information for a Domain Name …………………. 142

    5.3.3 Traceroute ……………………………………………………………………… 144
    5.3.4 Sam Spade……………………………………………………………………… 145

    5.4 Summary ………………………………………………………………………………….. 146

  • References
  • ………………………………………………………………………………………………. 147

    CMU/SEI-2005-HB-003 iii

    iv CMU/SEI-2005-HB-003

  • List of Figures
  • Figure 1: Example Run of the Swatch Configuration File……………………………….. 14

    Figure 2: Example Run of PsList ………………………………………………………………… 39

    Figure 3: Sysinternals Process Explorer Utility……………………………………………… 40

    Figure 4: Verifying a Process Image in Process Explorer ………………………………. 41

    Figure 5: The Strings Tab in Process Explorer ……………………………………………… 41

    Figure 6: Displaying a Process Tree Using PsList…………………………………………. 43

    Figure 7: Displaying a Process Tree Using pstree ………………………………………… 44

    Figure 8: Displaying PID Assignments Using ps …………………………………………… 45

    Figure 9: WinTasks Process Description ……………………………………………………… 47

    Figure 10: Listing Process Filenames Using pulist………………………………………….. 52

    Figure 11: Displaying Open Ports Using fport ………………………………………………… 53

    Figure 12: Displaying Open Ports Using netstat……………………………………………… 54

    Figure 13: Viewing Handles Using handle……………………………………………………… 55

    Figure 14: Displaying Which Process Has Port 6002 Open ……………………………… 56

    Figure 15: Displaying Who Has the Bash Shell Open ……………………………………… 56

    Figure 16: Displaying All the Currently Open Files by the User Root …………………. 56

    Figure 17: Listing Priority Levels Using pslist …………………………………………………. 57

    Figure 18: Listing Priority Levels Using top ……………………………………………………. 57

    Figure 19: Displaying the Priority Level for a Specific Process …………………………. 57

    CMU/SEI-2005-HB-003 v

    Figure 20: Checking Uptime Using psuptime …………………………………………………. 58

    Figure 21: Checking Elapsed Time for a Process Using pslist ………………………….. 58

    Figure 22: Windows Event Log ……………………………………………………………………. 59

    Figure 23: psloglist Command……………………………………………………………………… 59

    Figure 24: Locating a Process Image Using ListDLLs …………………………………….. 60

    Figure 25: Locating a Process Image Using ps………………………………………………. 60

    Figure 26: Locating a Process Image by PID…………………………………………………. 61

    Figure 27: autorunsc.exe Command …………………………………………………………….. 62

    Figure 28: The chkconfig -list Command……………………………………………………….. 63

    Figure 29: A Cron Log ………………………………………………………………………………… 64

    Figure 30: The Crontab Command……………………………………………………………….. 65

    Figure 31: The svchost.exe 780 Process ………………………………………………………. 67

    Figure 32: listdlls.exe Output for svchost.exe…………………………………………………. 68

    Figure 33: MD5deep Utility………………………………………………………………………….. 69

    Figure 34: Performing a String Search Using grep………………………………………….. 69

    Figure 35: The mshearts.exe 2840 Process ………………………………………………….. 70

    Figure 36: listdlls.exe Output for the mshearts Process …………………………………… 71

    Figure 37: MD5deep.exe Command Line Arguments ……………………………………… 71

    Figure 38: strings Command ……………………………………………………………………….. 73

    Figure 39: strings Command Output …………………………………………………………….. 73

    Figure 40: Hash of John the Ripper ……………………………………………………………… 74

    Figure 41: First Part of the fruc.ini File ………………………………………………………….. 80

    Figure 42: Second Part of the fruc.ini File ……………………………………………………… 80

    vi CMU/SEI-2005-HB-003

    Figure 43: Final Part of fruc.ini File……………………………………………………………….. 81

    Figure 44: FSP Setup …………………………………………………………………………………. 83

    Figure 45: FRUC Utility Command ……………………………………………………………….. 83

    Figure 46: FSP Command Output ………………………………………………………………… 84

    Figure 47: FRUC Output File……………………………………………………………………….. 85

    Figure 48: FRUC Audit File………………………………………………………………………….. 85

    Figure 49: Result of Using md5 to Calculate a Hash Value………………………………. 92

    Figure 50: Confirming the Result of Splitting Images ………………………………………. 92

    Figure 51: Result of Using cat and md5sum to Check the Integrity of Split
    Images………………………………………………………………………………………. 93

    Figure 52: Result of Using md5sum to Check the Integrity of a New Image ……….. 94

    Figure 53: Finding a Tag in a Captured Image …………………………………………. 96

    Figure 54: Decimal Form of the Beginning of the File ……………………………….. 96

    Figure 55: Searching for the End of the File …………………………………………….. 97

    Figure 56: Tag Delineating the End of a File…………………………………………….. 97

    Figure 57: Decimal Address for the End of the File …………………………………… 97

    Figure 58: Calculating the Size of the File ……………………………………………….. 97

    Figure 59: File Carved Out Using dd …………………………………………………………….. 98

    Figure 60: Viewing Carved File………………………………………………………………. 98

    Figure 61: Running a Trusted Command …………………………………………………….. 106

    Figure 62: Command Shell Spawned from a Trusted CD……………………………….. 106

    Figure 63: netcat Command to Listen on Port 3333………………………………………. 106

    Figure 64: Using Trusted pslist and netcat to Specify IP Address and Listening
    Port…………………………………………………………………………………………. 107

    CMU/SEI-2005-HB-003 vii

    Figure 65: Looking for Suspicious Processes Using cat ………………………………… 107

    Figure 66: Suspicious Process Found…………………………………………………………. 107

    Figure 67: netcat Command to Listen on Port 4444………………………………………. 108

    Figure 68: Specifying netcat Listener Machine and Port ………………………………… 108

    Figure 69: Viewing Path to a Suspicious Process …………………………………………. 108

    Figure 70: Setting Up a Listening Session on a Suspicious Process……………….. 109

    Figure 71: Collecting the Executable of a Suspicious Process ……………………….. 109

    Figure 72: Calculating a Hash of a Captured Process …………………………………… 109

    Figure 73: The Life Cycle of an Email …………………………………………………………..118

    Figure 74: Mail Delivery for Valid Users ………………………………………………………. 128

    Figure 75: Spoofed Email via an Open Relay ………………………………………………. 128

    Figure 76: nslookup of Valid Fully Qualified Domain Name ……………………………. 137

    Figure 77: nslookup of Falsified Host Information ………………………………………… 138

    Figure 78: WHOIS Query of ARIN………………………………………………………………. 140

    Figure 79: WHOIS Query of APNIC ……………………………………………………………. 141

    Figure 80: WHOIS Query of IANA………………………………………………………………. 142

    Figure 81: Query of .com WHOIS Database ………………………………………………… 143

    Figure 82: Query of the Registrar’s WHOIS Database…………………………………… 143

    Figure 83: Traceroute Example ………………………………………………………………….. 145

    viii CMU/SEI-2005-HB-003

  • List of Tables
  • Table 1: Actions in Swatch ……………………………………………………………………….. 11

    Table 2: time_regex for Popular Services ……………………………………………….. 13

    Table 3: Common Input Formats……………………………………………………………….. 22

    Table 4: Output Formats ………………………………………………………………………….. 24

    Table 5: Misc Log Parser Commands ………………………………………………………… 31

    Table 6: A Subset of ps Options ………………………………………………………………… 52

    Table 7: Output Headings for ps and top ……………………………………………………. 52

    Table 8: dd Syntax ………………………………………………………………………………….. 88

    Table 9: Tools for Capturing Running Processes ……………………………………….. 104

    Table 10: The Life Cycle of an Email …………………………………………………………. 118

    Table 11: Email Headers………………………………………………………………………….. 124

    CMU/SEI-2005-HB-003 ix

    x CMU/SEI-2005-HB-003

    Executive Summary

    First Responders Guide to Computer Forensics: Advanced Topics expands on the technical
    material presented in SEI handbook CMU/SEI-2005-HB-001, First Responders Guide to
    Computer Forensics [Nolan 05]. While the latter presented techniques for forensically sound
    collection of data and reviewed the fundamentals of admissibility pertaining to electronic
    files, this handbook focuses exclusively on more advanced technical operations like process
    characterization and spoofed email. It is designed for experienced security and network pro-
    fessionals who already have a fundamental understanding of forensic methodology. There-
    fore, emphasis is placed on technical procedures and not forensic methodology.

    The first module focuses on log file analysis as well as exploring techniques for using com-
    mon analysis tools such as Swatch and Log Parser. The second module focuses on advanced
    techniques for process characterization, analysis, and volatile data recovery. The third module
    demonstrates advanced usage of the dd command-line utility. Topics include how to slice an
    image and reassemble it with dd, carving out a section of data with dd, and imaging a running
    process with dd. The fourth and final module examines spoofed email messages. This module
    looks at the RFCs for email, describes how email messages are spoofed, and presents some
    techniques for identifying and tracing spoofed email.

    Our focus is to provide system and network administrators with advanced methodologies,
    tools, and procedures for applying sound computer forensics best practices when performing
    routine log file reviews, network alert verifications, and other routine interactions with sys-
    tems and networks. The final goal is to create trained system and network professionals who
    are able to understand the fundamentals of computer forensics so that in the normal course of
    their duties they can safely preserve technical information related to network alerts and other
    security issues. This handbook is not intended to be a training guide for computer forensics
    practitioners, but rather an advanced resource for system and network security professionals
    who are charged with performing first responder functions. The target audience includes sys-
    tem and network administrators, law enforcement, and any information security practitioners
    who find themselves in the role of first responders. The handbook should help the target au-
    dience to

    • install, configure, and use Swatch to analyze log files

    • install, configure, and use Log Parser to analyze log files

    • understand advanced elements of a running process

    • perform an automated collection of volatile data

    • carve out data using the dd command-line utility

    • use the dd command-line utility to slice and reassemble images and files

    CMU/SEI-2005-HB-003 xi

    • understand spoofed email

    • identify reliable information in an email header

    xii CMU/SEI-2005-HB-003

    Abstract

    This handbook expands on the technical material presented in SEI handbook CMU/SEI-
    2005-HB-001, First Responders Guide to Computer Forensics. While the latter presented
    techniques for forensically sound collection of data and explained the fundamentals of admis-
    sibility pertaining to electronic files, this handbook covers more advanced technical opera-
    tions such as process characterization and spoofed email. It describes advanced methodolo-
    gies, tools, and procedures for applying computer forensics when performing routine log file
    reviews, network alert verifications, and other routine interactions with systems and net-
    works. The material will help system and network professionals to safely preserve technical
    information related to network alerts and other security issues.

    CMU/SEI-2005-HB-003 xiii

    xiv CMU/SEI-2005-HB-003

    1 Module 1: Log File Analysis

    © 2005 Carnegie Mellon University

    First Responders Guide to
    Computer Forensics:

    Advanced Topics

    Module 1:
    Log File Analysis

    This module focuses on log file analysis, specifically post-event analysis using Swatch and
    Log Parser. We explain how to install, configure, and execute Swatch and Log Parser and
    provide several sample configurations for each.

    CMU/SEI-2005-HB-003 1

    © 2005 Carnegie Mellon University

    First Responders Guide to
    Computer Forensics

    Swatch

    2 CMU/SEI-2005-HB-003

    © 2005 Carnegie Mellon University 3

    Overview
    Why Swatch?

    Installation

    Configuration

    Execution

    Forensics, in this case, is the act of looking for events
    after they have happened, not performing an
    investigation for law enforcement.

    1.1 Swatch
    The focus is on using Swatch and Log Parser as forensic analysis tools, meaning that they
    will be used on logs after an incident has occurred. If you are planning to use these tech-
    niques on files involved in a law enforcement investigation, please make sure you prepare the
    files according to established best practices before use.

    CMU/SEI-2005-HB-003 3

    © 2005 Carnegie Mellon University 4

    Swatch Log Monitor
    Swatch, the Simple Watcher, is an open
    source log monitoring tool written in Perl for
    use primarily on UNIX/Linux systems.

    Swatch can be used to monitor current logs on
    running servers, or to examine older logs.

    The configuration file contains a list of regular
    expressions to look for and actions to take, if
    any are found, called rules.

    While originally designed for use with syslog
    files, Swatch can be used on any file.

    1.1.1 Swatch Log Monitor
    Log files are useful only if they are read. After an incident, log files often have clues as to
    what happened. However, many servers produce large volumes of log information, often
    spread out over more than one file, so sifting through this data can be tedious and time con-
    suming. As an added problem, different servers have different log formats. If it is necessary
    to compare files, it can be challenging to match up fields.

    Swatch, the Simple Watcher log monitoring tool, is capable of searching a file for a list of
    strings and then performing specific actions when one is found. It was designed to do real-
    time monitoring of server log files but can also be set to process a stand-alone file. Swatch
    was designed to work with syslog files, but it can be used on any file.

    Swatch was written in Perl, and because of the way it is installed it is best used on a Linux
    system. It is an open source tool, and the project is maintained on SourceForge.

    Throughout this module we will consider more heavily the case where Swatch is used to ex-
    amine older log files as opposed to active log files.

    4 CMU/SEI-2005-HB-003

    © 2005 Carnegie Mellon University 5

    Swatch Installation
    Requirements: Perl 5, make utility, tar utility

    Download Swatch from the SourceForge project:
    http://sourceforge.net/projects/swatch/

    Download the throttle patch from http://www.cert.org

    Obtain and install the additional Perl modules:
    Time::HiRes
    Date::Calc
    Date::Format
    File::Tail

    Make Swatch – On the command line, type in progression:
    tar zxvf swatch-3.1.1.tar.gz
    patch –p0 < throttle.patch cd swatch-3.1.1 perl Makefile.PL

    make

    make test

    make install

    1.1.2 Swatch Installation
    Swatch has the same installation process as a Perl module. You download a tarball, uncom-
    press it, expand it, and build it. The tool installs itself in /usr/bin, and you can use it from any
    directory. It also installs a manual page.

    To begin, make sure that Perl 5 is installed on the machine. Later versions of Perl may come
    with some of the necessary modules installed already. You also need the ability to use the
    GNU utility make to fully install Swatch.

    1.1.2.1 Installing Perl Modules

    If your Linux distribution offers versions of the Perl modules needed to support Swatch, it is
    best to get the operating-system-specific ones. Otherwise, you will need to obtain them from
    either the module’s developer’s web site or from a centralized repository such as the Com-
    prehensive Perl Archive Network (CPAN).1 CPAN indexes most of the Perl packages avail-
    able, makes the list searchable, and has them available for download. They also have links to
    the developer’s web site if you would prefer to get the modules straight from the source.

    To install Swatch you need these modules:2

    • File::Tail – in File-Tail-0.99.1.tar.gz

    • Date::Calc – in Date-Calc-5.4.tar.gz

    1 http://www.cpan.org
    2 All module version numbers are current at time of printing.

    CMU/SEI-2005-HB-003 5

    • Date::Parse – in TimeDate-1.16.tar.gz

    • Time::HiRes – in Time-HiRes-1.66.tar.gz

    To support these you might also need

    • Bit::Vector – in Bit-Vector-6.4.tar.gz

    • Carp::Clan – in Carp-Clan-5.3.tar.gz

    Once the tar file is on the machine, you must decompress and expand it before it can be in-
    stalled. Once expanded, read the INSTALL file to make sure that the module has the standard
    installation commands. For these modules, there is a Perl script called Makefile.PL that cre-
    ates a makefile specific to the machine. Next, run the make file three times: once to initialize,
    once to test, and then once to install. After that, the package is ready to use. In order for other
    users to be able to use these modules, they must be installed by root. The commands follow
    in shaded boxes (the normal text is what is sent to the console):

    tar zxvf perlmod.tar.gz

    Lists all the files in perlmod.tar

    cd perlmod
    perl Makefile.PL

    Writing Makefile for Perl::Mod

    make

    Check for errors

    make test

    Look for “All tests successful”

    make install

    Check for errors

    Repeat for the other packages and you are ready to install Swatch itself.

    1.1.2.2 Installing Swatch

    Installing Swatch involves the same procedure as the Perl modules. First, download the tar-
    ball to the local machine from http://sourceforge.net/projects/swatch. There is a patch needed
    to enable the throttle action to fully work. Download that from http://www.cert.org. These
    instructions are for Swatch 3.1.1 (the normal text is what is sent to the console):

    tar zxvf swatch-X.X.X.tar.gz

    Lists all the files in swatch-X.X.X.tar

    patch –p0 < throttle.patch

    6 CMU/SEI-2005-HB-003

    The character after the –p is a zero

    cd swatch-X.X.X
    perl Makefile.PL

    Writing Makefile for swatch

    If Time::HiRes, Date::Calc, or Date::Parse are missing it will say

    make
    Check for errors
    make test
    Look for “All tests successful”
    make install
    Check for errors

    Swatch is now ready to be executed.

    CMU/SEI-2005-HB-003 7

    © 2005 Carnegie Mellon University 6

    Swatch Configuration–Rules 1
    The configuration file contains a list of rules

    Default file location is $HOME/.swatchrc, but it
    can be any name and any location

    The three parts of a rule:
    Event – “watchfor” or “ignore”
    Pattern – regular expression pattern to look for
    Action – what the script does when the pattern
    is found

    1.1.3 Swatch Configuration
    The configuration file is the source of Swatch’s power. It is a text file of rules that are used to
    create the script that will be run against the log file. This topic is about how to develop your
    own configuration file.

    Before you begin adding rules, determine what you are trying to find. Perhaps you want to
    look for Nessus attacks in your Apache log files, or find when people try to use an SMTP
    server as an open relay. Make a list of strings or regular expression patterns that you might
    need. Keep in mind that creating a good configuration file is an iterative process, and it may
    take a few rounds to extract the desired information from the file.

    8 CMU/SEI-2005-HB-003

    © 2005 Carnegie Mellon University 7

    Swatch Configuration–Rules 2
    Rules are looked for in the order they appear in the configuration
    file.

    Example rules:
    ignore /127\.0\.0\.5/

    watchfor /Nessus/
    throttle 0:10:00,key=nessus
    echo

    The first rule looks for the string “127.0.0.5” and ignores any log
    entries that contain it. The second rule looks for log entries that
    contain “Nessus” and echoes them to the console, but only at the
    rate of one entry every 10 minutes.

    Pattern

    Event

    Event
    Pattern

    Action

    Action

    1.1.3.1 The Configuration File Location

    By default, Swatch looks for the configuration file .swatchrc in the home directory. If this file
    is not found, it uses a default configuration of
    watchfor /.*/

    echo

    This merely echoes every message in the log file to the console. This is not any more useful
    than inspecting the log file by hand. To harness the power, a customized configuration file
    should be created (this is addressed in the next section, 1.1.3.2).

    The default name is .swatchrc, but it can be whatever you want. Configuration files for dif-
    ferent types of log files may be identified by a distinct name. One might call their Apache
    configuration file apache.swatchrc and their sendmail sendmail.swatchrc. The file can be
    stored anywhere that is accessible from the command line, not just in the home directory. If a
    different name or location is used for the configuration file, it is added as an argument to the
    command line when Swatch is executed (this is discussed in Section 1.1.4).

    1.1.3.2 Adding Rules to the Configuration File

    Rules are a list of keywords and values that are used to make conditional statements to check
    against, and actions to take if one is true. They have three parts: the event, the pattern, and the
    action(s).

    CMU/SEI-2005-HB-003 9

    1.1.3.2.1 Types of Events

    There are two types of events in Swatch: “watchfor” and “ignore.” The keyword “watchfor”
    looks for the specified pattern in messages in the log file. The “ignore” keyword will skip the
    rest of the rules when a message matches the pattern.

    By default, the first rule that matches a message will be the only rule that acts on that mes-
    sage. This property can be harnessed by using the “ignore” event to filter out messages. For
    example, since you know that the system administrator always uses the same machine to do
    penetration testing, you create an “ignore” rule for messages that come from a specific inter-
    nal IP address, 127.0.0.5, and list the rule for Nessus scans after it so that internal scans will
    not cause alerts. In this case, you will want to put these two events in this order:
    ignore /127\.0\.0\.5/

    watchfor /Nessus/

    throttle 0:10:00,key=nessus

    echo

    1.1.3.2.2 Types of Patterns

    The value for the event keyword is the regular expression pattern that follows on the same
    line. The simplest regular expression is a string to match character by character enclosed in
    “/”; for example, “/Nessus/” matches only the substring “Nessus” if it appears anywhere in
    the line. If there are characters in the search string, the capitalization must be the same for the
    string to match. If you want “nEsSuS” to also match, then you need to put an “i” after the
    second “/” to indicate a case insensitive search.

    Regular Expressions

    A regular expression is a pattern that describes or matches a set of strings [Wikipedia 05d]. It
    is a syntax for describing more general criteria for matching strings than simply matching a
    word in a string. For example, with a regular search you could find the substring “cat” in
    “catapult.” But a regular expression would let you look for a string that starts with “ca” and
    ends with “t,” and you would find both “cat” and “catapult.”

    For more examples of regular expressions in general, see the Wikipedia entry:
    http://en.wikipedia.org/wiki/Regular_expression

    For more examples of regular expressions in Perl, see the Perl manual page:
    http://www.perl.com/doc/manual/html/pod/perlre.html

    1.1.3.2.3 Types of Actions

    Actions are what the script does when it matches a pattern. They range from printing the log
    message to the console to executing a separate script to call a pager. There can be multiple

    10 CMU/SEI-2005-HB-003

    actions associated with each rule. The “ignore” event has its action built in, namely, to stop
    looking at the log entry. The complete list of actions is found in Table 1 [SourceForge 04]:

    Table 1: Actions in Swatch

    Action Description

    echo [modes] Prints the log message to the console.

    Takes an optional value of a text color, a background color, or a
    font weight.

    Possible values are bold, underscore, inverse, blink, black,
    red, green, yellow, blue, magenta, cyan, white, black_h,
    red_h, green_h, yellow_h, blue_h, magenta_h, cyan_h, and
    white_h.

    bell [n] Prints the log message to the console and then rings the bell (\007)
    n times.

    throttle H:M:S

    [,key=log|]

    [,time_from=timestamp]

    [,time_regex=]

    [,threshold=N]

    throttle reduces the number of times an action is performed on
    messages matching the same pattern in the specified duration.

    Hours, minutes, and seconds must all be specified. However, the
    time does not need to be specified if threshold is being used.

    The key is the identifier that is stored to compare to new mes-
    sages. log means use the exact log file, excluding a syslog time-
    stamp, if present, and is the default. Any other string will be used
    exactly as requested/indicated.

    Setting the time_from option to timestamp indicates that the
    time in the log message should be used instead of the system time
    for comparisons. This is best for examining a log file.

    The time_regex lets you specify a regular expression to match the
    timestamp of the message. The default is a regular expression for
    the syslog timestamp.

    The threshold=N acts on the first instance and on every Nth in-
    stance after that. It repeats counting once N messages have been
    found. Each instance is appended with “(threshold N ex-
    ceeded).”

    exec command
    Executes the command listed.

    If arguments are needed, they may be substituted with fields in the
    log message. $N is replaced with the Nth field in the line. A $0 or a
    $* uses the entire message. The –awk-field-separator switch
    must be used during execution (see Section 1.1.4).

    CMU/SEI-2005-HB-003 11

    Action Description

    mail [ad-

    dresses:bob:joe:…]

    [,subject=Subject]

    Sends an email to the address(es) listed with the subject listed con-
    taining the matched log messages. Must have a sendmail compati-
    ble server installed. Default recipient is the user who is running the
    program.

    pipe com-

    mand[,keep_open]

    Pipes the log messages into the command. keep_open keeps the
    pipe open until a different pipe is activated or Swatch exits.

    write [user:user:…] Uses write(1) to send the message to the users listed. The user
    running Swatch is the default.

    continue Tells Swatch to evaluate this message against the rule set.

    quit Causes Swatch to exit.

    when=day:hour This action is a modifier to all the other actions indicating that the
    action should occur only during the times specified. For example,
    when=1-5-8-17 indicates that the action should occur only Mon-
    day-Friday between 8 a.m. and 5 p.m.

    The exec command can be used to write log entries to a file. Redirection from the console
    does not work because there are unprintable characters on the command line that are printed
    in the resulting file and are meaningless and in the way. Use this action:

    exec “echo $* >> output.txt”

    When examining a file, the most useful actions will be echo, exec, and throttle. The others are
    more oriented for when you need to be alerted to a new development in real time.

    It is also possible to include Perl in the configuration file if you want to do something such as
    define a regular expression for repeated use. Start each line with “perlcode” and end it with a
    semicolon.

    The throttle command can be very powerful. It will take some practice to get the right bal-
    ance of regular expressions to search for timing and to determine whether throttle or thresh-
    old is better.

    For the regular expressions in the time_regex, all backslashes must be escaped, (e.g., put in
    two instead of one). Regular expressions on the action line with commas get cut off, so you
    need to put the expression in a perlcode. This includes both IIS formats. For example:
    perlcode my $iis_time = “(\d{4}-\d{2}-\d{2}\s+\d{1,2}:\d{2}:\d{2}\s)”;

    watchfor /WEBROOT DIRECTORY TRANSVERSAL/

    throttle 0:04:00,key=web,time_from=timestamp,time_regex=$iis_time

    echo blue

    12 CMU/SEI-2005-HB-003

    Some log formats may not have time_regex. Table 2 lists time_regexes for the log files on
    popular services:

    Table 2: time_regex for Popular Services

    Log File Timestamp Regular Expression

    Apache
    access_log

    04/Mar/2005:11:38:45 (\\d{2}\\/\\w{3}\\/\\d{4}:\\d{2}:\\d{2}:\\d{2})

    Apache
    error_log;
    ssh logs

    Fri Mar 04 11:38:51 2005 (\\w{3}\\s+\\w{3}\\s+\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+\\d{4})

    IIS 6.0 and
    later

    03/04/05, 11:38:51 (\d{2}\/\d{2}\/\d{2},\s+\d{1,2}:\d{2}:\d{2}\s)

    IIS 5.*,
    W3C Ex-
    tended

    2005-03-14 11:38:51 (\d{4}-\d{2}-\d{2}\s+\d{1,2}:\d{2}:\d{2}\s)

    The when command can be useful for identifying events that occur at abnormal times. Use it
    to look for login attempts in the middle of the night.

    The following is an example configuration file for a syslog setup that has two machines,
    named “server” and “client,” logging to one file. The central syslog server resides on the
    server. All facilities on the client log to this file. The client is running the default applications.
    The server logs most facilities to the file and is running Apache (httpd) and Snort, in addition
    to the basics.

    # Copies all of the entries from the client to a separate file

    watchfor / client /

    exec “echo $* >> client.log” #echoes the log entry to a file

    # Prints one entry every 4 minutes (based on the time in the logfile #for

    any entries containing a Nessus attack keyword.

    watchfor /WEBROOT DIRECTORY TRANSVERSAL/

    throttle 0:04:00,key=webroot,time_from=timestamp

    echo blue

    # Searches for snort followed by portscan somewhere in the log entry

    # Prints the first entry and then every 6th one both to the console and

    # a separate file

    watchfor /snort.*portscan/

    throttle threshold=6,key=ps

    echo red

    exec “echo $* >> portscan.log”

    CMU/SEI-2005-HB-003 13

    Figure 1 is an example run of the configuration file on a syslog file (“(portscan)” and
    “(http_inspect)” distinguish the different types of messages).

    Figure 1: Example Run of the Swatch Configuration File

    14 CMU/SEI-2005-HB-003

    © 2005 Carnegie Mellon University 8

    Swatch Execution

    Swatch is run from the command line.
    swatch -c .swatchrc -f file.log

    This runs Swatch using the file .swatchrc as the configuration file
    on file.log.
    Swatch can be run on only one file at a time, but multiple
    instances of Swatch can be running at once.

    Accepts its input from this command-p command

    Tail the specific file (/var/log/messages is the default)-t file.log
    Examine the specific file-f file.log

    Name a specific configuration file-c config.file
    UseSwitch

    Examine this fileConfiguration file

    1.1.4 Swatch Execution
    Swatch is run on the command line and has many options to specialize the execution. You can
    identify the configuration file, the log file, how to monitor the log file, and even what charac-
    ter(s) indicate a new log message. While most options will be listed, the focus is on the op-
    tions that relate to running Swatch on a log file in a single pass. More information about all
    the options can be found in the manual page.

    -c filename or –config-file=filename
    Indicates where the configuration file is. The default location is $HOME/.swatchrc.

    -f filename or –examine=filename
    Indicates that Swatch should perform a single pass on the log file.

    -t filename or –tail-file=filename
    This option enables Swatch to monitor a file as a service continues to log to it. This action is
    the default, so if none of -f, -p, or -t is given, Swatch will tail either “/var/log/messages” or
    “/var/log/syslog.”

    -p command or –read-pipe=command
    Monitors the data that is being piped in from the given command.

    –awk-field-syntax

    Tells Swatch to use the syntax for awk expressions. It is needed when the exec action is used.

    CMU/SEI-2005-HB-003 15

    –input-record-separator=regular_expression

    This option indicates that the default record separator of carriage return should be replaced
    with the regular expression listed.

    Other options include –help and –version, which respectively give usage information and
    the current version; –script-dir=path, which indicates where the temporary script should
    be stored if not in the user’s home directory; and –restart-time=hh:mm[am|pm], which
    tells Swatch to restart at a particular time.

    The most common usage will be
    swatch -c .swatchrc -f log_file

    Remember to specify the complete path of the configuration file or the log file if either one is
    not located in the local directory.

    16 CMU/SEI-2005-HB-003

    © 2005 Carnegie Mellon University 9

    Summary

    Swatch is a simple log monitor designed to run
    regular expressions against a text log file.

    an effective tool for finding interesting or
    anomalous events
    configured easily to watch for any type of entry
    in any type of file

    Many actions can be taken on matching
    message logs, but for analysis “echo” will be
    used most often.

    1.1.5 Summary
    Swatch can be an effective tool for sifting through log files to find interesting or anomalous
    events. The results serve as a jumping off point for further inspection of the files by leading
    you directly to areas of interest. Or it can be used to filter out entries that you know can be
    excluded so as to reduce the amount of material to examine by hand. Swatch can also be used
    on other files, such as VMWare virtual disk files and disk images, to efficiently find strings in
    data.

    CMU/SEI-2005-HB-003 17

    © 2005 Carnegie Mellon University
    First Responders Guide to
    Computer Forensics

    Microsoft Log Parser

    1.2 Microsoft Log Parser 2.2
    This topic is an overview of the installation, configuration, and usage of Microsoft’s Log
    Parser 2.2. The focus is on using Log Parser as a forensic analysis tool, meaning that it will
    be used on logs after an incident has occurred. If you are planning to use these techniques on
    files involved in a law enforcement investigation, please make sure you prepare the files ac-
    cording to established best practices.

    18 CMU/SEI-2005-HB-003

    © 2005 Carnegie Mellon University 2

    Overview
    Why Log Parser?

    Installation

    Writing Queries

    Execution

    Forensics in this case is the act of looking for
    events after they have happened, not
    performing an investigation for law
    enforcement

    CMU/SEI-2005-HB-003 19

    © 2005 Carnegie Mellon University 3

    Microsoft Log Parser 2.2
    Command line tool from Microsoft to process log files
    using SQL-like queries

    Can read in many formats and many types of log files

    Output available in many formats—from text to XML
    files to database storage

    Easy generation of HTML reports and MS Office
    objects

    Log Parser functions usable in other scripts

    1.2.1 Microsoft Log Parser Features
    Microsoft Log Parser 2.2 is the most recent incarnation of Microsoft’s log analysis tool. Re-
    leased in January 2005, it contains many improvements and additions to make it useful to
    anyone with a log file to process. Log Parser is free to download and use. It is a command
    line tool; there is no GUI to make creating commands easier.

    Log Parser uses SQL-like queries to sort through log files. It is very flexible and can be used
    to read any text based file, file system objects, registries, and database formats.

    Log Parser can format the text output into a variety of formats. It can also send output di-
    rectly to a syslog server, a database, and MS Office charts, and can be used to create HTML
    reports from a template.

    Log Parser can also be used in other programs and scripts to bring its processing power to
    other applications.

    20 CMU/SEI-2005-HB-003

    © 2005 Carnegie Mellon University 4

    Log Parser Installation
    Requirements: Windows 2000, 2003, or XP
    Professional

    Download Log Parser from Microsoft’s website

    Double-click on the setup file and follow the
    instructions

    The Unofficial Log Parser Support Site is an
    excellent resource: http://www.logparser.com/

    1.2.2 Log Parser Installation
    Log Parser is a Microsoft Windows application that runs on Windows 2000, 2003, and Win-
    dows XP Professional. Installation is quick and easy.

    Download the file from the Microsoft website. In addition to the Microsoft website, The Un-
    official Log Parser Support Site maintains a current link to the setup file on its home page:
    http://www.logparser.com. That site is also an excellent resource for Log Parser information.

    Once you’ve downloaded the file, double-click on the setup file, LogParser.msi. Follow the
    instructions in the Setup Wizard and Log Parser is installed.

    CMU/SEI-2005-HB-003 21

    © 2005 Carnegie Mellon University 5

    Log Parser Input and Output
    Log Parser can read many text-based log formats

    Use the switch -i:TYPE to indicate file type
    Default is determined from the input file type
    Type LogParser -h -i:TYPE for more information
    on a specific type

    Output can be formatted into text files or MS Office
    objects or sent to other programs

    Use the switch -o:TYPE to indicate type of report
    Default is determined from the name of the output file
    Type LogParser -h -o:TYPE for more information
    on a specific type

    1.2.3 Log Parser Input and Output
    Log Parser has a variety of built-in text-based formats that it can use to easily parse files and
    several output formats it can create. Many of them correspond to the log formats of popular
    applications, though it is Windows-centric.

    1.2.3.1 Input Formats

    To specify an import format, use the switch -i:TYPE, where TYPE is one of the built-in types.
    The default input type is determined by Log Parser based on the file extension in the FROM
    clause. Table 3 lists many of the types and application logs for which each can be used. More
    information and usage examples for each one can be found by using the command line help:
    LogParser -h -i:TYPE. Other types can be found under LogParser -h.

    Table 3: Common Input Formats

    Type Uses Selected Parameters

    IISW3C IIS W3C Extended Log Format, primar-
    ily IIS 5.X logs and older

    n/a

    IIS Microsoft IIS log format, mostly used
    with version 6.0 and newer

    n/a

    NCSA NCSA Common, Combined, and Ex-
    tended Log formats, for Apache logs

    n/a

    22 CMU/SEI-2005-HB-003

    Type Uses Selected Parameters

    CSV Text files with comma-separated values -headerRow [ON|OFF] – for speci-
    fying if there is a header row

    -iTsFormat
    – for specifying timestamps other than
    “yyyy-MM-dd hh:mm:ss”

    TSV Tab or space separated values -headerRow [ON|OFF] – for speci-
    fying if there is a header row

    -iSeparator
    Character that indicates a new field;
    can be any character, “spaces,”
    “space,” or “tab”

    W3C Generic W3C log format -iSeparator
    Character that indicates a new field;
    can be any character, “spaces,”
    “space,” or “tab”

    XML XML formatted logs -rootXPath – XPath query
    of nodes to be considered roots

    EVT Windows Event Log -fullText [ON|OFF] – Use the full
    text message

    NETMON NetMon captures files -fMode [TCPIP|TCPConn] – Field
    mode, each record is a single packet or
    a single connection

    REG Registry keys and values n/a

    ADS Active Directory objects -objClass – Spe-
    cific class for object mode

    -username – user name for
    AD access

    -password – password for
    the specified user

    TEXTLINE Parses entire lines of text files n/a

    TEXTWORD Parses single words out of generic text
    files

    n/a

    FS File system properties n/a

    COM Custom COM input format -iProgID – version inde-
    pendent Prog ID of the COM plug-in

    CMU/SEI-2005-HB-003 23

    1.2.3.2 Output Formats

    To specify an output format to create, use the switch -o:TYPE. Output can be in several text
    formats as well as some non-text ones. The default, for when no INTO clause is stated, is to
    print the list using NAT to STDOUT. When the INTO clause is stated, if there is no -o:TYPE,
    then Log Parser will attempt to guess from the file extension. Table 4 lists many of the types.
    More information and usage examples can be found by using the command line help: Log-
    Parser -h -o:TYPE. Other types can be found under LogParser -h.

    Table 4: Output Formats

    Type Format Special Parameters

    CSV Comma-separated values -headers [ON|OFF|AUTO] – Write
    field names as the first line; AUTO
    won’t write headers when appending to
    an existing file

    TSV Tab-separated values -headers [ON|OFF|AUTO] – Write
    field names as the first line; AUTO
    won’t write headers when appending to
    an existing file

    -oSeparator
    Separator between fields: ,
    “space,” or “tab”

    XML XML output format -rootName
    Name of the Root element

    DATAGRID ASP.NET data type for displaying
    tabular data

    -rpt – Rows to
    print before pausing

    CHART Microsoft Office Chart web compo-
    nent; MS Office must be installed for
    use

    -chartType – One
    of the designated chart types

    SYSLOG Sends output to a syslog server -hostName – syslog
    server name

    NAT Native format – tabular view of the
    records

    -rtp – Rows to
    print before pausing

    W3C W3C Extended Log format -rtp – Rows to
    print before pausing

    IIS IIS Log format -rtp – Rows to
    print before pausing

    24 CMU/SEI-2005-HB-003

    Type Format Special Parameters

    SQL Sends the output to a SQL table -server – Server
    the database is on

    -database
    Name of the database

    TPL Output a report in a user-specified tem-
    plate

    -tpl