2023-02-04 20:52:57 -05:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
|
|
|
|
module Msf::Sessions
|
|
|
|
|
###
|
|
|
|
|
#
|
|
|
|
|
# This class provides basic interaction with an AWS SSM
|
|
|
|
|
# session socket encapsulated by a
|
|
|
|
|
# Rex::Proto::Http::WebSocket::AmazonSsm::Interface::SsmChannel
|
|
|
|
|
#
|
|
|
|
|
# Date: Feb 4, 2023
|
|
|
|
|
# Author: RageLtMan
|
|
|
|
|
#
|
|
|
|
|
###
|
|
|
|
|
class AwsSsmCommandShellBind < Msf::Sessions::CommandShell
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# This interface supports basic interaction.
|
|
|
|
|
#
|
|
|
|
|
include Msf::Session::Basic
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# This interface supports interacting with a single command shell.
|
|
|
|
|
#
|
|
|
|
|
include Msf::Session::Provider::SingleCommandShell
|
|
|
|
|
|
2023-05-22 17:11:16 -04:00
|
|
|
def abort_foreground_supported
|
|
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-10 17:48:53 -04:00
|
|
|
def shell_command_token_unix(cmd, timeout=10)
|
|
|
|
|
res = super
|
|
|
|
|
|
|
|
|
|
res.gsub!("\r\n", "\n") if res
|
|
|
|
|
res
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-18 16:41:48 -04:00
|
|
|
def initialize(conn, opts=nil)
|
|
|
|
|
super
|
|
|
|
|
|
|
|
|
|
if opts && (ssm_peer_info = opts.fetch(:aws_ssm_host_info))
|
|
|
|
|
case ssm_peer_info['PlatformType']
|
|
|
|
|
when 'Linux'
|
|
|
|
|
@platform = 'linux'
|
2023-05-10 17:48:53 -04:00
|
|
|
@session_type = 'shell'
|
2023-04-18 16:41:48 -04:00
|
|
|
when 'MacOS'
|
|
|
|
|
@platform = 'osx'
|
2023-05-10 17:48:53 -04:00
|
|
|
@session_type = 'shell'
|
2023-04-18 16:41:48 -04:00
|
|
|
when 'Windows'
|
2023-05-10 17:48:53 -04:00
|
|
|
@platform = 'windows'
|
2023-05-22 17:11:16 -04:00
|
|
|
@session_type = 'powershell:winpty'
|
2023-05-10 17:48:53 -04:00
|
|
|
extend(Msf::Sessions::PowerShell::Mixin)
|
2023-04-18 16:41:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@info = "AWS SSM #{ssm_peer_info['ResourceType']} (#{ssm_peer_info['InstanceId']})"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-10 17:48:53 -04:00
|
|
|
def type
|
|
|
|
|
@session_type.dup
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def bootstrap(*args)
|
|
|
|
|
if @platform == 'linux'
|
|
|
|
|
# The session from SSM-SessionManagerRunShell starts with a TTY which breaks the post API so change the settings
|
|
|
|
|
# and make it behave in a way consistent with other shell sessions
|
2023-05-22 17:11:16 -04:00
|
|
|
shell_command('stty -echo cbreak;pipe=$(mktemp -u);mkfifo -m 600 $pipe;cat $pipe & sh 1>$pipe 2>$pipe; rm $pipe; exit')
|
2023-05-10 17:48:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
super
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-04 20:52:57 -05:00
|
|
|
##
|
|
|
|
|
#
|
|
|
|
|
# Returns the session description.
|
|
|
|
|
#
|
|
|
|
|
def desc
|
2023-04-18 12:23:46 -04:00
|
|
|
'AWS SSM command shell'
|
2023-02-04 20:52:57 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|