
- Python 數字取證
- Python 數字取證 - 首頁
- 介紹
- Python 入門
- 痕跡報告
- 移動裝置取證
- 調查嵌入式元資料
- 網路取證-I
- 網路取證-II
- 使用電子郵件進行調查
- Windows-I 中的重要痕跡
- Windows-II 中的重要痕跡
- Windows-III 中的重要痕跡
- 基於日誌的痕跡調查
- Python 數字取證資源
- 快速指南
- Python 數字取證 - 資源
- Python 數字取證 - 討論
Windows-III 中的重要痕跡
本章將解釋調查人員在 Windows 上進行取證分析期間可以獲取的更多痕跡。
事件日誌
Windows 事件日誌檔案,顧名思義,是儲存重要事件的特殊檔案,例如使用者何時登入計算機、程式何時遇到錯誤、系統更改、RDP 訪問、特定應用程式事件等。網路調查人員始終對事件日誌資訊感興趣,因為它提供了大量有關係統訪問的有用歷史資訊。在以下 Python 指令碼中,我們將處理傳統和當前的 Windows 事件日誌格式。
對於 Python 指令碼,我們需要安裝第三方模組,即pytsk3、pyewf、unicodecsv、pyevt 和 pyevtx。我們可以按照以下步驟從事件日誌中提取資訊:
首先,搜尋與輸入引數匹配的所有事件日誌。
然後,執行檔案簽名驗證。
現在,使用適當的庫處理找到的每個事件日誌。
最後,將輸出寫入電子表格。
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)
成功執行上述指令碼後,我們將在電子表格中獲得事件日誌的資訊。
網際網路歷史記錄
網際網路歷史記錄對於取證分析師非常有用;因為大多數網路犯罪僅發生在網際網路上。讓我們看看如何從 Internet Explorer 中提取網際網路歷史記錄,因為我們正在討論 Windows 取證,而 Internet Explorer 是 Windows 的預設瀏覽器。
在 Internet Explorer 中,網際網路歷史記錄儲存在index.dat檔案中。讓我們看一下 Python 指令碼,它將從index.dat檔案中提取資訊。
我們可以按照以下步驟從index.dat檔案中提取資訊:
首先,在系統中搜索index.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和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 = "Output 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 中的資訊到電子表格中。