Class: Unisec::Bidi::Spoof
- Inherits:
-
Object
- Object
- Unisec::Bidi::Spoof
- Defined in:
- lib/unisec/bidi.rb
Overview
Attack using BiDi code points like RtLO, for example, for spoofing a domain name or a file name
Instance Attribute Summary collapse
-
#spoof_payload ⇒ String
readonly
The string for the spoofing attack with the BiDi characters.
-
#spoof_string ⇒ String
readonly
The string for the spoofing attack without the BiDi characters.
-
#target_display ⇒ String
readonly
The target string to spoof (eg. URL, domain or file name).
Class Method Summary collapse
-
.bidi_affix(input, **opts) ⇒ String
Inject BiDi characters into the input string.
-
.reverse(target, **opts) ⇒ String
Reverse the (sub)-string (grapheme cluster aware).
Instance Method Summary collapse
-
#bidi_affix(**opts) ⇒ Object
Call Spoof.bidi_affix with
@spoof_string
as input. -
#display(light: false) ⇒ String
Display a CLI-friendly output summurizing the spoof payload.
-
#initialize(input, **opts) ⇒ Spoof
constructor
A new instance of Spoof.
-
#reverse(**opts) ⇒ Object
Call Spoof.reverse with
@target_display
as default input (target). -
#set_target_display(input, **opts) ⇒ String
Set a new target string to spoof.
Constructor Details
#initialize(input, **opts) ⇒ Spoof
Returns a new instance of Spoof.
43 44 45 46 47 48 49 |
# File 'lib/unisec/bidi.rb', line 43 def initialize(input, **opts) opts[:index] ||= opts[:infix_pos] @target_display = input @spoof_string = reverse(**opts) @spoof_payload = bidi_affix(**opts) end |
Instance Attribute Details
#spoof_payload ⇒ String (readonly)
The string for the spoofing attack with the BiDi characters. (Spoof payload = spoof string + BiDi)
34 35 36 |
# File 'lib/unisec/bidi.rb', line 34 def spoof_payload @spoof_payload end |
#spoof_string ⇒ String (readonly)
The string for the spoofing attack without the BiDi characters
30 31 32 |
# File 'lib/unisec/bidi.rb', line 30 def spoof_string @spoof_string end |
#target_display ⇒ String (readonly)
The target string to spoof (eg. URL, domain or file name)
13 14 15 |
# File 'lib/unisec/bidi.rb', line 13 def target_display @target_display end |
Class Method Details
.bidi_affix(input, **opts) ⇒ String
Inject BiDi characters into the input string
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/unisec/bidi.rb', line 112 def self.bidi_affix(input, **opts) opts[:prefix] ||= "\u{202E}" # RLO opts[:suffix] ||= "\u{202C}" # PDF opts[:infix_bidi] ||= '' opts[:infix_pos] ||= 0 out = "#{opts[:prefix]}#{input}#{opts[:suffix]}" out.insert(opts[:infix_pos], opts[:infix_bidi]) out end |
.reverse(target, **opts) ⇒ String
Reverse the (sub)-string (grapheme cluster aware)
62 63 64 65 66 |
# File 'lib/unisec/bidi.rb', line 62 def self.reverse(target, **opts) opts[:index] ||= 0 target[0...opts[:index]] + Unisec::Utils::String.grapheme_reverse(target[opts[:index]..]) end |
Instance Method Details
#bidi_affix(**opts) ⇒ Object
Call bidi_affix with @spoof_string
as input.
124 125 126 |
# File 'lib/unisec/bidi.rb', line 124 def bidi_affix(**opts) Spoof.bidi_affix(@spoof_string, **opts) end |
#display(light: false) ⇒ String
Display a CLI-friendly output summurizing the spoof payload
The light version displays only the spoof payload for easy piping with other commands.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/unisec/bidi.rb', line 151 def display(light: false) if light == false # full display "Target string: #{@target_display}\n" \ "Spoof payload (display) ⚠: #{@spoof_payload}\n" \ "Spoof string 🛈: #{@spoof_string}\n" \ "Spoof payload (hex): #{@spoof_payload.to_hex}\n" \ "Spoof payload (hex, escaped): #{@spoof_payload.to_hex(prefixall: '\\x')}\n" \ "Spoof payload (base64): #{@spoof_payload.to_b64}\n" \ "Spoof payload (urlencode): #{@spoof_payload.urlencode}\n" \ "Spoof payload (code points): #{Unisec::Properties.chars2codepoints(@spoof_payload)}\n" \ "\n\n\n" \ '⚠: for the spoof payload to display correctly, be sure your VTE has RTL support, ' \ "e.g. see https://wiki.archlinux.org/title/Bidirectional_text#Terminal.\n" \ '🛈: Does not contain the BiDi character (e.g. RtLO).' else # light display @spoof_payload end end |
#reverse(**opts) ⇒ Object
Call reverse with @target_display
as default input (target).
69 70 71 |
# File 'lib/unisec/bidi.rb', line 69 def reverse(**opts) Spoof.reverse(@target_display, **opts) end |
#set_target_display(input, **opts) ⇒ String
Set a new target string to spoof
It will automatically set @spoof_string
and @spoof_payload
as well.
21 22 23 24 25 26 |
# File 'lib/unisec/bidi.rb', line 21 def set_target_display(input, **opts) @target_display = input @spoof_string = reverse(**opts) @spoof_payload = bidi_affix(**opts) @target_display end |