Module: Rex::Encoder::NDR

Defined in:
lib/rex/encoder/ndr.rb

Class Method Summary collapse

Class Method Details

.align(string) ⇒ Object

Provide padding to align the string to the 32bit boundary



9
10
11
# File 'lib/rex/encoder/ndr.rb', line 9

def NDR.align(string)
  return "\x00" * ((4 - (string.length & 3)) & 3)
end

.byte(string) ⇒ Object

Encode a single byte use to encode:

byte element_1;


30
31
32
# File 'lib/rex/encoder/ndr.rb', line 30

def NDR.byte(string)
  return [string].pack('C')
end

.long(string) ⇒ Object

Encode a 4 byte long use to encode:

long element_1;


16
17
18
# File 'lib/rex/encoder/ndr.rb', line 16

def NDR.long(string)
  return [string].pack('V')
end

.short(string) ⇒ Object

Encode a 2 byte short use to encode:

short element_1;


23
24
25
# File 'lib/rex/encoder/ndr.rb', line 23

def NDR.short(string)
  return [string].pack('v')
end

.string(string) ⇒ Object

Encode a string use to encode:

char *element_1;


44
45
46
47
# File 'lib/rex/encoder/ndr.rb', line 44

def NDR.string(string)
  string << "\x00" # null pad
  return long(string.length) + long(0) + long(string.length) + string + align(string)
end

.UnicodeConformantVaryingString(string) ⇒ Object

alias to wstring, going away soon



78
79
80
# File 'lib/rex/encoder/ndr.rb', line 78

def NDR.UnicodeConformantVaryingString(string)
  NDR.wstring(string)
end

.UnicodeConformantVaryingStringPreBuilt(string) ⇒ Object

alias to wstring_prebuilt, going away soon



83
84
85
# File 'lib/rex/encoder/ndr.rb', line 83

def NDR.UnicodeConformantVaryingStringPreBuilt(string)
  NDR.wstring_prebuilt(string)
end

.UniConformantArray(string) ⇒ Object

Encode a byte array use to encode:

char  element_1


37
38
39
# File 'lib/rex/encoder/ndr.rb', line 37

def NDR.UniConformantArray(string)
  return long(string.length) + string + align(string)
end

.uwstring(string) ⇒ Object

Encode a string and make it unique use to encode:

[unique] w_char *element_1;


60
61
62
63
# File 'lib/rex/encoder/ndr.rb', line 60

def NDR.uwstring(string)
  string  = string + "\x00" # null pad
  return long(rand(0xffffffff))+long(string.length) + long(0) + long(string.length) + Rex::Text.to_unicode(string) + align(Rex::Text.to_unicode(string))
end

.wstring(string) ⇒ Object

Encode a string use to encode:

w_char *element_1;


52
53
54
55
# File 'lib/rex/encoder/ndr.rb', line 52

def NDR.wstring(string)
  string  = string + "\x00" # null pad
  return long(string.length) + long(0) + long(string.length) + Rex::Text.to_unicode(string) + align(Rex::Text.to_unicode(string))
end

.wstring_prebuilt(string) ⇒ Object

Encode a string that is already unicode encoded use to encode:

w_char *element_1;


68
69
70
71
72
73
74
75
# File 'lib/rex/encoder/ndr.rb', line 68

def NDR.wstring_prebuilt(string)
  # if the string len is odd, thats bad!
  if string.length % 2 > 0
    string = string + "\x00"
  end
  len = string.length / 2;
  return long(len) + long(0) + long(len) + string + align(string)
end