Skip to content

Commit 5f145bc

Browse files
author
Jens Färber
committed
initial gem commit
1 parent 411fe49 commit 5f145bc

37 files changed

+1205
-0
lines changed

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "http://rubygems.org"
2+
3+
# Specify your gem's dependencies in fidius-cvedb.gemspec
4+
gemspec

LICENSE

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
The Simplified BSD License
2+
3+
Copyright (C) 2010-2011 FIDIUS Intrusion Detection with Intelligent
4+
User Support (FIDIUS). All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are
8+
met:
9+
10+
1. Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
17+
THIS SOFTWARE IS PROVIDED BY FIDIUS ``AS IS'' AND ANY EXPRESS OR
18+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL FIDIUS OR CONTRIBUTORS BE LIABLE FOR ANY
21+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
POSSIBILITY OF SUCH DAMAGE.
28+
29+
The views and conclusions contained in the software and documentation
30+
are those of the authors and should not be interpreted as representing
31+
official policies, either expressed or implied, of FIDIUS.
32+
33+
34+
*OR*
35+
36+
GNU GENERAL PUBLIC LICENSE
37+
Version 2, June 1991
38+
39+
Copyright (C) 2010-2011 FIDIUS Intrusion Detection with Intelligent
40+
User Suppport.
41+
42+
This program is free software; you can redistribute it and/or modify
43+
it under the terms of the GNU General Public License as published by
44+
the Free Software Foundation; either version 2 of the License, or
45+
(at your option) any later version.
46+
47+
This program is distributed in the hope that it will be useful,
48+
but WITHOUT ANY WARRANTY; without even the implied warranty of
49+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50+
GNU General Public License for more details.
51+
52+
You should have received a copy of the GNU General Public License along
53+
with this program; if not, write to the Free Software Foundation, Inc.,
54+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
55+
56+
A digital copy is also available for download here:
57+
http://www.gnu.org/licenses/gpl-2.0.txt.

README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
3+
4+
5+
#TODO
6+
#Database Example config
7+
#Gemfile requirements (nokogiri)
8+
#cve establich connection
9+
#rake tasks
10+
11+
12+
13+
14+
# FIDIUS fidius-cvedb
15+
16+
The purpose of this package is...
17+
18+
We will use these concepts to describe $foo: ...
19+
20+
This package is targeted at...
21+
22+
23+
## Installation
24+
25+
Simply install this package with Rubygems:
26+
27+
$ gem install fidius-cvedb
28+
29+
30+
## Example of use
31+
32+
To use this package as library, follow these steps:
33+
34+
1. do this
35+
2. and
36+
3. that
37+
38+
39+
## Synopsis
40+
41+
This package comes with an executable script. You may invoke it as
42+
43+
$ gemname-runner [--opt=x|--no-opt=y] <file>
44+
45+
where
46+
47+
* `--opt` does absolutely nothing with `x`
48+
* `--no-opt` does aparently nothing with `y`
49+
* `<file>` is ignores
50+
51+
52+
## Authors and Contact
53+
54+
fidius-cvedb was written by
55+
56+
* FIDIUS Intrusion Detection with Intelligent User Support
57+
<[email protected]>, <http://fidius.me>
58+
* in particular:
59+
* Andreas Bender <[email protected]>
60+
* Jens Färber <[email protected]>
61+
62+
If you have any questions, remarks, suggestion, improvements,
63+
etc. feel free to drop a line at the addresses given above.
64+
You might also join `#fidius` on Freenode or use the contact
65+
form on our [website](http://fidius.me/en/contact).
66+
67+
68+
## License
69+
70+
Simplified BSD License and GNU GPLv2. See also the file LICENSE.

Rakefile

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require 'bundler'
2+
require 'rake/hooks'
3+
require 'rake/clean'
4+
require 'digest/sha1'
5+
require 'find'
6+
require 'rubygems'
7+
8+
Bundler::GemHelper.install_tasks
9+
10+
CLOBBER.include 'pkg'
11+
12+
RAILS_PATH = File.expand_path(File.join('..', '..', 'cve-db', 'cveprovider'))
13+
14+
before :build do
15+
16+
#TODO:
17+
#copy tests
18+
#edit readme
19+
#give db-hints
20+
#change module for all files to Fidius
21+
#(git autocommit after copy)
22+
#implement runner script
23+
24+
copy_files File.join('app', 'models')
25+
copy_files 'cveparser'
26+
copy_files File.join('lib', 'tasks')
27+
copy_files File.join('db', 'migrate')
28+
29+
end
30+
31+
# Copies files from cveprovider directory to gem's lib directory
32+
# Only new and changed files will be copied (based on SHA1 Hash)
33+
def copy_files path
34+
changed_files = false
35+
Find.find(File.expand_path(File.join(RAILS_PATH, path))) do |src|
36+
unless File.directory? src
37+
rel_src = src.sub(File.join(RAILS_PATH, path.split('/')[0...-1]), "")
38+
dst = File.expand_path(File.join(File.dirname(__FILE__), 'lib', rel_src))
39+
40+
if File.exists? dst
41+
unless Digest::SHA1.hexdigest(File.read(src)) ==
42+
Digest::SHA1.hexdigest(File.read(dst))
43+
puts "CHANGE: #{dst}"
44+
FileUtils.cp(src, dst)
45+
end
46+
changed_files = true
47+
48+
else
49+
FileUtils.mkdir_p(File.dirname(dst))
50+
FileUtils.cp(src, dst)
51+
puts "NEW: #{dst}"
52+
changed_files = true
53+
end
54+
end
55+
end
56+
changed_files
57+
end

bin/fidius-cvedb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env ruby
2+
require 'optparse'
3+
require 'fidius-cvedb/version'
4+
require 'fidius-cvedb'
5+
6+
options = {}
7+
8+
optparse = OptionParser.new do|opts|
9+
10+
opts.banner = "Usage: fidius-cvedb-runner [options]"
11+
12+
opts.on_tail("-f", "--fidius", "Initialize CVE-DB for Usage in FIDIUS C&C-Server") do
13+
puts opts
14+
exit
15+
end
16+
17+
opts.on_tail("-s", "--standalone", "Initialize CVE-DB standalone version") do
18+
puts opts
19+
exit
20+
end
21+
22+
opts.on_tail("-h", "--help", "Show this message") do
23+
puts opts
24+
exit
25+
end
26+
27+
opts.on_tail("-v", "--version", "Show version") do
28+
puts "FIDIUS CVE-DB, Version #{Fidius::Cvedb::VERSION}"
29+
exit
30+
end
31+
end
32+
33+
optparse.parse!

fidius-cvedb.gemspec

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- encoding: utf-8 -*-
2+
$:.push File.expand_path("../lib", __FILE__)
3+
require "fidius-cvedb/version"
4+
5+
Gem::Specification.new do |s|
6+
s.name = "fidius-cvedb"
7+
s.version = Fidius::Cvedb::VERSION
8+
s.platform = Gem::Platform::RUBY
9+
s.authors = ["Andreas Bender, Jens Färber"]
10+
11+
s.homepage = "http://www.fidius.me"
12+
s.summary = %q{Provides a parser and ActiveRecord models for the Common Vulnerability and Exposures (CVE) entries offered by the National Vulnerability Database (http://nvd.nist.gov/). }
13+
s.description = %q{This gem provides an opportunity to run a vulnerability database in your own environt. Therefore it comes with a parser for the National Vulnerability Database and ActiveRecord models for storing the entries in a local database. }
14+
15+
s.rubyforge_project = "fidius-cvedb"
16+
17+
s.files = `git ls-files`.split("\n")
18+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20+
s.require_paths = ["lib"]
21+
end

lib/cveparser/main.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "#{Rails.root.to_s}/cveparser/parser"
2+
require "#{Rails.root.to_s}/cveparser/rails_store"
3+
require "#{Rails.root.to_s}/cveparser/ms_parser"
4+
5+
include NVDParser
6+
include CveDb
7+
8+
PARAMS = {
9+
'-p' => 'Parse new XML file passed as 2nd param.',
10+
'-f' => 'Fix duplicate products.',
11+
'-u' => 'Updates CVE-Entries, needs modified.xml or recent.xml by nvd.org as 2nd argument.',
12+
'-m' => 'Creates the mapping between CVEs and Microsoft Security Bulletin Notation entries in the database.'
13+
}
14+
15+
case ARGV[0]
16+
when '-p'
17+
entries = NVDParser.parse_cve_file ARGV[1]
18+
RailsStore.create_new_entries(ARGV[1].split("/").last, entries)
19+
when '-f'
20+
RailsStore.fix_product_duplicates
21+
when '-u'
22+
entries = NVDParser.parse_cve_file ARGV[1]
23+
RailsStore.update_cves(entries)
24+
when '-m'
25+
MSParser.parse_ms_cve
26+
else
27+
puts "ERROR: You've passed none or an unknown parameter, available "+
28+
"parameters are:"
29+
PARAMS.each_key do |param|
30+
puts "#{param}\t#{PARAMS[param]}"
31+
end
32+
end

lib/cveparser/ms_parser.rb

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require 'open-uri'
2+
3+
module MSParser
4+
5+
include CveDb
6+
7+
BASE_URL = "http://cve.mitre.org/data/refs/refmap/source-MS.html"
8+
9+
def self.parse_ms_cve
10+
entries = parse
11+
counter = 0
12+
entries.each_pair do |ms,cves|
13+
cves.each do |cve|
14+
existing_cve = NvdEntry.find_by_cve(cve.strip)
15+
if existing_cve
16+
Mscve.find_or_create_by_nvd_entry_id_and_name(existing_cve.id, ms)
17+
puts "Found: #{existing_cve.cve}."
18+
counter += 1
19+
end
20+
end
21+
end
22+
puts "Added #{counter} items to database."
23+
end
24+
25+
def self.print_map
26+
entries = parse
27+
entries.each_pair do |ms,cves|
28+
puts "#{ms}"
29+
cves.each {|cve| puts "----#{cve}"}
30+
end
31+
end
32+
33+
private
34+
35+
def self.parse
36+
doc = Nokogiri::HTML(open(BASE_URL))
37+
entries = Hash.new("")
38+
current_ms_entry = ""
39+
doc.css('table[border="2"] > tr').each do |entry|
40+
entry.css("td").each do |td|
41+
if td.content =~ /CVE-\d{4}-\d{4}/
42+
entries[current_ms_entry] = td.content.split("\n")
43+
else
44+
current_ms_entry = td.content.split(":").last
45+
entries[current_ms_entry]
46+
end
47+
end
48+
end
49+
puts "Parsed #{entries.size} entries."
50+
entries
51+
end
52+
end

0 commit comments

Comments
 (0)