diff --git a/lib/msf/core/encoder.rb b/lib/msf/core/encoder.rb index 95839a3914..083dc51598 100644 --- a/lib/msf/core/encoder.rb +++ b/lib/msf/core/encoder.rb @@ -383,17 +383,17 @@ protected # Scan each byte position 0.upto(decoder_key_size - 1) { |index| - # Subtract the bad and leave the good - good_keys = allset-bad_keys[index].keys + # Subtract the bad and leave the good + good_keys = allset-bad_keys[index].keys - # Was there anything left for this index? - if (good_keys.length == 0) - # Not much we can do about this :( - return nil - end + # Was there anything left for this index? + if (good_keys.length == 0) + # Not much we can do about this :( + return nil + end - # Set the appropriate key byte - key_bytes[index] = good_keys[ rand(good_keys.length) ] + # Set the appropriate key byte + key_bytes[index] = good_keys[ rand(good_keys.length) ] } # Assume that we're going to rock this shit... diff --git a/lib/msf/core/encoder/xor.rb b/lib/msf/core/encoder/xor.rb index 660171ea6c..d713d770ba 100644 --- a/lib/msf/core/encoder/xor.rb +++ b/lib/msf/core/encoder/xor.rb @@ -11,7 +11,7 @@ class Msf::Encoder::Xor < Msf::Encoder # Encodes a block using the XOR encoder from the Rex library. # def encode_block(state, block) - return Rex::Encoding::Xor::Dword.encode(block, [ state.key ].pack(state.decoder_key_pack))[0] + Rex::Encoding::Xor::Dword.encode(block, [ state.key ].pack(state.decoder_key_pack))[0] end # @@ -24,15 +24,14 @@ class Msf::Encoder::Xor < Msf::Encoder # 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 - badchars.each_byte { |badchar| - - buf.each_byte { |byte| + buf.each_byte { |byte| + badchars.each_byte { |badchar| bad_keys[byte_idx % decoder_key_size][byte ^ badchar] = true - - byte_idx += 1 } - - # Assume our key itself is placed w/o encoding + byte_idx += 1 + } + + badchars.each_byte { |badchar| 0.upto(decoder_key_size-1) { |i| bad_keys[i][badchar] = true } @@ -41,27 +40,4 @@ class Msf::Encoder::Xor < Msf::Encoder return bad_keys end - # Added for test purposes, remove once we resolve encoding issues... - def find_key_verify(buf, key_bytes, badchars) - ekey = key_bytes_to_buffer(key_bytes) - - out = '' - idx = 0 - while (idx < buf.length) - 0.upto(ekey.length-1) do |i| - break if ! buf[idx+i] - out << (buf[idx+i]^ekey[i]).chr - end - - idx += ekey.length - end - - badchars.each do |c| - return false if out.index(c) - end - - true - end - - end