CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/dcerpc/ndr.rb
Views: 11704
1
# -*- coding: binary -*-
2
require "rex/text"
3
4
module Rex
5
module Proto
6
module DCERPC
7
class NDR
8
9
10
# Provide padding to align the string to the 32bit boundary
11
def self.align(string)
12
warn 'should be using Rex::Encoder::NDR'
13
return "\x00" * ((4 - (string.length & 3)) & 3)
14
end
15
16
# Encode a 4 byte long
17
# use to encode:
18
# long element_1;
19
def self.long(string)
20
warn 'should be using Rex::Encoder::NDR'
21
return [string].pack('V')
22
end
23
24
# Encode a 2 byte short
25
# use to encode:
26
# short element_1;
27
def self.short(string)
28
warn 'should be using Rex::Encoder::NDR'
29
return [string].pack('v')
30
end
31
32
# Encode a single byte
33
# use to encode:
34
# byte element_1;
35
def self.byte(string)
36
warn 'should be using Rex::Encoder::NDR'
37
return [string].pack('C')
38
end
39
40
# Encode a byte array
41
# use to encode:
42
# char element_1
43
def self.UniConformantArray(string)
44
warn 'should be using Rex::Encoder::NDR'
45
return long(string.length) + string + align(string)
46
end
47
48
# Encode a string
49
# use to encode:
50
# w_char *element_1;
51
def self.UnicodeConformantVaryingString(string)
52
warn 'should be using Rex::Encoder::NDR'
53
string += "\x00" # null pad
54
return long(string.length) + long(0) + long(string.length) + Rex::Text.to_unicode(string) + align(Rex::Text.to_unicode(string))
55
end
56
57
# Encode a string that is already unicode encoded
58
# use to encode:
59
# w_char *element_1;
60
def self.UnicodeConformantVaryingStringPreBuilt(string)
61
warn 'should be using Rex::Encoder::NDR'
62
# if the string len is odd, thats bad!
63
if string.length % 2 > 0
64
string += "\x00"
65
end
66
len = string.length / 2;
67
return long(len) + long(0) + long(len) + string + align(string)
68
end
69
70
end
71
end
72
end
73
end
74
75