mirror of
https://github.com/rapid7/metasploit-payloads
synced 2024-11-20 14:39:22 +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)
|
||||
glob = packet_get_tlv(request, TLV_TYPE_SEARCH_GLOB)['value']
|
||||
recurse = packet_get_tlv(request, TLV_TYPE_SEARCH_RECURSE)['value']
|
||||
sd = packet_get_tlv(request,TLV_TYPE_SEARCH_M_START_DATE)['value']
|
||||
ed = packet_get_tlv(request,TLV_TYPE_SEARCH_M_END_DATE)['value']
|
||||
start_date = packet_get_tlv(request,TLV_TYPE_SEARCH_M_START_DATE)
|
||||
end_date = packet_get_tlv(request,TLV_TYPE_SEARCH_M_END_DATE)
|
||||
if recurse:
|
||||
for root, dirs, files in os.walk(search_root):
|
||||
for f in filter(lambda f: fnmatch.fnmatch(f, glob), files):
|
||||
mtime = int(os.stat(os.path.join(root, f)).st_mtime)
|
||||
if sd > 0 and sd > mtime:
|
||||
file_stat = os.stat(os.path.join(root, f))
|
||||
mtime = int(file_stat.st_mtime)
|
||||
if start_date and start_date['value'] > mtime:
|
||||
continue
|
||||
if ed > 0 and ed < mtime:
|
||||
if end_date and end_date['value'] < mtime:
|
||||
continue
|
||||
file_tlv = bytes()
|
||||
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_SIZE, os.stat(os.path.join(root, f)).st_size)
|
||||
file_tlv += tlv_pack(TLV_TYPE_SEARCH_MTIME,mtime)
|
||||
file_tlv += tlv_pack(TLV_TYPE_FILE_SIZE, file_stat.st_size)
|
||||
file_tlv += tlv_pack(TLV_TYPE_SEARCH_MTIME, mtime)
|
||||
response += tlv_pack(TLV_TYPE_SEARCH_RESULTS, file_tlv)
|
||||
else:
|
||||
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()
|
||||
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_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_SEARCH_MTIME,mtime)
|
||||
file_tlv += tlv_pack(TLV_TYPE_FILE_SIZE, file_stat.st_size)
|
||||
file_tlv += tlv_pack(TLV_TYPE_SEARCH_MTIME, mtime)
|
||||
response += tlv_pack(TLV_TYPE_SEARCH_RESULTS, file_tlv)
|
||||
return ERROR_SUCCESS, response
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user