This file is indexed.

/usr/bin/grokevt-parselog is in grokevt 0.5.0-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#! /usr/bin/python

# This script will take an input Windows Event Log and parse it to
# stdout as ASCII text.  This is particularly useful for forensics being
# conducted on an evidence drive under *NIX.
#
# The original code was written in PHP by Jamie French.  It has been
# since ported to Python and extended by Timothy Morgan.
#
# For the original PHP version, please see:
#http://www.whitehats.ca/main/members/Malik/malik_eventlogs/malik_eventlogs.html
# 
# Copyright (C) 2005-2007,2011 Timothy D. Morgan
# Copyright (C) 2004 Jamie French
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation version 3 of the
# License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# vi:set tabsize=4:
# $Id: grokevt-parselog 119 2011-06-20 17:14:14Z tim $


import sys
import string
import os
import types
import struct
import re
import time
import csv
from grokevt import *


meta_fields=('header_first_off', 'cursor_first_off',
             'header_first_num', 'cursor_first_num',
             'header_next_off', 'cursor_next_off',
             'header_next_num', 'cursor_next_num',
             'header_file_size', 'real_file_size',
             'retention_period',
             'flag_dirty', 'flag_wrapped',
             'flag_logfull', 'flag_primary')

meta_header={'header_first_off':"HEADER_FIRST_OFFSET",
             'cursor_first_off':"CURSOR_FIRST_OFFSET",
             'header_first_num':"HEADER_FIRST_NUMBER",
             'cursor_first_num':"CURSOR_FIRST_NUMBER",
             'header_next_off':"HEADER_NEXT_OFFSET",
             'cursor_next_off':"CURSOR_NEXT_OFFSET",
             'header_next_num':"HEADER_NEXT_NUMBER",
             'cursor_next_num':"CURSOR_NEXT_NUMBER",
             'header_file_size':"HEADER_FILE_SIZE",
             'real_file_size':"REAL_FILE_SIZE",
             'retention_period':"RETENTION_PERIOD",
             'flag_dirty':"DIRTY", 'flag_wrapped':"WRAPPED",
             'flag_logfull':"LOGFULL", 'flag_primary':"PRIMARY"}

log_fields =("msg_num","event_type",
             "date_created","date_written",
             "source","category",
             "event_id","event_rva",
             "user","computer",
             "message","strings","data")

log_header = {'msg_num':"MSG_NUM",'event_type':"EVENT_TYPE",
              'date_created':"DATE_CREATED",'date_written':"DATE_WRITTEN",
              'source':"SOURCE",'category':"CATEGORY",
              'event_id':"EVENT_ID",'event_rva':"EVENT_RVA",
              'user':"USER",'computer':"COMPUTER",
              'message':"MESSAGE",'strings':"STRINGS",'data':"DATA"}


def usage():
    command = os.path.basename(sys.argv[0])
    sys.stderr.write(
        "USAGE:\n"\
        +"  %s -?|--help\n" % command\
        +"  %s -l <DATABASE_DIR>\n" % command\
        +"  %s -m <DATABASE_DIR> <LOG_TYPE>\n" % command\
        +"  %s [-v] [-H] [-h] <DATABASE_DIR> <LOG_TYPE>\n\n"\
        % command\
        +"This program parses a windows event log and prints a\n"\
        +"CSV version of the log to stdout.  Please see the man\n"\
        +"page for more information.\n")


# Globals influenced by command line options
mode_loglist = 0
mode_meta = 0
print_verbose = 0
print_header = 1
DB_PATH = None
LOG = None


# Parse command line
argv_len = len(sys.argv)
if (argv_len < 3) or (sys.argv[1] == '-?') or (sys.argv[1] == '--help'):
    usage()
    sys.exit(os.EX_OK)
elif sys.argv[1] == '-l':
    if argv_len == 3:
        mode_loglist = 1
        DB_PATH=sys.argv[2]
    else:
        usage()
        sys.stderr.write("ERROR: Incorrect usage for log list mode.\n")
        sys.exit(os.EX_USAGE)
elif sys.argv[1] == '-m':
    if argv_len == 4:
        mode_meta = 1
        DB_PATH=sys.argv[2]
        LOG=sys.argv[3]
    else:
        usage()
        sys.stderr.write("ERROR: Incorrect usage for meta information mode.\n")
        sys.exit(os.EX_USAGE)
else:
    if (argv_len >= 3):
        DB_PATH=sys.argv[argv_len-2]
        LOG=sys.argv[argv_len-1]

        for option in sys.argv[1:argv_len-2]:
            if option == '-v':
                print_verbose = 1
            elif option == '-H':
                print_header = 0
            elif option == '-h':
                print_header = 1
            else:
                usage()
                sys.stderr.write("ERROR: Unrecognized option '%s'.\n" % option)
                sys.exit(os.EX_USAGE)
    else:
        usage()
        sys.stderr.write("ERROR: Incorrect usage for log parse command.\n")
        sys.exit(os.EX_USAGE)


if mode_loglist:
    try:
        logs = os.listdir("%s/services" % DB_PATH)
        for l in logs:
            print(l)
    except Exception as inst:
        sys.stderr.write("%s\n" % inst)
        sys.stderr.write("ERROR: Could not list services directory.\n")
        sys.stderr.write("       Did you run grokevt-builddb first?\n")
        sys.exit(os.EX_OSFILE)
    sys.exit(os.EX_OK)

try:
    if print_verbose:
        sys.stderr.write("INFO: Opening message repository '%s'.\n" % DB_PATH)
    msg_repo = messageRepository(DB_PATH, LOG)
except Exception as inst:
    sys.stderr.write("%s\n" % inst)
    sys.stderr.write("ERROR: Could not read message repository.\n")
    sys.stderr.write("       Did you specify the correct DATABASE_DIR?\n")
    sys.stderr.write("       Did you run grokevt-builddb first?\n")
    sys.exit(os.EX_OSFILE)


evt_file = None
evt_filename = "%s/logs/%s.evt" % (DB_PATH, LOG)
try:
    if print_verbose:
        sys.stderr.write("INFO: Opening event log file at '%s'.\n"
                         % evt_filename)
    evt_file = evtFile(evt_filename, msg_repo)
except Exception as inst:
    sys.stderr.write("%s\n" % inst)
    sys.stderr.write("ERROR: Could not open log file.\n")
    sys.stderr.write("       Did grokevt-builddb finish without errors?\n")
    sys.exit(os.EX_OSFILE)


evt_size = evt_file.size()
# Begin parsing logic
if mode_meta:
    csvwriter = csv.DictWriter(sys.stdout, meta_fields, '', 'ignore')
    row = {'header_first_off':"Unknown",
           'cursor_first_off':"Unknown",
           'header_first_num':"Unknown",
           'cursor_first_num':"Unknown",
           'header_next_off':"Unknown",
           'cursor_next_off':"Unknown",
           'header_next_num':"Unknown",
           'cursor_next_num':"Unknown",
           'header_file_size':"Unknown",
           'real_file_size':evt_size,
           'retention_period':"Unknown",
           'flag_dirty':"Unknown",
           'flag_wrapped':"Unknown",
           'flag_logfull':"Unknown",
           'flag_primary':"Unknown"}
    
    if evt_file.header:
        row['header_first_off'] = evt_file.header['first_off']
        row['header_first_num'] = evt_file.header['first_num']
        row['header_next_off']  = evt_file.header['next_off']
        row['header_next_num']  = evt_file.header['next_num']
        row['header_file_size'] = evt_file.header['file_size']
        row['retention_period'] = evt_file.header['retention']
        row['flag_dirty']       = evt_file.header['flag_dirty']
        row['flag_wrapped']     = evt_file.header['flag_wrapped']
        row['flag_logfull']     = evt_file.header['flag_logfull']
        row['flag_primary']     = evt_file.header['flag_primary']

    if evt_file.cursor:        
        row['cursor_first_off'] = evt_file.cursor['first_off']
        row['cursor_first_num'] = evt_file.cursor['first_num']
        row['cursor_next_off']  = evt_file.cursor['next_off']
        row['cursor_next_num']  = evt_file.cursor['next_num']

    csvwriter.writerow(meta_header)
    csvwriter.writerow(row)
    sys.exit(os.EX_OK)


def encodeRec(rec):
    for k in rec.keys():
        if k == 'strings':
            rec[k] = '|'.join((quoteUnicode(s) 
                               for s in rec[k]))
            rec[k] = rec[k].strip('|')
        elif isinstance(rec[k], bytes) or isinstance(rec[k], bytearray):
            rec[k] = quoteBinary(rec[k])
        elif not isinstance(rec[k], int):
            rec[k] = quoteUnicode(rec[k])

    return rec


csvwriter = csv.DictWriter(sys.stdout, log_fields, '', 'ignore')
if print_header:
    csvwriter.writerow(log_header)

if print_verbose:
    sys.stderr.write("INFO: Now parsing file.\n")
    
if evt_file.header and evt_file.header['flag_dirty']:
    sys.stderr.write("WARNING: Log file marked as dirty.\n")

if (evt_file.header == None) or (evt_file.cursor == None):
    sys.stderr.write("WARNING: Naive parsing enabled.\n")

    record_type = None
    while record_type != 'wrapped-log':
        # First, try to find the first log record. This will skip over any split
        # log records at the beginning of the file.
        record_type = evt_file.guessRecordType()
        while ((evt_file.guessRecordType()=='unknown')
               and (evt_file.tell()<evt_size)):
            evt_file.seek(1,1)
            record_type = evt_file.guessRecordType()

        if evt_file.tell() >= evt_size:
            break

        # Next walk through the file hoping to stay aligned with proper records
        # We skip over anything that looks like a header or cursor, and bail out
        # as soon as we run across a non-record.
        if record_type in ('log', 'wrapped-log'):
            # XXX: catch exceptions?
            rec = evt_file.getLogRecord()
            rec = encodeRec(rec)        
            csvwriter.writerow(rec)

        elif record_type == 'cursor':
            sys.stderr.write("WARNING: Skipping potential cursor record "
                            +"at offset %d.\n" % evt_file.tell())
            evt_file.seek(evt_file.tell()+cursor_size)
            
        elif record_type == 'header':
            sys.stderr.write("WARNING: Skipping potential header record "
                             +"at offset %d.\n" % evt_file.tell())
            evt_file.seek(evt_file.tell()+header_size)
        
else:
    for i in range(evt_file.cursor['first_num'],evt_file.cursor['next_num']):
        # XXX: catch exceptions?
        rec = evt_file.getLogRecord()
        rec = encodeRec(rec)
        
        csvwriter.writerow(rec)