ssl_scan 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,274 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module SSLScan
4
+
5
+ ###
6
+ #
7
+ # Base mixin for all exceptions that can be thrown from inside SSLScan.
8
+ #
9
+ ###
10
+ module Exception
11
+ end
12
+
13
+ ###
14
+ #
15
+ # This exception is raised when a timeout occurs.
16
+ #
17
+ ###
18
+ class TimeoutError < Interrupt
19
+ include Exception
20
+
21
+ def to_s
22
+ "Operation timed out."
23
+ end
24
+ end
25
+
26
+ ###
27
+ #
28
+ # This exception is raised when a method is called or a feature is used that
29
+ # is not implemented.
30
+ #
31
+ ###
32
+ class NotImplementedError < ::NotImplementedError
33
+ include Exception
34
+
35
+ def to_s
36
+ "The requested method is not implemented."
37
+ end
38
+ end
39
+
40
+ ###
41
+ #
42
+ # This exception is raised when a generalized runtime error occurs.
43
+ #
44
+ ###
45
+ class RuntimeError < ::RuntimeError
46
+ include Exception
47
+ end
48
+
49
+ ###
50
+ #
51
+ # This exception is raised when an invalid argument is supplied to a method.
52
+ #
53
+ ###
54
+ class ArgumentError < ::ArgumentError
55
+ include Exception
56
+
57
+ def initialize(message = nil)
58
+ @message = message
59
+ end
60
+
61
+ def to_s
62
+ str = 'An invalid argument was specified.'
63
+ if @message
64
+ str << " #{@message}"
65
+ end
66
+ str
67
+ end
68
+ end
69
+
70
+ ###
71
+ #
72
+ # This exception is raised when an argument that was supplied to a method
73
+ # could not be parsed correctly.
74
+ #
75
+ ###
76
+ class ArgumentParseError < ::ArgumentError
77
+ include Exception
78
+
79
+ def to_s
80
+ "The argument could not be parsed correctly."
81
+ end
82
+ end
83
+
84
+ ###
85
+ #
86
+ # This exception is raised when an argument is ambiguous.
87
+ #
88
+ ###
89
+ class AmbiguousArgumentError < ::RuntimeError
90
+ include Exception
91
+
92
+ def initialize(name = nil)
93
+ @name = name
94
+ end
95
+
96
+ def to_s
97
+ "The name #{@name} is ambiguous."
98
+ end
99
+ end
100
+
101
+ ###
102
+ #
103
+ # This error is thrown when a stream is detected as being closed.
104
+ #
105
+ ###
106
+ class StreamClosedError < ::IOError
107
+ include Exception
108
+
109
+ def initialize(stream)
110
+ @stream = stream
111
+ end
112
+
113
+ def stream
114
+ @stream
115
+ end
116
+
117
+ def to_s
118
+ "Stream #{@stream} is closed."
119
+ end
120
+ end
121
+
122
+ ##
123
+ #
124
+ # Socket exceptions
125
+ #
126
+ ##
127
+
128
+ ###
129
+ #
130
+ # This exception is raised when a general socket error occurs.
131
+ #
132
+ ###
133
+ module SocketError
134
+ include Exception
135
+
136
+ def to_s
137
+ "A socket error occurred."
138
+ end
139
+ end
140
+
141
+ ###
142
+ #
143
+ # This exception is raised when there is some kind of error related to
144
+ # communication with a host.
145
+ #
146
+ ###
147
+ module HostCommunicationError
148
+ def initialize(addr = nil, port = nil)
149
+ self.host = addr
150
+ self.port = port
151
+ end
152
+
153
+ #
154
+ # This method returns a printable address and optional port associated
155
+ # with the host that triggered the exception.
156
+ #
157
+ def addr_to_s
158
+ if host and port
159
+ "(#{host}:#{port})"
160
+ elsif host
161
+ "(#{host})"
162
+ else
163
+ ""
164
+ end
165
+ end
166
+
167
+ attr_accessor :host, :port
168
+ end
169
+
170
+
171
+ ###
172
+ #
173
+ # This is a generic exception for errors that cause a connection to fail.
174
+ #
175
+ ###
176
+ class ConnectionError < ::IOError
177
+ include SocketError
178
+ include HostCommunicationError
179
+ end
180
+
181
+ ###
182
+ #
183
+ # This exception is raised when a connection attempt fails because the remote
184
+ # side refused the connection.
185
+ #
186
+ ###
187
+ class ConnectionRefused < ConnectionError
188
+ def to_s
189
+ "The connection was refused by the remote host #{addr_to_s}."
190
+ end
191
+ end
192
+
193
+ ###
194
+ #
195
+ # This exception is raised when a connection attempt fails because the remote
196
+ # side is unreachable.
197
+ #
198
+ ###
199
+ class HostUnreachable < ConnectionError
200
+ def to_s
201
+ "The host #{addr_to_s} was unreachable."
202
+ end
203
+ end
204
+
205
+ ###
206
+ #
207
+ # This exception is raised when a connection attempt times out.
208
+ #
209
+ ###
210
+ class ConnectionTimeout < ConnectionError
211
+ def to_s
212
+ "The connection timed out #{addr_to_s}."
213
+ end
214
+ end
215
+
216
+
217
+ ###
218
+ #
219
+ # This exception is raised when an attempt to use an address or port that is
220
+ # already in use occurs, such as binding to a host on a given port that is
221
+ # already in use. Note that Windows raises this in some cases when attempting
222
+ # to connect to addresses that it can't handle, e.g. "0.0.0.0". Thus, this is
223
+ # a ConnectionError.
224
+ #
225
+ ###
226
+ class AddressInUse < ConnectionError
227
+ include SocketError
228
+ include HostCommunicationError
229
+
230
+ def to_s
231
+ "The address is already in use #{addr_to_s}."
232
+ end
233
+ end
234
+
235
+ ###
236
+ #
237
+ # This exception is raised when an unsupported internet protocol is specified.
238
+ #
239
+ ###
240
+ class UnsupportedProtocol < ::ArgumentError
241
+ include SocketError
242
+
243
+ def initialize(proto = nil)
244
+ self.proto = proto
245
+ end
246
+
247
+ def to_s
248
+ "The protocol #{proto} is not supported."
249
+ end
250
+
251
+ attr_accessor :proto
252
+ end
253
+
254
+
255
+ ###
256
+ #
257
+ # This exception is raised when a proxy fails to pass a connection
258
+ #
259
+ ###
260
+ class ConnectionProxyError < ConnectionError
261
+ def initialize(host,port,ptype,reason)
262
+ super(host,port)
263
+ self.ptype = ptype
264
+ self.reason = reason
265
+ end
266
+
267
+ def to_s
268
+ self.ptype + ": " + self.reason
269
+ end
270
+
271
+ attr_accessor :ptype, :reason
272
+ end
273
+
274
+ end
@@ -0,0 +1,161 @@
1
+ # -*- coding: binary -*-
2
+ module Rex
3
+ module IO
4
+
5
+ require 'rex/ui/text/output'
6
+ require 'rex/ui/text/output/buffer'
7
+ require 'rex/ui/text/input/buffer'
8
+
9
+ class BidirectionalPipe < Rex::Ui::Text::Input
10
+
11
+ def initialize
12
+ @subscribers_out = {}
13
+ @subscribers_ref = {}
14
+ @subscribers_idx = 0
15
+ @pipe_input = Rex::Ui::Text::Input::Buffer.new
16
+
17
+ # We are the shell, the input, and the output
18
+ self.output = self
19
+ self.input = self
20
+ end
21
+
22
+ def pipe_input
23
+ @pipe_input
24
+ end
25
+
26
+ def close
27
+ @pipe_input.close
28
+ end
29
+
30
+ def has_subscriber?(id)
31
+ @subscribers_out.has_key?(id)
32
+ end
33
+
34
+ def create_subscriber(id=nil)
35
+ id ||= (@subscribers_idx += 1).to_s
36
+ @subscribers_out[id] = Rex::Ui::Text::Output::Buffer.new
37
+ return id
38
+ end
39
+
40
+ def create_subscriber_proc(id=nil, &block)
41
+ id = create_subscriber(id)
42
+ @subscribers_ref[id] = block
43
+ end
44
+
45
+ def remove_subscriber(id)
46
+ @subscribers_out.delete(id)
47
+ @subscribers_ref.delete(id)
48
+ end
49
+
50
+ def write_input(buf)
51
+ @pipe_input.put(buf)
52
+ end
53
+
54
+ def read_subscriber(id)
55
+ output = @subscribers_out[id]
56
+
57
+ return '' if output.nil?
58
+
59
+ buf = output.buf
60
+
61
+ output.reset
62
+
63
+ buf
64
+ end
65
+
66
+ def print(msg='')
67
+ @subscribers_out.each_pair { |id, buf|
68
+ begin
69
+ @subscribers_ref[id] ? @subscribers_ref[id].call(msg) : buf.print(msg)
70
+ rescue ::Exception => e
71
+ # $stderr.puts "Error handling subscriber #{id}: #{e} #{e.backtrace.inspect}"
72
+ raise e
73
+ end
74
+ }
75
+ msg
76
+ end
77
+
78
+ def print_error(msg='')
79
+ print_line('[-] ' + msg)
80
+ end
81
+
82
+ def print_line(msg='')
83
+ print(msg + "\n")
84
+ end
85
+
86
+ def print_good(msg='')
87
+ print_line('[+] ' + msg)
88
+ end
89
+
90
+ def print_debug(msg='')
91
+ print_line('[!] ' + msg)
92
+ end
93
+
94
+ def flush
95
+ end
96
+
97
+ def print_status(msg='')
98
+ print_line('[*] ' + msg)
99
+ end
100
+
101
+ def print_warning(msg='')
102
+ print_line('[!] ' + msg)
103
+ end
104
+
105
+ #
106
+ # Wrappers for the pipe_input methods
107
+ #
108
+
109
+ def close
110
+ @pipe_input.close
111
+ end
112
+
113
+ def sysread(len = 1)
114
+ @pipe_input.sysread(len)
115
+ end
116
+
117
+ def put(msg)
118
+ @pipe_input.put(msg)
119
+ end
120
+
121
+ def gets
122
+ @pipe_input.gets
123
+ end
124
+
125
+ def eof?
126
+ @pipe_input.eof?
127
+ end
128
+
129
+ def fd
130
+ @pipe_input.fd
131
+ end
132
+
133
+ #
134
+ # Wrappers for shell methods
135
+ #
136
+
137
+ attr_accessor :output, :prompt, :input
138
+
139
+ def intrinsic_shell?
140
+ true
141
+ end
142
+
143
+ def supports_readline
144
+ false
145
+ end
146
+
147
+ def supports_color?
148
+ false
149
+ end
150
+
151
+ def pgets
152
+ gets
153
+ end
154
+
155
+
156
+ protected
157
+
158
+ end
159
+
160
+ end
161
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: binary -*-
2
+
3
+ require 'socket'
4
+
5
+ module Rex
6
+ module IO
7
+
8
+ ###
9
+ #
10
+ # This class provides an abstraction to a datagram based
11
+ # connection through the use of a datagram socketpair.
12
+ #
13
+ ###
14
+ module DatagramAbstraction
15
+
16
+ #
17
+ # Creates a streaming socket pair
18
+ #
19
+ def initialize_abstraction
20
+ self.lsock, self.rsock = Rex::Socket.udp_socket_pair()
21
+ end
22
+
23
+
24
+ # The left side of the stream (local)
25
+ attr_reader :lsock
26
+ # The right side of the stream (remote)
27
+ attr_reader :rsock
28
+
29
+ protected
30
+ attr_writer :lsock
31
+ attr_writer :rsock
32
+
33
+ end
34
+
35
+ end; end