Class: Rex::Encoder::BloXor

Inherits:
Msf::Encoder
  • Object
show all
Defined in:
lib/rex/encoder/bloxor/bloxor.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ BloXor

Returns a new instance of BloXor.



11
12
13
14
15
16
# File 'lib/rex/encoder/bloxor/bloxor.rb', line 11

def initialize( *args )
  super
  @machine    = nil
  @blocks_out = []
  @block_size = 0
end

Instance Method Details

#decoder_stub(state) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rex/encoder/bloxor/bloxor.rb', line 21

def decoder_stub( state )

  if( not state.decoder_stub )
    @blocks_out = []
    @block_size = 0

    # XXX: It would be ideal to use a random block size but unless we know the maximum size our final encoded
    # blob can be we should instead start with the smallest block size and go up to avoid generating
    # anything too big (if we knew the max size we could try something smaller if we generated a blob too big)
    #block_sizes = (1..state.buf.length).to_a.shuffle
    #block_sizes.each do | len |

    1.upto( state.buf.length ) do | len |

      # For now we ignore all odd sizes to help with performance (The rex poly machine
      # doesnt have many load/store primitives that can handle byte sizes efficiently)
      if( len % 2 != 0 )
        next
      end

      blocks, size = compute_encoded( state, len )
      if( blocks and size )

        # We sanity check that the newly generated block ammount and the block size
        # are not in the badchar list when converted into a hex form. Helps speed
        # things up a great deal when generating a decoder stub later as these
        # values may be used throughout.

        if( not number_is_valid?( state, blocks.length - 1 ) or not number_is_valid?( state, ~( blocks.length - 1 ) ) )
          next
        end

        if( not number_is_valid?( state, size ) or not number_is_valid?( state, ~size ) )
          next
        end

        @blocks_out = blocks
        @block_size = size

        break
      end
    end

    raise RuntimeError, "Unable to generate seed block." if( @blocks_out.empty? )

    state.decoder_stub = compute_decoder( state )
  end

  state.decoder_stub
end

#encode_block(state, data) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/rex/encoder/bloxor/bloxor.rb', line 75

def encode_block( state, data )

  buffer = ''

  @blocks_out.each do | block |
    buffer << block.pack( 'C*' )
  end

  buffer
end