1
mirror of https://github.com/rapid7/metasploit-payloads synced 2024-11-26 17:41:08 +01:00

Land #499, Add support for updating terminal size dynamically

This commit is contained in:
adfoster-r7 2021-09-14 12:37:11 +01:00 committed by GitHub
commit dc14eada5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -39,6 +39,12 @@ try:
except ImportError:
has_termios = False
try:
import fcntl
has_fcntl = True
except ImportError:
has_fcntl = False
try:
import _winreg as winreg
has_winreg = True
@ -610,6 +616,9 @@ TLV_TYPE_REGISTER_SIZE = TLV_META_TYPE_UINT | 2541
TLV_TYPE_REGISTER_VALUE_32 = TLV_META_TYPE_UINT | 2542
TLV_TYPE_REGISTER = TLV_META_TYPE_GROUP | 2550
TLV_TYPE_TERMINAL_ROWS = TLV_META_TYPE_UINT | 2600
TLV_TYPE_TERMINAL_COLUMNS = TLV_META_TYPE_UINT | 2601
##
# Ui
##
@ -1159,7 +1168,6 @@ def stdapi_sys_process_execute(request, response):
if has_termios:
try:
settings = termios.tcgetattr(master)
settings[3] = settings[3] & ~termios.ECHO
termios.tcsetattr(master, termios.TCSADRAIN, settings)
except:
pass
@ -2549,3 +2557,16 @@ def stdapi_ui_get_idle_time(request, response):
idle_time = (GetTickCount() - info.dwTime) / 1000
response += tlv_pack(TLV_TYPE_IDLE_TIME, idle_time)
return ERROR_SUCCESS, response
@register_function_if(has_termios and has_fcntl)
def stdapi_sys_process_set_term_size(request, response):
channel_id = packet_get_tlv(request, TLV_TYPE_CHANNEL_ID)['value']
rows = packet_get_tlv(request, TLV_TYPE_TERMINAL_ROWS)['value']
columns = packet_get_tlv(request, TLV_TYPE_TERMINAL_COLUMNS)['value']
if channel_id in meterpreter.interact_channels:
proc_h = meterpreter.channels[channel_id].proc_h
winsize = struct.pack("HHHH", rows, columns, 0, 0)
fcntl.ioctl(proc_h.stdin, termios.TIOCSWINSZ, winsize)
else:
return ERROR_FAILURE, response
return ERROR_SUCCESS, response

View File

@ -347,6 +347,8 @@ COMMAND_IDS = (
(1115, 'stdapi_audio_mic_start'),
(1116, 'stdapi_audio_mic_stop'),
(1117, 'stdapi_audio_mic_list'),
(1118, 'stdapi_sys_process_set_term_size'),
)
# ---------------------------------------------------------------