Files
metasploit-gs/modules/post/windows/manage/remove_host.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
1.8 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2021-09-10 12:53:39 +01:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Windows Manage Host File Entry Removal',
'Description' => %q{
This module allows the attacker to remove an entry from the Windows hosts file.
},
'License' => BSD_LICENSE,
'Author' => [ 'vt <nick.freeman[at]security-assessment.com>'],
'Platform' => [ 'win' ],
2021-10-06 13:43:31 +01:00
'SessionTypes' => [ 'meterpreter' ],
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
core_channel_close
core_channel_eof
core_channel_open
core_channel_read
core_channel_tell
core_channel_write
]
}
}
2021-09-10 12:53:39 +01:00
)
)
2013-08-30 16:28:54 -05:00
register_options(
[
OptString.new('DOMAIN', [ true, 'Domain name to remove from the hosts file.' ])
2021-09-10 12:53:39 +01:00
]
)
end
2013-08-30 16:28:54 -05:00
def run
hosttoremove = datastore['DOMAIN']
# remove hostname from hosts file
2023-02-08 13:47:34 +00:00
fd = client.fs.file.new('C:\\WINDOWS\\System32\\drivers\\etc\\hosts', 'r+b')
2013-08-30 16:28:54 -05:00
# Get a temporary file path
meterp_temp = Tempfile.new('meterp')
meterp_temp.binmode
temp_path = meterp_temp.path
2013-08-30 16:28:54 -05:00
print_status("Removing hosts file entry pointing to #{hosttoremove}")
2013-08-30 16:28:54 -05:00
newfile = ''
fdray = fd.read.split("\r\n")
2013-08-30 16:28:54 -05:00
fdray.each do |line|
2023-02-08 13:47:34 +00:00
unless line.match("\t#{hosttoremove}$")
newfile += "#{line}\r\n"
end
end
2013-08-30 16:28:54 -05:00
fd.close
2013-08-30 16:28:54 -05:00
meterp_temp.write(newfile)
meterp_temp.close
2013-08-30 16:28:54 -05:00
client.fs.file.upload_file('C:\\WINDOWS\\System32\\drivers\\etc\\hosts', meterp_temp)
2023-02-08 13:47:34 +00:00
print_good('Done!')
end
end