2 * Routines for portmap dissection
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-smb.c
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include "packet-rpc.h"
34 #include "packet-portmap.h"
35 #include <epan/ipproto.h>
36 #include <epan/conversation.h>
37 #include <epan/packet_info.h>
42 * RFC 1833, "Binding Protocols for ONC RPC Version 2".
45 static int proto_portmap = -1;
46 static int hf_portmap_procedure_v1 = -1;
47 static int hf_portmap_procedure_v2 = -1;
48 static int hf_portmap_procedure_v3 = -1;
49 static int hf_portmap_procedure_v4 = -1;
50 static int hf_portmap_proto = -1;
51 static int hf_portmap_prog = -1;
52 static int hf_portmap_proc = -1;
53 static int hf_portmap_version = -1;
54 static int hf_portmap_port = -1;
55 static int hf_portmap_answer = -1;
56 static int hf_portmap_args = -1;
57 static int hf_portmap_result = -1;
58 static int hf_portmap_rpcb = -1;
59 static int hf_portmap_rpcb_prog = -1;
60 static int hf_portmap_rpcb_version = -1;
61 static int hf_portmap_rpcb_netid = -1;
62 static int hf_portmap_rpcb_addr = -1;
63 static int hf_portmap_rpcb_owner = -1;
64 static int hf_portmap_uaddr = -1;
67 static gint ett_portmap = -1;
68 static gint ett_portmap_rpcb = -1;
69 static gint ett_portmap_entry = -1;
71 static dissector_handle_t rpc_handle;
73 /* Dissect a getport call */
75 dissect_getport_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
78 guint32 proto, version;
80 const char *prog_name;
81 const char *proto_name;
83 /* make sure we remember protocol type until the reply packet */
84 if(!pinfo->fd->flags.visited){
85 rpc_call_info_value *rpc_call=pinfo->private_data;
87 proto = tvb_get_ntohl(tvb, offset+8);
88 if(proto==IP_PROTO_UDP){ /* only do this for UDP */
89 rpc_call->private_data=(void *)PT_UDP;
95 prog = tvb_get_ntohl(tvb, offset+0);
96 prog_name = rpc_prog_name(prog);
97 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
98 offset, 4, prog, "Program: %s (%u)",
100 if (check_col(pinfo->cinfo, COL_INFO)) {
101 col_append_fstr(pinfo->cinfo, COL_INFO, " %s(%u)", prog_name, prog);
104 proto_item_append_text(tree, " GETPORT Call %s(%u)", prog_name, prog);
107 version = tvb_get_ntohl(tvb, offset+4);
108 proto_tree_add_item(tree, hf_portmap_version, tvb,
110 if (check_col(pinfo->cinfo, COL_INFO)) {
111 col_append_fstr(pinfo->cinfo, COL_INFO, " V:%d", version);
114 proto_item_append_text(tree, " Version:%d", version);
118 proto = tvb_get_ntohl(tvb, offset+8);
119 proto_name = ipprotostr(proto);
120 proto_tree_add_uint_format(tree, hf_portmap_proto, tvb,
121 offset+8, 4, proto, "Proto: %s (%u)", proto_name, proto);
122 if (check_col(pinfo->cinfo, COL_INFO)) {
123 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", proto_name);
126 proto_item_append_text(tree, " %s", proto_name);
129 proto_tree_add_item(tree, hf_portmap_port, tvb,
130 offset+12, 4, FALSE);
136 dissect_getport_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
141 /* we might have learnt a <ipaddr><protocol><port> mapping for ONC-RPC*/
142 if(!pinfo->fd->flags.visited){
143 rpc_call_info_value *rpc_call=pinfo->private_data;
144 /* only do this for UDP, TCP does not need anything like this */
145 if(rpc_call && (GPOINTER_TO_UINT(rpc_call->private_data)==PT_UDP) ){
147 port=tvb_get_ntohl(tvb, offset);
149 conversation_t *conv;
150 conv=find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, (port_type)rpc_call->private_data, port, 0, NO_ADDR_B|NO_PORT_B);
152 conv=conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, (port_type)rpc_call->private_data, port, 0, NO_ADDR2|NO_PORT2);
154 conversation_set_dissector(conv, rpc_handle);
159 portx = tvb_get_ntohl(tvb, offset);
160 offset = dissect_rpc_uint32(tvb, tree, hf_portmap_port,
162 proto_item_append_text(tree, " GETPORT Reply Port:%d", portx);
164 if (check_col(pinfo->cinfo, COL_INFO)) {
165 col_append_fstr(pinfo->cinfo, COL_INFO, " Port:%d", portx);
167 proto_item_append_text(tree, " Port:%d", portx);
169 col_append_str(pinfo->cinfo, COL_INFO, " PROGRAM_NOT_AVAILABLE");
170 proto_item_append_text(tree, " PROGRAM_NOT_AVAILABLE");
176 /* Dissect a 'set' call */
178 dissect_set_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
186 prog = tvb_get_ntohl(tvb, offset+0);
187 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
188 offset, 4, prog, "Program: %s (%d)",
189 rpc_prog_name(prog), prog);
190 proto_tree_add_item(tree, hf_portmap_version, tvb,
193 proto = tvb_get_ntohl(tvb, offset+8);
194 proto_tree_add_uint_format(tree, hf_portmap_proto,tvb,
195 offset+8, 4, proto, "Proto: %s (%d)", ipprotostr(proto), proto);
197 proto_tree_add_item(tree, hf_portmap_port, tvb,
198 offset+12, 4, FALSE);
204 /* Dissect a 'unset' call */
206 dissect_unset_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
214 prog = tvb_get_ntohl(tvb, offset+0);
215 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
216 offset, 4, prog, "Program: %s (%d)",
217 rpc_prog_name(prog), prog);
218 proto_tree_add_item(tree, hf_portmap_version, tvb,
221 proto = tvb_get_ntohl(tvb, offset+8);
222 proto_tree_add_uint(tree, hf_portmap_proto, tvb,
225 proto_tree_add_item(tree, hf_portmap_port, tvb,
226 offset+12, 4, FALSE);
233 dissect_set_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
236 offset = dissect_rpc_bool(tvb, tree, hf_portmap_answer,
242 dissect_dump_entry(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
245 int prog, version, proto, port;
246 proto_item *ti, *subtree;
248 prog = tvb_get_ntohl(tvb, offset+0);
249 version = tvb_get_ntohl(tvb, offset+4);
250 proto = tvb_get_ntohl(tvb, offset+8);
251 port = tvb_get_ntohl(tvb, offset+12);
254 ti = proto_tree_add_text(tree, tvb, offset, 16,
255 "Map Entry: %s (%u) V%d",
256 rpc_prog_name(prog), prog, version);
257 subtree = proto_item_add_subtree(ti, ett_portmap_entry);
259 proto_tree_add_uint_format(subtree, hf_portmap_prog, tvb,
261 "Program: %s (%u)", rpc_prog_name(prog), prog);
262 proto_tree_add_uint(subtree, hf_portmap_version, tvb,
263 offset+4, 4, version);
264 proto_tree_add_uint_format(subtree, hf_portmap_proto, tvb,
266 "Protocol: %s (0x%02x)", ipprotostr(proto), proto);
267 proto_tree_add_uint(subtree, hf_portmap_port, tvb,
275 dissect_dump_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
278 offset = dissect_rpc_list(tvb, pinfo, tree, offset,
283 /* Dissect a callit call */
285 dissect_callit_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
288 guint32 prog, vers, proc;
290 prog = tvb_get_ntohl(tvb, offset+0);
293 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
294 offset, 4, prog, "Program: %s (%u)",
295 rpc_prog_name(prog), prog);
298 vers = tvb_get_ntohl(tvb, offset+4);
301 proto_tree_add_uint(tree, hf_portmap_version, tvb,
305 proc = tvb_get_ntohl(tvb, offset+8);
308 proto_tree_add_uint_format(tree, hf_portmap_proc, tvb,
309 offset+8, 4, proc, "Procedure: %s (%u)",
310 rpc_proc_name(prog, vers, proc), proc);
315 /* Dissect the arguments for this procedure.
316 Make the columns non-writable, so the dissector won't change
317 them out from under us. */
318 col_set_writable(pinfo->cinfo, FALSE);
319 offset = dissect_rpc_indir_call(tvb, pinfo, tree, offset,
320 hf_portmap_args, prog, vers, proc);
325 /* Dissect a callit reply */
327 dissect_callit_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
332 proto_tree_add_item(tree, hf_portmap_port, tvb,
337 /* Dissect the result of this procedure.
338 Make the columns non-writable, so the dissector won't change
339 them out from under us. */
340 col_set_writable(pinfo->cinfo, FALSE);
341 offset = dissect_rpc_indir_reply(tvb, pinfo, tree, offset,
342 hf_portmap_result, hf_portmap_prog, hf_portmap_version,
348 /* proc number, "proc name", dissect_request, dissect_reply */
349 /* NULL as function pointer means: type of arguments is "void". */
350 static const vsff portmap1_proc[] = {
351 { PORTMAPPROC_NULL, "NULL", NULL, NULL },
352 { PORTMAPPROC_SET, "SET", NULL, NULL },
353 { PORTMAPPROC_UNSET, "UNSET", NULL, NULL },
354 { PORTMAPPROC_GETPORT, "GETPORT", NULL, NULL },
355 { PORTMAPPROC_DUMP, "DUMP", NULL, NULL },
356 { PORTMAPPROC_CALLIT, "CALLIT", NULL, NULL },
357 { 0, NULL, NULL, NULL }
359 static const value_string portmap1_proc_vals[] = {
360 { PORTMAPPROC_NULL, "NULL" },
361 { PORTMAPPROC_SET, "SET" },
362 { PORTMAPPROC_UNSET, "UNSET" },
363 { PORTMAPPROC_GETPORT, "GETPORT" },
364 { PORTMAPPROC_DUMP, "DUMP" },
365 { PORTMAPPROC_CALLIT, "CALLIT" },
368 /* end of Portmap version 1 */
370 static const vsff portmap2_proc[] = {
371 { PORTMAPPROC_NULL, "NULL",
373 { PORTMAPPROC_SET, "SET",
374 dissect_set_call, dissect_set_reply },
375 { PORTMAPPROC_UNSET, "UNSET",
376 dissect_unset_call, dissect_set_reply },
377 { PORTMAPPROC_GETPORT, "GETPORT",
378 dissect_getport_call, dissect_getport_reply },
379 { PORTMAPPROC_DUMP, "DUMP",
380 NULL, dissect_dump_reply },
381 { PORTMAPPROC_CALLIT, "CALLIT",
382 dissect_callit_call, dissect_callit_reply },
383 { 0, NULL, NULL, NULL }
385 static const value_string portmap2_proc_vals[] = {
386 { PORTMAPPROC_NULL, "NULL" },
387 { PORTMAPPROC_SET, "SET" },
388 { PORTMAPPROC_UNSET, "UNSET" },
389 { PORTMAPPROC_GETPORT, "GETPORT" },
390 { PORTMAPPROC_DUMP, "DUMP" },
391 { PORTMAPPROC_CALLIT, "CALLIT" },
394 /* end of Portmap version 2 */
397 /* RFC 1833, Page 3 */
399 dissect_rpcb(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
401 proto_item* rpcb_item = NULL;
402 proto_tree* rpcb_tree = NULL;
403 int old_offset = offset;
407 rpcb_item = proto_tree_add_item(tree, hf_portmap_rpcb, tvb,
410 rpcb_tree = proto_item_add_subtree(rpcb_item, ett_portmap_rpcb);
413 prog = tvb_get_ntohl(tvb, offset);
415 proto_tree_add_uint_format(rpcb_tree, hf_portmap_rpcb_prog, tvb,
417 "Program: %s (%u)", rpc_prog_name(prog), prog);
420 offset = dissect_rpc_uint32(tvb, rpcb_tree,
421 hf_portmap_rpcb_version, offset);
422 offset = dissect_rpc_string(tvb, rpcb_tree,
423 hf_portmap_rpcb_netid, offset, NULL);
424 offset = dissect_rpc_string(tvb, rpcb_tree,
425 hf_portmap_rpcb_addr, offset, NULL);
426 offset = dissect_rpc_string(tvb, rpcb_tree,
427 hf_portmap_rpcb_owner, offset, NULL);
429 /* now we know, that rpcb is shorter */
431 proto_item_set_len(rpcb_item, offset - old_offset);
439 /* RFC 1833, Page 7 */
441 dissect_rpcb3_getaddr_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
444 offset = dissect_rpcb(tvb, offset, pinfo, tree);
450 /* RFC 1833, Page 7 */
452 dissect_rpcb3_getaddr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
455 offset = dissect_rpc_string(tvb, tree,
456 hf_portmap_uaddr, offset, NULL);
462 /* RFC 1833, Page 7 */
464 dissect_rpcb3_dump_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
467 offset = dissect_rpc_list(tvb, pinfo, tree, offset, dissect_rpcb);
471 /* RFC 1833, page 4 */
473 dissect_rpcb_rmtcallres(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
476 /* Dissect the remote universal address. */
477 offset = dissect_rpc_string(tvb, tree,
478 hf_portmap_rpcb_addr, offset, NULL);
480 /* Dissect the result of this procedure.
481 Make the columns non-writable, so the dissector won't change
482 them out from under us. */
483 col_set_writable(pinfo->cinfo, FALSE);
484 offset = dissect_rpc_indir_reply(tvb, pinfo, tree, offset,
485 hf_portmap_result, hf_portmap_prog, hf_portmap_version,
492 /* Portmapper version 3, RFC 1833, Page 7 */
493 static const vsff portmap3_proc[] = {
494 { RPCBPROC_NULL, "NULL",
496 { RPCBPROC_SET, "SET",
498 { RPCBPROC_UNSET, "UNSET",
500 { RPCBPROC_GETADDR, "GETADDR",
501 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
502 { RPCBPROC_DUMP, "DUMP",
503 NULL, dissect_rpcb3_dump_reply },
504 { RPCBPROC_CALLIT, "CALLIT",
505 dissect_callit_call, dissect_rpcb_rmtcallres },
506 { RPCBPROC_GETTIME, "GETTIME",
508 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
510 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
512 { 0, NULL, NULL, NULL }
514 static const value_string portmap3_proc_vals[] = {
515 { RPCBPROC_NULL, "NULL" },
516 { RPCBPROC_SET, "SET" },
517 { RPCBPROC_UNSET, "UNSET" },
518 { RPCBPROC_GETADDR, "GETADDR" },
519 { RPCBPROC_DUMP, "DUMP" },
520 { RPCBPROC_CALLIT, "CALLIT" },
521 { RPCBPROC_GETTIME, "GETTIME" },
522 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR" },
523 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR" },
526 /* end of Portmap version 3 */
529 /* Portmapper version 4, RFC 1833, Page 8 */
530 static const vsff portmap4_proc[] = {
531 { RPCBPROC_NULL, "NULL",
533 { RPCBPROC_SET, "SET",
535 { RPCBPROC_UNSET, "UNSET",
537 { RPCBPROC_GETADDR, "GETADDR",
538 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
539 { RPCBPROC_DUMP, "DUMP",
540 NULL, dissect_rpcb3_dump_reply },
541 { RPCBPROC_BCAST, "BCAST",
542 dissect_callit_call, dissect_rpcb_rmtcallres },
543 { RPCBPROC_GETTIME, "GETTIME",
545 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
547 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
549 { RPCBPROC_GETVERSADDR, "GETVERSADDR",
551 { RPCBPROC_INDIRECT, "INDIRECT",
552 dissect_callit_call, dissect_rpcb_rmtcallres },
553 { RPCBPROC_GETADDRLIST, "GETADDRLIST",
555 { RPCBPROC_GETSTAT, "GETSTAT",
557 { 0, NULL, NULL, NULL }
559 static const value_string portmap4_proc_vals[] = {
560 { RPCBPROC_NULL, "NULL" },
561 { RPCBPROC_SET, "SET" },
562 { RPCBPROC_UNSET, "UNSET" },
563 { RPCBPROC_GETADDR, "GETADDR" },
564 { RPCBPROC_DUMP, "DUMP" },
565 { RPCBPROC_BCAST, "BCAST" },
566 { RPCBPROC_GETTIME, "GETTIME" },
567 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR" },
568 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR" },
569 { RPCBPROC_GETVERSADDR, "GETVERSADDR" },
570 { RPCBPROC_INDIRECT, "INDIRECT" },
571 { RPCBPROC_GETADDRLIST, "GETADDRLIST" },
572 { RPCBPROC_GETSTAT, "GETSTAT" },
575 /* end of Portmap version 4 */
578 proto_register_portmap(void)
580 static hf_register_info hf[] = {
581 { &hf_portmap_procedure_v1, {
582 "V1 Procedure", "portmap.procedure_v1", FT_UINT32, BASE_DEC,
583 VALS(portmap1_proc_vals), 0, NULL, HFILL }},
584 { &hf_portmap_procedure_v2, {
585 "V2 Procedure", "portmap.procedure_v2", FT_UINT32, BASE_DEC,
586 VALS(portmap2_proc_vals), 0, NULL, HFILL }},
587 { &hf_portmap_procedure_v3, {
588 "V3 Procedure", "portmap.procedure_v3", FT_UINT32, BASE_DEC,
589 VALS(portmap3_proc_vals), 0, NULL, HFILL }},
590 { &hf_portmap_procedure_v4, {
591 "V4 Procedure", "portmap.procedure_v4", FT_UINT32, BASE_DEC,
592 VALS(portmap4_proc_vals), 0, NULL, HFILL }},
593 { &hf_portmap_prog, {
594 "Program", "portmap.prog", FT_UINT32, BASE_DEC,
595 NULL, 0, NULL, HFILL }},
596 { &hf_portmap_port, {
597 "Port", "portmap.port", FT_UINT32, BASE_DEC,
598 NULL, 0, NULL, HFILL }},
599 { &hf_portmap_proc, {
600 "Procedure", "portmap.proc", FT_UINT32, BASE_DEC,
601 NULL, 0, NULL, HFILL }},
602 { &hf_portmap_proto, {
603 "Protocol", "portmap.proto", FT_UINT32, BASE_DEC,
604 NULL, 0, NULL, HFILL }},
605 { &hf_portmap_version, {
606 "Version", "portmap.version", FT_UINT32, BASE_DEC,
607 NULL, 0, NULL, HFILL }},
608 { &hf_portmap_answer, {
609 "Answer", "portmap.answer", FT_BOOLEAN, BASE_NONE,
610 NULL, 0x0, NULL, HFILL }},
611 { &hf_portmap_args, {
612 "Arguments", "portmap.args", FT_BYTES, BASE_NONE,
613 NULL, 0, NULL, HFILL }},
614 { &hf_portmap_result, {
615 "Result", "portmap.result", FT_BYTES, BASE_NONE,
616 NULL, 0, NULL, HFILL }},
617 { &hf_portmap_rpcb, {
618 "RPCB", "portmap.rpcb", FT_NONE, BASE_NONE,
619 NULL, 0, NULL, HFILL }},
620 { &hf_portmap_rpcb_prog, {
621 "Program", "portmap.rpcb.prog", FT_UINT32, BASE_DEC,
622 NULL, 0, NULL, HFILL }},
623 { &hf_portmap_rpcb_version, {
624 "Version", "portmap.rpcb.version", FT_UINT32, BASE_DEC,
625 NULL, 0, NULL, HFILL }},
626 { &hf_portmap_rpcb_netid, {
627 "Network Id", "portmap.rpcb.netid", FT_STRING, BASE_NONE,
628 NULL, 0, NULL, HFILL }},
629 { &hf_portmap_rpcb_addr, { /* address in rpcb structure in request */
630 "Universal Address", "portmap.rpcb.addr", FT_STRING, BASE_NONE,
631 NULL, 0, NULL, HFILL }},
632 { &hf_portmap_rpcb_owner, {
633 "Owner of this Service", "portmap.rpcb.owner", FT_STRING, BASE_NONE,
634 NULL, 0, NULL, HFILL }},
635 { &hf_portmap_uaddr, { /* address in RPCBPROC_GETADDR reply */
636 "Universal Address", "portmap.uaddr", FT_STRING, BASE_NONE,
637 NULL, 0, NULL, HFILL }},
639 static gint *ett[] = {
645 proto_portmap = proto_register_protocol("Portmap", "Portmap", "portmap");
646 proto_register_field_array(proto_portmap, hf, array_length(hf));
647 proto_register_subtree_array(ett, array_length(ett));
651 proto_reg_handoff_portmap(void)
653 /* Register the protocol as RPC */
654 rpc_init_prog(proto_portmap, PORTMAP_PROGRAM, ett_portmap);
655 /* Register the procedure tables */
656 rpc_init_proc_table(PORTMAP_PROGRAM, 1, portmap1_proc, hf_portmap_procedure_v1);
657 rpc_init_proc_table(PORTMAP_PROGRAM, 2, portmap2_proc, hf_portmap_procedure_v2);
658 rpc_init_proc_table(PORTMAP_PROGRAM, 3, portmap3_proc, hf_portmap_procedure_v3);
659 rpc_init_proc_table(PORTMAP_PROGRAM, 4, portmap4_proc, hf_portmap_procedure_v4);
660 rpc_handle = find_dissector("rpc");