class PatchFinder::MSU

Constants

MAX_THREADS

Public Class Methods

new(opts={}) click to toggle source
# File lib/patch_finder/msu.rb, line 14
def initialize(opts={})
  self.verbose = opts[:verbose] || false
end

Public Instance Methods

Private Instance Methods

collect_msbs(args) click to toggle source

Returns the MSBs (advisories) numbers.

@param args [Hash] @return [Array]

# File lib/patch_finder/msu.rb, line 61
def collect_msbs(args)
  msb_numbers = []

  case args[:search_engine]
  when :technet
    print_verbose("Searching advisories that include #{args[:keyword]} via Technet")
    msb_numbers = technet_search(args[:keyword])
  when :google
    print_verbose("Searching advisories that include #{args[:keyword]} via Google")
    msb_numbers = google_search(args[:keyword], args[:google_api_key], args[:google_search_engine_id])
  end

  msb_numbers
end
download_advisory(msb) click to toggle source

Returns the advisory page.

@param msb [String] @return [String]

# File lib/patch_finder/msu.rb, line 157
def download_advisory(msb)
  send_http_get_request("#{PatchFinder::Engine::MSU::TECHNET}/en-us/library/security/#{msb}.aspx")
end
get_appropriate_pattern(n) click to toggle source

Returns a pattern that matches the advisory page.

@param n [Nokogiri::HTML::Document] @return [String] If a match is found @return [NilClass] If no match found

# File lib/patch_finder/msu.rb, line 215
def get_appropriate_pattern(n)
  PatchFinder::Engine::MSU::ADVISORY_PATTERNS.each do |pattern|
    if n.at_xpath(pattern[:check])
      return pattern[:pattern]
    end
  end

  nil
end
get_details_aspx(res) click to toggle source

Returns the found details pages

@param res [Res::Response] @return [Array]

# File lib/patch_finder/msu.rb, line 165
def get_details_aspx(res)
  links = []

  page = res.body
  n = ::Nokogiri::HTML(page)

  appropriate_pattern = get_appropriate_pattern(n)
  return links unless appropriate_pattern

  n.search(appropriate_pattern).each do |anchor|
    found_link = anchor.attributes['href'].value
    if /https:\/\/www\.microsoft\.com\/downloads\/details\.aspx\?familyid=/i === found_link
      begin
        links << found_link
      rescue ::URI::InvalidURIError
        print_verbose_error "Unable to parse URI: #{found_link}"
      end
    end
  end

  links
end
get_download_page(link) click to toggle source

Returns the download page.

@param link [string] @return [Net::Response]

# File lib/patch_finder/msu.rb, line 123
def get_download_page(link)
  res = send_http_get_request(link)

  if res.header['Location']
    return send_http_get_request("#{PatchFinder::Engine::MSU::MICROSOFT}/#{res.header['Location']}")
  end

  res
end
has_advisory?(res) click to toggle source

Checks if the page is an advisory.

@param res [Net::Response] @return [Boolean]

# File lib/patch_finder/msu.rb, line 229
def has_advisory?(res)
  !res.body.include?('We are sorry. The page you requested cannot be found')
end
is_valid_msb?(msb) click to toggle source

Checks if the string is a MSB format.

@param msb [String] @return [Boolean]

# File lib/patch_finder/msu.rb, line 237
def is_valid_msb?(msb)
  /^ms\d\d\-\d\d\d$/i === msb
end