nvd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a882d44796a5863b20c0a416ff519a6998b354a2
4
+ data.tar.gz: 202c210f928e8f7ca9952eeb36bb966a15567783
5
+ SHA512:
6
+ metadata.gz: cc0145c0d7ede5f9f8c18b984247b0476d76d239c243acd734ab6aaede10d5c609b68c8e7688753be2163357d3cbced3d225b6e64ea3307186207853724a3041
7
+ data.tar.gz: 5497bc4652471fc39a02a49e688fce3dee02c93f1a28d60d7b19b385250a52260d01ab3d421102c6f3ec7ba3f5d14ac174500f260a8645d8ea38d8f95cad16a8
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nvd.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ben Hamilton
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ # Nvd
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'nvd'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install nvd
18
+
19
+ ## Usage
20
+
21
+ To use:
22
+ require 'nvd'
23
+ cve_data = {}
24
+ cve_data.merge! NVD::Feeds.fetch("cve_modified")
25
+ cve_data.merge! NVD::Feeds.fetch("cve_recent")
26
+ cve_data.keys #=> ["cve_recent", "cve_modified"]
27
+
28
+ # First run returns parsed values
29
+ NVD::Feeds.fetch("cve_modified")
30
+ #=> {"cve_modified"=>[<An Array of Entries>]}
31
+ # Second run return the etag if the etag is unchanged; otherwise,
32
+ # the parsed values are returned.
33
+ NVD::Feeds.fetch("cve_modified")
34
+ #=> {"cve_modified"=>"\"89e2a7785a6ce1:0\""}
35
+
36
+ # If you've stored the etag
37
+ NVD::Feeds.fetch("cve_modified", "\"89e2a7785a6ce1:0\"")
38
+
39
+ # If you want to skip etag checking
40
+ NVD::Feeds.fetch!("cve_modified")
41
+ # OR
42
+ NVD::Feeds.fetch("cve_modified", "\"89e2a7785a6ce1:0\"")
43
+
44
+ ## Available Feeds
45
+
46
+ cpe_dictionary, cve_2002, cve_2003, cve_2004,
47
+ cve_2005, cve_2006, cve_2007, cve_2008, cve_2009,
48
+ cve_2010, cve_2011, cve_2012, cve_2013,
49
+ cve_modified, cve_recent
50
+
51
+ NOTE: cve_YEAR is populated dynamically to be future proof
52
+
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ require 'httparty'
2
+ require "nvd/version"
3
+ require "nvd/feed.rb"
4
+
5
+
6
+ module NVD
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,44 @@
1
+ require './lib/nvd/feed/cve.rb'
2
+ require './lib/nvd/feed/cpe.rb'
3
+ module NVD
4
+ module Feed
5
+ @@feeds ||= []
6
+ @@etags ||= {}
7
+
8
+ def self.etags
9
+ @@etags
10
+ end
11
+
12
+ def self.fetch!(tag,etag=nil)
13
+ etags.delete tag
14
+ fetch(tag, etag)
15
+ end
16
+
17
+ def self.fetch(tag,etag=nil)
18
+ feed = @@feeds.detect {|f| f::LOCATIONS.any? {|k,v| k == tag || v == tag}}
19
+ location = feed::LOCATIONS.detect {|k,v| k == tag || v == tag}
20
+ return nil unless location
21
+ tag = location[0]
22
+ etag = (etags[tag] || "") unless etag
23
+ puts "Fetching entries for #{tag} ..."
24
+ {tag => feed.fetch(tag,etag)}
25
+ end
26
+
27
+ def self.gunzip(gdata)
28
+ zi = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
29
+ begin
30
+ return zi.inflate(gdata)
31
+ rescue Zlib::DataError => e
32
+ raise "please provide gzipped data"
33
+ rescue => e
34
+ raise e
35
+ end
36
+
37
+ end
38
+
39
+ def self.feeds
40
+ @@feeds
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,46 @@
1
+ module NVD
2
+ module Feed
3
+
4
+ module CPE
5
+ LOCATIONS = {} unless defined? LOCATIONS
6
+ LOCATIONS["cpe_dictionary"] = "http://static.nvd.nist.gov/feeds/xml/cpe/dictionary/official-cpe-dictionary_v2.3.xml.gz"
7
+
8
+ def self.fetch(tag,etag=nil)
9
+ location = LOCATIONS[tag]
10
+ return nil unless location
11
+ retval = {}
12
+ etag = (NVD::Feed.etags[tag] || "" ) unless etag
13
+ data = HTTParty.get(location, {:headers => {"If-None-Match" => etag}})
14
+ NVD::Feed.etags[tag] = data.response.header["etag"]
15
+ return NVD::Feed.etags[tag] if data.nil?
16
+ if location.match(/gz$/)
17
+ data = NVD::Feed.gunzip(data)
18
+ if location.match(/\.xml/)
19
+ xml = HTTParty::Parser.new(data, :xml).parse
20
+ data = []
21
+ xml["cpe_list"]["cpe_item"].each do |item|
22
+ item.each do |k,v|
23
+ v = v.detect {|i| i["lang"] == "en-US"} if v.is_a?(Array)
24
+ item[k] = v["__content__"] if v["__content__"]
25
+ end
26
+ item.delete "cpe23_item"
27
+ data << item
28
+ end
29
+ end
30
+ end
31
+ retval[name] = data
32
+ end
33
+
34
+ def self.fetch_all
35
+ retval = {}
36
+ LOCATIONS.each do |name, location|
37
+ end
38
+ retval
39
+ end #end method
40
+ end #end CPE module
41
+
42
+ @@feeds ||= []
43
+ @@feeds << CPE
44
+
45
+ end
46
+ end
@@ -0,0 +1,104 @@
1
+ module NVD
2
+ module Feed
3
+ module CVE
4
+ LOCATIONS = {} unless defined? CVE_LOCATIONS
5
+ (["recent", "modified"] | (2002..Date.today.year).to_a).each do |key|
6
+ LOCATIONS["cve_" + key.to_s] = "https://nvd.nist.gov/static/feeds/xml/cve/nvdcve-2.0-#{key.to_s}.xml"
7
+ end
8
+
9
+ def self.fetch(tag,etag=nil)
10
+ retval = {}
11
+ location = LOCATIONS[tag]
12
+ return nil unless location
13
+ etag = (NVD::Feed.etags[tag] || "" ) unless etag
14
+ data = HTTParty.get(location, {:headers => {"If-None-Match" => etag}})
15
+ NVD::Feed.etags[tag] = data.response.header["etag"]
16
+ return NVD::Feed.etags[tag] if data.nil?
17
+ if location.match(/gz$/)
18
+ data = NVD::Feed.gunzip(data)
19
+ if location.match(/\.xml/)
20
+ xml = HTTParty::Parser.new(data, :xml).parse
21
+ data = []
22
+ binding.pry #unless xml["nvd"] && xml["nvd"]["entry"]
23
+ xml["nvd"]["entry"].each do |item|
24
+ # item = OpenStruct.new(item)
25
+ item.each_pair do |k,v|
26
+ v = v.detect {|i| i["lang"] == "en-US"} if v.is_a?(Array)
27
+ item[k] = v["__content__"] if v["__content__"]
28
+ end
29
+ data << item
30
+ end
31
+ retval[tag] = data
32
+ end
33
+ end
34
+
35
+ if data.class == HTTParty::Response
36
+ response = []
37
+ data["nvd"]["entry"].each do |item|
38
+ item["cvss"].each do |k,v|
39
+ v.each do |j,l|
40
+ item["cvss"][k][j] = Time.parse(l) if j.to_s.include?("datetime")
41
+ item["cvss"][k][j] = l.to_f if j.to_s.include?("score")
42
+ end if v.is_a?(Hash)
43
+ end if item["cvss"]
44
+ refs = []
45
+ [item["references"]].flatten.each do |r|
46
+ r.each do |k,v|
47
+ v = v.detect {|i| i["lang"] == "en-US"} if v.is_a?(Array)
48
+ r[k] = v["href"] if v["__content__"] && v["href"]
49
+ end if r
50
+ refs << r
51
+ end
52
+ item["references"] = refs
53
+ products = []
54
+ products = [item["vulnerable_software_list"]["product"]].flatten if item["vulnerable_software_list"]
55
+ item["vulnerable_software_list"] = products
56
+ item.each do |k,v|
57
+ item[k] = Time.parse(v) if k.to_s.include?("datetime")
58
+ end
59
+ response << item
60
+ end
61
+ retval = response
62
+ end
63
+ return retval
64
+ end
65
+
66
+ def self.fetch_all
67
+ retval = {}
68
+ LOCATIONS.each do |tag, location|
69
+ puts tag
70
+ retval[tag] = fetch(tag)
71
+ return retval
72
+ end
73
+ retval
74
+ end
75
+
76
+ def self.save_off(name,data)
77
+
78
+ end
79
+ end
80
+
81
+ @@feeds ||= []
82
+ @@feeds << CVE
83
+
84
+ end
85
+ end
86
+
87
+
88
+ class Person < OpenStruct
89
+ attr_accessor :name, :age, :gender
90
+ def work
91
+ puts "POOF! Eight more hours gone!"
92
+ end
93
+
94
+ def slumber(num=10)
95
+ puts "going to sleep"
96
+ sleep num
97
+ puts "waking up"
98
+ sleep num/10
99
+ end
100
+
101
+ def eat(meal="bacon and eggs")
102
+ puts "I'm sitting down to eat #{meal}"
103
+ end
104
+ end
@@ -0,0 +1,3 @@
1
+ module Nvd
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nvd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nvd"
8
+ spec.version = Nvd::VERSION
9
+ spec.authors = ["Ben Hamilton"]
10
+ spec.email = ["benhami@gmail.com"]
11
+ spec.description = %q{A simple gem abstraction for MITRE NVD SCAP data}
12
+ spec.summary = %q{MITRE NVD SCAP data}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_dependency "httparty"
26
+
27
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nvd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Hamilton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A simple gem abstraction for MITRE NVD SCAP data
70
+ email:
71
+ - benhami@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/nvd.rb
83
+ - lib/nvd/feed.rb
84
+ - lib/nvd/feed/cpe.rb
85
+ - lib/nvd/feed/cve.rb
86
+ - lib/nvd/version.rb
87
+ - nvd.gemspec
88
+ - spec/spec_helper.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.0.3
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: MITRE NVD SCAP data
113
+ test_files:
114
+ - spec/spec_helper.rb