Class: Rex::Post::Meterpreter::Extensions::Python::Python
- Inherits:
-
Rex::Post::Meterpreter::Extension
- Object
- Rex::Post::Meterpreter::Extension
- Rex::Post::Meterpreter::Extensions::Python::Python
- Defined in:
- lib/rex/post/meterpreter/extensions/python/python.rb
Overview
Python extension - gives remote python scripting capabilities on the target.
Constant Summary collapse
- PY_CODE_TYPE_STRING =
0
- PY_CODE_TYPE_PY =
1
- PY_CODE_TYPE_PYC =
2
- PY_CODE_FILE_TYPES =
[ '.py', '.pyc' ]
- PY_CODE_FILE_TYPE_MAP =
{ '.py' => PY_CODE_TYPE_PY, '.pyc' => PY_CODE_TYPE_PYC }
Instance Attribute Summary
Attributes inherited from Rex::Post::Meterpreter::Extension
Class Method Summary collapse
Instance Method Summary collapse
-
#execute_string(code, result_var) ⇒ Hash<Symbol,Object>
Dump the LSA secrets from the target machine.
- #import(file, mod_name, result_var) ⇒ Object
-
#initialize(client) ⇒ Python
constructor
Typical extension initialization routine.
- #reset ⇒ Object
Constructor Details
#initialize(client) ⇒ Python
Typical extension initialization routine.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rex/post/meterpreter/extensions/python/python.rb', line 40 def initialize(client) super(client, 'python') client.register_extension_aliases( [ { 'name' => 'python', 'ext' => self } ]) end |
Class Method Details
.extension_id ⇒ Object
32 33 34 |
# File 'lib/rex/post/meterpreter/extensions/python/python.rb', line 32 def self.extension_id EXTENSION_ID_PYTHON end |
Instance Method Details
#execute_string(code, result_var) ⇒ Hash<Symbol,Object>
Dump the LSA secrets from the target machine.
85 86 87 88 89 90 91 92 |
# File 'lib/rex/post/meterpreter/extensions/python/python.rb', line 85 def execute_string(code, result_var) request = Packet.create_request(COMMAND_ID_PYTHON_EXECUTE) request.add_tlv(TLV_TYPE_PYTHON_CODE, code) request.add_tlv(TLV_TYPE_PYTHON_CODE_TYPE, PY_CODE_TYPE_STRING) request.add_tlv(TLV_TYPE_PYTHON_RESULT_VAR, result_var) if result_var run_exec_request(request) end |
#import(file, mod_name, result_var) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rex/post/meterpreter/extensions/python/python.rb', line 59 def import(file, mod_name, result_var) unless ::File.file?(file) raise ArgumentError, "File not found: #{file}" end ext = ::File.extname(file).downcase unless PY_CODE_FILE_TYPES.include?(ext) raise ArgumentError, "File not a valid type: #{file}" end code = ::File.read(file) request = Packet.create_request(COMMAND_ID_PYTHON_EXECUTE) request.add_tlv(TLV_TYPE_PYTHON_CODE, code) request.add_tlv(TLV_TYPE_PYTHON_CODE_LEN, code.length) request.add_tlv(TLV_TYPE_PYTHON_CODE_TYPE, PY_CODE_FILE_TYPE_MAP[ext]) request.add_tlv(TLV_TYPE_PYTHON_NAME, mod_name) if mod_name request.add_tlv(TLV_TYPE_PYTHON_RESULT_VAR, result_var) if result_var run_exec_request(request) end |
#reset ⇒ Object
52 53 54 55 56 57 |
# File 'lib/rex/post/meterpreter/extensions/python/python.rb', line 52 def reset request = Packet.create_request(COMMAND_ID_PYTHON_RESET) client.send_request(request) return true end |