mirror of
https://github.com/PacktPublishing/Python-Digital-Forensics-Cookbook.git
synced 2026-02-20 13:50:43 +00:00
119 lines
4.0 KiB
Python
119 lines
4.0 KiB
Python
from __future__ import print_function
|
|
import argparse
|
|
import os
|
|
import pytsk3
|
|
import pyewf
|
|
import sys
|
|
from tabulate import tabulate
|
|
|
|
"""
|
|
MIT License
|
|
|
|
Copyright (c) 2017 Chapin Bryce, Preston Miller
|
|
|
|
Please share comments and questions at:
|
|
https://github.com/PythonForensics/PythonForensicsCookbook
|
|
or email pyforcookbook@gmail.com
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
"""
|
|
|
|
__authors__ = ["Chapin Bryce", "Preston Miller"]
|
|
__date__ = 20170815
|
|
__description__ = "Utility to gather open evidence containers"
|
|
|
|
|
|
class EWFImgInfo(pytsk3.Img_Info):
|
|
def __init__(self, ewf_handle):
|
|
self._ewf_handle = ewf_handle
|
|
super(EWFImgInfo, self).__init__(url="",
|
|
type=pytsk3.TSK_IMG_TYPE_EXTERNAL)
|
|
|
|
def close(self):
|
|
self._ewf_handle.close()
|
|
|
|
def read(self, offset, size):
|
|
self._ewf_handle.seek(offset)
|
|
return self._ewf_handle.read(size)
|
|
|
|
def get_size(self):
|
|
return self._ewf_handle.get_media_size()
|
|
|
|
|
|
def main(image, img_type, offset):
|
|
print("[+] Opening {}".format(image))
|
|
if img_type == "ewf":
|
|
try:
|
|
filenames = pyewf.glob(image)
|
|
except IOError:
|
|
_, e, _ = sys.exc_info()
|
|
print("[-] Invalid EWF format:\n {}".format(e))
|
|
sys.exit(2)
|
|
ewf_handle = pyewf.handle()
|
|
ewf_handle.open(filenames)
|
|
# Open PYTSK3 handle on EWF Image
|
|
img_info = EWFImgInfo(ewf_handle)
|
|
else:
|
|
img_info = pytsk3.Img_Info(image)
|
|
|
|
# Get Filesystem Handle
|
|
try:
|
|
fs = pytsk3.FS_Info(img_info, offset)
|
|
except IOError:
|
|
_, e, _ = sys.exc_info()
|
|
print("[-] Unable to open FS:\n {}".format(e))
|
|
exit()
|
|
|
|
root_dir = fs.open_dir(path="/")
|
|
table = [["Name", "Type", "Size", "Create Date", "Modify Date"]]
|
|
for f in root_dir:
|
|
name = f.info.name.name
|
|
if f.info.meta.type == pytsk3.TSK_FS_META_TYPE_DIR:
|
|
f_type = "DIR"
|
|
else:
|
|
f_type = "FILE"
|
|
size = f.info.meta.size
|
|
create = f.info.meta.crtime
|
|
modify = f.info.meta.mtime
|
|
table.append([name, f_type, size, create, modify])
|
|
print(tabulate(table, headers="firstrow"))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(
|
|
description=__description__,
|
|
epilog="Developed by {} on {}".format(
|
|
", ".join(__authors__), __date__)
|
|
)
|
|
parser.add_argument("EVIDENCE_FILE", help="Evidence file path")
|
|
parser.add_argument("TYPE",
|
|
help="Type of evidence: raw (dd) or EWF (E01)",
|
|
choices=("raw", "ewf"))
|
|
parser.add_argument("-o", "--offset",
|
|
help="Partition byte offset", type=int)
|
|
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.offset)
|
|
else:
|
|
print("[-] Supplied input file {} does not exist or is not a "
|
|
"file".format(args.EVIDENCE_FILE))
|
|
sys.exit(1)
|