aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-dcerpc-frsrpc.c
blob: 6fd2c1e692604e3f3bcb232bc27c56f3a25535a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
47
48
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
144
145
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
177
178
179
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
214
215
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/* packet-dcerpc-frsrpc.c
 * Routines for the frs (File Replication Service) MSRPC interface 
 * Copyright 2004 Jean-Baptiste Marchand <jbm@hsc.fr>
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <glib.h>
#include <epan/packet.h>
#include "packet-dcerpc.h"
#include "packet-dcerpc-frsrpc.h"
#include "packet-smb-common.h"
#include "packet-windows-common.h"

static int proto_dcerpc_frsrpc		= -1;

static int hf_frsrpc_opnum 		= -1;
static int hf_frsrpc_tlvsize		= -1;
static int hf_frsrpc_tlv		= -1;
static int hf_frsrpc_tlv_item		= -1;
static int hf_frsrpc_tlv_tag		= -1;
static int hf_frsrpc_tlv_size		= -1;
static int hf_frsrpc_tlv_data		= -1;
static int hf_frsrpc_unknown32		= -1;
static int hf_frsrpc_unknownbytes	= -1;
static int hf_frsrpc_guid_size		= -1;
static int hf_frsrpc_ssrv_guid		= -1;
static int hf_frsrpc_dsrv_guid		= -1;
static int hf_frsrpc_str_size		= -1;
static int hf_frsrpc_ssrv		= -1;
static int hf_frsrpc_dsrv		= -1;
static int hf_frsrpc_timestamp		= -1;


static gint ett_dcerpc_frsrpc		= -1;
static gint ett_frsrpc_tlv		= -1;
static gint ett_frsrpc_tlv_item		= -1;

/*
IDL [ uuid(f5cc59b4-4264-101a-8c59-08002b2f8426),
IDL  version(1.1),
IDL  implicit_handle(handle_t rpc_binding)
IDL ] interface frsrpc
*/


static e_uuid_t uuid_dcerpc_frsrpc = {
	0xf5cc59b4, 0x4264, 0x101a,
	{ 0x8c, 0x59, 0x08, 0x00, 0x2b, 0x2f, 0x84, 0x26 }
};

static guint16 ver_dcerpc_frsrpc = 1; 

#define TLV_SSRV	3
#define TLV_DSRV	4
#define TLV_TS		18
static const value_string tag_vals[] = {
	{TLV_SSRV,	"SOURCE SERVER"},
	{TLV_DSRV,	"DESTINATION SERVER"},
	{TLV_TS,	"TIMESTAMP"},
	{0,NULL}
};



static void
dissect_tlv_ssrv(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, guint8 *drep)
{
	int offset = 0;
	const char *dn;
	int dn_len;
	guint16 bc;

	/* a GUID */
	proto_tree_add_item(tree, hf_frsrpc_guid_size, tvb, offset, 4, TRUE);
	offset+=4;

	offset=dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, hf_frsrpc_ssrv_guid, NULL);


	/* the name of the source server sending this */
	proto_tree_add_item(tree, hf_frsrpc_str_size, tvb, offset, 4, TRUE);
	dn_len = tvb_get_ntohl(tvb, offset);
	offset+=4;

	bc = tvb_length_remaining(tvb, offset);
	dn = get_unicode_or_ascii_string(tvb, &offset, TRUE, &dn_len, TRUE, TRUE, &bc);
	proto_tree_add_string(tree, hf_frsrpc_ssrv, tvb, offset, dn_len, dn);
}

static void
dissect_tlv_dsrv(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, guint8 *drep)
{
	int offset = 0;
	const char *dn;
	int dn_len;
	guint16 bc;

	/* a GUID */
	proto_tree_add_item(tree, hf_frsrpc_guid_size, tvb, offset, 4, TRUE);
	offset+=4;

	offset=dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, hf_frsrpc_dsrv_guid, NULL);


	/* the name of the source server sending this */
	proto_tree_add_item(tree, hf_frsrpc_str_size, tvb, offset, 4, TRUE);
	dn_len = tvb_get_ntohl(tvb, offset);
	offset+=4;

	bc = tvb_length_remaining(tvb, offset);
	dn = get_unicode_or_ascii_string(tvb, &offset, TRUE, &dn_len, TRUE, TRUE, &bc);
	proto_tree_add_string(tree, hf_frsrpc_dsrv, tvb, offset, dn_len, dn);
}


static void
dissect_tlv_ts(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, guint8 *drep _U_)
{
	dissect_nt_64bit_time(tvb, tree, 0, hf_frsrpc_timestamp);
}


static void
dissect_TLV_blob(packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, guint8 *drep)
{
	proto_item *item = NULL;
	proto_tree *tree = NULL;
	proto_item *tlv_item = NULL;
	proto_tree *tlv_tree = NULL;
	unsigned int offset = 0;
	guint16 tag;
	guint32 size;

	item = proto_tree_add_item(parent_tree, hf_frsrpc_tlv, tvb, offset, -1, TRUE);
	tree = proto_item_add_subtree(item, ett_frsrpc_tlv);

	while (offset < tvb_length(tvb)) {
		unsigned int old_offset = offset;
		tvbuff_t *next_tvb;

		tlv_item = proto_tree_add_item(tree, hf_frsrpc_tlv_item, tvb, offset, -1, TRUE);
		tlv_tree = proto_item_add_subtree(tlv_item, ett_frsrpc_tlv_item);

		tag = tvb_get_letohs(tvb, offset);
		proto_tree_add_item(tlv_tree, hf_frsrpc_tlv_tag, tvb, offset, 2, TRUE);
		offset+=2;
		proto_item_append_text(tlv_item, " %s", val_to_str(tag, tag_vals, "UNKNOWN TAG:0x%x"));


		size = tvb_get_letohl(tvb, offset);
		proto_tree_add_item(tlv_tree, hf_frsrpc_tlv_size, tvb, offset, 2, TRUE);
		offset+=4;

		next_tvb = tvb_new_subset(tvb, offset, size, size);
		switch (tag) {
		case TLV_SSRV:
			dissect_tlv_ssrv(pinfo, tlv_tree, next_tvb, drep);
			break;
		case TLV_DSRV:
			dissect_tlv_dsrv(pinfo, tlv_tree, next_tvb, drep);
			break;
		case TLV_TS:
			dissect_tlv_ts(pinfo, tlv_tree, next_tvb, drep);
			break;
		default:
			proto_tree_add_item(tlv_tree, hf_frsrpc_tlv_data, next_tvb, 0, size, TRUE);
		}
		offset+=size;

		proto_item_set_len(tlv_item, offset-old_offset);
	}
}

static int
frsrpc_dissect_SendCommPkt_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)
{
	tvbuff_t *next_tvb;
	guint32 tlvsize;
	dcerpc_info *di;

	di=pinfo->private_data;
	pinfo->dcerpc_procedure_name="SendCommPkt";

	if(di->conformant_run){
		/* just a run to handle conformant arrays, no scalars to dissect */
		return offset;
	}

	/* 16 unknown bytes */
	proto_tree_add_item(tree, hf_frsrpc_unknownbytes, tvb, offset, 16, TRUE);
	offset+=16;

	offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, hf_frsrpc_tlvsize, 0);

	/* 16 unknown bytes */
	proto_tree_add_item(tree, hf_frsrpc_unknownbytes, tvb, offset, 16, TRUE);
	offset+=16;

	/* this is a subcontext that starts with the length of the data in bytes
	   followed by concatenated TLV values.
	   this is NOT ndr encoded
	*/
	offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, tree, drep, hf_frsrpc_tlvsize, &tlvsize);
	next_tvb = tvb_new_subset(tvb, offset, tlvsize, tlvsize);
	dissect_TLV_blob(pinfo, tree, next_tvb, drep);
	offset+=tlvsize;



	proto_tree_add_item(tree, hf_frsrpc_unknownbytes, tvb, offset, -1, TRUE);
	offset += tvb_length_remaining(tvb, offset);

	return offset;
}

static dcerpc_sub_dissector dcerpc_frsrpc_dissectors[] = {
	{ FRSRPC_SEND_COMM_PKT, "FrsRpcSendCommPkt", 
		frsrpc_dissect_SendCommPkt_request, NULL },
	{ FRSRPC_VERIFY_PROMOTION_PARENT, "FrsRpcVerifyPromotionParent", 
		NULL, NULL },
	{ FRSRPC_START_PROMOTION_PARENT, "FrsRpcStartPromotionParent", 
		NULL, NULL },
	{ FRSRPC_NOP, "FrsRpcNop", NULL, NULL },
/* operations 4 to 9 are apparently identical */
	{ FRSRPC_BACKUP_COMPLETE, "FrsRpcBackupComplete", NULL, NULL },
	{ FRSRPC_BACKUP_COMPLETE_5, "FrsRpcBackupComplete", NULL, NULL },
	{ FRSRPC_BACKUP_COMPLETE_6, "FrsRpcBackupComplete", NULL, NULL },
	{ FRSRPC_BACKUP_COMPLETE_7, "FrsRpcBackupComplete", NULL, NULL },
	{ FRSRPC_BACKUP_COMPLETE_8, "FrsRpcBackupComplete", NULL, NULL },
	{ FRSRPC_BACKUP_COMPLETE_9, "FrsRpcBackupComplete", NULL, NULL },
	{ FRSRPC_VERIFY_PROMOTION_PARENT_EX, "FrsRpcVerifyPromotionParentEx",
		NULL, NULL },
        { 0, NULL, NULL,  NULL }
};


void
proto_register_dcerpc_frsrpc(void)
{

        static hf_register_info hf[] = {

		{ &hf_frsrpc_opnum, 
		  { "Operation", "frsrpc.opnum", FT_UINT16, BASE_DEC,
		   NULL, 0x0, NULL, HFILL }},	

		{ &hf_frsrpc_unknown32, 
		  { "unknown32", "frsrpc.unknown32", FT_UINT32, BASE_HEX,
		   NULL, 0x0, "unknown int32", HFILL }},	

		{ &hf_frsrpc_tlvsize, 
		  { "TLV Size", "frsrpc.tlv_size", FT_UINT32, BASE_DEC,
		   NULL, 0x0, "Size of tlv blob in bytes", HFILL }},	

		{ &hf_frsrpc_tlv, 
		  { "TLV", "frsrpc.tlv", FT_NONE, BASE_NONE,
		   NULL, 0x0, "A tlv blob", HFILL }},	

		{ &hf_frsrpc_tlv_item, 
		  { "TLV", "frsrpc.tlv_item", FT_NONE, BASE_NONE,
		   NULL, 0x0, "A tlv item", HFILL }},	

		{ &hf_frsrpc_tlv_tag, 
		  { "TLV Tag", "frsrpc.tlv.tag", FT_UINT16, BASE_DEC,
		   NULL, 0x0, NULL, HFILL }},	

		{ &hf_frsrpc_tlv_size, 
		  { "TLV Size", "frsrpc.tlv.size", FT_UINT32, BASE_DEC,
		   NULL, 0x0, NULL, HFILL }},	

		{ &hf_frsrpc_tlv_data, 
		  { "TLV Data", "frsrpc.tlv.data", FT_BYTES, BASE_NONE,
		   NULL, 0x0, NULL, HFILL }},	

		{ &hf_frsrpc_unknownbytes, 
		  { "unknown", "frsrpc.unknownbytes", FT_BYTES, BASE_NONE,
		   NULL, 0x0, "unknown bytes", HFILL }},	

		{ &hf_frsrpc_guid_size, 
		  { "Guid Size", "frsrpc.guid.size", FT_UINT32, BASE_DEC,
		   NULL, 0x0, NULL, HFILL }},	

		{ &hf_frsrpc_ssrv_guid,
		  { "SSRV GUID", "frsrpc.ssrv.guid", FT_GUID, BASE_NONE,
		    NULL, 0x0, NULL, HFILL }},

		{ &hf_frsrpc_dsrv_guid,
		  { "DSRV GUID", "frsrpc.dsrv.guid", FT_GUID, BASE_NONE,
		    NULL, 0x0, NULL, HFILL }},

		{ &hf_frsrpc_str_size, 
		  { "String Size", "frsrpc.str.size", FT_UINT32, BASE_DEC,
		   NULL, 0x0, NULL, HFILL }},	

		{ &hf_frsrpc_ssrv,
		  { "SSRV", "frsrpc.ssrv", FT_STRING, BASE_NONE,
		    NULL, 0x0, NULL, HFILL }},

		{ &hf_frsrpc_dsrv,
		  { "DSRV", "frsrpc.dsrv", FT_STRING, BASE_NONE,
		    NULL, 0x0, NULL, HFILL }},

		{ &hf_frsrpc_timestamp,
		  { "Timestamp", "frsrpc.timestamp", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
		    NULL, 0x0, NULL, HFILL }},
	};


        static gint *ett[] = {
                &ett_dcerpc_frsrpc,
		&ett_frsrpc_tlv,
		&ett_frsrpc_tlv_item,
        };


	proto_dcerpc_frsrpc = proto_register_protocol(
		"Microsoft File Replication Service", "FRSRPC", "frsrpc");

	proto_register_field_array(proto_dcerpc_frsrpc, hf, array_length(hf));

        proto_register_subtree_array(ett, array_length(ett));

}


void
proto_reg_handoff_dcerpc_frsrpc(void)
{
	/* register protocol as dcerpc */

	dcerpc_init_uuid(
		proto_dcerpc_frsrpc, ett_dcerpc_frsrpc, &uuid_dcerpc_frsrpc,
		ver_dcerpc_frsrpc, dcerpc_frsrpc_dissectors, hf_frsrpc_opnum);
}