Class: Rex::Proto::DCERPC::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/dcerpc/packet.rb

Defined Under Namespace

Classes: UnitTest

Constant Summary collapse

UUID =
Rex::Proto::DCERPC::UUID

Class Method Summary collapse

Class Method Details

.make_alter_context(uuid, vers) ⇒ Object

Create a standard DCERPC ALTER_CONTEXT request packet



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rex/proto/dcerpc/packet.rb', line 146

def self.make_alter_context(uuid, vers)
	u = Rex::Proto::DCERPC::UUID

	# Process the version strings ("1.0", 1.0, "1", 1)
	bind_vers_maj, bind_vers_min = UUID.vers_to_nums(vers)
	xfer_vers_maj, xfer_vers_min = UUID.vers_to_nums(UUID.xfer_syntax_vers)

	buff =
	[
		5,      # major version 5
		0,      # minor version 0
		14,     # alter context
		3,      # flags
		0x10000000,     # data representation
		72,     # frag length
		0,      # auth length
		0,      # call id
		5840,   # max xmit frag
		5840,   # max recv frag
		0,      # assoc group
		1,      # num ctx items
		0,      # context id
		1,      # num trans items
		UUID.uuid_pack(uuid),   # interface uuid
		bind_vers_maj,       # interface major version
		bind_vers_min,       # interface minor version
		UUID.xfer_syntax_uuid,  # transfer syntax
		xfer_vers_maj,       # syntax major version
		xfer_vers_min,       # syntax minor version
	].pack('CCCCNvvVvvVVvvA16vvA16vv')
end

.make_bind(uuid, vers) ⇒ Object

Create a standard DCERPC BIND request packet



14
15
16
17
18
19
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
# File 'lib/rex/proto/dcerpc/packet.rb', line 14

def self.make_bind(uuid, vers)

	# Process the version strings ("1.0", 1.0, "1", 1)
	bind_vers_maj, bind_vers_min = UUID.vers_to_nums(vers)
	xfer_vers_maj, xfer_vers_min = UUID.vers_to_nums(UUID.xfer_syntax_vers)

	# Create the bind request packet
	buff =
	[
		5,      # major version 5
		0,      # minor version 0
		11,     # bind type
		3,      # flags
		0x10000000,  # data representation
		72,     # frag length
		0,      # auth length
		0,      # call id
		5840,   # max xmit frag
		5840,   # max recv frag
		0,      # assoc group
		1,      # num ctx items
		0,      # context id
		1,      # num trans items
		UUID.uuid_pack(uuid),   # interface uuid
		bind_vers_maj,       # interface major version
		bind_vers_min,       # interface minor version
		UUID.xfer_syntax_uuid,  # transfer syntax
		xfer_vers_maj,       # syntax major version
		xfer_vers_min,       # syntax minor version
	].pack('CCCCNvvVvvVVvvA16vvA16vv')

	return buff, 0
end

.make_bind_fake_multi(uuid, vers, bind_head = 0, bind_tail = 0) ⇒ Object

Create an obfuscated DCERPC BIND request packet



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/rex/proto/dcerpc/packet.rb', line 49

def self.make_bind_fake_multi(uuid, vers, bind_head=0, bind_tail=0)

	bind_head = bind_head.to_i
	bind_tail = bind_tail.to_i
	bind_head = rand(6)+10 if bind_head == 0
	bind_tail = rand(4)+1 if bind_head == 0

	u = Rex::Proto::DCERPC::UUID

	# Process the version strings ("1.0", 1.0, "1", 1)
	bind_vers_maj, bind_vers_min = UUID.vers_to_nums(vers)
	xfer_vers_maj, xfer_vers_min = UUID.vers_to_nums(UUID.xfer_syntax_vers)

	bind_total = bind_head + bind_tail + 1
	bind_size  = (bind_total * 44) + 28
	real_ctx, ctx = 0, 0

	# Create the header of the bind request
	data =
	[
		5,      # major version 5
		0,      # minor version 0
		11,     # bind type
		3,      # flags
		0x10000000,  # data representation
		bind_size,   # frag length
		0,      # auth length
		0,      # call id
		5840,   # max xmit frag
		5840,   # max recv frag
		0,      # assoc group
		bind_total,  # num ctx items
	].pack('CCCCNvvVvvVV')

	# Generate the fake UUIDs prior to the real one
	1.upto(bind_head) do ||
		# Generate some random UUID and versions
		rand_uuid = Rex::Text.rand_text(16)
		rand_imaj = rand(6)
		rand_imin = rand(4)

		data +=
		[
			ctx,        # context id
			1,          # num trans items
			rand_uuid,  # interface uuid
			rand_imaj,  # interface major version
			rand_imin,  # interface minor version
			UUID.xfer_syntax_uuid,  # transfer syntax
			xfer_vers_maj,       # syntax major version
			xfer_vers_min,       # syntax minor version
		].pack('vvA16vvA16vv')
		ctx += 1
	end

	# Stuff the real UUID onto the end of the buffer
	real_ctx = ctx;
	data +=
	[
		ctx,      # context id
		1,        # num trans items
		UUID.uuid_pack(uuid),   # interface uuid
		bind_vers_maj,       # interface major version
		bind_vers_min,       # interface minor version
		UUID.xfer_syntax_uuid,  # transfer syntax
		xfer_vers_maj,       # syntax major version
		xfer_vers_min,       # syntax minor version
	].pack('vvA16vvA16vv')
	ctx += 1


	# Generate the fake UUIDs after the real one
	1.upto(bind_tail) do ||
		# Generate some random UUID and versions
		rand_uuid = Rex::Text.rand_text(16)
		rand_imaj = rand(6)
		rand_imin = rand(4)

		data +=
		[
			ctx,        # context id
			1,          # num trans items
			rand_uuid,  # interface uuid
			rand_imaj,  # interface major version
			rand_imin,  # interface minor version
			UUID.xfer_syntax_uuid,  # transfer syntax
			xfer_vers_maj,       # syntax major version
			xfer_vers_min,       # syntax minor version
		].pack('vvA16vvA16vv')
		ctx += 1
	end

	# Return both the bind packet and the real context_id
	return data, real_ctx
end

.make_request(opnum = 0, data = "", size = data.length, ctx = 0, object_id = '') ⇒ Object

Used to create standard DCERPC REQUEST packet(s)



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/rex/proto/dcerpc/packet.rb', line 216

def self.make_request(opnum=0, data="", size=data.length, ctx=0, object_id = '')

	opnum = opnum.to_i
	size  = [4000, size.to_i].min
	ctx   = ctx.to_i

	chunks, frags = [], []
	ptr = 0

	# Break the request into fragments of 'size' bytes
	while ptr < data.length
		chunks.push( data[ ptr, size ] )
		ptr += size
	end

	# Process requests with no stub data
	if chunks.length == 0
		frags.push( make_request_chunk(3, opnum, '', ctx, object_id) )
		return frags
	end

	# Process requests with only one fragment
	if chunks.length == 1
		frags.push( make_request_chunk(3, opnum, chunks[0], ctx, object_id) )
		return frags
	end

	# Create the first fragment of the request
	frags.push( make_request_chunk(1, opnum, chunks.shift, ctx, object_id) )

	# Create all of the middle fragments
	while chunks.length != 1
		frags.push( make_request_chunk(0, opnum, chunks.shift, ctx, object_id) )
	end

	# Create the last fragment of the request
	frags.push( make_request_chunk(2, opnum, chunks.shift, ctx, object_id) )

	return frags
end

.make_request_chunk(flags = 3, opnum = 0, data = "", ctx = 0, object_id = '') ⇒ Object

Used to create a piece of a DCERPC REQUEST packet



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/rex/proto/dcerpc/packet.rb', line 180

def self.make_request_chunk(flags=3, opnum=0, data="", ctx=0, object_id = '')

	flags = flags.to_i
	opnum = opnum.to_i
	ctx   = ctx.to_i

	dlen = data.length
	flen = dlen + 24

	use_object = 0

	object_str = ''

	if object_id.size > 0
		flags |= 0x80
		flen = flen + 16
		object_str = UUID.uuid_pack(object_id)
	end

	buff =
	[
		5,      # major version 5
		0,      # minor version 0
		0,      # request type
		flags,  # flags
		0x10000000,     # data representation
		flen,   # frag length
		0,      # auth length
		0,      # call id
		dlen,   # alloc hint
		ctx,    # context id
		opnum,  # operation number
	].pack('CCCCNvvVVvv') + object_str + data
end