Module: Interactsh::Utils

Defined in:
lib/interactsh/utils.rb

Overview

Utility methods for Interactsh

Class Method Summary collapse

Class Method Details

.create_uuid_bytesArray

Creates the byte array for UUID with proper version and variant



29
30
31
32
33
34
35
# File 'lib/interactsh/utils.rb', line 29

def create_uuid_bytes
  bytes = Array.new(16) { rand(0..255) }
  # Set version (4) and variant (RFC4122)
  bytes[6] = (bytes[6] & 0x0F) | 0x40 # version 4
  bytes[8] = (bytes[8] & 0x3F) | 0x80 # variant RFC4122
  bytes
end

.format_uuid(hex) ⇒ String

Formats a hex string as a UUID with hyphens



41
42
43
# File 'lib/interactsh/utils.rb', line 41

def format_uuid(hex)
  [hex[0..7], hex[8..11], hex[12..15], hex[16..19], hex[20..31]].join('-')
end

.generate_random_string(length) ⇒ String

Generates a random string of specified length



12
13
14
15
# File 'lib/interactsh/utils.rb', line 12

def generate_random_string(length)
  charset = Array('a'..'z') + Array(0..9)
  Array.new(length) { charset.sample }.join
end

.generate_uuidString

Generates a RFC4122 version 4 UUID



20
21
22
23
24
# File 'lib/interactsh/utils.rb', line 20

def generate_uuid
  random_bytes = create_uuid_bytes
  hex = random_bytes.map { |b| b.to_s(16).rjust(2, '0') }.join
  format_uuid(hex)
end