ronin-support 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +14 -0
- data/.rubocop.yml +109 -0
- data/ChangeLog.md +33 -1
- data/Gemfile +8 -4
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/examples/ssl_proxy.rb +2 -1
- data/examples/tcp_proxy.rb +6 -4
- data/lib/ronin/support/archive/core_ext/file.rb +43 -0
- data/lib/ronin/support/archive/core_ext.rb +1 -1
- data/lib/ronin/support/archive/tar/writer.rb +2 -2
- data/lib/ronin/support/archive/tar.rb +4 -4
- data/lib/ronin/support/archive/zip/reader.rb +2 -2
- data/lib/ronin/support/binary/array.rb +5 -8
- data/lib/ronin/support/binary/bit_flip.rb +7 -1
- data/lib/ronin/support/binary/buffer.rb +25 -25
- data/lib/ronin/support/binary/byte_slice.rb +17 -17
- data/lib/ronin/support/binary/core_ext.rb +2 -0
- data/lib/ronin/support/binary/cstring.rb +50 -4
- data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +4 -0
- data/lib/ronin/support/binary/ctypes/arch/arm.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +4 -0
- data/lib/ronin/support/binary/ctypes/arch/arm64.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +4 -0
- data/lib/ronin/support/binary/ctypes/arch/mips.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +4 -0
- data/lib/ronin/support/binary/ctypes/arch/mips64.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/ppc.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/x86.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +3 -0
- data/lib/ronin/support/binary/ctypes/array_type.rb +2 -2
- data/lib/ronin/support/binary/ctypes/big_endian.rb +3 -0
- data/lib/ronin/support/binary/ctypes/enum_type.rb +2 -2
- data/lib/ronin/support/binary/ctypes/little_endian.rb +3 -0
- data/lib/ronin/support/binary/ctypes/native.rb +3 -0
- data/lib/ronin/support/binary/ctypes/os/bsd.rb +1 -1
- data/lib/ronin/support/binary/ctypes/scalar_type.rb +2 -2
- data/lib/ronin/support/binary/ctypes/struct_type.rb +3 -3
- data/lib/ronin/support/binary/ctypes/type_resolver.rb +7 -8
- data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +2 -2
- data/lib/ronin/support/binary/ctypes/union_type.rb +3 -3
- data/lib/ronin/support/binary/ctypes.rb +3 -3
- data/lib/ronin/support/binary/memory.rb +2 -2
- data/lib/ronin/support/binary/packet.rb +80 -0
- data/lib/ronin/support/binary/stack.rb +6 -7
- data/lib/ronin/support/binary/struct/member.rb +5 -3
- data/lib/ronin/support/binary/struct.rb +81 -79
- data/lib/ronin/support/binary/template.rb +2 -5
- data/lib/ronin/support/binary/unhexdump/parser.rb +11 -11
- data/lib/ronin/support/binary/union.rb +22 -22
- data/lib/ronin/support/binary.rb +1 -0
- data/lib/ronin/support/cli/ansi.rb +0 -1
- data/lib/ronin/support/cli/io_shell/core_ext/io.rb +1 -1
- data/lib/ronin/support/cli/io_shell.rb +4 -4
- data/lib/ronin/support/cli/printing.rb +3 -3
- data/lib/ronin/support/compression/core_ext/file.rb +16 -0
- data/lib/ronin/support/compression/zlib.rb +1 -1
- data/lib/ronin/support/core_ext/enumerable.rb +0 -2
- data/lib/ronin/support/core_ext/file.rb +1 -1
- data/lib/ronin/support/core_ext/kernel.rb +6 -9
- data/lib/ronin/support/core_ext/string.rb +2 -2
- data/lib/ronin/support/crypto/cert.rb +11 -15
- data/lib/ronin/support/crypto/cert_chain.rb +1 -1
- data/lib/ronin/support/crypto/cipher/aes.rb +3 -0
- data/lib/ronin/support/crypto/cipher/aes128.rb +4 -1
- data/lib/ronin/support/crypto/cipher/aes256.rb +4 -1
- data/lib/ronin/support/crypto/cipher.rb +1 -1
- data/lib/ronin/support/crypto/core_ext/file.rb +33 -1
- data/lib/ronin/support/crypto/core_ext/string.rb +34 -2
- data/lib/ronin/support/crypto/key/methods.rb +4 -1
- data/lib/ronin/support/crypto/key.rb +5 -2
- data/lib/ronin/support/crypto/openssl.rb +1 -1
- data/lib/ronin/support/crypto.rb +0 -1
- data/lib/ronin/support/encoding/base16.rb +2 -2
- data/lib/ronin/support/encoding/base32.rb +29 -18
- data/lib/ronin/support/encoding/c/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/c/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/c.rb +6 -6
- data/lib/ronin/support/encoding/core_ext/string.rb +2 -2
- data/lib/ronin/support/encoding/hex/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/hex.rb +4 -4
- data/lib/ronin/support/encoding/js/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/js.rb +5 -5
- data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +2 -2
- data/lib/ronin/support/encoding/powershell.rb +5 -6
- data/lib/ronin/support/encoding/quoted_printable.rb +3 -1
- data/lib/ronin/support/encoding/ruby.rb +5 -5
- data/lib/ronin/support/encoding/shell/core_ext/integer.rb +2 -2
- data/lib/ronin/support/encoding/shell.rb +3 -3
- data/lib/ronin/support/encoding/sql.rb +1 -1
- data/lib/ronin/support/encoding/uuencoding.rb +3 -1
- data/lib/ronin/support/encoding/xml.rb +3 -3
- data/lib/ronin/support/encoding.rb +95 -0
- data/lib/ronin/support/network/asn/list.rb +6 -1
- data/lib/ronin/support/network/asn/record.rb +3 -0
- data/lib/ronin/support/network/asn/record_set.rb +3 -0
- data/lib/ronin/support/network/asn.rb +167 -6
- data/lib/ronin/support/network/dns/mixin.rb +2 -10
- data/lib/ronin/support/network/dns/resolver.rb +3 -0
- data/lib/ronin/support/network/domain.rb +21 -21
- data/lib/ronin/support/network/email_address.rb +1 -5
- data/lib/ronin/support/network/esmtp/mixin.rb +1 -0
- data/lib/ronin/support/network/ftp/mixin.rb +1 -1
- data/lib/ronin/support/network/host.rb +75 -47
- data/lib/ronin/support/network/http/core_ext/uri/http.rb +8 -0
- data/lib/ronin/support/network/http/core_ext.rb +1 -1
- data/lib/ronin/support/network/http.rb +317 -80
- data/lib/ronin/support/network/ip.rb +49 -23
- data/lib/ronin/support/network/ip_range/cidr.rb +1 -5
- data/lib/ronin/support/network/ip_range/glob.rb +1 -0
- data/lib/ronin/support/network/ip_range/range.rb +1 -1
- data/lib/ronin/support/network/ip_range.rb +5 -7
- data/lib/ronin/support/network/proxy.rb +4 -4
- data/lib/ronin/support/network/public_suffix/list.rb +10 -8
- data/lib/ronin/support/network/public_suffix/suffix_set.rb +3 -0
- data/lib/ronin/support/network/public_suffix.rb +9 -4
- data/lib/ronin/support/network/smtp/email.rb +0 -9
- data/lib/ronin/support/network/smtp/mixin.rb +2 -2
- data/lib/ronin/support/network/ssl/local_cert.rb +1 -3
- data/lib/ronin/support/network/ssl/mixin.rb +13 -13
- data/lib/ronin/support/network/ssl/openssl.rb +1 -1
- data/lib/ronin/support/network/ssl/proxy.rb +14 -16
- data/lib/ronin/support/network/ssl.rb +4 -2
- data/lib/ronin/support/network/tcp/proxy.rb +3 -3
- data/lib/ronin/support/network/tcp.rb +10 -12
- data/lib/ronin/support/network/telnet/mixin.rb +14 -14
- data/lib/ronin/support/network/tld/list.rb +2 -1
- data/lib/ronin/support/network/tld.rb +7 -4
- data/lib/ronin/support/network/tls/proxy.rb +1 -1
- data/lib/ronin/support/network/tls.rb +0 -2
- data/lib/ronin/support/network/udp/proxy.rb +5 -5
- data/lib/ronin/support/network/udp.rb +14 -16
- data/lib/ronin/support/path.rb +4 -4
- data/lib/ronin/support/text/erb/mixin.rb +3 -0
- data/lib/ronin/support/text/homoglyph/core_ext/string.rb +33 -0
- data/lib/ronin/support/text/homoglyph/table.rb +3 -3
- data/lib/ronin/support/text/patterns/credentials.rb +2 -2
- data/lib/ronin/support/text/patterns/crypto.rb +1 -1
- data/lib/ronin/support/text/patterns/file_system.rb +3 -4
- data/lib/ronin/support/text/patterns/network.rb +21 -21
- data/lib/ronin/support/text/patterns/numeric.rb +1 -1
- data/lib/ronin/support/text/patterns/source_code.rb +2 -2
- data/lib/ronin/support/text/random/mixin.rb +17 -17
- data/lib/ronin/support/text/random.rb +25 -25
- data/lib/ronin/support/text/typo/core_ext/string.rb +24 -0
- data/lib/ronin/support/text/typo/generator.rb +2 -2
- data/lib/ronin/support/version.rb +1 -1
- data/ronin-support.gemspec +6 -5
- metadata +3 -2
@@ -55,10 +55,10 @@ module Ronin
|
|
55
55
|
#
|
56
56
|
# ip.asn
|
57
57
|
# # => #<Ronin::Support::Network::ASN::DNSRecord:0x00007f34142de598
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
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
|
-
|
96
|
-
|
97
|
-
|
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
|
103
|
+
rescue IPAddr::InvalidAddressError
|
103
104
|
raise(InvalidIP,"invalid IP address: #{address.inspect}")
|
104
105
|
end
|
106
|
+
end
|
105
107
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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)
|
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
|
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)
|
@@ -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
|
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
|
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
|
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
|
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
|
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
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
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
|
@@ -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
|
-
|
35
|
-
|
36
|
-
|
38
|
+
@list ||= begin
|
39
|
+
List.update
|
40
|
+
List.load_file
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
@@ -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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
394
|
+
cert = Crypto::Cert(socket.peer_cert)
|
395
|
+
|
396
396
|
socket.close
|
397
397
|
return cert
|
398
398
|
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
|
-
|
242
|
-
|
243
|
-
|
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
|
256
|
-
context
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
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,
|
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
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
36
|
+
@list ||= begin
|
37
|
+
List.update
|
38
|
+
List.load_file
|
39
|
+
end
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|