firescan 0.07
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.
- data/LICENSE.txt +202 -0
- data/README.txt +37 -0
- data/USAGE.txt +43 -0
- data/VERSION.txt +4 -0
- data/bin/firescan +4 -0
- data/build +7 -0
- data/doc/Example.html +224 -0
- data/doc/Firebind.html +213 -0
- data/doc/Firebind/Client.html +750 -0
- data/doc/Firebind/Portspec.html +390 -0
- data/doc/Firebind/Scan.html +413 -0
- data/doc/Firebind/ScanError.html +277 -0
- data/doc/Firebind/ScanState.html +1015 -0
- data/doc/Firebind/SimpleProtocol.html +292 -0
- data/doc/Firebind/TcpTransport.html +481 -0
- data/doc/Firebind/Transport.html +275 -0
- data/doc/Firebind/UdpTransport.html +472 -0
- data/doc/LICENSE_txt.html +323 -0
- data/doc/README_txt.html +171 -0
- data/doc/Runner.html +166 -0
- data/doc/TestPortspec.html +289 -0
- data/doc/Tools.html +321 -0
- data/doc/USAGE_txt.html +184 -0
- data/doc/VERSION_txt.html +126 -0
- data/doc/build.html +125 -0
- data/doc/created.rid +22 -0
- data/doc/doc/created_rid.html +121 -0
- data/doc/firescan_gemspec.html +140 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +118 -0
- data/doc/js/darkfish.js +155 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +595 -0
- data/doc/table_of_contents.html +230 -0
- data/firescan.gemspec +18 -0
- data/lib/example.rb +20 -0
- data/lib/firebind/client.rb +308 -0
- data/lib/firebind/portspec.rb +107 -0
- data/lib/firebind/scan.rb +288 -0
- data/lib/firebind/scan_error.rb +32 -0
- data/lib/firebind/scan_state.rb +140 -0
- data/lib/firebind/simple_protocol.rb +59 -0
- data/lib/firebind/tcp_transport.rb +184 -0
- data/lib/firebind/tools.rb +107 -0
- data/lib/firebind/transport.rb +44 -0
- data/lib/firebind/udp_transport.rb +174 -0
- data/test/portspec_test.rb +53 -0
- data/test/runner.rb +7 -0
- metadata +136 -0
@@ -0,0 +1,230 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
6
|
+
|
7
|
+
<title>Table of Contents - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
|
10
|
+
|
11
|
+
<script type="text/javascript">
|
12
|
+
var rdoc_rel_prefix = "./";
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
|
16
|
+
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
|
17
|
+
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
|
18
|
+
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
|
19
|
+
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
|
20
|
+
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
|
21
|
+
|
22
|
+
|
23
|
+
<body class="indexpage">
|
24
|
+
<h1>Table of Contents - RDoc Documentation</h1>
|
25
|
+
|
26
|
+
<h2>Pages</h2>
|
27
|
+
<ul>
|
28
|
+
<li class="file">
|
29
|
+
<a href="LICENSE_txt.html">LICENSE</a>
|
30
|
+
</li>
|
31
|
+
<li class="file">
|
32
|
+
<a href="README_txt.html">README</a>
|
33
|
+
|
34
|
+
<img class="toc-toggle" src="images/transparent.png" alt="" title="toggle headings">
|
35
|
+
<ul class="initially-hidden">
|
36
|
+
<li><a href="README_txt.html#label-"></a>
|
37
|
+
<li><a href="README_txt.html#label-"></a>
|
38
|
+
</ul>
|
39
|
+
</li>
|
40
|
+
<li class="file">
|
41
|
+
<a href="USAGE_txt.html">USAGE</a>
|
42
|
+
|
43
|
+
<img class="toc-toggle" src="images/transparent.png" alt="" title="toggle headings">
|
44
|
+
<ul class="initially-hidden">
|
45
|
+
<li><a href="USAGE_txt.html#label-Synopsis">Synopsis</a>
|
46
|
+
<li><a href="USAGE_txt.html#label-Examples">Examples</a>
|
47
|
+
<li><a href="USAGE_txt.html#label-Usage">Usage</a>
|
48
|
+
<li><a href="USAGE_txt.html#label-Options">Options</a>
|
49
|
+
<li><a href="USAGE_txt.html#label-Author">Author</a>
|
50
|
+
<li><a href="USAGE_txt.html#label-Copyright">Copyright</a>
|
51
|
+
</ul>
|
52
|
+
</li>
|
53
|
+
<li class="file">
|
54
|
+
<a href="VERSION_txt.html">VERSION</a>
|
55
|
+
</li>
|
56
|
+
<li class="file">
|
57
|
+
<a href="build.html">build</a>
|
58
|
+
</li>
|
59
|
+
<li class="file">
|
60
|
+
<a href="doc/created_rid.html">created.rid</a>
|
61
|
+
</li>
|
62
|
+
<li class="file">
|
63
|
+
<a href="firescan_gemspec.html">firescan.gemspec</a>
|
64
|
+
</li>
|
65
|
+
|
66
|
+
</ul>
|
67
|
+
|
68
|
+
<h2 id="classes">Classes/Modules</h2>
|
69
|
+
<ul>
|
70
|
+
<li class="class">
|
71
|
+
<a href="Example.html">Example</a>
|
72
|
+
</li>
|
73
|
+
<li class="module">
|
74
|
+
<a href="Firebind.html">Firebind</a>
|
75
|
+
</li>
|
76
|
+
<li class="class">
|
77
|
+
<a href="Firebind/Client.html">Firebind::Client</a>
|
78
|
+
</li>
|
79
|
+
<li class="class">
|
80
|
+
<a href="Firebind/Portspec.html">Firebind::Portspec</a>
|
81
|
+
</li>
|
82
|
+
<li class="class">
|
83
|
+
<a href="Firebind/Scan.html">Firebind::Scan</a>
|
84
|
+
</li>
|
85
|
+
<li class="class">
|
86
|
+
<a href="Firebind/ScanError.html">Firebind::ScanError</a>
|
87
|
+
</li>
|
88
|
+
<li class="class">
|
89
|
+
<a href="Firebind/ScanState.html">Firebind::ScanState</a>
|
90
|
+
</li>
|
91
|
+
<li class="class">
|
92
|
+
<a href="Firebind/SimpleProtocol.html">Firebind::SimpleProtocol</a>
|
93
|
+
</li>
|
94
|
+
<li class="class">
|
95
|
+
<a href="Firebind/TcpTransport.html">Firebind::TcpTransport</a>
|
96
|
+
</li>
|
97
|
+
<li class="class">
|
98
|
+
<a href="Firebind/Transport.html">Firebind::Transport</a>
|
99
|
+
</li>
|
100
|
+
<li class="class">
|
101
|
+
<a href="Firebind/UdpTransport.html">Firebind::UdpTransport</a>
|
102
|
+
</li>
|
103
|
+
<li class="class">
|
104
|
+
<a href="Runner.html">Runner</a>
|
105
|
+
</li>
|
106
|
+
<li class="class">
|
107
|
+
<a href="TestPortspec.html">TestPortspec</a>
|
108
|
+
</li>
|
109
|
+
<li class="module">
|
110
|
+
<a href="Tools.html">Tools</a>
|
111
|
+
</li>
|
112
|
+
|
113
|
+
</ul>
|
114
|
+
|
115
|
+
<h2 id="methods">Methods</h2>
|
116
|
+
<ul>
|
117
|
+
|
118
|
+
<li class="method"><a href="Firebind/TcpTransport.html#method-c-new">::new — Firebind::TcpTransport</a>
|
119
|
+
|
120
|
+
<li class="method"><a href="Firebind/Client.html#method-c-new">::new — Firebind::Client</a>
|
121
|
+
|
122
|
+
<li class="method"><a href="Firebind/SimpleProtocol.html#method-c-new">::new — Firebind::SimpleProtocol</a>
|
123
|
+
|
124
|
+
<li class="method"><a href="Firebind/ScanState.html#method-c-new">::new — Firebind::ScanState</a>
|
125
|
+
|
126
|
+
<li class="method"><a href="Firebind/ScanError.html#method-c-new">::new — Firebind::ScanError</a>
|
127
|
+
|
128
|
+
<li class="method"><a href="Firebind/Transport.html#method-c-new">::new — Firebind::Transport</a>
|
129
|
+
|
130
|
+
<li class="method"><a href="Firebind/Portspec.html#method-c-new">::new — Firebind::Portspec</a>
|
131
|
+
|
132
|
+
<li class="method"><a href="Firebind/UdpTransport.html#method-c-new">::new — Firebind::UdpTransport</a>
|
133
|
+
|
134
|
+
<li class="method"><a href="Firebind/Scan.html#method-c-new">::new — Firebind::Scan</a>
|
135
|
+
|
136
|
+
<li class="method"><a href="Firebind/Client.html#method-i-arguments_valid-3F">#arguments_valid? — Firebind::Client</a>
|
137
|
+
|
138
|
+
<li class="method"><a href="Tools.html#method-i-big_endian">#big_endian — Tools</a>
|
139
|
+
|
140
|
+
<li class="method"><a href="Firebind/Transport.html#method-i-close">#close — Firebind::Transport</a>
|
141
|
+
|
142
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-closed_ports">#closed_ports — Firebind::ScanState</a>
|
143
|
+
|
144
|
+
<li class="method"><a href="Firebind/TcpTransport.html#method-i-connect">#connect — Firebind::TcpTransport</a>
|
145
|
+
|
146
|
+
<li class="method"><a href="Firebind/UdpTransport.html#method-i-connect">#connect — Firebind::UdpTransport</a>
|
147
|
+
|
148
|
+
<li class="method"><a href="Tools.html#method-i-debug">#debug — Tools</a>
|
149
|
+
|
150
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-description">#description — Firebind::ScanState</a>
|
151
|
+
|
152
|
+
<li class="method"><a href="Firebind/Client.html#method-i-do_output">#do_output — Firebind::Client</a>
|
153
|
+
|
154
|
+
<li class="method"><a href="Firebind/Client.html#method-i-do_scan_output">#do_scan_output — Firebind::Client</a>
|
155
|
+
|
156
|
+
<li class="method"><a href="Firebind/SimpleProtocol.html#method-i-echo">#echo — Firebind::SimpleProtocol</a>
|
157
|
+
|
158
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-on_error">#on_error — Firebind::ScanState</a>
|
159
|
+
|
160
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-on_port_complete">#on_port_complete — Firebind::ScanState</a>
|
161
|
+
|
162
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-on_port_start">#on_port_start — Firebind::ScanState</a>
|
163
|
+
|
164
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-on_port_tick">#on_port_tick — Firebind::ScanState</a>
|
165
|
+
|
166
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-on_scan_complete">#on_scan_complete — Firebind::ScanState</a>
|
167
|
+
|
168
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-on_scan_start">#on_scan_start — Firebind::ScanState</a>
|
169
|
+
|
170
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-on_scan_stop">#on_scan_stop — Firebind::ScanState</a>
|
171
|
+
|
172
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-on_start_failure">#on_start_failure — Firebind::ScanState</a>
|
173
|
+
|
174
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-open_ports">#open_ports — Firebind::ScanState</a>
|
175
|
+
|
176
|
+
<li class="method"><a href="Tools.html#method-i-out">#out — Tools</a>
|
177
|
+
|
178
|
+
<li class="method"><a href="Firebind/Client.html#method-i-output_options">#output_options — Firebind::Client</a>
|
179
|
+
|
180
|
+
<li class="method"><a href="Firebind/Client.html#method-i-parsed_options-3F">#parsed_options? — Firebind::Client</a>
|
181
|
+
|
182
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-percent_complete">#percent_complete — Firebind::ScanState</a>
|
183
|
+
|
184
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-port_delay_seconds">#port_delay_seconds — Firebind::ScanState</a>
|
185
|
+
|
186
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-port_duration">#port_duration — Firebind::ScanState</a>
|
187
|
+
|
188
|
+
<li class="method"><a href="Firebind/UdpTransport.html#method-i-receive">#receive — Firebind::UdpTransport</a>
|
189
|
+
|
190
|
+
<li class="method"><a href="Firebind/TcpTransport.html#method-i-receive">#receive — Firebind::TcpTransport</a>
|
191
|
+
|
192
|
+
<li class="method"><a href="Firebind/Client.html#method-i-run">#run — Firebind::Client</a>
|
193
|
+
|
194
|
+
<li class="method"><a href="Firebind/Scan.html#method-i-scan">#scan — Firebind::Scan</a>
|
195
|
+
|
196
|
+
<li class="method"><a href="Firebind/TcpTransport.html#method-i-send">#send — Firebind::TcpTransport</a>
|
197
|
+
|
198
|
+
<li class="method"><a href="Firebind/UdpTransport.html#method-i-send">#send — Firebind::UdpTransport</a>
|
199
|
+
|
200
|
+
<li class="method"><a href="TestPortspec.html#method-i-setup">#setup — TestPortspec</a>
|
201
|
+
|
202
|
+
<li class="method"><a href="Firebind/Portspec.html#method-i-size">#size — Firebind::Portspec</a>
|
203
|
+
|
204
|
+
<li class="method"><a href="Firebind/Scan.html#method-i-stop">#stop — Firebind::Scan</a>
|
205
|
+
|
206
|
+
<li class="method"><a href="TestPortspec.html#method-i-teardown">#teardown — TestPortspec</a>
|
207
|
+
|
208
|
+
<li class="method"><a href="TestPortspec.html#method-i-test_fail">#test_fail — TestPortspec</a>
|
209
|
+
|
210
|
+
<li class="method"><a href="Firebind/ScanState.html#method-i-to_s">#to_s — Firebind::ScanState</a>
|
211
|
+
|
212
|
+
<li class="method"><a href="Firebind/Portspec.html#method-i-to_s">#to_s — Firebind::Portspec</a>
|
213
|
+
|
214
|
+
<li class="method"><a href="Firebind/ScanError.html#method-i-to_s">#to_s — Firebind::ScanError</a>
|
215
|
+
|
216
|
+
<li class="method"><a href="Firebind/Client.html#method-i-update">#update — Firebind::Client</a>
|
217
|
+
|
218
|
+
<li class="method"><a href="Example.html#method-i-update">#update — Example</a>
|
219
|
+
|
220
|
+
<li class="method"><a href="Tools.html#method-i-verbose">#verbose — Tools</a>
|
221
|
+
|
222
|
+
</ul>
|
223
|
+
|
224
|
+
|
225
|
+
<footer id="validator-badges">
|
226
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
227
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.1.
|
228
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
229
|
+
</footer>
|
230
|
+
|
data/firescan.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'firescan'
|
4
|
+
s.summary = 'Perform network path scanning'
|
5
|
+
s.description = File.read(File.join(File.dirname(__FILE__), 'README.txt'))
|
6
|
+
s.requirements = 'none'
|
7
|
+
s.version = '0.07'
|
8
|
+
s.author = 'Jay Houghton'
|
9
|
+
s.email = 'jay@firebind.com'
|
10
|
+
s.homepage = 'http://www.firebind.com'
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.required_ruby_version = '>=1.9'
|
13
|
+
s.files = Dir['**/**']
|
14
|
+
s.executables = ['firescan']
|
15
|
+
s.test_files = Dir['test/test*.rb']
|
16
|
+
s.has_rdoc = false
|
17
|
+
|
18
|
+
end
|
data/lib/example.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'firebind/scan'
|
2
|
+
|
3
|
+
class Example
|
4
|
+
def update(state)
|
5
|
+
case state.current_state
|
6
|
+
when :PORT_COMPLETE
|
7
|
+
puts "#{state.transport} port #{state.port} #{state.description(state.port_result_code)}"
|
8
|
+
when :PORT_START
|
9
|
+
when :PORT_TICK
|
10
|
+
when :SCAN_START
|
11
|
+
when :START_FAILURE
|
12
|
+
when :SCAN_COMPLETE
|
13
|
+
else
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
scan = Firebind::Scan.new('scanme.firebind.com','1-10',:UDP)
|
19
|
+
scan.add_observer Example.new
|
20
|
+
state = scan.scan
|
@@ -0,0 +1,308 @@
|
|
1
|
+
# Firebind -- Path Scan Client Software
|
2
|
+
# Copyright (C) 2013 Firebind Inc. All rights reserved.
|
3
|
+
# Authors - Jay Houghton
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
7
|
+
# the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require 'optparse'
|
18
|
+
require 'ostruct'
|
19
|
+
require 'date'
|
20
|
+
require 'pp'
|
21
|
+
require_relative 'scan'
|
22
|
+
require_relative 'tools'
|
23
|
+
|
24
|
+
module Firebind
|
25
|
+
|
26
|
+
# Firescan command line Ruby client for path scanning to a Firebind server
|
27
|
+
class Client
|
28
|
+
include Tools
|
29
|
+
VERSION = '0.07'
|
30
|
+
|
31
|
+
attr_reader :options
|
32
|
+
|
33
|
+
def initialize(arguments)
|
34
|
+
@arguments = arguments
|
35
|
+
|
36
|
+
@opts = NIL
|
37
|
+
# Set defaults
|
38
|
+
@options = OpenStruct.new
|
39
|
+
@options.username = NIL
|
40
|
+
@options.password = NIL
|
41
|
+
@options.command_server = 'scanme.firebind.com'
|
42
|
+
@options.protocol = :Simple
|
43
|
+
@options.transport = :TCP
|
44
|
+
@options.timeout = 5000
|
45
|
+
@options.tcp_port_list = NIL
|
46
|
+
@options.udp_port_list = NIL
|
47
|
+
@options.local_address = NIL
|
48
|
+
@options.tag = NIL
|
49
|
+
end
|
50
|
+
|
51
|
+
# Parse options, check arguments, then process the command
|
52
|
+
def run
|
53
|
+
scan = NIL
|
54
|
+
begin
|
55
|
+
|
56
|
+
if parsed_options? && arguments_valid?
|
57
|
+
puts ''
|
58
|
+
verbose "Start at #{DateTime.now}"
|
59
|
+
puts "Firescan Ruby client version #{VERSION} ( http://www.firebind.com )"
|
60
|
+
#############
|
61
|
+
# TCP scan
|
62
|
+
#############
|
63
|
+
unless @options.tcp_port_list.nil?
|
64
|
+
|
65
|
+
debug "performing scan on TCP #{@options.tcp_port_list} via #{@options.command_server}"
|
66
|
+
|
67
|
+
scan = Scan.new(@options.command_server,
|
68
|
+
@options.tcp_port_list,
|
69
|
+
:TCP,
|
70
|
+
@options.timeout,
|
71
|
+
:SimpleProtocol,
|
72
|
+
@options.username,
|
73
|
+
@options.password)
|
74
|
+
|
75
|
+
scan.add_observer self
|
76
|
+
begin
|
77
|
+
@tcp_scan = scan.scan
|
78
|
+
|
79
|
+
debug "scan state: #{@tcp_scan.to_s}"
|
80
|
+
rescue Errno::EHOSTUNREACH
|
81
|
+
puts 'host not reachable'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
#############
|
86
|
+
# UDP scan
|
87
|
+
#############
|
88
|
+
unless @options.udp_port_list.nil?
|
89
|
+
|
90
|
+
debug "performing scan on UDP #{@options.udp_port_list} via #{@options.command_server}"
|
91
|
+
|
92
|
+
scan = Scan.new(@options.command_server,
|
93
|
+
@options.udp_port_list,
|
94
|
+
:UDP,
|
95
|
+
@options.timeout,
|
96
|
+
:SimpleProtocol,
|
97
|
+
@options.username,
|
98
|
+
@options.password)
|
99
|
+
|
100
|
+
scan.add_observer self
|
101
|
+
puts ''
|
102
|
+
begin
|
103
|
+
@udp_scan = scan.scan
|
104
|
+
|
105
|
+
debug "scan state: #{@udp_scan.to_s}"
|
106
|
+
rescue Errno::EHOSTUNREACH
|
107
|
+
puts 'host not reachable'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
do_output
|
112
|
+
verbose "Finished at #{DateTime.now}"
|
113
|
+
|
114
|
+
else
|
115
|
+
puts @opts
|
116
|
+
end
|
117
|
+
rescue Interrupt
|
118
|
+
puts 'Stopping scan'
|
119
|
+
scan.stop
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
# command line output formatting helpers
|
125
|
+
def do_scan_output(state)
|
126
|
+
open_ports = state.open_ports
|
127
|
+
closed_ports = state.closed_ports
|
128
|
+
|
129
|
+
open_defa = if open_ports.size>1 then 'are' else 'is' end
|
130
|
+
closed_defa = if closed_ports.size>1 then 'are' else 'is' end
|
131
|
+
|
132
|
+
port_or_ports = if state.ports_scanned == 1 then 'port' else 'ports' end
|
133
|
+
|
134
|
+
transport_output = ''
|
135
|
+
transport_output << "#{state.transport} Port#{'s' unless open_ports.size == 1} #{open_ports.to_s} " \
|
136
|
+
"#{open_defa} open\n" unless open_ports.size == 0
|
137
|
+
transport_output << "#{state.transport} Port#{'s' unless closed_ports.size == 1} #{closed_ports.to_s} " \
|
138
|
+
"#{closed_defa} closed\n" unless closed_ports.size == 0
|
139
|
+
|
140
|
+
scanned_output = ''
|
141
|
+
scanned_output << "\nScanned #{state.ports_scanned} #{state.transport} #{port_or_ports}"
|
142
|
+
scanned_output << ", #{open_ports.size} #{open_defa} open" unless open_ports.size == 0
|
143
|
+
scanned_output << ", #{closed_ports.size} #{closed_defa} closed" unless closed_ports.size == 0
|
144
|
+
|
145
|
+
port_detail_output = ''
|
146
|
+
state.result_map.each do |code,ports|
|
147
|
+
unless code == $success
|
148
|
+
ps = Portspec.new(ports)
|
149
|
+
port_detail_output << "#{port_or_ports.capitalize} #{ps.to_s} #{if ps.size>1 then 'are' else 'is' end} closed - #{$result_code_messages[code]}\n"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
return transport_output,scanned_output,port_detail_output
|
154
|
+
end
|
155
|
+
|
156
|
+
def do_output
|
157
|
+
|
158
|
+
tcp = @tcp_scan && @tcp_scan.current_state == :SCAN_COMPLETE
|
159
|
+
udp = @udp_scan && @udp_scan.current_state == :SCAN_COMPLETE
|
160
|
+
|
161
|
+
# we had a complete scan, show summary
|
162
|
+
|
163
|
+
out = "\n"
|
164
|
+
if tcp
|
165
|
+
out << "Completed #{@tcp_scan.protocol} scan of #{@tcp_scan.transport} #{@tcp_scan.portspec.to_s}\n"
|
166
|
+
tcp_transport_out,tcp_scanned_out,tcp_port_detail_out = do_scan_output(@tcp_scan)
|
167
|
+
end
|
168
|
+
if udp
|
169
|
+
out << "Completed #{@udp_scan.protocol} scan of #{@udp_scan.transport} #{@udp_scan.portspec.to_s}\n"
|
170
|
+
udp_transport_out,udp_scanned_out,udp_port_detail_out = do_scan_output(@udp_scan)
|
171
|
+
end
|
172
|
+
|
173
|
+
out << tcp_transport_out if tcp_transport_out
|
174
|
+
out << udp_transport_out if udp_transport_out
|
175
|
+
|
176
|
+
out << tcp_scanned_out if tcp_scanned_out
|
177
|
+
out << udp_scanned_out if udp_scanned_out
|
178
|
+
out << "\n"
|
179
|
+
|
180
|
+
out << tcp_port_detail_out if tcp_port_detail_out
|
181
|
+
out << udp_port_detail_out if udp_port_detail_out
|
182
|
+
|
183
|
+
puts out
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
# scan callback interface
|
188
|
+
# @param [Object] state
|
189
|
+
def update(state)
|
190
|
+
debug "callback #{state.to_s}"
|
191
|
+
|
192
|
+
case state.current_state
|
193
|
+
when :PORT_COMPLETE
|
194
|
+
|
195
|
+
if state.port_result_code == $success
|
196
|
+
puts " open in #{state.port_duration}ms #{state.percent_complete}%"
|
197
|
+
else
|
198
|
+
puts " closed after #{state.port_duration}ms - #{$result_code_messages[state.port_result_code]}"
|
199
|
+
end
|
200
|
+
|
201
|
+
$stdout.flush
|
202
|
+
when :PORT_START
|
203
|
+
print "#{state.transport.to_s} #{state.port.to_s}"
|
204
|
+
when :PORT_TICK
|
205
|
+
print '.'
|
206
|
+
when :SCAN_START
|
207
|
+
puts "Performing #{state.protocol} scan on #{state.transport} ports #{state.portspec.to_s} via #{state.command_server} with #{state.timeout}ms timeout"
|
208
|
+
when :START_FAILURE
|
209
|
+
case state.status_code
|
210
|
+
when $authentication_failure
|
211
|
+
puts 'Authentication failure'
|
212
|
+
when $request_invalid
|
213
|
+
puts 'Incompatible command server (request invalid)'
|
214
|
+
when $server_bind_error
|
215
|
+
puts "Server unable to bind on ports #{state.portspec.to_s}"
|
216
|
+
when $command_server_unavailable
|
217
|
+
puts "Unable to reach command server #{state.message}"
|
218
|
+
else
|
219
|
+
puts "Unable to start scan (code #{state.status_code})"
|
220
|
+
end
|
221
|
+
when :SCAN_COMPLETE
|
222
|
+
|
223
|
+
else
|
224
|
+
puts "unhandled callback #{state.to_s}"
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
protected
|
230
|
+
|
231
|
+
# figure what arguments we have to work with
|
232
|
+
def parsed_options?
|
233
|
+
|
234
|
+
@opts = OptionParser.new do |opt|
|
235
|
+
opt.banner = "\nFirescan Ruby client version #{VERSION} ( http://www.firebind.com )\nUsage: firescan [options] "
|
236
|
+
opt.separator ''
|
237
|
+
opt.separator 'Options'
|
238
|
+
|
239
|
+
opt.on('-h', '--help','Show help and version') do
|
240
|
+
puts @opts
|
241
|
+
exit
|
242
|
+
end
|
243
|
+
opt.on('-v', '--verbose','Show verbose output') do
|
244
|
+
$verbose = true
|
245
|
+
end
|
246
|
+
opt.on('-s ADDRESS', '--command-server ADDRESS','Address:port or hostname:port of command server, default port is 80',String) do |address|
|
247
|
+
@options.command_server = address
|
248
|
+
end
|
249
|
+
opt.on('-t PORT_LIST', '--tcp PORT_LIST','TCP Port specification (list), use commas and dashes to specify a list of ports',String) do |tcp_port_list|
|
250
|
+
@options.tcp_port_list = tcp_port_list
|
251
|
+
end
|
252
|
+
opt.on('-u PORT_LIST', '--udp PORT_LIST','UDP Port specification (list), use commas and dashes to specify a list of ports',String) do |udp_port_list|
|
253
|
+
@options.udp_port_list = udp_port_list
|
254
|
+
end
|
255
|
+
opt.on('-i TIMEOUT', '--timeout TIMEOUT','Timeout (in milliseconds) to use for connect, transmit and receive operations',Integer) do |timeout|
|
256
|
+
@options.timeout = timeout
|
257
|
+
end
|
258
|
+
opt.on('-n USERNAME', '--username USERNAME','Specify a username (to connect to command server)',String) do |username|
|
259
|
+
@options.username = username
|
260
|
+
end
|
261
|
+
opt.on('-p PASSWORD', '--password PASSWORD','Specify a password (to connect to command server)',String) do |password|
|
262
|
+
@options.password = password
|
263
|
+
end
|
264
|
+
#opt.on('-r PROTOCOL', '--protocol PROTOCOL','Specify a protocol (defaults to Simple protocol)',String) do |protocol|
|
265
|
+
#@options.protocol = protocol
|
266
|
+
# todo handle this when IMG is available
|
267
|
+
#end
|
268
|
+
opt.on('-g TAG', '--tag TAG','tag the scan with value',String) do |tag|
|
269
|
+
@options.tag = tag
|
270
|
+
end
|
271
|
+
#opt.on('-l LOCAL_ADDRESS', '--localaddr LOCAL_ADDRESS','Specify local IP address for client binding',String) do |addr|
|
272
|
+
# @options.local_address = addr
|
273
|
+
#end
|
274
|
+
opt.on('-d', '--xdebug','Show debug output') do
|
275
|
+
$verbose = true
|
276
|
+
$debug = true
|
277
|
+
end
|
278
|
+
opt.separator ''
|
279
|
+
end
|
280
|
+
|
281
|
+
@opts.parse!(@arguments) rescue return false
|
282
|
+
|
283
|
+
verbose 'verbose output is on'
|
284
|
+
debug 'debug output is on'
|
285
|
+
|
286
|
+
if $debug
|
287
|
+
output_options
|
288
|
+
end
|
289
|
+
#debug @options.to_s
|
290
|
+
|
291
|
+
true
|
292
|
+
end
|
293
|
+
|
294
|
+
def output_options
|
295
|
+
puts "Options:\ "
|
296
|
+
@options.marshal_dump.each do |name, val|
|
297
|
+
puts " #{name} = #{val}"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
# True if required arguments were provided
|
302
|
+
def arguments_valid?
|
303
|
+
true if @options.udp_port_list != NIL || @options.tcp_port_list != NIL
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|