Path: blob/master/modules/payloads/adapters/cmd/unix/python.rb
19515 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6include Msf::Payload::Adapter78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Python Exec',13'Description' => 'Execute a Python payload as an OS command from a Posix-compatible shell',14'Author' => 'Spencer McIntyre',15'Platform' => 'unix',16'Arch' => ARCH_CMD,17'License' => MSF_LICENSE,18'AdaptedArch' => ARCH_PYTHON,19'AdaptedPlatform' => 'python'20)21)22end2324def compatible?(mod)25if 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 space26return false27end2829super30end3132def generate(_opts = {})33payload = super3435if payload.include?("\n")36payload = Msf::Payload::Python.create_exec_stub(payload)37end3839"echo #{Shellwords.escape(payload)} | exec $(which python || which python3 || which python2) -"40end41end424344