ronin-support 1.0.0 → 1.0.2

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.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +14 -0
  3. data/.rubocop.yml +109 -0
  4. data/ChangeLog.md +33 -1
  5. data/Gemfile +8 -4
  6. data/README.md +1 -1
  7. data/Rakefile +2 -2
  8. data/examples/ssl_proxy.rb +2 -1
  9. data/examples/tcp_proxy.rb +6 -4
  10. data/lib/ronin/support/archive/core_ext/file.rb +43 -0
  11. data/lib/ronin/support/archive/core_ext.rb +1 -1
  12. data/lib/ronin/support/archive/tar/writer.rb +2 -2
  13. data/lib/ronin/support/archive/tar.rb +4 -4
  14. data/lib/ronin/support/archive/zip/reader.rb +2 -2
  15. data/lib/ronin/support/binary/array.rb +5 -8
  16. data/lib/ronin/support/binary/bit_flip.rb +7 -1
  17. data/lib/ronin/support/binary/buffer.rb +25 -25
  18. data/lib/ronin/support/binary/byte_slice.rb +17 -17
  19. data/lib/ronin/support/binary/core_ext.rb +2 -0
  20. data/lib/ronin/support/binary/cstring.rb +50 -4
  21. data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +4 -0
  22. data/lib/ronin/support/binary/ctypes/arch/arm.rb +3 -0
  23. data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +4 -0
  24. data/lib/ronin/support/binary/ctypes/arch/arm64.rb +3 -0
  25. data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +4 -0
  26. data/lib/ronin/support/binary/ctypes/arch/mips.rb +3 -0
  27. data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +4 -0
  28. data/lib/ronin/support/binary/ctypes/arch/mips64.rb +3 -0
  29. data/lib/ronin/support/binary/ctypes/arch/ppc.rb +3 -0
  30. data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +3 -0
  31. data/lib/ronin/support/binary/ctypes/arch/x86.rb +3 -0
  32. data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +3 -0
  33. data/lib/ronin/support/binary/ctypes/array_type.rb +2 -2
  34. data/lib/ronin/support/binary/ctypes/big_endian.rb +3 -0
  35. data/lib/ronin/support/binary/ctypes/enum_type.rb +2 -2
  36. data/lib/ronin/support/binary/ctypes/little_endian.rb +3 -0
  37. data/lib/ronin/support/binary/ctypes/native.rb +3 -0
  38. data/lib/ronin/support/binary/ctypes/os/bsd.rb +1 -1
  39. data/lib/ronin/support/binary/ctypes/scalar_type.rb +2 -2
  40. data/lib/ronin/support/binary/ctypes/struct_type.rb +3 -3
  41. data/lib/ronin/support/binary/ctypes/type_resolver.rb +7 -8
  42. data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +2 -2
  43. data/lib/ronin/support/binary/ctypes/union_type.rb +3 -3
  44. data/lib/ronin/support/binary/ctypes.rb +3 -3
  45. data/lib/ronin/support/binary/memory.rb +2 -2
  46. data/lib/ronin/support/binary/packet.rb +80 -0
  47. data/lib/ronin/support/binary/stack.rb +6 -7
  48. data/lib/ronin/support/binary/struct/member.rb +5 -3
  49. data/lib/ronin/support/binary/struct.rb +81 -79
  50. data/lib/ronin/support/binary/template.rb +2 -5
  51. data/lib/ronin/support/binary/unhexdump/parser.rb +11 -11
  52. data/lib/ronin/support/binary/union.rb +22 -22
  53. data/lib/ronin/support/binary.rb +1 -0
  54. data/lib/ronin/support/cli/ansi.rb +0 -1
  55. data/lib/ronin/support/cli/io_shell/core_ext/io.rb +1 -1
  56. data/lib/ronin/support/cli/io_shell.rb +4 -4
  57. data/lib/ronin/support/cli/printing.rb +3 -3
  58. data/lib/ronin/support/compression/core_ext/file.rb +16 -0
  59. data/lib/ronin/support/compression/zlib.rb +1 -1
  60. data/lib/ronin/support/core_ext/enumerable.rb +0 -2
  61. data/lib/ronin/support/core_ext/file.rb +1 -1
  62. data/lib/ronin/support/core_ext/kernel.rb +6 -9
  63. data/lib/ronin/support/core_ext/string.rb +2 -2
  64. data/lib/ronin/support/crypto/cert.rb +11 -15
  65. data/lib/ronin/support/crypto/cert_chain.rb +1 -1
  66. data/lib/ronin/support/crypto/cipher/aes.rb +3 -0
  67. data/lib/ronin/support/crypto/cipher/aes128.rb +4 -1
  68. data/lib/ronin/support/crypto/cipher/aes256.rb +4 -1
  69. data/lib/ronin/support/crypto/cipher.rb +1 -1
  70. data/lib/ronin/support/crypto/core_ext/file.rb +33 -1
  71. data/lib/ronin/support/crypto/core_ext/string.rb +34 -2
  72. data/lib/ronin/support/crypto/key/methods.rb +4 -1
  73. data/lib/ronin/support/crypto/key.rb +5 -2
  74. data/lib/ronin/support/crypto/openssl.rb +1 -1
  75. data/lib/ronin/support/crypto.rb +0 -1
  76. data/lib/ronin/support/encoding/base16.rb +2 -2
  77. data/lib/ronin/support/encoding/base32.rb +29 -18
  78. data/lib/ronin/support/encoding/c/core_ext/integer.rb +1 -1
  79. data/lib/ronin/support/encoding/c/core_ext/string.rb +1 -1
  80. data/lib/ronin/support/encoding/c.rb +6 -6
  81. data/lib/ronin/support/encoding/core_ext/string.rb +2 -2
  82. data/lib/ronin/support/encoding/hex/core_ext/string.rb +1 -1
  83. data/lib/ronin/support/encoding/hex.rb +4 -4
  84. data/lib/ronin/support/encoding/js/core_ext/integer.rb +1 -1
  85. data/lib/ronin/support/encoding/js.rb +5 -5
  86. data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +2 -2
  87. data/lib/ronin/support/encoding/powershell.rb +5 -6
  88. data/lib/ronin/support/encoding/quoted_printable.rb +3 -1
  89. data/lib/ronin/support/encoding/ruby.rb +5 -5
  90. data/lib/ronin/support/encoding/shell/core_ext/integer.rb +2 -2
  91. data/lib/ronin/support/encoding/shell.rb +3 -3
  92. data/lib/ronin/support/encoding/sql.rb +1 -1
  93. data/lib/ronin/support/encoding/uuencoding.rb +3 -1
  94. data/lib/ronin/support/encoding/xml.rb +3 -3
  95. data/lib/ronin/support/encoding.rb +95 -0
  96. data/lib/ronin/support/network/asn/list.rb +6 -1
  97. data/lib/ronin/support/network/asn/record.rb +3 -0
  98. data/lib/ronin/support/network/asn/record_set.rb +3 -0
  99. data/lib/ronin/support/network/asn.rb +167 -6
  100. data/lib/ronin/support/network/dns/mixin.rb +2 -10
  101. data/lib/ronin/support/network/dns/resolver.rb +3 -0
  102. data/lib/ronin/support/network/domain.rb +21 -21
  103. data/lib/ronin/support/network/email_address.rb +1 -5
  104. data/lib/ronin/support/network/esmtp/mixin.rb +1 -0
  105. data/lib/ronin/support/network/ftp/mixin.rb +1 -1
  106. data/lib/ronin/support/network/host.rb +75 -47
  107. data/lib/ronin/support/network/http/core_ext/uri/http.rb +8 -0
  108. data/lib/ronin/support/network/http/core_ext.rb +1 -1
  109. data/lib/ronin/support/network/http.rb +317 -80
  110. data/lib/ronin/support/network/ip.rb +49 -23
  111. data/lib/ronin/support/network/ip_range/cidr.rb +1 -5
  112. data/lib/ronin/support/network/ip_range/glob.rb +1 -0
  113. data/lib/ronin/support/network/ip_range/range.rb +1 -1
  114. data/lib/ronin/support/network/ip_range.rb +5 -7
  115. data/lib/ronin/support/network/proxy.rb +4 -4
  116. data/lib/ronin/support/network/public_suffix/list.rb +10 -8
  117. data/lib/ronin/support/network/public_suffix/suffix_set.rb +3 -0
  118. data/lib/ronin/support/network/public_suffix.rb +9 -4
  119. data/lib/ronin/support/network/smtp/email.rb +0 -9
  120. data/lib/ronin/support/network/smtp/mixin.rb +2 -2
  121. data/lib/ronin/support/network/ssl/local_cert.rb +1 -3
  122. data/lib/ronin/support/network/ssl/mixin.rb +13 -13
  123. data/lib/ronin/support/network/ssl/openssl.rb +1 -1
  124. data/lib/ronin/support/network/ssl/proxy.rb +14 -16
  125. data/lib/ronin/support/network/ssl.rb +4 -2
  126. data/lib/ronin/support/network/tcp/proxy.rb +3 -3
  127. data/lib/ronin/support/network/tcp.rb +10 -12
  128. data/lib/ronin/support/network/telnet/mixin.rb +14 -14
  129. data/lib/ronin/support/network/tld/list.rb +2 -1
  130. data/lib/ronin/support/network/tld.rb +7 -4
  131. data/lib/ronin/support/network/tls/proxy.rb +1 -1
  132. data/lib/ronin/support/network/tls.rb +0 -2
  133. data/lib/ronin/support/network/udp/proxy.rb +5 -5
  134. data/lib/ronin/support/network/udp.rb +14 -16
  135. data/lib/ronin/support/path.rb +4 -4
  136. data/lib/ronin/support/text/erb/mixin.rb +3 -0
  137. data/lib/ronin/support/text/homoglyph/core_ext/string.rb +33 -0
  138. data/lib/ronin/support/text/homoglyph/table.rb +3 -3
  139. data/lib/ronin/support/text/patterns/credentials.rb +2 -2
  140. data/lib/ronin/support/text/patterns/crypto.rb +1 -1
  141. data/lib/ronin/support/text/patterns/file_system.rb +3 -4
  142. data/lib/ronin/support/text/patterns/network.rb +21 -21
  143. data/lib/ronin/support/text/patterns/numeric.rb +1 -1
  144. data/lib/ronin/support/text/patterns/source_code.rb +2 -2
  145. data/lib/ronin/support/text/random/mixin.rb +17 -17
  146. data/lib/ronin/support/text/random.rb +25 -25
  147. data/lib/ronin/support/text/typo/core_ext/string.rb +24 -0
  148. data/lib/ronin/support/text/typo/generator.rb +2 -2
  149. data/lib/ronin/support/version.rb +1 -1
  150. data/ronin-support.gemspec +6 -5
  151. metadata +3 -2
@@ -55,10 +55,10 @@ module Ronin
55
55
  #
56
56
  # ip.asn
57
57
  # # => #<Ronin::Support::Network::ASN::DNSRecord:0x00007f34142de598
58
- # @country_code="US",
59
- # @name=nil,
60
- # @number=15133,
61
- # @range=#<Ronin::Support::Network::IPRange::CIDR: 93.184.216.0/24>>
58
+ # # @country_code="US",
59
+ # # @name=nil,
60
+ # # @number=15133,
61
+ # # @range=#<Ronin::Support::Network::IPRange::CIDR: 93.184.216.0/24>>
62
62
  #
63
63
  # @api public
64
64
  #
@@ -66,11 +66,6 @@ module Ronin
66
66
  #
67
67
  class IP < IPAddr
68
68
 
69
- # The address of the IP.
70
- #
71
- # @return [String]
72
- attr_reader :address
73
-
74
69
  #
75
70
  # Initializes the IP address.
76
71
  #
@@ -92,23 +87,46 @@ module Ronin
92
87
  # the IP address.
93
88
  #
94
89
  def initialize(address,family=Socket::AF_UNSPEC)
95
- # XXX: remove the %iface suffix for ruby < 3.1.0
96
- if address.kind_of?(String) && address =~ /%.+$/
97
- address = address.sub(/%.+$/,'')
90
+ case address
91
+ when String
92
+ # XXX: remove the %iface suffix for ruby < 3.1.0
93
+ if address =~ /%.+$/
94
+ address = address.sub(/%.+$/,'')
95
+ end
96
+
97
+ # pre-cache the given IP address String
98
+ @address = address
98
99
  end
99
100
 
100
101
  begin
101
102
  super(address,family)
102
- rescue IPAddr::InvalidAddressError => error
103
+ rescue IPAddr::InvalidAddressError
103
104
  raise(InvalidIP,"invalid IP address: #{address.inspect}")
104
105
  end
106
+ end
105
107
 
106
- @address = case address
107
- when String then address.to_s
108
- else to_s
109
- end
108
+ protected
109
+
110
+ #
111
+ # Sets the IP address using the numeric IP address value.
112
+ #
113
+ # @param [Integer] addr
114
+ # The new numeric IP address value.
115
+ #
116
+ # @param [Integer] family
117
+ # Optional IP address family.
118
+ #
119
+ # @api private
120
+ #
121
+ def set(addr,*family)
122
+ super(addr,*family)
123
+
124
+ # unset the cached IP address since the numeric address has changed
125
+ @address = nil
110
126
  end
111
127
 
128
+ public
129
+
112
130
  # The URI for https://ipinfo.io/ip
113
131
  IPINFO_URI = URI::HTTPS.build(host: 'ipinfo.io', path: '/ip')
114
132
 
@@ -122,6 +140,7 @@ module Ronin
122
140
  response = begin
123
141
  Net::HTTP.get_response(IPINFO_URI)
124
142
  rescue
143
+ # ignore any network failures
125
144
  end
126
145
 
127
146
  if response && response.code == '200'
@@ -230,7 +249,7 @@ module Ronin
230
249
  # IPAddr.extract(text,:v4) do |ip|
231
250
  # puts ip
232
251
  # end
233
- #
252
+ #
234
253
  def self.extract(text,version=nil,&block)
235
254
  return enum_for(__method__,text,version).to_a unless block_given?
236
255
 
@@ -240,10 +259,7 @@ module Ronin
240
259
  else Text::Patterns::IP_ADDR
241
260
  end
242
261
 
243
- text.scan(regexp) do |match|
244
- yield match
245
- end
246
-
262
+ text.scan(regexp,&block)
247
263
  return nil
248
264
  end
249
265
 
@@ -288,6 +304,16 @@ module Ronin
288
304
  ipv4? && (@addr & 0xff) == 0x00
289
305
  end
290
306
 
307
+ #
308
+ # The IP address.
309
+ #
310
+ # @return [String]
311
+ # The String version of the IP address.
312
+ #
313
+ def address
314
+ @address ||= to_s
315
+ end
316
+
291
317
  #
292
318
  # The Autonomous System Number (ASN) information for the IP address.
293
319
  #
@@ -521,8 +547,8 @@ module Ronin
521
547
  end
522
548
 
523
549
  alias canonical to_string
524
- alias to_uint to_i
525
550
  alias to_str to_s
551
+ alias to_uint to_i
526
552
 
527
553
  #
528
554
  # Inspects the IP.
@@ -124,10 +124,9 @@ module Ronin
124
124
  end
125
125
 
126
126
  num_bits = SIZES.fetch(first_ip.family)
127
- mask = MASKS.fetch(first_ip.family)
128
127
  diff_bits = first_ip.to_i ^ last_ip.to_i
129
128
 
130
- if diff_bits != 0
129
+ if diff_bits > 0
131
130
  prefix_length = num_bits - Math.log2(diff_bits).ceil
132
131
 
133
132
  return new("#{first_ip}/#{prefix_length}")
@@ -191,9 +190,6 @@ module Ronin
191
190
  return enum_for(__method__) unless block_given?
192
191
 
193
192
  family_mask = MASKS[@family]
194
- octet_mask = if ipv6? then 0xffff
195
- else 0xff
196
- end
197
193
 
198
194
  (0..((~@mask_addr) & family_mask)).each do |i|
199
195
  ip_uint = (@addr | i)
@@ -265,6 +265,7 @@ module Ronin
265
265
  #
266
266
  def parse_range(range)
267
267
  start, stop = range.split('-',2)
268
+
268
269
  start = start.to_i(@base)
269
270
  stop = stop.to_i(@base)
270
271
 
@@ -76,7 +76,7 @@ module Ronin
76
76
  #
77
77
  # @param [String] last
78
78
  # The last IP address in the ASN IP range.
79
- #
79
+ #
80
80
  # @raise [ArgumentError]
81
81
  # Both IP addresses must be either IPv4 addresses or IPv6 addresses.
82
82
  #
@@ -40,7 +40,7 @@ module Ronin
40
40
  #
41
41
  # Enumerating over a IP-glob range:
42
42
  #
43
- # IPRange.each('10.0.1-3.*/24') { |ip| puts ip }
43
+ # IPRange.each('10.0.1-3.*') { |ip| puts ip }
44
44
  # # 10.0.1.1
45
45
  # # 10.0.1.2
46
46
  # # ...
@@ -75,7 +75,7 @@ module Ronin
75
75
  # ip_range = IPRange.new('10.0.0.1/24')
76
76
  #
77
77
  # @example Initializing an IP-glob range:
78
- # ip_range = IPRange.new('10.0.1-3.*/24')
78
+ # ip_range = IPRange.new('10.0.1-3.*')
79
79
  #
80
80
  def initialize(string)
81
81
  @range = if self.class.glob?(string) then Glob.new(string)
@@ -125,7 +125,7 @@ module Ronin
125
125
  # # 10.0.0.255
126
126
  #
127
127
  # @example Enumerating over a IP-glob range:
128
- # IPRange.each('10.0.1-3.*/24') { |ip| puts ip }
128
+ # IPRange.each('10.0.1-3.*') { |ip| puts ip }
129
129
  # # 10.0.1.1
130
130
  # # 10.0.1.2
131
131
  # # ...
@@ -173,9 +173,7 @@ module Ronin
173
173
  # Indicates that the IP range is a IP-glob range.
174
174
  #
175
175
  def self.glob?(string)
176
- string.include?('*') ||
177
- string.include?(',') ||
178
- string.include?('-')
176
+ string.include?('*') || string.include?(',') || string.include?('-')
179
177
  end
180
178
 
181
179
  #
@@ -230,7 +228,7 @@ module Ronin
230
228
  # # 10.0.0.255
231
229
  #
232
230
  # @example Enumerating over a IP-glob range:
233
- # ip_range = IPRange.new('10.0.1-3.*/24')
231
+ # ip_range = IPRange.new('10.0.1-3.*')
234
232
  # ip_range.each { |ip| puts ip }
235
233
  # # 10.0.1.1
236
234
  # # 10.0.1.2
@@ -75,12 +75,12 @@ module Ronin
75
75
  attr_reader :port
76
76
 
77
77
  # The remote port the proxy will relay data to
78
- #
78
+ #
79
79
  # @return [String]
80
80
  attr_reader :server_host
81
81
 
82
82
  # The remote host the proxy will relay data to
83
- #
83
+ #
84
84
  # @return [Integer]
85
85
  attr_reader :server_port
86
86
 
@@ -130,7 +130,7 @@ module Ronin
130
130
  @port = port
131
131
 
132
132
  @server_host, @server_port = server
133
- @server_port ||= @port
133
+ @server_port ||= @port
134
134
 
135
135
  @callbacks = {client_data: [], server_data: []}
136
136
 
@@ -240,7 +240,7 @@ module Ronin
240
240
  # Closes the proxy.
241
241
  #
242
242
  # @api public
243
- #
243
+ #
244
244
  def close
245
245
  close_connections
246
246
  close_proxy
@@ -149,6 +149,7 @@ module Ronin
149
149
  begin
150
150
  download(url: url, path: path)
151
151
  rescue
152
+ # ignore any network failures
152
153
  end
153
154
  end
154
155
  end
@@ -224,6 +225,7 @@ module Ronin
224
225
 
225
226
  suffix.name.split('.').reverse_each.each_cons(2) do |parent,child|
226
227
  subtree = tree[parent] ||= {}
228
+
227
229
  subtree[child] ||= nil
228
230
 
229
231
  tree = subtree
@@ -313,14 +315,14 @@ module Ronin
313
315
  def tld_regexp(tld,subtree)
314
316
  if subtree
315
317
  subtree_regexp = if subtree.length == 1
316
- tld_regexp(subtree.keys[0],subtree.values[0])
317
- else
318
- Regexp.union(
319
- subtree.map { |sub_tld,sub_subtree|
320
- tld_regexp(sub_tld,sub_subtree)
321
- }
322
- )
323
- end
318
+ tld_regexp(subtree.keys[0],subtree.values[0])
319
+ else
320
+ Regexp.union(
321
+ subtree.map { |sub_tld,sub_subtree|
322
+ tld_regexp(sub_tld,sub_subtree)
323
+ }
324
+ )
325
+ end
324
326
 
325
327
  /(?:#{subtree_regexp}\.)?#{tld}/
326
328
  else
@@ -20,6 +20,9 @@ module Ronin
20
20
  module Support
21
21
  module Network
22
22
  module PublicSuffix
23
+ #
24
+ # A sub-set of public suffixes.
25
+ #
23
26
  class SuffixSet
24
27
 
25
28
  include Enumerable
@@ -21,6 +21,11 @@ require 'ronin/support/network/public_suffix/list'
21
21
  module Ronin
22
22
  module Support
23
23
  module Network
24
+ #
25
+ # Manages the [public suffixes list].
26
+ #
27
+ # [public suffix list]: https://publicsuffix.org/
28
+ #
24
29
  module PublicSuffix
25
30
  #
26
31
  # Downloads/updates then loads the cached file
@@ -30,10 +35,10 @@ module Ronin
30
35
  # The loaded list file.
31
36
  #
32
37
  def self.list
33
- @list ||= (
34
- List.update
35
- List.load_file
36
- )
38
+ @list ||= begin
39
+ List.update
40
+ List.load_file
41
+ end
37
42
  end
38
43
  end
39
44
  end
@@ -137,15 +137,6 @@ module Ronin
137
137
  # @api public
138
138
  #
139
139
  def to_s
140
- address = lambda { |info|
141
- case info
142
- when Array
143
- "#{info[0]} <#{info[1]}>"
144
- else
145
- info
146
- end
147
- }
148
-
149
140
  message = []
150
141
 
151
142
  if @from
@@ -146,8 +146,8 @@ module Ronin
146
146
  ssl: nil,
147
147
  helo: 'localhost',
148
148
  auth: :login)
149
- host = DNS::IDN.to_ascii(host)
150
- user = user.to_s
149
+ host = DNS::IDN.to_ascii(host)
150
+ user = user.to_s
151
151
  password = password.to_s
152
152
 
153
153
  case ssl
@@ -53,7 +53,7 @@ module Ronin
53
53
  subject: {
54
54
  common_name: 'localhost',
55
55
  organization: 'ronin-rb',
56
- organizational_unit: 'ronin-support',
56
+ organizational_unit: 'ronin-support'
57
57
  },
58
58
  extensions: {
59
59
  'subjectAltName' => subject_alt_name
@@ -90,8 +90,6 @@ module Ronin
90
90
  end
91
91
  end
92
92
 
93
- private
94
-
95
93
  #
96
94
  # The value for the `subjectAltName` extension.
97
95
  #
@@ -116,6 +116,7 @@ module Ronin
116
116
  #
117
117
  def ssl_socket(socket,**kwargs)
118
118
  ssl_socket = OpenSSL::SSL::SSLSocket.new(socket,ssl_context(**kwargs))
119
+
119
120
  ssl_socket.sync_close = true
120
121
  return ssl_socket
121
122
  end
@@ -182,19 +183,17 @@ module Ronin
182
183
  #
183
184
  def ssl_open?(host,port, bind_host: nil, bind_port: nil, timeout: 5,
184
185
  **kwargs)
185
- begin
186
- Timeout.timeout(timeout) do
187
- ssl_connect(host,port, bind_host: bind_host,
188
- bind_port: bind_port,
189
- **kwargs)
190
- end
191
-
192
- return true
193
- rescue Timeout::Error
194
- return nil
195
- rescue SocketError, SystemCallError
196
- return false
186
+ Timeout.timeout(timeout) do
187
+ ssl_connect(host,port, bind_host: bind_host,
188
+ bind_port: bind_port,
189
+ **kwargs)
197
190
  end
191
+
192
+ return true
193
+ rescue Timeout::Error
194
+ return nil
195
+ rescue SocketError, SystemCallError
196
+ return false
198
197
  end
199
198
 
200
199
  #
@@ -392,7 +391,8 @@ module Ronin
392
391
  #
393
392
  def ssl_cert(host,port,**kwargs)
394
393
  socket = ssl_connect(host,port,**kwargs)
395
- cert = Crypto::Cert(socket.peer_cert)
394
+ cert = Crypto::Cert(socket.peer_cert)
395
+
396
396
  socket.close
397
397
  return cert
398
398
  end
@@ -18,6 +18,6 @@
18
18
 
19
19
  begin
20
20
  require 'openssl'
21
- rescue ::LoadError
21
+ rescue LoadError
22
22
  warn "WARNING: Ruby was not compiled with OpenSSL support"
23
23
  end
@@ -28,7 +28,7 @@ module Ronin
28
28
  # protocols.
29
29
  #
30
30
  # ## Example
31
- #
31
+ #
32
32
  # require 'ronin/support/network/ssl/proxy'
33
33
  # require 'hexdump'
34
34
  #
@@ -216,7 +216,7 @@ module Ronin
216
216
  #
217
217
  # @param [OpenSSL::SSL::SSLSocket] connection
218
218
  # A SSL connection to write data to.
219
- #
219
+ #
220
220
  # @param [String] data
221
221
  # The data to write.
222
222
  #
@@ -238,11 +238,9 @@ module Ronin
238
238
  # @api public
239
239
  #
240
240
  def recv(connection)
241
- begin
242
- connection.readpartial(@buffer_size)
243
- rescue Errno::ECONNRESET, EOFError
244
- ''
245
- end
241
+ connection.readpartial(@buffer_size)
242
+ rescue Errno::ECONNRESET, EOFError
243
+ ''
246
244
  end
247
245
 
248
246
  #
@@ -252,15 +250,15 @@ module Ronin
252
250
  # The new SSL connection.
253
251
  #
254
252
  def accept_client_connection
255
- client = super
256
- context = SSL.context(version: @version,
257
- key: @key,
258
- key_file: @key_file,
259
- cert: @cert,
260
- cert_file: @cert_file,
261
- verify: @verify)
262
-
253
+ client = super
254
+ context = SSL.context(version: @version,
255
+ key: @key,
256
+ key_file: @key_file,
257
+ cert: @cert,
258
+ cert_file: @cert_file,
259
+ verify: @verify)
263
260
  ssl_socket = OpenSSL::SSL::SSLSocket.new(client,context)
261
+
264
262
  ssl_socket.sync_close = true
265
263
 
266
264
  begin
@@ -281,8 +279,8 @@ module Ronin
281
279
  def open_server_connection
282
280
  server_socket = super
283
281
  context = SSL.context(verify: @verify, ca_bundle: @ca_bundle)
282
+ ssl_socket = OpenSSL::SSL::SSLSocket.new(server_socket,context)
284
283
 
285
- ssl_socket = OpenSSL::SSL::SSLSocket.new(server_socket,context)
286
284
  ssl_socket.sync_close = true
287
285
  ssl_socket.connect
288
286
 
@@ -24,6 +24,9 @@ require 'ronin/support/network/ssl/proxy'
24
24
  module Ronin
25
25
  module Support
26
26
  module Network
27
+ #
28
+ # Top-level SSL methods.
29
+ #
27
30
  module SSL
28
31
  # SSL/TLS versions
29
32
  VERSIONS = {
@@ -136,7 +139,7 @@ module Ronin
136
139
  cert: nil,
137
140
  cert_file: nil,
138
141
  ca_bundle: nil)
139
- context = OpenSSL::SSL::SSLContext.new()
142
+ context = OpenSSL::SSL::SSLContext.new
140
143
 
141
144
  if version
142
145
  context.ssl_version = VERSIONS.fetch(version,version)
@@ -166,7 +169,6 @@ module Ronin
166
169
 
167
170
  return context
168
171
  end
169
-
170
172
  end
171
173
  end
172
174
  end
@@ -28,7 +28,7 @@ module Ronin
28
28
  # The TCP Proxy allows for inspecting and manipulating TCP protocols.
29
29
  #
30
30
  # ## Example
31
- #
31
+ #
32
32
  # require 'ronin/support/network/tcp/proxy'
33
33
  # require 'hexdump'
34
34
  #
@@ -152,7 +152,7 @@ module Ronin
152
152
  def poll
153
153
  sockets = [@socket] + client_connections + server_connections
154
154
 
155
- readable, writtable, errors = IO.select(sockets,nil,sockets)
155
+ readable, _writtable, errors = IO.select(sockets,nil,sockets)
156
156
 
157
157
  (errors & client_connections).each do |client_socket|
158
158
  server_socket = server_connection_for(client_socket)
@@ -200,7 +200,7 @@ module Ronin
200
200
  #
201
201
  # @param [TCPSocket] connection
202
202
  # A TCP connection to write data to.
203
- #
203
+ #
204
204
  # @param [String] data
205
205
  # The data to write.
206
206
  #
@@ -67,18 +67,16 @@ module Ronin
67
67
  # @since 0.5.0
68
68
  #
69
69
  def self.open?(host,port, timeout: 5, **kwargs)
70
- begin
71
- Timeout.timeout(timeout) do
72
- socket = connect(host,port,**kwargs)
73
- socket.close
74
- end
75
-
76
- return true
77
- rescue Timeout::Error
78
- return nil
79
- rescue SocketError, SystemCallError
80
- return false
70
+ Timeout.timeout(timeout) do
71
+ socket = connect(host,port,**kwargs)
72
+ socket.close
81
73
  end
74
+
75
+ return true
76
+ rescue Timeout::Error
77
+ return nil
78
+ rescue SocketError, SystemCallError
79
+ return false
82
80
  end
83
81
 
84
82
  #
@@ -345,7 +343,7 @@ module Ronin
345
343
  #
346
344
  def self.server_session(**kwargs,&block)
347
345
  server = server(**kwargs,&block)
348
- server.close()
346
+ server.close
349
347
  return nil
350
348
  end
351
349
 
@@ -103,20 +103,20 @@ module Ronin
103
103
  # @api public
104
104
  #
105
105
  def telnet_connect(host, # connection options
106
- proxy: Telnet.proxy,
107
- port: Telnet::DEFAULT_PORT,
108
- binmode: false,
109
- wait_time: 0,
110
- prompt: Telnet::DEFAULT_PROMPT,
111
- timeout: Telnet.default_timeout,
112
- telnet: nil,
113
- plain: nil,
114
- # authentication options
115
- user: nil,
116
- password: nil,
117
- # log options
118
- output_log: nil,
119
- dump_log: nil)
106
+ proxy: Telnet.proxy,
107
+ port: Telnet::DEFAULT_PORT,
108
+ binmode: false,
109
+ wait_time: 0,
110
+ prompt: Telnet::DEFAULT_PROMPT,
111
+ timeout: Telnet.default_timeout,
112
+ telnet: nil,
113
+ plain: nil,
114
+ # authentication options
115
+ user: nil,
116
+ password: nil,
117
+ # log options
118
+ output_log: nil,
119
+ dump_log: nil)
120
120
  host = DNS::IDN.to_ascii(host)
121
121
 
122
122
  telnet_options = {
@@ -152,6 +152,7 @@ module Ronin
152
152
  begin
153
153
  download(url: url, path: path)
154
154
  rescue
155
+ # ignore any network failures
155
156
  end
156
157
  end
157
158
  end
@@ -228,7 +229,7 @@ module Ronin
228
229
  end
229
230
 
230
231
  name = host_name[0...index]
231
- tld = host_name[(index+1)..]
232
+ tld = host_name[(index + 1)..]
232
233
 
233
234
  unless @list.include?(tld)
234
235
  raise(InvalidHostname,"hostname does not have a valid TLD: #{host_name.inspect}")
@@ -21,6 +21,9 @@ require 'ronin/support/network/tld/list'
21
21
  module Ronin
22
22
  module Support
23
23
  module Network
24
+ #
25
+ # Manages the list of Top-Level-Domains (TLDs).
26
+ #
24
27
  module TLD
25
28
  #
26
29
  # Downloads/updates then loads the cached file
@@ -30,10 +33,10 @@ module Ronin
30
33
  # The loaded list file.
31
34
  #
32
35
  def self.list
33
- @list ||= (
34
- List.update
35
- List.load_file
36
- )
36
+ @list ||= begin
37
+ List.update
38
+ List.load_file
39
+ end
37
40
  end
38
41
  end
39
42
  end