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
|
/*
Unix SMB/CIFS implementation.
SMB2 client getinfo calls
Copyright (C) Andrew Tridgell 2005
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
/*
send a getinfo request
*/
struct smb2_request *smb2_getinfo_send(struct smb2_tree *tree, struct smb2_getinfo *io)
{
struct smb2_request *req;
req = smb2_request_init_tree(tree, SMB2_OP_GETINFO, 0x28, 0);
if (req == NULL) return NULL;
/* this seems to be a bug, they use 0x29 but only send 0x28 bytes */
SSVAL(req->out.body, 0x00, 0x29);
SSVAL(req->out.body, 0x02, io->in.level);
SIVAL(req->out.body, 0x04, io->in.max_response_size);
SIVAL(req->out.body, 0x08, io->in.unknown1);
SIVAL(req->out.body, 0x0C, io->in.flags);
SIVAL(req->out.body, 0x10, io->in.unknown3);
SIVAL(req->out.body, 0x14, io->in.unknown4);
smb2_push_handle(req->out.body+0x18, &io->in.handle);
smb2_transport_send(req);
return req;
}
/*
recv a getinfo reply
*/
NTSTATUS smb2_getinfo_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
struct smb2_getinfo *io)
{
NTSTATUS status;
if (!smb2_request_receive(req) ||
smb2_request_is_error(req)) {
return smb2_request_destroy(req);
}
SMB2_CHECK_PACKET_RECV(req, 0x08, True);
status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x02, &io->out.blob);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
return smb2_request_destroy(req);
}
/*
sync getinfo request
*/
NTSTATUS smb2_getinfo(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
struct smb2_getinfo *io)
{
struct smb2_request *req = smb2_getinfo_send(tree, io);
return smb2_getinfo_recv(req, mem_ctx, io);
}
/*
parse a returned getinfo data blob
*/
NTSTATUS smb2_getinfo_parse(TALLOC_CTX *mem_ctx,
uint16_t level,
DATA_BLOB blob,
union smb2_fileinfo *io)
{
switch (level) {
case SMB2_GETINFO_FILE_BASIC_INFO:
if (blob.length != 0x28) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->basic_info.create_time = smbcli_pull_nttime(blob.data, 0x00);
io->basic_info.access_time = smbcli_pull_nttime(blob.data, 0x08);
io->basic_info.write_time = smbcli_pull_nttime(blob.data, 0x10);
io->basic_info.change_time = smbcli_pull_nttime(blob.data, 0x18);
io->basic_info.file_attr = IVAL(blob.data, 0x20);
io->basic_info.unknown = IVAL(blob.data, 0x24);
break;
case SMB2_GETINFO_FILE_SIZE_INFO:
if (blob.length != 0x18) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->size_info.alloc_size = BVAL(blob.data, 0x00);
io->size_info.size = BVAL(blob.data, 0x08);
io->size_info.nlink = IVAL(blob.data, 0x10);
io->size_info.delete_pending = CVAL(blob.data, 0x14);
io->size_info.directory = CVAL(blob.data, 0x15);
break;
case SMB2_GETINFO_FILE_ID:
if (blob.length != 0x8) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->file_id.file_id = BVAL(blob.data, 0x00);
break;
case SMB2_GETINFO_FILE_EA_SIZE:
if (blob.length != 0x4) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->ea_size.ea_size = IVAL(blob.data, 0x00);
break;
case SMB2_GETINFO_FILE_ACCESS_INFO:
if (blob.length != 0x4) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->access_info.access_mask = IVAL(blob.data, 0x00);
break;
case SMB2_GETINFO_FILE_0E:
if (blob.length != 0x8) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->unknown0e.unknown1 = IVAL(blob.data, 0x00);
io->unknown0e.unknown2 = IVAL(blob.data, 0x04);
break;
case SMB2_GETINFO_FILE_ALL_EAS:
return ea_pull_list_chained(&blob, mem_ctx,
&io->all_eas.num_eas,
&io->all_eas.eas);
case SMB2_GETINFO_FILE_10:
if (blob.length != 0x4) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->unknown10.unknown = IVAL(blob.data, 0x00);
break;
case SMB2_GETINFO_FILE_11:
if (blob.length != 0x4) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->unknown11.unknown = IVAL(blob.data, 0x00);
break;
case SMB2_GETINFO_FILE_ALL_INFO: {
uint32_t nlen;
ssize_t size;
void *vstr;
if (blob.length < 0x64) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->all_info.create_time = smbcli_pull_nttime(blob.data, 0x00);
io->all_info.access_time = smbcli_pull_nttime(blob.data, 0x08);
io->all_info.write_time = smbcli_pull_nttime(blob.data, 0x10);
io->all_info.change_time = smbcli_pull_nttime(blob.data, 0x18);
io->all_info.file_attr = IVAL(blob.data, 0x20);
io->all_info.alloc_size = BVAL(blob.data, 0x28);
io->all_info.size = BVAL(blob.data, 0x30);
io->all_info.nlink = IVAL(blob.data, 0x38);
io->all_info.delete_pending = CVAL(blob.data, 0x3C);
io->all_info.directory = CVAL(blob.data, 0x3D);
io->all_info.file_id = BVAL(blob.data, 0x40);
io->all_info.ea_size = IVAL(blob.data, 0x48);
io->all_info.access_mask = IVAL(blob.data, 0x4C);
io->all_info.unknown5 = BVAL(blob.data, 0x50);
io->all_info.unknown6 = BVAL(blob.data, 0x58);
nlen = IVAL(blob.data, 0x60);
if (nlen > blob.length - 0x64) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
size = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX,
blob.data+0x64, nlen, &vstr);
if (size == -1) {
return NT_STATUS_ILLEGAL_CHARACTER;
}
io->all_info.fname = vstr;
break;
}
case SMB2_GETINFO_FILE_SHORT_INFO: {
uint32_t nlen;
ssize_t size;
void *vstr;
if (blob.length < 0x04) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
nlen = IVAL(blob.data, 0x00);
if (nlen > blob.length - 0x04) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
size = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX,
blob.data+0x04, nlen, &vstr);
if (size == -1) {
return NT_STATUS_ILLEGAL_CHARACTER;
}
io->short_info.short_name = vstr;
break;
}
case SMB2_GETINFO_FILE_STREAM_INFO:
return smbcli_parse_stream_info(blob, mem_ctx, &io->stream_info);
case SMB2_GETINFO_FILE_EOF_INFO:
if (blob.length != 0x10) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->eof_info.size = BVAL(blob.data, 0x00);
io->eof_info.unknown = BVAL(blob.data, 0x08);
break;
case SMB2_GETINFO_FILE_STANDARD_INFO:
if (blob.length != 0x38) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->standard_info.create_time = smbcli_pull_nttime(blob.data, 0x00);
io->standard_info.access_time = smbcli_pull_nttime(blob.data, 0x08);
io->standard_info.write_time = smbcli_pull_nttime(blob.data, 0x10);
io->standard_info.change_time = smbcli_pull_nttime(blob.data, 0x18);
io->standard_info.alloc_size = BVAL(blob.data, 0x20);
io->standard_info.size = BVAL(blob.data, 0x28);
io->standard_info.file_attr = IVAL(blob.data, 0x30);
io->standard_info.unknown = IVAL(blob.data, 0x34);
break;
case SMB2_GETINFO_FILE_ATTRIB_INFO:
if (blob.length != 0x08) {
return NT_STATUS_INFO_LENGTH_MISMATCH;
}
io->attrib_info.file_attr = IVAL(blob.data, 0x00);
io->attrib_info.unknown = IVAL(blob.data, 0x04);
break;
case SMB2_GETINFO_SECURITY: {
struct ndr_pull *ndr;
NTSTATUS status;
ndr = ndr_pull_init_blob(&blob, mem_ctx);
if (!ndr) {
return NT_STATUS_NO_MEMORY;
}
io->security.sd = talloc(mem_ctx, struct security_descriptor);
if (io->security.sd == NULL) {
return NT_STATUS_NO_MEMORY;
}
status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->security.sd);
talloc_free(ndr);
return status;
}
default:
return NT_STATUS_INVALID_INFO_CLASS;
}
return NT_STATUS_OK;
}
/*
recv a getinfo reply and parse the level info
*/
NTSTATUS smb2_getinfo_level_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
uint16_t level, union smb2_fileinfo *io)
{
struct smb2_getinfo b;
NTSTATUS status;
status = smb2_getinfo_recv(req, mem_ctx, &b);
NT_STATUS_NOT_OK_RETURN(status);
status = smb2_getinfo_parse(mem_ctx, level, b.out.blob, io);
data_blob_free(&b.out.blob);
return status;
}
/*
level specific getinfo call
*/
NTSTATUS smb2_getinfo_level(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
struct smb2_handle handle,
uint16_t level, union smb2_fileinfo *io)
{
struct smb2_getinfo b;
struct smb2_request *req;
ZERO_STRUCT(b);
b.in.max_response_size = 0x10000;
b.in.handle = handle;
b.in.level = level;
req = smb2_getinfo_send(tree, &b);
return smb2_getinfo_level_recv(req, mem_ctx, level, io);
}
|