@@ -1087,7 +1087,7 @@ def upload_manually(self, data, target_path = './payload', prompt = b'$', chunk_
1087
1087
1088
1088
The file is uploaded in base64-encoded chunks by appending to a file
1089
1089
and then decompressing it:
1090
-
1090
+
1091
1091
```
1092
1092
loop:
1093
1093
echo <chunk> | base64 -d >> <target_path>.<compression>
@@ -1168,11 +1168,15 @@ def upload_manually(self, data, target_path = './payload', prompt = b'$', chunk_
1168
1168
compressed_path = target_path + '.xz'
1169
1169
elif compression_mode == 'gzip' :
1170
1170
import gzip
1171
- compressed_data = gzip .compress (data , compresslevel = 9 )
1171
+ from six import BytesIO
1172
+ f = BytesIO ()
1173
+ with gzip .GzipFile (fileobj = f , mode = 'wb' , compresslevel = 9 ) as g :
1174
+ g .write (data )
1175
+ compressed_data = f .getvalue ()
1172
1176
compressed_path = target_path + '.gz'
1173
1177
else :
1174
1178
compressed_path = target_path
1175
-
1179
+
1176
1180
# Don't compress if it doesn't reduce the size.
1177
1181
if len (compressed_data ) >= len (data ):
1178
1182
compression_mode = None
@@ -1186,12 +1190,12 @@ def upload_manually(self, data, target_path = './payload', prompt = b'$', chunk_
1186
1190
if None in chunk :
1187
1191
chunk = chunk [:chunk .index (None )]
1188
1192
if idx == 0 :
1189
- self .sendlineafter (end_markerb , "echo {} | base64 -d > {}{}" .format (fiddling .b64e (bytes (chunk )), compressed_path , echo_end ).encode ())
1193
+ self .sendlineafter (end_markerb , "echo {} | base64 -d > {}{}" .format (fiddling .b64e (bytearray (chunk )), compressed_path , echo_end ).encode ())
1190
1194
else :
1191
- self .sendlineafter (end_markerb , "echo {} | base64 -d >> {}{}" .format (fiddling .b64e (bytes (chunk )), compressed_path , echo_end ).encode ())
1195
+ self .sendlineafter (end_markerb , "echo {} | base64 -d >> {}{}" .format (fiddling .b64e (bytearray (chunk )), compressed_path , echo_end ).encode ())
1192
1196
p .status ('{}/{} {}' .format (idx + 1 , len (data )// chunk_size + 1 , misc .size (idx * chunk_size + len (chunk ))))
1193
1197
p .success (misc .size (len (data )))
1194
-
1198
+
1195
1199
# Decompress the file and set the permissions.
1196
1200
if compression_mode is not None :
1197
1201
self .sendlineafter (end_markerb , '{} -d -f {}{}' .format (compression_mode , compressed_path , echo_end ).encode ())
0 commit comments