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
|
/*
Unix SMB/CIFS implementation.
SMB torture tester
Copyright (C) Andrew Tridgell 2003
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"
static const struct dcerpc_interface_table *find_pipe(const char *pipe_name)
{
int i;
for (i=0;dcerpc_pipes[i];i++) {
if (strcmp(dcerpc_pipes[i]->name, pipe_name) == 0) {
break;
}
}
if (!dcerpc_pipes[i]) {
printf("pipe '%s' not in table\n", pipe_name);
exit(1);
}
return dcerpc_pipes[i];
}
static const struct dcerpc_interface_call *find_function(
const struct dcerpc_interface_table *p,
const char *function)
{
int i;
if (isdigit(function[0])) {
i = strtol(function, NULL, 0);
return &p->calls[i];
}
for (i=0;i<p->num_calls;i++) {
if (strcmp(p->calls[i].name, function) == 0) {
break;
}
}
if (i == p->num_calls) {
printf("Function '%s' not found\n", function);
exit(1);
}
return &p->calls[i];
}
static void usage(void)
{
printf("Usage: ndrdump <pipe> <function> <inout> <filename>\n");
}
static void show_pipes(void)
{
int i;
usage();
printf("\nYou must specify a pipe\n");
printf("known pipes are:\n");
for (i=0;dcerpc_pipes[i];i++) {
if(dcerpc_pipes[i]->helpstring) {
printf("\t%s - %s\n", dcerpc_pipes[i]->name, dcerpc_pipes[i]->helpstring);
} else {
printf("\t%s\n", dcerpc_pipes[i]->name);
}
}
exit(1);
}
static void show_functions(const struct dcerpc_interface_table *p)
{
int i;
usage();
printf("\nYou must specify a function\n");
printf("known functions on '%s' are:\n", p->name);
for (i=0;i<p->num_calls;i++) {
printf("\t0x%02x (%2d) %s\n", i, i, p->calls[i].name);
}
exit(1);
}
int main(int argc, char *argv[])
{
const struct dcerpc_interface_table *p;
const struct dcerpc_interface_call *f;
const char *pipe_name, *function, *inout, *filename;
char *data;
size_t size;
DATA_BLOB blob;
struct ndr_pull *ndr;
TALLOC_CTX *mem_ctx;
int flags;
NTSTATUS status;
void *st;
struct ndr_print pr;
DEBUGLEVEL = 10;
setup_logging("smbtorture", DEBUG_STDOUT);
if (argc < 2) {
show_pipes();
exit(1);
}
pipe_name = argv[1];
p = find_pipe(pipe_name);
if (argc < 5) {
show_functions(p);
exit(1);
}
function = argv[2];
inout = argv[3];
filename = argv[4];
if (strcmp(inout, "in") == 0 ||
strcmp(inout, "request") == 0) {
flags = NDR_IN;
} else if (strcmp(inout, "out") == 0 ||
strcmp(inout, "response") == 0) {
flags = NDR_OUT;
} else {
printf("Bad inout value '%s'\n", inout);
exit(1);
}
f = find_function(p, function);
data = file_load(filename, &size);
if (!data) {
perror(filename);
exit(1);
}
blob.data = data;
blob.length = size;
mem_ctx = talloc_init("ndrdump");
ndr = ndr_pull_init_blob(&blob, mem_ctx);
st = talloc_zero(mem_ctx, f->struct_size);
if (!st) {
printf("Unable to allocate %d bytes\n", f->struct_size);
exit(1);
}
if (flags == NDR_OUT) {
ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
}
status = f->ndr_pull(ndr, flags, st);
printf("pull returned %s\n", nt_errstr(status));
if (ndr->offset != ndr->data_size) {
printf("WARNING! %d unread bytes\n", ndr->data_size - ndr->offset);
dump_data(0, ndr->data+ndr->offset, ndr->data_size - ndr->offset);
}
pr.mem_ctx = mem_ctx;
pr.print = ndr_print_debug_helper;
pr.depth = 1;
f->ndr_print(&pr, function, flags, st);
if (!NT_STATUS_IS_OK(status) ||
ndr->offset != ndr->data_size) {
printf("dump FAILED\n");
exit(1);
}
printf("dump OK\n");
return 0;
}
|