Esempio n. 1
0
    def run(self):
        logger.info('Parsing image {p}, ignoring offset'.format(p=self._path))
        image = imagemounter.ImageParser([self._path],
                                         volume_detector='parted')
        try:
            volumes = list(image.init(swallow_exceptions=False))
        except Exception as exc:
            logger.exception(exc)
            raise

        valid_volumes = []
        skipped_volumes = []
        for volume in volumes:
            logger.info('Volume found: {v}'.format(v=str(volume)))
            #            if 'statfstype' in volume.info and not volume.is_mounted:
            #                volume.mount()
            if not volume.mountpoint:
                logger.warn(
                    'Skipping empty mount point for volume {v}: {m!r}. '
                    'Non-mountable partition or insufficient permissions'.
                    format(
                        v=volume,
                        m=volume.mountpoint,
                    ))
                self.add_warning('Skipped volume {v}'.format(v=volume))
                skipped_volumes.append(volume)
                continue
            logger.info('Adding mount point {mp}'.format(mp=volume.mountpoint))
            self.add_next_task({
                'name': find_tasks_by_filetype('directory'),
                'path': volume.mountpoint,
            })
            valid_volumes.append(volume)
        # NOTE do not unmount the volumes or the next tasks will fail
        self._result = 'Volumes: {vv} valid, {iv} skipped'.format(
            vv=len(valid_volumes),
            iv=len(skipped_volumes),
        )
Esempio n. 2
0
    # 'digitalcorpora/m57-patents/jo-work-usb-2009-12-11.E01',
    # 'digitalcorpora/national_gallery/tracy-external-2012-07-16-final.E01',
    # internally available
    "WinXP2.E01",
    "xp-tdungan/xp-tdungan-c-drive.E01",
]

imgs = []

os.chdir("test_images")

for image_path in images:

    print(f"################### {image_path} ##########################")
    img = {}
    image_parser = imagemounter.ImageParser([image_path])
    disk = image_parser.disks[0]

    img["name"] = disk._name
    img["imagepath"] = disk.paths[0]
    # img['mountpoint'] = disk.mountpoint  # gets overridden below because there is no disk mountpoint if no volumes are mounted
    img["volumes"] = []

    mountable = False
    mountable_checked = False

    for volume in image_parser.init():
        # img['mountpoint'] = disk.mountpoint

        if not mountable_checked and not volume.mountpoint in [None, ""]:
            mountable = True
Esempio n. 3
0
def mount_image(relative_image_path):
    mount_dir = current_app.config["MOUNT_DIR"]
    if not mount_dir:
        msg = "Mount directory is not properly set by thumbtack server"
        current_app.logger.error(msg)
        raise NotADirectoryError(msg)

    full_image_path = f"{current_app.config['IMAGE_DIR']}/{relative_image_path}"

    image_info = get_image_info(relative_image_path)

    if not image_info:
        raise ImageNotInDatabaseError

    # Verify we have a valid file path
    if not os.access(full_image_path, os.R_OK):
        msg = f"* {relative_image_path} is not a valid file or is not accessible for reading"
        current_app.logger.error(msg)
        raise PermissionError(msg)

    # Mount it
    current_app.logger.info(f'* Mounting image_path "{relative_image_path}"')
    if full_image_path.endswith('.vmdk') or full_image_path.endswith('.vhdx'):
        image_parser = imagemounter.ImageParser([full_image_path],
                                                pretty=True,
                                                mountdir=mount_dir,
                                                disk_mounter='nbd')
    else:
        image_parser = imagemounter.ImageParser([full_image_path],
                                                pretty=True,
                                                mountdir=mount_dir)

    if image_info["status"] == "Mounted":
        increment_ref_count(relative_image_path)
        current_app.logger.info(f"* {relative_image_path} is already mounted")
        return image_info["parser"].disks[0]

    # Volumes won't be mounted unless this generator is iterated
    for _ in image_parser.init():
        pass

    # thumbtack can only handle images that have one disk
    num_disks = len(image_parser.disks)
    if num_disks != 1:
        current_app.logger.error(
            f"Error: Unexpected number of disks (expected 1, got {num_disks:d})"
        )
        image_parser.clean(allow_lazy=True)
        raise UnexpectedDiskError(
            f"Unexpected number of disks (expected 1, got {num_disks:d})")

    # Fail if we couldn't mount any of the volumes
    if not [v for v in image_parser.disks[0].volumes if v.mountpoint]:
        image_parser.clean(allow_lazy=True)
        msg = f"* No mountable volumes in image {relative_image_path}"
        current_app.logger.error(msg)
        raise NoMountableVolumesError(msg)

    mount_codes = get_mount_codes()
    disk_mount_status_id = (mount_codes["Mounted"]
                            if image_parser.disks[0].mountpoint else
                            mount_codes["Unable to mount"])
    img_parser_pickle = pickle.dumps(image_parser)

    # log our success
    current_app.logger.info(
        f"* Disk Mounted: {image_parser.disks[0].mountpoint}")
    sql = """UPDATE disk_images
                 SET ref_count = 1, mountpoint = ?, mount_status_id = ?, parser = ?
                 WHERE rel_path = ?
          """
    update_or_insert_db(
        sql,
        [
            image_parser.disks[0].mountpoint,
            disk_mount_status_id,
            sqlite3.Binary(img_parser_pickle),
            relative_image_path,
        ],
    )

    disk_image_id = image_info["id"]
    for volume in image_parser.disks[0].volumes:
        v_mountpoint = volume.mountpoint if volume.mountpoint else None
        # these mount codes come from the init_db() function
        mount_status_id = (mount_codes["Mounted"]
                           if v_mountpoint else mount_codes["Unable to mount"])
        v_index = volume.index

        current_app.logger.info(
            f"  * Volume description: {volume.get_description()}")
        current_app.logger.info(f"  * Volume mountpoint: {v_mountpoint}")
        sql = "SELECT * FROM volumes WHERE disk_id = ? AND partition_index = ?"
        row = query_db(sql, [disk_image_id, v_index], one=True)

        if row:
            # UPDATE
            sql = "UPDATE volumes SET mountpoint = ?, mount_status_id = ? WHERE disk_id = ? AND partition_index = ?"
            update_or_insert_db(
                sql, [v_mountpoint, mount_status_id, disk_image_id, v_index])
        else:
            sql = "INSERT INTO volumes (disk_id, mount_status_id, partition_index, mountpoint) VALUES (?, ?, ?, ?)"
            update_or_insert_db(
                sql, [disk_image_id, mount_status_id, v_index, v_mountpoint])

    return image_parser.disks[0]
Esempio n. 4
0
import imagemounter
files = ["/home/jade/Documents/Recover.E01", "/home/jade/Documents/Recover.E02"]
parser = imagemounter.ImageParser(files, None, True)
for volume in parser.init():
	print("test")
Esempio n. 5
0
def analyseimage(pathtoimg):
    # mount the image
    parser = imm.ImageParser(pathtoimg)
    print(parser)
    print(parser.fstypes)
Esempio n. 6
0
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types

# Import the Pillow Library
from PIL import Image

if len(sys.argv) < 3:
	print("Usage: vision.py encase_file_name google_credentials.json")
	exit()
else:
	encase_file = sys.argv[1]
	credential_path = sys.argv[2]

parser = imagemounter.ImageParser([encase_file])

for volume in parser.init():
	print(volume.get_description())
	volume.unmount()

index = raw_input("Enter the volume you want to search in: ")
volume = parser.get_by_index(index)
volume.init()
volume.mount()

result = []

for root, dirs, files in os.walk(volume.mountpoint):
	for file in files:
		if file.endswith((".jpg", ".png", ".gif")):
Esempio n. 7
0
def mount_image(relative_image_path):
    mount_dir = current_app.config['MOUNT_DIR']
    if not mount_dir:
        msg = "Mount directory is not properly set by thumbtack server"
        current_app.logger.error(msg)
        raise NotADirectoryError(msg)

    full_image_path = '{}/{}'.format(current_app.config['IMAGE_DIR'],
                                     relative_image_path)

    image_info = get_image_info(relative_image_path)

    if not image_info:
        raise ImageNotInDatabaseError

    if image_info['status'] == 'Mounted':
        increment_ref_count(relative_image_path)
        return image_info

    # Verify we have a valid file path
    if not os.access(full_image_path, os.R_OK):
        msg = '* {} is not a valid file or is not accessible for reading'.format(
            relative_image_path)
        current_app.logger.error(msg)
        raise PermissionError(msg)

    # Mount it
    current_app.logger.info(
        '* Mounting image_path "{}"'.format(relative_image_path))
    image_parser = imagemounter.ImageParser([full_image_path],
                                            pretty=True,
                                            mountdir=mount_dir)

    # Volumes won't be mounted unless this generator is iterated
    for _ in image_parser.init():
        pass

    # thumbtack can only handle images that have one disk
    num_disks = len(image_parser.disks)
    if num_disks != 1:
        current_app.logger.error(
            'Error: Unexpected number of disks (expected 1, got {:d})'.format(
                num_disks))
        image_parser.clean(allow_lazy=True)
        raise UnexpectedDiskError(
            'Unexpected number of disks (expected 1, got {:d})'.format(
                num_disks))

    # Fail if we couldn't mount any of the volumes
    if not [v for v in image_parser.disks[0].volumes if v.mountpoint]:
        image_parser.clean(allow_lazy=True)
        msg = '* No mountable volumes in image {}'.format(relative_image_path)
        current_app.logger.error(msg)
        raise NoMountableVolumesError(msg)

    mount_codes = get_mount_codes()
    disk_mount_status_id = mount_codes['Mounted'] if image_parser.disks[
        0].mountpoint else mount_codes['Unable to mount']
    img_parser_pickle = pickle.dumps(image_parser)

    # log our success
    current_app.logger.info("* Disk Mounted: {}".format(
        image_parser.disks[0].mountpoint))
    sql = """UPDATE disk_images
                 SET ref_count = 1, mountpoint = ?, mount_status_id = ?, parser = ?
                 WHERE rel_path = ?
          """
    update_or_insert_db(sql, [
        image_parser.disks[0].mountpoint, disk_mount_status_id,
        sqlite3.Binary(img_parser_pickle), relative_image_path
    ])

    disk_image_id = image_info['id']
    for volume in image_parser.disks[0].volumes:
        v_mountpoint = volume.mountpoint if volume.mountpoint else None
        # these mount codes come from the init_db() function
        mount_status_id = mount_codes[
            'Mounted'] if v_mountpoint else mount_codes['Unable to mount']
        v_index = volume.index

        current_app.logger.info("  * Volume description: {}".format(
            volume.get_description()))
        current_app.logger.info(
            "  * Volume mountpoint: {}".format(v_mountpoint))
        sql = "SELECT * FROM volumes WHERE disk_id = ? AND partition_index = ?"
        row = query_db(sql, [disk_image_id, v_index], one=True)

        if row:
            # UPDATE
            sql = "UPDATE volumes SET mountpoint = ?, mount_status_id = ? WHERE disk_id = ? AND partition_index = ?"
            update_or_insert_db(
                sql, [v_mountpoint, mount_status_id, disk_image_id, v_index])
        else:
            sql = "INSERT INTO volumes (disk_id, mount_status_id, partition_index, mountpoint) VALUES (?, ?, ?, ?)"
            update_or_insert_db(
                sql, [disk_image_id, mount_status_id, v_index, v_mountpoint])

    return image_parser.disks[0]