Beispiel #1
0
def plaso_mr(item_to_process, case_number, root_folder_path, evidence):
    #(evidence_type, case_number, folder_path, evidence_path.strip())

    print("The item to process is: " + item_to_process)
    print("The case_name is: " + case_number)
    print("The output folder is: " + root_folder_path)
    print("The evidence to process is: " + evidence)

    evidence_no_quotes = evidence
    evidence = '"' + evidence + '"'

    root_folder_path_no_quotes = root_folder_path
    root_folder_path = "'" + root_folder_path + "'"

    #get datetime
    now = datetime.datetime.now()

    #create output folder path
    folder_path = root_folder_path_no_quotes + "/" + "Plaso"
    check_for_folder(folder_path, "NONE")

    #open a log file for output
    log_file = folder_path + "/Plaso_mr_logfile.txt"
    outfile = open(log_file, 'wt+')

    if (item_to_process == "Directory"):
        folder_to_process = evidence_no_quotes
        process_folder(folder_path, case_number, folder_to_process, outfile)
    elif (item_to_process == "EnCase Logical Evidence File"):
        file_to_process = evidence
        mount_point = mount_encase_v6_l01(case_number, file_to_process,
                                          outfile)
        process_folder(mount_point, export_file, outfile)

        #umount
        if (os.path.exists(mount_point)):
            subprocess.call(['sudo umount -f ' + mount_point], shell=True)
            os.rmdir(mount_point)
    elif (item_to_process == "Bit-Stream Image"):
        Image_Path = evidence_no_quotes

        #get datetime
        now = datetime.datetime.now()
        process_folder(folder_path, case_number, Image_Path, outfile)

        ## I have not been able to test this code yet since I don't have a large enough test imge
        #set file to split
        #file_to_split = folder_path + "/" + case_number + ".plaso.csv"
        #file_to_split_basename = case_number + ".plaso.csv"

        #pass csv file to split_csv to see if it needs to get split
        #split_csv(case_number, folder_path, outfile)
        #split_csv(case_number, folder_path, outfile, file_to_split, file_to_split_basename)

    #close output file
    outfile.close()
Beispiel #2
0
def plist_processor(item_to_process, case_number, root_folder_path, evidence):
    print("The item to process is: " + item_to_process)
    print("The case_name is: " + case_number)
    print("The output folder is: " + root_folder_path)
    print("The evidence to process is: " + evidence)

    evidence_no_quotes = evidence
    evidence = '"' + evidence + '"'

    # get datetime
    now = datetime.datetime.now()

    # set Mount Point
    mount_point = "/mnt/" + "MantaRay_" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

    # create output folder path
    folder_path = root_folder_path + "/" + "PLIST_Processor"
    check_for_folder(folder_path, "NONE")

    # open a log file for output
    log_file = folder_path + "/PLIST_processor_logfile.txt"
    outfile = open(log_file, "wt+")

    # open an error file for output
    log_file = folder_path + "/PLIST_processor_error_log.txt"
    outfile_error = open(log_file, "wt+")

    # open file to write output
    exp_file = folder_path + "/" + case_number + "_PLIST_Triage.txt"
    export_file = open(exp_file, "a")

    if item_to_process == "Directory":
        folder_to_process = evidence_no_quotes
        process_folder(folder_to_process, export_file, outfile, outfile_error, now)
    elif item_to_process == "EnCase Logical Evidence File":
        file_to_process = evidence
        mount_point = mount_encase_v6_l01(case_number, file_to_process, outfile)
        process_folder(mount_point, export_file, outfile, outfile_error, now)

        # umount
        if os.path.exists(mount_point):
            subprocess.call(["sudo umount -f " + mount_point], shell=True)
            os.rmdir(mount_point)
    elif item_to_process == "Bit-Stream Image":

        # set Mount Point
        mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

        Image_Path = evidence

        # check if Image file is in Encase format
        if re.search(".E01", Image_Path):
            # set mount point
            # mount_point = "/mnt/"+	case_number+"_ewf"
            Image_Path = mount_ewf(Image_Path, outfile, mount_point)

            # call mmls function
        partition_info_dict, temp_time = mmls(outfile, Image_Path)
        partition_info_dict_temp = partition_info_dict

        # get filesize of mmls_output.txt
        file_size = os.path.getsize("/tmp/mmls_output_" + temp_time + ".txt")

        # if filesize of mmls output is 0 then run parted
        if file_size == 0:
            print("mmls output was empty, running parted\n")
            outfile.write("mmls output was empty, running parted\n")
            # call parted function
            partition_info_dict, temp_time = parted(outfile, Image_Path)

        else:

            # read through the mmls output and look for GUID Partition Tables (used on MACS)
            mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt", "r")
            for line in mmls_output_file:
                if re.search("GUID Partition Table", line):
                    print("We found a GUID partition table, need to use parted")
                    outfile.write("We found a GUID partition table, need to use parted\n")
                    # call parted function
                    partition_info_dict, temp_time = parted(outfile, Image_Path)
            mmls_output_file.close()

            # loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
        for key, value in partition_info_dict.items():
            cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
            try:
                subprocess.call([cmd_false], shell=True)
            except:
                print("Autmount false failed")

                # process plist files
            if value == "hfs+":
                # call mount sub-routine
                success_code, loopback_device_mount = mount(value, str(key), Image_Path, outfile, mount_point)

                if success_code:
                    print("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
                    outfile.write("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
                else:

                    print("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")
                    outfile.write("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")

                    # process
                    process_folder(mount_point, export_file, outfile, outfile_error, now)

                    # unmount
                    subprocess.call(["umount " + mount_point], shell=True)
                    subprocess.call(["losetup -d " + loopback_device_mount], shell=True)

            else:
                print("This partition is not formatted HFS+")
                outfile.write("This partition is not formatted HFS+\n\n")
                # close export_file
        export_file.close()

        # chdir to output foler
        os.chdir(folder_path)

        # unmount and remount points
        if re.search(".E01", Image_Path):
            if os.path.exists(mount_point + "_ewf"):
                subprocess.call(["sudo umount -f " + mount_point + "_ewf"], shell=True)
                os.rmdir(mount_point + "_ewf")

                # remove empty directories
        for root, dirs, files in os.walk(folder_path, topdown=False):
            for directory in dirs:
                dir_path = os.path.join(root, directory)
                if not os.listdir(dir_path):
                    outfile.write("Removing empty folder: " + dir_path + "\n")
                    os.rmdir(dir_path)

                    # close outfiles
        outfile.close()

        # run text files through unix2dos
        for root, dirs, files in os.walk(folder_path):
            for filenames in files:
                # get file extension
                fileName, fileExtension = os.path.splitext(filenames)
                if fileExtension.lower() == ".txt":
                    full_path = os.path.join(root, filenames)
                    quoted_full_path = "'" + full_path + "'"
                    print("Running Unix2dos against file: " + filenames)
                    unix2dos_command = "sudo unix2dos " + quoted_full_path
                    subprocess.call([unix2dos_command], shell=True)

                    # delete /tmp/ls_output.txt
        if os.path.exists("/tmp/mmls_output_" + temp_time + ".txt"):
            os.remove("/tmp/mmls_output_" + temp_time + ".txt")
        if os.path.exists("/tmp/timeline_partition_info_" + temp_time + ".txt"):
            os.remove("/tmp/timeline_partition_info_" + temp_time + ".txt")
        if os.path.exists("/tmp/dump_" + temp_time + ".txt"):
            os.remove("/tmp/dump_" + temp_time + ".txt")
        if os.path.exists("/tmp/fls_output_" + temp_time + ".txt"):
            os.remove("/tmp/fls_output_" + temp_time + ".txt")
        if os.path.exists("/tmp/hives_to_rename_" + temp_time):
            shutil.rmtree("/tmp/hives_to_rename_" + temp_time)
Beispiel #3
0
def be_mr(item_to_process, case_number, folder_path, evidence, whitelist_location, speed, keyword_list):
	evidence = "'" + evidence + "'"
	speed = speed.strip()

	#calculate number of processors to use (Speed-Slow, Speed-Fast, Speed-Med
	calc_cores_command = "cat /proc/cpuinfo | grep processor | wc -l"
	num_of_cores = subprocess.check_output([calc_cores_command], shell=True)
	num_of_cores = num_of_cores.decode(encoding='UTF-8')
	num_of_cores = num_of_cores.strip()
	print("This VM has " + str(num_of_cores) +" cores")

	if(num_of_cores == "1"):
		cores_to_use = 1	
	elif(speed == "Speed-Slow"):
		cores_to_use = 1
	elif(speed == "Speed-Med"):
		cores_to_use = int(num_of_cores)//2
	elif(speed == "Speed-Fast"):
		cores_to_use = num_of_cores 
	

	print("Item to process is: " + item_to_process)
	print("Case number is: " + case_number)
	print("Output folder is: " + folder_path)
	print("Evidence type is: " + evidence)
	print("Whitelist location is: " + whitelist_location)
	print("Processing speed is: " + speed)
	print("Keyword list is: " + keyword_list)

	#open a log file for output
	#log_file = folder_path + "/" + case_number + "_logfile.txt"
	#outfile = open(log_file, 'a')

	#add subfolder to output path so BE has empty folder to write to
	folder_path_be = "'" + folder_path +"/Bulk_Extractor_Results'" 
	check_for_folder(folder_path_be, "NONE")
	
	if(item_to_process == "Directory"):
		process_folder(evidence, folder_path_be, whitelist_location, speed, "NONE", keyword_list, cores_to_use)
	elif(item_to_process == "EnCase Logical Evidence File"):
		mount_point = mount_encase_v6_l01(case_number, evidence, "NONE")
		process_folder(mount_point, folder_path_be, whitelist_location, speed, "NONE", keyword_list, cores_to_use)
	elif(item_to_process == "Single File") or (item_to_process == "Memory Image") or (item_to_process == "EnCase Logical Evidence File"):

		#set up bulk extractor command
		if(whitelist_location != "NONE") and (keyword_list == "NONE"):
			be_command = "bulk_extractor -o " + folder_path_be + " -w " + whitelist_location + " -j " + str(cores_to_use) + " " + evidence
		elif(whitelist_location == "NONE") and (keyword_list =="NONE"):
			be_command = "bulk_extractor -o " + folder_path_be + " -j " + str(cores_to_use) + " " + evidence
		elif(whitelist_location != "NONE") and (keyword_list != "NONE"):
			be_command = "bulk_extractor -o " + folder_path_be + " -w " + whitelist_location + " -x find l -F " + keyword_list + " -j " + str(cores_to_use) + " " + evidence
		elif(whitelist_location == "NONE") and (keyword_list != "NONE"):
			be_command = "bulk_extractor -o " + folder_path_be + " -x find -F " + keyword_list + " -j " + str(cores_to_use) + " " + evidence

		#outfile.write("The be_command is: " + be_command + "\n")

		#run be_command
		print("The be command is: " + be_command)
		subprocess.call([be_command], shell=True)
	elif(item_to_process == "Bit-Stream Image"):
		#set up bulk extractor command
		if(whitelist_location != "NONE") and (keyword_list == "NONE"):
			be_command = "bulk_extractor -C 60 -o " + folder_path_be + " -w " + whitelist_location + " -j " + str(cores_to_use) + " " + evidence
		elif(whitelist_location == "NONE") and (keyword_list =="NONE"):
			be_command = "bulk_extractor -C 60 -o " + folder_path_be + " -j " + str(cores_to_use) + " " + evidence
		elif(whitelist_location != "NONE") and (keyword_list != "NONE"):
			be_command = "bulk_extractor -C 60 -o " + folder_path_be + " -w " + whitelist_location + " -x find -F " + keyword_list + " -j " + str(cores_to_use) + " " + evidence
		elif(whitelist_location == "NONE") and (keyword_list != "NONE"):
			be_command = "bulk_extractor -C 60 -o " + folder_path_be + " -x find -F " + keyword_list + " -j " + str(cores_to_use) + " " + evidence

		#run be_command
		print("The be command is: " + be_command)
		subprocess.call([be_command], shell=True)

		#run fiwalk
		fiwalk_command = "fiwalk -x " + evidence + " >" + '"' + folder_path + "/Bulk_Extractor_Results/fiwalk_output.xml" + "'"
		print("Running fiwalk: " + fiwalk_command)
		subprocess.call([fiwalk_command], shell=True)

		#run identify_filenames.py
		identify_filenames_command = "python3 /usr/share/bulk_extractor/python/identify_filenames.py --all --imagefile " + evidence + " --xmlfile " + '"' + folder_path + "/Bulk_Extractor_Results/fiwalk_output.xml" + '"' + " "  + '"' + folder_path + "/Bulk_Extractor_Results" + '"' + " " + '"' + folder_path + "/Bulk_Extractor_Results/annotated_results/" + '"'
		print("Running identify_filenames.py: " + identify_filenames_command)
		subprocess.call([identify_filenames_command], shell=True)

		#chdir to output foler
		os.chdir(folder_path)

		#run text files through unix2dos
		for root, dirs, files in os.walk(folder_path + "/Bulk_Extractor_Results/"):
			for filenames in files:
				#get file extension
				fileName, fileExtension = os.path.splitext(filenames)
				if(fileExtension.lower() == ".txt"):
					full_path = os.path.join(root,filenames)
					quoted_full_path = "'" +full_path+"'"
					print("Running Unix2dos against file: " + quoted_full_path)
					#unix2dos_command = "sudo unix2dos " + "'"+filenames+"'"
					unix2dos_command = "sudo unix2dos " + quoted_full_path
					subprocess.call([unix2dos_command], shell=True)
Beispiel #4
0
def av_scanner_mr(item_to_process, case_number, root_folder_path, evidence, conf_file):
	
	print("The item to process is: " + item_to_process)
	print("The case_name is: " + case_number)
	print("The output folder is: " + root_folder_path)
	print("The evidence to process is: " + evidence)
	print("The configuration file is located at: " + conf_file)

	evidence_no_quotes = evidence
	evidence = '"' + evidence + '"'

	#get datetime
	now = datetime.datetime.now()

	#set Mount Point
	mount_point = "/mnt/" + "MantaRay_" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")
	
	#create output folder path
	output_folder_path = root_folder_path + "/" + "AV_Scanner"
	check_for_folder(output_folder_path, "NONE")
	

	#open a log file for output
	log_file = output_folder_path + "/AV_Scanner_logfile.txt"
	outfile = open(log_file, 'wt+')

	if(item_to_process == "Single File"):
		print("Please put your file in a folder and then scan the folder")

	elif(item_to_process == "Directory"):
		folder_to_process = evidence_no_quotes
		process_folder(folder_to_process, output_folder_path, outfile, "Directory", conf_file)
	elif(item_to_process =="EnCase Logical Evidence File"):
		file_to_process = evidence
		mount_point = mount_encase_v6_l01(case_number, file_to_process, outfile)
		process_folder(mount_point, output_folder_path, outfile, "LEF", conf_file)

		#umount
		if(os.path.exists(mount_point)):
			subprocess.call(['sudo umount -f ' + mount_point], shell=True)
			os.rmdir(mount_point)
	elif(item_to_process == "Bit-Stream Image"):
		Image_Path = evidence
		#process every file on every partition
		#get datetime
		now = datetime.datetime.now()

		#set Mount Point
		mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

		#check if Image file is in Encase format
		if re.search(".E01", Image_Path):

			#strip out single quotes from the quoted path
			#no_quotes_path = Image_Path.replace("'","")
			#print("THe no quotes path is: " +  no_quotes_path)
			#call mount_ewf function
			Image_Path = mount_ewf(Image_Path, outfile,mount_point)


		#call mmls function
		partition_info_dict, temp_time = mmls(outfile, Image_Path)
		partition_info_dict_temp = partition_info_dict

		#get filesize of mmls_output.txt
		file_size = os.path.getsize("/tmp/mmls_output_" + temp_time + ".txt") 


		#if filesize of mmls output is 0 then run parted
		if(file_size == 0):
			print("mmls output was empty, running parted")
			outfile.write("mmls output was empty, running parted")
			#call parted function
			partition_info_dict, temp_time = parted(outfile, Image_Path)	

		else:

			#read through the mmls output and look for GUID Partition Tables (used on MACS)
			mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt", 'r')
			for line in mmls_output_file:
				if re.search("GUID Partition Table", line):
					print("We found a GUID partition table, need to use parted")
					outfile.write("We found a GUID partition table, need to use parted\n")
					#call parted function
					partition_info_dict, temp_time = parted(outfile, Image_Path)
			mmls_output_file.close()
			

		#loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
		for key,value in sorted(partition_info_dict.items()):

			#disable auto-mount in nautilis - this stops a nautilis window from popping up everytime the mount command is executed
			cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
			try:
				subprocess.call([cmd_false], shell=True)
			except:
				print("Autmount false failed")

			#call mount sub-routine
			success_code, loopback_device_mount = mount(value,str(key),Image_Path, outfile, mount_point)

			if(success_code):
				print("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
				outfile.write("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
			else:
		
				print("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")
				outfile.write("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")

				#call av_scanner function for each mount_point
				process_folder(mount_point, output_folder_path, outfile, "partition_offset_"+str(key), conf_file)
				print("We just finished scanning every file...sorting output")

				#unmount and remove mount points
				if(os.path.exists(mount_point)): 
					subprocess.call(['sudo umount -f ' + mount_point], shell=True)
					os.rmdir(mount_point)
				#unmount loopback device if this image was HFS+ - need to run losetup -d <loop_device> before unmounting
				if not (loopback_device_mount == "NONE"):
					losetup_d_command = "losetup -d " + loopback_device_mount
					subprocess.call([losetup_d_command], shell=True)

			

		#delete /tmp files created for each partition
		if (os.path.exists("/tmp/mmls_output_" + temp_time + ".txt")):
			os.remove("/tmp/mmls_output_" + temp_time + ".txt")

	#close logfile
	outfile.close()

	#remove mount points created for this program
	if(os.path.exists(mount_point)):
		os.rmdir(mount_point)
	if(os.path.exists(mount_point+"_ewf")):
		subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
		os.rmdir(mount_point+"_ewf")

#run text files through unix2dos
	for root, dirs, files in os.walk(output_folder_path):
		for filenames in files:
			#get file extension
			fileName, fileExtension = os.path.splitext(filenames)
			if(fileExtension.lower() == ".txt"):
				full_path = os.path.join(root,filenames)
				quoted_full_path = "'" +full_path+"'"
				print("Running Unix2dos against file: " + quoted_full_path)
				#unix2dos_command = "sudo unix2dos " + "'"+filenames+"'"
				unix2dos_command = "sudo unix2dos " + quoted_full_path
				subprocess.call([unix2dos_command], shell=True)
Beispiel #5
0
def exifdata_mr(item_to_process, case_number, root_folder_path, evidence):
	print("The item to process is: " + item_to_process)
	print("The case_name is: " + case_number)
	print("The output folder is: " + root_folder_path)
	print("The evidence to process is: " + evidence)

	evidence_no_quotes = evidence

	evidence = '"' + evidence + '"'

	#get datetime
	now = datetime.datetime.now()

	#set Mount Point
	mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")
	
	#create output folder path
	folder_path = root_folder_path + "/" + "EXIF_Tool"
	check_for_folder(folder_path, "NONE")
	

	#open a log file for output
	log_file = folder_path + "/EXIF_Tool_logfile.txt"
	outfile = open(log_file, 'wt+')

	#set up tuple holding all of the file extensions exiftool can process
	valid_extensions = ('3FR', '3G2', '3GP2', '3GP', '3GPP', 'ACR', 'AFM', 'ACFM', 'AMFM', 'AI', 'AIT', 'AIFF', 'AIF', 'AIFC', 'APE', 'ARW', 'ASF', 'AVI', 'BMP', 'DIB', 'BTF', 'TIFF', 'TIF', 'CHM', 'COS', 'CR2', 'CRW', 'CIFF', 'CS1', 'DCM', 'DC3', 'DIC', 'DICM', 'DCP', 'DCR', 'DFONT', 'DIVX', 'DJVU', 'DJV', 'DNG', 'DOC', 'DOT', 'DOCX', 'DOCM', 'DOTX', 'DOTM', 'DYLIB', 'DV', 'DVB', 'EIP', 'EPS', 'EPSF', 'EXR', 'PS', 'ERF', 'EXE', 'DLL', 'EXIF', 'F4A', 'F4B', 'F4P', 'F4V', 'FFF', 'FLA', 'FLAC', 'FLV', 'FPX', 'GIF', 'GZ', 'GZIP', 'HDP', 'HDR', 'WDP', 'HTML', 'HTM', 'XHTML', 'ICC', 'ICM', 'IIQ', 'IND', 'INDD', 'INDT', 'INX', 'ITC', 'JP2', 'JPF', 'JPM', 'JPX', 'JPEG', 'JPC', 'JPG', 'J2C', 'J2K', 'K25', 'KDC', 'KEY', 'KTH', 'LNK', 'M2TS', 'MTS', 'M2T', 'TS', 'M4A', 'M4B', 'M4P', 'M4V', 'MEF', 'MIE', 'MIFF', 'MIF', 'MKA', 'MKV', 'MKS', 'MOS', 'MOV', 'Q', 'MP3', 'MP4', 'MPC', 'MPEG', 'MPG', 'M2V', 'MPO', 'MQV', 'QT', 'MRW', 'MXF', 'NEF', 'NMBTEMPLATE', 'NRW', 'NUMBERS', 'ODB', 'ODC', 'ODF', 'ODG', 'OGI', 'ODP', 'ODS', 'ODT', 'OGG', 'ORF', 'OTF', 'PAGES', 'PDF', 'PEF', 'PFA', 'PFB', 'PFM', 'PGF', 'PICT', 'PCT', 'PMP', 'PNG', 'JNG', 'MNG', 'PPM', 'PBM', 'PGM', 'PPT', 'PPS', 'POT', 'POTX', 'POTM', 'PPSX', 'PPSM', 'PPTX', 'PPTM', 'PSD', 'PSB', 'PSP', 'PSPIMAGE', 'QTIF', 'QTI', 'QIF', 'RAF', 'RAM', 'RPM', 'RAW', 'RAR', 'RAW', 'RIFF', 'RIF', 'RM', 'RV', 'RMVB', 'RSRC', 'RTF', 'RW2', 'RWL', 'RWZ', 'SO', 'SR2', 'SRF', 'SRW', 'SVG', 'SWF', 'THM', 'THMX', 'TIFF', 'TIF', 'TTF', 'TTC', 'VOB', 'VRD', 'VSD', 'WAV', 'WEBM', 'WEBP', ',WMA', 'WMV', 'X3F', 'XCF', 'XLS', 'XLT', 'XLSX', 'XLSM', 'XLSB', 'XLTX', 'XLTM', 'XMP', 'ZIP')

	if(item_to_process =="EnCase Logical Evidence File"):

		file_to_process = evidence
		mount_point = mount_encase_v6_l01(case_number, file_to_process, outfile)
		process_folder(mount_point, valid_extensions, item_to_process)

		#umount
		if(os.path.exists(mount_point)):
			subprocess.call(['sudo umount -f ' + mount_point], shell=True)
			os.rmdir(mount_point)


	if(item_to_process == "Directory"):

		mount_point = evidence_no_quotes
		process_folder(mount_point, valid_extensions, item_to_process, outfile, folder_path)

	

	elif(item_to_process == "Bit-Stream Image"):

		#get datetime
		now = datetime.datetime.now()

		#set Mount Point
		mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

		#select dd image to process	
		Image_Path = evidence

		#check if Image file is in Encase format
		if re.search(".E01", Image_Path):

			#strip out single quotes from the quoted path
			#no_quotes_path = Image_Path.replace("'","")
			#print("THe no quotes path is: " +  no_quotes_path)
			#call mount_ewf function
			Image_Path = mount_ewf(Image_Path, outfile, mount_point)

		#call mmls function
		partition_info_dict, temp_time = mmls(outfile, Image_Path)

		#get filesize of mmls_output.txt
		file_size = os.path.getsize("/tmp/mmls_output_" + temp_time + ".txt") 

		#if filesize of mmls output is 0 then run parted
		if(file_size == 0):
			print("mmls output was empty, running parted")
			outfile.write("mmls output was empty, running parted")
			#call parted function
			partition_info_dict, temp_time = parted(outfile, Image_Path)	

		else:

			#read through the mmls output and look for GUID Partition Tables (used on MACS)
			mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt", 'r')
			for line in mmls_output_file:
				if re.search("GUID Partition Table", line):
					print("We found a GUID partition table, need to use parted")
					outfile.write("We found a GUID partition table, need to use parted\n")
					#call parted function
					partition_info_dict, temp_time = parted(outfile, Image_Path)

	
		#loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
		for key,value in partition_info_dict.items():

			#set up file object for output file
			output_file = folder_path + "/Exif_data_partition_offset_" + str(key) +".txt"
			print("The output_file is: " + output_file)
			exif_out = open(output_file, 'wt+')

			#disable auto-mount in nautilis - this stops a nautilis window from popping up everytime the mount command is executed
			cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
			try:
				subprocess.call([cmd_false], shell=True)
			except:
				print("Autmount false failed")

			#call mount sub-routine
			success_code, loopback_device_mount = mount(value,key,Image_Path, outfile, mount_point)

			if(success_code):
				print("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
				outfile.write("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
			else:
		
				print("We just mounted filesystem: " + value + " at offset:" + str(key) + ". Scanning for files of interest.....\n")
				outfile.write("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")
			

				#get the filename without extension
				for root,dirs,files in os.walk(mount_point):
					for filenames in files:
						fileName, fileExtension = os.path.splitext(filenames)
					
						#replace the . in the file extension with nothing
						file_extension = fileExtension.replace('.','')	
						file_extension = file_extension.upper()				
						file_name = os.path.basename(fileName)
						for extension in valid_extensions:
							if(file_extension == extension):
								print("Running exiftool against file: " + filenames)
								outfile.write("Running exiftool against file: " + filenames)

								#chdir to output foler
								os.chdir(folder_path)
						
								#get absolute path to file
								file_name = os.path.join(root,filenames)
								quoted_file_name = "'" +file_name +"'"

								#enclose strings in quotes
								quoted_root = "'" +root +"'"	
								
	
								#set up exiftool command			
								exif_command = "exiftool -ext " + extension + " -l -sep *********** -z " + quoted_file_name + " >> " + "'" +  folder_path + "/Exif_data_partition_offset_" + str(key) +".txt" + "'"
										
								#print("The exif command is: " + exif_command + "\n\n")
								outfile.write("The exif command is: " + exif_command + "\n\n")

								#execute the exif command
								subprocess.call([exif_command], shell=True)
								#exif_out.write("\n\n")
						

				#unmount and remove mount points
				if(os.path.exists(mount_point)): 
					subprocess.call(['sudo umount -f ' + mount_point], shell=True)
					os.rmdir(mount_point)
				#unmount loopback device if this image was HFS+ - need to run losetup -d <loop_device> before unmounting
				if not (loopback_device_mount == "NONE"):
					losetup_d_command = "losetup -d " + loopback_device_mount
					subprocess.call([losetup_d_command], shell=True)

			#close outfile
			exif_out.close()

	#program cleanup
	outfile.close()
	
	#remove mount points created for this program
	if(os.path.exists(mount_point)):
		if not (item_to_process == "Directory"):
			os.rmdir(mount_point)
	if(os.path.exists(mount_point+"_ewf")):
		subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
		os.rmdir(mount_point+"_ewf")

	#delete empty directories in output folder
	for root, dirs, files in os.walk(folder_path, topdown=False):	
		for directories in dirs:
			files = []
			dir_path = os.path.join(root,directories)
			files = os.listdir(dir_path)	
			if(len(files) == 0):
				os.rmdir(dir_path)
Beispiel #6
0
def be_mr(item_to_process, case_number, folder_path, evidence, whitelist_location, speed, keyword_list):
	evidence = "'" + evidence + "'"
	speed = speed.strip()

	#calculate number of processors to use (Speed-Slow, Speed-Fast, Speed-Med
	calc_cores_command = "cat /proc/cpuinfo | grep processor | wc -l"
	num_of_cores = subprocess.check_output([calc_cores_command], shell=True)
	num_of_cores = num_of_cores.decode(encoding='UTF-8')
	num_of_cores = num_of_cores.strip()
	print("This VM has " + str(num_of_cores) +" cores")

	if(num_of_cores == "1"):
		cores_to_use = 1	
	elif(speed == "Speed-Slow"):
		cores_to_use = 1
	elif(speed == "Speed-Med"):
		cores_to_use = int(num_of_cores)//2
	elif(speed == "Speed-Fast"):
		cores_to_use = num_of_cores 
	

	print("Item to process is: " + item_to_process)
	print("Case number is: " + case_number)
	print("Output folder is: " + folder_path)
	print("Evidence type is: " + evidence)
	print("Whitelist location is: " + whitelist_location)
	print("Processing speed is: " + speed)
	print("Keyword list is: " + keyword_list)

	#open a log file for output
	#log_file = folder_path + "/" + case_number + "_logfile.txt"
	#outfile = open(log_file, 'a')

	#add subfolder to output path so BE has empty folder to write to
	folder_path_be = "'" + folder_path +"/Bulk_Extractor_Results'" 
	check_for_folder(folder_path_be, "NONE")
	
	if(item_to_process == "Directory"):
		process_folder(evidence, folder_path_be, whitelist_location, speed, "NONE", keyword_list, cores_to_use)
	elif(item_to_process == "EnCase Logical Evidence File"):
		mount_point = mount_encase_v6_l01(case_number, evidence, "NONE")
		process_folder(mount_point, folder_path_be, whitelist_location, speed, "NONE", keyword_list, cores_to_use)
	elif(item_to_process == "Single File") or (item_to_process == "Memory Image") or (item_to_process == "EnCase Logical Evidence File"):

		#set up bulk extractor command
		if(whitelist_location != "NONE") and (keyword_list == "NONE"):
			be_command = "bulk_extractor -o " + folder_path_be + ' -w "' + whitelist_location + '" -j ' + str(cores_to_use) + " " + evidence
		elif(whitelist_location == "NONE") and (keyword_list =="NONE"):
			be_command = "bulk_extractor -o " + folder_path_be + " -j " + str(cores_to_use) + " " + evidence
		elif(whitelist_location != "NONE") and (keyword_list != "NONE"):
			be_command = "bulk_extractor -o " + folder_path_be + ' -w "' + whitelist_location + '" -F "' + keyword_list + '" -j ' + str(cores_to_use) + " " + evidence
		elif(whitelist_location == "NONE") and (keyword_list != "NONE"):
			be_command = "bulk_extractor -o " + folder_path_be + ' -F "' + keyword_list + '" -j ' + str(cores_to_use) + " " + evidence

		#outfile.write("The be_command is: " + be_command + "\n")

		#run be_command
		print("The be command is: " + be_command)
		subprocess.call([be_command], shell=True)
	elif(item_to_process == "Bit-Stream Image"):
		#set up bulk extractor command
		if(whitelist_location != "NONE") and (keyword_list == "NONE"):
			be_command = "bulk_extractor -C 60 -o " + folder_path_be + ' -w "' + whitelist_location + '" -j ' + str(cores_to_use) + " " + evidence
		elif(whitelist_location == "NONE") and (keyword_list =="NONE"):
			be_command = "bulk_extractor -C 60 -o " + folder_path_be + " -j " + str(cores_to_use) + " " + evidence
		elif(whitelist_location != "NONE") and (keyword_list != "NONE"):
			be_command = "bulk_extractor -C 60 -o " + folder_path_be + ' -w "' + whitelist_location + '" -F "' + keyword_list + '" -j ' + str(cores_to_use) + " " + evidence
		elif(whitelist_location == "NONE") and (keyword_list != "NONE"):
			be_command = "bulk_extractor -C 60 -o " + folder_path_be + ' -F "' + keyword_list + '" -j ' + str(cores_to_use) + " " + evidence

		#run be_command
		print("The be command is: " + be_command)
		subprocess.call([be_command], shell=True)

		#run fiwalk
		fiwalk_command = "fiwalk -x " + evidence + " > " + '"' + folder_path + '/Bulk_Extractor_Results/fiwalk_output.xml' + '"'
		print("Running fiwalk: " + fiwalk_command)
		subprocess.call([fiwalk_command], shell=True)

		#run identify_filenames.py
		identify_filenames_command = "python3 /usr/share/bulk-extractor/python/identify_filenames.py --all --imagefile " + evidence + " --xmlfile " + '"' + folder_path + "/Bulk_Extractor_Results/fiwalk_output.xml" + '" "' + folder_path + "/Bulk_Extractor_Results" + '" "' + folder_path + "/Bulk_Extractor_Results/annotated_results/" + '"'
		print("Running identify_filenames.py: " + identify_filenames_command)
		subprocess.call([identify_filenames_command], shell=True)

		#chdir to output foler
		os.chdir(folder_path)

		#run text files through unix2dos
		for root, dirs, files in os.walk(folder_path + "/Bulk_Extractor_Results/"):
			for filenames in files:
				#get file extension
				fileName, fileExtension = os.path.splitext(filenames)
				if(fileExtension.lower() == ".txt"):
					full_path = os.path.join(root,filenames)
					quoted_full_path = "'" +full_path+"'"
					print("Running Unix2dos against file: " + quoted_full_path)
					#unix2dos_command = "sudo unix2dos " + "'"+filenames+"'"
					unix2dos_command = "sudo unix2dos " + quoted_full_path
					subprocess.call([unix2dos_command], shell=True)
def create_kml_from_exif_mr(item_to_process, case_number, root_folder_path, evidence):
	print("The item to process is: " + item_to_process)
	print("The case_name is: " + case_number)
	print("The output folder is: " + root_folder_path)
	print("The evidence to process is: " + evidence)

	evidence_no_quotes = evidence
	evidence = '"' + evidence + '"'

	#create output folder path
	folder_path = root_folder_path + "/" + "KML_From_EXIF"
	check_for_folder(folder_path, "NONE")
	

	#open a log file for output
	log_file = folder_path + "/KML_From_EXIF_logfile.txt"
	outfile = open(log_file, 'wt+')

	#initialize variables
	files_of_interest = {}
	files_of_interest_list = []
	mount_point = "NONE"

	log_file3 = folder_path + "/" + case_number + "_files_to_exploit.xls"
	outfile3 = open(log_file3, 'wt+')

	#write out column headers to xls file
	outfile3.write("Name\tMD5\tFile Size (kb)\n")



	if(item_to_process == "Directory"):
		#select folder to process
		folder_process = evidence_no_quotes
	
		#set folder variable to "folder" since this is a folder and not a disk partition
		folder = "Directory"

		#call process subroutine
		process(folder_process, outfile, folder_path, folder, outfile3)

	elif(item_to_process == 'EnCase Logical Evidence File'):
		folder = "LEF"
		file_to_process = evidence
		mount_point = mount_encase_v6_l01(case_number, file_to_process, outfile)
		process(mount_point, outfile, folder_path, folder, outfile3)

		#umount
		if(os.path.exists(mount_point)):
			subprocess.call(['sudo umount -f ' + mount_point], shell=True)
			os.rmdir(mount_point)

	elif(item_to_process == 'Single File'):
		process_single_file(evidence_no_quotes, outfile, folder_path, "Single-File", outfile3)

	elif(item_to_process == 'Bit-Stream Image'):

		#select image to process
		Image_Path = evidence

		#get datetime
		now = datetime.datetime.now()

		#set Mount Point
		mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S")	

		#check to see if Image file is in Encase format
		if re.search(".E01", Image_Path):
			#strip out single quotes from the quoted path
			no_quotes_path = Image_Path.replace("'","")
			print("The no quotes path is: " + no_quotes_path)
			#call mount_ewf function
			cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
			try:
				subprocess.call([cmd_false], shell=True)
			except:
				print("Autmount false failed")
			Image_Path = mount_ewf(Image_Path, outfile, mount_point)

		#call mmls function
		partition_info_dict, temp_time = mmls(outfile, Image_Path)
		#partition_info_dict_temp, temp_time = partition_info_dict

		#get filesize of mmls_output.txt
		file_size = os.path.getsize("/tmp/mmls_output_" + temp_time +".txt") 
		print("The filesize is: " + str(file_size))

		#if filesize of mmls output is 0 then run parted
		if(file_size == 0):
			print("mmls output was empty, running parted")
			outfile.write("mmls output was empty, running parted")
			#call parted function
			partition_info_dict, temp_time = parted(outfile, Image_Path)	

		else:
	
			#read through the mmls output and look for GUID Partition Tables (used on MACS)
			mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt", 'r')
			for line in mmls_output_file:
				if re.search("GUID Partition Table", line):
					print("We found a GUID partition table, need to use parted")
					outfile.write("We found a GUID partition table, need to use parted\n")
					#call parted function
					partition_info_dict, temp_time = parted(outfile, Image_Path)

			#close file
			mmls_output_file.close()

		#loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
		#for key,value in partition_info_dict.items():
		for key,value in sorted(partition_info_dict.items()):

			#create output folder for processed files
			if not os.path.exists(folder_path + "/Processed_files_" + str(key)):
				os.mkdir(folder_path + "/Processed_files_" + str(key))

			#disable auto-mount in nautilis - this stops a nautilis window from popping up everytime the mount command is executed
			cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
			try:
				subprocess.call([cmd_false], shell=True)
			except:
				print("Autmount false failed")

			#call mount sub-routine
			success_code, loopback_device_mount = mount(value,key,Image_Path, outfile, mount_point)

			if(success_code):
				print("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
				outfile.write("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
			else:
		
				print("We just mounted filesystem: " + value + " at offset:" + str(key) + ". Scanning for files of interest.....\n")
				outfile.write("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")

				#call process subroutine
				process(mount_point, outfile, folder_path, key, outfile3)
			

				#unmount and remove mount points
				if(os.path.exists(mount_point)): 
					subprocess.call(['sudo umount -f ' + mount_point], shell=True)
					os.rmdir(mount_point)
				#unmount loopback device if this image was HFS+ - need to run losetup -d <loop_device> before unmounting
				if not (loopback_device_mount == "NONE"):
					losetup_d_command = "losetup -d " + loopback_device_mount
					subprocess.call([losetup_d_command], shell=True)

			#delete /tmp files created for processing bit-stream images
			if (os.path.exists("/tmp/mmls_output_" + temp_time + ".txt")):
				os.remove("/tmp/mmls_output_" + temp_time + ".txt")

	#write out list of filenames to end of output file so that user can create a filter for those filenames in Encase
	outfile3.write("\n\n******** LIST of FILENAMES of INTEREST ******************\n")
	#sort list so that all values are unique
	unique(files_of_interest_list) 
	for files in files_of_interest_list:
		outfile3.write(files + "\n")
	

	#program cleanup
	outfile.close()
	outfile3.close()

	#remove mount points created for this program
	if(os.path.exists(mount_point)):
		subprocess.call(['sudo umount -f ' + mount_point], shell=True)
		os.rmdir(mount_point)
	if(os.path.exists(mount_point+"_ewf")):
		subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
		os.rmdir(mount_point+"_ewf")
	
	#convert outfile using unix2dos	
	#chdir to output foler
	os.chdir(folder_path)

	#run text files through unix2dos
	for root, dirs, files in os.walk(folder_path):
		for filenames in files:
			#get file extension
			fileName, fileExtension = os.path.splitext(filenames)
			if(fileExtension.lower() == ".txt"):
				full_path = os.path.join(root,filenames)
				quoted_full_path = "'" +full_path+"'"
				print("Running Unix2dos against file: " + filenames)
				unix2dos_command = "sudo unix2dos " + filenames
				subprocess.call([unix2dos_command], shell=True)

	#delete empty directories in output folder
	for root, dirs, files in os.walk(folder_path, topdown=False):	
		for directories in dirs:
			files = []
			dir_path = os.path.join(root,directories)
			files = os.listdir(dir_path)	
			if(len(files) == 0):
				os.rmdir(dir_path)

	#unmount and remove mount points
	if(mount_point != "NONE"):
		if(os.path.exists(mount_point+"_ewf")):
			subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
			os.rmdir(mount_point+"_ewf")
Beispiel #8
0
def entropy_mr(item_to_process, case_number, root_folder_path, evidence):
	
	print("The item to process is: " + item_to_process)
	print("The case_name is: " + case_number)
	print("The output folder is: " + root_folder_path)
	print("The evidence to process is: " + evidence)

	evidence_no_quotes = evidence
	evidence = '"' + evidence + '"'

	#get datetime
	now = datetime.datetime.now()

	#set Mount Point
	mount_point = "/mnt/" + "MantaRay_" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")
	
	#create output folder path
	folder_path = root_folder_path + "/" + "Entropy"
	check_for_folder(folder_path, "NONE")
	

	#open a log file for output
	log_file = folder_path + "/Entropy_logfile.txt"
	outfile = open(log_file, 'wt+')

	#open file to write output
	exp_file = folder_path + "/" + case_number +"_entropy.csv"
	export_file = open(exp_file, 'a+', encoding='latin-1', errors="ignore")
	#export_file = open(exp_file, 'a')

	if(item_to_process == "Single File"):
		ent = calc_entropy(evidence)
		print(ent)

	elif(item_to_process == "Directory"):
		folder_to_process = evidence_no_quotes
		process_folder(folder_to_process, export_file, outfile)
	elif(item_to_process =="EnCase Logical Evidence File"):
		file_to_process = evidence
		mount_point = mount_encase_v6_l01(case_number, file_to_process, outfile)
		process_folder(mount_point, export_file, outfile)

		#umount
		if(os.path.exists(mount_point)):
			subprocess.call(['sudo umount -f ' + mount_point], shell=True)
			os.rmdir(mount_point)
	elif(item_to_process == "Bit-Stream Image"):
		Image_Path = evidence
		#process every file on every partition
		#get datetime
		now = datetime.datetime.now()

		#set Mount Point
		mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

		#check if Image file is in Encase format
		if re.search(".E01", Image_Path):

			#strip out single quotes from the quoted path
			#no_quotes_path = Image_Path.replace("'","")
			#print("THe no quotes path is: " +  no_quotes_path)
			#call mount_ewf function
			Image_Path = mount_ewf(Image_Path, outfile,mount_point)


		#call mmls function
		partition_info_dict, temp_time = mmls(outfile, Image_Path)
		partition_info_dict_temp = partition_info_dict

		#get filesize of mmls_output.txt
		file_size = os.path.getsize("/tmp/mmls_output_" + temp_time + ".txt") 


		#if filesize of mmls output is 0 then run parted
		if(file_size == 0):
			print("mmls output was empty, running parted")
			outfile.write("mmls output was empty, running parted")
			#call parted function
			partition_info_dict, temp_time = parted(outfile, Image_Path)	

		else:

			#read through the mmls output and look for GUID Partition Tables (used on MACS)
			mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt", 'r')
			for line in mmls_output_file:
				if re.search("GUID Partition Table", line):
					print("We found a GUID partition table, need to use parted")
					outfile.write("We found a GUID partition table, need to use parted\n")
					#call parted function
					partition_info_dict, temp_time = parted(outfile, Image_Path)
			mmls_output_file.close()
			

		#loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
		for key,value in sorted(partition_info_dict.items()):

			#disable auto-mount in nautilis - this stops a nautilis window from popping up everytime the mount command is executed
			cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
			try:
				subprocess.call([cmd_false], shell=True)
			except:
				print("Autmount false failed")

			#call mount sub-routine
			success_code, loopback_device_mount = mount(value,str(key),Image_Path, outfile, mount_point)

			if(success_code):
				print("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
				outfile.write("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
			else:
		
				print("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")
				outfile.write("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")

				#call entropy function for each mount_point
				process_folder(mount_point, export_file, outfile)
				print("We just finished calculating the entropy for every file...sorting output")

				#unmount and remove mount points
				if(os.path.exists(mount_point)): 
					subprocess.call(['sudo umount -f ' + mount_point], shell=True)
					os.rmdir(mount_point)
				#unmount loopback device if this image was HFS+ - need to run losetup -d <loop_device> before unmounting
				if not (loopback_device_mount == "NONE"):
					losetup_d_command = "losetup -d " + loopback_device_mount
					subprocess.call([losetup_d_command], shell=True)

			

		#delete /tmp files created for each partition
		if (os.path.exists("/tmp/mmls_output_" + temp_time + ".txt")):
			os.remove("/tmp/mmls_output_" + temp_time + ".txt")

		

	#close output file
	export_file.close()

	#sort output file
	sort_command = "strings -a  " + "'" + exp_file + "'" + " |sort -t\| -r -k 2n > " + "'" + folder_path + "'" + "/" + case_number +"_entropy_sorted.csv"
	subprocess.call([sort_command], shell=True)

	#write header row to export_file
	#sed_command = "sed -i '1i\ Entropy,File Name,File Size,MD5,File Path' " + "'" + folder_path + "'" + "/" + 	case_number +"_entropy_sorted.csv"
	sed_command = "sed -i '1i\ Entropy,File Name,File Size,FilePath' " + "'" + folder_path + "'" + "/" + 	case_number +"_entropy_sorted.csv"
	subprocess.call([sed_command], shell=True)

	#remove original output file
	os.remove(exp_file)

	#remove mount points created for this program
	if(os.path.exists(mount_point)):
		os.rmdir(mount_point)
	if(os.path.exists(mount_point+"_ewf")):
		subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
		os.rmdir(mount_point+"_ewf")
def create_kml_from_exif_mr(item_to_process, case_number, root_folder_path,
                            evidence):
    print("The item to process is: " + item_to_process)
    print("The case_name is: " + case_number)
    print("The output folder is: " + root_folder_path)
    print("The evidence to process is: " + evidence)

    evidence_no_quotes = evidence
    evidence = '"' + evidence + '"'

    #create output folder path
    folder_path = root_folder_path + "/" + "KML_From_EXIF"
    check_for_folder(folder_path, "NONE")

    #open a log file for output
    log_file = folder_path + "/KML_From_EXIF_logfile.txt"
    outfile = open(log_file, 'wt+')

    #initialize variables
    files_of_interest = {}
    files_of_interest_list = []
    mount_point = "NONE"

    log_file3 = folder_path + "/" + case_number + "_files_to_exploit.xls"
    outfile3 = open(log_file3, 'wt+')

    #write out column headers to xls file
    outfile3.write("Name\tMD5\tFile Size (kb)\n")

    if (item_to_process == "Directory"):
        #select folder to process
        folder_process = evidence_no_quotes

        #set folder variable to "folder" since this is a folder and not a disk partition
        folder = "Directory"

        #call process subroutine
        process(folder_process, outfile, folder_path, folder, outfile3)

    elif (item_to_process == 'EnCase Logical Evidence File'):
        folder = "LEF"
        file_to_process = evidence
        mount_point = mount_encase_v6_l01(case_number, file_to_process,
                                          outfile)
        process(mount_point, outfile, folder_path, folder, outfile3)

        #umount
        if (os.path.exists(mount_point)):
            subprocess.call(['sudo umount -f ' + mount_point], shell=True)
            os.rmdir(mount_point)

    elif (item_to_process == 'Single File'):
        process_single_file(evidence_no_quotes, outfile, folder_path,
                            "Single-File", outfile3)

    elif (item_to_process == 'Bit-Stream Image'):

        #select image to process
        Image_Path = evidence

        #get datetime
        now = datetime.datetime.now()

        #set Mount Point
        mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S")

        #check to see if Image file is in Encase format
        if re.search(".E01", Image_Path):
            #strip out single quotes from the quoted path
            no_quotes_path = Image_Path.replace("'", "")
            print("The no quotes path is: " + no_quotes_path)
            #call mount_ewf function
            cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
            try:
                subprocess.call([cmd_false], shell=True)
            except:
                print("Autmount false failed")
            Image_Path = mount_ewf(Image_Path, outfile, mount_point)

        #call mmls function
        partition_info_dict, temp_time = mmls(outfile, Image_Path)
        #partition_info_dict_temp, temp_time = partition_info_dict

        #get filesize of mmls_output.txt
        file_size = os.path.getsize("/tmp/mmls_output_" + temp_time + ".txt")
        print("The filesize is: " + str(file_size))

        #if filesize of mmls output is 0 then run parted
        if (file_size == 0):
            print("mmls output was empty, running parted")
            outfile.write("mmls output was empty, running parted")
            #call parted function
            partition_info_dict, temp_time = parted(outfile, Image_Path)

        else:

            #read through the mmls output and look for GUID Partition Tables (used on MACS)
            mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt",
                                    'r')
            for line in mmls_output_file:
                if re.search("GUID Partition Table", line):
                    print(
                        "We found a GUID partition table, need to use parted")
                    outfile.write(
                        "We found a GUID partition table, need to use parted\n"
                    )
                    #call parted function
                    partition_info_dict, temp_time = parted(
                        outfile, Image_Path)

            #close file
            mmls_output_file.close()

        #loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
        #for key,value in partition_info_dict.items():
        for key, value in sorted(partition_info_dict.items()):

            #create output folder for processed files
            if not os.path.exists(folder_path + "/Processed_files_" +
                                  str(key)):
                os.mkdir(folder_path + "/Processed_files_" + str(key))

            #disable auto-mount in nautilis - this stops a nautilis window from popping up everytime the mount command is executed
            cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
            try:
                subprocess.call([cmd_false], shell=True)
            except:
                print("Autmount false failed")

            #call mount sub-routine
            success_code, loopback_device_mount = mount(
                value, key, Image_Path, outfile, mount_point)

            if (success_code):
                print("Could not mount partition with filesystem: " + value +
                      " at offset:" + str(key))
                outfile.write("Could not mount partition with filesystem: " +
                              value + " at offset:" + str(key))
            else:

                print("We just mounted filesystem: " + value + " at offset:" +
                      str(key) + ". Scanning for files of interest.....\n")
                outfile.write("We just mounted filesystem: " + value +
                              " at offset:" + str(key) + "\n")

                #call process subroutine
                process(mount_point, outfile, folder_path, key, outfile3)

                #unmount and remove mount points
                if (os.path.exists(mount_point)):
                    subprocess.call(['sudo umount -f ' + mount_point],
                                    shell=True)
                    os.rmdir(mount_point)
                #unmount loopback device if this image was HFS+ - need to run losetup -d <loop_device> before unmounting
                if not (loopback_device_mount == "NONE"):
                    losetup_d_command = "losetup -d " + loopback_device_mount
                    subprocess.call([losetup_d_command], shell=True)

            #delete /tmp files created for processing bit-stream images
            if (os.path.exists("/tmp/mmls_output_" + temp_time + ".txt")):
                os.remove("/tmp/mmls_output_" + temp_time + ".txt")

    #write out list of filenames to end of output file so that user can create a filter for those filenames in Encase
    outfile3.write(
        "\n\n******** LIST of FILENAMES of INTEREST ******************\n")
    #sort list so that all values are unique
    unique(files_of_interest_list)
    for files in files_of_interest_list:
        outfile3.write(files + "\n")

    #program cleanup
    outfile.close()
    outfile3.close()

    #remove mount points created for this program
    if (os.path.exists(mount_point)):
        subprocess.call(['sudo umount -f ' + mount_point], shell=True)
        os.rmdir(mount_point)
    if (os.path.exists(mount_point + "_ewf")):
        subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
        os.rmdir(mount_point + "_ewf")

    #convert outfile using unix2dos
    #chdir to output foler
    os.chdir(folder_path)

    #run text files through unix2dos
    for root, dirs, files in os.walk(folder_path):
        for filenames in files:
            #get file extension
            fileName, fileExtension = os.path.splitext(filenames)
            if (fileExtension.lower() == ".txt"):
                full_path = os.path.join(root, filenames)
                quoted_full_path = "'" + full_path + "'"
                print("Running Unix2dos against file: " + filenames)
                unix2dos_command = "sudo unix2dos " + filenames
                subprocess.call([unix2dos_command], shell=True)

    #delete empty directories in output folder
    for root, dirs, files in os.walk(folder_path, topdown=False):
        for directories in dirs:
            files = []
            dir_path = os.path.join(root, directories)
            files = os.listdir(dir_path)
            if (len(files) == 0):
                os.rmdir(dir_path)

    #unmount and remove mount points
    if (mount_point != "NONE"):
        if (os.path.exists(mount_point + "_ewf")):
            subprocess.call(['sudo umount -f ' + mount_point + "_ewf"],
                            shell=True)
            os.rmdir(mount_point + "_ewf")
Beispiel #10
0
def plaso_mr(item_to_process, case_number, root_folder_path, evidence):
	#(evidence_type, case_number, folder_path, evidence_path.strip())
	
	print("The item to process is: " + item_to_process)
	print("The case_name is: " + case_number)
	print("The output folder is: " + root_folder_path)
	print("The evidence to process is: " + evidence)

	evidence_no_quotes = evidence
	evidence = '"' + evidence + '"'

	root_folder_path_no_quotes = root_folder_path
	root_folder_path = "'" + root_folder_path + "'"

	#get datetime
	now = datetime.datetime.now()
	
	#create output folder path
	folder_path = root_folder_path_no_quotes + "/" + "Plaso"
	check_for_folder(folder_path, "NONE")
	

	#open a log file for output
	log_file = folder_path + "/Plaso_mr_logfile.txt"
	outfile = open(log_file, 'wt+')

	if(item_to_process == "Directory"):
		folder_to_process = evidence_no_quotes
		process_folder(folder_path, case_number, folder_to_process, outfile)
	elif(item_to_process =="EnCase Logical Evidence File"):
		file_to_process = evidence
		mount_point = mount_encase_v6_l01(case_number, file_to_process, outfile)
		process_folder(mount_point, export_file, outfile)

		#umount
		if(os.path.exists(mount_point)):
			subprocess.call(['sudo umount -f ' + mount_point], shell=True)
			os.rmdir(mount_point)
	elif(item_to_process == "Bit-Stream Image"):
		Image_Path = evidence_no_quotes
		
		#get datetime
		now = datetime.datetime.now()
		process_folder(folder_path, case_number, Image_Path, outfile)

		

		## I have not been able to test this code yet since I don't have a large enough test imge
		#set file to split
		#file_to_split = folder_path + "/" + case_number + ".plaso.csv"
		#file_to_split_basename = case_number + ".plaso.csv"

		#pass csv file to split_csv to see if it needs to get split
		#split_csv(case_number, folder_path, outfile)
		#split_csv(case_number, folder_path, outfile, file_to_split, file_to_split_basename)

		

			
			

	#close output file
	outfile.close()
Beispiel #11
0
def plist_processor(item_to_process, case_number, root_folder_path, evidence):
    print("The item to process is: " + item_to_process)
    print("The case_name is: " + case_number)
    print("The output folder is: " + root_folder_path)
    print("The evidence to process is: " + evidence)

    evidence_no_quotes = evidence
    evidence = '"' + evidence + '"'

    #get datetime
    now = datetime.datetime.now()

    #set Mount Point
    mount_point = "/mnt/" + "MantaRay_" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

    #create output folder path
    folder_path = root_folder_path + "/" + "PLIST_Processor"
    check_for_folder(folder_path, "NONE")

    #open a log file for output
    log_file = folder_path + "/PLIST_processor_logfile.txt"
    outfile = open(log_file, 'wt+')

    #open an error file for output
    log_file = folder_path + "/PLIST_processor_error_log.txt"
    outfile_error = open(log_file, 'wt+')

    #open file to write output
    exp_file = folder_path + "/" + case_number + "_PLIST_Triage.txt"
    export_file = open(exp_file, 'a')

    if (item_to_process == "Directory"):
        folder_to_process = evidence_no_quotes
        process_folder(folder_to_process, export_file, outfile, outfile_error,
                       now)
    elif (item_to_process == "EnCase Logical Evidence File"):
        file_to_process = evidence
        mount_point = mount_encase_v6_l01(case_number, file_to_process,
                                          outfile)
        process_folder(mount_point, export_file, outfile, outfile_error, now)

        #umount
        if (os.path.exists(mount_point)):
            subprocess.call(['sudo umount -f ' + mount_point], shell=True)
            os.rmdir(mount_point)
    elif (item_to_process == "Bit-Stream Image"):

        #set Mount Point
        mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

        Image_Path = evidence

        #check if Image file is in Encase format
        if re.search(".E01", Image_Path):
            #set mount point
            #mount_point = "/mnt/"+	case_number+"_ewf"
            Image_Path = mount_ewf(Image_Path, outfile, mount_point)

        #call mmls function
        partition_info_dict, temp_time = mmls(outfile, Image_Path)
        partition_info_dict_temp = partition_info_dict

        #get filesize of mmls_output.txt
        file_size = os.path.getsize("/tmp/mmls_output_" + temp_time + ".txt")

        #if filesize of mmls output is 0 then run parted
        if (file_size == 0):
            print("mmls output was empty, running parted\n")
            outfile.write("mmls output was empty, running parted\n")
            #call parted function
            partition_info_dict, temp_time = parted(outfile, Image_Path)

        else:

            #read through the mmls output and look for GUID Partition Tables (used on MACS)
            mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt",
                                    'r')
            for line in mmls_output_file:
                if re.search("GUID Partition Table", line):
                    print(
                        "We found a GUID partition table, need to use parted")
                    outfile.write(
                        "We found a GUID partition table, need to use parted\n"
                    )
                    #call parted function
                    partition_info_dict, temp_time = parted(
                        outfile, Image_Path)
            mmls_output_file.close()

        #loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
        for key, value in partition_info_dict.items():
            cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
            try:
                subprocess.call([cmd_false], shell=True)
            except:
                print("Autmount false failed")

            #process plist files
            if (value == "hfs+"):
                #call mount sub-routine
                success_code, loopback_device_mount = mount(
                    value, str(key), Image_Path, outfile, mount_point)

                if (success_code):
                    print("Could not mount partition with filesystem: " +
                          value + " at offset:" + str(key))
                    outfile.write(
                        "Could not mount partition with filesystem: " + value +
                        " at offset:" + str(key))
                else:

                    print("We just mounted filesystem: " + value +
                          " at offset:" + str(key) + "\n")
                    outfile.write("We just mounted filesystem: " + value +
                                  " at offset:" + str(key) + "\n")

                    #process
                    process_folder(mount_point, export_file, outfile,
                                   outfile_error, now)

                    #unmount
                    subprocess.call(['umount ' + mount_point], shell=True)
                    subprocess.call(['losetup -d ' + loopback_device_mount],
                                    shell=True)

            else:
                print("This partition is not formatted HFS+")
                outfile.write("This partition is not formatted HFS+\n\n")
        #close export_file
        export_file.close()

        #chdir to output foler
        os.chdir(folder_path)

        #unmount and remount points
        if re.search(".E01", Image_Path):
            if (os.path.exists(mount_point + "_ewf")):
                subprocess.call(['sudo umount -f ' + mount_point + "_ewf"],
                                shell=True)
                os.rmdir(mount_point + "_ewf")

        #remove empty directories
        for root, dirs, files in os.walk(folder_path, topdown=False):
            for directory in dirs:
                dir_path = os.path.join(root, directory)
                if not os.listdir(dir_path):
                    outfile.write("Removing empty folder: " + dir_path + "\n")
                    os.rmdir(dir_path)

        #close outfiles
        outfile.close()

        #run text files through unix2dos
        for root, dirs, files in os.walk(folder_path):
            for filenames in files:
                #get file extension
                fileName, fileExtension = os.path.splitext(filenames)
                if (fileExtension.lower() == ".txt"):
                    full_path = os.path.join(root, filenames)
                    quoted_full_path = "'" + full_path + "'"
                    print("Running Unix2dos against file: " + filenames)
                    unix2dos_command = "sudo unix2dos " + quoted_full_path
                    subprocess.call([unix2dos_command], shell=True)

        #delete /tmp/ls_output.txt
        if (os.path.exists("/tmp/mmls_output_" + temp_time + ".txt")):
            os.remove("/tmp/mmls_output_" + temp_time + ".txt")
        if (os.path.exists("/tmp/timeline_partition_info_" + temp_time +
                           ".txt")):
            os.remove("/tmp/timeline_partition_info_" + temp_time + ".txt")
        if (os.path.exists("/tmp/dump_" + temp_time + ".txt")):
            os.remove("/tmp/dump_" + temp_time + ".txt")
        if (os.path.exists("/tmp/fls_output_" + temp_time + ".txt")):
            os.remove("/tmp/fls_output_" + temp_time + ".txt")
        if (os.path.exists("/tmp/hives_to_rename_" + temp_time)):
            shutil.rmtree("/tmp/hives_to_rename_" + temp_time)
Beispiel #12
0
def sa_mr(item_to_process, case_number, root_folder_path, evidence):
	
	print("The item to process is: " + item_to_process)
	print("The case_name is: " + case_number)
	print("The output folder is: " + root_folder_path)
	print("The evidence to process is: " + evidence)

	evidence_no_quotes = evidence
	evidence = '"' + evidence + '"'

	#get datetime
	now = datetime.datetime.now()

	#set Mount Point
	mount_point = "/mnt/" + "MantaRay_" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")
	
	#create output folder path
	folder_path = root_folder_path + "/" + "Static Malware Analysis"
	check_for_folder(folder_path , "NONE")
	

	#open a log file for output
	log_file = folder_path + "/Static_Malware_Analysis_logfile.txt"
	outfile = open(log_file, 'wt+')

	if(item_to_process == "Single File"):
		#get base filename to process
		filename = os.path.basename(evidence_no_quotes)
		print("The file to process is: " + filename)

		#make output folder for this file
		check_for_folder(folder_path + "/" + filename, "NONE")

		#run Mastiff
		run_mastiff(evidence, filename, folder_path, evidence_no_quotes, outfile)

		#run pescanner
		run_pescanner(evidence, filename, folder_path, evidence_no_quotes, outfile)

		#run pestr
		run_pestr(evidence, filename, folder_path, evidence_no_quotes, outfile)

		#run readpe
		run_readpe(evidence, filename, folder_path, evidence_no_quotes, outfile)

		#run pedump
		run_pedump(evidence, filename, folder_path, evidence_no_quotes, outfile)

		#run peframe
		run_peframe(evidence, filename, folder_path, evidence_no_quotes, outfile)

		#run signsrch
		run_signsrch(evidence, filename, folder_path, evidence_no_quotes, outfile)

	elif(item_to_process == "Directory"):
		folder_to_process = evidence_no_quotes
		#get base filename to process
		process_folder(folder_to_process, folder_path, evidence_no_quotes, outfile)
	elif(item_to_process =="EnCase Logical Evidence File"):
		file_to_process = evidence
		mount_point = mount_encase_v6_l01(case_number, file_to_process, outfile)
		process_folder(mount_point, folder_path, evidence_no_quotes, outfile)

		#umount
		if(os.path.exists(mount_point)):
			subprocess.call(['sudo umount -f ' + mount_point], shell=True)
			os.rmdir(mount_point)


	#remove mount points created for this program
	if(os.path.exists(mount_point)):
		os.rmdir(mount_point)
	if(os.path.exists(mount_point+"_ewf")):
		subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
		os.rmdir(mount_point+"_ewf")

	#close outfile
	outfile.close()

	#run text files through unix2dos
	for root, dirs, files in os.walk(folder_path):
		for filenames in files:
			#get file extension
			fileName, fileExtension = os.path.splitext(filenames)
			if(fileExtension.lower() == ".txt"):
				full_path = os.path.join(root,filenames)
				quoted_full_path = "'" +full_path+"'"
				print("Running Unix2dos against file: " + quoted_full_path)
				unix2dos_command = "sudo unix2dos " + quoted_full_path
				subprocess.call([unix2dos_command], shell=True)
Beispiel #13
0
def entropy_module(item_to_process, folder_path, case_number):

    #get datetime
    now = datetime.datetime.now()

    #open a log file for output
    log_file = folder_path + "/" + case_number + "_logfile.txt"
    outfile = open(log_file, 'a')

    #open file to write output
    exp_file = folder_path + "/" + case_number + "_entropy.csv"
    export_file = open(exp_file, 'a')

    if (item_to_process == "file"):
        file_to_process = select_file_to_process(outfile)
        ent = calc_entropy(file_to_process)
        print(ent)

    elif (item_to_process == "folder"):
        folder_to_process = select_folder_to_process(outfile)
        process_folder(folder_to_process, export_file)
    elif (item_to_process == "L01"):
        file_to_process = select_file_to_process(outfile)
        mount_point = mount_encase_v6_l01(case_number, file_to_process,
                                          outfile)
        process_folder(mount_point, export_file)

        #umount
        if (os.path.exists(mount_point)):
            subprocess.call(['sudo umount -f ' + mount_point], shell=True)
            os.rmdir(mount_point)
    elif (item_to_process == "image"):
        Image_Path = select_file_to_process(outfile)

        #process every file on every partition
        #get datetime
        now = datetime.datetime.now()

        #set Mount Point
        mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S")

        #check if Image file is in Encase format
        if re.search(".E01", Image_Path):

            #strip out single quotes from the quoted path
            #no_quotes_path = Image_Path.replace("'","")
            #print("THe no quotes path is: " +  no_quotes_path)
            #call mount_ewf function
            Image_Path = mount_ewf(Image_Path, outfile, mount_point)

        #call mmls function
        partition_info_dict = mmls(outfile, Image_Path)
        partition_info_dict_temp = partition_info_dict

        #get filesize of mmls_output.txt
        file_size = os.path.getsize("/tmp/mmls_output.txt")

        #if filesize of mmls output is 0 then run parted
        if (file_size == 0):
            print("mmls output was empty, running parted")
            outfile.write("mmls output was empty, running parted")
            #call parted function
            partition_info_dict = parted(outfile, Image_Path)

        else:

            #read through the mmls output and look for GUID Partition Tables (used on MACS)
            mmls_output_file = open("/tmp/mmls_output.txt", 'r')
            for line in mmls_output_file:
                if re.search("GUID Partition Table", line):
                    print(
                        "We found a GUID partition table, need to use parted")
                    outfile.write(
                        "We found a GUID partition table, need to use parted\n"
                    )
                    #call parted function
                    partition_info_dict = parted(outfile, Image_Path)

        #loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
        for key, value in sorted(partition_info_dict.items()):

            #call mount sub-routine
            success_code = mount(value, str(key), Image_Path, outfile,
                                 mount_point)

            if (success_code):
                print("Could not mount partition with filesystem: " + value +
                      " at offset:" + str(key))
                outfile.write("Could not mount partition with filesystem: " +
                              value + " at offset:" + str(key))
            else:

                print("We just mounted filesystem: " + value + " at offset:" +
                      str(key) + "\n")
                outfile.write("We just mounted filesystem: " + value +
                              " at offset:" + str(key) + "\n")

                #call entropy function for each mount_point
                process_folder(mount_point, export_file)

                #unmount and remove mount points
                if (os.path.exists(mount_point)):
                    subprocess.call(['sudo umount -f ' + mount_point],
                                    shell=True)
                    os.rmdir(mount_point)

    #close output file
    export_file.close()

    #sort output file
    sort_command = "strings -a  " + "'" + exp_file + "'" + " |sort -t\| -r -k 2n > " + "'" + folder_path + "'" + "/" + case_number + "_entropy_sorted.csv"
    subprocess.call([sort_command], shell=True)

    #write header row to export_file
    sed_command = "sed -i '1i\ Entropy,File Name,File Size,File Path' " + "'" + folder_path + "'" + "/" + case_number + "_entropy_sorted.csv"
    subprocess.call([sed_command], shell=True)

    #remove original output file
    os.remove(exp_file)
Beispiel #14
0
def av_scanner_mr(item_to_process, case_number, root_folder_path, evidence,
                  conf_file):

    print("The item to process is: " + item_to_process)
    print("The case_name is: " + case_number)
    print("The output folder is: " + root_folder_path)
    print("The evidence to process is: " + evidence)
    print("The configuration file is located at: " + conf_file)

    evidence_no_quotes = evidence
    evidence = '"' + evidence + '"'

    #get datetime
    now = datetime.datetime.now()

    #set Mount Point
    mount_point = "/mnt/" + "MantaRay_" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

    #create output folder path
    output_folder_path = root_folder_path + "/" + "AV_Scanner"
    check_for_folder(output_folder_path, "NONE")

    #open a log file for output
    log_file = output_folder_path + "/AV_Scanner_logfile.txt"
    outfile = open(log_file, 'wt+')

    if (item_to_process == "Single File"):
        print("Please put your file in a folder and then scan the folder")

    elif (item_to_process == "Directory"):
        folder_to_process = evidence_no_quotes
        process_folder(folder_to_process, output_folder_path, outfile,
                       "Directory", conf_file)
    elif (item_to_process == "EnCase Logical Evidence File"):
        file_to_process = evidence
        mount_point = mount_encase_v6_l01(case_number, file_to_process,
                                          outfile)
        process_folder(mount_point, output_folder_path, outfile, "LEF",
                       conf_file)

        #umount
        if (os.path.exists(mount_point)):
            subprocess.call(['sudo umount -f ' + mount_point], shell=True)
            os.rmdir(mount_point)
    elif (item_to_process == "Bit-Stream Image"):
        Image_Path = evidence
        #process every file on every partition
        #get datetime
        now = datetime.datetime.now()

        #set Mount Point
        mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

        #check if Image file is in Encase format
        if re.search(".E01", Image_Path):

            #strip out single quotes from the quoted path
            #no_quotes_path = Image_Path.replace("'","")
            #print("THe no quotes path is: " +  no_quotes_path)
            #call mount_ewf function
            Image_Path = mount_ewf(Image_Path, outfile, mount_point)

        #call mmls function
        partition_info_dict, temp_time = mmls(outfile, Image_Path)
        partition_info_dict_temp = partition_info_dict

        #get filesize of mmls_output.txt
        file_size = os.path.getsize("/tmp/mmls_output_" + temp_time + ".txt")

        #if filesize of mmls output is 0 then run parted
        if (file_size == 0):
            print("mmls output was empty, running parted")
            outfile.write("mmls output was empty, running parted")
            #call parted function
            partition_info_dict, temp_time = parted(outfile, Image_Path)

        else:

            #read through the mmls output and look for GUID Partition Tables (used on MACS)
            mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt",
                                    'r')
            for line in mmls_output_file:
                if re.search("GUID Partition Table", line):
                    print(
                        "We found a GUID partition table, need to use parted")
                    outfile.write(
                        "We found a GUID partition table, need to use parted\n"
                    )
                    #call parted function
                    partition_info_dict, temp_time = parted(
                        outfile, Image_Path)
            mmls_output_file.close()

        #loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
        for key, value in sorted(partition_info_dict.items()):

            #disable auto-mount in nautilis - this stops a nautilis window from popping up everytime the mount command is executed
            cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
            try:
                subprocess.call([cmd_false], shell=True)
            except:
                print("Autmount false failed")

            #call mount sub-routine
            success_code, loopback_device_mount = mount(
                value, str(key), Image_Path, outfile, mount_point)

            if (success_code):
                print("Could not mount partition with filesystem: " + value +
                      " at offset:" + str(key))
                outfile.write("Could not mount partition with filesystem: " +
                              value + " at offset:" + str(key))
            else:

                print("We just mounted filesystem: " + value + " at offset:" +
                      str(key) + "\n")
                outfile.write("We just mounted filesystem: " + value +
                              " at offset:" + str(key) + "\n")

                #call av_scanner function for each mount_point
                process_folder(mount_point, output_folder_path, outfile,
                               "partition_offset_" + str(key), conf_file)
                print("We just finished scanning every file...sorting output")

                #unmount and remove mount points
                if (os.path.exists(mount_point)):
                    subprocess.call(['sudo umount -f ' + mount_point],
                                    shell=True)
                    os.rmdir(mount_point)
                #unmount loopback device if this image was HFS+ - need to run losetup -d <loop_device> before unmounting
                if not (loopback_device_mount == "NONE"):
                    losetup_d_command = "losetup -d " + loopback_device_mount
                    subprocess.call([losetup_d_command], shell=True)

        #delete /tmp files created for each partition
        if (os.path.exists("/tmp/mmls_output_" + temp_time + ".txt")):
            os.remove("/tmp/mmls_output_" + temp_time + ".txt")

    #close logfile
    outfile.close()

    #remove mount points created for this program
    if (os.path.exists(mount_point)):
        os.rmdir(mount_point)
    if (os.path.exists(mount_point + "_ewf")):
        subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
        os.rmdir(mount_point + "_ewf")

#run text files through unix2dos
    for root, dirs, files in os.walk(output_folder_path):
        for filenames in files:
            #get file extension
            fileName, fileExtension = os.path.splitext(filenames)
            if (fileExtension.lower() == ".txt"):
                full_path = os.path.join(root, filenames)
                quoted_full_path = "'" + full_path + "'"
                print("Running Unix2dos against file: " + quoted_full_path)
                #unix2dos_command = "sudo unix2dos " + "'"+filenames+"'"
                unix2dos_command = "sudo unix2dos " + quoted_full_path
                subprocess.call([unix2dos_command], shell=True)
Beispiel #15
0
def entropy_module(item_to_process, folder_path, case_number):

	#get datetime
	now = datetime.datetime.now()

	#open a log file for output
	log_file = folder_path + "/" + case_number + "_logfile.txt"
	outfile = open(log_file, 'a')

	#open file to write output
	exp_file = folder_path + "/" + case_number +"_entropy.csv"
	export_file = open(exp_file, 'a')

	if(item_to_process == "file"):
		file_to_process = select_file_to_process(outfile)
		ent = calc_entropy(file_to_process)
		print(ent)

	elif(item_to_process == "folder"):
		folder_to_process = select_folder_to_process(outfile)
		process_folder(folder_to_process, export_file)
	elif(item_to_process =="L01"):
		file_to_process = select_file_to_process(outfile)
		mount_point = mount_encase_v6_l01(case_number, file_to_process, outfile)
		process_folder(mount_point, export_file)

		#umount
		if(os.path.exists(mount_point)):
			subprocess.call(['sudo umount -f ' + mount_point], shell=True)
			os.rmdir(mount_point)
	elif(item_to_process == "image"):
		Image_Path = select_file_to_process(outfile)
	
		#process every file on every partition
		#get datetime
		now = datetime.datetime.now()

		#set Mount Point
		mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S")

		#check if Image file is in Encase format
		if re.search(".E01", Image_Path):

			#strip out single quotes from the quoted path
			#no_quotes_path = Image_Path.replace("'","")
			#print("THe no quotes path is: " +  no_quotes_path)
			#call mount_ewf function
			Image_Path = mount_ewf(Image_Path, outfile,mount_point)


		#call mmls function
		partition_info_dict = mmls(outfile, Image_Path)
		partition_info_dict_temp = partition_info_dict

		#get filesize of mmls_output.txt
		file_size = os.path.getsize("/tmp/mmls_output.txt") 


		#if filesize of mmls output is 0 then run parted
		if(file_size == 0):
			print("mmls output was empty, running parted")
			outfile.write("mmls output was empty, running parted")
			#call parted function
			partition_info_dict = parted(outfile, Image_Path)	

		else:

			#read through the mmls output and look for GUID Partition Tables (used on MACS)
			mmls_output_file = open("/tmp/mmls_output.txt", 'r')
			for line in mmls_output_file:
				if re.search("GUID Partition Table", line):
					print("We found a GUID partition table, need to use parted")
					outfile.write("We found a GUID partition table, need to use parted\n")
					#call parted function
					partition_info_dict = parted(outfile, Image_Path)
			

		#loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
		for key,value in sorted(partition_info_dict.items()):

			#call mount sub-routine
			success_code = mount(value,str(key),Image_Path, outfile, mount_point)

			if(success_code):
				print("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
				outfile.write("Could not mount partition with filesystem: " + value + " at offset:" + str(key))
			else:
		
				print("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")
				outfile.write("We just mounted filesystem: " + value + " at offset:" + str(key) + "\n")

				#call entropy function for each mount_point
				process_folder(mount_point, export_file)

				#unmount and remove mount points
				if(os.path.exists(mount_point)):
					subprocess.call(['sudo umount -f ' + mount_point], shell=True)
					os.rmdir(mount_point)

	#close output file
	export_file.close()

	#sort output file
	sort_command = "strings -a  " + "'" + exp_file + "'" + " |sort -t\| -r -k 2n > " + "'" + folder_path + "'" + "/" + case_number +"_entropy_sorted.csv"
	subprocess.call([sort_command], shell=True)

	#write header row to export_file
	sed_command = "sed -i '1i\ Entropy,File Name,File Size,File Path' " + "'" + folder_path + "'" + "/" + case_number +"_entropy_sorted.csv"
	subprocess.call([sed_command], shell=True)

	#remove original output file
	os.remove(exp_file)
Beispiel #16
0
def entropy_mr(item_to_process, case_number, root_folder_path, evidence):

    print("The item to process is: " + item_to_process)
    print("The case_name is: " + case_number)
    print("The output folder is: " + root_folder_path)
    print("The evidence to process is: " + evidence)

    evidence_no_quotes = evidence
    evidence = '"' + evidence + '"'

    #get datetime
    now = datetime.datetime.now()

    #set Mount Point
    mount_point = "/mnt/" + "MantaRay_" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

    #create output folder path
    folder_path = root_folder_path + "/" + "Entropy"
    check_for_folder(folder_path, "NONE")

    #open a log file for output
    log_file = folder_path + "/Entropy_logfile.txt"
    outfile = open(log_file, 'wt+')

    #open file to write output
    exp_file = folder_path + "/" + case_number + "_entropy.csv"
    export_file = open(exp_file, 'a+', encoding='latin-1', errors="ignore")
    #export_file = open(exp_file, 'a')

    if (item_to_process == "Single File"):
        ent = calc_entropy(evidence)
        print(ent)

    elif (item_to_process == "Directory"):
        folder_to_process = evidence_no_quotes
        process_folder(folder_to_process, export_file, outfile)
    elif (item_to_process == "EnCase Logical Evidence File"):
        file_to_process = evidence
        mount_point = mount_encase_v6_l01(case_number, file_to_process,
                                          outfile)
        process_folder(mount_point, export_file, outfile)

        #umount
        if (os.path.exists(mount_point)):
            subprocess.call(['sudo umount -f ' + mount_point], shell=True)
            os.rmdir(mount_point)
    elif (item_to_process == "Bit-Stream Image"):
        Image_Path = evidence
        #process every file on every partition
        #get datetime
        now = datetime.datetime.now()

        #set Mount Point
        mount_point = "/mnt/" + now.strftime("%Y-%m-%d_%H_%M_%S_%f")

        #check if Image file is in Encase format
        if re.search(".E01", Image_Path):

            #strip out single quotes from the quoted path
            #no_quotes_path = Image_Path.replace("'","")
            #print("THe no quotes path is: " +  no_quotes_path)
            #call mount_ewf function
            Image_Path = mount_ewf(Image_Path, outfile, mount_point)

        #call mmls function
        partition_info_dict, temp_time = mmls(outfile, Image_Path)
        partition_info_dict_temp = partition_info_dict

        #get filesize of mmls_output.txt
        file_size = os.path.getsize("/tmp/mmls_output_" + temp_time + ".txt")

        #if filesize of mmls output is 0 then run parted
        if (file_size == 0):
            print("mmls output was empty, running parted")
            outfile.write("mmls output was empty, running parted")
            #call parted function
            partition_info_dict, temp_time = parted(outfile, Image_Path)

        else:

            #read through the mmls output and look for GUID Partition Tables (used on MACS)
            mmls_output_file = open("/tmp/mmls_output_" + temp_time + ".txt",
                                    'r')
            for line in mmls_output_file:
                if re.search("GUID Partition Table", line):
                    print(
                        "We found a GUID partition table, need to use parted")
                    outfile.write(
                        "We found a GUID partition table, need to use parted\n"
                    )
                    #call parted function
                    partition_info_dict, temp_time = parted(
                        outfile, Image_Path)
            mmls_output_file.close()

        #loop through the dictionary containing the partition info (filesystem is VALUE, offset is KEY)
        for key, value in sorted(partition_info_dict.items()):

            #disable auto-mount in nautilis - this stops a nautilis window from popping up everytime the mount command is executed
            cmd_false = "sudo gsettings set org.gnome.desktop.media-handling automount false && sudo gsettings set org.gnome.desktop.media-handling automount-open false"
            try:
                subprocess.call([cmd_false], shell=True)
            except:
                print("Autmount false failed")

            #call mount sub-routine
            success_code, loopback_device_mount = mount(
                value, str(key), Image_Path, outfile, mount_point)

            if (success_code):
                print("Could not mount partition with filesystem: " + value +
                      " at offset:" + str(key))
                outfile.write("Could not mount partition with filesystem: " +
                              value + " at offset:" + str(key))
            else:

                print("We just mounted filesystem: " + value + " at offset:" +
                      str(key) + "\n")
                outfile.write("We just mounted filesystem: " + value +
                              " at offset:" + str(key) + "\n")

                #call entropy function for each mount_point
                process_folder(mount_point, export_file, outfile)
                print(
                    "We just finished calculating the entropy for every file...sorting output"
                )

                #unmount and remove mount points
                if (os.path.exists(mount_point)):
                    subprocess.call(['sudo umount -f ' + mount_point],
                                    shell=True)
                    os.rmdir(mount_point)
                #unmount loopback device if this image was HFS+ - need to run losetup -d <loop_device> before unmounting
                if not (loopback_device_mount == "NONE"):
                    losetup_d_command = "losetup -d " + loopback_device_mount
                    subprocess.call([losetup_d_command], shell=True)

        #delete /tmp files created for each partition
        if (os.path.exists("/tmp/mmls_output_" + temp_time + ".txt")):
            os.remove("/tmp/mmls_output_" + temp_time + ".txt")

    #close output file
    export_file.close()

    #sort output file
    sort_command = "strings -a  " + "'" + exp_file + "'" + " |sort -t\| -r -k 2n > " + "'" + folder_path + "'" + "/" + case_number + "_entropy_sorted.csv"
    subprocess.call([sort_command], shell=True)

    #write header row to export_file
    #sed_command = "sed -i '1i\ Entropy,File Name,File Size,MD5,File Path' " + "'" + folder_path + "'" + "/" + 	case_number +"_entropy_sorted.csv"
    sed_command = "sed -i '1i\ Entropy,File Name,File Size,FilePath' " + "'" + folder_path + "'" + "/" + case_number + "_entropy_sorted.csv"
    subprocess.call([sed_command], shell=True)

    #remove original output file
    os.remove(exp_file)

    #remove mount points created for this program
    if (os.path.exists(mount_point)):
        os.rmdir(mount_point)
    if (os.path.exists(mount_point + "_ewf")):
        subprocess.call(['sudo umount -f ' + mount_point + "_ewf"], shell=True)
        os.rmdir(mount_point + "_ewf")