mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-03-24 18:16:24 +01:00
cleanup python fs_search
This commit is contained in:
parent
a5d2e6cbe3
commit
5b0433f08f
@ -1521,34 +1521,36 @@ def stdapi_fs_search(request, response):
|
|||||||
search_root = unicode(search_root)
|
search_root = unicode(search_root)
|
||||||
glob = packet_get_tlv(request, TLV_TYPE_SEARCH_GLOB)['value']
|
glob = packet_get_tlv(request, TLV_TYPE_SEARCH_GLOB)['value']
|
||||||
recurse = packet_get_tlv(request, TLV_TYPE_SEARCH_RECURSE)['value']
|
recurse = packet_get_tlv(request, TLV_TYPE_SEARCH_RECURSE)['value']
|
||||||
sd = packet_get_tlv(request,TLV_TYPE_SEARCH_M_START_DATE)['value']
|
start_date = packet_get_tlv(request,TLV_TYPE_SEARCH_M_START_DATE)
|
||||||
ed = packet_get_tlv(request,TLV_TYPE_SEARCH_M_END_DATE)['value']
|
end_date = packet_get_tlv(request,TLV_TYPE_SEARCH_M_END_DATE)
|
||||||
if recurse:
|
if recurse:
|
||||||
for root, dirs, files in os.walk(search_root):
|
for root, dirs, files in os.walk(search_root):
|
||||||
for f in filter(lambda f: fnmatch.fnmatch(f, glob), files):
|
for f in filter(lambda f: fnmatch.fnmatch(f, glob), files):
|
||||||
mtime = int(os.stat(os.path.join(root, f)).st_mtime)
|
file_stat = os.stat(os.path.join(root, f))
|
||||||
if sd > 0 and sd > mtime:
|
mtime = int(file_stat.st_mtime)
|
||||||
|
if start_date and start_date['value'] > mtime:
|
||||||
continue
|
continue
|
||||||
if ed > 0 and ed < mtime:
|
if end_date and end_date['value'] < mtime:
|
||||||
continue
|
continue
|
||||||
file_tlv = bytes()
|
file_tlv = bytes()
|
||||||
file_tlv += tlv_pack(TLV_TYPE_FILE_PATH, root)
|
file_tlv += tlv_pack(TLV_TYPE_FILE_PATH, root)
|
||||||
file_tlv += tlv_pack(TLV_TYPE_FILE_NAME, f)
|
file_tlv += tlv_pack(TLV_TYPE_FILE_NAME, f)
|
||||||
file_tlv += tlv_pack(TLV_TYPE_FILE_SIZE, os.stat(os.path.join(root, f)).st_size)
|
file_tlv += tlv_pack(TLV_TYPE_FILE_SIZE, file_stat.st_size)
|
||||||
file_tlv += tlv_pack(TLV_TYPE_SEARCH_MTIME,mtime)
|
file_tlv += tlv_pack(TLV_TYPE_SEARCH_MTIME, mtime)
|
||||||
response += tlv_pack(TLV_TYPE_SEARCH_RESULTS, file_tlv)
|
response += tlv_pack(TLV_TYPE_SEARCH_RESULTS, file_tlv)
|
||||||
else:
|
else:
|
||||||
for f in filter(lambda f: fnmatch.fnmatch(f, glob), os.listdir(search_root)):
|
for f in filter(lambda f: fnmatch.fnmatch(f, glob), os.listdir(search_root)):
|
||||||
|
file_stat = os.stat(os.path.join(search_root, f))
|
||||||
|
mtime = int(file_stat.st_mtime)
|
||||||
|
if start_date and start_date['value'] > mtime:
|
||||||
|
continue
|
||||||
|
if end_date and end_date['value'] < mtime:
|
||||||
|
continue
|
||||||
file_tlv = bytes()
|
file_tlv = bytes()
|
||||||
mtime = int(os.stat(os.path.join(root, f)).st_mtime)
|
|
||||||
if sd > 0 and sd > mtime:
|
|
||||||
continue
|
|
||||||
if ed > 0 and ed < mtime:
|
|
||||||
continue
|
|
||||||
file_tlv += tlv_pack(TLV_TYPE_FILE_PATH, search_root)
|
file_tlv += tlv_pack(TLV_TYPE_FILE_PATH, search_root)
|
||||||
file_tlv += tlv_pack(TLV_TYPE_FILE_NAME, f)
|
file_tlv += tlv_pack(TLV_TYPE_FILE_NAME, f)
|
||||||
file_tlv += tlv_pack(TLV_TYPE_FILE_SIZE, os.stat(os.path.join(search_root, f)).st_size)
|
file_tlv += tlv_pack(TLV_TYPE_FILE_SIZE, file_stat.st_size)
|
||||||
file_tlv += tlv_pack(TLV_TYPE_SEARCH_MTIME,mtime)
|
file_tlv += tlv_pack(TLV_TYPE_SEARCH_MTIME, mtime)
|
||||||
response += tlv_pack(TLV_TYPE_SEARCH_RESULTS, file_tlv)
|
response += tlv_pack(TLV_TYPE_SEARCH_RESULTS, file_tlv)
|
||||||
return ERROR_SUCCESS, response
|
return ERROR_SUCCESS, response
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user