Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit b2f0533

Browse files
author
byt3bl33d3r
committed
Added error handling when searching file contents
1 parent 3988708 commit b2f0533

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

crackmapexec.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,23 +2630,26 @@ def dir_list(files, ip, path, pattern, share, smb):
26302630
return
26312631

26322632
def search_content(smb, path, result, share, pattern, ip):
2633-
rfile = RemoteFile(smb, path + '/' + result.get_longname(), share, access = FILE_READ_DATA)
2634-
rfile.open()
2633+
try:
2634+
rfile = RemoteFile(smb, path + '/' + result.get_longname(), share, access = FILE_READ_DATA)
2635+
rfile.open()
26352636

2636-
while True:
2637-
try:
2638-
contents = rfile.read(4096)
2639-
except SessionError as e:
2640-
if 'STATUS_END_OF_FILE' in str(e):
2641-
return
2637+
while True:
2638+
try:
2639+
contents = rfile.read(4096)
2640+
except SessionError as e:
2641+
if 'STATUS_END_OF_FILE' in str(e):
2642+
return
26422643

2643-
if contents == '':
2644-
return
2644+
if contents == '':
2645+
return
26452646

2646-
if re.findall(pattern, contents, re.IGNORECASE):
2647-
print_att("//{}/{}/{} offset:{} pattern:{}".format(ip, path.replace("//",""), result.get_longname().encode('utf8'), rfile.tell(), pattern))
2648-
rfile.close()
2649-
return
2647+
if re.findall(pattern, contents, re.IGNORECASE):
2648+
print_att("//{}/{}/{} offset:{} pattern:{}".format(ip, path.replace("//",""), result.get_longname().encode('utf8'), rfile.tell(), pattern))
2649+
rfile.close()
2650+
return
2651+
except Exception:
2652+
pass
26502653

26512654
def enum_shares(smb):
26522655
permissions = {}

0 commit comments

Comments
 (0)