ronin-support 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +17 -0
- data/Gemfile +5 -5
- data/README.md +10 -9
- data/Rakefile +1 -0
- data/gemspec.yml +2 -2
- data/lib/ronin/formatting/extensions/binary/string.rb +1 -2
- data/lib/ronin/network.rb +1 -0
- data/lib/ronin/network/extensions.rb +2 -0
- data/lib/ronin/network/extensions/dns.rb +20 -0
- data/lib/ronin/network/extensions/dns/net.rb +24 -0
- data/lib/ronin/network/extensions/http/uri/http.rb +47 -45
- data/lib/ronin/network/http/http.rb +26 -25
- data/lib/ronin/network/mixins/dns.rb +1 -1
- data/lib/ronin/network/mixins/esmtp.rb +3 -1
- data/lib/ronin/network/mixins/http.rb +23 -21
- data/lib/ronin/network/mixins/imap.rb +3 -1
- data/lib/ronin/network/mixins/pop3.rb +3 -1
- data/lib/ronin/network/mixins/smtp.rb +3 -1
- data/lib/ronin/network/mixins/ssl.rb +5 -1
- data/lib/ronin/network/mixins/tcp.rb +17 -1
- data/lib/ronin/network/mixins/telnet.rb +3 -1
- data/lib/ronin/network/mixins/udp.rb +12 -0
- data/lib/ronin/network/smtp/smtp.rb +2 -2
- data/lib/ronin/network/ssl.rb +122 -117
- data/lib/ronin/network/tcp.rb +9 -9
- data/lib/ronin/network/telnet.rb +1 -1
- data/lib/ronin/network/udp.rb +7 -7
- data/lib/ronin/support/support.rb +1 -0
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/ui/output/output.rb +1 -1
- data/lib/ronin/ui/output/terminal/color.rb +5 -5
- data/lib/ronin/ui/output/terminal/raw.rb +5 -5
- data/spec/extensions/string_spec.rb +14 -12
- data/spec/network/dns_spec.rb +6 -6
- data/spec/network/tcp_spec.rb +25 -22
- data/spec/network/udp_spec.rb +24 -21
- metadata +25 -23
data/lib/ronin/network/ssl.rb
CHANGED
@@ -22,6 +22,7 @@ require 'ronin/network/tcp'
|
|
22
22
|
begin
|
23
23
|
require 'openssl'
|
24
24
|
rescue ::LoadError
|
25
|
+
$stderr.puts "WARNING: Ruby was not compiled with OpenSSL support"
|
25
26
|
end
|
26
27
|
|
27
28
|
module Ronin
|
@@ -30,7 +31,7 @@ module Ronin
|
|
30
31
|
# Provides helper methods for communicating with SSL-enabled services.
|
31
32
|
#
|
32
33
|
module SSL
|
33
|
-
|
34
|
+
include TCP
|
34
35
|
|
35
36
|
# Maps SSL verify modes to `OpenSSL::SSL::VERIFY_*` constants.
|
36
37
|
#
|
@@ -53,130 +54,134 @@ module Ronin
|
|
53
54
|
|
54
55
|
hash[key] = OpenSSL::SSL.const_get(verify_const)
|
55
56
|
end
|
56
|
-
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
+
# @see http://rubydoc.info/stdlib/openssl/OpenSSL/SSL/SSLSocket
|
104
|
+
#
|
105
|
+
# @api public
|
106
|
+
#
|
107
|
+
def ssl_connect(host,port,options={})
|
108
|
+
local_host = options[:local_host]
|
109
|
+
local_port = options[:local_port]
|
108
110
|
|
109
|
-
|
111
|
+
socket = tcp_connect(host,port,local_host,local_port)
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
+
ssl_context = OpenSSL::SSL::SSLContext.new()
|
114
|
+
ssl_context.verify_mode = SSL::VERIFY[options[:verify]]
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
if options[:cert]
|
117
|
+
cert_file = File.new(options[:cert])
|
118
|
+
ssl_context.cert = OpenSSL::X509::Certificate.new(cert_file)
|
119
|
+
end
|
118
120
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
if options[:key]
|
122
|
+
key_file = File.new(options[:key])
|
123
|
+
ssl_context.key = OpenSSL::PKey::RSA.new(key_file)
|
124
|
+
end
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
126
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket,ssl_context)
|
127
|
+
ssl_socket.sync_close = true
|
128
|
+
ssl_socket.connect
|
127
129
|
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
yield ssl_socket if block_given?
|
131
|
+
return ssl_socket
|
132
|
+
end
|
131
133
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
134
|
+
#
|
135
|
+
# Creates a new temporary SSL connection.
|
136
|
+
#
|
137
|
+
# @param [String] host
|
138
|
+
# The host to connect to.
|
139
|
+
#
|
140
|
+
# @param [Integer] port
|
141
|
+
# The port to connect to.
|
142
|
+
#
|
143
|
+
# @param [Hash] options
|
144
|
+
# Additional options.
|
145
|
+
#
|
146
|
+
# @option options [String] :local_host
|
147
|
+
# The local host to bind to.
|
148
|
+
#
|
149
|
+
# @option options [Integer] :local_port
|
150
|
+
# The local port to bind to.
|
151
|
+
#
|
152
|
+
# @option options [Symbol] :verify
|
153
|
+
# Specifies whether to verify the SSL certificate.
|
154
|
+
#
|
155
|
+
# @option options [String] :cert
|
156
|
+
# The path to the SSL certificate.
|
157
|
+
#
|
158
|
+
# @option options [String] :key
|
159
|
+
# The path to the SSL key.
|
160
|
+
#
|
161
|
+
# @yield [ssl_socket]
|
162
|
+
# The given block will be passed the temporary SSL Socket.
|
163
|
+
#
|
164
|
+
# @yieldparam [OpenSSL::SSL::SSLSocket] ssl_socket
|
165
|
+
# The temporary SSL Socket.
|
166
|
+
#
|
167
|
+
# @return [nil]
|
168
|
+
#
|
169
|
+
# @example
|
170
|
+
# ssl_session('twitter.com',443) do |sock|
|
171
|
+
# sock.write("GET / HTTP/1.1\n\r\n\r")
|
172
|
+
#
|
173
|
+
# sock.each_line { |line| puts line }
|
174
|
+
# end
|
175
|
+
#
|
176
|
+
# @see http://rubydoc.info/stdlib/openssl/OpenSSL/SSL/SSLSocket
|
177
|
+
#
|
178
|
+
# @api public
|
179
|
+
#
|
180
|
+
def ssl_session(host,port,options={},&block)
|
181
|
+
ssl_socket = ssl_connect(host,port,options,&block)
|
182
|
+
ssl_socket.close
|
183
|
+
return nil
|
184
|
+
end
|
180
185
|
end
|
181
186
|
end
|
182
187
|
end
|
data/lib/ronin/network/tcp.rb
CHANGED
@@ -54,7 +54,7 @@ module Ronin
|
|
54
54
|
#
|
55
55
|
# @example
|
56
56
|
# tcp_connect('www.wired.com',80) do |socket|
|
57
|
-
# socket.write("GET
|
57
|
+
# socket.write("GET / HTTP/1.1\n\r\n\r")
|
58
58
|
#
|
59
59
|
# puts socket.readlines
|
60
60
|
# socket.close
|
@@ -62,7 +62,7 @@ module Ronin
|
|
62
62
|
#
|
63
63
|
# @api public
|
64
64
|
#
|
65
|
-
def tcp_connect(host,port,local_host=nil,local_port=
|
65
|
+
def tcp_connect(host,port,local_host=nil,local_port=0)
|
66
66
|
host = host.to_s
|
67
67
|
local_host = (local_host || '0.0.0.0').to_s
|
68
68
|
|
@@ -99,7 +99,7 @@ module Ronin
|
|
99
99
|
#
|
100
100
|
# @api public
|
101
101
|
#
|
102
|
-
def tcp_connect_and_send(data,host,port,local_host=nil,local_port=
|
102
|
+
def tcp_connect_and_send(data,host,port,local_host=nil,local_port=0)
|
103
103
|
socket = tcp_connect(host,port,local_host,local_port)
|
104
104
|
socket.write(data)
|
105
105
|
|
@@ -134,7 +134,7 @@ module Ronin
|
|
134
134
|
#
|
135
135
|
# @api public
|
136
136
|
#
|
137
|
-
def tcp_session(host,port,local_host=nil,local_port=
|
137
|
+
def tcp_session(host,port,local_host=nil,local_port=0)
|
138
138
|
socket = tcp_connect(host,port,local_host,local_port)
|
139
139
|
|
140
140
|
yield socket if block_given?
|
@@ -173,7 +173,7 @@ module Ronin
|
|
173
173
|
#
|
174
174
|
# @api public
|
175
175
|
#
|
176
|
-
def tcp_banner(host,port,local_host=nil,local_port=
|
176
|
+
def tcp_banner(host,port,local_host=nil,local_port=0)
|
177
177
|
banner = nil
|
178
178
|
|
179
179
|
tcp_session(host,port,local_host,local_port) do |socket|
|
@@ -213,7 +213,7 @@ module Ronin
|
|
213
213
|
#
|
214
214
|
# @api public
|
215
215
|
#
|
216
|
-
def tcp_send(data,host,port,local_host=nil,local_port=
|
216
|
+
def tcp_send(data,host,port,local_host=nil,local_port=0)
|
217
217
|
tcp_session(host,port,local_host,local_port) do |socket|
|
218
218
|
socket.write(data)
|
219
219
|
end
|
@@ -238,7 +238,7 @@ module Ronin
|
|
238
238
|
#
|
239
239
|
# @api public
|
240
240
|
#
|
241
|
-
def tcp_server(port=
|
241
|
+
def tcp_server(port=0,host=nil)
|
242
242
|
host = (host || '0.0.0.0').to_s
|
243
243
|
|
244
244
|
server = TCPServer.new(host,port)
|
@@ -279,7 +279,7 @@ module Ronin
|
|
279
279
|
#
|
280
280
|
# @api public
|
281
281
|
#
|
282
|
-
def tcp_server_session(port=
|
282
|
+
def tcp_server_session(port=0,host=nil,&block)
|
283
283
|
server = tcp_server(port,host,&block)
|
284
284
|
server.close()
|
285
285
|
return nil
|
@@ -305,7 +305,7 @@ module Ronin
|
|
305
305
|
#
|
306
306
|
# @api public
|
307
307
|
#
|
308
|
-
def tcp_single_server(port=
|
308
|
+
def tcp_single_server(port=0,host=nil)
|
309
309
|
host = host.to_s
|
310
310
|
|
311
311
|
server = TCPServer.new(host,port)
|
data/lib/ronin/network/telnet.rb
CHANGED
data/lib/ronin/network/udp.rb
CHANGED
@@ -60,7 +60,7 @@ module Ronin
|
|
60
60
|
#
|
61
61
|
# @api public
|
62
62
|
#
|
63
|
-
def udp_connect(host,port,local_host=nil,local_port=
|
63
|
+
def udp_connect(host,port,local_host=nil,local_port=0)
|
64
64
|
host = host.to_s
|
65
65
|
local_host = (local_host || '0.0.0.0').to_s
|
66
66
|
|
@@ -102,7 +102,7 @@ module Ronin
|
|
102
102
|
#
|
103
103
|
# @api public
|
104
104
|
#
|
105
|
-
def udp_connect_and_send(data,host,port,local_host=nil,local_port=
|
105
|
+
def udp_connect_and_send(data,host,port,local_host=nil,local_port=0)
|
106
106
|
socket = udp_connect(host,port,local_host,local_port)
|
107
107
|
socket.write(data)
|
108
108
|
|
@@ -137,7 +137,7 @@ module Ronin
|
|
137
137
|
#
|
138
138
|
# @api public
|
139
139
|
#
|
140
|
-
def udp_session(host,port,local_host=nil,local_port=
|
140
|
+
def udp_session(host,port,local_host=nil,local_port=0)
|
141
141
|
socket = udp_connect(host,port,local_host,local_port)
|
142
142
|
|
143
143
|
yield socket if block_given?
|
@@ -177,7 +177,7 @@ module Ronin
|
|
177
177
|
#
|
178
178
|
# @since 0.4.0
|
179
179
|
#
|
180
|
-
def udp_send(data,host,port,local_host=nil,local_port=
|
180
|
+
def udp_send(data,host,port,local_host=nil,local_port=0)
|
181
181
|
udp_session(host,port,local_host,local_port) do |socket|
|
182
182
|
socket.write(data)
|
183
183
|
end
|
@@ -211,7 +211,7 @@ module Ronin
|
|
211
211
|
#
|
212
212
|
# @api public
|
213
213
|
#
|
214
|
-
def udp_banner(host,port,local_host=nil,local_port=
|
214
|
+
def udp_banner(host,port,local_host=nil,local_port=0)
|
215
215
|
banner = nil
|
216
216
|
|
217
217
|
udp_session(host,port,local_host,local_port) do |socket|
|
@@ -239,7 +239,7 @@ module Ronin
|
|
239
239
|
#
|
240
240
|
# @api public
|
241
241
|
#
|
242
|
-
def udp_server(port=
|
242
|
+
def udp_server(port=0,host=nil)
|
243
243
|
host = (host || '0.0.0.0').to_s
|
244
244
|
server = UDPSocket.new
|
245
245
|
|
@@ -274,7 +274,7 @@ module Ronin
|
|
274
274
|
#
|
275
275
|
# @api public
|
276
276
|
#
|
277
|
-
def udp_server_session(port=
|
277
|
+
def udp_server_session(port=0,host=nil,&block)
|
278
278
|
server = udp_server(port,host,&block)
|
279
279
|
|
280
280
|
server.close()
|
@@ -52,7 +52,7 @@ module Ronin
|
|
52
52
|
# @api private
|
53
53
|
#
|
54
54
|
def self.write(data)
|
55
|
-
|
55
|
+
$stdout.write(data)
|
56
56
|
end
|
57
57
|
|
58
58
|
#
|
@@ -66,7 +66,7 @@ module Ronin
|
|
66
66
|
# @api private
|
67
67
|
#
|
68
68
|
def self.print_info(message)
|
69
|
-
puts "#{GREEN}[-] #{message}#{CLEAR}"
|
69
|
+
$stdout.puts "#{GREEN}[-] #{message}#{CLEAR}"
|
70
70
|
end
|
71
71
|
|
72
72
|
#
|
@@ -80,7 +80,7 @@ module Ronin
|
|
80
80
|
# @api private
|
81
81
|
#
|
82
82
|
def self.print_debug(message)
|
83
|
-
puts "#{CYAN}[=] #{message}#{CLEAR}"
|
83
|
+
$stdout.puts "#{CYAN}[=] #{message}#{CLEAR}"
|
84
84
|
end
|
85
85
|
|
86
86
|
#
|
@@ -94,7 +94,7 @@ module Ronin
|
|
94
94
|
# @api private
|
95
95
|
#
|
96
96
|
def self.print_warning(message)
|
97
|
-
puts "#{YELLOW}[*] #{message}#{CLEAR}"
|
97
|
+
$stdout.puts "#{YELLOW}[*] #{message}#{CLEAR}"
|
98
98
|
end
|
99
99
|
|
100
100
|
#
|
@@ -108,7 +108,7 @@ module Ronin
|
|
108
108
|
# @api private
|
109
109
|
#
|
110
110
|
def self.print_error(message)
|
111
|
-
puts "#{RED}[!] #{message}#{CLEAR}"
|
111
|
+
$stdout.puts "#{RED}[!] #{message}#{CLEAR}"
|
112
112
|
end
|
113
113
|
|
114
114
|
end
|