scandb 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-07-08
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,22 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/scandb
6
+ lib/scandb/exceptions/invalid_database_config.rb
7
+ lib/scandb/exceptions.rb
8
+ lib/scandb/config.rb
9
+ lib/scandb/database.rb
10
+ lib/scandb/model.rb
11
+ lib/scandb/port.rb
12
+ lib/scandb/service.rb
13
+ lib/scandb/scanned_port.rb
14
+ lib/scandb/os.rb
15
+ lib/scandb/os_guess.rb
16
+ lib/scandb/host_name.rb
17
+ lib/scandb/host.rb
18
+ lib/scandb/nmap.rb
19
+ lib/scandb/runner.rb
20
+ lib/scandb/scandb.rb
21
+ lib/scandb/version.rb
22
+ lib/scandb.rb
data/README.txt ADDED
@@ -0,0 +1,47 @@
1
+ = ScanDB
2
+
3
+ * http://rubyforge.org/projects/scandb/
4
+
5
+ == DESCRIPTION:
6
+
7
+ ScanDB is a library for importing and analyzing information generated by
8
+ various network scanning utilities.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Imports scan information from Nmap XML scan files.
13
+
14
+ == REQUIREMENTS:
15
+
16
+ * DataMapper:
17
+ * do_sqlite3 >= 0.9.2
18
+ * dm-core >= 0.9.2
19
+ * dm-types >= 0.9.2
20
+ * libxml-ruby
21
+
22
+ == INSTALL:
23
+
24
+ $ sudo gem install scandb
25
+
26
+ == EXAMPLES:
27
+
28
+ == LICENSE:
29
+
30
+ ScanDB - A library for importing and analyzing information generated by
31
+ various network scanning utilities.
32
+
33
+ Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
34
+
35
+ This program is free software; you can redistribute it and/or modify
36
+ it under the terms of the GNU General Public License as published by
37
+ the Free Software Foundation; either version 2 of the License, or
38
+ (at your option) any later version.
39
+
40
+ This program is distributed in the hope that it will be useful,
41
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
42
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43
+ GNU General Public License for more details.
44
+
45
+ You should have received a copy of the GNU General Public License along
46
+ with this program; if not, write to the Free Software Foundation, Inc.,
47
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/scandb/version.rb'
6
+
7
+ Hoe.new('scandb', ScanDB::VERSION) do |p|
8
+ p.rubyforge_name = 'scandb'
9
+ p.developer('Postmodern Modulus III', 'postmodern.mod3@gmail.com')
10
+ p.extra_deps = [
11
+ ['do_sqlite3', '>=0.9.3'],
12
+ ['dm-core', '>=0.9.3'],
13
+ ['dm-types', '>=0.9.3'],
14
+ ['libxml-ruby']
15
+ ]
16
+ end
17
+
18
+ # vim: syntax=Ruby
data/bin/scandb ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
4
+ unless $LOAD_PATH.include?(lib_dir)
5
+ $LOAD_PATH << lib_dir
6
+ end
7
+
8
+ require 'scandb/runner'
9
+
10
+ ScanDB::Runner.command_line(ARGV)
data/lib/scandb.rb ADDED
@@ -0,0 +1,26 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/nmap'
25
+ require 'scandb/scandb'
26
+ require 'scandb/version'
@@ -0,0 +1,33 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'fileutils'
25
+
26
+ module ScanDB
27
+ module Config
28
+ # The configuration directory
29
+ PATH = File.join(ENV['HOME'],'.scandb')
30
+
31
+ FileUtils.mkdir(PATH) unless File.directory?(PATH)
32
+ end
33
+ end
@@ -0,0 +1,103 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/exceptions/invalid_database_config'
25
+ require 'scandb/config'
26
+ require 'scandb/port'
27
+ require 'scandb/service'
28
+ require 'scandb/os'
29
+ require 'scandb/os_guess'
30
+ require 'scandb/host_name'
31
+ require 'scandb/host'
32
+
33
+ require 'dm-core'
34
+
35
+ module ScanDB
36
+ module Database
37
+ # Database configuration file
38
+ CONFIG_FILE = File.join(Config::PATH,'database.yml')
39
+
40
+ # Default database configuration
41
+ DEFAULT_CONFIG = "sqlite3://" + File.join(Config::PATH,'scandb.db')
42
+
43
+ # Default log path
44
+ DEFAULT_LOG_PATH = File.join(Config::PATH,'scandb.log')
45
+
46
+ # Default log level
47
+ DEFAULT_LOG_LEVEL = :info
48
+
49
+ #
50
+ # Returns the Database configuration that is stored in the
51
+ # +CONFIG_FILE+. Defaults to +DEFAULT_CONFIG+ if +CONFIG_FILE+ does not
52
+ # exist.
53
+ #
54
+ def Database.config
55
+ if File.file?(CONFIG_FILE)
56
+ conf = YAML.load(CONFIG_FILE)
57
+
58
+ unless (conf.kind_of?(Hash) || conf.kind_of?(String))
59
+ raise(InvalidDatabaseConfig,"#{CONFIG_FILE} must contain either a Hash or a String",caller)
60
+ end
61
+
62
+ return conf
63
+ end
64
+
65
+ return DEFAULT_CONFIG
66
+ end
67
+
68
+ #
69
+ # Setup the Database log with the given _options_.
70
+ #
71
+ # _options_ may contain the following keys:
72
+ # <tt>:path</tt>:: The path of the log file. Defaults to
73
+ # +DEFAULT_LOG_PATH+.
74
+ # <tt>:stream</tt>:: The stream to use for the log.
75
+ # <tt>:level</tt>:: The level of messages to log.
76
+ #
77
+ def Database.setup_log(options={})
78
+ path = (options[:path] || DEFAULT_LOG_PATH)
79
+ stream = (options[:stream] || File.new(path,'w+'))
80
+ level = (options[:level] || DEFAULT_LOG_LEVEL)
81
+
82
+ DataMapper::Logger.new(stream,level)
83
+ return nil
84
+ end
85
+
86
+ #
87
+ # Sets up the Database with the given _configuration_. If
88
+ # _configuration is not given, +DEFAULT_CONFIG+ will be used to setup
89
+ # the Database.
90
+ #
91
+ def Database.setup(configuration=DEFAULT_CONFIG,&block)
92
+ Database.setup_log
93
+ DataMapper.setup(:default, configuration)
94
+
95
+ block.call if block
96
+
97
+ DataMapper.auto_upgrade!
98
+ return nil
99
+ end
100
+
101
+ Database.setup
102
+ end
103
+ end
@@ -0,0 +1,24 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/exceptions/invalid_database_config'
@@ -0,0 +1,27 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ module ScanDB
25
+ class InvalidDatabaseConfig < RuntimeError
26
+ end
27
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/model'
25
+ require 'scandb/host_name'
26
+ require 'scandb/os_guess'
27
+ require 'scandb/scanned_port'
28
+
29
+ module ScanDB
30
+ class Host
31
+
32
+ include Model
33
+
34
+ property :ip, String
35
+
36
+ has n, :names, :class_name => 'HostName'
37
+
38
+ has n, :os_guesses, :order => [:accuracy.desc], :class_name => 'OSGuess'
39
+
40
+ has n, :scanned_ports
41
+
42
+ #
43
+ # Returns the primary host name.
44
+ #
45
+ def host_name
46
+ names.first
47
+ end
48
+
49
+ def to_s
50
+ ip
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/host'
25
+
26
+ module ScanDB
27
+ class HostName
28
+
29
+ include Model
30
+
31
+ property :name, Text
32
+
33
+ belongs_to :host
34
+
35
+ def inspect
36
+ name
37
+ end
38
+
39
+ #
40
+ # Returns the host name in String form.
41
+ #
42
+ def to_s
43
+ name
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'dm-core'
25
+
26
+ module ScanDB
27
+ module Model
28
+ include DataMapper::Types
29
+
30
+ def self.included(base)
31
+ base.module_eval do
32
+ include DataMapper::Resource
33
+ include DataMapper::AutoMigrations
34
+
35
+ property :id, Serial
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,93 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/database'
25
+ require 'scandb/host'
26
+
27
+ require 'libxml'
28
+
29
+ module ScanDB
30
+ module Nmap
31
+ #
32
+ # Imports scan information from a Nmap XML scan file, specified by
33
+ # the _path_. Returns an Array of Host objects.
34
+ #
35
+ # Nmap.from_xml('path/to/scan.xml')
36
+ # # => [...]
37
+ #
38
+ def Nmap.from_xml(path)
39
+ doc = XML::Document.file(path)
40
+ hosts = []
41
+
42
+ doc.find("/nmaprun/host[status[@state='up']]").each do |host|
43
+ ip = host.find_first("address[@addr and @addrtype='ipv4']")['addr']
44
+ new_host = Host.first_or_create(:ip => ip)
45
+
46
+ host.find('hostname').each do |hostname|
47
+ new_host.names << HostName.first_or_create(
48
+ :name => hostname['name'],
49
+ :host_id => new_host.id
50
+ )
51
+ end
52
+
53
+ host.find('os/osclass').each do |osclass|
54
+ new_os = OS.first_or_create(
55
+ :type => osclass['type'],
56
+ :vendor => osclass['vendor'],
57
+ :family => osclass['osfamily'],
58
+ :version => osclass['osgen']
59
+ )
60
+
61
+ new_host.os_guesses << OSGuess.first_or_create(
62
+ :os_id => new_os.id,
63
+ :accuracy => osclass['accuracy'].to_i
64
+ )
65
+ end
66
+
67
+ host.find('ports/port').each do |port|
68
+ new_port = Port.first_or_create(
69
+ :number => port['portid'].to_i,
70
+ :protocol => port['protocol'].to_sym
71
+ )
72
+
73
+ new_service = Service.first_or_create(
74
+ :name => port.find_first('service[@name]')['name']
75
+ )
76
+
77
+ new_host.scanned_ports << ScannedPort.first_or_create(
78
+ :status => port.find_first('state[@state]')['state'].to_sym,
79
+ :service_id => new_service.id,
80
+ :port_id => new_port.id,
81
+ :host_id => new_host.id
82
+ )
83
+ end
84
+
85
+ new_host.save
86
+
87
+ hosts << new_host
88
+ end
89
+
90
+ return hosts
91
+ end
92
+ end
93
+ end
data/lib/scandb/os.rb ADDED
@@ -0,0 +1,42 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/model'
25
+
26
+ module ScanDB
27
+ class OS
28
+
29
+ include Model
30
+
31
+ property :type, String
32
+
33
+ property :vendor, String
34
+
35
+ property :family, String
36
+
37
+ property :version, String
38
+
39
+ has n, :guesses, :class_name => 'OSGuess'
40
+
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/model'
25
+ require 'scandb/os'
26
+ require 'scandb/host'
27
+
28
+ module ScanDB
29
+ class OSGuess
30
+
31
+ include Model
32
+
33
+ property :accuracy, Integer
34
+
35
+ belongs_to :os, :class_name => 'OS'
36
+
37
+ belongs_to :host
38
+
39
+ end
40
+ end
@@ -0,0 +1,53 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/model'
25
+ require 'scandb/host'
26
+ require 'scandb/service'
27
+
28
+ require 'dm-types/enum'
29
+
30
+ module ScanDB
31
+ class Port
32
+
33
+ include Model
34
+
35
+ property :protocol, Enum[:tcp, :udp]
36
+
37
+ property :number, Integer
38
+
39
+ has n, :scanned, :class_name => 'ScannedPort'
40
+
41
+ has n, :hosts, :through => :scanned
42
+
43
+ has n, :services, :through => :scanned
44
+
45
+ #
46
+ # Returns the String form of the port.
47
+ #
48
+ def to_s
49
+ "#{number}/#{protocol}"
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,91 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/database'
25
+ require 'scandb/nmap'
26
+
27
+ require 'ostruct'
28
+ require 'optparse'
29
+
30
+ module ScanDB
31
+ module Runner
32
+ #
33
+ # The command-line runner.
34
+ #
35
+ def Runner.command_line(args)
36
+ options = OpenStruct.new
37
+
38
+ opts = OptionParser.new do |opts|
39
+ opts.banner = 'usage: scandb [-d URI] [--import-nmap FILE | -L | -p PORT | -s NAME]'
40
+
41
+ opts.on('-d','--database URI','The URI for the Database.','Defaults to ~/.scandb/scandb.db') do |uri|
42
+ options.database = uri
43
+ end
44
+
45
+ opts.on('--import-nmap FILE','Import a Nmap XML scan file') do |file|
46
+ options.import = :nmap
47
+ options.import_file = file
48
+ end
49
+
50
+ opts.on('-L','--list-hosts','List all hosts within ScanDB') do
51
+ options.list_hosts = true
52
+ end
53
+
54
+ opts.on('-p','--with-port PORT','List hosts with the specified open PORT') do |port|
55
+ options.with_port = port.to_i
56
+ end
57
+
58
+ opts.on('-s','--with-service NAME','List hosts with the specified service') do |name|
59
+ options.with_service = name
60
+ end
61
+
62
+ opts.on('-h','--help','This cruft') do
63
+ puts opts
64
+ exit
65
+ end
66
+ end
67
+
68
+ opts.parse!(args)
69
+
70
+ if options.import
71
+ case options.import
72
+ when :nmap then
73
+ hosts = Nmap.from_xml(options.import_file)
74
+ puts "Success imported #{hosts.length} hosts."
75
+ end
76
+ else
77
+ if options.with_port
78
+ hosts = Port.all(:number => options.with_port).scanned(:status => :open).host
79
+ elsif options.with_service
80
+ hosts = Service.all(:name.like => "%#{options.with_service}%").scanned(:status => :open).host
81
+ else
82
+ hosts = Host.all
83
+ end
84
+
85
+ hosts.each { |host| puts host}
86
+ end
87
+
88
+ return true
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ module ScanDB
25
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/model'
25
+ require 'scandb/service'
26
+ require 'scandb/port'
27
+ require 'scandb/host'
28
+
29
+ require 'dm-types/enum'
30
+
31
+ module ScanDB
32
+ class ScannedPort
33
+
34
+ include Model
35
+
36
+ property :status, Enum[:open, :filtered, :closed]
37
+
38
+ belongs_to :service
39
+
40
+ belongs_to :port
41
+
42
+ belongs_to :host
43
+
44
+ #
45
+ # Returns the String form of the scanned port.
46
+ #
47
+ def to_s
48
+ sprintf("%9s%9s\t%s",port,status,service)
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ require 'scandb/model'
25
+
26
+ require 'dm-types/enum'
27
+
28
+ module ScanDB
29
+ class Service
30
+
31
+ include Model
32
+
33
+ property :name, String
34
+
35
+ has n, :scanned, :class_name => 'ScannedPort'
36
+
37
+ has n, :hosts, :through => :scanned
38
+
39
+ #
40
+ # Returns the String form of the service.
41
+ #
42
+ def to_s
43
+ name
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ #--
3
+ # ScanDB - A library for importing and analyzing information generated by
4
+ # various network scanning utilities.
5
+ #
6
+ # Copyright (c) 2008 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, write to the Free Software Foundation, Inc.,
20
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ #++
22
+ #
23
+
24
+ module ScanDB
25
+ # ScanDB version
26
+ VERSION = '0.0.9'
27
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scandb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Postmodern Modulus III
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-27 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: do_sqlite3
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: dm-core
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: dm-types
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.3
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: libxml-ruby
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.7.0
64
+ version:
65
+ description: ScanDB is a library for importing and analyzing information generated by various network scanning utilities.
66
+ email:
67
+ - postmodern.mod3@gmail.com
68
+ executables:
69
+ - scandb
70
+ extensions: []
71
+
72
+ extra_rdoc_files:
73
+ - History.txt
74
+ - Manifest.txt
75
+ - README.txt
76
+ files:
77
+ - History.txt
78
+ - Manifest.txt
79
+ - README.txt
80
+ - Rakefile
81
+ - bin/scandb
82
+ - lib/scandb/exceptions/invalid_database_config.rb
83
+ - lib/scandb/exceptions.rb
84
+ - lib/scandb/config.rb
85
+ - lib/scandb/database.rb
86
+ - lib/scandb/model.rb
87
+ - lib/scandb/port.rb
88
+ - lib/scandb/service.rb
89
+ - lib/scandb/scanned_port.rb
90
+ - lib/scandb/os.rb
91
+ - lib/scandb/os_guess.rb
92
+ - lib/scandb/host_name.rb
93
+ - lib/scandb/host.rb
94
+ - lib/scandb/nmap.rb
95
+ - lib/scandb/runner.rb
96
+ - lib/scandb/scandb.rb
97
+ - lib/scandb/version.rb
98
+ - lib/scandb.rb
99
+ has_rdoc: true
100
+ homepage: http://rubyforge.org/projects/scandb/
101
+ post_install_message:
102
+ rdoc_options:
103
+ - --main
104
+ - README.txt
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: "0"
118
+ version:
119
+ requirements: []
120
+
121
+ rubyforge_project: scandb
122
+ rubygems_version: 1.2.0
123
+ signing_key:
124
+ specification_version: 2
125
+ summary: ScanDB is a library for importing and analyzing information generated by various network scanning utilities.
126
+ test_files: []
127
+