git-svn-id: file:///home/svn/incoming/trunk@3621 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2006-04-26 16:51:05 +00:00
parent 0f142d18e4
commit d0b3483d41
2 changed files with 16 additions and 40 deletions

View File

@ -383,17 +383,17 @@ protected
# Scan each byte position # Scan each byte position
0.upto(decoder_key_size - 1) { |index| 0.upto(decoder_key_size - 1) { |index|
# Subtract the bad and leave the good # Subtract the bad and leave the good
good_keys = allset-bad_keys[index].keys good_keys = allset-bad_keys[index].keys
# Was there anything left for this index? # Was there anything left for this index?
if (good_keys.length == 0) if (good_keys.length == 0)
# Not much we can do about this :( # Not much we can do about this :(
return nil return nil
end end
# Set the appropriate key byte # Set the appropriate key byte
key_bytes[index] = good_keys[ rand(good_keys.length) ] key_bytes[index] = good_keys[ rand(good_keys.length) ]
} }
# Assume that we're going to rock this shit... # Assume that we're going to rock this shit...

View File

@ -11,7 +11,7 @@ class Msf::Encoder::Xor < Msf::Encoder
# Encodes a block using the XOR encoder from the Rex library. # Encodes a block using the XOR encoder from the Rex library.
# #
def encode_block(state, block) 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 end
# #
@ -24,15 +24,14 @@ class Msf::Encoder::Xor < Msf::Encoder
# Scan through all the badchars and build out the bad_keys array # Scan through all the badchars and build out the bad_keys array
# based on the XOR'd combinations that can occur at certain bytes # based on the XOR'd combinations that can occur at certain bytes
# to produce bad characters # to produce bad characters
badchars.each_byte { |badchar| buf.each_byte { |byte|
badchars.each_byte { |badchar|
buf.each_byte { |byte|
bad_keys[byte_idx % decoder_key_size][byte ^ badchar] = true bad_keys[byte_idx % decoder_key_size][byte ^ badchar] = true
byte_idx += 1
} }
byte_idx += 1
}
# Assume our key itself is placed w/o encoding badchars.each_byte { |badchar|
0.upto(decoder_key_size-1) { |i| 0.upto(decoder_key_size-1) { |i|
bad_keys[i][badchar] = true bad_keys[i][badchar] = true
} }
@ -41,27 +40,4 @@ class Msf::Encoder::Xor < Msf::Encoder
return bad_keys return bad_keys
end 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 end