antfarm-core 0.5.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+ ################################################################################
2
+ # #
3
+ # Copyright (2008-2010) Sandia Corporation. Under the terms of Contract #
4
+ # DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains #
5
+ # certain rights in this software. #
6
+ # #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy #
8
+ # of this software and associated documentation files (the "Software"), to #
9
+ # deal in the Software without restriction, including without limitation the #
10
+ # rights to use, copy, modify, merge, publish, distribute, distribute with #
11
+ # modifications, sublicense, and/or sell copies of the Software, and to permit #
12
+ # persons to whom the Software is furnished to do so, subject to the following #
13
+ # conditions: #
14
+ # #
15
+ # The above copyright notice and this permission notice shall be included in #
16
+ # all copies or substantial portions of the Software. #
17
+ # #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
21
+ # ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR #
23
+ # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
24
+ # SOFTWARE. #
25
+ # #
26
+ # Except as contained in this notice, the name(s) of the above copyright #
27
+ # holders shall not be used in advertising or otherwise to promote the sale, #
28
+ # use or other dealings in this Software without prior written authorization. #
29
+ # #
30
+ ################################################################################
31
+
32
+ module Antfarm
33
+ module Plugin
34
+ class FileDoesNotExistError < Antfarm::AntfarmError; end
35
+
36
+ class LoadHost
37
+ include Antfarm::Plugin
38
+
39
+ def initialize
40
+ super({ :name => 'Load Host',
41
+ :desc => 'Given a file with one IP address per line, create a new IP Interface in the DB',
42
+ :author => 'Bryan T. Richardson <btricha>' },
43
+ [ { :name => :input_file,
44
+ :desc => 'File with IP addresses in it',
45
+ :type => String,
46
+ :required => true },
47
+ { :name => :tags,
48
+ :desc => 'Comma-separated list of tags for each interface',
49
+ :type => String,
50
+ :required => false }
51
+ ])
52
+ end
53
+
54
+ def run(options)
55
+ print_message "Parsing file #{options[:input_file]}"
56
+
57
+ begin
58
+ File.open(options[:input_file]) do |file|
59
+ file.each do |line|
60
+ data = line.strip.split(' ')
61
+
62
+ if data.length == 1
63
+ iface = Antfarm::Model::IpInterface.find_by_address(data[0])
64
+
65
+ if iface.nil?
66
+ Antfarm::Model::IpInterface.create(:address => data[0])
67
+ else
68
+ node = iface.layer3_interface.layer2_interface.node
69
+ node.name = data[0]
70
+ node.save
71
+ end
72
+ else
73
+ name = data.shift
74
+ node = Antfarm::Model::Node.find_by_name(name)
75
+
76
+ if node.nil?
77
+ node = Antfarm::Model::Node.new
78
+ node.name = name
79
+ node.save
80
+
81
+ for address in data
82
+ iface = Antfarm::Model::IpInterface.find_by_address(address)
83
+ if iface.nil?
84
+ Antfarm::Model::IpInterface.create(:address => address)
85
+ else
86
+ l2iface = iface.layer3_interface.layer2_interface
87
+ l2iface.node = node
88
+ l2iface.save
89
+ end
90
+ end
91
+ else
92
+ # TODO
93
+ end
94
+ end
95
+ end
96
+ end
97
+ rescue Errno::ENOENT
98
+ raise FileDoesNotExistError, "The file '#{options[:input_file]}' doesn't exist"
99
+ rescue Exception => e
100
+ raise Antfarm::AntfarmError, e.message
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,71 @@
1
+ ################################################################################
2
+ # #
3
+ # Copyright (2008-2010) Sandia Corporation. Under the terms of Contract #
4
+ # DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains #
5
+ # certain rights in this software. #
6
+ # #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy #
8
+ # of this software and associated documentation files (the "Software"), to #
9
+ # deal in the Software without restriction, including without limitation the #
10
+ # rights to use, copy, modify, merge, publish, distribute, distribute with #
11
+ # modifications, sublicense, and/or sell copies of the Software, and to permit #
12
+ # persons to whom the Software is furnished to do so, subject to the following #
13
+ # conditions: #
14
+ # #
15
+ # The above copyright notice and this permission notice shall be included in #
16
+ # all copies or substantial portions of the Software. #
17
+ # #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
21
+ # ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR #
23
+ # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
24
+ # SOFTWARE. #
25
+ # #
26
+ # Except as contained in this notice, the name(s) of the above copyright #
27
+ # holders shall not be used in advertising or otherwise to promote the sale, #
28
+ # use or other dealings in this Software without prior written authorization. #
29
+ # #
30
+ ################################################################################
31
+
32
+ module Antfarm
33
+ module Plugin
34
+ class FileDoesNotExistError < Antfarm::AntfarmError; end
35
+
36
+ class LoadNetwork
37
+ include Antfarm::Plugin
38
+
39
+ def initialize
40
+ super({ :name => 'Load Network',
41
+ :desc => 'Given a file with one IP network address per line, create a new IP Network in the DB',
42
+ :author => 'Bryan T. Richardson <btricha>' },
43
+ [ { :name => :input_file,
44
+ :desc => 'File with IP networks in it',
45
+ :type => String,
46
+ :required => true }
47
+ ])
48
+ end
49
+
50
+ def run(options)
51
+ print_message "Parsing file #{options[:input_file]}"
52
+
53
+ begin
54
+ File.open(options[:input_file]) do |file|
55
+ file.each do |line|
56
+ print_message "Loading network #{line.strip}"
57
+
58
+ unless Antfarm::Model::IpNetwork.find_by_address line.strip
59
+ Antfarm::Model::IpNetwork.create :address => line.strip
60
+ end
61
+ end
62
+ end
63
+ rescue Errno::ENOENT
64
+ raise FileDoesNotExistError, "The file '#{options[:input_file]}' doesn't exist"
65
+ rescue Exception => e
66
+ raise Antfarm::AntfarmError, e.message
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,84 @@
1
+ ################################################################################
2
+ # #
3
+ # Copyright (2008-2010) Sandia Corporation. Under the terms of Contract #
4
+ # DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains #
5
+ # certain rights in this software. #
6
+ # #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy #
8
+ # of this software and associated documentation files (the "Software"), to #
9
+ # deal in the Software without restriction, including without limitation the #
10
+ # rights to use, copy, modify, merge, publish, distribute, distribute with #
11
+ # modifications, sublicense, and/or sell copies of the Software, and to permit #
12
+ # persons to whom the Software is furnished to do so, subject to the following #
13
+ # conditions: #
14
+ # #
15
+ # The above copyright notice and this permission notice shall be included in #
16
+ # all copies or substantial portions of the Software. #
17
+ # #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
21
+ # ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR #
23
+ # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
24
+ # SOFTWARE. #
25
+ # #
26
+ # Except as contained in this notice, the name(s) of the above copyright #
27
+ # holders shall not be used in advertising or otherwise to promote the sale, #
28
+ # use or other dealings in this Software without prior written authorization. #
29
+ # #
30
+ ################################################################################
31
+
32
+ module Antfarm
33
+ module Plugin
34
+ module Nmap
35
+ class FileDoesNotExistError < Antfarm::AntfarmError; end
36
+
37
+ class ParseXml
38
+ include Antfarm::Plugin
39
+
40
+ def initialize
41
+ super({ :name => 'Parse Nmap XML Output',
42
+ :desc => 'Parses the XML result of an Nmap scan and creates an IP interface for each host',
43
+ :author => 'Bryan T. Richardson <btricha>' },
44
+ [ { :name => :input,
45
+ :desc => 'Nmap XML output file or directory',
46
+ :type => String,
47
+ :required => true }
48
+ ])
49
+ end
50
+
51
+ def run(options)
52
+ input = options[:input]
53
+
54
+ if File.directory?(input)
55
+ Find.find(input) do |path|
56
+ if File.file?(path)
57
+ parse(path)
58
+ end
59
+ end
60
+ else
61
+ parse(input)
62
+ end
63
+ end
64
+
65
+ def parse(file)
66
+ print_message "Parsing file #{file}"
67
+
68
+ begin
69
+ results = REXML::Document.new(File.new(file))
70
+ results.elements.each('nmaprun') do |scan|
71
+ scan.elements.each('host') do |host|
72
+ Antfarm::Model::IpInterface.create :address => host.elements['address'].attributes['addr']
73
+ end
74
+ end
75
+ rescue Errno::ENOENT
76
+ raise FileDoesNotExistError, "The file #{file} doesn't exist"
77
+ rescue Exception => e
78
+ raise Antfarm::AntfarmError, e.message
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,9 @@
1
+ module Antfarm
2
+ MAJOR = 0
3
+ MINOR = 5
4
+ BUG = 0
5
+
6
+ def self.version
7
+ return "#{MAJOR}.#{MINOR}.#{BUG}"
8
+ end
9
+ end
@@ -0,0 +1,56 @@
1
+ ################################################################################
2
+ # #
3
+ # Copyright (2008-2010) Sandia Corporation. Under the terms of Contract #
4
+ # DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains #
5
+ # certain rights in this software. #
6
+ # #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy #
8
+ # of this software and associated documentation files (the "Software"), to #
9
+ # deal in the Software without restriction, including without limitation the #
10
+ # rights to use, copy, modify, merge, publish, distribute, distribute with #
11
+ # modifications, sublicense, and/or sell copies of the Software, and to permit #
12
+ # persons to whom the Software is furnished to do so, subject to the following #
13
+ # conditions: #
14
+ # #
15
+ # The above copyright notice and this permission notice shall be included in #
16
+ # all copies or substantial portions of the Software. #
17
+ # #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
21
+ # ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR #
23
+ # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
24
+ # SOFTWARE. #
25
+ # #
26
+ # Except as contained in this notice, the name(s) of the above copyright #
27
+ # holders shall not be used in advertising or otherwise to promote the sale, #
28
+ # use or other dealings in this Software without prior written authorization. #
29
+ # #
30
+ ################################################################################
31
+
32
+ require 'spec/rake/spectask'
33
+
34
+ SPEC_SUITES = [
35
+ { :id => :models, :title => 'models', :files => %w(spec/models/*_spec.rb) }
36
+ ]
37
+
38
+ namespace :spec do
39
+ SPEC_SUITES.each do |suite|
40
+ desc "Run all specs in #{suite[:title]} spec suite"
41
+ Spec::Rake::SpecTask.new(suite[:id]) do |t|
42
+ files = []
43
+
44
+ if suite[:files]
45
+ suite[:files].each { |glob| files += Dir[glob] }
46
+ end
47
+
48
+ if suite[:dirs]
49
+ suite[:dirs].each { |glob| files += Dir["#{glob}/**/*_spec.rb"] }
50
+ end
51
+
52
+ t.spec_files = files
53
+ t.spec_opts = [ '--color' ]
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,69 @@
1
+ .\" generated with Ronn/v0.5
2
+ .\" http://github.com/rtomayko/ronn/
3
+ .
4
+ .TH "ANTFARM\-PLUGINS" "1" "September 2010" "" "ANTFARM"
5
+ .
6
+ .SH "NAME"
7
+ \fBantfarm\-plugins\fR \-\- plugins for the ANTFARM passive network mapping tool
8
+ .
9
+ .SH "DESCRIPTION"
10
+ ANTFARM (Advanced Network Toolkit For Assessments and Remote Mapping) is a
11
+ passive network mapping application that utilizes output from existing network
12
+ examination tools to populate its OSI\-modeled database. This data can then be
13
+ used to form a ‘picture’ of the network being analyzed.
14
+ .
15
+ .P
16
+ ANTFARM plugins provide an easy way to extend the parsing and outputting of
17
+ data into and out of ANTFARM. Currently available plugins are described below.
18
+ .
19
+ .SH "PLUGINS"
20
+ load\-host:
21
+ .
22
+ .P
23
+ Given a file that contains a list of IP addresses, one per line, this plugin
24
+ simply creates an IpInterface model for each address provided.
25
+ .
26
+ .TP
27
+ \fB\-\-input\-file\fR \fIfile\fR
28
+ The location of the file containing the IP addresses
29
+ .
30
+ .P
31
+ load\-network:
32
+ .
33
+ .P
34
+ Given a file that contains a list of IP networks, one per line, this plugin
35
+ simply creates and IpNetwork model for each network address provided.
36
+ .
37
+ .TP
38
+ \fB\-\-input\-file\fR \fIfile\fR
39
+ The location of the file containing the IP network addresses
40
+ .
41
+ .SH "COPYRIGHT"
42
+ Copyright (2008\-2010) Sandia Corporation. Under the terms of Contract
43
+ DE\-AC04\-94AL85000 with Sandia Corporation, the U.S. Government retains certain
44
+ rights in this software.
45
+ .
46
+ .P
47
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
48
+ this software and associated documentation files (the "Software"), to deal in
49
+ the Software without restriction, including without limitation the rights to
50
+ use, copy, modify, merge, publish, distribute, distribute with modifications,
51
+ sublicense, and/or sell copies of the Software, and to permit persons to whom
52
+ the Software is furnished to do so, subject to the following conditions:
53
+ .
54
+ .P
55
+ The above copyright notice and this permission notice shall be included in all
56
+ copies or substantial portions of the Software.
57
+ .
58
+ .P
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
+ ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
63
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
64
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65
+ .
66
+ .P
67
+ Except as contained in this notice, the name(s) of the above copyright holders
68
+ shall not be used in advertising or otherwise to promote the sale, use or other
69
+ dealings in this Software without prior written authorization.
@@ -0,0 +1,57 @@
1
+ antfarm-plugins(1) -- plugins for the ANTFARM passive network mapping tool
2
+ ==========================================================================
3
+
4
+ ## DESCRIPTION
5
+
6
+ ANTFARM (Advanced Network Toolkit For Assessments and Remote Mapping) is a
7
+ passive network mapping application that utilizes output from existing network
8
+ examination tools to populate its OSI-modeled database. This data can then be
9
+ used to form a ‘picture’ of the network being analyzed.
10
+
11
+ ANTFARM plugins provide an easy way to extend the parsing and outputting of
12
+ data into and out of ANTFARM. Currently available plugins are described below.
13
+
14
+ ## PLUGINS
15
+
16
+ load-host:
17
+
18
+ Given a file that contains a list of IP addresses, one per line, this plugin
19
+ simply creates an IpInterface model for each address provided.
20
+
21
+ * `--input-file` <file>:
22
+ The location of the file containing the IP addresses
23
+
24
+ load-network:
25
+
26
+ Given a file that contains a list of IP networks, one per line, this plugin
27
+ simply creates and IpNetwork model for each network address provided.
28
+
29
+ * `--input-file` <file>:
30
+ The location of the file containing the IP network addresses
31
+
32
+ ## COPYRIGHT
33
+
34
+ Copyright (2008-2010) Sandia Corporation. Under the terms of Contract
35
+ DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain
36
+ rights in this software.
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
39
+ this software and associated documentation files (the "Software"), to deal in
40
+ the Software without restriction, including without limitation the rights to
41
+ use, copy, modify, merge, publish, distribute, distribute with modifications,
42
+ sublicense, and/or sell copies of the Software, and to permit persons to whom
43
+ the Software is furnished to do so, subject to the following conditions:
44
+
45
+ The above copyright notice and this permission notice shall be included in all
46
+ copies or substantial portions of the Software.
47
+
48
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
50
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
51
+ ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
52
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54
+
55
+ Except as contained in this notice, the name(s) of the above copyright holders
56
+ shall not be used in advertising or otherwise to promote the sale, use or other
57
+ dealings in this Software without prior written authorization.