File tree Expand file tree Collapse file tree 3 files changed +127
-0
lines changed
ui/console/command_dispatcher Expand file tree Collapse file tree 3 files changed +127
-0
lines changed Original file line number Diff line number Diff line change
1
+ # -*- coding: binary -*-
2
+
3
+ require 'rex/post/meterpreter/extensions/python/tlv'
4
+ require 'set'
5
+
6
+ module Rex
7
+ module Post
8
+ module Meterpreter
9
+ module Extensions
10
+ module Python
11
+
12
+ ###
13
+ #
14
+ # Python extension - gives remote python scripting capabilities on the target.
15
+ #
16
+ ###
17
+
18
+ class Python < Extension
19
+
20
+ #
21
+ # Typical extension initialization routine.
22
+ #
23
+ # @param client (see Extension#initialize)
24
+ def initialize ( client )
25
+ super ( client , 'python' )
26
+
27
+ client . register_extension_aliases (
28
+ [
29
+ {
30
+ 'name' => 'python' ,
31
+ 'ext' => self
32
+ }
33
+ ] )
34
+ end
35
+
36
+ #
37
+ # Dump the LSA secrets from the target machine.
38
+ #
39
+ # @return [Hash<Symbol,Object>]
40
+ def execute_string ( code )
41
+ request = Packet . create_request ( 'python_execute_string' )
42
+ request . add_tlv ( TLV_TYPE_PYTHON_STRING , code )
43
+
44
+ response = client . send_request ( request )
45
+
46
+ response . get_tlv_value ( TLV_TYPE_PYTHON_OUTPUT )
47
+ end
48
+
49
+ end
50
+
51
+ end ; end ; end ; end ; end
52
+
Original file line number Diff line number Diff line change
1
+ # -*- coding: binary -*-
2
+ module Rex
3
+ module Post
4
+ module Meterpreter
5
+ module Extensions
6
+ module Python
7
+
8
+ TLV_TYPE_PYTHON_STRING = TLV_META_TYPE_STRING | ( TLV_EXTENSIONS + 1 )
9
+ TLV_TYPE_PYTHON_OUTPUT = TLV_META_TYPE_STRING | ( TLV_EXTENSIONS + 2 )
10
+
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
Original file line number Diff line number Diff line change
1
+ # -*- coding: binary -*-
2
+ require 'rex/post/meterpreter'
3
+
4
+ module Rex
5
+ module Post
6
+ module Meterpreter
7
+ module Ui
8
+
9
+ ###
10
+ #
11
+ # Python extension - interact with a python interpreter
12
+ #
13
+ ###
14
+ class Console ::CommandDispatcher ::Python
15
+
16
+ Klass = Console ::CommandDispatcher ::Python
17
+
18
+ include Console ::CommandDispatcher
19
+
20
+ #
21
+ # Name for this dispatcher
22
+ #
23
+ def name
24
+ 'Python'
25
+ end
26
+
27
+ #
28
+ # List of supported commands.
29
+ #
30
+ def commands
31
+ {
32
+ 'python_execute' => 'Execute a python command string'
33
+ }
34
+ end
35
+
36
+ def python_execute_usage
37
+ print_line ( 'Usage: python_execute [python code]' )
38
+ print_line
39
+ print_line ( 'Runs the given python string on the target and returns the output.' )
40
+ end
41
+
42
+ #
43
+ # Execute a simple python command string
44
+ #
45
+ def cmd_python_execute ( *args )
46
+ if args . length == 0
47
+ python_execute_usage
48
+ return false
49
+ end
50
+
51
+ client . python . execute_string ( args [ 0 ] )
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
60
+
You can’t perform that action at this time.
0 commit comments