forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsu_finder.rb
executable file
·108 lines (86 loc) · 2.91 KB
/
msu_finder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env ruby
require 'patch_finder/core/helper'
require 'patch_finder/msu'
require 'optparse'
class PatchFinderBin
include PatchFinder::Helper
attr_reader :args
def get_parsed_options
options = {}
parser = OptionParser.new do |opt|
opt.separator ''
opt.separator 'Specific options:'
opt.on('-q', '--query <keyword>', 'Find advisories including this keyword') do |v|
options[:keyword] = v
end
opt.on('-s', '--search-engine <engine>', '(Optional) The type of search engine to use (Technet or Google). Default: Technet') do |v|
case v.to_s
when /^google$/i
options[:search_engine] = :google
when /^technet$/i
options[:search_engine] = :technet
else
fail OptionParser::InvalidOption, "Invalid search engine: #{v}"
end
end
opt.on('-r', '--regex <string>', '(Optional) Specify what type of links you want') do |v|
options[:regex] = v
end
opt.on('--apikey <key>', '(Optional) Google API key.') do |v|
options[:google_api_key] = v
end
opt.on('--cx <id>', '(Optional) Google search engine ID.') do |v|
options[:google_search_engine_id] = v
end
opt.on('-d', '--dir <string>', '(Optional) The directory to save the patches') do |v|
unless File.directory?(v)
fail OptionParser::InvalidOption, "Directory not found: #{v}"
end
options[:destdir] = v
end
opt.on_tail('-h', '--help', 'Show this message') do
$stderr.puts opt
exit
end
end
parser.parse!
if options.empty?
fail OptionParser::MissingArgument, 'No options set, try -h for usage'
elsif options[:keyword].nil? || options[:keyword].empty?
fail OptionParser::MissingArgument, '-q is required'
end
unless options[:search_engine]
options[:search_engine] = :technet
end
if options[:search_engine] == :google
if options[:google_api_key].nil? || options[:google_search_engine_id].empty?
fail OptionParser::MissingArgument, 'No API key set for Google'
elsif options[:google_search_engine_id].nil? || options[:google_search_engine_id].empty?
fail OptionParser::MissingArgument, 'No search engine ID set for Google'
end
end
options
end
def initialize
@args = get_parsed_options
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
print_error(e.message)
exit
end
def main
cli = PatchFinder::MSU.new(verbose: true)
links = cli.find_msu_download_links(args)
if args[:destdir]
print_status("Download links found: #{links.length}")
print_status('Downloading files, please wait...')
download_files(links, args[:destdir])
else
print_status('Download links found:')
print_line(links * "\n")
end
end
end
if __FILE__ == $PROGRAM_NAME
bin = PatchFinderBin.new
bin.main
end