Skip to content

Commit 8ce3280

Browse files
committed
Clearer dns feature results
1 parent 00f5081 commit 8ce3280

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lib/msf/ui/console/command_dispatcher/dns.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,15 @@ def add_dns(*args)
209209
comm_obj = driver.framework.sessions[comm_int]
210210
end
211211

212+
rules.each do |rule|
213+
print_warning("DNS rule #{rule} does not contain wildcards, so will not match subdomains") unless rule.include?('*')
214+
end
215+
212216
# Split each DNS server entry up into a separate entry
213217
servers.each do |server|
214218
driver.framework.dns_resolver.add_nameserver(rules, server, comm_obj)
215219
end
220+
print_good("DNS #{servers.length > 1 ? 'entries' : 'entry'} added")
216221
end
217222

218223
#
@@ -228,26 +233,33 @@ def remove_dns(*args)
228233
end
229234
end
230235

231-
driver.framework.dns_resolver.remove_ids(remove_ids)
236+
removed = driver.framework.dns_resolver.remove_ids(remove_ids)
237+
difference = remove_ids.difference(removed.map { |entry| entry[:id] })
238+
print_warning("Some entries were not removed: #{difference.join(', ')}") unless difference.empty?
239+
if removed.length > 0
240+
print_good("#{removed.length} DNS #{removed.length > 1 ? 'entries' : 'entry'} removed")
241+
print_dns_set('Deleted entries', ['ID', 'Rules(s)', 'DNS Server', 'Commm channel'], removed.map {|hash| [hash[:id], hash[:wildcard_rules].join(','), hash[:dns_server], prettify_comm(hash[:comm], hash[:dns_server])]})
242+
end
232243
end
233244

234245
#
235246
# Delete all user-configured DNS settings
236247
#
237248
def purge_dns
238249
driver.framework.dns_resolver.purge
250+
print_good('DNS entries purged')
239251
end
240252

241253
#
242254
# Display the user-configured DNS settings
243255
#
244256
def print_dns
245257
results = driver.framework.dns_resolver.nameserver_entries
246-
columns = ['ID','Rule(s)', 'DNS Server(s)', 'Comm channel']
258+
columns = ['ID','Rule(s)', 'DNS Server', 'Comm channel']
247259
print_dns_set('Custom nameserver rules', columns, results[0].map {|hash| [hash[:id], hash[:wildcard_rules].join(','), hash[:dns_server], prettify_comm(hash[:comm], hash[:dns_server])]})
248260

249261
# Default nameservers don't include a rule
250-
columns = ['ID', 'DNS Server(s)', 'Comm channel']
262+
columns = ['ID', 'DNS Server', 'Comm channel']
251263
print_dns_set('Default nameservers', columns, results[1].map {|hash| [hash[:id], hash[:dns_server], prettify_comm(hash[:comm], hash[:dns_server])]})
252264
end
253265

lib/rex/proto/dns/custom_nameserver_provider.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def load_config
8282
with_rules << entry
8383
end
8484

85-
next_id = [id, next_id].max
85+
next_id = [id + 1, next_id].max
8686
end
8787

8888
# Now that config has successfully read, update the global values
@@ -118,11 +118,23 @@ def add_nameserver(wildcard_rules, dns_server, comm)
118118
#
119119
# Remove entries with the given IDs
120120
# Ignore entries that are not found
121+
# @param [Array<Integer>] The IDs to removed
122+
# @return [Array<Hash>] The removed entries
123+
#
121124
def remove_ids(ids)
125+
removed= []
122126
ids.each do |id|
123-
self.entries_with_rules.delete_if {|entry| entry[:id] == id}
124-
self.entries_without_rules.delete_if {|entry| entry[:id] == id}
127+
removed_with, remaining_with = self.entries_with_rules.partition {|entry| entry[:id] == id}
128+
self.entries_with_rules.replace(remaining_with)
129+
130+
removed_without, remaining_without = self.entries_without_rules.partition {|entry| entry[:id] == id}
131+
self.entries_without_rules.replace(remaining_without)
132+
133+
removed.concat(removed_with)
134+
removed.concat(removed_without)
125135
end
136+
137+
removed
126138
end
127139

128140
#

0 commit comments

Comments
 (0)