Skip to content

Commit 16eab48

Browse files
committed
Adding help and tab functions for db_nmap
These functions address certain problems listed in GitHub issue rapid7#4353, but do not address all issues in that ticket. Most notably, this commit adds basic tab completion for db_nmap.
1 parent 02c7461 commit 16eab48

File tree

1 file changed

+52
-5
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+52
-5
lines changed

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

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,11 +1594,19 @@ def cmd_db_nmap(*args)
15941594
print_status("Usage: db_nmap [nmap options]")
15951595
return
15961596
end
1597-
1597+
15981598
save = false
1599-
if args.include?("save")
1600-
save = active?
1601-
args.delete("save")
1599+
arguments = ''
1600+
while (arg = args.shift)
1601+
case arg
1602+
when 'save'
1603+
save = active?
1604+
when '--help', '-h'
1605+
cmd_db_nmap_help
1606+
return
1607+
else
1608+
arguments << arg + ' '
1609+
end
16021610
end
16031611

16041612
nmap =
@@ -1629,7 +1637,7 @@ def cmd_db_nmap(*args)
16291637
end
16301638

16311639
begin
1632-
nmap_pipe = ::Open3::popen3([nmap, "nmap"], *args)
1640+
nmap_pipe = ::Open3::popen3([nmap, "nmap"], arguments)
16331641
temp_nmap_threads = []
16341642
temp_nmap_threads << framework.threads.spawn("db_nmap-Stdout", false, nmap_pipe[1]) do |np_1|
16351643
np_1.each_line do |nmap_out|
@@ -1662,6 +1670,45 @@ def cmd_db_nmap(*args)
16621670
}
16631671
end
16641672

1673+
def cmd_db_nmap_help
1674+
nmap =
1675+
Rex::FileUtils.find_full_path('nmap') ||
1676+
Rex::FileUtils.find_full_path('nmap.exe')
1677+
1678+
stdout, stderr = Open3.capture3([nmap, 'nmap'], '--help')
1679+
1680+
stdout.each_line do |out_line|
1681+
next if out_line.strip.empty?
1682+
print_status(out_line.strip);
1683+
end
1684+
1685+
stderr.each_line do |err_line|
1686+
next if err_line.strip.empty?
1687+
print_error(err_line.strip)
1688+
end
1689+
end
1690+
1691+
def cmd_db_nmap_tabs(str, words)
1692+
nmap =
1693+
Rex::FileUtils.find_full_path('nmap') ||
1694+
Rex::FileUtils.find_full_path('nmap.exe')
1695+
1696+
stdout, stderr = Open3.capture3([nmap, 'nmap'], '--help')
1697+
tabs = []
1698+
stdout.each_line do |out_line|
1699+
if out_line.strip.starts_with?('-')
1700+
tabs.push(out_line.strip.split(':').first)
1701+
end
1702+
end
1703+
1704+
stderr.each_line do |err_line|
1705+
next if err_line.strip.empty?
1706+
print_error(err_line.strip)
1707+
end
1708+
1709+
return tabs
1710+
end
1711+
16651712
#
16661713
# Store some locally-generated data as a file, similiar to store_loot.
16671714
#

0 commit comments

Comments
 (0)