Class: Msf::Encoder::Xor

Inherits:
Msf::Encoder show all
Defined in:
lib/msf/core/encoder/xor.rb

Overview

This class provides basic XOR encoding of buffers.

Direct Known Subclasses

XorAdditiveFeedback

Instance Attribute Summary

Attributes inherited from Module

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

Attributes included from Framework::Offspring

#framework

Attributes included from Rex::Ui::Subscriber::Input

#user_input

Attributes included from Rex::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, #decoder_stub, #do_encode, #encode, #encode_begin, #encode_end, #encode_finalize_stub, #encoder_type, #initialize, #prepend_buf, #to_native, #type, type

Methods inherited from 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, #initialize, 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 Rex::Ui::Subscriber

#copy_ui, #init_ui, #reset_ui

Methods included from Rex::Ui::Subscriber::Input

#gets

Methods included from Rex::Ui::Subscriber::Output

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

Constructor Details

This class inherits a constructor from Msf::Encoder

Instance Method Details

#encode_block(state, block) ⇒ Object

Encodes a block using the XOR encoder from the Rex library.


14
15
16
17
18
19
20
21
22
23
# File 'lib/msf/core/encoder/xor.rb', line 14

def encode_block(state, block)
  encoder = case state.decoder_key_size
    when Rex::Encoding::Xor::Qword.keysize then Rex::Encoding::Xor::Qword
    when Rex::Encoding::Xor::Dword.keysize then	Rex::Encoding::Xor::Dword
    when Rex::Encoding::Xor::Word.keysize then Rex::Encoding::Xor::Word
    when Rex::Encoding::Xor::Byte.keysize then Rex::Encoding::Xor::Byte
    else Rex::Encoding::Xor::Dword
  end
  encoder.encode(block, [ state.key ].pack(state.decoder_key_pack))[0]
end

#find_bad_keys(buf, badchars) ⇒ Object

Finds keys that are incompatible with the supplied bad character list.


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
# File 'lib/msf/core/encoder/xor.rb', line 28

def find_bad_keys(buf, badchars)
  # Short circuit if there are no badchars
  return super if badchars.length == 0

  bad_keys = Array.new(decoder_key_size) { Hash.new }
  byte_idx = 0

  # Scan through all the badchars and build out the bad_keys array
  # based on the XOR'd combinations that can occur at certain bytes
  # to produce bad characters
  buf.each_byte { |byte|
    badchars.each_byte { |badchar|
      bad_keys[byte_idx % decoder_key_size][byte ^ badchar] = true
    }
    byte_idx += 1
  }

  badchars.each_byte { |badchar|
    0.upto(decoder_key_size-1) { |i|
      bad_keys[i][badchar] = true
    }
  }

  return bad_keys
end