nmap_service_dumper 0.0.0

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: 2ecc804cde0739efec19d78b44bf5cd0db905bc8
4
+ data.tar.gz: 83b63e52138096ce3c1d550023c57290758c76b6
5
+ SHA512:
6
+ metadata.gz: 459d1af48ac6ddb869e880c4842ab035f07088df987e3f31543af5cbd3af758f655ffe47ac9b9be6f9609f2b5395d022b189a28d9803f4b2947bb7867b2e4607
7
+ data.tar.gz: 5f87de0096d54489efb1c07686fa5b42a10e34f1f697da65b49fb15011ac4715b60ff59a9710c599e36b2d6c929399a53a77c4a09b10766c5537ec4de4556e15
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nmap_service_dumper.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 arch4ngel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # NmapServiceDumper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nmap_service_dumper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nmap_service_dumper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nmap_service_dumper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nmap_service_dumper.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,270 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'colorize'
4
+ require 'nokogiri'
5
+ require 'thor'
6
+
7
+ class Product
8
+
9
+ attr_accessor :name, :versions
10
+
11
+ def initialize(name=nil, versions=[])
12
+
13
+ @name = name
14
+ @versions = versions
15
+
16
+ end
17
+
18
+ def to_s()
19
+
20
+ if @name and @versions.length > 0
21
+
22
+ s = @name + "\n#{'-'*@name.bytesize}\n" + @versions.join("\n")
23
+
24
+ elsif @name
25
+
26
+ s = @name + "\n#{'-'*@name.bytesize}\n" + "<NO VERSIONS EXTRACTED>"
27
+
28
+ else
29
+
30
+ s = nil
31
+
32
+ end
33
+
34
+ return s
35
+
36
+ end
37
+
38
+ end
39
+
40
+ class Service
41
+
42
+ attr_accessor :name, :addresses, :portids, :sockets, :products
43
+
44
+ def initialize(name=nil, addresses=[], sockets=[], portids=[], products={})
45
+
46
+ @name = name
47
+ @addresses = addresses
48
+ @portids = portids
49
+ @sockets = sockets
50
+
51
+ # product is the service product, e.g. iis, and versions for that product
52
+ @products = products
53
+
54
+ end
55
+
56
+ def dump()
57
+
58
+ File::open("addresses",'w+') do |file|
59
+ @addresses.each {|a| file.puts(a)}
60
+ end
61
+
62
+ File::open("ports",'w+') do |file|
63
+ file.puts( @portids.join(',') )
64
+ end
65
+
66
+ File::open("sockets",'w+') do |file|
67
+ @sockets.each { |s| file.puts(s) }
68
+ end
69
+
70
+ if @products.length > 0
71
+
72
+ File::open("versions", 'w+') do |file|
73
+ @products.each { |p,v| file.puts(v.to_s + "\n\n") }
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ def extract_address(host)
83
+
84
+ return host.xpath('address')
85
+ .first
86
+ .attributes["addr"]
87
+ .value
88
+
89
+ end
90
+
91
+ def extract_open_ports(host)
92
+
93
+ query = 'ports/port/state[@state="open"]/..'
94
+
95
+ return host.xpath(query)
96
+
97
+ end
98
+
99
+ def extract_service(port)
100
+
101
+ name, product, version = nil, nil, nil
102
+
103
+ vars = ["name", "product", "version"]
104
+
105
+ snode = port.xpath('service[@name]').first
106
+
107
+ if snode
108
+
109
+ vars.map! { |v| v = snode.attributes[v].value if snode.attributes[v] }
110
+
111
+ else
112
+
113
+ return nil
114
+
115
+ end
116
+
117
+ return vars
118
+
119
+ end
120
+
121
+ def process_host(host, services)
122
+
123
+ address = extract_address(host)
124
+
125
+ open_ports = extract_open_ports(host)
126
+
127
+ open_ports.each do |port|
128
+
129
+ portid = port.attributes["portid"].value
130
+ service, product, version = extract_service(port)
131
+ socket = address + ":" + portid
132
+
133
+ if ! services.keys.include?(service)
134
+
135
+ services[service] = Service.new(service)
136
+
137
+ end
138
+
139
+ service = services[service]
140
+
141
+ service.addresses << address
142
+
143
+ if ! service.portids.include?(portid)
144
+ service.portids << portid
145
+ end
146
+
147
+ if ! service.sockets.include?(socket)
148
+ service.sockets << socket
149
+ end
150
+
151
+ if product and ! service.products.keys.include?(product)
152
+
153
+ n_product = Product.new(product)
154
+ n_product.versions << version if version
155
+ service.products[product] = n_product
156
+
157
+ end
158
+
159
+ if version and service.products[product]
160
+
161
+ if ! service.products[product].versions.include?(version)
162
+
163
+ service.products[product].versions << version
164
+
165
+ end
166
+
167
+ end
168
+
169
+ end
170
+
171
+ end
172
+
173
+ class CLI < Thor
174
+
175
+ desc "dump","Parse and dump services from NMAP XML file."
176
+
177
+ option :xml_file, { desc: "Nmap XML File.",
178
+ required: true,
179
+ aliases: ["-x"] }
180
+
181
+ option :output_dir, { desc: "Name of directory to output dump.",
182
+ required: false,
183
+ aliases: ["-o"],
184
+ default: "dumped_services" }
185
+
186
+ def dump()
187
+
188
+ services = {}
189
+ doc = File.open(options[:xml_file]) { |f| Nokogiri::XML(f) }
190
+
191
+ puts
192
+ puts "Service Dumper".green.bold()
193
+
194
+ puts
195
+ print "[+] Processing input file: #{options[:xml_file].bold()} ..."
196
+
197
+ # Extract all host elements
198
+ hosts = doc.xpath('//host')
199
+
200
+ # Process each host element
201
+ hosts.each { |host| process_host(host, services) }
202
+ puts "done!".green()
203
+
204
+ ### Begin dumping to file ###
205
+
206
+ # Create the output directory
207
+ dir = options[:output_dir]
208
+ puts "[+] Writing output to #{dir.bold}"
209
+ Dir::mkdir(dir)# if ! Dir::exist?(dir)
210
+
211
+ # Change to the output directory
212
+ Dir::chdir(dir)
213
+
214
+ # create a file to keep a manifest of service names
215
+ manifest = File::open('service_manifest.txt','w+')
216
+
217
+
218
+ manifest.puts("Brief Service Manifest:\n\n")
219
+ services.each { |sname,service| manifest.puts(sname) }
220
+ manifest.puts("\n\nDetailed Service Manifest:\n\n")
221
+
222
+ # write dump for each service to disk
223
+ services.each do |sname, service|
224
+
225
+ next if !sname
226
+
227
+ manifest.puts(sname)
228
+ manifest.puts("-------------")
229
+
230
+ if service.products.keys.length > 0
231
+
232
+ service.products.each { |name,product| manifest.puts(product.to_s+"\n\n") }
233
+
234
+ else
235
+
236
+ manifest.puts("<NO PRODUCTS EXTRACTED>")
237
+
238
+ end
239
+
240
+ manifest.puts("-------------\n\n")
241
+ manifest.puts("\n\n")
242
+
243
+ # create the directory name
244
+ dname = sname.gsub('-','_')
245
+
246
+ # make a directory for the service
247
+ Dir::mkdir(dname)
248
+
249
+ # change to the service directory
250
+ Dir::chdir(dname)
251
+
252
+ # dump the service details to file
253
+ service.dump
254
+
255
+ # change back to previous directory
256
+ Dir::chdir('..')
257
+
258
+ end
259
+
260
+ # close the manifest file
261
+ manifest.close()
262
+
263
+ puts "[+] Finished!"
264
+ puts
265
+
266
+ end
267
+
268
+ end
269
+
270
+ CLI::start(ARGV)
@@ -0,0 +1 @@
1
+ require "nmap_service_dumper/version"
@@ -0,0 +1,3 @@
1
+ module NmapServiceDumper
2
+ VERSION = "0.0.0"
3
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nmap_service_dumper/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nmap_service_dumper"
8
+ spec.version = NmapServiceDumper::VERSION
9
+ spec.authors = ["arch4ngel"]
10
+ spec.email = ["justinangel86@gmail.com"]
11
+
12
+ spec.summary = %q{Parses an Nmap XML file and dumps a directory structure to disk representing each listening service.}
13
+ spec.homepage = "https://github.com/arch4ngel/nmap_service_dumper"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "bin"
29
+ spec.executables = ["nmap_service_dumper"]
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.15"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_dependency('colorize')
36
+ spec.add_dependency('nokogiri')
37
+ spec.add_dependency('thor')
38
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nmap_service_dumper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - arch4ngel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-07 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
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
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - justinangel86@gmail.com
100
+ executables:
101
+ - nmap_service_dumper
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/nmap_service_dumper
113
+ - lib/nmap_service_dumper.rb
114
+ - lib/nmap_service_dumper/version.rb
115
+ - nmap_service_dumper.gemspec
116
+ homepage: https://github.com/arch4ngel/nmap_service_dumper
117
+ licenses:
118
+ - MIT
119
+ metadata:
120
+ allowed_push_host: https://rubygems.org
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.5.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Parses an Nmap XML file and dumps a directory structure to disk representing
141
+ each listening service.
142
+ test_files: []