Skip to content

Commit

Permalink
Linux bug fixes
Browse files Browse the repository at this point in the history
Fixed two bugs for Linux and created Linux binary using pyinstaller.
  • Loading branch information
bli-dn committed Aug 22, 2016
1 parent cd58866 commit 8b853d9
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 42 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ panhunt.py requires:
To create panhunt.exe as a standalone executable with an icon run:

```
pyinstaller.exe panhunt.py -F -i dionach.ico
pyinstaller.exe panhunt.py -F
```

You will find the Windows panhunt.exe (built on Windows using pyinstaller) and the Linux panhunt binary here (built on CentOS 6 using pyinstaller).


##Usage

```
Expand Down
59 changes: 30 additions & 29 deletions filehunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def set_file_stats(self):
self.accessed = self.dtm_from_ts(stat.st_atime)
self.modified = self.dtm_from_ts(stat.st_mtime)
self.created = self.dtm_from_ts(stat.st_ctime)
except WindowsError:
except: # WindowsError:
self.size = -1
self.set_error(sys.exc_info()[1])

Expand Down Expand Up @@ -96,8 +96,8 @@ def check_regexs(self, regexs, search_extensions):
try:
file_text = read_file(self.path, 'rb')
self.check_text_regexs(file_text, regexs, '')
except WindowsError:
self.set_error(sys.exc_info()[1])
#except WindowsError:
# self.set_error(sys.exc_info()[1])
except IOError:
self.set_error(sys.exc_info()[1])
except:
Expand Down Expand Up @@ -133,32 +133,33 @@ def check_pst_regexs(self, regexs, search_extensions, hunt_type, gauge_update_fu

try:
apst = pst.PST(self.path)

total_messages = apst.get_total_message_count()
total_attachments = apst.get_total_attachment_count()
total_items = total_messages + total_attachments
items_completed = 0

for folder in apst.folder_generator():
for message in apst.message_generator(folder):
if message.Subject:
message_path = os.path.join(folder.path, message.Subject)
else:
message_path = os.path.join(folder.path, u'[NoSubject]')
if message.Body:
self.check_text_regexs(message.Body, regexs, message_path)
if message.HasAttachments:
for subattachment in message.subattachments:
if get_ext(subattachment.Filename) in search_extensions['TEXT']+search_extensions['ZIP']:
attachment = message.get_attachment(subattachment)
self.check_attachment_regexs(attachment, regexs, search_extensions, message_path)
items_completed += 1
items_completed += 1
if not gauge_update_function:
pbar_widgets[6] = progressbar.FormatLabel(' %ss:%s' % (hunt_type, len(self.matches)))
pbar.update(items_completed * 100.0 / total_items)
else:
gauge_update_function(value = items_completed * 100.0 / total_items)
if apst.header.validPST:

total_messages = apst.get_total_message_count()
total_attachments = apst.get_total_attachment_count()
total_items = total_messages + total_attachments
items_completed = 0

for folder in apst.folder_generator():
for message in apst.message_generator(folder):
if message.Subject:
message_path = os.path.join(folder.path, message.Subject)
else:
message_path = os.path.join(folder.path, u'[NoSubject]')
if message.Body:
self.check_text_regexs(message.Body, regexs, message_path)
if message.HasAttachments:
for subattachment in message.subattachments:
if get_ext(subattachment.Filename) in search_extensions['TEXT']+search_extensions['ZIP']:
attachment = message.get_attachment(subattachment)
self.check_attachment_regexs(attachment, regexs, search_extensions, message_path)
items_completed += 1
items_completed += 1
if not gauge_update_function:
pbar_widgets[6] = progressbar.FormatLabel(' %ss:%s' % (hunt_type, len(self.matches)))
pbar.update(items_completed * 100.0 / total_items)
else:
gauge_update_function(value = items_completed * 100.0 / total_items)

apst.close()

Expand Down
Binary file added panhunt
Binary file not shown.
Binary file modified panhunt.exe
Binary file not shown.
76 changes: 64 additions & 12 deletions pst.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ class PSTException(Exception):
error_log_list = []


###########################################################################################################
##############################################################################################################################
# _ _ _ ____ _ _ ___ _ ____ ______ _
# | \ | | ___ __| | ___ | _ \ __ _| |_ __ _| |__ __ _ ___ ___ / / \ | | _ \| __ ) \ | | __ _ _ _ ___ _ __
# | \| |/ _ \ / _` |/ _ \ | | | |/ _` | __/ _` | '_ \ / _` / __|/ _ \ | || \| | | | | _ \| | | | / _` | | | |/ _ \ '__|
# | |\ | (_) | (_| | __/ | |_| | (_| | || (_| | |_) | (_| \__ \ __/ | || |\ | |_| | |_) | | | |__| (_| | |_| | __/ |
# |_| \_|\___/ \__,_|\___| |____/ \__,_|\__\__,_|_.__/ \__,_|___/\___| | ||_| \_|____/|____/| | |_____\__,_|\__, |\___|_|
# \_\ /_/ |___/
##############################################################################################################################


class NID:
Expand Down Expand Up @@ -455,9 +462,14 @@ def get_page_leaf_entries(self, entry_type, page_offset):




###########################################################################################################

################################################################################################################################################################################
# _ _ _ _____ _ _ _ ____ _ _ ___ _____ ______ _
# | | (_)___| |_ ___ |_ _|_ _| |__ | | ___ ___ __ _ _ __ __| | | _ \ _ __ ___ _ __ ___ _ __| |_(_) ___ ___ / / | |_ _| _ \ \ | | __ _ _ _ ___ _ __
# | | | / __| __/ __| | |/ _` | '_ \| |/ _ \/ __| / _` | '_ \ / _` | | |_) | '__/ _ \| '_ \ / _ \ '__| __| |/ _ \/ __| | || | | | | |_) | | | | / _` | | | |/ _ \ '__|
# | |___| \__ \ |_\__ \_ | | (_| | |_) | | __/\__ \_ | (_| | | | | (_| | | __/| | | (_) | |_) | __/ | | |_| | __/\__ \ | || |___| | | __/| | | |__| (_| | |_| | __/ |
# |_____|_|___/\__|___( ) |_|\__,_|_.__/|_|\___||___( ) \__,_|_| |_|\__,_| |_| |_| \___/| .__/ \___|_| \__|_|\___||___/ | ||_____|_| |_| | | |_____\__,_|\__, |\___|_|
# |/ |/ |_| \_\ /_/ |___/
################################################################################################################################################################################


class HID:
Expand Down Expand Up @@ -1155,8 +1167,14 @@ def strip_SubjectPrefix(self, Subject):



##############################################################################################################

#############################################################################################################################
# __ __ _ _
# | \/ | ___ ___ ___ __ _ __ _(_)_ __ __ _ | | __ _ _ _ ___ _ __
# | |\/| |/ _ \/ __/ __|/ _` |/ _` | | '_ \ / _` | | | / _` | | | |/ _ \ '__|
# | | | | __/\__ \__ \ (_| | (_| | | | | | (_| | | |__| (_| | |_| | __/ |
# |_| |_|\___||___/___/\__,_|\__, |_|_| |_|\__, | |_____\__,_|\__, |\___|_|
# |___/ |___/ |___/
#############################################################################################################################


class EntryID:
Expand Down Expand Up @@ -1462,7 +1480,14 @@ def get_named_properties(self):
return '\n'.join(['%s = %s' % (hex(nameid.NPID), repr(nameid.name)) for nameid in self.nameid_entries if nameid.N==1])


##############################################################################################################
#############################################################################################################################
# ____ ____ _____ _
# | _ \/ ___|_ _| | | __ _ _ _ ___ _ __
# | |_) \___ \ | | | | / _` | | | |/ _ \ '__|
# | __/ ___) || | | |__| (_| | |_| | __/ |
# |_| |____/ |_| |_____\__,_|\__, |\___|_|
# |___/
#############################################################################################################################


class CRC:
Expand Down Expand Up @@ -1776,7 +1801,13 @@ def __init__(self, fd):
self.dwMagic = fd.read(FieldSize.DWORD)
self.dwCRCPartial = fd.read(FieldSize.DWORD) # ignore
self.wMagicClient = fd.read(FieldSize.WORD)
self.wVer, self.wVerClient, self.bPlatformCreate, self.bPlatformAccess = struct.unpack('HHBB',fd.read(FieldSize.WORD+FieldSize.WORD+FieldSize.BYTE+FieldSize.BYTE))

try:
self.wVer, self.wVerClient, self.bPlatformCreate, self.bPlatformAccess = struct.unpack('HHBB',fd.read(FieldSize.WORD+FieldSize.WORD+FieldSize.BYTE+FieldSize.BYTE))
except struct.error:
self.validPST = False
return

self.dwReserved1 = fd.read(FieldSize.DWORD) # ignore
self.dwReserved2 = fd.read(FieldSize.DWORD) # ignore

Expand Down Expand Up @@ -1992,7 +2023,14 @@ def crack_password(crc, dictionary_file=''):
return ''


#################### GENERAL FUNCTIONS ######################################################
###################################################################################################################################
# _ _ _ _ _ _ _ _____ _ _
# | | | | |_(_) (_) |_ _ _ | ___| _ _ __ ___| |_(_) ___ _ __ ___
# | | | | __| | | | __| | | | | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
# | |_| | |_| | | | |_| |_| | | _|| |_| | | | | (__| |_| | (_) | | | \__ \
# \___/ \__|_|_|_|\__|\__, | |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
# |___/
###################################################################################################################################



Expand Down Expand Up @@ -2069,7 +2107,15 @@ def log_error(e):



########################## TEST/EXAMPLES ####################################################
###############################################################################################################################
#
# _____ _ _____ _ _
# |_ _|__ ___| |_ | ___| _ _ __ ___| |_(_) ___ _ __ ___
# | |/ _ \/ __| __| | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
# | | __/\__ \ |_ | _|| |_| | | | | (__| |_| | (_) | | | \__ \
# |_|\___||___/\__| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#
###############################################################################################################################



Expand Down Expand Up @@ -2136,8 +2182,14 @@ def test_folder_psts(psts_folder):




########################## MAIN #######################################
###################################################################################################################################
# __ __ _
# | \/ | __ _(_)_ __
# | |\/| |/ _` | | '_ \
# | | | | (_| | | | | |
# |_| |_|\__,_|_|_| |_|
#
###################################################################################################################################


if __name__=="__main__":
Expand Down

0 comments on commit 8b853d9

Please sign in to comment.