Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d5758c3
Version bump to 1.2.0.
postmodern Aug 1, 2024
94e175e
Added a `Encoding::SMTP` alias to `QuotedPrintable` (closes #522).
postmodern Aug 1, 2024
941fdec
Added `Ronin::Support::Crypto::Cipher::DES3` (closes #524).
postmodern Aug 9, 2024
317c88f
Added `Crypto.des3_cipher`, `.des3_encrypt`, `.des3_decrypt` (closes …
postmodern Aug 9, 2024
ba54ae8
Added `Crypto::Mixin#crypto_des3_cipher`, `#crypto_des3_encrypt`, `#c…
postmodern Aug 9, 2024
a3495fc
Ruby 3.0's openssl does not support the `des3-wrap` cipher.
postmodern Aug 9, 2024
b54493a
Added `String#des3_encrypt` and `String#des3_decrypt` (closes #527).
postmodern Aug 9, 2024
a5afff4
Added `File.des3_encrypt` and `File.des3_decrypt` (closes #528).
postmodern Aug 9, 2024
c85992b
Added `Encoding::PHP` (closes #518).
postmodern Aug 16, 2024
cffc8ce
Replaced `Encoding::RUBY::UNESCAPE_CHARS` with `BACKSLASH_CHARS`.
postmodern Aug 16, 2024
94beeb7
Added `Encoding::NodeJS` (closes #535).
postmodern Aug 17, 2024
2800246
Added `Encoding::Python` (closes #533).
postmodern Aug 17, 2024
bd2ea94
Added `Network::URL` (closes #536).
postmodern Aug 17, 2024
08b0d03
Avoid including `URI::QueryParams::Mixin` twice.
postmodern Aug 18, 2024
01fdfd4
Added `Encoding::Perl` (closes #534).
postmodern Aug 19, 2024
c5510c5
Added `Network::Defang` (closes #540, #541, #516, #517, #542).
postmodern Nov 18, 2024
35fe6f5
Added `Network::Host#defang` (closes #543).
postmodern Nov 18, 2024
ab40733
Added `Network::IP#defang` (closes #544).
postmodern Nov 18, 2024
9803c06
Added `Network::URL#defang` (closes #545).
postmodern Nov 18, 2024
b95da92
Added `Network::Wildcard#===` / `#include?` (closes #539).
postmodern Nov 21, 2024
d832365
Renamed `UnboundedArrayType` to `FlexibleArrayType` (closes #537).
postmodern Nov 21, 2024
e76279d
Added `Encoding::Java` (closes #521).
postmodern Nov 22, 2024
9f32a46
Added `Network::URL::REGEX` to complement `Network::IP::REGEX`.
postmodern Nov 25, 2024
261ac29
Added `Network::Defang.defang` (closes #547).
postmodern Nov 25, 2024
b189b2a
Added `Network::Defang::Mixin#defang` (closes #548).
postmodern Nov 25, 2024
ab5c5d8
Added `String#defang` (closes #549).
postmodern Nov 25, 2024
7e82783
Added `Software::Version` (closes #510).
postmodern Nov 28, 2024
8b12ee8
Added `Software::VersionConstraint` (close #551).
postmodern Nov 28, 2024
eb53490
Added `Software::VersionRange` (closes #546).
postmodern Nov 28, 2024
132fa0e
Added `ronin/support/software`.
postmodern Nov 28, 2024
37fe141
Link to the docs for `Software::Version` and `Software::VersionRange`.
postmodern Dec 9, 2024
ea6fc9c
Added `Network::Host::REGEX` (closes #550).
postmodern Dec 10, 2024
0556462
Added `Text::Patterns::DECIMAL_BYTE` (issue #553).
postmodern Dec 10, 2024
752dee5
Added `Text::Patterns::HEX_BYTE` (issue #553).
postmodern Dec 10, 2024
b1ac537
Added `Text::Patterns::HEX_WORD` (issue #553).
postmodern Dec 11, 2024
ad0ac27
Added `Text::Patterns::HEX_DWORD` (issue #553).
postmodern Dec 11, 2024
dab60de
Added `Text::Patterns::HEX_QWORD` (issue #553).
postmodern Dec 11, 2024
ea1b20e
Added `Text::Patterns::OCTAL_BYTE` (issue #553).
postmodern Dec 11, 2024
af2bed1
Added `Text::Patterns::FLOATING_POINT_NUMBER` (closes #553).
postmodern Dec 11, 2024
0587e86
Deprecate `Text::Patterns::DECIMAL_OCTET` in favor of `DECIMAL_BYTE`.
postmodern Dec 11, 2024
b2f8c3d
Allow `Text::Patterns::NUMBER` and `FLOAT` to match negative numbers.
postmodern Dec 12, 2024
b4468fd
Allow `Text::Patterns::NUMBER` to match `e` exponents.
postmodern Dec 12, 2024
1ddf3bd
Moved `VERSION_NUMBER` to `ronin/support/text/patterns/software` (clo…
postmodern Dec 12, 2024
8b231ef
Added `Text::Patterns::VERSION_CONSTRAINT` (closes #555).
postmodern Dec 12, 2024
7060c55
Added `Text::Patterns::VERSION_RANGE` (closes #556).
postmodern Dec 12, 2024
5e4afce
Refactor `ronin/support/encoding/base64` to not use the `Base64` library
Feb 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ Style/MapIntoArray:
Style/CaseEquality:
Exclude:
- 'lib/ronin/support/network/ip_range.rb'
- 'lib/ronin/support/network/wildcard.rb'
- 'spec/network/ip_range_spec.rb'
- 'spec/network/ip_range/cidr_spec.rb'
- 'spec/network/ip_range/glob_spec.rb'
- 'spec/network/ip_range/range_spec.rb'
- 'spec/network/wildcard_spec.rb'

Style/ConditionalAssignment:
Exclude:
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ research and development.
* [Hex][docs-encoding-hex]
* [HTML][docs-encoding-html]
* [HTTP][docs-encoding-http]
* [Java][docs-encoding-java]
* [JavaScript][docs-encoding-js]
* [Node.js][docs-encoding-node-js]
* [PowerShell][docs-encoding-powershell]
* [Punycode][docs-encoding-punycode]
* [Quoted-printable][docs-encoding-quoted-printable]
* [Perl strings][docs-encoding-perl]
* [PHP strings][docs-encoding-php]
* [Ruby strings][docs-encoding-ruby]
* [Shell][docs-encoding-shell]
* [SQL][docs-encoding-sql]
Expand Down Expand Up @@ -90,10 +94,14 @@ research and development.
* [Public Suffix List][docs-network-public_suffix]
* [Host names][docs-network-host]
* [Domain names][docs-network-domain]
* [Defangin / Refanging][docs-network-defang]
* Working with text:
* [Generating typos][docs-text-typo].
* [Generating homoglyphs][docs-text-homoglyp].
* [Regexs for matching/extracting common types of data][docs-text-patterns].
* Working with software versions:
* [Parsing versions][docs-software-version].
* [Version ranges][docs-software-version_range].
* Adds additional methods to many of [Ruby's core classes][docs-core-exts].
* Small memory footprint (~46Kb).
* Has 96% documentation coverage.
Expand Down Expand Up @@ -205,10 +213,14 @@ along with ronin-support. If not, see <https://www.gnu.org/licenses/>.
[docs-encoding-hex]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/Hex.html
[docs-encoding-html]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/HTML.html
[docs-encoding-http]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/HTTP.html
[docs-encoding-java]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/Java.html
[docs-encoding-js]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/JS.html
[docs-encoding-node-js]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/NodeJS.html
[docs-encoding-powershell]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/PowerShell.html
[docs-encoding-punycode]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/Punycode.html
[docs-encoding-quoted-printable]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/QuotedPrintable.html
[docs-encoding-perl]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/Perl.html
[docs-encoding-php]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/PHP.html
[docs-encoding-ruby]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/Ruby.html
[docs-encoding-shell]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/Shell.html
[docs-encoding-sql]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Encoding/SQL.html
Expand Down Expand Up @@ -250,7 +262,10 @@ along with ronin-support. If not, see <https://www.gnu.org/licenses/>.
[docs-network-public_suffix]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Network/PublicSuffix.html
[docs-network-host]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Network/Host.html
[docs-network-domain]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Network/Domain.html
[docs-network-defang]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Network/Defang.html
[docs-text-typo]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Text/Typo.html
[docs-text-homoglyp]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Text/Homoglyph.html
[docs-text-patterns]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Text/Patterns.html
[docs-software-version]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Software/Version.html
[docs-software-version_range]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Software/VersionRange.html
[docs-core-exts]: https://ronin-rb.dev/docs/ronin-support/top-level-namespace.html
1 change: 1 addition & 0 deletions lib/ronin/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require 'ronin/support/network'
require 'ronin/support/path'
require 'ronin/support/text'
require 'ronin/support/software'
require 'ronin/support/version'

module Ronin
Expand Down
4 changes: 2 additions & 2 deletions lib/ronin/support/binary/ctypes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
require 'ronin/support/binary/ctypes/os'

require 'ronin/support/binary/ctypes/array_type'
require 'ronin/support/binary/ctypes/unbounded_array_type'
require 'ronin/support/binary/ctypes/flexible_array_type'
require 'ronin/support/binary/ctypes/struct_type'

require 'ronin/support/binary/ctypes/array_object_type'
Expand Down Expand Up @@ -65,7 +65,7 @@ module Binary
# `1.79769313486231570E+308`)
# * Aggregate Types:
# * {CTypes::ArrayType Array} (ex: `{1,2,3}`)
# * {CTypes::UnboundedArrayType unbounded Array} (ex: `char c[] = {...}`)
# * {CTypes::FlexibleArrayType unbounded Array} (ex: `char c[] = {...}`)
# * {CTypes::StructType struct} (ex: `struct s = {1, 'c', ...}`)
# * {CTypes::UnionType union} (ex: `union u = {1234}`)
# * Object Types:
Expand Down
6 changes: 3 additions & 3 deletions lib/ronin/support/binary/ctypes/array_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#

require 'ronin/support/binary/ctypes/aggregate_type'
require 'ronin/support/binary/ctypes/unbounded_array_type'
require 'ronin/support/binary/ctypes/flexible_array_type'

module Ronin
module Support
Expand Down Expand Up @@ -60,8 +60,8 @@ class ArrayType < AggregateType
# Custom type alignment to override the type's alignment.
#
def initialize(type,length, alignment: nil)
if type.kind_of?(UnboundedArrayType)
raise(ArgumentError,"cannot initialize an #{self.class} of #{UnboundedArrayType}")
if type.kind_of?(FlexibleArrayType)
raise(ArgumentError,"cannot initialize an #{self.class} of #{FlexibleArrayType}")
end

@type = type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ module CTypes
#
# @api private
#
# @since 1.0.0
# @since 1.2.0
#
class UnboundedArrayType < AggregateType
class FlexibleArrayType < AggregateType

# The type of each element in the unbounded array type.
#
Expand All @@ -44,11 +44,11 @@ class UnboundedArrayType < AggregateType
# The type of each element in the unbounded array type.
#
# @raise [ArgumentError]
# Cannot initialize a nested {UnboundedArrayType}.
# Cannot initialize a nested {FlexibleArrayType}.
#
def initialize(type, alignment: nil)
if type.kind_of?(UnboundedArrayType)
raise(ArgumentError,"cannot initialize a nested #{UnboundedArrayType}")
if type.kind_of?(FlexibleArrayType)
raise(ArgumentError,"cannot initialize a nested #{FlexibleArrayType}")
end

@type = type
Expand Down
4 changes: 2 additions & 2 deletions lib/ronin/support/binary/ctypes/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ def initialize(pack_string: )
# @param [Integer, nil] length
# The length of the Array.
#
# @return [ArrayType, UnboundedArrayType]
# @return [ArrayType, FlexibleArrayType]
# The new Array type or an unbounded Array type if `length` was not
# given.
#
def [](length=nil)
if length then ArrayType.new(self,length)
else UnboundedArrayType.new(self)
else FlexibleArrayType.new(self)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ronin/support/binary/ctypes/type_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def resolve_array(type_signature)
#
# @param [Range] type_signature
#
# @return [UnboundedArrayType]
# @return [FlexibleArrayType]
#
def resolve_range(type_signature)
range = type_signature
Expand Down
4 changes: 2 additions & 2 deletions lib/ronin/support/binary/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module Binary
# struct.pack
# # => "\x00\x00\x00\x00\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00"
#
# ### Unbounded Array Fields
# ### Flexible Array Fields
#
# class MyStruct < Ronin::Support::Binary::Struct
#
Expand Down Expand Up @@ -517,7 +517,7 @@ def self.read_from(io)
def [](name)
if (member = @type.members[name])
case member.type
when CTypes::UnboundedArrayType
when CTypes::FlexibleArrayType
# XXX: but how do we handle an unbounded array of structs?
@cache[name] ||= begin
offset = member.offset
Expand Down
2 changes: 1 addition & 1 deletion lib/ronin/support/binary/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module Binary
# union.pack
# # => "\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00"
#
# ### Unbounded Array Fields
# ### Flexible Array Fields
#
# class MyUnion < Ronin::Support::Binary::Union
#
Expand Down
100 changes: 100 additions & 0 deletions lib/ronin/support/crypto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require 'ronin/support/crypto/openssl'
require 'ronin/support/crypto/hmac'
require 'ronin/support/crypto/cipher'
require 'ronin/support/crypto/cipher/des3'
require 'ronin/support/crypto/cipher/aes'
require 'ronin/support/crypto/cipher/aes128'
require 'ronin/support/crypto/cipher/aes256'
Expand Down Expand Up @@ -289,6 +290,105 @@ def self.decrypt(data, cipher: ,**kwargs)
self.cipher(cipher, direction: :decrypt, **kwargs).decrypt(data)
end

#
# Creates a new DES3 cipher.
#
# @param [Hash{Symbol => Object}] kwargs
# Additional keyword arguments for {Cipher::DES3#initialize}.
#
# @option kwargs [:wrap, Symbol, nil] :mode
# The desired DES3 cipher mode.
#
# @option kwargs [String] :key
# The secret key to use.
#
# @option kwargs [String] :iv
# The optional Initial Vector (IV).
#
# @option kwargs [Integer] :padding
# Sets the padding for the cipher.
#
# @return [Cipher::DES3]
# The new DES3 cipher.
#
# @example
# Crypto.des3_cipher(direction: :encrypt, key: 'A' * 24)
# # => #<Ronin::Support::Crypto::Cipher::DES3:0x00007f54c3752b90 @mode=nil>
#
# @see Cipher::DES3
#
# @since 1.2.0
#
def self.des3_cipher(**kwargs)
Cipher::DES3.new(**kwargs)
end

#
# Encrypts data using DES3.
#
# @param [#to_s] data
# The data to encrypt.
#
# @param [Hash{Symbol => Object}] kwargs
# Additional keyword arguments for {Cipher::DES3#initialize}.
#
# @option kwargs [:wrap, Symbol, nil] :mode
# The desired DES3 cipher mode.
#
# @option kwargs [String] :key
# The secret key to use.
#
# @option kwargs [String] :iv
# The optional Initial Vector (IV).
#
# @option kwargs [Integer] :padding
# Sets the padding for the cipher.
#
# @return [String]
# The encrypted data.
#
# @raise [ArgumentError]
# The `key:` keyword argument must be given.
#
# @since 1.2.0
#
def self.des3_encrypt(data,**kwargs)
self.des3_cipher(direction: :encrypt, **kwargs).encrypt(data)
end

#
# Decrypts data using DES3.
#
# @param [#to_s] data
# The data to decrypt.
#
# @param [Hash{Symbol => Object}] kwargs
# Additional keyword arguments for {Cipher::DES3#initialize}.
#
# @option kwargs [:wrap, Symbol, nil] :mode
# The desired DES3 cipher mode.
#
# @option kwargs [String] :key
# The secret key to use.
#
# @option kwargs [String] :iv
# The optional Initial Vector (IV).
#
# @option kwargs [Integer] :padding
# Sets the padding for the cipher.
#
# @return [String]
# The encrypted data.
#
# @raise [ArgumentError]
# The `key:` keyword argument must be given.
#
# @since 1.2.0
#
def self.des3_decrypt(data,**kwargs)
self.des3_cipher(direction: :decrypt, **kwargs).decrypt(data)
end

#
# Creates a new AES cipher.
#
Expand Down
70 changes: 70 additions & 0 deletions lib/ronin/support/crypto/cipher/des3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true
#
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# Ronin Support is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ronin Support is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
#

require 'ronin/support/crypto/cipher'

module Ronin
module Support
module Crypto
class Cipher < OpenSSL::Cipher
#
# The DES3 cipher.
#
# @since 1.2.0
#
class DES3 < Cipher

# The DES3 cipher mode.
#
# @return [:wrap, Symbol, nil]
attr_reader :mode

#
# Initializes the DES3 cipher.
#
# @param [:wrap, Symbol, nil] mode
# The desired DES3 cipher mode.
#
# @param [Hash{Symbol => Object}] kwargs
# Additional keyword arguments for {Cipher#initialize}.
#
def initialize(mode: nil, **kwargs)
name = if mode then "des3-#{mode}"
else "des3"
end

super(name, **kwargs)

@mode = mode
end

#
# The list of supported DES3 ciphers.
#
# @return [Array<String>]
# The list of supported DES3 cipher names.
#
def self.supported
super().grep(/^des3/)
end

end
end
end
end
end
Loading