2 * Routines for Microsoft Proxy packet dissection
3 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
5 * $Id: packet-msproxy.c,v 1.32 2002/08/28 21:00:22 jmayer Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * This was derived from the dante socks implementation source code.
26 * Most of the information came from common.h and msproxy_clientprotocol.c
28 * See http://www.inet.no/dante for more information
31 /************************************************************************
33 * Notes: These are possible command values. User input is welcome *
35 * Command = 0x040a - Remote host closed connection (maybe ?? ) *
36 * Command = 0x0411 - Remote host closed connection *
37 * Command = 0x0413 - Local host closed connection or SYN worked *
39 ************************************************************************/
52 #include <epan/packet.h>
53 #include <epan/resolv.h>
54 #include "alignment.h"
55 #include <epan/conversation.h>
57 #include "packet-tcp.h"
58 #include "packet-udp.h"
60 extern void udp_hash_add(guint16 proto,
61 void (*dissect)(const guchar *, int, frame_data *, proto_tree *));
64 static int proto_msproxy = -1;
66 static int ett_msproxy = -1;
67 static int ett_msproxy_name = -1;
69 static int hf_msproxy_cmd = -1;
70 static int hf_msproxy_clntport = -1;
72 static int hf_msproxy_dstaddr = -1;
74 static int hf_msproxy_srcport = -1;
75 static int hf_msproxy_dstport = -1;
76 static int hf_msproxy_serverport = -1;
77 static int hf_msproxy_serveraddr = -1;
78 static int hf_msproxy_bindport = -1;
79 static int hf_msproxy_bindaddr = -1;
80 static int hf_msproxy_boundport = -1;
81 static int hf_msproxy_bind_id = -1;
82 static int hf_msproxy_resolvaddr = -1;
84 static int hf_msproxy_server_int_addr = -1;
85 static int hf_msproxy_server_int_port = -1;
86 static int hf_msproxy_server_ext_addr = -1;
87 static int hf_msproxy_server_ext_port = -1;
89 static dissector_handle_t msproxy_sub_handle;
92 #define UDP_PORT_MSPROXY 1745
94 #define N_MSPROXY_HELLO 0x05 /* packet 1 from client */
95 #define N_MSPROXY_ACK 0x10 /* packet 1 from server */
96 #define N_MSPROXY_USERINFO_ACK 0x04 /* packet 2 from server */
97 #define N_MSPROXY_AUTH 0x47 /* packet 3 from client */
98 #define N_MSPROXY_RESOLVE 0x07 /* Resolve request */
101 /*$$$ 0x0500 was dante value, I see 0x05ff and 0x0500 */
103 #define MSPROXY_HELLO 0x0500
104 #define MSPROXY_HELLO_2 0x05ff
106 #define MSPROXY_HELLO_ACK 0x1000
108 #define MSPROXY_USERINFO 0x1000
109 #define MSPROXY_USERINFO_ACK 0x0400
111 #define MSPROXY_AUTH 0x4700
112 #define MSPROXY_AUTH_1_ACK 0x4714
113 #define MSPROXY_AUTH_2 0x4701
114 #define MSPROXY_AUTH_2_ACK 0x4715
115 #define MSPROXY_AUTH_2_ACK2 0x4716
117 #define MSPROXY_RESOLVE 0x070d
118 #define MSPROXY_RESOLVE_ACK 0x070f
120 #define MSPROXY_BIND 0x0704
121 #define MSPROXY_BIND_ACK 0x0706
123 #define MSPROXY_TCP_BIND 0x0707
124 #define MSPROXY_TCP_BIND_ACK 0x0708
126 #define MSPROXY_LISTEN 0x0406
128 #define MSPROXY_BINDINFO 0x0709
130 #define MSPROXY_BINDINFO_ACK 0x070a
132 #define MSPROXY_CONNECT 0x071e
133 #define MSPROXY_CONNECT_ACK 0x0703
135 #define MSPROXY_UDPASSOCIATE 0x0705
136 #define MSPROXY_UDPASSOCIATE_ACK 0x0706
138 #define MSPROXY_UDP_BIND_REQ 0x070b
140 #define MSPROXY_CONNECTED 0x042c
141 #define MSPROXY_SESSIONEND 0x251e
143 #define MSPROXY_BIND_AUTHFAILED 0x0804
144 #define MSPROXY_CONNECT_AUTHFAILED 0x081e
145 #define MSPROXY_CONNREFUSED 0x4 /* low 12 bits seem to vary. */
147 #define FROM_SERVER 1 /* direction of packet data for get_msproxy_cmd_name */
148 #define FROM_CLIENT 0
153 /*$$$ should this be the same as redirect_entry_t ?? */
154 /* then the add_conversation could just copy the structure */
155 /* using the same allocation (instance for you object guys) */
156 /* wouldn't work because there may be multiple child conversations */
157 /* from the same MSProxy conversation */
163 guint32 server_int_port;
168 /************** conversation hash stuff ***************/
170 #define hash_init_count 20
171 #define hash_val_length (sizeof(hash_entry_t))
173 static GMemChunk *vals = NULL;
178 guint32 server_int_port;
184 /************** negotiated conversation hash stuff ***************/
186 #define redirect_init_count 20
187 #define redirect_val_length (sizeof(redirect_entry_t))
189 static GMemChunk *redirect_vals = NULL;
192 static guint32 last_row= 0; /* used to see if packet is new */
194 static void msproxy_sub_dissector( tvbuff_t *tvb, packet_info *pinfo,
197 /* Conversation dissector called from TCP or UDP dissector. Decode and */
198 /* display the msproxy header, the pass the rest of the data to the tcp */
199 /* or udp port decode routine to handle the payload. */
202 redirect_entry_t *redirect_info;
203 conversation_t *conversation;
204 proto_tree *msp_tree;
207 conversation = find_conversation( &pinfo->src, &pinfo->dst,
208 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
210 g_assert( conversation); /* should always find a conversation */
212 redirect_info = conversation_get_proto_data(conversation,
215 if (check_col(pinfo->cinfo, COL_PROTOCOL))
216 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MS Proxy");
218 if (check_col(pinfo->cinfo, COL_INFO))
219 col_set_str(pinfo->cinfo, COL_INFO,
220 (( redirect_info->proto == PT_TCP) ? "TCP stream" :
224 ti = proto_tree_add_item( tree, proto_msproxy, tvb, 0, 0,
227 msp_tree = proto_item_add_subtree(ti, ett_msproxy);
229 proto_tree_add_uint( msp_tree, hf_msproxy_dstport, tvb, 0, 0,
230 redirect_info->remote_port);
232 proto_tree_add_ipv4( msp_tree, hf_msproxy_dstaddr, tvb, 0, 0,
233 redirect_info->remote_addr);
237 /* set pinfo->{src/dst port} and call the UDP sub-dissector lookup */
239 if ( pinfo->srcport == redirect_info->clnt_port)
240 ptr = &pinfo->destport;
242 ptr = &pinfo->srcport;
244 *ptr = redirect_info->remote_port;
246 if ( redirect_info->proto == PT_TCP)
247 decode_tcp_ports( tvb, 0, pinfo, tree, pinfo->srcport,
250 decode_udp_ports( tvb, 0, pinfo, tree, pinfo->srcport,
253 *ptr = redirect_info->server_int_port;
258 static void add_msproxy_conversation( packet_info *pinfo,
259 hash_entry_t *hash_info){
261 /* check to see if a conversation already exists, if it does assume */
262 /* it's our conversation and quit. Otherwise create a new conversation. */
263 /* Load the conversation dissector to our dissector and load the */
264 /* conversation data structure with the info needed to call the TCP or */
265 /* UDP port decoder. */
267 /* NOTE: Currently this assume that the conversation will be created */
268 /* during a packet from the server. If that changes, pinfo->src */
269 /* and pinfo->dst will not be correct and this routine will have */
272 conversation_t *conversation;
273 redirect_entry_t *new_conv_info;
275 if (pinfo->fd->flags.visited) {
277 * We've already processed this frame once, so we
278 * should already have done this.
283 conversation = find_conversation( &pinfo->src,
284 &pinfo->dst, hash_info->proto, hash_info->server_int_port,
285 hash_info->clnt_port, 0);
287 if ( !conversation) {
288 conversation = conversation_new( &pinfo->src, &pinfo->dst,
289 hash_info->proto, hash_info->server_int_port,
290 hash_info->clnt_port, 0);
292 conversation_set_dissector(conversation, msproxy_sub_handle);
294 new_conv_info = g_mem_chunk_alloc(redirect_vals);
296 new_conv_info->remote_addr = hash_info->dst_addr;
297 new_conv_info->clnt_port = hash_info->clnt_port;
298 new_conv_info->remote_port = hash_info->dst_port;
299 new_conv_info->server_int_port = hash_info->server_int_port;
300 new_conv_info->proto = hash_info->proto;
302 conversation_add_proto_data(conversation, proto_msproxy,
308 static int display_application_name(tvbuff_t *tvb, int offset,
311 /* display the application name in the proto tree. */
313 /* NOTE: this routine assumes that the tree pointer is valid (not NULL) */
317 length = tvb_strnlen( tvb, offset, 255);
318 proto_tree_add_text( tree, tvb, offset, length, "Application: %.*s",
319 length, tvb_get_ptr( tvb, offset, length));
325 static char *get_msproxy_cmd_name( int cmd, int direction) {
327 /* return the command name string for cmd */
330 case MSPROXY_HELLO_2:
331 case MSPROXY_HELLO: return "Hello";
333 /* MSPROXY_HELLO_ACK & MSPROXY_USERINFO have the same value (0x1000). */
334 /* So use the direction flag to determine which to use. */
336 case MSPROXY_USERINFO:
337 if ( direction == FROM_SERVER)
338 return "Hello Acknowledge";
341 case MSPROXY_USERINFO_ACK: return "User Info Acknowledge";
342 case MSPROXY_AUTH: return "Authentication";
343 case MSPROXY_AUTH_1_ACK: return "Authentication Acknowledge";
344 case MSPROXY_AUTH_2: return "Authentication 2";
345 case MSPROXY_AUTH_2_ACK: return "Authentication 2 Acknowledge";
346 case MSPROXY_RESOLVE: return "Resolve";
347 case MSPROXY_RESOLVE_ACK: return "Resolve Acknowledge";
348 case MSPROXY_BIND: return "Bind";
349 case MSPROXY_TCP_BIND: return "TCP Bind";
350 case MSPROXY_TCP_BIND_ACK: return "TCP Bind Acknowledge";
351 case MSPROXY_LISTEN: return "Listen";
352 case MSPROXY_BINDINFO: return "Bind Info";
353 case MSPROXY_BINDINFO_ACK: return "Bind Info Acknowledge";
354 case MSPROXY_CONNECT: return "Connect";
355 case MSPROXY_CONNECT_ACK: return "Connect Acknowledge";
356 case MSPROXY_UDPASSOCIATE: return "UDP Associate";
357 case MSPROXY_UDP_BIND_REQ: return "UDP Bind";
358 case MSPROXY_UDPASSOCIATE_ACK: return "Bind or Associate Acknowledge";
359 case MSPROXY_CONNECTED: return "Connected";
360 case MSPROXY_SESSIONEND: return "Session End";
362 default: return "Unknown";
368 static void dissect_user_info_2(tvbuff_t *tvb, int offset,
371 /* decode the user, application, computer name */
377 length = tvb_strnlen( tvb, offset, 255);
380 proto_tree_add_text( tree, tvb, offset, length + 1,
381 "User name: %.*s", length,
382 tvb_get_ptr( tvb, offset, length));
383 offset += length + 2;
385 length = tvb_strnlen( tvb, offset, 255);
388 proto_tree_add_text( tree, tvb, offset, length + 1,
389 "Application name: %.*s", length,
390 tvb_get_ptr( tvb, offset, length));
391 offset += length + 1;
393 length = tvb_strnlen( tvb, offset, 255);
396 proto_tree_add_text( tree, tvb, offset, length + 1,
397 "Client computer name: %.*s", length,
398 tvb_get_ptr( tvb, offset, length));
404 static void dissect_msproxy_request_1(tvbuff_t *tvb, int offset,
407 /* decode the request _1 structure */
412 dissect_user_info_2( tvb, offset, tree);
418 static void dissect_bind(tvbuff_t *tvb, int offset,
419 proto_tree *tree, hash_entry_t *conv_info) {
421 /* decode the bind request */
426 proto_tree_add_item( tree, hf_msproxy_bindaddr, tvb, offset, 4,
431 proto_tree_add_item( tree, hf_msproxy_bindport, tvb, offset, 2,
436 proto_tree_add_item( tree, hf_msproxy_clntport, tvb, offset, 2,
440 conv_info->clnt_port = tvb_get_ntohs( tvb, offset);
444 proto_tree_add_item( tree, hf_msproxy_boundport, tvb, offset, 2,
448 display_application_name( tvb, offset, tree);
454 static void dissect_auth(tvbuff_t *tvb, int offset,
457 /* decode the authorization request */
462 proto_tree_add_text( tree, tvb, offset, 7, "NTLMSSP signature: %.7s",
463 tvb_get_ptr( tvb, offset, 7));
470 static void dissect_tcp_bind(tvbuff_t *tvb, int offset,
471 proto_tree *tree, hash_entry_t *conv_info) {
473 /* decode the bind packet. Set the protocol type in the conversation */
474 /* information so the bind_info can use it to create the payload */
478 conv_info->proto = PT_TCP;
483 proto_tree_add_item( tree, hf_msproxy_bind_id, tvb, offset, 4,
487 proto_tree_add_item( tree, hf_msproxy_boundport, tvb, offset, 2,
491 display_application_name( tvb, offset, tree);
496 static void dissect_request_connect(tvbuff_t *tvb, int offset,
497 proto_tree *tree, hash_entry_t *conv_info) {
499 /* decode the connect request, display */
501 conv_info->proto = PT_TCP;
506 proto_tree_add_item( tree, hf_msproxy_dstport, tvb, offset, 2,
509 conv_info->dst_port = tvb_get_ntohs( tvb, offset);
513 proto_tree_add_item( tree, hf_msproxy_dstaddr, tvb, offset, 4,
516 tvb_memcpy( tvb, (guint8 *)&conv_info->dst_addr, offset, sizeof( guint32));
520 conv_info->clnt_port = tvb_get_ntohs( tvb, offset);
523 proto_tree_add_uint( tree, hf_msproxy_clntport, tvb, offset, 2,
524 conv_info->clnt_port);
528 display_application_name( tvb, offset, tree);
533 static void dissect_bind_info_ack(tvbuff_t *tvb, int offset, proto_tree *tree) {
535 /* decode the client bind info ack */
541 proto_tree_add_item( tree, hf_msproxy_bind_id, tvb, offset, 4,
545 proto_tree_add_item( tree, hf_msproxy_dstport, tvb, offset, 2,
549 proto_tree_add_item( tree, hf_msproxy_dstaddr, tvb, offset, 4,
553 proto_tree_add_item( tree, hf_msproxy_server_int_port, tvb,
557 proto_tree_add_item( tree, hf_msproxy_server_ext_port, tvb,
561 proto_tree_add_item( tree, hf_msproxy_server_ext_addr, tvb,
565 display_application_name( tvb, offset, tree);
570 static void dissect_request_resolve(tvbuff_t *tvb, int offset,
573 /* dissect the request resolve structure */
574 /* display a string with a length, characters encoding */
575 /* they are displayed under a tree with the name in Label variable */
576 /* return the length of the string and the length byte */
578 proto_tree *name_tree;
581 int length = tvb_get_guint8( tvb, offset);
584 ti = proto_tree_add_text(tree, tvb, offset, length + 1,
585 "Host Name: %.*s", length,
586 tvb_get_ptr( tvb, offset + 18, length));
588 name_tree = proto_item_add_subtree(ti, ett_msproxy_name);
590 proto_tree_add_text( name_tree, tvb, offset, 1, "Length: %d",
596 proto_tree_add_text( name_tree, tvb, offset, length, "String: %s",
597 tvb_get_ptr( tvb, offset, length));
603 static void dissect_udp_bind(tvbuff_t *tvb, int offset,
604 proto_tree *tree, hash_entry_t *conv_info) {
606 /* Dissect the udp bind request. Load the protocol id (PT_UDP) and the */
607 /* remote address so bind_info can use it to create conversation */
610 conv_info->proto = PT_UDP;
616 proto_tree_add_item( tree, hf_msproxy_bind_id, tvb, offset, 4,
622 proto_tree_add_item( tree, hf_msproxy_dstport, tvb, offset, 2,
627 proto_tree_add_item( tree, hf_msproxy_dstaddr, tvb, offset, 4,
633 display_application_name( tvb, offset, tree);
637 static void dissect_udp_assoc(tvbuff_t *tvb, int offset,
638 proto_tree *tree, hash_entry_t *conv_info) {
640 /* dissect the udp associate request. And load client port into */
641 /* conversation data structure for later. */
647 proto_tree_add_item( tree, hf_msproxy_clntport, tvb, offset, 2,
650 conv_info->clnt_port = tvb_get_ntohs( tvb, offset);
655 display_application_name( tvb, offset, tree);
659 static void dissect_msproxy_request(tvbuff_t *tvb,
660 proto_tree *tree, hash_entry_t *conv_info) {
666 proto_tree_add_text( tree, tvb, offset, 4, "Client id: 0x%0x",
667 tvb_get_letohl( tvb, offset));
670 proto_tree_add_text( tree, tvb, offset, 4, "Version: 0x%04x",
671 tvb_get_letohl( tvb, offset));
674 proto_tree_add_text( tree, tvb, offset, 4, "Server id: 0x%0x",
675 tvb_get_letohl( tvb, offset));
678 proto_tree_add_text( tree, tvb, offset, 1, "Server ack: %u",
679 tvb_get_guint8( tvb, offset));
682 proto_tree_add_text( tree, tvb, offset, 1, "Sequence Number: %u",
683 tvb_get_guint8( tvb, offset));
686 proto_tree_add_text( tree, tvb, offset, 4, "RWSP signature: %.4s",
687 tvb_get_ptr( tvb, offset, 4));
693 cmd = tvb_get_ntohs( tvb, offset);
696 proto_tree_add_uint_format( tree, hf_msproxy_cmd, tvb, offset, 2,
697 cmd, "Command: 0x%02x (%s)", cmd,
698 get_msproxy_cmd_name( cmd, FROM_CLIENT));
704 dissect_auth( tvb, offset, tree);
708 dissect_bind( tvb, offset, tree, conv_info);
711 case MSPROXY_UDP_BIND_REQ:
712 dissect_udp_bind( tvb, offset, tree, conv_info);
715 case MSPROXY_AUTH_2: /*$$ this is probably wrong place for this */
716 case MSPROXY_TCP_BIND:
717 dissect_tcp_bind( tvb, offset, tree, conv_info);
720 case MSPROXY_RESOLVE:
721 dissect_request_resolve( tvb, offset, tree);
724 case MSPROXY_CONNECT:
726 dissect_request_connect( tvb, offset, tree,
730 case MSPROXY_BINDINFO_ACK:
731 dissect_bind_info_ack( tvb, offset, tree);
735 case MSPROXY_HELLO_2:
736 dissect_msproxy_request_1( tvb, offset, tree);
739 case MSPROXY_UDPASSOCIATE:
740 dissect_udp_assoc( tvb, offset, tree, conv_info);
744 proto_tree_add_text( tree, tvb, offset, 0,
745 "Unhandled request command (report this, please)");
751 static void dissect_hello_ack(tvbuff_t *tvb, int offset, proto_tree *tree) {
753 /* decode the hello acknowledge packet */
758 proto_tree_add_item( tree, hf_msproxy_serverport, tvb, offset, 2,
762 proto_tree_add_item( tree, hf_msproxy_serveraddr, tvb, offset, 4,
770 static void dissect_user_info_ack(tvbuff_t *tvb, int offset,
773 /* decode the response _2 structure */
783 static void dissect_udpassociate_ack(tvbuff_t *tvb, int offset,
789 proto_tree_add_item( tree, hf_msproxy_bind_id, tvb, offset, 4,
793 proto_tree_add_item( tree, hf_msproxy_server_ext_port, tvb,
797 proto_tree_add_item( tree, hf_msproxy_server_ext_addr, tvb,
801 display_application_name( tvb, offset, tree);
807 static void dissect_auth_1_ack(tvbuff_t *tvb, int offset,
812 proto_tree_add_text( tree, tvb, offset, 7, "NTLMSSP signature: %.7s",
813 tvb_get_ptr( tvb, offset, 7));
816 /* XXX - always 255? */
817 proto_tree_add_text( tree, tvb, offset, 255, "NT domain: %.255s",
818 tvb_get_ptr( tvb, offset, 255));
824 static void dissect_msproxy_response_4( tvbuff_t *tvb, int offset,
827 /* decode the response _4 structure */
834 static void dissect_connect_ack( tvbuff_t *tvb, int offset, packet_info *pinfo,
835 proto_tree *tree, hash_entry_t *conv_info) {
837 /* decode the connect ack packet */
841 proto_tree_add_item( tree, hf_msproxy_server_int_port, tvb,
845 conv_info->proto = PT_TCP;
846 conv_info->server_int_port = tvb_get_ntohs( tvb, offset);
850 proto_tree_add_item( tree, hf_msproxy_server_int_addr, tvb,
854 proto_tree_add_item( tree, hf_msproxy_server_ext_port, tvb,
858 proto_tree_add_item( tree, hf_msproxy_server_ext_addr, tvb,
862 display_application_name( tvb, offset, tree);
865 add_msproxy_conversation( pinfo, conv_info);
870 static void dissect_tcp_bind_ack( tvbuff_t *tvb, int offset, proto_tree *tree) {
872 /* decode the tcp bind */
877 proto_tree_add_item( tree, hf_msproxy_bind_id, tvb, offset, 4,
881 proto_tree_add_uint( tree, hf_msproxy_server_int_port, tvb,
885 proto_tree_add_item( tree, hf_msproxy_server_ext_port, tvb,
889 proto_tree_add_item( tree, hf_msproxy_server_ext_addr, tvb,
894 display_application_name( tvb, offset, tree);
900 static void dissect_bind_info( tvbuff_t *tvb, int offset, packet_info *pinfo,
901 proto_tree *tree, hash_entry_t *conv_info) {
903 /* decode the Bind info response from server */
908 proto_tree_add_item( tree, hf_msproxy_bind_id, tvb, offset, 4,
913 conv_info->dst_port = tvb_get_ntohs( tvb, offset);
915 proto_tree_add_uint( tree, hf_msproxy_dstport, tvb, offset, 2,
916 conv_info->dst_port);
919 tvb_memcpy( tvb, (guint8 *)&conv_info->dst_addr, offset, sizeof( guint32));
921 proto_tree_add_item( tree, hf_msproxy_dstaddr, tvb, offset, 4,
925 conv_info->server_int_port = tvb_get_ntohs( tvb, offset);
927 proto_tree_add_uint( tree, hf_msproxy_server_int_port, tvb,
928 offset, 2, conv_info->server_int_port);
932 proto_tree_add_item( tree, hf_msproxy_server_ext_port, tvb,
936 proto_tree_add_item( tree, hf_msproxy_server_ext_addr, tvb,
940 display_application_name( tvb, offset, tree);
944 add_msproxy_conversation( pinfo, conv_info);
949 static void dissect_resolve(tvbuff_t *tvb, int offset, proto_tree *tree) {
951 /* dissect the response resolve structure */
952 /* display a string with a length, characters encoding */
953 /* they are displayed under a tree with the name in Label variable */
954 /* return the length of the string and the length byte */
959 addr_offset = tvb_get_guint8( tvb, offset);
961 proto_tree_add_text( tree, tvb, offset, 1, "Address offset: %d",
968 offset += addr_offset;
970 proto_tree_add_item( tree, hf_msproxy_resolvaddr, tvb, offset, 4,
977 static void dissect_msproxy_response(tvbuff_t *tvb, packet_info *pinfo,
978 proto_tree *tree, hash_entry_t *conv_info) {
984 proto_tree_add_text( tree, tvb, offset, 4, "Client id: 0x%0x",
985 tvb_get_letohl( tvb, offset));
988 proto_tree_add_text( tree, tvb, offset, 4, "Version: 0x%04x",
989 tvb_get_letohl( tvb, offset));
992 proto_tree_add_text( tree, tvb, offset, 4, "Server id: 0x%04x",
993 tvb_get_letohl( tvb, offset));
996 proto_tree_add_text( tree, tvb, offset, 1, "Client ack: 0x%02x",
997 tvb_get_guint8( tvb, offset));
1000 proto_tree_add_text( tree, tvb, offset, 1, "Sequence Number: 0x%02x",
1001 tvb_get_guint8( tvb, offset));
1005 proto_tree_add_text( tree, tvb, offset, 4, "RWSP signature: %.4s",
1006 tvb_get_ptr( tvb, offset, 4));
1013 cmd = tvb_get_ntohs( tvb, offset);
1016 proto_tree_add_uint_format( tree, hf_msproxy_cmd, tvb, offset, 2,
1017 cmd, "Command: 0x%02x (%s)", cmd,
1018 get_msproxy_cmd_name( cmd, FROM_SERVER));
1022 case MSPROXY_HELLO_ACK:
1023 dissect_hello_ack( tvb, offset, tree);
1026 case MSPROXY_USERINFO_ACK:
1027 dissect_user_info_ack( tvb, offset, tree);
1030 case MSPROXY_AUTH_1_ACK:
1031 dissect_auth_1_ack( tvb, offset, tree);
1034 /* this also handle the MSPROXY_BIND_ACK ??? check this */
1036 case MSPROXY_UDPASSOCIATE_ACK:
1037 dissect_udpassociate_ack( tvb, offset, tree);
1040 case MSPROXY_AUTH_2_ACK:
1041 case MSPROXY_AUTH_2_ACK2:
1042 dissect_msproxy_response_4( tvb, offset, tree);
1045 case MSPROXY_TCP_BIND_ACK:
1046 dissect_tcp_bind_ack( tvb, offset, tree);
1049 case MSPROXY_CONNECT_ACK:
1050 dissect_connect_ack( tvb, offset, pinfo, tree,
1054 case MSPROXY_BINDINFO:
1055 dissect_bind_info( tvb, offset, pinfo, tree, conv_info);
1058 case MSPROXY_RESOLVE_ACK:
1059 dissect_resolve( tvb, offset, tree);
1062 case MSPROXY_CONNECT_AUTHFAILED:
1063 case MSPROXY_BIND_AUTHFAILED:
1064 proto_tree_add_text( tree, tvb, offset, 0, "No know information (help wanted)");
1070 (((cmd >> 8) == MSPROXY_CONNREFUSED) ||
1071 ((cmd >> 12) == MSPROXY_CONNREFUSED)))
1072 proto_tree_add_text( tree, tvb, offset, 0,
1073 "No know information (help wanted)");
1076 proto_tree_add_text( tree, tvb, offset, 0,
1077 "Unhandled response command (report this, please)");
1085 static void dissect_msproxy(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
1088 proto_tree *msproxy_tree = NULL;
1093 hash_entry_t *hash_info;
1094 conversation_t *conversation;
1096 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1097 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSproxy");
1098 if (check_col(pinfo->cinfo, COL_INFO))
1099 col_clear(pinfo->cinfo, COL_INFO);
1101 conversation = find_conversation( &pinfo->src, &pinfo->dst,
1102 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
1104 if ( !conversation) {
1105 conversation = conversation_new( &pinfo->src, &pinfo->dst,
1106 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
1108 hash_info = conversation_get_proto_data(conversation, proto_msproxy);
1110 hash_info = g_mem_chunk_alloc(vals);
1111 conversation_add_proto_data(conversation, proto_msproxy,
1115 if (check_col(pinfo->cinfo, COL_INFO)){
1117 cmd = tvb_get_ntohs( tvb, 36);
1119 if ( pinfo->srcport == UDP_PORT_MSPROXY)
1120 col_add_fstr( pinfo->cinfo, COL_INFO, "Server message: %s",
1121 get_msproxy_cmd_name( cmd, FROM_SERVER));
1123 col_add_fstr(pinfo->cinfo, COL_INFO, "Client message: %s",
1124 get_msproxy_cmd_name( cmd, FROM_CLIENT));
1128 if (tree) { /* if proto tree, decode data */
1129 ti = proto_tree_add_item( tree, proto_msproxy, tvb, 0, -1,
1132 msproxy_tree = proto_item_add_subtree(ti, ett_msproxy);
1135 if ( pinfo->srcport == UDP_PORT_MSPROXY)
1136 dissect_msproxy_response( tvb, pinfo, msproxy_tree, hash_info);
1138 dissect_msproxy_request( tvb, msproxy_tree, hash_info);
1143 static void msproxy_reinit( void){
1145 /* Do the cleanup work when a new pass through the packet list is */
1146 /* performed. Reset the highest row seen counter and re-initialize the */
1147 /* conversation memory chunks. */
1152 g_mem_chunk_destroy(vals);
1154 vals = g_mem_chunk_new("msproxy_vals", hash_val_length,
1155 hash_init_count * hash_val_length,
1159 g_mem_chunk_destroy(redirect_vals);
1161 redirect_vals = g_mem_chunk_new("msproxy_redirect_vals", redirect_val_length,
1162 redirect_init_count * redirect_val_length,
1169 proto_register_msproxy( void){
1171 /* Prep the msproxy protocol, for now, just register it */
1173 static gint *ett[] = {
1177 static hf_register_info hf[] = {
1180 { "Command", "msproxy.command", FT_UINT16, BASE_DEC,
1181 NULL, 0x0, "", HFILL
1185 { &hf_msproxy_dstaddr,
1186 { "Destination Address", "msproxy.dstaddr", FT_IPv4, BASE_NONE, NULL,
1191 { &hf_msproxy_srcport,
1192 { "Source Port", "msproxy.srcport", FT_UINT16,
1193 BASE_DEC, NULL, 0x0, "", HFILL
1196 { &hf_msproxy_dstport,
1197 { "Destination Port", "msproxy.dstport", FT_UINT16,
1198 BASE_DEC, NULL, 0x0, "", HFILL
1201 { &hf_msproxy_clntport,
1202 { "Client Port", "msproxy.clntport", FT_UINT16,
1203 BASE_DEC, NULL, 0x0, "", HFILL
1206 { &hf_msproxy_server_ext_addr,
1207 { "Server External Address", "msproxy.server_ext_addr", FT_IPv4, BASE_NONE, NULL,
1212 { &hf_msproxy_server_ext_port,
1213 { "Server External Port", "msproxy.server_ext_port", FT_UINT16,
1214 BASE_DEC, NULL, 0x0, "", HFILL
1218 { &hf_msproxy_server_int_addr,
1219 { "Server Internal Address", "msproxy.server_int_addr", FT_IPv4, BASE_NONE, NULL,
1224 { &hf_msproxy_server_int_port,
1225 { "Server Internal Port", "msproxy.server_int_port", FT_UINT16,
1226 BASE_DEC, NULL, 0x0, "", HFILL
1229 { &hf_msproxy_serverport,
1230 { "Server Port", "msproxy.serverport", FT_UINT16,
1231 BASE_DEC, NULL, 0x0, "", HFILL
1234 { &hf_msproxy_bindport,
1235 { "Bind Port", "msproxy.bindport", FT_UINT16,
1236 BASE_DEC, NULL, 0x0, "", HFILL
1239 { &hf_msproxy_boundport,
1240 { "Bound Port", "msproxy.boundport", FT_UINT16,
1241 BASE_DEC, NULL, 0x0, "", HFILL
1244 { &hf_msproxy_serveraddr,
1245 { "Server Address", "msproxy.serveraddr", FT_IPv4, BASE_NONE, NULL,
1249 { &hf_msproxy_bindaddr,
1250 { "Destination", "msproxy.bindaddr", FT_IPv4, BASE_NONE, NULL,
1254 { &hf_msproxy_bind_id,
1255 { "Bound Port Id", "msproxy.bindid", FT_UINT32,
1256 BASE_HEX, NULL, 0x0, "", HFILL
1259 { &hf_msproxy_resolvaddr,
1260 { "Address", "msproxy.resolvaddr", FT_IPv4, BASE_NONE, NULL,
1267 proto_msproxy = proto_register_protocol( "MS Proxy Protocol",
1268 "MS Proxy", "msproxy");
1270 proto_register_field_array(proto_msproxy, hf, array_length(hf));
1271 proto_register_subtree_array(ett, array_length(ett));
1273 register_init_routine( &msproxy_reinit); /* register re-init routine */
1275 msproxy_sub_handle = create_dissector_handle(msproxy_sub_dissector,
1281 proto_reg_handoff_msproxy(void) {
1283 /* dissector install routine */
1285 dissector_handle_t msproxy_handle;
1287 msproxy_handle = create_dissector_handle(dissect_msproxy,
1289 dissector_add("udp.port", UDP_PORT_MSPROXY, msproxy_handle);