Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for shell sessions to post/windows/gather/enum_hostfile #12585

Merged
merged 1 commit into from Nov 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 5 additions & 16 deletions modules/post/windows/gather/enum_hostfile.rb
Expand Up @@ -4,6 +4,7 @@
##

class MetasploitModule < Msf::Post
include Msf::Post::File

def initialize(info={})
super(update_info(info,
Expand All @@ -20,35 +21,23 @@ def initialize(info={})

def run
# read in the hosts in the hosts file.
fd = session.fs.file.new("C:\\WINDOWS\\System32\\drivers\\etc\\hosts", "rb")

# Load up the original hosts file
buf = ''
until fd.eof?
buf << fd.read
end

# Finished loading the hosts file, close fd
fd.close
hosts = read_file "C:\\WINDOWS\\System32\\drivers\\etc\\hosts"

# Store the original hosts file
p = store_loot(
'hosts.confige',
'text/plain',
session,
buf,
hosts,
'hosts_file.txt',
'Windows Hosts File'
)

# Split lines
lines = buf.split("\n")

# Print out each line that doesn't start w/ a comment
entries = []
lines.each do |line|
hosts.each_line do |line|
next if line =~ /^[\r|\n|#]/
entries << line
entries << line.strip
end

# Show results
Expand Down