Skip to content

Commit 00f5081

Browse files
committed
Implemented tab completion for DNS command
1 parent 1a7eefd commit 00f5081

File tree

1 file changed

+55
-0
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+55
-0
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,61 @@ def commands
3737
commands
3838
end
3939

40+
#
41+
# Tab completion for the dns command
42+
#
43+
# @param str [String] the string currently being typed before tab was hit
44+
# @param words [Array<String>] the previously completed words on the command line. words is always
45+
# at least 1 when tab completion has reached this stage since the command itself has been completed
46+
def cmd_dns_tabs(str, words)
47+
if words.length == 1
48+
options = ['add','del','remove','flush','print']
49+
return options.select { |opt| opt.start_with?(str) }
50+
end
51+
52+
cmd = words[1]
53+
case cmd
54+
when 'flush','print'
55+
# These commands don't have any arguments
56+
return
57+
when 'add'
58+
# We expect a repeating pattern of tag (e.g. -r) and then a value (e.g. *.metasploit.com)
59+
# Once this pattern is violated, we're just specifying DNS servers at that point.
60+
tag_is_expected = true
61+
if words.length > 2
62+
words[2..-1].each do |word|
63+
if tag_is_expected && !word.start_with?('-')
64+
return # They're trying to specify a DNS server - we can't help them from here on out
65+
end
66+
tag_is_expected = !tag_is_expected
67+
end
68+
end
69+
70+
case words[-1]
71+
when '-s', '--session'
72+
session_ids = driver.framework.sessions.keys.map { |k| k.to_s }
73+
return session_ids.select { |id| id.start_with?(str) }
74+
when '-r', '--rule'
75+
# Hard to auto-complete a rule with any meaningful value; just return
76+
return
77+
when /^-/
78+
# Unknown tag
79+
return
80+
end
81+
82+
options = @@add_opts.option_keys.select { |opt| opt.start_with?(str) }
83+
options << '' # Prevent tab-completion of a dash, given they could provide an IP address at this point
84+
return options
85+
when 'del','remove'
86+
if words[-1] == '-i'
87+
ids = driver.framework.dns_resolver.nameserver_entries.flatten.map { |entry| entry[:id].to_s }
88+
return ids.select { |id| id.start_with? str }
89+
else
90+
return @@remove_opts.option_keys.select { |opt| opt.start_with?(str) }
91+
end
92+
end
93+
end
94+
4095
def cmd_dns_help
4196
print_line 'Usage: dns'
4297
print_line

0 commit comments

Comments
 (0)