unisec 0.0.4 → 0.0.5
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/lib/unisec/bidi.rb +1 -0
- data/lib/unisec/cli/cli.rb +2 -0
- data/lib/unisec/cli/hexdump.rb +4 -1
- data/lib/unisec/cli/normalization.rb +55 -0
- data/lib/unisec/hexdump.rb +1 -0
- data/lib/unisec/normalization.rb +94 -0
- data/lib/unisec/surrogates.rb +1 -0
- data/lib/unisec/version.rb +1 -1
- data/lib/unisec/versions.rb +13 -13
- data/lib/unisec.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b6f74de3dc3d0f9aebac59ff68bc5731b7185e9e73e86e87477c23408900452
|
4
|
+
data.tar.gz: 910be7b95b71022f352cc6d612c7752fe2ea13a0e6e3dc89aca4566cb1879569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47b730a884a30979be5968d90a30bc214ec93725383f20c48a02ec1090ce64e6043f95427c7ed79ebc31b3b4e1d3b66e01c7b0d63f936793f6c8eb008ce5f9fe
|
7
|
+
data.tar.gz: be9ca5cc40baaf9cd56141a3a8e41f5709c6071d5e7797ebd64a1daf231671e6835c168bce53f540e72ead4f68fc93bfd2d211764ba474e1cd8a4ca1bf5e7a65
|
data/lib/unisec/bidi.rb
CHANGED
@@ -129,6 +129,7 @@ module Unisec
|
|
129
129
|
#
|
130
130
|
# The light version displays only the spoof payload for easy piping with other commands.
|
131
131
|
# @param light [Boolean] `true` = light display (displays only the spoof payload for easy piping with other commands), `false` (default) = full display.
|
132
|
+
# @return [String] CLI-ready output
|
132
133
|
# @example
|
133
134
|
# puts Unisec::Bidi::Spoof.new('noraj').display
|
134
135
|
# # Target string: noraj
|
data/lib/unisec/cli/cli.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'unisec/cli/bidi'
|
4
4
|
require 'unisec/cli/confusables'
|
5
5
|
require 'unisec/cli/hexdump'
|
6
|
+
require 'unisec/cli/normalization'
|
6
7
|
require 'unisec/cli/properties'
|
7
8
|
require 'unisec/cli/rugrep'
|
8
9
|
require 'unisec/cli/size'
|
@@ -23,6 +24,7 @@ module Unisec
|
|
23
24
|
register 'confusables randomize', Confusables::Randomize
|
24
25
|
register 'grep', Grep
|
25
26
|
register 'hexdump', Hexdump
|
27
|
+
register 'normalize', Normalize
|
26
28
|
register 'properties char', Properties::Char
|
27
29
|
register 'properties codepoints', Properties::Codepoints
|
28
30
|
register 'properties list', Properties::List
|
data/lib/unisec/cli/hexdump.rb
CHANGED
@@ -17,6 +17,9 @@ module Unisec
|
|
17
17
|
# UTF-16LE: 4100 4300 4300 4500 4900 5300
|
18
18
|
# UTF-32BE: 00000041 00000043 00000043 00000045 00000049 00000053
|
19
19
|
# UTF-32LE: 41000000 43000000 43000000 45000000 49000000 53000000
|
20
|
+
#
|
21
|
+
# $unisec hexdump "ACCEIS" --enc utf16le
|
22
|
+
# 4100 4300 4300 4500 4900 5300
|
20
23
|
# ```
|
21
24
|
class Hexdump < Dry::CLI::Command
|
22
25
|
desc 'Hexdump in all Unicode encodings'
|
@@ -35,7 +38,7 @@ module Unisec
|
|
35
38
|
puts Unisec::Hexdump.new(input).display
|
36
39
|
else
|
37
40
|
# using send() is safe here thanks to the value whitelist
|
38
|
-
puts
|
41
|
+
puts Unisec::Hexdump.send(options[:enc], input)
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry/cli'
|
4
|
+
require 'unisec'
|
5
|
+
require 'unisec/utils'
|
6
|
+
|
7
|
+
module Unisec
|
8
|
+
module CLI
|
9
|
+
module Commands
|
10
|
+
# CLI sub-commands `unisec normalize xxx` for the class {Unisec::Normalization} from the lib.
|
11
|
+
#
|
12
|
+
# Command `unisec normalize "example"`
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
#
|
16
|
+
# ```plaintext
|
17
|
+
# ➜ unisec normalize ẛ̣
|
18
|
+
# Original: ẛ̣
|
19
|
+
# U+1E9B U+0323
|
20
|
+
# NFC: ẛ̣
|
21
|
+
# U+1E9B U+0323
|
22
|
+
# NFKC: ṩ
|
23
|
+
# U+1E69
|
24
|
+
# NFD: ẛ̣
|
25
|
+
# U+017F U+0323 U+0307
|
26
|
+
# NFKD: ṩ
|
27
|
+
# U+0073 U+0323 U+0307
|
28
|
+
#
|
29
|
+
# ➜ unisec normalize ẛ̣ --form nfkd
|
30
|
+
# ṩ
|
31
|
+
# ```
|
32
|
+
class Normalize < Dry::CLI::Command
|
33
|
+
desc 'Normalize in all forms'
|
34
|
+
|
35
|
+
argument :input, required: true,
|
36
|
+
desc: 'String input. Read from STDIN if equal to -.'
|
37
|
+
|
38
|
+
option :form, default: nil, values: %w[nfc nfkc nfd nfkd],
|
39
|
+
desc: 'Output only in the specified normalization form.'
|
40
|
+
|
41
|
+
# Normalize in all forms
|
42
|
+
# @param input [String] Input string to normalize
|
43
|
+
def call(input: nil, **options)
|
44
|
+
input = $stdin.read.chomp if input == '-'
|
45
|
+
if options[:form].nil?
|
46
|
+
puts Unisec::Normalization.new(input).display
|
47
|
+
else
|
48
|
+
# using send() is safe here thanks to the value whitelist
|
49
|
+
puts Unisec::Normalization.send(options[:form], input)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/unisec/hexdump.rb
CHANGED
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ctf_party'
|
4
|
+
|
5
|
+
module Unisec
|
6
|
+
# Normalization Forms
|
7
|
+
class Normalization
|
8
|
+
# Original input
|
9
|
+
# @return [String] untouched input
|
10
|
+
attr_reader :original
|
11
|
+
|
12
|
+
# Normalization Form C (NFC) - Canonical Decomposition, followed by Canonical Composition
|
13
|
+
# @return [String] input normalized with NFC
|
14
|
+
attr_reader :nfc
|
15
|
+
|
16
|
+
# Normalization Form KC (NFKC) - Compatibility Decomposition, followed by Canonical Composition
|
17
|
+
# @return [String] input normalized with NFKC
|
18
|
+
attr_reader :nfkc
|
19
|
+
|
20
|
+
# Normalization Form D (NFD) - Canonical Decomposition
|
21
|
+
# @return [String] input normalized with NFD
|
22
|
+
attr_reader :nfd
|
23
|
+
|
24
|
+
# Normalization Form KD (NFKD) - Compatibility Decomposition
|
25
|
+
# @return [String] input normalized with NFKD
|
26
|
+
attr_reader :nfkd
|
27
|
+
|
28
|
+
# Generate all normilzation forms for a given input
|
29
|
+
# @param str [String] the target string
|
30
|
+
# @return [nil]
|
31
|
+
def initialize(str)
|
32
|
+
@original = str
|
33
|
+
@nfc = Normalization.nfc(str)
|
34
|
+
@nfkc = Normalization.nfkc(str)
|
35
|
+
@nfd = Normalization.nfd(str)
|
36
|
+
@nfkd = Normalization.nfkd(str)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Normalization Form C (NFC) - Canonical Decomposition, followed by Canonical Composition
|
40
|
+
# @param str [String] the target string
|
41
|
+
# @return [String] input normalized with NFC
|
42
|
+
def self.nfc(str)
|
43
|
+
str.unicode_normalize(:nfc)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Normalization Form KC (NFKC) - Compatibility Decomposition, followed by Canonical Composition
|
47
|
+
# @param str [String] the target string
|
48
|
+
# @return [String] input normalized with NFKC
|
49
|
+
def self.nfkc(str)
|
50
|
+
str.unicode_normalize(:nfkc)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Normalization Form D (NFD) - Canonical Decomposition
|
54
|
+
# @param str [String] the target string
|
55
|
+
# @return [String] input normalized with NFD
|
56
|
+
def self.nfd(str)
|
57
|
+
str.unicode_normalize(:nfd)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Normalization Form KD (NFKD) - Compatibility Decomposition
|
61
|
+
# @param str [String] the target string
|
62
|
+
# @return [String] input normalized with NFKD
|
63
|
+
def self.nfkd(str)
|
64
|
+
str.unicode_normalize(:nfkd)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Display a CLI-friendly output summurizing all normalization forms
|
68
|
+
# @return [String] CLI-ready output
|
69
|
+
# @example
|
70
|
+
# puts Unisec::Normalization.new("\u{1E9B 0323}").display
|
71
|
+
# # =>
|
72
|
+
# # Original: ẛ̣
|
73
|
+
# # U+1E9B U+0323
|
74
|
+
# # NFC: ẛ̣
|
75
|
+
# # U+1E9B U+0323
|
76
|
+
# # NFKC: ṩ
|
77
|
+
# # U+1E69
|
78
|
+
# # NFD: ẛ̣
|
79
|
+
# # U+017F U+0323 U+0307
|
80
|
+
# # NFKD: ṩ
|
81
|
+
# # U+0073 U+0323 U+0307
|
82
|
+
def display
|
83
|
+
colorize = lambda { |form_title, form_attr|
|
84
|
+
"#{Paint[form_title.to_s, :underline,
|
85
|
+
:bold]}: #{form_attr}\n #{Paint[Unisec::Properties.chars2codepoints(form_attr), :red]}\n"
|
86
|
+
}
|
87
|
+
colorize.call('Original', @original) +
|
88
|
+
colorize.call('NFC', @nfc) +
|
89
|
+
colorize.call('NFKC', @nfkc) +
|
90
|
+
colorize.call('NFD', @nfd) +
|
91
|
+
colorize.call('NFKD', @nfkd)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/unisec/surrogates.rb
CHANGED
@@ -102,6 +102,7 @@ module Unisec
|
|
102
102
|
# Display a CLI-friendly output summurizing everithing about the surrogates:
|
103
103
|
# the corresponding character, code point, high and low surrogates
|
104
104
|
# (each displayed as hexadecimal, decimal and binary).
|
105
|
+
# @return [String] CLI-ready output
|
105
106
|
# @example
|
106
107
|
# surr = Unisec::Surrogates.new(128169)
|
107
108
|
# puts surr.display # =>
|
data/lib/unisec/version.rb
CHANGED
data/lib/unisec/versions.rb
CHANGED
@@ -72,19 +72,19 @@ module Unisec
|
|
72
72
|
# # …
|
73
73
|
def self.display # rubocop:disable Metrics/AbcSize
|
74
74
|
data = versions
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
75
|
+
colorize = ->(node) { Paint[data[node][:label], :red, :bold].ljust(44) + " #{data[node][:version]}\n" }
|
76
|
+
Paint["Unicode:\n", :underline] +
|
77
|
+
colorize.call(:ruby_unicode) +
|
78
|
+
colorize.call(:twittercldr_unicode) +
|
79
|
+
colorize.call(:unicodeconfusable_unicode) +
|
80
|
+
colorize.call(:twittercldr_icu) +
|
81
|
+
colorize.call(:twittercldr_cldr) +
|
82
|
+
colorize.call(:ruby_unicode_emoji) +
|
83
|
+
colorize.call(:ucd_derivedname) +
|
84
|
+
Paint["\nGems:\n", :underline] +
|
85
|
+
colorize.call(:unisec) +
|
86
|
+
colorize.call(:twittercldr) +
|
87
|
+
colorize.call(:unicodeconfusable)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
data/lib/unisec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unisec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre ZANNI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ctf-party
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
version: '1.9'
|
89
89
|
description: 'Toolkit for security research manipulating Unicode: confusables, homoglyphs,
|
90
90
|
hexdump, code point, UTF-8, UTF-16, UTF-32, properties, regexp search, size, grapheme,
|
91
|
-
surrogates, version, ICU, CLDR, UCD'
|
91
|
+
surrogates, version, ICU, CLDR, UCD, BiDi, normalization'
|
92
92
|
email: alexandre.zanni@europe.com
|
93
93
|
executables:
|
94
94
|
- unisec
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/unisec/cli/cli.rb
|
105
105
|
- lib/unisec/cli/confusables.rb
|
106
106
|
- lib/unisec/cli/hexdump.rb
|
107
|
+
- lib/unisec/cli/normalization.rb
|
107
108
|
- lib/unisec/cli/properties.rb
|
108
109
|
- lib/unisec/cli/rugrep.rb
|
109
110
|
- lib/unisec/cli/size.rb
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- lib/unisec/cli/versions.rb
|
112
113
|
- lib/unisec/confusables.rb
|
113
114
|
- lib/unisec/hexdump.rb
|
115
|
+
- lib/unisec/normalization.rb
|
114
116
|
- lib/unisec/properties.rb
|
115
117
|
- lib/unisec/rugrep.rb
|
116
118
|
- lib/unisec/size.rb
|