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/adapters/cmd/windows/python.rb
Views: 11777
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
module MetasploitModule
7
include Msf::Payload::Adapter
8
9
def initialize(info = {})
10
super(
11
update_info(
12
info,
13
'Name' => 'Python Exec',
14
'Description' => 'Execute a Python payload from a command',
15
'Author' => 'Spencer McIntyre',
16
'Platform' => 'win',
17
'Arch' => ARCH_CMD,
18
'License' => MSF_LICENSE,
19
'AdaptedArch' => ARCH_PYTHON,
20
'AdaptedPlatform' => 'python',
21
'RequiredCmd' => 'python'
22
)
23
)
24
register_advanced_options(
25
[
26
OptString.new('PythonPath', [true, 'The path to the Python executable', 'python'])
27
]
28
)
29
end
30
31
def compatible?(mod)
32
# size is not unlimited due to the standard command length limit, the final size depends on the options that are
33
# configured but 3,000 is in a good range (can go up to 4,000 with default settings at this time)
34
if mod.type == Msf::MODULE_PAYLOAD && (mod.class.const_defined?(:CachedSize) && mod.class::CachedSize != :dynamic) && (mod.class::CachedSize >= 3_000)
35
return false
36
end
37
38
super
39
end
40
41
def generate
42
payload = super
43
44
if payload.include?("\n")
45
payload = Msf::Payload::Python.create_exec_stub(payload)
46
end
47
48
"#{datastore['PythonPath']} -c \"#{payload}\""
49
end
50
end
51
52