Skip to content

Commit b8f9f1d

Browse files
committed
Land rapid7#2310, Minor Python Meterpreter Issues
- Windows file mode (removes duplicated b) - Socket timeout value increased - SetSID for nix systems [Closes rapid7#2310]
2 parents 0736677 + d84939c commit b8f9f1d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

data/meterpreter/ext_server_stdapi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def channel_create_stdapi_fs_file(request, response):
303303
fmode = packet_get_tlv(request, TLV_TYPE_FILE_MODE)
304304
if fmode:
305305
fmode = fmode['value']
306+
fmode = fmode.replace('bb', 'b')
306307
else:
307308
fmode = 'rb'
308309
file_h = open(fpath, fmode)
@@ -320,6 +321,7 @@ def channel_create_stdapi_net_tcp_client(request, response):
320321
connected = False
321322
for i in range(retries + 1):
322323
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
324+
sock.settimeout(3.0)
323325
if local_host.get('value') and local_port.get('value'):
324326
sock.bind((local_host['value'], local_port['value']))
325327
try:
@@ -380,7 +382,7 @@ def stdapi_sys_process_execute(request, response):
380382
if len(cmd) == 0:
381383
return ERROR_FAILURE, response
382384
if os.path.isfile('/bin/sh'):
383-
args = ['/bin/sh', '-c', cmd, raw_args]
385+
args = ['/bin/sh', '-c', cmd + ' ' + raw_args]
384386
else:
385387
args = [cmd]
386388
args.extend(shlex.split(raw_args))

data/meterpreter/meterpreter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,5 +404,7 @@ def create_response(self, request):
404404
return resp
405405

406406
if not hasattr(os, 'fork') or (hasattr(os, 'fork') and os.fork() == 0):
407+
if hasattr(os, 'setsid'):
408+
os.setsid()
407409
met = PythonMeterpreter(s)
408410
met.run()

0 commit comments

Comments
 (0)