Class: Rex::Encoder::BloXor

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

Instance Attribute Summary

Attributes inherited from Msf::Module

#arch, #author, #datastore, #error, #job_id, #license, #module_store, #options, #platform, #privileged, #references, #uuid

Attributes included from Msf::Framework::Offspring

#framework

Attributes included from Ui::Subscriber::Input

#user_input

Attributes included from Ui::Subscriber::Output

#user_output

Instance Method Summary collapse

Methods inherited from Msf::Encoder

#decoder_block_size, #decoder_hash, #decoder_key_offset, #decoder_key_pack, #decoder_key_size, #do_encode, #encode, #encode_begin, #encode_end, #encode_finalize_stub, #encoder_type, #prepend_buf, #to_native, #type, type

Methods inherited from Msf::Module

#[], #[]=, #alias, #arch?, #arch_to_s, #author_to_s, #auxiliary?, cached?, #check, #comm, #compat, #compatible?, #debugging?, #description, #disclosure_date, #each_arch, #each_author, #encoder?, #exploit?, #fail_with, #file_path, #framework, #fullname, fullname, #import_defaults, is_usable, #name, #nop?, #orig_cls, #owner, #payload?, #platform?, #platform_to_s, #post?, #print_error, #print_good, #print_line, #print_line_prefix, #print_prefix, #print_status, #print_warning, #privileged?, rank, #rank, rank_to_h, #rank_to_h, rank_to_s, #rank_to_s, #refname, #register_parent, #replicant, #search_filter, #share_datastore, #shortname, shortname, #support_ipv6?, #target_host, #target_port, #type, type, #validate, #vprint_debug, #vprint_error, #vprint_good, #vprint_line, #vprint_status, #vprint_warning, #workspace

Methods included from Ui::Subscriber

#copy_ui, #init_ui, #reset_ui

Methods included from Ui::Subscriber::Input

#gets

Methods included from Ui::Subscriber::Output

#flush, #print, #print_debug, #print_error, #print_good, #print_line, #print_status, #print_warning

Constructor Details

#initialize(*args) ⇒ BloXor

Returns a new instance of BloXor


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

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

Instance Method Details

#decoder_stub(state) ⇒ Object


20
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
# File 'lib/rex/encoder/bloxor/bloxor.rb', line 20

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


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

def encode_block( state, data )

  buffer = ''

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

  buffer
end