-
Notifications
You must be signed in to change notification settings - Fork 0
/
bdpl_run_be.py
75 lines (52 loc) · 2.89 KB
/
bdpl_run_be.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import subprocess
import openpyxl
import glob
'''Run for earlier BDPL shipments where entire Bulk Extractor output was not retained for appraisal.'''
def main():
while True:
shipment = input('\nFull path to shipment folder: ')
shipment = shipment.replace('"', '').rstrip()
if not os.path.exists(shipment):
print('Shipment folder not recognized; enclose in quotes and use "/".\n')
continue
#check on spreadsheet before we go any further; the following will help make sure that a hidden temp file doesn't foul things up
spreadsheets = list(set(glob.glob(os.path.join(shipment, '*.xlsx'))) - set(glob.glob(os.path.join(shipment, '~*.xlsx'))))
if len(spreadsheets) !=1:
print('\nWARNING: cannot identify shipment spreadsheet. Please check directory to make sure .XLSX file is present.')
print(spreadsheets)
continue
else:
spreadsheet = spreadsheets[0]
break
#pii_list = ['EMAIL', 'TELEPHONE NOs', 'ACCOUNT NOs', 'CCNs']
pii_list = ['ACCOUNT NOs', 'CCNs']
#set shipment directory as current working directory
os.chdir(shipment)
#open shipment workbook
wb = openpyxl.load_workbook(spreadsheet)
ws = wb['Appraisal']
iterrows = ws.iter_rows()
next(iterrows)
for row in iterrows:
barcode = str(row[0].value)
target = os.path.join(shipment, barcode, 'files')
bulkext_dir = os.path.join(shipment, barcode, 'bulk_extractor')
if not os.path.exists(target):
continue
if not row[23].value is None:
if [p for p in pii_list if p in row[23].value]:
if os.path.exists(os.path.join(bulkext_dir, 'report.xml')):
print('\n\n%s already has b_e report' % barcode)
continue
else:
print('\nCreating b_e report for', barcode)
#use default command with buklk_extractor; individuak could implement changes to use 'find' scanner at a later date
bulkext_command = 'bulk_extractor -x aes -x base64 -x elf -x exif -x gps -x hiberfile -x httplogs -x json -x kml -x net -x pdf -x sqlite -x vcard -x winlnk -x winpe -x winprefetch -S ssn_mode=2 -o "%s" -R "%s"' % (bulkext_dir, target)
try:
exitcode = subprocess.call(bulkext_command, shell=True, text=True)
print('\n\tCompleted bulk_extractor operation.')
except subprocess.CalledProcessError as e:
print('\n\tError:', e)
if __name__ == '__main__':
main()