Files
metasploit-gs/modules/payloads/adapters/cmd/unix/python.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.1 KiB
Ruby
Raw Normal View History

2022-02-23 12:17:59 -05:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
module MetasploitModule
include Msf::Payload::Adapter
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Python Exec',
2025-05-09 11:32:38 -04:00
'Description' => 'Execute a Python payload as an OS command from a Posix-compatible shell',
2022-02-23 12:17:59 -05:00
'Author' => 'Spencer McIntyre',
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'License' => MSF_LICENSE,
'AdaptedArch' => ARCH_PYTHON,
'AdaptedPlatform' => 'python'
)
)
end
def compatible?(mod)
2025-05-22 11:47:50 -04:00
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
2022-02-23 12:17:59 -05:00
return false
end
super
end
2022-11-04 00:33:03 +00:00
def generate(_opts = {})
2022-02-23 12:17:59 -05:00
payload = super
if payload.include?("\n")
payload = Msf::Payload::Python.create_exec_stub(payload)
end
"echo #{Shellwords.escape(payload)} | exec $(which python || which python3 || which python2) -"
end
end