aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-gpef.c
blob: e92e73a29ecb880487e2b0313960c8a732c903a2 (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
/* packet-gpef.c
 * Routines for dissection of Group Policy : Encrypted File System Extension
 * Described in Microsoft document MS-GPEF.pdf
 * Copyright 2008, Ronnie Sahlberg
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include "packet-windows-common.h"
#include <epan/asn1.h>
#include "packet-x509af.h"

void proto_register_gpef(void);

static int proto_gpef = -1;
static int hf_gpef_keycount = -1;
static int hf_gpef_efskey = -1;
static int hf_gpef_efskey_length1 = -1;
static int hf_gpef_efskey_length2 = -1;
static int hf_gpef_efskey_sid_offset = -1;
static int hf_gpef_efskey_cert_offset = -1;
static int hf_gpef_efskey_cert_length = -1;
static int hf_gpef_efskey_certificate = -1;

static gint ett_gpef = -1;
static gint ett_gpef_efskey = -1;


/* MS-GPEF section 2.2.1.2.2 EfsKey*/
static int
dissect_gpef_efskey(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree)
{
	proto_item *item = NULL;
	proto_tree *tree = NULL;
	int old_offset = offset;
	guint32 length1, sid_offset;
	guint32 cert_length, cert_offset;
	tvbuff_t *next_tvb;
	asn1_ctx_t asn1_ctx;
	asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);

	if (parent_tree) {
		item = proto_tree_add_item(parent_tree, hf_gpef_efskey, tvb, -1, -1, ENC_NA);
		tree = proto_item_add_subtree(item, ett_gpef_efskey);
	}

	/* length 1 */
	length1 = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_gpef_efskey_length1, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* length 2 */
	proto_tree_add_item(tree, hf_gpef_efskey_length2, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* sid offset */
	sid_offset = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_gpef_efskey_sid_offset, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* reserved */
	offset += 4;

	/* cert length */
	cert_length = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_gpef_efskey_cert_length, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* cert offset */
	cert_offset = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_gpef_efskey_cert_offset, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	/*offset += 4;*/

	/* reserved, must be 0x20 0x00 0x00 0x00 */
	/*offset += 4;*/

	/* sid */
	dissect_nt_sid(tvb, old_offset+4+sid_offset, tree, "sid", NULL, -1);

	/* certificate */
	next_tvb = tvb_new_subset_length(tvb, old_offset+4+cert_offset, cert_length);
	(void)dissect_x509af_Certificate(FALSE, next_tvb, 0, &asn1_ctx, tree, hf_gpef_efskey_certificate);


	offset = old_offset + length1;
	proto_item_set_len(item, offset-old_offset);
	return offset;
}

/* MS-GPEF section 2.2.1.2.1 */
static int
dissect_gpef_efsblob(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data _U_)
{
	int offset = 0;
	proto_tree *tree;
	proto_item *item;
	guint32 count;

	item = proto_tree_add_item(parent_tree, proto_gpef, tvb, 0, -1, ENC_NA);
	tree = proto_item_add_subtree(item, ett_gpef);

	/* reserved, must be 0x01 0x00 0x01 0x00 */
	offset += 4;

	/* key count */
	count = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_gpef_keycount, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	while (count--) {
	      offset = dissect_gpef_efskey(tvb, offset, pinfo, tree);
	}

	return offset;
}

void
proto_register_gpef(void)
{
	static hf_register_info hf[] = {
		{ &hf_gpef_keycount,
		  { "Key Count",   "gpef.key_count", FT_UINT32, BASE_DEC, NULL,
		    0x0, NULL, HFILL }},

		{ &hf_gpef_efskey_length1,
		  { "Length1",   "gpef.efskey.length1", FT_UINT32, BASE_DEC, NULL,
		    0x0, NULL, HFILL }},

		{ &hf_gpef_efskey_length2,
		  { "Length2",   "gpef.efskey.length2", FT_UINT32, BASE_DEC, NULL,
		    0x0, NULL, HFILL }},

		{ &hf_gpef_efskey_sid_offset,
		  { "SID Offset",   "gpef.efskey.sid_offset", FT_UINT32, BASE_DEC, NULL,
		    0x0, NULL, HFILL }},

		{ &hf_gpef_efskey_cert_offset,
		  { "Cert Offset",   "gpef.efskey.cert_offset", FT_UINT32, BASE_DEC, NULL,
		    0x0, NULL, HFILL }},

		{ &hf_gpef_efskey_cert_length,
		  { "Cert Length",   "gpef.efskey.cert_length", FT_UINT32, BASE_DEC, NULL,
		    0x0, NULL, HFILL }},

		{ &hf_gpef_efskey,
		  { "EfsKey",   "gpef.efskey", FT_NONE, BASE_NONE, NULL,
		    0x0, NULL, HFILL }},

		{ &hf_gpef_efskey_certificate,
		  { "Certificate", "gpef.efskey.certificate", FT_NONE, BASE_NONE, NULL,
		    0x0, NULL, HFILL }},

	};

	static gint *ett[] = {
		&ett_gpef,
		&ett_gpef_efskey,
	};

	proto_gpef = proto_register_protocol("GPEF", "GPEF", "gpef");
	proto_register_field_array(proto_gpef, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));

	register_dissector("efsblob", dissect_gpef_efsblob, proto_gpef);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 *
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
 * :indentSize=8:tabSize=8:noTabs=false:
 */