Class: Ronin::Payloads::Encoders::XOR
- Defined in:
- lib/ronin/payloads/encoders/xor.rb
Instance Attribute Summary collapse
-
#allow ⇒ Object
Set of characters to allow in the encoded data.
Instance Method Summary collapse
-
#encode(data) ⇒ Object
XOR encodes the specified data prefixing the XOR key to the encoded data.
-
#initialize(options = {}, &block) ⇒ XOR
constructor
Creates a new XOR Encoder object using the given options.
Methods inherited from Encoder
Methods included from Model::TargetsOS
Methods included from Model::TargetsArch
Constructor Details
#initialize(options = {}, &block) ⇒ XOR
Creates a new XOR Encoder object using the given options. If a block is given it will be passed the newly created Encoder object.
options may include the following keys:
:allow
-
The set of characters allowed in the encoded result. Defaults to
(1..255)
. :disallow
-
The set of characters that are not allowed in the encoded result.
45 46 47 48 49 50 51 52 53 |
# File 'lib/ronin/payloads/encoders/xor.rb', line 45 def initialize(={},&block) @allow = Chars::CharSet.new([:allow] || (1..255)) if [:disallow] @allow -= [:disallow] end super(&block) end |
Instance Attribute Details
#allow ⇒ Object
Set of characters to allow in the encoded data
32 33 34 |
# File 'lib/ronin/payloads/encoders/xor.rb', line 32 def allow @allow end |
Instance Method Details
#encode(data) ⇒ Object
XOR encodes the specified data prefixing the XOR key to the encoded data.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ronin/payloads/encoders/xor.rb', line 59 def encode(data) alphabet = Chars.ascii.select { |b| data.include?(b.chr) } excluded = (Chars.ascii - alphabet) key = excluded.select { |b| @allow.include?(b) && alphabet.all? { |i| @allow.include?(i ^ b) } }.last text = '' text << key.chr data.each_byte { |b| text << (b ^ key).chr } return text end |