From 3310342a954ea5111fdd616e918a0b636a6c8712 Mon Sep 17 00:00:00 2001 From: sinn3r Date: Wed, 5 Nov 2014 10:58:41 -0600 Subject: [PATCH] Add save-as feature The tool produces A LOT OF results so it's really painful to manually copy and paste and to be able to use the data. So it should automatically save. Tagging the issue here because I forgot to do it: Fix #4039 --- tools/module_reference.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/module_reference.rb b/tools/module_reference.rb index 57f5de349b..00f66ecf93 100755 --- a/tools/module_reference.rb +++ b/tools/module_reference.rb @@ -47,6 +47,7 @@ filters = ['all','exploit','payload','post','nop','encoder','auxiliary'] type ='ALL' match = nil check = false +save = nil opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help menu." ], @@ -56,6 +57,7 @@ opts = Rex::Parser::Arguments.new( "-f" => [ true, "Filter based on Module Type [All,Exploit,Payload,Post,NOP,Encoder,Auxiliary] (Default = ALL)."], "-t" => [ true, "Type of Reference to sort by #{types.keys}"], "-x" => [ true, "String or RegEx to try and match against the Reference Field"], + "-o" => [ false, "Save the results to a file"] ) flags = [] @@ -95,6 +97,9 @@ opts.parse(ARGV) { |opt, idx, val| when "-x" flags << "Regex: #{val}" match = Regexp.new(val) + when "-o" + flags << "Output to file: Yes" + save = val end } @@ -146,6 +151,17 @@ def is_url_alive?(uri) true end +def save_results(path, results) + begin + File.new(path, 'wb') do |f| + f.write(results) + end + puts "Results saved to: #{path}" + rescue + puts "Failed to save the file" + end +end + # Always disable the database (we never need it just to list module # information). framework_opts = { 'DisableDatabase' => true } @@ -220,3 +236,5 @@ puts puts tbl.to_s puts puts "Number of bad references found: #{bad_refs_count}" + +save_results(save, tbl.tos) if save