ronin-support 0.3.0 → 0.4.0.rc1
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/ChangeLog.md +77 -7
- data/README.md +19 -3
- data/gemspec.yml +2 -2
- data/lib/ronin/extensions/regexp.rb +50 -2
- data/lib/ronin/extensions/string.rb +1 -0
- data/lib/ronin/formatting.rb +1 -0
- data/lib/ronin/formatting/extensions.rb +1 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +56 -5
- data/lib/ronin/formatting/extensions/html/string.rb +6 -7
- data/lib/ronin/formatting/extensions/sql/string.rb +34 -0
- data/lib/ronin/formatting/extensions/text/string.rb +0 -180
- data/lib/ronin/fuzzing.rb +21 -0
- data/lib/ronin/fuzzing/extensions.rb +20 -0
- data/lib/ronin/fuzzing/extensions/string.rb +380 -0
- data/lib/ronin/fuzzing/fuzzing.rb +191 -0
- data/lib/ronin/network/esmtp.rb +94 -1
- data/lib/ronin/network/extensions/esmtp/net.rb +2 -82
- data/lib/ronin/network/extensions/http/net.rb +1 -736
- data/lib/ronin/network/extensions/imap/net.rb +1 -103
- data/lib/ronin/network/extensions/pop3/net.rb +1 -71
- data/lib/ronin/network/extensions/smtp/net.rb +2 -157
- data/lib/ronin/network/extensions/ssl/net.rb +1 -132
- data/lib/ronin/network/extensions/tcp/net.rb +2 -296
- data/lib/ronin/network/extensions/telnet/net.rb +1 -135
- data/lib/ronin/network/extensions/udp/net.rb +2 -214
- data/lib/ronin/network/http/http.rb +750 -5
- data/lib/ronin/network/imap.rb +105 -2
- data/lib/ronin/network/mixins.rb +1 -1
- data/lib/ronin/network/mixins/esmtp.rb +49 -52
- data/lib/ronin/network/mixins/http.rb +49 -53
- data/lib/ronin/network/mixins/imap.rb +47 -44
- data/lib/ronin/network/mixins/mixin.rb +58 -0
- data/lib/ronin/network/mixins/pop3.rb +44 -38
- data/lib/ronin/network/mixins/smtp.rb +49 -51
- data/lib/ronin/network/mixins/tcp.rb +56 -69
- data/lib/ronin/network/mixins/telnet.rb +57 -50
- data/lib/ronin/network/mixins/udp.rb +48 -52
- data/lib/ronin/network/network.rb +1 -0
- data/lib/ronin/network/pop3.rb +72 -2
- data/lib/ronin/network/smtp/email.rb +1 -0
- data/lib/ronin/network/smtp/smtp.rb +159 -3
- data/lib/ronin/network/ssl.rb +131 -2
- data/lib/ronin/network/tcp.rb +306 -1
- data/lib/ronin/network/telnet.rb +136 -2
- data/lib/ronin/network/udp.rb +229 -1
- data/lib/ronin/support.rb +2 -3
- data/lib/ronin/support/support.rb +38 -0
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/templates/erb.rb +2 -1
- data/lib/ronin/ui/output/helpers.rb +35 -1
- data/lib/ronin/ui/shell.rb +12 -2
- data/lib/ronin/wordlist.rb +157 -0
- data/spec/extensions/regexp_spec.rb +38 -0
- data/spec/formatting/html/string_spec.rb +1 -1
- data/spec/formatting/sql/string_spec.rb +23 -3
- data/spec/formatting/text/string_spec.rb +0 -110
- data/spec/fuzzing/string_spec.rb +158 -0
- data/spec/wordlist_spec.rb +65 -0
- metadata +35 -27
data/lib/ronin/network/ssl.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#
|
19
19
|
|
20
|
-
require 'ronin/network/
|
20
|
+
require 'ronin/network/tcp'
|
21
21
|
|
22
22
|
begin
|
23
23
|
require 'openssl'
|
@@ -27,9 +27,11 @@ end
|
|
27
27
|
module Ronin
|
28
28
|
module Network
|
29
29
|
#
|
30
|
-
#
|
30
|
+
# Provides helper methods for communicating with SSL-enabled services.
|
31
31
|
#
|
32
32
|
module SSL
|
33
|
+
extend TCP
|
34
|
+
|
33
35
|
# Maps SSL verify modes to `OpenSSL::SSL::VERIFY_*` constants.
|
34
36
|
#
|
35
37
|
# @return [Hash{Symbol => Integer}]
|
@@ -52,5 +54,132 @@ module Ronin
|
|
52
54
|
hash[key] = OpenSSL::SSL.const_get(verify_const)
|
53
55
|
end
|
54
56
|
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Establishes a SSL connection.
|
60
|
+
#
|
61
|
+
# @param [String] host
|
62
|
+
# The host to connect to.
|
63
|
+
#
|
64
|
+
# @param [Integer] port
|
65
|
+
# The port to connect to.
|
66
|
+
#
|
67
|
+
# @param [Hash] options
|
68
|
+
# Additional options.
|
69
|
+
#
|
70
|
+
# @option options [String] :local_host
|
71
|
+
# The local host to bind to.
|
72
|
+
#
|
73
|
+
# @option options [Integer] :local_port
|
74
|
+
# The local port to bind to.
|
75
|
+
#
|
76
|
+
# @option options [Symbol] :verify
|
77
|
+
# Specifies whether to verify the SSL certificate.
|
78
|
+
# May be one of the following:
|
79
|
+
#
|
80
|
+
# * `:none`
|
81
|
+
# * `:peer`
|
82
|
+
# * `:client_once`
|
83
|
+
# * `:fail_if_no_peer_cert`
|
84
|
+
#
|
85
|
+
# @option options [String] :cert
|
86
|
+
# The path to the SSL certificate.
|
87
|
+
#
|
88
|
+
# @option options [String] :key
|
89
|
+
# The path to the SSL key.
|
90
|
+
#
|
91
|
+
# @yield [ssl_socket]
|
92
|
+
# The given block will be passed the new SSL Socket.
|
93
|
+
#
|
94
|
+
# @yieldparam [OpenSSL::SSL::SSLSocket] ssl_socket
|
95
|
+
# The new SSL Socket.
|
96
|
+
#
|
97
|
+
# @return [OpenSSL::SSL::SSLSocket]
|
98
|
+
# the new SSL Socket.
|
99
|
+
#
|
100
|
+
# @example
|
101
|
+
# socket = ssl_connect('twitter.com',443)
|
102
|
+
#
|
103
|
+
# @api public
|
104
|
+
#
|
105
|
+
def ssl_connect(host,port,options={})
|
106
|
+
local_host = options[:local_host]
|
107
|
+
local_port = options[:local_port]
|
108
|
+
|
109
|
+
socket = tcp_connect(host,port,local_host,local_port)
|
110
|
+
|
111
|
+
ssl_context = OpenSSL::SSL::SSLContext.new()
|
112
|
+
ssl_context.verify_mode = SSL::VERIFY[options[:verify]]
|
113
|
+
|
114
|
+
if options[:cert]
|
115
|
+
cert_file = File.new(options[:cert])
|
116
|
+
ssl_context.cert = OpenSSL::X509::Certificate.new(cert_file)
|
117
|
+
end
|
118
|
+
|
119
|
+
if options[:key]
|
120
|
+
key_file = File.new(options[:key])
|
121
|
+
ssl_context.key = OpenSSL::PKey::RSA.new(key_file)
|
122
|
+
end
|
123
|
+
|
124
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket,ssl_context)
|
125
|
+
ssl_socket.sync_close = true
|
126
|
+
ssl_socket.connect
|
127
|
+
|
128
|
+
yield ssl_socket if block_given?
|
129
|
+
return ssl_socket
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Creates a new temporary SSL connection.
|
134
|
+
#
|
135
|
+
# @param [String] host
|
136
|
+
# The host to connect to.
|
137
|
+
#
|
138
|
+
# @param [Integer] port
|
139
|
+
# The port to connect to.
|
140
|
+
#
|
141
|
+
# @param [Hash] options
|
142
|
+
# Additional options.
|
143
|
+
#
|
144
|
+
# @option options [String] :local_host
|
145
|
+
# The local host to bind to.
|
146
|
+
#
|
147
|
+
# @option options [Integer] :local_port
|
148
|
+
# The local port to bind to.
|
149
|
+
#
|
150
|
+
# @option options [Symbol] :verify
|
151
|
+
# Specifies whether to verify the SSL certificate.
|
152
|
+
#
|
153
|
+
# @option options [String] :cert
|
154
|
+
# The path to the SSL certificate.
|
155
|
+
#
|
156
|
+
# @option options [String] :key
|
157
|
+
# The path to the SSL key.
|
158
|
+
#
|
159
|
+
# @yield [ssl_socket]
|
160
|
+
# The given block will be passed the temporary SSL Socket.
|
161
|
+
#
|
162
|
+
# @yieldparam [OpenSSL::SSL::SSLSocket] ssl_socket
|
163
|
+
# The temporary SSL Socket.
|
164
|
+
#
|
165
|
+
# @return [nil]
|
166
|
+
#
|
167
|
+
# @example
|
168
|
+
# ssl_session('twitter.com',443) do |sock|
|
169
|
+
# sock.write("GET /\n\n")
|
170
|
+
#
|
171
|
+
# sock.each_line { |line| puts line }
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# @api public
|
175
|
+
#
|
176
|
+
def ssl_session(host,port)
|
177
|
+
ssl_socket = ssl_connect(host,port)
|
178
|
+
|
179
|
+
yield ssl_socket if block_given?
|
180
|
+
|
181
|
+
ssl_socket.close
|
182
|
+
return nil
|
183
|
+
end
|
55
184
|
end
|
56
185
|
end
|
data/lib/ronin/network/tcp.rb
CHANGED
@@ -17,4 +17,309 @@
|
|
17
17
|
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#
|
19
19
|
|
20
|
-
require '
|
20
|
+
require 'socket'
|
21
|
+
|
22
|
+
module Ronin
|
23
|
+
module Network
|
24
|
+
#
|
25
|
+
# Provides helper methods for using the TCP protocol.
|
26
|
+
#
|
27
|
+
module TCP
|
28
|
+
#
|
29
|
+
# Creates a new TCPSocket object connected to a given host and port.
|
30
|
+
#
|
31
|
+
# @param [String] host
|
32
|
+
# The host to connect to.
|
33
|
+
#
|
34
|
+
# @param [Integer] port
|
35
|
+
# The port to connect to.
|
36
|
+
#
|
37
|
+
# @param [String] local_host (nil)
|
38
|
+
# The local host to bind to.
|
39
|
+
#
|
40
|
+
# @param [Integer] local_port (nil)
|
41
|
+
# The local port to bind to.
|
42
|
+
#
|
43
|
+
# @yield [socket]
|
44
|
+
# If a block is given, it will be passed the newly created socket.
|
45
|
+
#
|
46
|
+
# @yieldparam [TCPsocket] socket
|
47
|
+
# The newly created TCPSocket object.
|
48
|
+
#
|
49
|
+
# @return [TCPSocket]
|
50
|
+
# The newly created TCPSocket object.
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# tcp_connect('www.hackety.org',80) # => TCPSocket
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# tcp_connect('www.wired.com',80) do |sock|
|
57
|
+
# sock.write("GET /\n\n")
|
58
|
+
# puts sock.readlines
|
59
|
+
# sock.close
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# @api public
|
63
|
+
#
|
64
|
+
def tcp_connect(host,port,local_host=nil,local_port=nil)
|
65
|
+
host = host.to_s
|
66
|
+
local_host = if local_host
|
67
|
+
local_host.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
sock = TCPSocket.new(host,port,local_host,local_port)
|
71
|
+
|
72
|
+
yield sock if block_given?
|
73
|
+
return sock
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Creates a new TCPSocket object, connected to a given host and port.
|
78
|
+
# The given data will then be written to the newly created TCPSocket.
|
79
|
+
#
|
80
|
+
# @param [String] data
|
81
|
+
# The data to send through the connection.
|
82
|
+
#
|
83
|
+
# @param [String] host
|
84
|
+
# The host to connect to.
|
85
|
+
#
|
86
|
+
# @param [Integer] port
|
87
|
+
# The port to connect to.
|
88
|
+
#
|
89
|
+
# @param [String] local_host (nil)
|
90
|
+
# The local host to bind to.
|
91
|
+
#
|
92
|
+
# @param [Integer] local_port (nil)
|
93
|
+
# The local port to bind to.
|
94
|
+
#
|
95
|
+
# @yield [socket]
|
96
|
+
# If a block is given, it will be passed the newly created socket.
|
97
|
+
#
|
98
|
+
# @yieldparam [TCPsocket] socket
|
99
|
+
# The newly created TCPSocket object.
|
100
|
+
#
|
101
|
+
# @api public
|
102
|
+
#
|
103
|
+
def tcp_connect_and_send(data,host,port,local_host=nil,local_port=nil)
|
104
|
+
sock = tcp_connect(host,port,local_host,local_port)
|
105
|
+
sock.write(data)
|
106
|
+
|
107
|
+
yield sock if block_given?
|
108
|
+
return sock
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Creates a new temporary TCPSocket object, connected to the given host
|
113
|
+
# and port.
|
114
|
+
#
|
115
|
+
# @param [String] host
|
116
|
+
# The host to connect to.
|
117
|
+
#
|
118
|
+
# @param [Integer] port
|
119
|
+
# The port to connect to.
|
120
|
+
#
|
121
|
+
# @param [String] local_host (nil)
|
122
|
+
# The local host to bind to.
|
123
|
+
#
|
124
|
+
# @param [Integer] local_port (nil)
|
125
|
+
# The local port to bind to.
|
126
|
+
#
|
127
|
+
# @yield [socket]
|
128
|
+
# If a block is given, it will be passed the newly created socket.
|
129
|
+
# After the block has returned, the socket will then be closed.
|
130
|
+
#
|
131
|
+
# @yieldparam [TCPsocket] socket
|
132
|
+
# The newly created TCPSocket object.
|
133
|
+
#
|
134
|
+
# @return [nil]
|
135
|
+
#
|
136
|
+
# @api public
|
137
|
+
#
|
138
|
+
def tcp_session(host,port,local_host=nil,local_port=nil)
|
139
|
+
sock = tcp_connect(host,port,local_host,local_port)
|
140
|
+
|
141
|
+
yield sock if block_given?
|
142
|
+
|
143
|
+
sock.close
|
144
|
+
return nil
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Reads the banner from the service running on the given host and port.
|
149
|
+
#
|
150
|
+
# @param [String] host
|
151
|
+
# The host to connect to.
|
152
|
+
#
|
153
|
+
# @param [Integer] port
|
154
|
+
# The port to connect to.
|
155
|
+
#
|
156
|
+
# @param [String] local_host (nil)
|
157
|
+
# The local host to bind to.
|
158
|
+
#
|
159
|
+
# @param [Integer] local_port (nil)
|
160
|
+
# The local port to bind to.
|
161
|
+
#
|
162
|
+
# @yield [banner]
|
163
|
+
# If a block is given, it will be passed the grabbed banner.
|
164
|
+
#
|
165
|
+
# @yieldparam [String] banner
|
166
|
+
# The grabbed banner.
|
167
|
+
#
|
168
|
+
# @return [String]
|
169
|
+
# The grabbed banner.
|
170
|
+
#
|
171
|
+
# @example
|
172
|
+
# tcp_banner('pop.gmail.com',25)
|
173
|
+
# # => "220 mx.google.com ESMTP c20sm3096959rvf.1"
|
174
|
+
#
|
175
|
+
# @api public
|
176
|
+
#
|
177
|
+
def tcp_banner(host,port,local_host=nil,local_port=nil)
|
178
|
+
banner = nil
|
179
|
+
|
180
|
+
tcp_session(host,port,local_host,local_port) do |sock|
|
181
|
+
banner = sock.readline.strip
|
182
|
+
end
|
183
|
+
|
184
|
+
yield banner if block_given?
|
185
|
+
return banner
|
186
|
+
end
|
187
|
+
|
188
|
+
#
|
189
|
+
# Connects to a specified host and port, sends the given data and then
|
190
|
+
# closes the connection.
|
191
|
+
#
|
192
|
+
# @param [String] data
|
193
|
+
# The data to send through the connection.
|
194
|
+
#
|
195
|
+
# @param [String] host
|
196
|
+
# The host to connect to.
|
197
|
+
#
|
198
|
+
# @param [Integer] port
|
199
|
+
# The port to connect to.
|
200
|
+
#
|
201
|
+
# @param [String] local_host (nil)
|
202
|
+
# The local host to bind to.
|
203
|
+
#
|
204
|
+
# @param [Integer] local_port (nil)
|
205
|
+
# The local port to bind to.
|
206
|
+
#
|
207
|
+
# @return [true]
|
208
|
+
# The data was successfully sent.
|
209
|
+
#
|
210
|
+
# @example
|
211
|
+
# buffer = "GET /" + ('A' * 4096) + "\n\r"
|
212
|
+
# tcp_send(buffer,'victim.com',80)
|
213
|
+
# # => true
|
214
|
+
#
|
215
|
+
# @api public
|
216
|
+
#
|
217
|
+
def tcp_send(data,host,port,local_host=nil,local_port=nil)
|
218
|
+
tcp_session(host,port,local_host,local_port) do |sock|
|
219
|
+
sock.write(data)
|
220
|
+
end
|
221
|
+
|
222
|
+
return true
|
223
|
+
end
|
224
|
+
|
225
|
+
#
|
226
|
+
# Creates a new TCPServer listening on a given host and port.
|
227
|
+
#
|
228
|
+
# @param [Integer] port
|
229
|
+
# The local port to listen on.
|
230
|
+
#
|
231
|
+
# @param [String] host ('0.0.0.0')
|
232
|
+
# The host to bind to.
|
233
|
+
#
|
234
|
+
# @return [TCPServer]
|
235
|
+
# The new TCP server.
|
236
|
+
#
|
237
|
+
# @example
|
238
|
+
# tcp_server(1337)
|
239
|
+
#
|
240
|
+
# @api public
|
241
|
+
#
|
242
|
+
def tcp_server(port,host='0.0.0.0')
|
243
|
+
host = host.to_s
|
244
|
+
|
245
|
+
server = TCPServer.new(host,port)
|
246
|
+
server.listen(3)
|
247
|
+
|
248
|
+
yield server if block_given?
|
249
|
+
return server
|
250
|
+
end
|
251
|
+
|
252
|
+
#
|
253
|
+
# Creates a new temporary TCPServer listening on a host and port.
|
254
|
+
#
|
255
|
+
# @param [Integer] port
|
256
|
+
# The local port to bind to.
|
257
|
+
#
|
258
|
+
# @param [String] host ('0.0.0.0')
|
259
|
+
# The host to bind to.
|
260
|
+
#
|
261
|
+
# @yield [server]
|
262
|
+
# The block which will be called after the server has been created.
|
263
|
+
# After the block has finished, the server will be closed.
|
264
|
+
#
|
265
|
+
# @yieldparam [TCPServer] server
|
266
|
+
# The newly created TCP server.
|
267
|
+
#
|
268
|
+
# @return [nil]
|
269
|
+
#
|
270
|
+
# @example
|
271
|
+
# tcp_server_session(1337) do |server|
|
272
|
+
# client1 = server.accept
|
273
|
+
# client2 = server.accept
|
274
|
+
#
|
275
|
+
# client2.write(server.read_line)
|
276
|
+
#
|
277
|
+
# client1.close
|
278
|
+
# client2.close
|
279
|
+
# end
|
280
|
+
#
|
281
|
+
# @api public
|
282
|
+
#
|
283
|
+
def tcp_server_session(port,host='0.0.0.0',&block)
|
284
|
+
server = tcp_server(port,host,&block)
|
285
|
+
server.close()
|
286
|
+
return nil
|
287
|
+
end
|
288
|
+
|
289
|
+
#
|
290
|
+
# Creates a new TCPServer listening on a given host and port,
|
291
|
+
# accepts only one client and then stops listening.
|
292
|
+
#
|
293
|
+
# @param [Integer] port
|
294
|
+
# After the block has finished, the client and the server will be
|
295
|
+
# closed.
|
296
|
+
#
|
297
|
+
# @yieldparam [TCPSocket] client
|
298
|
+
# The newly connected client.
|
299
|
+
#
|
300
|
+
# @return [nil]
|
301
|
+
#
|
302
|
+
# @example
|
303
|
+
# tcp_single_server(1337) do |client|
|
304
|
+
# client.puts 'lol'
|
305
|
+
# end
|
306
|
+
#
|
307
|
+
# @api public
|
308
|
+
#
|
309
|
+
def tcp_single_server(port,host='0.0.0.0')
|
310
|
+
host = host.to_s
|
311
|
+
|
312
|
+
server = TCPServer.new(host,port)
|
313
|
+
server.listen(1)
|
314
|
+
|
315
|
+
client = server.accept
|
316
|
+
|
317
|
+
yield client if block_given?
|
318
|
+
|
319
|
+
client.close
|
320
|
+
server.close
|
321
|
+
return nil
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|