Files
metasploit-gs/lib/msf/core/encoder/xor.rb
T

44 lines
941 B
Ruby
Raw Normal View History

2005-07-09 21:18:49 +00:00
require 'msf/core'
2005-05-21 17:57:00 +00:00
###
#
# This class provides basic XOR encoding of buffers.
#
###
class Msf::Encoder::Xor < Msf::Encoder
2005-11-15 15:11:43 +00:00
#
# Encodes a block using the XOR encoder from the Rex library.
#
2005-05-21 17:57:00 +00:00
def encode_block(state, block)
2006-04-26 16:51:05 +00:00
Rex::Encoding::Xor::Dword.encode(block, [ state.key ].pack(state.decoder_key_pack))[0]
2005-05-21 17:57:00 +00:00
end
2005-11-15 15:11:43 +00:00
#
# Finds keys that are incompatible with the supplied bad character list.
#
2005-05-21 17:57:00 +00:00
def find_bad_keys(buf, badchars)
bad_keys = [ {}, {}, {}, {} ]
byte_idx = 0
# Scan through all the badchars and build out the bad_keys array
# based on the XOR'd combinations that can occur at certain bytes
# to produce bad characters
2006-04-26 16:51:05 +00:00
buf.each_byte { |byte|
badchars.each_byte { |badchar|
2005-05-21 17:57:00 +00:00
bad_keys[byte_idx % decoder_key_size][byte ^ badchar] = true
}
2006-04-26 16:51:05 +00:00
byte_idx += 1
}
badchars.each_byte { |badchar|
0.upto(decoder_key_size-1) { |i|
bad_keys[i][badchar] = true
}
2005-05-21 17:57:00 +00:00
}
2006-04-26 05:14:55 +00:00
2005-05-21 17:57:00 +00:00
return bad_keys
end
2006-04-26 05:14:55 +00:00
2005-05-21 17:57:00 +00:00
end