ronin-support 1.0.0.beta3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) 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 +12 -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/tar/writer.rb +2 -2
  11. data/lib/ronin/support/archive/tar.rb +4 -4
  12. data/lib/ronin/support/archive/zip/reader.rb +2 -2
  13. data/lib/ronin/support/binary/array.rb +4 -7
  14. data/lib/ronin/support/binary/bit_flip.rb +7 -1
  15. data/lib/ronin/support/binary/buffer.rb +22 -22
  16. data/lib/ronin/support/binary/byte_slice.rb +17 -17
  17. data/lib/ronin/support/binary/cstring.rb +7 -4
  18. data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +4 -0
  19. data/lib/ronin/support/binary/ctypes/arch/arm.rb +3 -0
  20. data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +4 -0
  21. data/lib/ronin/support/binary/ctypes/arch/arm64.rb +3 -0
  22. data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +4 -0
  23. data/lib/ronin/support/binary/ctypes/arch/mips.rb +3 -0
  24. data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +4 -0
  25. data/lib/ronin/support/binary/ctypes/arch/mips64.rb +3 -0
  26. data/lib/ronin/support/binary/ctypes/arch/ppc.rb +3 -0
  27. data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +3 -0
  28. data/lib/ronin/support/binary/ctypes/arch/x86.rb +3 -0
  29. data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +3 -0
  30. data/lib/ronin/support/binary/ctypes/array_type.rb +1 -1
  31. data/lib/ronin/support/binary/ctypes/big_endian.rb +3 -0
  32. data/lib/ronin/support/binary/ctypes/enum_type.rb +2 -2
  33. data/lib/ronin/support/binary/ctypes/little_endian.rb +3 -0
  34. data/lib/ronin/support/binary/ctypes/native.rb +3 -0
  35. data/lib/ronin/support/binary/ctypes/scalar_type.rb +2 -2
  36. data/lib/ronin/support/binary/ctypes/struct_type.rb +3 -3
  37. data/lib/ronin/support/binary/ctypes/type_resolver.rb +7 -8
  38. data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +1 -1
  39. data/lib/ronin/support/binary/ctypes/union_type.rb +3 -3
  40. data/lib/ronin/support/binary/ctypes.rb +3 -3
  41. data/lib/ronin/support/binary/memory.rb +2 -2
  42. data/lib/ronin/support/binary/packet.rb +3 -0
  43. data/lib/ronin/support/binary/stack.rb +3 -4
  44. data/lib/ronin/support/binary/struct/member.rb +5 -3
  45. data/lib/ronin/support/binary/struct.rb +81 -79
  46. data/lib/ronin/support/binary/template.rb +1 -0
  47. data/lib/ronin/support/binary/unhexdump/parser.rb +11 -11
  48. data/lib/ronin/support/binary/union.rb +22 -22
  49. data/lib/ronin/support/cli/ansi.rb +0 -1
  50. data/lib/ronin/support/cli/io_shell/core_ext/io.rb +1 -1
  51. data/lib/ronin/support/cli/io_shell.rb +4 -4
  52. data/lib/ronin/support/cli/printing.rb +3 -3
  53. data/lib/ronin/support/compression/zlib.rb +1 -1
  54. data/lib/ronin/support/core_ext/enumerable.rb +0 -2
  55. data/lib/ronin/support/core_ext/file.rb +1 -1
  56. data/lib/ronin/support/core_ext/kernel.rb +6 -5
  57. data/lib/ronin/support/core_ext/string.rb +2 -2
  58. data/lib/ronin/support/crypto/cert.rb +11 -15
  59. data/lib/ronin/support/crypto/cert_chain.rb +1 -1
  60. data/lib/ronin/support/crypto/cipher/aes.rb +3 -0
  61. data/lib/ronin/support/crypto/cipher/aes128.rb +4 -1
  62. data/lib/ronin/support/crypto/cipher/aes256.rb +4 -1
  63. data/lib/ronin/support/crypto/cipher.rb +1 -1
  64. data/lib/ronin/support/crypto/core_ext/file.rb +1 -1
  65. data/lib/ronin/support/crypto/key/methods.rb +4 -1
  66. data/lib/ronin/support/crypto/key.rb +5 -2
  67. data/lib/ronin/support/crypto/openssl.rb +1 -1
  68. data/lib/ronin/support/crypto.rb +0 -1
  69. data/lib/ronin/support/encoding/base16.rb +1 -1
  70. data/lib/ronin/support/encoding/base32.rb +28 -17
  71. data/lib/ronin/support/encoding/c/core_ext/integer.rb +1 -1
  72. data/lib/ronin/support/encoding/c.rb +4 -4
  73. data/lib/ronin/support/encoding/hex.rb +2 -2
  74. data/lib/ronin/support/encoding/js/core_ext/integer.rb +1 -1
  75. data/lib/ronin/support/encoding/js.rb +4 -4
  76. data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +2 -2
  77. data/lib/ronin/support/encoding/powershell.rb +4 -5
  78. data/lib/ronin/support/encoding/ruby.rb +4 -4
  79. data/lib/ronin/support/encoding/shell/core_ext/integer.rb +2 -2
  80. data/lib/ronin/support/encoding/shell.rb +3 -3
  81. data/lib/ronin/support/encoding/sql.rb +1 -1
  82. data/lib/ronin/support/encoding/xml.rb +2 -2
  83. data/lib/ronin/support/encoding.rb +95 -0
  84. data/lib/ronin/support/network/asn/list.rb +6 -1
  85. data/lib/ronin/support/network/asn/record.rb +3 -0
  86. data/lib/ronin/support/network/asn/record_set.rb +3 -0
  87. data/lib/ronin/support/network/asn.rb +167 -6
  88. data/lib/ronin/support/network/dns/resolver.rb +3 -0
  89. data/lib/ronin/support/network/domain.rb +21 -21
  90. data/lib/ronin/support/network/email_address.rb +1 -5
  91. data/lib/ronin/support/network/esmtp/mixin.rb +1 -0
  92. data/lib/ronin/support/network/ftp/mixin.rb +1 -1
  93. data/lib/ronin/support/network/host.rb +75 -47
  94. data/lib/ronin/support/network/http/core_ext.rb +1 -1
  95. data/lib/ronin/support/network/http.rb +317 -80
  96. data/lib/ronin/support/network/ip.rb +8 -10
  97. data/lib/ronin/support/network/ip_range/cidr.rb +1 -5
  98. data/lib/ronin/support/network/ip_range/glob.rb +1 -0
  99. data/lib/ronin/support/network/ip_range/range.rb +1 -1
  100. data/lib/ronin/support/network/ip_range.rb +1 -3
  101. data/lib/ronin/support/network/proxy.rb +4 -4
  102. data/lib/ronin/support/network/public_suffix/list.rb +10 -8
  103. data/lib/ronin/support/network/public_suffix/suffix_set.rb +3 -0
  104. data/lib/ronin/support/network/public_suffix.rb +9 -4
  105. data/lib/ronin/support/network/smtp/email.rb +0 -9
  106. data/lib/ronin/support/network/smtp/mixin.rb +2 -2
  107. data/lib/ronin/support/network/ssl/local_cert.rb +1 -3
  108. data/lib/ronin/support/network/ssl/mixin.rb +13 -13
  109. data/lib/ronin/support/network/ssl/openssl.rb +1 -1
  110. data/lib/ronin/support/network/ssl/proxy.rb +14 -16
  111. data/lib/ronin/support/network/ssl.rb +4 -2
  112. data/lib/ronin/support/network/tcp/proxy.rb +3 -3
  113. data/lib/ronin/support/network/tcp.rb +10 -12
  114. data/lib/ronin/support/network/telnet/mixin.rb +14 -14
  115. data/lib/ronin/support/network/tld/list.rb +2 -1
  116. data/lib/ronin/support/network/tld.rb +7 -4
  117. data/lib/ronin/support/network/tls/proxy.rb +1 -1
  118. data/lib/ronin/support/network/tls.rb +0 -2
  119. data/lib/ronin/support/network/udp/proxy.rb +5 -5
  120. data/lib/ronin/support/network/udp.rb +14 -16
  121. data/lib/ronin/support/path.rb +3 -3
  122. data/lib/ronin/support/text/erb/mixin.rb +3 -0
  123. data/lib/ronin/support/text/homoglyph/table.rb +3 -3
  124. data/lib/ronin/support/text/patterns/credentials.rb +2 -2
  125. data/lib/ronin/support/text/patterns/crypto.rb +1 -1
  126. data/lib/ronin/support/text/patterns/file_system.rb +3 -4
  127. data/lib/ronin/support/text/patterns/network.rb +10 -10
  128. data/lib/ronin/support/text/patterns/numeric.rb +1 -1
  129. data/lib/ronin/support/text/patterns/source_code.rb +2 -2
  130. data/lib/ronin/support/text/random.rb +2 -2
  131. data/lib/ronin/support/text/typo/generator.rb +2 -2
  132. data/lib/ronin/support/version.rb +1 -1
  133. data/ronin-support.gemspec +6 -5
  134. metadata +3 -2
@@ -23,6 +23,9 @@ module Ronin
23
23
  module Binary
24
24
  module CTypes
25
25
  module Arch
26
+ #
27
+ # Represents the C types for the ARM64 architecture.
28
+ #
26
29
  module ARM64
27
30
  include LittleEndian
28
31
 
@@ -24,6 +24,10 @@ module Ronin
24
24
  module CTypes
25
25
  module Arch
26
26
  module MIPS
27
+ #
28
+ # Represents the C types for the MIPS architecture, in little-endian
29
+ # mode.
30
+ #
27
31
  module LittleEndian
28
32
  include CTypes::LittleEndian
29
33
 
@@ -23,6 +23,9 @@ module Ronin
23
23
  module Binary
24
24
  module CTypes
25
25
  module Arch
26
+ #
27
+ # Represents the C types for the MIPS architecture.
28
+ #
26
29
  module MIPS
27
30
  include BigEndian
28
31
 
@@ -24,6 +24,10 @@ module Ronin
24
24
  module CTypes
25
25
  module Arch
26
26
  module MIPS64
27
+ #
28
+ # Represents the C types for the MIPS64 architecture,
29
+ # in little-endian mode.
30
+ #
27
31
  module LittleEndian
28
32
  include CTypes::LittleEndian
29
33
 
@@ -23,6 +23,9 @@ module Ronin
23
23
  module Binary
24
24
  module CTypes
25
25
  module Arch
26
+ #
27
+ # Represents the C types for the MIPS64 architecture.
28
+ #
26
29
  module MIPS64
27
30
  include BigEndian
28
31
 
@@ -23,6 +23,9 @@ module Ronin
23
23
  module Binary
24
24
  module CTypes
25
25
  module Arch
26
+ #
27
+ # Represents the C types for the PPC architecture.
28
+ #
26
29
  module PPC
27
30
  include BigEndian
28
31
 
@@ -23,6 +23,9 @@ module Ronin
23
23
  module Binary
24
24
  module CTypes
25
25
  module Arch
26
+ #
27
+ # Represents the C types for the PPC64 architecture.
28
+ #
26
29
  module PPC64
27
30
  include BigEndian
28
31
 
@@ -23,6 +23,9 @@ module Ronin
23
23
  module Binary
24
24
  module CTypes
25
25
  module Arch
26
+ #
27
+ # Represents the C types for the x86 architecture.
28
+ #
26
29
  module X86
27
30
  include LittleEndian
28
31
 
@@ -23,6 +23,9 @@ module Ronin
23
23
  module Binary
24
24
  module CTypes
25
25
  module Arch
26
+ #
27
+ # Represents the C types for the x86-64 architecture.
28
+ #
26
29
  module X86_64
27
30
  include LittleEndian
28
31
 
@@ -60,7 +60,7 @@ module Ronin
60
60
  # Custom type alignment to override the type's alignment.
61
61
  #
62
62
  def initialize(type,length, alignment: nil)
63
- if type.class == UnboundedArrayType
63
+ if type.kind_of?(UnboundedArrayType)
64
64
  raise(ArgumentError,"cannot initialize an #{self.class} of #{UnboundedArrayType}")
65
65
  end
66
66
 
@@ -33,6 +33,9 @@ module Ronin
33
33
  module Support
34
34
  module Binary
35
35
  module CTypes
36
+ #
37
+ # Represents the C types, but in big-endian byte-order.
38
+ #
36
39
  module BigEndian
37
40
  include CharTypes
38
41
 
@@ -54,8 +54,8 @@ module Ronin
54
54
  def initialize(int_type,mapping)
55
55
  super(pack_string: nil)
56
56
 
57
- @int_type = int_type
58
- @mapping = mapping
57
+ @int_type = int_type
58
+ @mapping = mapping
59
59
  @reverse_mapping = @mapping.invert
60
60
  end
61
61
 
@@ -33,6 +33,9 @@ module Ronin
33
33
  module Support
34
34
  module Binary
35
35
  module CTypes
36
+ #
37
+ # Represents the C types, but in little-endian byte-order.
38
+ #
36
39
  module LittleEndian
37
40
  include CharTypes
38
41
 
@@ -32,6 +32,9 @@ module Ronin
32
32
  module Support
33
33
  module Binary
34
34
  module CTypes
35
+ #
36
+ # Represents the system's native C types.
37
+ #
35
38
  module Native
36
39
  include CharTypes
37
40
 
@@ -82,7 +82,7 @@ module Ronin
82
82
  @signed = signed
83
83
  end
84
84
 
85
- #
85
+ #
86
86
  # Whether the scalar type is signed.
87
87
  #
88
88
  # @return [Boolean]
@@ -91,7 +91,7 @@ module Ronin
91
91
  @signed
92
92
  end
93
93
 
94
- #
94
+ #
95
95
  # Whether the scalar type is unsigned.
96
96
  #
97
97
  # @return [Boolean]
@@ -214,9 +214,9 @@ module Ronin
214
214
  # The uninitialized values for the new struct's members.
215
215
  #
216
216
  def uninitialized_value
217
- Hash[@members.map { |name,member|
218
- [name, member.type.uninitialized_value]
219
- }]
217
+ @members.transform_values do |member|
218
+ member.type.uninitialized_value
219
+ end
220
220
  end
221
221
 
222
222
  #
@@ -155,9 +155,9 @@ module Ronin
155
155
  #
156
156
  def resolve_struct(type_signature)
157
157
  struct_class = type_signature
158
- struct_members = Hash[struct_class.members.map { |name,member|
159
- [name, resolve(member.type_signature)]
160
- }]
158
+ struct_members = struct_class.members.transform_values { |member|
159
+ resolve(member.type_signature)
160
+ }
161
161
 
162
162
  struct_type = StructType.build(
163
163
  struct_members, alignment: struct_class.alignment,
@@ -176,9 +176,9 @@ module Ronin
176
176
  #
177
177
  def resolve_union(type_signature)
178
178
  union_class = type_signature
179
- union_members = Hash[union_class.members.map { |name,member|
180
- [name, resolve(member.type_signature)]
181
- }]
179
+ union_members = union_class.members.transform_values { |member|
180
+ resolve(member.type_signature)
181
+ }
182
182
 
183
183
  union_type = UnionType.build(
184
184
  union_members, alignment: union_class.alignment
@@ -191,7 +191,7 @@ module Ronin
191
191
  # Resolves a type name.
192
192
  #
193
193
  # @param [Symbol] name
194
- #
194
+ #
195
195
  # @return [Type]
196
196
  #
197
197
  def resolve_symbol(name)
@@ -203,4 +203,3 @@ module Ronin
203
203
  end
204
204
  end
205
205
  end
206
-
@@ -47,7 +47,7 @@ module Ronin
47
47
  # Cannot initialize a nested {UnboundedArrayType}.
48
48
  #
49
49
  def initialize(type, alignment: nil)
50
- if type.class == UnboundedArrayType
50
+ if type.kind_of?(UnboundedArrayType)
51
51
  raise(ArgumentError,"cannot initialize a nested #{UnboundedArrayType}")
52
52
  end
53
53
 
@@ -162,9 +162,9 @@ module Ronin
162
162
  # The uninitialized values for the new union's members.
163
163
  #
164
164
  def uninitialized_value
165
- Hash[@members.map { |name,member|
166
- [name, member.type.uninitialized_value]
167
- }]
165
+ @members.transform_values do |member|
166
+ member.type.uninitialized_value
167
+ end
168
168
  end
169
169
 
170
170
  #
@@ -61,7 +61,7 @@ module Ronin
61
61
  # * Floating Point Types:
62
62
  # * {CTypes::Float32Type float} (`-3.40282347E+38F` -
63
63
  # `3.40282347E+38F`)
64
- # * {CTypes::Float64Type double} (`-1.79769313486231570E+308` -
64
+ # * {CTypes::Float64Type double} (`-1.79769313486231570E+308` -
65
65
  # `1.79769313486231570E+308`)
66
66
  # * Aggregate Types:
67
67
  # * {CTypes::ArrayType Array} (ex: `{1,2,3}`)
@@ -182,7 +182,7 @@ module Ronin
182
182
  UINT32_NET = Network::UINT32
183
183
  UINT64_NET = Network::UINT64
184
184
 
185
- WORD_NET = Network::WORD
185
+ WORD_NET = Network::WORD
186
186
  DWORD_NET = Network::DWORD
187
187
  QWORD_NET = Network::QWORD
188
188
 
@@ -390,7 +390,7 @@ module Ronin
390
390
  openbsd: OS::OpenBSD,
391
391
  netbsd: OS::NetBSD,
392
392
 
393
- linux: OS:: Linux,
393
+ linux: OS::Linux,
394
394
  macos: OS::MacOS,
395
395
  windows: OS::Windows
396
396
  }
@@ -145,7 +145,7 @@ module Ronin
145
145
 
146
146
  case length
147
147
  when Integer then @string[index,length] = value
148
- when nil then @string[index] = value
148
+ when nil then @string[index] = value
149
149
  when Float::INFINITY
150
150
  @string[index,@string.length - index] = value
151
151
  else
@@ -157,7 +157,7 @@ module Ronin
157
157
  end
158
158
 
159
159
  #
160
- # Returns a byte slice of the memory at the given offset and for the
160
+ # Returns a byte slice of the memory at the given offset and for the
161
161
  # remainder of the memory.
162
162
  #
163
163
  # @param [Integer] offset
@@ -21,6 +21,9 @@ require 'ronin/support/binary/struct'
21
21
  module Ronin
22
22
  module Support
23
23
  module Binary
24
+ #
25
+ # Represents a network packet in network byte-order.
26
+ #
24
27
  class Packet < Binary::Struct
25
28
 
26
29
  platform endian: :net
@@ -152,7 +152,7 @@ module Ronin
152
152
  else index
153
153
  end
154
154
 
155
- if offset+@machine_word.size > @size
155
+ if (offset + @machine_word.size) > @size
156
156
  raise(IndexError,"index #{index} is out of bounds: 0...#{@size}")
157
157
  end
158
158
 
@@ -184,12 +184,11 @@ module Ronin
184
184
  else index
185
185
  end
186
186
 
187
- if offset+@machine_word.size > @size
187
+ if (offset + @machine_word.size) > @size
188
188
  raise(IndexError,"index #{index} is out of bounds: 0...#{@size}")
189
189
  end
190
190
 
191
- data = @machine_word.pack(value)
192
- @string[offset,@machine_word.size] = data
191
+ @string[offset,@machine_word.size] = @machine_word.pack(value)
193
192
  return value
194
193
  end
195
194
 
@@ -22,6 +22,9 @@ module Ronin
22
22
  module Support
23
23
  module Binary
24
24
  class Struct < Memory
25
+ #
26
+ # Represents a member defined within a {Struct}.
27
+ #
25
28
  class Member
26
29
 
27
30
  # The name of the structure member.
@@ -51,10 +54,9 @@ module Ronin
51
54
  # The optional default value for the structure's field.
52
55
  #
53
56
  def initialize(name,type_signature, default: nil)
54
- @name = name
57
+ @name = name
55
58
  @type_signature = type_signature
56
-
57
- @default = default
59
+ @default = default
58
60
  end
59
61
 
60
62
  #