Windows-III 中的重要工件


本章将解释调查人员在 Windows 上进行取证分析期间可以获得的更多工件。

事件日志


顾名思义,Windows 事件日志文件是存储重要事件的特殊文件,例如用户登录计算机时、程序遇到错误时、关于系统更改、RDP 访问、应用程序特定事件等。网络调查人员总是对事件感兴趣日志信息,因为它提供了大量有关系统访问的有用历史信息。在以下 Python 脚本中,我们将处理旧版和当前的 Windows 事件日志格式。

对于 Python 脚本,我们需要安装第三方模块,即 pytsk3、pyewf、unicodecsv、pyevt 和 pyevt X。我们可以按照以下步骤从事件日志中提取信息:

  • 首先,搜索与输入参数匹配的所有事件日志。

  • 然后,执行文件签名验证。

  • 现在,使用适当的库处理找到的每个事件日志。

  • 最后,将输出写入电子表格。

Python代码

让我们看看如何为此目的使用 Python 代码:

首先,导入以下 Python 库:

from __future__ import print_function
import argparse
import unicodecsv as csv
import os
import pytsk3
import pyewf
import pyevt
import pyevtx
import sys
from utility.pytskutil import TSKUtil

现在,为命令行处理程序提供参数。请注意,这里它将接受三个参数——第一个是证据文件的路径,第二个是证据文件的类型,第三个是要处理的事件日志的名称。

if __name__ == "__main__":
    parser = argparse.ArgumentParser('Information from Event Logs')
    parser.add_argument("EVIDENCE_FILE", help = "Evidence file path")
    parser.add_argument("TYPE", help = "Type of Evidence",choices = ("raw", "ewf"))
    parser.add_argument(
        "LOG_NAME",help = "Event Log Name (SecEvent.Evt, SysEvent.Evt, ""etc.)")
   
    parser.add_argument(
        "-d", help = "Event log directory to scan",default = "/WINDOWS/SYSTEM32/WINEVT")
   
    parser.add_argument(
        "-f", help = "Enable fuzzy search for either evt or"" evtx extension", action = "store_true")
    args = parser.parse_args()
   
    if os.path.exists(args.EVIDENCE_FILE) and \ os.path.isfile(args.EVIDENCE_FILE):
        main(args.EVIDENCE_FILE, args.TYPE, args.LOG_NAME, args.d, args.f)
    else:
        print("[-] Supplied input file {} does not exist or is not a ""file".format(args.EVIDENCE_FILE))
    sys.exit(1)

现在,通过创建我们的事件日志来查询用户提供的路径是否存在 TSKUtil 目的。它可以在帮助下完成 main() 方法如下:

def main(evidence, image_type, log, win_event, fuzzy):
    tsk_util = TSKUtil(evidence, image_type)
    event_dir = tsk_util.query_directory(win_event)
   
    if event_dir is not None:
        if fuzzy is True:
            event_log = tsk_util.recurse_files(log, path=win_event)
    else:
        event_log = tsk_util.recurse_files(log, path=win_event, logic="equal")
   
    if event_log is not None:
        event_data = []
        for hit in event_log:
            event_file = hit[2]
            temp_evt = write_file(event_file)

现在,我们需要执行签名验证,然后定义一个将整个内容写入当前目录的方法:

def write_file(event_file):
    with open(event_file.info.name.name, "w") as outfile:
        outfile.write(event_file.read_random(0, event_file.info.meta.size))
    return event_file.info.name.name
        if pyevt.check_file_signature(temp_evt):
            evt_log = pyevt.open(temp_evt)
            print("[+] Identified {} records in {}".format(
                evt_log.number_of_records, temp_evt))
         
            for i, record in enumerate(evt_log.records):
                strings = ""
                for s in record.strings:
                    if s is not None:
                        strings += s + "\n"
                event_data.append([
                    i, hit[0], record.computer_name,
                    record.user_security_identifier,
                    record.creation_time, record.written_time,
                    record.event_category, record.source_name,
                    record.event_identifier, record.event_type,
                    strings, "",
                    os.path.join(win_event, hit[1].lstrip("// "))
                ])
        elif pyevtx.check_file_signature(temp_evt):
            evtx_log = pyevtx.open(temp_evt)
            print("[+] Identified {} records in {}".format(
                evtx_log.number_of_records, temp_evt))
            for i, record in enumerate(evtx_log.records):
                strings = ""
                for s in record.strings:
			   if s is not None:
                    strings += s + "\n"
            event_data.append([
                i, hit[0], record.computer_name,
                record.user_security_identifier, "",
                record.written_time, record.event_level,
                record.source_name, record.event_identifier,
                "", strings, record.xml_string,
                os.path.join(win_event, hit[1].lstrip("// "))
        ])
        else:
            print("[-] {} not a valid event log. Removing temp" file...".format(temp_evt))
            os.remove(temp_evt)
        continue
        write_output(event_data)
    else:
        print("[-] {} Event log not found in {} directory".format(log, win_event))
        sys.exit(3)
else:
    print("[-] Win XP Event Log Directory {} not found".format(win_event))
    sys.exit(2

最后,定义一个将输出写入电子表格的方法,如下所示:

def write_output(data):
    output_name = "parsed_event_logs.csv"
    print("[+] Writing {} to current working directory: {}".format(
        output_name, os.getcwd()))
   
    with open(output_name, "wb") as outfile:
        writer = csv.writer(outfile)
        writer.writerow([
            "Index", "File name", "Computer Name", "SID",
            "Event Create Date", "Event Written Date",
            "Event Category/Level", "Event Source", "Event ID",
            "Event Type", "Data", "XML Data", "File Path"
        ])
        writer.writerows(data)

成功运行上述脚本后,我们将在电子表格中获取事件日志信息。

互联网历史


互联网历史对取证分析员非常有用;因为大多数网络犯罪只发生在互联网上。当我们讨论 Windows 取证时,让我们看看如何从 Internet Explorer 中提取 Internet 历史记录,而 Internet Explorer 默认随 Windows 提供。

在 Internet Explorer 上,Internet 历史记录保存在 索引.dat 文件。让我们看看一个 Python 脚本,它将从 索引.dat file.

我们可以按照下面给出的步骤从 索引.dat files:

  • 首先,搜索 索引.dat 系统内的文件。

  • 然后,通过迭代从该文件中提取信息。

  • 现在,将所有这些信息写入 CSV 报告。

Python代码

让我们看看如何为此目的使用 Python 代码:

首先,导入以下 Python 库:

from __future__ import print_function
import argparse

from datetime import datetime, timedelta
import os
import pytsk3
import pyewf
import pymsiecf
import sys
import unicodecsv as csv

from utility.pytskutil import TSKUtil

现在,为命令行处理程序提供参数。请注意,这里它将接受两个参数——第一个是证据文件的路径,第二个是证据文件的类型:

if __name__ == "__main__":
parser = argparse.ArgumentParser('getting information from internet history')
    parser.add_argument("EVIDENCE_FILE", help = "Evidence file path")
    parser.add_argument("TYPE", help = "Type of Evidence",choices = ("raw", "ewf"))
    parser.add_argument("-d", help = "Index.dat directory to scan",default = "/USERS")
    args = parser.parse_args()
   
    if os.path.exists(args.EVIDENCE_FILE) and os.path.isfile(args.EVIDENCE_FILE):
        main(args.EVIDENCE_FILE, args.TYPE, args.d)
    else:
        print("[-] Supplied input file {} does not exist or is not a ""file".format(args.EVIDENCE_FILE))
        sys.exit(1)

现在,通过创建一个对象来解释证据文件 TSKUtil 并遍历文件系统以查找 index.dat 文件。可以通过定义 main() 功能如下:

def main(evidence, image_type, path):
    tsk_util = TSKUtil(evidence, image_type)
    index_dir = tsk_util.query_directory(path)
   
    if index_dir is not None:
        index_files = tsk_util.recurse_files("index.dat", path = path,logic = "equal")
      
        if index_files is not None:
            print("[+] Identified {} potential index.dat files".format(len(index_files)))
            index_data = []
         
            for hit in index_files:
                index_file = hit[2]
                temp_index = write_file(index_file)

现在,定义一个函数,借助该函数,我们可以将 index.dat 文件的信息复制到当前工作目录,然后可以由第三方模块处理:

def write_file(index_file):
    with open(index_file.info.name.name, "w") as outfile:
    outfile.write(index_file.read_random(0, index_file.info.meta.size))
return index_file.info.name.name

现在,使用以下代码在内置函数的帮助下执行签名验证,即 check_file_signature()

if pymsiecf.check_file_signature(temp_index):
    index_dat = pymsiecf.open(temp_index)
    print("[+] Identified {} records in {}".format(
    index_dat.number_of_items, temp_index))

    for i, record in enumerate(index_dat.items):
    try:
        data = record.data
    if data is not None:
        data = data.rstrip("\x00")
    except AttributeError:
   
    if isinstance(record, pymsiecf.redirected):
        index_data.append([
            i, temp_index, "", "", "", "", "",record.location, "", "", record.offset,os.path.join(path, hit[1].lstrip("// "))])
   
    elif isinstance(record, pymsiecf.leak):
        index_data.append([
            i, temp_index, record.filename, "","", "", "", "", "", "", record.offset,os.path.join(path, hit[1].lstrip("// "))])
    continue
   
    index_data.append([
        i, temp_index, record.filename,
        record.type, record.primary_time,
        record.secondary_time,
        record.last_checked_time, record.location,
        record.number_of_hits, data, record.offset,
        os.path.join(path, hit[1].lstrip("// "))
    ])
    else:
        print("[-] {} not a valid index.dat file. Removing "
        "temp file..".format(temp_index))
        os.remove("index.dat")
        continue
        os.remove("index.dat")
        write_output(index_data)
    else:
        print("[-] Index.dat files not found in {} directory".format(path))
    sys.exit(3)
    else:
        print("[-] Directory {} not found".format(win_event))
    sys.exit(2)

现在,定义一个将输出打印到 CSV 文件中的方法,如下所示:

def write_output(data):
    output_name = "Internet_Indexdat_Summary_Report.csv"
    print("[+] Writing {} with {} parsed index.dat files to current "
    "working directory: {}".format(output_name, len(data),os.getcwd()))
   
    with open(output_name, "wb") as outfile:
        writer = csv.writer(outfile)
        writer.writerow(["Index", "File Name", "Record Name",
        "Record Type", "Primary Date", "Secondary Date",
        "Last Checked Date", "Location", "No. of Hits",
        "Record Data", "Record Offset", "File Path"])
        writer.writerows(data)

运行上述脚本后,我们将从 CSV 文件中的 index.dat 文件中获取信息。

卷影副本


卷影副本是 Windows 中包含的用于手动或自动获取计算机文件的备份副本或快照的技术。它也称为卷快照服务或卷影服务(VSS)。

在这些 VSS 文件的帮助下,取证专家可以获得一些关于系统如何随时间变化以及计算机上存在哪些文件的历史信息。卷影复制技术要求文件系统为 NTFS 以创建和存储卷影副本。

在本节中,我们将看到一个 Python 脚本,它有助于访问取证图像中存在的任何卷影副本。

对于 Python 脚本,我们需要安装第三方模块,即 pytsk3、pyewf、unicodecsv、pyvshadow and vss .我们可以按照下面给出的步骤从 VSS 文件中提取信息

  • 首先,访问原始映像卷并识别所有 NTFS 分区。

  • 然后,通过迭代从该卷影副本中提取信息。

  • 现在,最后我们需要在快照中创建一个数据文件列表。

Python代码

让我们看看如何为此目的使用 Python 代码:

首先,导入以下 Python 库:

from __future__ import print_function
import argparse
from datetime import datetime, timedelta

import os
import pytsk3
import pyewf
import pyvshadow
import sys
import unicodecsv as csv

from utility import vss
from utility.pytskutil import TSKUtil
from utility import pytskutil

现在,为命令行处理程序提供参数。这里它将接受两个参数——第一个是证据文件的路径,第二个是输出文件。

if __name__ == "__main__":
    parser = argparse.ArgumentParser('Parsing Shadow Copies')
    parser.add_argument("EVIDENCE_FILE", help = "Evidence file path")
    parser.add_argument("OUTPUT_CSV", help = "输出 CSV with VSS file listing")
    args = parser.parse_args()

现在,验证输入文件路径的存在,并将目录与输出文件分开。

directory = os.path.dirname(args.OUTPUT_CSV)
if not os.path.exists(directory) and directory != "":
    os.makedirs(directory)
if os.path.exists(args.EVIDENCE_FILE) and \ os.path.isfile(args.EVIDENCE_FILE):
    main(args.EVIDENCE_FILE, args.OUTPUT_CSV)
else:
    print("[-] Supplied input file {} does not exist or is not a "
    "file".format(args.EVIDENCE_FILE))
   
    sys.exit(1)

现在,通过创建 TSKUtil 目的。它可以在帮助下完成 main() 方法如下:

def main(evidence, output):
    tsk_util = TSKUtil(evidence, "raw")
    img_vol = tsk_util.return_vol()

if img_vol is not None:
    for part in img_vol:
        if tsk_util.detect_ntfs(img_vol, part):
            print("Exploring NTFS Partition for VSS")
            explore_vss(evidence, part.start * img_vol.info.block_size,output)
        else:
            print("[-] Must be a physical preservation to be compatible ""with this script")
            sys.exit(2)

现在,定义一个探索解析后的卷影文件的方法如下:

def explore_vss(evidence, part_offset, output):
    vss_volume = pyvshadow.volume()
    vss_handle = vss.VShadowVolume(evidence, part_offset)
    vss_count = vss.GetVssStoreCount(evidence, part_offset)
   
    if vss_count > 0:
        vss_volume.open_file_object(vss_handle)
        vss_data = []
      
        for x in range(vss_count):
            print("Gathering data for VSC {} of {}".format(x, vss_count))
            vss_store = vss_volume.get_store(x)
            image = vss.VShadowImgInfo(vss_store)
            vss_data.append(pytskutil.openVSSFS(image, x))
write_csv(vss_data, output)

最后,定义将结果写入电子表格的方法如下:

def write_csv(data, output):
    if data == []:
        print("[-] No output results to write")
        sys.exit(3)
    print("[+] Writing output to {}".format(output))
    if os.path.exists(output):
        append = True
with open(output, "ab") as csvfile:
        csv_writer = csv.writer(csvfile)
        headers = ["VSS", "File", "File Ext", "File Type", "Create Date",
            "Modify Date", "Change Date", "Size", "File Path"]
        if not append:
            csv_writer.writerow(headers)
        for result_list in data:
            csv_writer.writerows(result_list)

成功运行此 Python 脚本后,我们会将驻留在 VSS 中的信息放入电子表格中。