Skip to content

Commit e176b21

Browse files
committed
Land rapid7#4921, db_nmap help and tab completion
2 parents 1b3dfe6 + dac5b07 commit e176b21

File tree

1 file changed

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

1 file changed

+51
-5
lines changed

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

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,11 +1647,18 @@ def cmd_db_nmap(*args)
16471647
print_status("Usage: db_nmap [nmap options]")
16481648
return
16491649
end
1650-
16511650
save = false
1652-
if args.include?("save")
1653-
save = active?
1654-
args.delete("save")
1651+
arguments = ''
1652+
while (arg = args.shift)
1653+
case arg
1654+
when 'save'
1655+
save = active?
1656+
when '--help', '-h'
1657+
cmd_db_nmap_help
1658+
return
1659+
else
1660+
arguments << arg + ' '
1661+
end
16551662
end
16561663

16571664
nmap =
@@ -1682,7 +1689,7 @@ def cmd_db_nmap(*args)
16821689
end
16831690

16841691
begin
1685-
nmap_pipe = ::Open3::popen3([nmap, "nmap"], *args)
1692+
nmap_pipe = ::Open3::popen3([nmap, 'nmap'], arguments)
16861693
temp_nmap_threads = []
16871694
temp_nmap_threads << framework.threads.spawn("db_nmap-Stdout", false, nmap_pipe[1]) do |np_1|
16881695
np_1.each_line do |nmap_out|
@@ -1715,6 +1722,45 @@ def cmd_db_nmap(*args)
17151722
}
17161723
end
17171724

1725+
def cmd_db_nmap_help
1726+
nmap =
1727+
Rex::FileUtils.find_full_path('nmap') ||
1728+
Rex::FileUtils.find_full_path('nmap.exe')
1729+
1730+
stdout, stderr = Open3.capture3([nmap, 'nmap'], '--help')
1731+
1732+
stdout.each_line do |out_line|
1733+
next if out_line.strip.empty?
1734+
print_status(out_line.strip);
1735+
end
1736+
1737+
stderr.each_line do |err_line|
1738+
next if err_line.strip.empty?
1739+
print_error(err_line.strip)
1740+
end
1741+
end
1742+
1743+
def cmd_db_nmap_tabs(str, words)
1744+
nmap =
1745+
Rex::FileUtils.find_full_path('nmap') ||
1746+
Rex::FileUtils.find_full_path('nmap.exe')
1747+
1748+
stdout, stderr = Open3.capture3([nmap, 'nmap'], '--help')
1749+
tabs = []
1750+
stdout.each_line do |out_line|
1751+
if out_line.strip.starts_with?('-')
1752+
tabs.push(out_line.strip.split(':').first)
1753+
end
1754+
end
1755+
1756+
stderr.each_line do |err_line|
1757+
next if err_line.strip.empty?
1758+
print_error(err_line.strip)
1759+
end
1760+
1761+
tabs
1762+
end
1763+
17181764
#
17191765
# Store some locally-generated data as a file, similiar to store_loot.
17201766
#

0 commit comments

Comments
 (0)