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.
Files changed (37) hide show
  1. data/ChangeLog.md +17 -0
  2. data/Gemfile +5 -5
  3. data/README.md +10 -9
  4. data/Rakefile +1 -0
  5. data/gemspec.yml +2 -2
  6. data/lib/ronin/formatting/extensions/binary/string.rb +1 -2
  7. data/lib/ronin/network.rb +1 -0
  8. data/lib/ronin/network/extensions.rb +2 -0
  9. data/lib/ronin/network/extensions/dns.rb +20 -0
  10. data/lib/ronin/network/extensions/dns/net.rb +24 -0
  11. data/lib/ronin/network/extensions/http/uri/http.rb +47 -45
  12. data/lib/ronin/network/http/http.rb +26 -25
  13. data/lib/ronin/network/mixins/dns.rb +1 -1
  14. data/lib/ronin/network/mixins/esmtp.rb +3 -1
  15. data/lib/ronin/network/mixins/http.rb +23 -21
  16. data/lib/ronin/network/mixins/imap.rb +3 -1
  17. data/lib/ronin/network/mixins/pop3.rb +3 -1
  18. data/lib/ronin/network/mixins/smtp.rb +3 -1
  19. data/lib/ronin/network/mixins/ssl.rb +5 -1
  20. data/lib/ronin/network/mixins/tcp.rb +17 -1
  21. data/lib/ronin/network/mixins/telnet.rb +3 -1
  22. data/lib/ronin/network/mixins/udp.rb +12 -0
  23. data/lib/ronin/network/smtp/smtp.rb +2 -2
  24. data/lib/ronin/network/ssl.rb +122 -117
  25. data/lib/ronin/network/tcp.rb +9 -9
  26. data/lib/ronin/network/telnet.rb +1 -1
  27. data/lib/ronin/network/udp.rb +7 -7
  28. data/lib/ronin/support/support.rb +1 -0
  29. data/lib/ronin/support/version.rb +1 -1
  30. data/lib/ronin/ui/output/output.rb +1 -1
  31. data/lib/ronin/ui/output/terminal/color.rb +5 -5
  32. data/lib/ronin/ui/output/terminal/raw.rb +5 -5
  33. data/spec/extensions/string_spec.rb +14 -12
  34. data/spec/network/dns_spec.rb +6 -6
  35. data/spec/network/tcp_spec.rb +25 -22
  36. data/spec/network/udp_spec.rb +24 -21
  37. metadata +25 -23
@@ -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
- extend TCP
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
- # 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]
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
- socket = tcp_connect(host,port,local_host,local_port)
111
+ socket = tcp_connect(host,port,local_host,local_port)
110
112
 
111
- ssl_context = OpenSSL::SSL::SSLContext.new()
112
- ssl_context.verify_mode = SSL::VERIFY[options[:verify]]
113
+ ssl_context = OpenSSL::SSL::SSLContext.new()
114
+ ssl_context.verify_mode = SSL::VERIFY[options[:verify]]
113
115
 
114
- if options[:cert]
115
- cert_file = File.new(options[:cert])
116
- ssl_context.cert = OpenSSL::X509::Certificate.new(cert_file)
117
- end
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
- if options[:key]
120
- key_file = File.new(options[:key])
121
- ssl_context.key = OpenSSL::PKey::RSA.new(key_file)
122
- end
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
- ssl_socket = OpenSSL::SSL::SSLSocket.new(socket,ssl_context)
125
- ssl_socket.sync_close = true
126
- ssl_socket.connect
126
+ ssl_socket = OpenSSL::SSL::SSLSocket.new(socket,ssl_context)
127
+ ssl_socket.sync_close = true
128
+ ssl_socket.connect
127
129
 
128
- yield ssl_socket if block_given?
129
- return ssl_socket
130
- end
130
+ yield ssl_socket if block_given?
131
+ return ssl_socket
132
+ end
131
133
 
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,options={},&block)
177
- ssl_socket = ssl_connect(host,port,options,&block)
178
- ssl_socket.close
179
- return nil
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
@@ -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 /\n\n")
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=nil)
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=nil)
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=nil)
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=nil)
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=nil)
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=nil,host=nil)
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=nil,host=nil,&block)
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=nil,host=nil)
308
+ def tcp_single_server(port=0,host=nil)
309
309
  host = host.to_s
310
310
 
311
311
  server = TCPServer.new(host,port)
@@ -243,7 +243,7 @@ module Ronin
243
243
  # movie.each_line { |line| puts line }
244
244
  # end
245
245
  #
246
- # @see telnet_session
246
+ # @see #telnet_connect
247
247
  #
248
248
  # @api public
249
249
  #
@@ -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=nil)
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=nil)
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=nil)
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=nil)
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=nil)
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=nil,host=nil)
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=nil,host=nil,&block)
277
+ def udp_server_session(port=0,host=nil,&block)
278
278
  server = udp_server(port,host,&block)
279
279
 
280
280
  server.close()
@@ -29,6 +29,7 @@ module Ronin
29
29
  include Network::DNS
30
30
  include Network::TCP
31
31
  include Network::UDP
32
+ include Network::SSL
32
33
  include Network::SMTP
33
34
  include Network::ESMTP
34
35
  include Network::POP3
@@ -20,6 +20,6 @@
20
20
  module Ronin
21
21
  module Support
22
22
  # ronin-support version
23
- VERSION = '0.4.0'
23
+ VERSION = '0.4.1'
24
24
  end
25
25
  end
@@ -32,7 +32,7 @@ module Ronin
32
32
  :quiet
33
33
  end
34
34
 
35
- @handler = if STDOUT.tty?
35
+ @handler = if $stdout.tty?
36
36
  Terminal::Color
37
37
  else
38
38
  Terminal::Raw
@@ -52,7 +52,7 @@ module Ronin
52
52
  # @api private
53
53
  #
54
54
  def self.write(data)
55
- STDOUT.write(data)
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