From e1565e2af47c17c5ae7dd1561283490524e958d9 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Thu, 28 Dec 2006 05:19:31 +0000 Subject: [PATCH] fixed a few issues with the alpha2 implementation git-svn-id: file:///home/svn/framework3/trunk@4230 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/encoded_payload.rb | 1 + lib/rex/encoder/alpha2/alpha_upper.rb | 2 +- lib/rex/encoder/alpha2/generic.rb | 21 ++++++++++++--------- lib/rex/encoder/alpha2/unicode_upper.rb | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/msf/core/encoded_payload.rb b/lib/msf/core/encoded_payload.rb index c3c1eb6ba4..f2bcda8896 100644 --- a/lib/msf/core/encoded_payload.rb +++ b/lib/msf/core/encoded_payload.rb @@ -130,6 +130,7 @@ class EncodedPayload # framework that an encoder must be explicitly defined as the # encoder of choice for an exploit. if ((reqs['EncoderType'].nil?) and + (reqs['Encoder'].nil?) and (self.encoder.rank == ManualRanking)) wlog("#{pinst.refname}: Encoder #{encoder.refname} is manual ranked and was not defined as a preferred encoder.", 'core', LEV_1) diff --git a/lib/rex/encoder/alpha2/alpha_upper.rb b/lib/rex/encoder/alpha2/alpha_upper.rb index 3e240e0025..e9da1efcd5 100644 --- a/lib/rex/encoder/alpha2/alpha_upper.rb +++ b/lib/rex/encoder/alpha2/alpha_upper.rb @@ -7,7 +7,7 @@ module Encoder module Alpha2 class AlphaUpper < Generic - @@accepted_chars = ('B' .. 'Z').to_a + ('0' .. '9').to_a + @@default_accepted_chars = ('B' .. 'Z').to_a + ('0' .. '9').to_a def self.gen_decoder_prefix(reg, offset) if (offset > 20) diff --git a/lib/rex/encoder/alpha2/generic.rb b/lib/rex/encoder/alpha2/generic.rb index dddf20c60b..7e972a7859 100644 --- a/lib/rex/encoder/alpha2/generic.rb +++ b/lib/rex/encoder/alpha2/generic.rb @@ -7,7 +7,8 @@ module Encoder module Alpha2 class Generic - @@accepted_chars = ('a' .. 'z').to_a + ('B' .. 'Z').to_a + ('0' .. '9').to_a + + @@default_accepted_chars = ('a' .. 'z').to_a + ('B' .. 'Z').to_a + ('0' .. '9').to_a def Generic.gen_decoder_prefix(reg, offset) # Should never happen - have to pick a specifc @@ -35,24 +36,26 @@ class Generic end def Generic.encode_byte(block, badchars) - first = 0 - second = 1 - randbase = 0 + accepted_chars = @@default_accepted_chars.dup # Remove bad chars from the accepted_chars list. Sadly 'A' must be # an accepted char or we'll certainly fail at this point. This could # be fixed later maybe with some recalculation of the encoder stubs... # - Puss - (badchars || '').split('').each { |c| @@accepted_chars.delete(c) } + (badchars || '').split('').each { |c| accepted_chars.delete(c) } + + first = 0 + second = 1 + randbase = 0 gen_base_set(block).each do |randbase| second = gen_second(block, randbase) next if second < 0 - break if @@accepted_chars.include?(second.chr) + break if accepted_chars.include?(second.chr) end raise RuntimeError, "Negative" if second < 0 - raise RuntimeError, "BadChar; #{block} to #{second}" if not @@accepted_chars.include?(second.chr) + raise RuntimeError, "BadChar; #{block} to #{second}" if not accepted_chars.include?(second.chr) if (randbase > 0xa0) # first num must be 4 @@ -74,13 +77,13 @@ class Generic first.to_i.chr + second.chr end - def Generic.encode(buf, reg, offset) + def Generic.encode(buf, reg, offset, badchars = '') encoded = gen_decoder(reg, offset) buf.each_byte { |block| - encoded += encode_byte(block) + encoded += encode_byte(block, badchars) } encoded += add_terminator() diff --git a/lib/rex/encoder/alpha2/unicode_upper.rb b/lib/rex/encoder/alpha2/unicode_upper.rb index 366762338d..bd838568dc 100644 --- a/lib/rex/encoder/alpha2/unicode_upper.rb +++ b/lib/rex/encoder/alpha2/unicode_upper.rb @@ -7,7 +7,7 @@ module Encoder module Alpha2 class UnicodeUpper < Generic - @@accepted_chars = ('B' .. 'Z').to_a + ('0' .. '9').to_a + @@default_accepted_chars = ('B' .. 'Z').to_a + ('0' .. '9').to_a def self.gen_base_set(max) Rex::Text.shuffle_a(