ruby-nmap 0.1.1 → 0.2.0

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.
@@ -10,6 +10,9 @@ module Nmap
10
10
  # The arguments used with the scanner
11
11
  attr_reader :arguments
12
12
 
13
+ # The time the scan begun
14
+ attr_reader :start_time
15
+
13
16
  #
14
17
  # Creates a new Scanner object.
15
18
  #
@@ -22,10 +25,14 @@ module Nmap
22
25
  # @param [String] arguments
23
26
  # The arguments used with the scanner.
24
27
  #
25
- def initialize(name,version,arguments)
28
+ # @param [Time] start_time
29
+ # The time the scan begun
30
+ #
31
+ def initialize(name,version,arguments,start_time)
26
32
  @name = name
27
33
  @version = version
28
34
  @arguments = arguments
35
+ @start_time = start_time
29
36
  end
30
37
 
31
38
  #
@@ -2,139 +2,139 @@ require 'rprogram/task'
2
2
 
3
3
  module Nmap
4
4
  #
5
- # == Nmap options:
5
+ # ## Nmap options:
6
6
  #
7
- # === Target Specifications:
7
+ # ### Target Specifications:
8
8
  #
9
- # <tt>-iL</tt>:: <tt>nmap.target_file</tt>
10
- # <tt>-iR</tt>:: <tt>nmap.random_targets</tt>
11
- # <tt>--exclude</tt>:: <tt>nmap.exclude</tt>
12
- # <tt>--excludefile</tt>:: <tt>nmap.exclude_file</tt>
9
+ # * `-iL` - `nmap.target_file`
10
+ # * `-iR` - `nmap.random_targets`
11
+ # * `--exclude` - `nmap.exclude`
12
+ # * `--excludefile` - `nmap.exclude_file`
13
13
  #
14
- # === Host Discovery:
14
+ # ### Host Discovery:
15
15
  #
16
- # <tt>-sL</tt>:: <tt>nmap.list</tt>
17
- # <tt>-sP</tt>:: <tt>nmap.ping</tt>
18
- # <tt>-PN</tt>:: <tt>nmap.skip_discovery</tt>
19
- # <tt>-PS</tt>:: <tt>nmap.syn_discovery</tt>
20
- # <tt>-PA</tt>:: <tt>nmap.ack_discovery</tt>
21
- # <tt>-PU</tt>:: <tt>nmap.udp_discovery</tt>
22
- # <tt>-PE</tt>:: <tt>nmap.icmp_echo_discovery</tt>
23
- # <tt>-PP</tt>:: <tt>nmap.icmp_timestamp_discovery</tt>
24
- # <tt>-PM</tt>:: <tt>nmap.icmp_netmask_discovery</tt>
25
- # <tt>-PO</tt>:: <tt>nmap.ip_ping</tt>
26
- # <tt>-n</tt>:: <tt>nmap.disable_dns</tt>
27
- # <tt>-R</tt>:: <tt>nmap.enable_dns</tt>
28
- # <tt>--dns-servers</tt>:: <tt>nmap.dns_servers</tt>
29
- # <tt>--systems-dns</tt>:: <tt>nmap.systems_dns</tt>
16
+ # * `-sL` - `nmap.list`
17
+ # * `-sP` - `nmap.ping`
18
+ # * `-PN` - `nmap.skip_discovery`
19
+ # * `-PS` - `nmap.syn_discovery`
20
+ # * `-PA` - `nmap.ack_discovery`
21
+ # * `-PU` - `nmap.udp_discovery`
22
+ # * `-PE` - `nmap.icmp_echo_discovery`
23
+ # * `-PP` - `nmap.icmp_timestamp_discovery`
24
+ # * `-PM` - `nmap.icmp_netmask_discovery`
25
+ # * `-PO` - `nmap.ip_ping`
26
+ # * `-n` - `nmap.disable_dns`
27
+ # * `-R` - `nmap.enable_dns`
28
+ # * `--dns-servers` - `nmap.dns_servers`
29
+ # * `--systems-dns` - `nmap.systems_dns`
30
30
  #
31
- # === Scan Techniques:
31
+ # ### Scan Techniques:
32
32
  #
33
- # <tt>-sS</tt>:: <tt>nmap.syn_scan</tt>
34
- # <tt>-sT</tt>:: <tt>nmap.connect_scan</tt>
35
- # <tt>-sA</tt>:: <tt>nmap.ack_scan</tt>
36
- # <tt>-sW</tt>:: <tt>nmap.window_scan</tt>
37
- # <tt>-sM</tt>:: <tt>nmap.maimon_scan</tt>
38
- # <tt>-sU</tt>:: <tt>nmap.udp_scan</tt>
39
- # <tt>-sN</tt>:: <tt>nmap.null_scan</tt>
40
- # <tt>-sF</tt>:: <tt>nmap.fin_scan</tt>
41
- # <tt>-sX</tt>:: <tt>nmap.xmas_scan</tt>
42
- # <tt>--scanflags</tt>:: <tt>nmap.tcp_scan_flags</tt>
43
- # <tt>-sI</tt>:: <tt>nmap.idle_scan</tt>
44
- # <tt>-s0</tt>:: <tt>nmap.ip_scan</tt>
45
- # <tt>-b</tt>:: <tt>nmap.ftp_bounce_scan</tt>
46
- # <tt>--traceroute</tt>:: <tt>nmap.traceroute</tt>
47
- # <tt>--reason</tt>:: <tt>nmap.show_reason</tt>
33
+ # * `-sS` - `nmap.syn_scan`
34
+ # * `-sT` - `nmap.connect_scan`
35
+ # * `-sA` - `nmap.ack_scan`
36
+ # * `-sW` - `nmap.window_scan`
37
+ # * `-sM` - `nmap.maimon_scan`
38
+ # * `-sU` - `nmap.udp_scan`
39
+ # * `-sN` - `nmap.null_scan`
40
+ # * `-sF` - `nmap.fin_scan`
41
+ # * `-sX` - `nmap.xmas_scan`
42
+ # * `--scanflags` - `nmap.tcp_scan_flags`
43
+ # * `-sI` - `nmap.idle_scan`
44
+ # * `-s0` - `nmap.ip_scan`
45
+ # * `-b` - `nmap.ftp_bounce_scan`
46
+ # * `--traceroute` - `nmap.traceroute`
47
+ # * `--reason` - `nmap.show_reason`
48
48
  #
49
- # === Port Specification and Scan Order:
49
+ # ### Port Specification and Scan Order:
50
50
  #
51
- # <tt>-p</tt>:: <tt>nmap.ports</tt>
52
- # <tt>-F</tt>:: <tt>nmap.fast</tt>
53
- # <tt>-r</tt>:: <tt>nmap.consecutively</tt>
54
- # <tt>--top-ports</tt>:: <tt>nmap.top_ports</tt>
55
- # <tt>--port-ratio</tt>:: <tt>nmap.port_ratio</tt>
51
+ # * `-p` - `nmap.ports`
52
+ # * `-F` - `nmap.fast`
53
+ # * `-r` - `nmap.consecutively`
54
+ # * `--top-ports` - `nmap.top_ports`
55
+ # * `--port-ratio` - `nmap.port_ratio`
56
56
  #
57
- # === Service/Version Detection:
57
+ # ### Service/Version Detection:
58
58
  #
59
- # <tt>-sV</tt>:: <tt>nmap.service_scan</tt>
60
- # <tt>--version-intensity</tt>:: <tt>nmap.version_intensity</tt>
61
- # <tt>--version-light</tt>:: <tt>nmap.version_light</tt>
62
- # <tt>--version-all</tt>:: <tt>nmap.version_all</tt>
63
- # <tt>--version-trace</tt>:: <tt>nmap.version_trace</tt>
59
+ # * `-sV` - `nmap.service_scan`
60
+ # * `--version-intensity` - `nmap.version_intensity`
61
+ # * `--version-light` - `nmap.version_light`
62
+ # * `--version-all` - `nmap.version_all`
63
+ # * `--version-trace` - `nmap.version_trace`
64
64
  #
65
- # === Script Scan:
65
+ # ### Script Scan:
66
66
  #
67
- # <tt>-sC</tt>:: <tt>nmap.default_script</tt>
68
- # <tt>--script</tt>:: <tt>nmap.script</tt>
69
- # <tt>--script-args</tt>:: <tt>nmap.script_params</tt>
70
- # <tt>--script-trace</tt>:: <tt>nmap.script_trace</tt>
71
- # <tt>--script-updatedb</tt>:: <tt>nmap.update_scriptdb</tt>
67
+ # * `-sC` - `nmap.default_script`
68
+ # * `--script` - `nmap.script`
69
+ # * `--script-args` - `nmap.script_params`
70
+ # * `--script-trace` - `nmap.script_trace`
71
+ # * `--script-updatedb` - `nmap.update_scriptdb`
72
72
  #
73
- # === OS Detection:
73
+ # ### OS Detection:
74
74
  #
75
- # <tt>-O</tt>:: <tt>nmap.os_fingerprint</tt>
76
- # <tt>--osscan_limit</tt>:: <tt>nmap.limit_os_scan</tt>
77
- # <tt>--osscan_guess</tt>:: <tt>nmap.max_os_scan</tt>
75
+ # * `-O` - `nmap.os_fingerprint`
76
+ # * `--osscan_limit` - `nmap.limit_os_scan`
77
+ # * `--osscan_guess` - `nmap.max_os_scan`
78
78
  #
79
- # === Timing and Performance:
79
+ # ### Timing and Performance:
80
80
  #
81
- # <tt>--min-hostgroup</tt>:: <tt>nmap.min_host_group</tt>
82
- # <tt>--max-hostgroup</tt>:: <tt>nmap.max_host_group</tt>
83
- # <tt>--min-parallelism</tt>:: <tt>nmap.min_parallelism</tt>
84
- # <tt>--max-parallelism</tt>:: <tt>nmap.max_parallelism</tt>
85
- # <tt>--min-rtt-timeout</tt>:: <tt>nmap.min_rtt_timeout</tt>
86
- # <tt>--max-rtt-timeout</tt>:: <tt>nmap.max_rtt_timeout</tt>
87
- # <tt>--max-retries</tt>:: <tt>nmap.max_retries</tt>
88
- # <tt>--host-timeout</tt>:: <tt>nmap.host_timeout</tt>
89
- # <tt>--scan-delay</tt>:: <tt>nmap.scan_delay</tt>
90
- # <tt>--max-scan-delay</tt>:: <tt>nmap.max_scan_delay</tt>
91
- # <tt>--min-rate</tt>:: <tt>nmap.min_rate</tt>
92
- # <tt>--max-rate</tt>:: <tt>nmap.max_rate</tt>
81
+ # * `--min-hostgroup` - `nmap.min_host_group`
82
+ # * `--max-hostgroup` - `nmap.max_host_group`
83
+ # * `--min-parallelism` - `nmap.min_parallelism`
84
+ # * `--max-parallelism` - `nmap.max_parallelism`
85
+ # * `--min-rtt-timeout` - `nmap.min_rtt_timeout`
86
+ # * `--max-rtt-timeout` - `nmap.max_rtt_timeout`
87
+ # * `--max-retries` - `nmap.max_retries`
88
+ # * `--host-timeout` - `nmap.host_timeout`
89
+ # * `--scan-delay` - `nmap.scan_delay`
90
+ # * `--max-scan-delay` - `nmap.max_scan_delay`
91
+ # * `--min-rate` - `nmap.min_rate`
92
+ # * `--max-rate` - `nmap.max_rate`
93
93
  #
94
- # === Firewall/IDS Evasion and Spoofing:
94
+ # ### Firewall/IDS Evasion and Spoofing:
95
95
  #
96
- # <tt>-f</tt>:: <tt>nmap.packet_fragments</tt>
97
- # <tt>--mtu</tt>:: <tt>nmap.mtu</tt>
98
- # <tt>-D</tt>:: <tt>nmap.decoys</tt>
99
- # <tt>-S</tt>:: <tt>nmap.spoof</tt>
100
- # <tt>-e</tt>:: <tt>nmap.interface</tt>
101
- # <tt>-g</tt>:: <tt>nmap.source_port</tt>
102
- # <tt>--data-length</tt>:: <tt>nmap.data_length</tt>
103
- # <tt>--ip-options</tt>:: <tt>nmap.ip_options</tt>
104
- # <tt>--ttl</tt>:: <tt>nmap.ttl</tt>
105
- # <tt>--spoof-mac</tt>:: <tt>nmap.spoof_mac</tt>
106
- # <tt>--badsum</tt>:: <tt>nmap.bad_checksum</tt>
96
+ # * `-f` - `nmap.packet_fragments`
97
+ # * `--mtu` - `nmap.mtu`
98
+ # * `-D` - `nmap.decoys`
99
+ # * `-S` - `nmap.spoof`
100
+ # * `-e` - `nmap.interface`
101
+ # * `-g` - `nmap.source_port`
102
+ # * `--data-length` - `nmap.data_length`
103
+ # * `--ip-options` - `nmap.ip_options`
104
+ # * `--ttl` - `nmap.ttl`
105
+ # * `--spoof-mac` - `nmap.spoof_mac`
106
+ # * `--badsum` - `nmap.bad_checksum`
107
107
  #
108
- # === Output:
108
+ # ### Output:
109
109
  #
110
- # <tt>-oN</tt>:: <tt>nmap.save</tt>
111
- # <tt>-oX</tt>:: <tt>nmap.xml</tt>
112
- # <tt>-oS</tt>:: <tt>nmap.skiddie</tt>
113
- # <tt>-oG</tt>:: <tt>nmap.grepable</tt>
114
- # <tt>-v</tt>:: <tt>nmap.verbose</tt>
115
- # <tt>--open</tt>:: <tt>nmap.show_open_ports</tt>
116
- # <tt>--packet-trace</tt>:: <tt>nmap.show_packets</tt>
117
- # <tt>--iflist</tt>:: <tt>nmap.show_interfaces</tt>
118
- # <tt>--log-errors</tt>:: <tt>nmap.show_log_errors</tt>
119
- # <tt>--append-output</tt>:: <tt>nmap.append</tt>
120
- # <tt>--resume</tt>:: <tt>nmap.resume</tt>
121
- # <tt>--stylesheet</tt>:: <tt>nmap.stylesheet</tt>
122
- # <tt>--webxml</tt>:: <tt>nmap.nmap_stylesheet</tt>
123
- # <tt>--no-stylesheet</tt>:: <tt>nmap.disable_stylesheet</tt>
110
+ # * `-oN` - `nmap.save`
111
+ # * `-oX` - `nmap.xml`
112
+ # * `-oS` - `nmap.skiddie`
113
+ # * `-oG` - `nmap.grepable`
114
+ # * `-v` - `nmap.verbose`
115
+ # * `--open` - `nmap.show_open_ports`
116
+ # * `--packet-trace` - `nmap.show_packets`
117
+ # * `--iflist` - `nmap.show_interfaces`
118
+ # * `--log-errors` - `nmap.show_log_errors`
119
+ # * `--append-output` - `nmap.append`
120
+ # * `--resume` - `nmap.resume`
121
+ # * `--stylesheet` - `nmap.stylesheet`
122
+ # * `--webxml` - `nmap.nmap_stylesheet`
123
+ # * `--no-stylesheet` - `nmap.disable_stylesheet`
124
124
  #
125
- # === Misc:
125
+ # ### Misc:
126
126
  #
127
- # <tt>-6</tt>:: <tt>nmap.ipv6</tt>
128
- # <tt>-A</tt>:: <tt>nmap.all</tt>
129
- # <tt>--datadir</tt>:: <tt>nmap.nmap_datadir</tt>
130
- # <tt>--send-eth</tt>:: <tt>nmap.raw_ethernet</tt>
131
- # <tt>--send-ip</tt>:: <tt>nmap.raw_ip</tt>
132
- # <tt>--privledged</tt>:: <tt>nmap.privledged</tt>
133
- # <tt>--unprivledged</tt>:: <tt>nmap.unprivledged</tt>
134
- # <tt>-V</tt>:: <tt>nmap.version</tt>
135
- # <tt>-h</tt>:: <tt>nmap.help</tt>
127
+ # * `-6` - `nmap.ipv6`
128
+ # * `-A` - `nmap.all`
129
+ # * `--datadir` - `nmap.nmap_datadir`
130
+ # * `--send-eth` - `nmap.raw_ethernet`
131
+ # * `--send-ip` - `nmap.raw_ip`
132
+ # * `--privledged` - `nmap.privledged`
133
+ # * `--unprivledged` - `nmap.unprivledged`
134
+ # * `-V` - `nmap.version`
135
+ # * `-h` - `nmap.help`
136
136
  #
137
- # <tt>target specification</tt>:: <tt>nmap.targets</tt>
137
+ # * `target specification` - `nmap.targets`
138
138
  #
139
139
  # @see http://nmap.org/book/man.html
140
140
  #
@@ -180,7 +180,19 @@ module Nmap
180
180
  long_option :flag => '--reason', :name => :show_reason
181
181
 
182
182
  # PORT SPECIFICATION AND SCAN ORDER:
183
- short_option :flag => '-p', :name => :ports, :separator => ','
183
+ short_option :flag => '-p', :name => :ports do |opt,value|
184
+ unless value.empty?
185
+ [opt.flag, value.map { |port|
186
+ case port
187
+ when Range
188
+ "#{port.first}-#{port.last}"
189
+ else
190
+ port.to_s
191
+ end
192
+ }.join(',')]
193
+ end
194
+ end
195
+
184
196
  short_option :flag => '-F', :name => :fast
185
197
  short_option :flag => '-r', :name => :consecutively
186
198
  long_option :flag => '--top-ports'
@@ -197,8 +209,8 @@ module Nmap
197
209
  short_option :flag => '-sC', :name => :default_script
198
210
  long_option :flag => '--script'
199
211
  long_option :flag => '--script-args',
200
- :name => :script_params,
201
- :separator => ','
212
+ :name => :script_params,
213
+ :separator => ','
202
214
  long_option :flag => '--script-trace'
203
215
  long_option :flag => '--script-updatedb', :name => :update_scriptdb
204
216
 
@@ -1,4 +1,4 @@
1
1
  module Nmap
2
2
  # ruby-nmap version
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
@@ -1,6 +1,7 @@
1
- require 'nmap/host'
2
1
  require 'nmap/scanner'
2
+ require 'nmap/scan_task'
3
3
  require 'nmap/scan'
4
+ require 'nmap/host'
4
5
 
5
6
  require 'nokogiri'
6
7
  require 'enumerator'
@@ -42,7 +43,8 @@ module Nmap
42
43
  @scanner ||= Scanner.new(
43
44
  @doc.root['scanner'],
44
45
  @doc.root['version'],
45
- @doc.root['args']
46
+ @doc.root['args'],
47
+ Time.at(@doc.root['start'].to_i)
46
48
  )
47
49
  end
48
50
 
@@ -63,7 +65,7 @@ module Nmap
63
65
  # The scan information.
64
66
  #
65
67
  def scan_info
66
- @doc.xpath("/nmaprun/scaninfo").map do |scaninfo|
68
+ @doc.xpath('/nmaprun/scaninfo').map do |scaninfo|
67
69
  Scan.new(
68
70
  scaninfo['type'].to_sym,
69
71
  scaninfo['protocol'].to_sym,
@@ -85,7 +87,7 @@ module Nmap
85
87
  # The verbose level.
86
88
  #
87
89
  def verbose
88
- @verbose ||= @doc.at("verbose/@level").inner_text.to_i
90
+ @verbose ||= @doc.at('verbose/@level').inner_text.to_i
89
91
  end
90
92
 
91
93
  #
@@ -95,7 +97,28 @@ module Nmap
95
97
  # The debugging level.
96
98
  #
97
99
  def debugging
98
- @debugging ||= @doc.at("debugging/@level").inner_text.to_i
100
+ @debugging ||= @doc.at('debugging/@level').inner_text.to_i
101
+ end
102
+
103
+ #
104
+ # Parses the tasks of the scan.
105
+ #
106
+ # @return [Array<ScanTask>]
107
+ # The tasks of the scan.
108
+ #
109
+ # @since 0.1.2
110
+ #
111
+ def tasks
112
+ @doc.xpath('/nmaprun/taskbegin').map do |task_begin|
113
+ task_end = task_begin.xpath('following-sibling::taskend').first
114
+
115
+ ScanTask.new(
116
+ task_begin['task'],
117
+ Time.at(task_begin['time'].to_i),
118
+ Time.at(task_end['time'].to_i),
119
+ task_end['extrainfo']
120
+ )
121
+ end
99
122
  end
100
123
 
101
124
  #
@@ -111,7 +134,7 @@ module Nmap
111
134
  # The XML object.
112
135
  #
113
136
  def each_host(&block)
114
- @doc.xpath("/nmaprun/host").each do |host|
137
+ @doc.xpath('/nmaprun/host').each do |host|
115
138
  block.call(Host.new(host)) if block
116
139
  end
117
140
 
@@ -0,0 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ begin
4
+ Ore::Specification.new do |gemspec|
5
+ # custom logic here
6
+ end
7
+ rescue NameError
8
+ STDERR.puts "The 'ruby-nmap.gemspec' file requires Ore."
9
+ STDERR.puts "Run `gem install ore` to install Ore."
10
+ end
@@ -1,9 +1,9 @@
1
- require 'nmap/xml'
2
- require 'nmap/host'
3
-
4
1
  require 'spec_helper'
5
2
  require 'helpers/xml'
6
3
 
4
+ require 'nmap/xml'
5
+ require 'nmap/host'
6
+
7
7
  describe Host do
8
8
  include Helpers
9
9
 
@@ -12,6 +12,15 @@ describe Host do
12
12
  @host = @xml.hosts.first
13
13
  end
14
14
 
15
+ it "should parse the start_time" do
16
+ @host.start_time.should > Time.at(0)
17
+ end
18
+
19
+ it "should parse the end_time" do
20
+ @host.end_time.should > Time.at(0)
21
+ @host.end_time.should > @host.start_time
22
+ end
23
+
15
24
  it "should parse the status" do
16
25
  status = @host.status
17
26
 
@@ -1,7 +1,7 @@
1
- require 'nmap/version'
2
-
3
1
  require 'spec_helper'
4
2
 
3
+ require 'nmap/version'
4
+
5
5
  describe Nmap do
6
6
  it "should have a VERSION constant" do
7
7
  Nmap.const_defined?('VERSION').should == true
@@ -1,10 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'helpers/xml'
3
+
1
4
  require 'nmap/os'
2
5
  require 'nmap/xml'
3
6
  require 'cgi'
4
7
 
5
- require 'spec_helper'
6
- require 'helpers/xml'
7
-
8
8
  describe OS do
9
9
  include Helpers
10
10