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/unix/python.rb
Views: 11780
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' => 'unix',
17
'Arch' => ARCH_CMD,
18
'License' => MSF_LICENSE,
19
'AdaptedArch' => ARCH_PYTHON,
20
'AdaptedPlatform' => 'python'
21
)
22
)
23
end
24
25
def compatible?(mod)
26
if mod.type == Msf::MODULE_PAYLOAD && (mod.class.const_defined?(:CachedSize) && mod.class::CachedSize != :dynamic) && (mod.class::CachedSize >= 120_000) # echo does not have an unlimited amount of space
27
return false
28
end
29
30
super
31
end
32
33
def generate(_opts = {})
34
payload = super
35
36
if payload.include?("\n")
37
payload = Msf::Payload::Python.create_exec_stub(payload)
38
end
39
40
"echo #{Shellwords.escape(payload)} | exec $(which python || which python3 || which python2) -"
41
end
42
end
43
44