Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/tools/exploit/msu_finder.rb
Views: 11766
#!/usr/bin/env ruby12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##6begin7require 'patch_finder/core/helper'8require 'patch_finder/msu'9require 'optparse'1011class PatchFinderBin1213include PatchFinder::Helper1415attr_reader :args1617def get_parsed_options18options = {}1920parser = OptionParser.new do |opt|21opt.separator ''22opt.separator 'Specific options:'2324opt.on('-q', '--query <keyword>', 'Find advisories including this keyword') do |v|25options[:keyword] = v26end2728opt.on('-s', '--search-engine <engine>', '(Optional) The type of search engine to use (Technet or Google). Default: Technet') do |v|29case v.to_s30when /^google$/i31options[:search_engine] = :google32when /^technet$/i33options[:search_engine] = :technet34else35fail OptionParser::InvalidOption, "Invalid search engine: #{v}"36end37end3839opt.on('-r', '--regex <string>', '(Optional) Specify what type of links you want') do |v|40options[:regex] = v41end4243opt.on('--apikey <key>', '(Optional) Google API key.') do |v|44options[:google_api_key] = v45end4647opt.on('--cx <id>', '(Optional) Google search engine ID.') do |v|48options[:google_search_engine_id] = v49end5051opt.on('-d', '--dir <string>', '(Optional) The directory to save the patches') do |v|52unless File.directory?(v)53fail OptionParser::InvalidOption, "Directory not found: #{v}"54end5556options[:destdir] = v57end5859opt.on_tail('-h', '--help', 'Show this message') do60$stderr.puts opt61exit62end63end6465parser.parse!6667if options.empty?68fail OptionParser::MissingArgument, 'No options set, try -h for usage'69elsif options[:keyword].nil? || options[:keyword].empty?70fail OptionParser::MissingArgument, '-q is required'71end7273unless options[:search_engine]74options[:search_engine] = :technet75end7677if options[:search_engine] == :google78if options[:google_api_key].nil? || options[:google_search_engine_id].empty?79fail OptionParser::MissingArgument, 'No API key set for Google'80elsif options[:google_search_engine_id].nil? || options[:google_search_engine_id].empty?81fail OptionParser::MissingArgument, 'No search engine ID set for Google'82end83end8485options86end8788def initialize89@args = get_parsed_options90rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e91print_error(e.message)92exit93end9495def main96cli = PatchFinder::MSU.new(verbose: true)97links = cli.find_msu_download_links(args)98if args[:destdir]99print_status("Download links found: #{links.length}")100print_status('Downloading files, please wait...')101download_files(links, args[:destdir])102else103print_status('Download links found:')104print_line(links * "\n")105end106end107end108109if __FILE__ == $PROGRAM_NAME110bin = PatchFinderBin.new111bin.main112end113rescue SignalException => e114puts("Aborted! #{e}")115end116117118