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

Fix missing #add_static API method #19880

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/msf/core/exploit/remote/dns/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ def add_static_hosts(entries = datastore['STATIC_ENTRIES'], type = 'A')
data = entries.split(';')
end
data.each do |entry|
next if entry.gsub(/\s/,'').empty?
addr, names = entry.split(' ', 2)
next if entry.gsub(/\s/, '').empty?

address, names = entry.split(' ', 2)
names.split.each do |name|
name << '.' unless name[-1] == '.' or name == '*'
service.cache.add_static(name, addr, type)
name << '.' unless name.end_with?('.') || name == '*'

unless Rex::Socket.is_ip_addr?(address.to_s) && (name.to_s.match(MATCH_HOSTNAME) || name == '*')
raise "Invalid parameters for static entry - #{name}, #{address}, #{type}"
end

service.cache.cache_record(Dnsruby::RR.create(name: name, type: type, address: address), expire: false)
end
end
service.cache.records.select {|r,e| e == 0}
Expand Down
21 changes: 14 additions & 7 deletions lib/rex/proto/dns/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@ def find(search, type = Dnsruby::Types::A)
# Add record to cache, only when "running"
#
# @param record [Dnsruby::RR] Record to cache
def cache_record(record)
def cache_record(record, expire: true)
return unless @monitor_thread
if record.is_a?(Dnsruby::RR) and
(!record.respond_to?(:address) or Rex::Socket.is_ip_addr?(record.address.to_s)) and
record.name.to_s.match(MATCH_HOSTNAME)
add(record, ::Time.now.to_i + record.ttl)
else
raise "Invalid record for cache entry - #{record.inspect}"

unless record.is_a?(Dnsruby::RR)
raise "Invalid record for cache entry (not an RR) - #{record.inspect}"
end

unless (!record.respond_to?(:address) || Rex::Socket.is_ip_addr?(record.address.to_s))
raise "Invalid record for cache entry (no IP address) - #{record.inspect}"
end

unless record.name.to_s.match(MATCH_HOSTNAME)
raise "Invalid record for cache entry (invalid hostname) - #{record.inspect}"
end

add(record, expire ? (::Time.now.to_i + record.ttl) : 0)
end

#
Expand Down
Loading