ruby-nmap 0.1.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.
@@ -0,0 +1,35 @@
1
+ module Nmap
2
+ class OSMatch
3
+
4
+ # The name of the OS
5
+ attr_reader :name
6
+
7
+ # The accuracy of the OS guess
8
+ attr_reader :accuracy
9
+
10
+ #
11
+ # Creates a OSMatch object.
12
+ #
13
+ # @param [String] name
14
+ # The name of the OS.
15
+ #
16
+ # @param [Integer] accuracy
17
+ # The accuracy of the OS guess.
18
+ #
19
+ def initialize(name,accuracy)
20
+ @name = name
21
+ @accuracy = accuracy
22
+ end
23
+
24
+ #
25
+ # Converts the OS match to a String.
26
+ #
27
+ # @return [String]
28
+ # The String form of the OS match.
29
+ #
30
+ def to_s
31
+ "#{@name} (#{@accuracy}%)"
32
+ end
33
+
34
+ end
35
+ end
data/lib/nmap/port.rb ADDED
@@ -0,0 +1,66 @@
1
+ module Nmap
2
+ class Port
3
+
4
+ # The protocol the port runs on
5
+ attr_reader :protocol
6
+
7
+ # The port number
8
+ attr_reader :number
9
+
10
+ # The state of the port
11
+ attr_reader :state
12
+
13
+ # The reason the port was discovered
14
+ attr_reader :reason
15
+
16
+ # The service the port provides
17
+ attr_reader :service
18
+
19
+ #
20
+ # Creates a new Port object.
21
+ #
22
+ # @param [Integer] protocol
23
+ # The protocol the port runs on.
24
+ #
25
+ # @param [Integer] number
26
+ # The port number.
27
+ #
28
+ # @param [Symbol] state
29
+ # The state the port is in.
30
+ #
31
+ # @param [String] reason
32
+ # The reason for the ports state.
33
+ #
34
+ # @param [String] service
35
+ # The name of the service that runs on the port.
36
+ #
37
+ def initialize(protocol,number,state,reason,service=nil)
38
+ @protocol = protocol
39
+ @number = number
40
+ @state = state
41
+ @reason = reason
42
+ @service = service
43
+ end
44
+
45
+ #
46
+ # Converts the port to an Integer.
47
+ #
48
+ # @return [Integer]
49
+ # The port number.
50
+ #
51
+ def to_i
52
+ @number.to_i
53
+ end
54
+
55
+ #
56
+ # Converts the port to a String.
57
+ #
58
+ # @return [String]
59
+ # The port number.
60
+ #
61
+ def to_s
62
+ @number.to_s
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,65 @@
1
+ require 'nmap/task'
2
+
3
+ require 'rprogram/program'
4
+
5
+ module Nmap
6
+ class Program < RProgram::Program
7
+
8
+ name_program 'nmap'
9
+
10
+ #
11
+ # Finds the +nmap+ program and performs a scan.
12
+ #
13
+ # @param [Hash{Symbol => Object}] options
14
+ # Additional options for nmap.
15
+ #
16
+ # @yield [task]
17
+ # If a block is given, it will be passed a task object
18
+ # used to specify options for nmap.
19
+ #
20
+ # @yieldparam [Task] task
21
+ # The nmap task object.
22
+ #
23
+ # @return [Boolean]
24
+ # Specifies whether the command exited normally.
25
+ #
26
+ # @example Specifying Nmap options via a Hash.
27
+ # Nmap::Program.scan(
28
+ # :targets => '192.168.1.1',
29
+ # :ports => [22,80,443],
30
+ # :verbose => true
31
+ # )
32
+ #
33
+ # @example Specifying Nmap options via a {Task} object.
34
+ # Nmap::Program.scan do |nmap|
35
+ # nmap.targets = '192.168.1.1'
36
+ # nmap.ports = [22,80,443]
37
+ # nmap.verbose = true
38
+ # end
39
+ #
40
+ def self.scan(options={},&block)
41
+ self.find.scan(options,&block)
42
+ end
43
+
44
+ #
45
+ # Performs a scan.
46
+ #
47
+ # @param [Hash{Symbol => Object}] options
48
+ # Additional options for nmap.
49
+ #
50
+ # @yield [task]
51
+ # If a block is given, it will be passed a task object
52
+ # used to specify options for nmap.
53
+ #
54
+ # @yieldparam [Task] task
55
+ # The nmap task object.
56
+ #
57
+ # @return [Boolean]
58
+ # Specifies whether the command exited normally.
59
+ #
60
+ def scan(options={},&block)
61
+ run_task(Task.new(options,&block))
62
+ end
63
+
64
+ end
65
+ end
data/lib/nmap/scan.rb ADDED
@@ -0,0 +1,42 @@
1
+ module Nmap
2
+ class Scan
3
+
4
+ # The type of scan
5
+ attr_reader :type
6
+
7
+ # The protocol used for the scan
8
+ attr_reader :protocol
9
+
10
+ # The port numbers that were scanned
11
+ attr_reader :services
12
+
13
+ #
14
+ # Creates a new Scan object.
15
+ #
16
+ # @param [Symbol] type
17
+ # The type of the scan.
18
+ #
19
+ # @param [Symbol] protocol
20
+ # The protocol used for the scan.
21
+ #
22
+ # @param [Array<Integer, Rage>] services
23
+ # The port numbers scanned.
24
+ #
25
+ def initialize(type,protocol,services=[])
26
+ @type = type
27
+ @protocol = protocol
28
+ @services = services
29
+ end
30
+
31
+ #
32
+ # Converts the scan to a String.
33
+ #
34
+ # @return [String]
35
+ # The String form of the scan.
36
+ #
37
+ def to_s
38
+ "#{@protocol} #{@type}"
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ module Nmap
2
+ class Scanner
3
+
4
+ # The name of the scanner
5
+ attr_reader :name
6
+
7
+ # The version of the scanner
8
+ attr_reader :version
9
+
10
+ # The arguments used with the scanner
11
+ attr_reader :arguments
12
+
13
+ #
14
+ # Creates a new Scanner object.
15
+ #
16
+ # @param [String] name
17
+ # The name of the scanner.
18
+ #
19
+ # @param [String] version
20
+ # The version of the scanner.
21
+ #
22
+ # @param [String] arguments
23
+ # The arguments used with the scanner.
24
+ #
25
+ def initialize(name,version,arguments)
26
+ @name = name
27
+ @version = version
28
+ @arguments = arguments
29
+ end
30
+
31
+ #
32
+ # Converts the scanner to a String.
33
+ #
34
+ # @return [String]
35
+ # The scanner name and arguments.
36
+ #
37
+ def to_s
38
+ "#{@name} #{@arguments}"
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ module Nmap
2
+ class Status
3
+
4
+ # The state of a host
5
+ attr_reader :state
6
+
7
+ # The reason for the state
8
+ attr_reader :reason
9
+
10
+ #
11
+ # Creates a new Status object.
12
+ #
13
+ # @param [Symbol] state
14
+ # The state of a host.
15
+ #
16
+ # @param [String] reason
17
+ # The reason for the state.
18
+ #
19
+ def initialize(state,reason)
20
+ @state = state
21
+ @reason = reason
22
+ end
23
+
24
+ #
25
+ # Converts the status to a String.
26
+ #
27
+ # @return [String]
28
+ # The state.
29
+ #
30
+ def to_s
31
+ @state.to_s
32
+ end
33
+
34
+ end
35
+ end
data/lib/nmap/task.rb ADDED
@@ -0,0 +1,267 @@
1
+ require 'rprogram/task'
2
+
3
+ module Nmap
4
+ #
5
+ # == Nmap options:
6
+ #
7
+ # === Target Specifications:
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>
13
+ #
14
+ # === Host Discovery:
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>
30
+ #
31
+ # === Scan Techniques:
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>
48
+ #
49
+ # === Port Specification and Scan Order:
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>
56
+ #
57
+ # === Service/Version Detection:
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>
64
+ #
65
+ # === Script Scan:
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>
72
+ #
73
+ # === OS Detection:
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>
78
+ #
79
+ # === Timing and Performance:
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>
93
+ #
94
+ # === Firewall/IDS Evasion and Spoofing:
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>
107
+ #
108
+ # === Output:
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>
124
+ #
125
+ # === Misc:
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>
136
+ #
137
+ # <tt>target specification</tt>:: <tt>nmap.targets</tt>
138
+ #
139
+ # @see http://nmap.org/book/man.html
140
+ #
141
+ class Task < RProgram::Task
142
+
143
+ # TARGET SPECIFICATIONS:
144
+ short_option :flag => '-iL', :name => :target_file
145
+ short_option :flag => '-iR', :name => :random_targets
146
+ long_option :flag => '--exclude', :name => :exclude, :separator => ','
147
+ long_option :flag => '--excludefile', :name => :exclude_file
148
+
149
+ # HOST DISCOVERY:
150
+ short_option :flag => '-sL', :name => :list
151
+ short_option :flag => '-sP', :name => :ping
152
+ short_option :flag => '-PN', :name => :skip_discovery
153
+ short_option :flag => '-PS', :name => :syn_discovery
154
+ short_option :flag => '-PA', :name => :ack_discovery
155
+ short_option :flag => '-PU', :name => :udp_discovery
156
+ short_option :flag => '-PE', :name => :icmp_echo_discovery
157
+ short_option :flag => '-PP', :name => :icmp_timestamp_discovery
158
+ short_option :flag => '-PM', :name => :icmp_netmask_discovery
159
+ short_option :flag => '-PO', :name => :ip_ping
160
+ short_option :flag => '-n', :name => :disable_dns
161
+ short_option :flag => '-R', :name => :enable_dns
162
+ long_option :flag => '--dns-servers', :separator => ','
163
+ long_option :flag => '--system-dns'
164
+
165
+ # SCAN TECHNIQUES:
166
+ short_option :flag => '-sS', :name => :syn_scan
167
+ short_option :flag => '-sT', :name => :connect_scan
168
+ short_option :flag => '-sA', :name => :ack_scan
169
+ short_option :flag => '-sW', :name => :window_scan
170
+ short_option :flag => '-sM', :name => :maimon_scan
171
+ short_option :flag => '-sU', :name => :udp_scan
172
+ short_option :flag => '-sN', :name => :null_scan
173
+ short_option :flag => '-sF', :name => :fin_scan
174
+ short_option :flag => '-sX', :name => :xmas_scan
175
+ long_option :flag => '--scanflags', :name => :tcp_scan_flags
176
+ short_option :flag => '-sI', :name => :idle_scan
177
+ short_option :flag => '-s0', :name => :ip_scan
178
+ short_option :flag => '-b', :name => :ftp_bounce_scan
179
+ long_option :flag => '--traceroute', :name => :traceroute
180
+ long_option :flag => '--reason', :name => :show_reason
181
+
182
+ # PORT SPECIFICATION AND SCAN ORDER:
183
+ short_option :flag => '-p', :name => :ports, :separator => ','
184
+ short_option :flag => '-F', :name => :fast
185
+ short_option :flag => '-r', :name => :consecutively
186
+ long_option :flag => '--top-ports'
187
+ long_option :flag => '--port-ratio'
188
+
189
+ # SERVICE/VERSION DETECTION:
190
+ short_option :flag => '-sV', :name => :service_scan
191
+ long_option :flag => '--version-intensity'
192
+ long_option :flag => '--version-light'
193
+ long_option :flag => '--version-all'
194
+ long_option :flag => '--version-trace'
195
+
196
+ # SCRIPT SCAN:
197
+ short_option :flag => '-sC', :name => :default_script
198
+ long_option :flag => '--script'
199
+ long_option :flag => '--script-args',
200
+ :name => :script_params,
201
+ :separator => ','
202
+ long_option :flag => '--script-trace'
203
+ long_option :flag => '--script-updatedb', :name => :update_scriptdb
204
+
205
+ # OS DETECTION:
206
+ short_option :flag => '-O', :name => :os_fingerprint
207
+ long_option :flag => '--osscan_limit', :name => :limit_os_scan
208
+ long_option :flag => '--osscan_guess', :name => :max_os_scan
209
+
210
+ # TIMING AND PERFORMANCE:
211
+ long_option :flag => '--min-hostgroup', :name => :min_host_group
212
+ long_option :flag => '--max-hostgroup', :name => :max_host_group
213
+ long_option :flag => '--min-parallelism'
214
+ long_option :flag => '--max-parallelism'
215
+ long_option :flag => '--min-rtt-timeout'
216
+ long_option :flag => '--max-rtt-timeout'
217
+ long_option :flag => '--max-retries'
218
+ long_option :flag => '--host-timeout'
219
+ long_option :flag => '--scan-delay'
220
+ long_option :flag => '--max-scan-delay'
221
+ long_option :flag => '--min-rate'
222
+ long_option :flag => '--max-rate'
223
+
224
+ # FIREWALL/IDS EVASION AND SPOOFING:
225
+ short_option :flag => '-f', :name => :packet_fragments
226
+ long_option :flag => '--mtu'
227
+ short_option :flag => '-D', :name => :decoys, :separator => ','
228
+ short_option :flag => '-S', :name => :spoof
229
+ short_option :flag => '-e', :name => :interface
230
+ short_option :flag => '-g', :name => :source_port
231
+ long_option :flag => '--data-length'
232
+ long_option :flag => '--ip-options'
233
+ long_option :flag => '--ttl'
234
+ long_option :flag => '--spoof-mac'
235
+ long_option :flag => '--badsum', :name => :bad_checksum
236
+
237
+ # OUTPUT:
238
+ short_option :flag => '-oN', :name => :save
239
+ short_option :flag => '-oX', :name => :xml
240
+ short_option :flag => '-oS', :name => :skiddie
241
+ short_option :flag => '-oG', :name => :grepable
242
+ short_option :flag => '-v', :name => :verbose
243
+ long_option :flag => '--open', :name => :show_open_ports
244
+ long_option :flag => '--packet-trace', :name => :show_packets
245
+ long_option :flag => '--iflist', :name => :show_interfaces
246
+ long_option :flag => '--log-errors', :name => :show_log_errors
247
+ long_option :flag => '--append-output', :name => :append
248
+ long_option :flag => '--resume'
249
+ long_option :flag => '--stylesheet'
250
+ long_option :flag => '--webxml', :name => :nmap_stylesheet
251
+ long_option :flag => '--no-stylesheet', :name => :disable_stylesheet
252
+
253
+ # MISC:
254
+ short_option :flag => '-6', :name => :ipv6
255
+ short_option :flag => '-A', :name => :all
256
+ long_option :flag => '--datadir', :name => :nmap_datadir
257
+ long_option :flag => '--send-eth', :name => :raw_ethernet
258
+ long_option :flag => '--send-ip', :name => :raw_ip
259
+ long_option :flag => '--privledged'
260
+ long_option :flag => '--unprivleged'
261
+ short_option :flag => '-V', :name => :version
262
+ short_option :flag => '-h', :name => :help
263
+
264
+ non_option :tailing => true, :name => :targets
265
+
266
+ end
267
+ end
@@ -0,0 +1,4 @@
1
+ module Nmap
2
+ # ruby-nmap version
3
+ VERSION = '0.1.0'
4
+ end