Skip to content

Commit 5635e81

Browse files
author
Brent Cook
committed
export module.search command
1 parent e0695cb commit 5635e81

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

lib/msf/core/framework.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ def threads?
229229
}
230230
end
231231

232-
def search(match, verbose: true)
232+
def search(match, verbose: false)
233233
# Check if the database is usable
234234
use_db = true
235-
if @db
236-
if !(@db.migrated && @db.modules_cached)
235+
if self.db
236+
if !(self.db.migrated && self.db.modules_cached)
237237
if verbose
238238
print_warning("Module database cache not built yet, using slow search")
239239
end
@@ -248,12 +248,12 @@ def search(match, verbose: true)
248248

249249
# Used the database for search
250250
if use_db
251-
return @db.search_modules(match)
251+
return self.db.search_modules(match)
252252
end
253253

254254
# Do an in-place search
255255
matches = []
256-
[ @exploits, @auxiliary, @post, @payloads, @nops, @encoders ].each do |mset|
256+
[ self.exploits, self.auxiliary, self.post, self.payloads, self.nops, self.encoders ].each do |mset|
257257
mset.each do |m|
258258
begin
259259
o = mset.create(m[0])

lib/msf/core/rpc/v10/rpc_module.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ def rpc_info_html(mtype, mname)
9999
# rpc.call('module.info', 'exploit', 'windows/smb/ms08_067_netapi')
100100
def rpc_info(mtype, mname)
101101
m = _find_module(mtype,mname)
102-
res = {}
103-
104-
res['type'] = m.type
105-
res['name'] = m.name
106-
res['fullname'] = m.fullname
107-
res['rank'] = m.rank.to_i
102+
res = module_short_info(m)
108103
res['description'] = Rex::Text.compress(m.description)
109104
res['license'] = m.license
110105
res['filepath'] = m.file_path
@@ -165,6 +160,23 @@ def rpc_info(mtype, mname)
165160
res
166161
end
167162

163+
def module_short_info(m)
164+
res = {}
165+
res['type'] = m.type
166+
res['name'] = m.name
167+
res['fullname'] = m.fullname
168+
res['rank'] = RankingName[m.rank].to_s
169+
res['disclosuredate'] = m.disclosure_date.nil? ? "" : m.disclosure_date.strftime("%Y-%m-%d")
170+
res
171+
end
172+
173+
def rpc_search(match)
174+
matches = []
175+
self.framework.search(match).each do |m|
176+
matches << module_short_info(m)
177+
end
178+
matches
179+
end
168180

169181
# Returns the compatible payloads for a specific exploit.
170182
#

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class Modules
1818
# Constant for a retry timeout on using modules before they're loaded
1919
CMD_USE_TIMEOUT = 3
2020

21-
# Constant for disclosure date formatting in search functions
22-
DISCLOSURE_DATE_FORMAT = "%Y-%m-%d"
23-
2421
@@search_opts = Rex::Parser::Arguments.new(
2522
"-h" => [ false, "Help banner."],
2623
"-S" => [ true, "Row search filter."],
@@ -403,12 +400,12 @@ def cmd_search(*args)
403400

404401
# Display the table of matches
405402
tbl = generate_module_table("Matching Modules", search_term)
406-
framework.search(match, verbose: true).each do |o|
403+
framework.search(match, verbose: true).each do |m|
407404
tbl << [
408-
o.fullname,
409-
o.disclosure_date.nil? ? "" : o.disclosure_date.strftime(DISCLOSURE_DATE_FORMAT),
410-
RankingName[o.rank].to_s,
411-
o.name
405+
m.fullname,
406+
m.disclosure_date.nil? ? "" : m.disclosure_date.strftime("%Y-%m-%d"),
407+
RankingName[m.rank].to_s,
408+
m.name
412409
]
413410
end
414411
print_line(tbl.to_s)
@@ -1120,7 +1117,12 @@ def show_module_set(type, module_set, regex = nil, minrank = nil, opts = nil) #
11201117
end
11211118
end
11221119
if (opts == nil or show == true)
1123-
tbl << [ refname, o.disclosure_date.nil? ? "" : o.disclosure_date.strftime(DISCLOSURE_DATE_FORMAT), o.rank_to_s, o.name ]
1120+
tbl << [
1121+
refname,
1122+
o.disclosure_date.nil? ? "" : o.disclosure_date.strftime("%Y-%m-%d"),
1123+
o.rank_to_s,
1124+
o.name
1125+
]
11241126
end
11251127
end
11261128
end

0 commit comments

Comments
 (0)