Skip to content

Commit abeecec

Browse files
committed
Land rapid7#8493, creds -R fix with DbCommon
2 parents 44c9292 + 2682874 commit abeecec

File tree

3 files changed

+62
-38
lines changed

3 files changed

+62
-38
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'rexml/document'
44
require 'rex/parser/nmap_xml'
55
require 'msf/core/db_export'
6+
require 'msf/ui/console/command_dispatcher/db_common'
67

78
module Msf
89
module Ui
@@ -14,6 +15,7 @@ class Creds
1415

1516
include Msf::Ui::Console::CommandDispatcher
1617
include Metasploit::Credential::Creation
18+
include Msf::Ui::Console::CommandDispatcher::DbCommon
1719

1820
#
1921
# The dispatcher's name.

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

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'rexml/document'
44
require 'rex/parser/nmap_xml'
55
require 'msf/core/db_export'
6+
require 'msf/ui/console/command_dispatcher/db_common'
67

78
module Msf
89
module Ui
@@ -14,7 +15,8 @@ class Db
1415
require 'tempfile'
1516

1617
include Msf::Ui::Console::CommandDispatcher
17-
18+
include Msf::Ui::Console::CommandDispatcher::DbCommon
19+
1820
#
1921
# The dispatcher's name.
2022
#
@@ -1715,43 +1717,6 @@ def cmd_db_rebuild_cache_help
17151717
print_line
17161718
end
17171719

1718-
#
1719-
# Set RHOSTS in the +active_module+'s (or global if none) datastore from an array of addresses
1720-
#
1721-
# This stores all the addresses to a temporary file and utilizes the
1722-
# <pre>file:/tmp/filename</pre> syntax to confer the addrs. +rhosts+
1723-
# should be an Array. NOTE: the temporary file is *not* deleted
1724-
# automatically.
1725-
#
1726-
def set_rhosts_from_addrs(rhosts)
1727-
if rhosts.empty?
1728-
print_status("The list is empty, cowardly refusing to set RHOSTS")
1729-
return
1730-
end
1731-
if active_module
1732-
mydatastore = active_module.datastore
1733-
else
1734-
# if there is no module in use set the list to the global variable
1735-
mydatastore = self.framework.datastore
1736-
end
1737-
1738-
if rhosts.length > 5
1739-
# Lots of hosts makes 'show options' wrap which is difficult to
1740-
# read, store to a temp file
1741-
rhosts_file = Rex::Quickfile.new("msf-db-rhosts-")
1742-
mydatastore['RHOSTS'] = 'file:'+rhosts_file.path
1743-
# create the output file and assign it to the RHOSTS variable
1744-
rhosts_file.write(rhosts.join("\n")+"\n")
1745-
rhosts_file.close
1746-
else
1747-
# For short lists, just set it directly
1748-
mydatastore['RHOSTS'] = rhosts.join(" ")
1749-
end
1750-
1751-
print_line "RHOSTS => #{mydatastore['RHOSTS']}"
1752-
print_line
1753-
end
1754-
17551720
def db_find_tools(tools)
17561721
missed = []
17571722
tools.each do |name|
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: binary -*-
2+
3+
require 'rexml/document'
4+
require 'rex/parser/nmap_xml'
5+
require 'msf/core/db_export'
6+
7+
module Msf
8+
module Ui
9+
module Console
10+
module CommandDispatcher
11+
12+
module DbCommon
13+
14+
#
15+
# Set RHOSTS in the +active_module+'s (or global if none) datastore from an array of addresses
16+
#
17+
# This stores all the addresses to a temporary file and utilizes the
18+
# <pre>file:/tmp/filename</pre> syntax to confer the addrs. +rhosts+
19+
# should be an Array. NOTE: the temporary file is *not* deleted
20+
# automatically.
21+
#
22+
def set_rhosts_from_addrs(rhosts)
23+
if rhosts.empty?
24+
print_status("The list is empty, cowardly refusing to set RHOSTS")
25+
return
26+
end
27+
if active_module
28+
mydatastore = active_module.datastore
29+
else
30+
# if there is no module in use set the list to the global variable
31+
mydatastore = self.framework.datastore
32+
end
33+
34+
if rhosts.length > 5
35+
# Lots of hosts makes 'show options' wrap which is difficult to
36+
# read, store to a temp file
37+
rhosts_file = Rex::Quickfile.new("msf-db-rhosts-")
38+
mydatastore['RHOSTS'] = 'file:'+rhosts_file.path
39+
# create the output file and assign it to the RHOSTS variable
40+
rhosts_file.write(rhosts.join("\n")+"\n")
41+
rhosts_file.close
42+
else
43+
# For short lists, just set it directly
44+
mydatastore['RHOSTS'] = rhosts.join(" ")
45+
end
46+
47+
print_line "RHOSTS => #{mydatastore['RHOSTS']}"
48+
print_line
49+
end
50+
51+
52+
end
53+
54+
end
55+
end
56+
end
57+
end

0 commit comments

Comments
 (0)