2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2005-06-09 04:36:02 +00:00
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Encoder
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class performs basic XOR encoding.
|
|
|
|
#
|
|
|
|
###
|
2005-06-09 04:36:02 +00:00
|
|
|
class Xor
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
attr_accessor :raw, :encoded, :badchars, :opts, :key, :fkey # :nodoc:
|
2005-06-09 04:36:02 +00:00
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
2005-06-09 04:36:02 +00:00
|
|
|
# wrap that shit in a wanna be static class
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
2005-06-09 04:36:02 +00:00
|
|
|
def self.encode(*args)
|
|
|
|
self.new.encode(*args)
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Return the class associated with this encoder.
|
|
|
|
#
|
2005-06-09 04:36:02 +00:00
|
|
|
def encoder()
|
|
|
|
self.class::EncoderKlass
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# This method encodes the supplied data, taking into account the badchar
|
|
|
|
# list, and returns the encoded buffer.
|
|
|
|
#
|
2005-06-09 04:47:12 +00:00
|
|
|
def encode(data, badchars = '', opts = { })
|
2005-06-09 04:36:02 +00:00
|
|
|
self.raw = data
|
|
|
|
self.badchars = badchars
|
|
|
|
self.opts = opts
|
|
|
|
|
2005-06-09 18:22:39 +00:00
|
|
|
# apply any transforms to the plaintext data
|
|
|
|
data = _unencoded_transform(data)
|
|
|
|
|
2005-06-09 18:12:39 +00:00
|
|
|
self.encoded, self.key, self.fkey = encoder().find_key_and_encode(data, badchars)
|
2005-06-09 18:22:39 +00:00
|
|
|
|
|
|
|
# apply any transforms to the encoded data
|
|
|
|
self.encoded = _encoded_transform(encoded)
|
|
|
|
|
2005-06-09 04:36:02 +00:00
|
|
|
return _prepend() + encoded + _append()
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
2005-11-15 05:22:13 +00:00
|
|
|
def _unencoded_transform(data) # :nodoc:
|
2005-06-09 18:23:30 +00:00
|
|
|
data
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
def _encoded_transform(data) # :nodoc:
|
2005-06-09 18:23:30 +00:00
|
|
|
data
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
def _prepend() # :nodoc:
|
2005-06-09 04:36:02 +00:00
|
|
|
""
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
def _append() # :nodoc:
|
2005-06-09 04:36:02 +00:00
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end end
|