47 lines
1.1 KiB
Ruby
47 lines
1.1 KiB
Ruby
|
require 'bulk_insert'
|
||
|
require 'json'
|
||
|
|
||
|
class InthewildCveExploitImporter
|
||
|
attr_accessor :url
|
||
|
def initialize
|
||
|
@url = 'https://inthewild.io/api/exploited'
|
||
|
end
|
||
|
|
||
|
def get_exploit_feed
|
||
|
r = RestClient::Request.execute(
|
||
|
:method => :get,
|
||
|
:url => url,
|
||
|
:headers => {"Content-type": "application/json"}
|
||
|
)
|
||
|
if r.code == 200
|
||
|
JSON.parse(r.body)
|
||
|
else
|
||
|
puts "HTTP Code #{r.code}"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def cve_attrs_from_item(json)
|
||
|
cve_attrs = {}
|
||
|
cve_attrs[:cve_id] = json['id']
|
||
|
cve_attrs[:earliest_report] = json['earliestReport']
|
||
|
cve_attrs
|
||
|
end
|
||
|
|
||
|
def bulk_insert(cves)
|
||
|
InthewildCveExploit.bulk_insert do |worker|
|
||
|
cves.each do |attrs|
|
||
|
worker.add(attrs)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def import
|
||
|
feed = get_exploit_feed
|
||
|
puts "Now importing InthewildCveExploits."
|
||
|
cves = feed.map do |cve_entry|
|
||
|
cve_attrs_from_item(cve_entry)
|
||
|
end
|
||
|
|
||
|
bulk_insert(cves)
|
||
|
end
|
||
|
end
|