Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f5f8b33

Browse files
committedOct 26, 2024·
Fix gzip compression on Python 2
1 parent 4644b4b commit f5f8b33

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
 

‎pwnlib/tubes/tube.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ def upload_manually(self, data, target_path = './payload', prompt = b'$', chunk_
10871087
10881088
The file is uploaded in base64-encoded chunks by appending to a file
10891089
and then decompressing it:
1090-
1090+
10911091
```
10921092
loop:
10931093
echo <chunk> | base64 -d >> <target_path>.<compression>
@@ -1168,11 +1168,15 @@ def upload_manually(self, data, target_path = './payload', prompt = b'$', chunk_
11681168
compressed_path = target_path + '.xz'
11691169
elif compression_mode == 'gzip':
11701170
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()
11721176
compressed_path = target_path + '.gz'
11731177
else:
11741178
compressed_path = target_path
1175-
1179+
11761180
# Don't compress if it doesn't reduce the size.
11771181
if len(compressed_data) >= len(data):
11781182
compression_mode = None
@@ -1186,12 +1190,12 @@ def upload_manually(self, data, target_path = './payload', prompt = b'$', chunk_
11861190
if None in chunk:
11871191
chunk = chunk[:chunk.index(None)]
11881192
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())
11901194
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())
11921196
p.status('{}/{} {}'.format(idx+1, len(data)//chunk_size+1, misc.size(idx*chunk_size + len(chunk))))
11931197
p.success(misc.size(len(data)))
1194-
1198+
11951199
# Decompress the file and set the permissions.
11961200
if compression_mode is not None:
11971201
self.sendlineafter(end_markerb, '{} -d -f {}{}'.format(compression_mode, compressed_path, echo_end).encode())

0 commit comments

Comments
 (0)
Please sign in to comment.