From b2f0533ff3d98036fc55279746a768157e95400b Mon Sep 17 00:00:00 2001 From: byt3bl33d3r Date: Fri, 9 Oct 2015 19:44:02 -0600 Subject: [PATCH] Added error handling when searching file contents --- crackmapexec.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/crackmapexec.py b/crackmapexec.py index 27fa671a..245784f3 100755 --- a/crackmapexec.py +++ b/crackmapexec.py @@ -2630,23 +2630,26 @@ def dir_list(files, ip, path, pattern, share, smb): return def search_content(smb, path, result, share, pattern, ip): - rfile = RemoteFile(smb, path + '/' + result.get_longname(), share, access = FILE_READ_DATA) - rfile.open() + try: + rfile = RemoteFile(smb, path + '/' + result.get_longname(), share, access = FILE_READ_DATA) + rfile.open() - while True: - try: - contents = rfile.read(4096) - except SessionError as e: - if 'STATUS_END_OF_FILE' in str(e): + while True: + try: + contents = rfile.read(4096) + except SessionError as e: + if 'STATUS_END_OF_FILE' in str(e): + return + + if contents == '': return - if contents == '': - return - - if re.findall(pattern, contents, re.IGNORECASE): - print_att("//{}/{}/{} offset:{} pattern:{}".format(ip, path.replace("//",""), result.get_longname().encode('utf8'), rfile.tell(), pattern)) - rfile.close() - return + if re.findall(pattern, contents, re.IGNORECASE): + print_att("//{}/{}/{} offset:{} pattern:{}".format(ip, path.replace("//",""), result.get_longname().encode('utf8'), rfile.tell(), pattern)) + rfile.close() + return + except Exception: + pass def enum_shares(smb): permissions = {}