diff --git a/app/models/cisa_known_exploit.rb b/app/models/cisa_known_exploit.rb index 32785d5..beddde2 100644 --- a/app/models/cisa_known_exploit.rb +++ b/app/models/cisa_known_exploit.rb @@ -11,7 +11,8 @@ class CisaKnownExploit < ActiveRecord::Base end def self.cves_from_year(year) - last.vulnerabilities.select { |vuln| vuln if vuln.dig('cve_id') =~ /CVE-#{year}-\d{4,7}/ } + last.vulnerabilities.where("cve_id = 'CVE-#{year}-%'") + #last.vulnerabilities.select { |vuln| vuln if vuln.dig('cve_id') =~ /CVE-#{year}-\d{4,7}/ } end def self.by_product(product_name) diff --git a/db/migrate/20220427043126_create_cisa_known_exploits.rb b/db/migrate/20220427043126_create_cisa_known_exploits.rb index 19618d2..1cd36ad 100644 --- a/db/migrate/20220427043126_create_cisa_known_exploits.rb +++ b/db/migrate/20220427043126_create_cisa_known_exploits.rb @@ -6,7 +6,7 @@ class CreateCisaKnownExploits < ActiveRecord::Migration[7.0] t.date :date_released t.index :date_released, unique: true t.integer :count - t.jsonb :vulnerabilities + t.jsonb :vulnerabilities, array: true t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index 523946e..61e9787 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -19,7 +19,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_04_27_043126) do t.string "catalog_version" t.date "date_released" t.integer "count" - t.jsonb "vulnerabilities" + t.jsonb "vulnerabilities", array: true t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["date_released"], name: "index_cisa_known_exploits_on_date_released", unique: true diff --git a/lib/cna_scrapers/adobe_scraper.rb b/lib/cna_scrapers/adobe_scraper.rb new file mode 100644 index 0000000..f841add --- /dev/null +++ b/lib/cna_scrapers/adobe_scraper.rb @@ -0,0 +1,61 @@ +class AdobeScraper + attr_accessor :index_url, :doc + APSB_ID_MATCHER = /apsb\d{2}-\d{2,3}/i + APSA_ID_MATCHER = /apsa\d{2}-\d{2,3}/i + + def initialize + @index_url = 'https://helpx.adobe.com/security/security-bulletin.html' + @doc = read_html(get_html) + end + + def get_html + r = RestClient::Request.execute( + :method => :get, + :url => index_url + ) + if r.code == 200 + r.body + else + puts "HTTP Code #{r.code}" + end + end + + def read_html(doc) + Nokogiri::HTML(doc) + end + + def a_with_href + doc.xpath("//tr/td/a[starts-with(@href, 'https://')]") + end + + def advisory_id_from_url(url) + # adobes advisory ids end with .html + if url.ends_with?'.html' + # adobe product security bulletin + if url.include? 'apsb' + result = url.scan(APSB_ID_MATCHER).first.upcase + elsif url.include? 'apsa' + result = url.scan(APSA_ID_MATCHER).first.upcase + else + result = 'None' + end + result + end + end + + def index_hash + a_with_href.map.with_index do |a, index| + url = a.attributes['href'].value + advisory_id = advisory_id_from_url(url) + if advisory_id == 'None' + next + else + { + :index => index, + :advisory_id => advisory_id, + :url => url + } + end + end + end +end \ No newline at end of file