Files
metasploit-gs/lib/msf/core/payload/python.rb
T

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

26 lines
848 B
Ruby
Raw Normal View History

# -*- coding: binary -*-
module Msf::Payload::Python
2015-05-25 11:51:01 +10:00
#
# 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.
2015-05-25 11:51:01 +10:00
#
# @param cmd [String] The python code to execute.
# @return [String] Full python stub to execute the command.
#
2020-08-31 22:52:27 +02:00
def self.create_exec_stub(cmd)
2022-11-01 11:03:47 -04:00
# 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])))"
2015-05-25 11:51:01 +10:00
b64_stub
2020-08-31 21:22:46 +02:00
end
2020-08-31 21:22:46 +02:00
def py_create_exec_stub(cmd)
2022-02-23 12:17:59 -05:00
Msf::Payload::Python.create_exec_stub(cmd)
2015-05-25 11:51:01 +10:00
end
end