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.
- 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
@@ -37,7 +37,7 @@ module Ronin
|
|
37
37
|
# member :c, :char
|
38
38
|
# member :i, :int16
|
39
39
|
# member :u, :uint32
|
40
|
-
#
|
40
|
+
#
|
41
41
|
# end
|
42
42
|
#
|
43
43
|
# ### Initializing Fields
|
@@ -54,19 +54,19 @@ module Ronin
|
|
54
54
|
# member :c, :char
|
55
55
|
# member :i, :int16
|
56
56
|
# member :u, :uint32
|
57
|
-
#
|
57
|
+
#
|
58
58
|
# end
|
59
|
-
#
|
59
|
+
#
|
60
60
|
# class MyUnion2 < MyUnion
|
61
|
-
#
|
61
|
+
#
|
62
62
|
# member :f, :float32
|
63
63
|
# member :d, :float64
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# end
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# union = MyUnion.new
|
68
68
|
# union.i = -1
|
69
|
-
#
|
69
|
+
#
|
70
70
|
# union2 = MyUnion.new
|
71
71
|
# union2.i = -1
|
72
72
|
# union2.d = 1.123
|
@@ -74,13 +74,13 @@ module Ronin
|
|
74
74
|
# ### Packing Unions
|
75
75
|
#
|
76
76
|
# class MyUnion < Ronin::Support::Binary::Union
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# member :c, :char
|
79
79
|
# member :i, :int16
|
80
80
|
# member :u, :uint32
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# end
|
83
|
-
#
|
83
|
+
#
|
84
84
|
# union = MyUnion.new
|
85
85
|
# union.u = 0x11111111
|
86
86
|
# union.i = -1
|
@@ -90,13 +90,13 @@ module Ronin
|
|
90
90
|
# ### Unpacking Unions
|
91
91
|
#
|
92
92
|
# class MyUnion < Ronin::Support::Binary::Union
|
93
|
-
#
|
93
|
+
#
|
94
94
|
# member :c, :char
|
95
95
|
# member :i, :int32
|
96
96
|
# member :u, :uint32
|
97
|
-
#
|
97
|
+
#
|
98
98
|
# end
|
99
|
-
#
|
99
|
+
#
|
100
100
|
# union = MyUnion.unpack("\xFF\xFF\x11\x11")
|
101
101
|
# union.c
|
102
102
|
# # => "\xFF"
|
@@ -108,12 +108,12 @@ module Ronin
|
|
108
108
|
# ### Array Fields
|
109
109
|
#
|
110
110
|
# class MyUnion < Ronin::Support::Binary::Union
|
111
|
-
#
|
111
|
+
#
|
112
112
|
# member :c, :char
|
113
113
|
# member :i, :int16
|
114
114
|
# member :u, :uint32
|
115
115
|
# member :nums, [:uint8, 10]
|
116
|
-
#
|
116
|
+
#
|
117
117
|
# end
|
118
118
|
#
|
119
119
|
# union = MyUnion.new
|
@@ -124,14 +124,14 @@ module Ronin
|
|
124
124
|
# ### Unbounded Array Fields
|
125
125
|
#
|
126
126
|
# class MyUnion < Ronin::Support::Binary::Union
|
127
|
-
#
|
127
|
+
#
|
128
128
|
# member :c, :char
|
129
129
|
# member :i, :int16
|
130
130
|
# member :u, :uint32
|
131
131
|
# member :payload, (:uint8..)
|
132
|
-
#
|
132
|
+
#
|
133
133
|
# end
|
134
|
-
#
|
134
|
+
#
|
135
135
|
# union = MyUnion.new
|
136
136
|
# union.payload = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]
|
137
137
|
# union.pack
|
@@ -140,15 +140,15 @@ module Ronin
|
|
140
140
|
# ### Default Endianness
|
141
141
|
#
|
142
142
|
# class MyUnion < Ronin::Support::Binary::Union
|
143
|
-
#
|
143
|
+
#
|
144
144
|
# endian :big
|
145
|
-
#
|
145
|
+
#
|
146
146
|
# member :c, :char
|
147
147
|
# member :i, :int32
|
148
148
|
# member :u, :uint32
|
149
|
-
#
|
149
|
+
#
|
150
150
|
# end
|
151
|
-
#
|
151
|
+
#
|
152
152
|
# union = MyUnion.new(u: 0xaabbccdd)
|
153
153
|
# union.pack
|
154
154
|
# # => "\xAA\xBB\xCC\xDD"
|
data/lib/ronin/support/binary.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
require 'ronin/support/binary/core_ext'
|
20
20
|
require 'ronin/support/binary/template'
|
21
21
|
require 'ronin/support/binary/buffer'
|
22
|
+
require 'ronin/support/binary/cstring'
|
22
23
|
require 'ronin/support/binary/array'
|
23
24
|
require 'ronin/support/binary/stack'
|
24
25
|
require 'ronin/support/binary/struct'
|
@@ -34,7 +34,7 @@ module Ronin
|
|
34
34
|
# NOTICE AUTH :*** Checking Ident
|
35
35
|
# NOTICE AUTH :*** Found your hostname
|
36
36
|
# NOTICE AUTH :*** No ident response
|
37
|
-
# USER test_ruby * * *
|
37
|
+
# USER test_ruby * * *
|
38
38
|
# NICK test_ruby
|
39
39
|
# PING :3167790481
|
40
40
|
# PONG 3167790481
|
@@ -123,7 +123,7 @@ module Ronin
|
|
123
123
|
io_array = [@io, @stdin]
|
124
124
|
|
125
125
|
loop do
|
126
|
-
readable,
|
126
|
+
readable, _writable, errors = IO.select(io_array,nil,io_array)
|
127
127
|
|
128
128
|
if errors.include?(@io) || errors.include?(@stdin)
|
129
129
|
return false
|
@@ -132,7 +132,7 @@ module Ronin
|
|
132
132
|
if readable.include?(@io)
|
133
133
|
data = begin
|
134
134
|
@io.readpartial(4096)
|
135
|
-
rescue EOFError
|
135
|
+
rescue EOFError
|
136
136
|
return false
|
137
137
|
end
|
138
138
|
|
@@ -142,7 +142,7 @@ module Ronin
|
|
142
142
|
if readable.include?(@stdin)
|
143
143
|
data = begin
|
144
144
|
@stdin.readpartial(4096)
|
145
|
-
rescue EOFError
|
145
|
+
rescue EOFError
|
146
146
|
return true
|
147
147
|
end
|
148
148
|
|
@@ -27,7 +27,7 @@ module Ronin
|
|
27
27
|
# @since 1.0.0
|
28
28
|
#
|
29
29
|
module Printing
|
30
|
-
|
30
|
+
@debug = false
|
31
31
|
|
32
32
|
#
|
33
33
|
# The current debug mode.
|
@@ -38,7 +38,7 @@ module Ronin
|
|
38
38
|
# @api semipublic
|
39
39
|
#
|
40
40
|
def self.debug?
|
41
|
-
|
41
|
+
@debug
|
42
42
|
end
|
43
43
|
|
44
44
|
#
|
@@ -53,7 +53,7 @@ module Ronin
|
|
53
53
|
# @api semipublic
|
54
54
|
#
|
55
55
|
def self.debug=(debug_mode)
|
56
|
-
|
56
|
+
@debug = debug_mode
|
57
57
|
end
|
58
58
|
|
59
59
|
# Enables or disables debug mode.
|
@@ -36,6 +36,13 @@ class File
|
|
36
36
|
# @return [Ronin::Support::Compression::Gzip::Reader]
|
37
37
|
# The gzip reader object.
|
38
38
|
#
|
39
|
+
# @example
|
40
|
+
# File.gunzip('wordlist.gz') do |gz|
|
41
|
+
# gz.each_line do |line|
|
42
|
+
# # ...
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
#
|
39
46
|
# @api public
|
40
47
|
#
|
41
48
|
# @since 1.0.0
|
@@ -59,6 +66,15 @@ class File
|
|
59
66
|
# @return [Ronin::Support::Compression::Gzip::Writer]
|
60
67
|
# The gzip writer object.
|
61
68
|
#
|
69
|
+
# @example
|
70
|
+
# File.gunzip('file.gz') do |gz|
|
71
|
+
# # gzip header info
|
72
|
+
# gz.mtime = Time.now
|
73
|
+
# gz.orig_name = 'file.txt'
|
74
|
+
#
|
75
|
+
# gz.write('Hello World!')
|
76
|
+
# end
|
77
|
+
#
|
62
78
|
# @api public
|
63
79
|
#
|
64
80
|
# @since 1.0.0
|
@@ -16,11 +16,7 @@
|
|
16
16
|
# along with ronin-support. If not, see <https://www.gnu.org/licenses/>.
|
17
17
|
#
|
18
18
|
|
19
|
-
require 'ronin/support/mixin'
|
20
|
-
|
21
19
|
module Kernel
|
22
|
-
include Ronin::Support::Mixin
|
23
|
-
|
24
20
|
#
|
25
21
|
# Calls the given block and ignores any raised exceptions.
|
26
22
|
#
|
@@ -39,10 +35,11 @@ module Kernel
|
|
39
35
|
# @api public
|
40
36
|
#
|
41
37
|
def try
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
yield() if block_given?
|
39
|
+
rescue SyntaxError => error
|
40
|
+
# re-raise syntax errors
|
41
|
+
raise(error)
|
42
|
+
rescue StandardError
|
43
|
+
# ignore any exceptions
|
47
44
|
end
|
48
45
|
end
|
@@ -199,7 +199,7 @@ class String
|
|
199
199
|
other_index = (other.length - i - 1)
|
200
200
|
|
201
201
|
if self[index] != other[other_index]
|
202
|
-
return self[(index + 1)
|
202
|
+
return self[(index + 1)..]
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
@@ -220,7 +220,7 @@ class String
|
|
220
220
|
#
|
221
221
|
def uncommon_substring(other)
|
222
222
|
prefix = common_prefix(other)
|
223
|
-
postfix = self[prefix.length
|
223
|
+
postfix = self[prefix.length..].common_suffix(other[prefix.length..])
|
224
224
|
|
225
225
|
return self[prefix.length...(length - postfix.length)]
|
226
226
|
end
|
@@ -66,7 +66,7 @@ module Ronin
|
|
66
66
|
# The populated name.
|
67
67
|
#
|
68
68
|
def self.build(common_name: nil, organizational_unit: nil, organization: nil, locality: nil, state: nil, province: nil, country: nil)
|
69
|
-
name = new
|
69
|
+
name = new
|
70
70
|
name.add_entry("CN",common_name) if common_name
|
71
71
|
name.add_entry("OU",organizational_unit) if organizational_unit
|
72
72
|
name.add_entry("O",organization) if organization
|
@@ -83,9 +83,7 @@ module Ronin
|
|
83
83
|
# @return [Hash{String => String}]
|
84
84
|
#
|
85
85
|
def entries
|
86
|
-
@entries ||=
|
87
|
-
[oid, value]
|
88
|
-
}]
|
86
|
+
@entries ||= to_a.to_h { |(oid,value,type)| [oid, value] }
|
89
87
|
end
|
90
88
|
|
91
89
|
alias to_h entries
|
@@ -328,7 +326,7 @@ module Ronin
|
|
328
326
|
def self.generate(version: 2,
|
329
327
|
serial: 0,
|
330
328
|
not_before: Time.now,
|
331
|
-
not_after: not_before+ONE_YEAR,
|
329
|
+
not_after: not_before + ONE_YEAR,
|
332
330
|
subject: nil,
|
333
331
|
extensions: nil,
|
334
332
|
# signing arguments
|
@@ -336,9 +334,10 @@ module Ronin
|
|
336
334
|
ca_cert: nil,
|
337
335
|
ca_key: nil,
|
338
336
|
signing_hash: :sha256)
|
339
|
-
cert = new
|
337
|
+
cert = new
|
338
|
+
|
340
339
|
cert.version = version
|
341
|
-
cert.serial = if ca_cert then ca_cert.serial+1
|
340
|
+
cert.serial = if ca_cert then ca_cert.serial + 1
|
342
341
|
else serial
|
343
342
|
end
|
344
343
|
|
@@ -351,11 +350,10 @@ module Ronin
|
|
351
350
|
end
|
352
351
|
|
353
352
|
if extensions
|
354
|
-
extension_factory = OpenSSL::X509::ExtensionFactory.new
|
353
|
+
extension_factory = OpenSSL::X509::ExtensionFactory.new
|
354
|
+
|
355
355
|
extension_factory.subject_certificate = cert
|
356
|
-
extension_factory.issuer_certificate =
|
357
|
-
else cert
|
358
|
-
end
|
356
|
+
extension_factory.issuer_certificate = ca_cert || cert
|
359
357
|
|
360
358
|
extensions.each do |name,(value,critical)|
|
361
359
|
ext = extension_factory.create_extension(name,value,critical)
|
@@ -363,9 +361,7 @@ module Ronin
|
|
363
361
|
end
|
364
362
|
end
|
365
363
|
|
366
|
-
signing_key
|
367
|
-
else key
|
368
|
-
end
|
364
|
+
signing_key = ca_key || key
|
369
365
|
signing_digest = OpenSSL::Digest.const_get(signing_hash.upcase).new
|
370
366
|
|
371
367
|
cert.sign(signing_key,signing_digest)
|
@@ -421,7 +417,7 @@ module Ronin
|
|
421
417
|
# The Hash of extension OID names and extension objects.
|
422
418
|
#
|
423
419
|
def extensions_hash
|
424
|
-
|
420
|
+
extensions.to_h { |ext| [ext.oid, ext] }
|
425
421
|
end
|
426
422
|
|
427
423
|
#
|
@@ -22,6 +22,9 @@ module Ronin
|
|
22
22
|
module Support
|
23
23
|
module Crypto
|
24
24
|
class Cipher < OpenSSL::Cipher
|
25
|
+
#
|
26
|
+
# The AES128 cipher.
|
27
|
+
#
|
25
28
|
class AES128 < AES
|
26
29
|
|
27
30
|
#
|
@@ -44,7 +47,7 @@ module Ronin
|
|
44
47
|
# The list of supported AES 128bit cipher names.
|
45
48
|
#
|
46
49
|
def self.supported
|
47
|
-
super().grep(/^aes
|
50
|
+
super().grep(/^aes(?:-)?128/)
|
48
51
|
end
|
49
52
|
|
50
53
|
end
|
@@ -22,6 +22,9 @@ module Ronin
|
|
22
22
|
module Support
|
23
23
|
module Crypto
|
24
24
|
class Cipher < OpenSSL::Cipher
|
25
|
+
#
|
26
|
+
# The AES256 cipher.
|
27
|
+
#
|
25
28
|
class AES256 < AES
|
26
29
|
|
27
30
|
#
|
@@ -44,7 +47,7 @@ module Ronin
|
|
44
47
|
# The list of supported AES 256bit cipher names.
|
45
48
|
#
|
46
49
|
def self.supported
|
47
|
-
super().grep(/^aes
|
50
|
+
super().grep(/^aes(?:-)?256/)
|
48
51
|
end
|
49
52
|
|
50
53
|
end
|
@@ -172,7 +172,7 @@ class File
|
|
172
172
|
def self.hmac(path, key: , digest: :sha1)
|
173
173
|
hmac = Ronin::Support::Crypto.hmac(key: key, digest: digest)
|
174
174
|
|
175
|
-
open(path,'rb') do |file|
|
175
|
+
File.open(path,'rb') do |file|
|
176
176
|
until file.eof?
|
177
177
|
hmac.update(file.read(16384))
|
178
178
|
end
|
@@ -224,6 +224,10 @@ class File
|
|
224
224
|
# @return [String]
|
225
225
|
# The encrypted data.
|
226
226
|
#
|
227
|
+
# @example
|
228
|
+
# File.encrypt('file.txt', 'aes-256-cbc', password: 's3cr3t')
|
229
|
+
# # => "..."
|
230
|
+
#
|
227
231
|
# @see http://rubydoc.info/stdlib/openssl/OpenSSL/Cipher
|
228
232
|
#
|
229
233
|
# @since 0.6.0
|
@@ -281,6 +285,10 @@ class File
|
|
281
285
|
# @return [String]
|
282
286
|
# The decrypted data.
|
283
287
|
#
|
288
|
+
# @example
|
289
|
+
# File.decrypt('encrypted.bin', 'aes-256-cbc', password: 's3cr3t')
|
290
|
+
# # => "..."
|
291
|
+
#
|
284
292
|
# @see http://rubydoc.info/stdlib/openssl/OpenSSL/Cipher
|
285
293
|
#
|
286
294
|
# @since 0.6.0
|
@@ -338,6 +346,10 @@ class File
|
|
338
346
|
# @raise [ArgumentError]
|
339
347
|
# Either the the `key:` or `password:` keyword argument must be given.
|
340
348
|
#
|
349
|
+
# @example
|
350
|
+
# File.aes_encrypt('file.txt', key_size: 256, password: 's3cr3t')
|
351
|
+
# # => "..."
|
352
|
+
#
|
341
353
|
# @since 1.0.0
|
342
354
|
#
|
343
355
|
def self.aes_encrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -390,6 +402,10 @@ class File
|
|
390
402
|
# @raise [ArgumentError]
|
391
403
|
# Either the the `key:` or `password:` keyword argument must be given.
|
392
404
|
#
|
405
|
+
# @example
|
406
|
+
# File.aes_decrypt('encrypted.bin', key_size: 256, password: 's3cr3t')
|
407
|
+
# # => "..."
|
408
|
+
#
|
393
409
|
# @since 1.0.0
|
394
410
|
#
|
395
411
|
def self.aes_decrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -439,6 +455,10 @@ class File
|
|
439
455
|
# @raise [ArgumentError]
|
440
456
|
# Either the the `key:` or `password:` keyword argument must be given.
|
441
457
|
#
|
458
|
+
# @example
|
459
|
+
# File.aes128_encrypt('file.txt', password: 's3cr3t')
|
460
|
+
# # => "..."
|
461
|
+
#
|
442
462
|
# @since 1.0.0
|
443
463
|
#
|
444
464
|
def self.aes128_encrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -488,6 +508,10 @@ class File
|
|
488
508
|
# @raise [ArgumentError]
|
489
509
|
# Either the the `key:` or `password:` keyword argument must be given.
|
490
510
|
#
|
511
|
+
# @example
|
512
|
+
# File.aes256_decrypt('encrypted.bin', password: 's3cr3t')
|
513
|
+
# # => "..."
|
514
|
+
#
|
491
515
|
# @since 1.0.0
|
492
516
|
#
|
493
517
|
def self.aes128_decrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -537,6 +561,10 @@ class File
|
|
537
561
|
# @raise [ArgumentError]
|
538
562
|
# Either the the `key:` or `password:` keyword argument must be given.
|
539
563
|
#
|
564
|
+
# @example
|
565
|
+
# File.aes256_encrypt('file.txt', password: 's3cr3t')
|
566
|
+
# # => "..."
|
567
|
+
#
|
540
568
|
# @since 1.0.0
|
541
569
|
#
|
542
570
|
def self.aes256_encrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -586,6 +614,10 @@ class File
|
|
586
614
|
# @raise [ArgumentError]
|
587
615
|
# Either the the `key:` or `password:` keyword argument must be given.
|
588
616
|
#
|
617
|
+
# @example
|
618
|
+
# File.aes256_decrypt('encrypted.bin', password: 's3cr3t')
|
619
|
+
# # => "..."
|
620
|
+
#
|
589
621
|
# @since 1.0.0
|
590
622
|
#
|
591
623
|
def self.aes256_decrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -54,10 +54,10 @@ class String
|
|
54
54
|
|
55
55
|
#
|
56
56
|
# @return [String]
|
57
|
-
# The
|
57
|
+
# The SHA256 checksum of the String.
|
58
58
|
#
|
59
59
|
# @example
|
60
|
-
# "hello".
|
60
|
+
# "hello".sha256
|
61
61
|
# # => "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
|
62
62
|
#
|
63
63
|
# @api public
|
@@ -152,6 +152,10 @@ class String
|
|
152
152
|
# @return [String]
|
153
153
|
# The encrypted String.
|
154
154
|
#
|
155
|
+
# @example
|
156
|
+
# "top secret".encrypt('aes-256-cbc', password: 's3cr3t')
|
157
|
+
# # => "\xF0[\x17\xDA\xA2\x82\x93\xF4\xB6s\xB5\xD8\x1F\xF2\xC6\\"
|
158
|
+
#
|
155
159
|
# @see http://rubydoc.info/stdlib/openssl/OpenSSL/Cipher
|
156
160
|
#
|
157
161
|
# @since 0.6.0
|
@@ -191,6 +195,10 @@ class String
|
|
191
195
|
# @return [String]
|
192
196
|
# The decrypted String.
|
193
197
|
#
|
198
|
+
# @example
|
199
|
+
# "\xF0[\x17\xDA\xA2\x82\x93\xF4\xB6s\xB5\xD8\x1F\xF2\xC6\\".decrypt('aes-256-cbc', password: 's3cr3t')
|
200
|
+
# # => "top secret"
|
201
|
+
#
|
194
202
|
# @see http://rubydoc.info/stdlib/openssl/OpenSSL/Cipher
|
195
203
|
#
|
196
204
|
# @since 0.6.0
|
@@ -236,6 +244,10 @@ class String
|
|
236
244
|
# @raise [ArgumentError]
|
237
245
|
# Either the the `key:` or `password:` keyword argument must be given.
|
238
246
|
#
|
247
|
+
# @example
|
248
|
+
# "top secret".aes_encrypt(key_size: 256, password: 's3cr3t')
|
249
|
+
# # => "\xF0[\x17\xDA\xA2\x82\x93\xF4\xB6s\xB5\xD8\x1F\xF2\xC6\\"
|
250
|
+
#
|
239
251
|
# @since 1.0.0
|
240
252
|
#
|
241
253
|
def aes_encrypt(**kwargs)
|
@@ -275,6 +287,10 @@ class String
|
|
275
287
|
# @raise [ArgumentError]
|
276
288
|
# Either the the `key:` or `password:` keyword argument must be given.
|
277
289
|
#
|
290
|
+
# @example
|
291
|
+
# "\xF0[\x17\xDA\xA2\x82\x93\xF4\xB6s\xB5\xD8\x1F\xF2\xC6\\".aes_decrypt(key_size: 256, password: 's3cr3t')
|
292
|
+
# # => "top secret"
|
293
|
+
#
|
278
294
|
# @since 1.0.0
|
279
295
|
#
|
280
296
|
def aes_decrypt(**kwargs)
|
@@ -311,6 +327,10 @@ class String
|
|
311
327
|
# @raise [ArgumentError]
|
312
328
|
# Either the the `key:` or `password:` keyword argument must be given.
|
313
329
|
#
|
330
|
+
# @example
|
331
|
+
# "top secret".aes128_encrypt(password: 's3cr3t')
|
332
|
+
# # => "\x88\xA53\xE9|\xE2\x8E\xA0\xABv\xCF\x94\x17\xBB*\xC5"
|
333
|
+
#
|
314
334
|
# @since 1.0.0
|
315
335
|
#
|
316
336
|
def aes128_encrypt(**kwargs)
|
@@ -347,6 +367,10 @@ class String
|
|
347
367
|
# @raise [ArgumentError]
|
348
368
|
# Either the the `key:` or `password:` keyword argument must be given.
|
349
369
|
#
|
370
|
+
# @example
|
371
|
+
# "\x88\xA53\xE9|\xE2\x8E\xA0\xABv\xCF\x94\x17\xBB*\xC5".aes128_decrypt(password: 's3cr3t')
|
372
|
+
# # => "top secret"
|
373
|
+
#
|
350
374
|
# @since 1.0.0
|
351
375
|
#
|
352
376
|
def aes128_decrypt(**kwargs)
|
@@ -383,6 +407,10 @@ class String
|
|
383
407
|
# @raise [ArgumentError]
|
384
408
|
# Either the the `key:` or `password:` keyword argument must be given.
|
385
409
|
#
|
410
|
+
# @example
|
411
|
+
# "top secret".aes256_encrypt(password: 's3cr3t')
|
412
|
+
# # => "\xF0[\x17\xDA\xA2\x82\x93\xF4\xB6s\xB5\xD8\x1F\xF2\xC6\\"
|
413
|
+
#
|
386
414
|
# @since 1.0.0
|
387
415
|
#
|
388
416
|
def aes256_encrypt(**kwargs)
|
@@ -419,6 +447,10 @@ class String
|
|
419
447
|
# @raise [ArgumentError]
|
420
448
|
# Either the the `key:` or `password:` keyword argument must be given.
|
421
449
|
#
|
450
|
+
# @example
|
451
|
+
# "\xF0[\x17\xDA\xA2\x82\x93\xF4\xB6s\xB5\xD8\x1F\xF2\xC6\\".aes256_decrypt(password: 's3cr3t')
|
452
|
+
# # => "top secret"
|
453
|
+
#
|
422
454
|
# @since 1.0.0
|
423
455
|
#
|
424
456
|
def aes256_decrypt(**kwargs)
|
@@ -40,6 +40,9 @@ module Ronin
|
|
40
40
|
key_class.extend ClassMethods
|
41
41
|
end
|
42
42
|
|
43
|
+
#
|
44
|
+
# Class-methods.
|
45
|
+
#
|
43
46
|
module ClassMethods
|
44
47
|
#
|
45
48
|
# Generates a new random key.
|
@@ -151,7 +154,7 @@ module Ronin
|
|
151
154
|
cipher = OpenSSL::Cipher.new(cipher)
|
152
155
|
encoding_method.call(cipher,password)
|
153
156
|
else
|
154
|
-
encoding_method.call
|
157
|
+
encoding_method.call
|
155
158
|
end
|
156
159
|
|
157
160
|
File.write(path,exported)
|