Module: Msf::Payload::Python

Included in:
BindTcp, MeterpreterLoader, ReverseTcp, ReverseTcpSsl
Defined in:
lib/msf/core/payload/python.rb

Defined Under Namespace

Modules: BindTcp, MeterpreterLoader, ReverseHttp, ReverseTcp, ReverseTcpSsl, SendUUID

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_exec_stub(cmd) ⇒ String

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.

Parameters:

  • cmd (String)

    The python code to execute.

Returns:

  • (String)

    Full python stub to execute the command.



14
15
16
17
18
19
# File 'lib/msf/core/payload/python.rb', line 14

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

Instance Method Details

#py_create_exec_stub(cmd) ⇒ Object



21
22
23
# File 'lib/msf/core/payload/python.rb', line 21

def py_create_exec_stub(cmd)
  Msf::Payload::Python.create_exec_stub(cmd)
end