2000-04-12 22:53:16 +00:00
|
|
|
/* packet-socks.c
|
|
|
|
* Routines for socks versions 4 &5 packet dissection
|
|
|
|
* Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2000-04-12 22:53:16 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2001-06-08 08:41:03 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
2000-04-12 22:53:16 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-04-12 22:53:16 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-04-12 22:53:16 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-04-12 22:53:16 +00:00
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The Version 4 decode is based on SOCKS4.protocol and SOCKS4A.protocol.
|
|
|
|
* The Version 5 decoder is based upon rfc-1928
|
|
|
|
* The Version 5 User/Password authentication is based on rfc-1929.
|
|
|
|
*
|
2003-12-30 00:19:18 +00:00
|
|
|
* See
|
|
|
|
*
|
|
|
|
* http://www.socks.permeo.com/TechnicalResources/ProtocolDocuments.asp
|
|
|
|
*
|
2004-06-03 08:04:07 +00:00
|
|
|
* for these and other documents. See
|
|
|
|
*
|
|
|
|
* http://www.socks.nec.com/protocol/socks4a.protocol
|
|
|
|
*
|
|
|
|
* for information on SOCKS version 4a.
|
2000-04-12 22:53:16 +00:00
|
|
|
*
|
2001-01-10 10:59:11 +00:00
|
|
|
* Revisions:
|
|
|
|
*
|
2003-09-17 15:58:11 +00:00
|
|
|
* 2003-09-18 JCFoster Fixed problem with socks tunnel in socks tunnel
|
|
|
|
* causing heap overflow because of an infinite loop
|
|
|
|
* where the socks dissect was call over and over.
|
|
|
|
*
|
|
|
|
* Also remove some old code marked with __JUNK__
|
|
|
|
*
|
2001-01-10 10:59:11 +00:00
|
|
|
* 2001-01-08 JCFoster Fixed problem with NULL pointer for hash data.
|
|
|
|
* Now test and exit if hash_info is null.
|
2000-04-12 22:53:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Possible enhancements -
|
|
|
|
*
|
|
|
|
* Add GSS-API authentication per rfc-1961
|
|
|
|
* Add CHAP authentication
|
|
|
|
* Decode FLAG bits per
|
2003-12-30 00:22:38 +00:00
|
|
|
* http://archive.socks.permeo.com/draft/draft-ietf-aft-socks-pro-v5-04.txt
|
|
|
|
* In call_next_dissector, could load the destination address into
|
|
|
|
* pinfo->src or pinfo->dst structure before calling next dissector.
|
2000-04-12 22:53:16 +00:00
|
|
|
* remove display_string or at least make it use protocol identifiers
|
|
|
|
* socks_hash_entry_t needs to handle V5 address type and domain names
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
2004-08-06 19:57:49 +00:00
|
|
|
#include <epan/addr_resolv.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/conversation.h>
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
#include "packet-tcp.h"
|
|
|
|
#include "packet-udp.h"
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/strutil.h>
|
2005-08-12 21:21:49 +00:00
|
|
|
#include <epan/emem.h>
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
#define compare_packet(X) (X == (pinfo->fd->num))
|
|
|
|
#define get_packet_ptr (pinfo->fd->num)
|
2000-04-12 22:53:16 +00:00
|
|
|
#define row_pointer_type guint32
|
|
|
|
|
|
|
|
#define TCP_PORT_SOCKS 1080
|
|
|
|
|
|
|
|
|
|
|
|
/**************** Socks commands ******************/
|
|
|
|
|
|
|
|
#define CONNECT_COMMAND 1
|
|
|
|
#define BIND_COMMAND 2
|
|
|
|
#define UDP_ASSOCIATE_COMMAND 3
|
|
|
|
#define PING_COMMAND 0x80
|
|
|
|
#define TRACERT_COMMAND 0x81
|
|
|
|
|
|
|
|
|
|
|
|
/********** V5 Authentication methods *************/
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
#define NO_AUTHENTICATION 0
|
2000-04-12 22:53:16 +00:00
|
|
|
#define GSS_API_AUTHENTICATION 1
|
|
|
|
#define USER_NAME_AUTHENTICATION 2
|
|
|
|
#define CHAP_AUTHENTICATION 3
|
|
|
|
#define AUTHENTICATION_FAILED 0xff
|
|
|
|
|
2003-09-17 15:58:11 +00:00
|
|
|
/* 2003-09-18 JCFoster Fixed problem with socks tunnel in socks tunnel */
|
|
|
|
|
|
|
|
static int in_socks_dissector_flag = 0; /* set to 1 to avoid recursive overflow */
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/*********** Header field identifiers *************/
|
|
|
|
|
|
|
|
static int proto_socks = -1;
|
|
|
|
|
|
|
|
static int ett_socks = -1;
|
|
|
|
static int ett_socks_auth = -1;
|
|
|
|
static int ett_socks_name = -1;
|
|
|
|
|
|
|
|
static int hf_socks_ver = -1;
|
|
|
|
static int hf_socks_ip_dst = -1;
|
|
|
|
static int hf_socks_ip6_dst = -1;
|
|
|
|
static int hf_user_name = -1;
|
2004-06-03 08:04:07 +00:00
|
|
|
static int hf_v4a_dns_name = -1;
|
2000-04-12 22:53:16 +00:00
|
|
|
static int hf_socks_dstport = -1;
|
2001-12-11 21:35:01 +00:00
|
|
|
static int hf_socks_cmd = -1;
|
|
|
|
static int hf_socks_results = -1;
|
|
|
|
static int hf_socks_results_4 = -1;
|
|
|
|
static int hf_socks_results_5 = -1;
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
2001-11-27 07:13:32 +00:00
|
|
|
/************* Dissector handles ***********/
|
|
|
|
|
|
|
|
static dissector_handle_t socks_handle;
|
|
|
|
static dissector_handle_t socks_udp_handle;
|
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
/************* State Machine names ***********/
|
|
|
|
|
|
|
|
enum SockState {
|
|
|
|
None = 0,
|
|
|
|
Connecting,
|
|
|
|
V4UserNameWait,
|
|
|
|
V4NameWait,
|
|
|
|
V5Command,
|
|
|
|
V5Reply,
|
2002-08-28 21:04:11 +00:00
|
|
|
V5BindReply,
|
2000-04-12 22:53:16 +00:00
|
|
|
UserNameAuth,
|
2004-02-12 20:47:27 +00:00
|
|
|
UserNameAuthReply,
|
2000-04-12 22:53:16 +00:00
|
|
|
GssApiAuth,
|
|
|
|
AuthReply,
|
|
|
|
Done
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2001-10-29 21:45:12 +00:00
|
|
|
int state;
|
2004-02-12 20:47:27 +00:00
|
|
|
int version;
|
|
|
|
int command;
|
|
|
|
int grant;
|
2001-10-29 21:45:12 +00:00
|
|
|
guint32 port;
|
|
|
|
guint32 udp_port;
|
|
|
|
guint32 udp_remote_port;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
int connect_offset;
|
2000-04-12 22:53:16 +00:00
|
|
|
row_pointer_type v4_name_row;
|
|
|
|
row_pointer_type v4_user_name_row;
|
|
|
|
row_pointer_type connect_row;
|
|
|
|
row_pointer_type cmd_reply_row;
|
|
|
|
row_pointer_type bind_reply_row;
|
|
|
|
row_pointer_type command_row;
|
|
|
|
row_pointer_type auth_method_row;
|
|
|
|
row_pointer_type user_name_auth_row;
|
2004-02-12 20:47:27 +00:00
|
|
|
row_pointer_type auth_version;
|
2000-04-12 22:53:16 +00:00
|
|
|
guint32 start_done_row;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
guint32 dst_addr; /* this needs to handle IPv6 */
|
|
|
|
}socks_hash_entry_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-08-05 00:23:22 +00:00
|
|
|
static const char *address_type_table[] = {
|
2000-04-12 22:53:16 +00:00
|
|
|
"Unknown",
|
|
|
|
"IPv4",
|
|
|
|
"Unknown",
|
|
|
|
"Domain Name",
|
|
|
|
"IPv6",
|
|
|
|
"Unknown"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* String table for the V4 reply status messages */
|
|
|
|
|
2001-12-11 21:35:01 +00:00
|
|
|
static const value_string reply_table_v4[] = {
|
|
|
|
{90, "Granted"},
|
|
|
|
{91, "Rejected or Failed"},
|
|
|
|
{92, "Rejected because SOCKS server cannot connect to identd on the client"},
|
|
|
|
{93, "Rejected because the client program and identd report different user-ids"},
|
|
|
|
{0, NULL}
|
|
|
|
};
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* String table for the V5 reply status messages */
|
|
|
|
|
2001-12-11 21:35:01 +00:00
|
|
|
static const value_string reply_table_v5[] = {
|
|
|
|
{0, "Succeeded"},
|
|
|
|
{1, "General SOCKS server failure"},
|
|
|
|
{2, "Connection not allowed by ruleset"},
|
|
|
|
{3, "Network unreachable"},
|
|
|
|
{4, "Host unreachable"},
|
|
|
|
{5, "Connection refused"},
|
|
|
|
{6, "TTL expired"},
|
|
|
|
{7, "Command not supported"},
|
2003-12-04 05:57:53 +00:00
|
|
|
{8, "Address type not supported"},
|
|
|
|
{0, NULL},
|
2001-12-11 21:35:01 +00:00
|
|
|
};
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-12-11 21:35:01 +00:00
|
|
|
static const value_string cmd_strings[] = {
|
|
|
|
{0, "Unknow"},
|
|
|
|
{1, "Connect"},
|
2002-08-28 21:04:11 +00:00
|
|
|
{2, "Bind"},
|
2001-12-11 21:35:01 +00:00
|
|
|
{3, "UdpAssociate"},
|
|
|
|
{0x80, "Ping"},
|
|
|
|
{0x81, "Traceroute"},
|
|
|
|
{0, NULL}
|
|
|
|
};
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/************************* Support routines ***************************/
|
|
|
|
|
|
|
|
|
2002-04-11 09:38:03 +00:00
|
|
|
static int display_string(tvbuff_t *tvb, int offset,
|
2005-08-05 00:23:22 +00:00
|
|
|
proto_tree *tree, const char *label){
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* display a string with a length, characters encoding */
|
|
|
|
/* they are displayed under a tree with the name in Label variable */
|
|
|
|
/* return the length of the string and the length byte */
|
|
|
|
|
|
|
|
|
|
|
|
proto_tree *name_tree;
|
|
|
|
proto_item *ti;
|
|
|
|
|
|
|
|
char temp[ 256];
|
2001-10-29 21:45:12 +00:00
|
|
|
int length = tvb_get_guint8(tvb, offset);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2002-06-07 11:27:54 +00:00
|
|
|
tvb_memcpy(tvb, (guint8 *)temp, offset+1, length);
|
2000-04-12 22:53:16 +00:00
|
|
|
temp[ length ] = 0;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
ti = proto_tree_add_text(tree, tvb, offset, length + 1,
|
2004-02-12 20:47:27 +00:00
|
|
|
"%s: %s" , label, temp);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
name_tree = proto_item_add_subtree(ti, ett_socks_name);
|
|
|
|
|
2002-06-07 11:27:54 +00:00
|
|
|
proto_tree_add_text( name_tree, tvb, offset, 1, "Length: %u", length);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
++offset;
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( name_tree, tvb, offset, length, "String: %s", temp);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
return length + 1;
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
2005-08-05 00:23:22 +00:00
|
|
|
static const char *get_auth_method_name( guint Number){
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* return the name of the authenication method */
|
|
|
|
|
|
|
|
if ( Number == 0) return "No authentication";
|
|
|
|
if ( Number == 1) return "GSSAPI";
|
|
|
|
if ( Number == 2) return "Username/Password";
|
|
|
|
if ( Number == 3) return "Chap";
|
|
|
|
if (( Number >= 4) && ( Number <= 0x7f))return "IANA assigned";
|
|
|
|
if (( Number >= 0x80) && ( Number <= 0xfe)) return "private method";
|
|
|
|
if ( Number == 0xff) return "no acceptable method";
|
|
|
|
|
|
|
|
/* shouldn't reach here */
|
|
|
|
|
|
|
|
return "Bad method number (not 0-0xff)";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-05 00:23:22 +00:00
|
|
|
static const char *get_command_name( guint Number){
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* return the name of the command as a string */
|
|
|
|
|
|
|
|
if ( Number == 0) return "Unknow";
|
|
|
|
if ( Number == 1) return "Connect";
|
|
|
|
if ( Number == 2) return "Bind";
|
|
|
|
if ( Number == 3) return "UdpAssociate";
|
|
|
|
if ( Number == 0x80) return "Ping";
|
|
|
|
if ( Number == 0x81) return "Traceroute";
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-11 09:38:03 +00:00
|
|
|
static int display_address(tvbuff_t *tvb, int offset, proto_tree *tree) {
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* decode and display the v5 address, return offset of next byte */
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
int a_type = tvb_get_guint8(tvb, offset);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, 1,
|
2002-08-28 21:04:11 +00:00
|
|
|
"Address Type: %d (%s)", a_type,
|
2001-10-26 18:28:17 +00:00
|
|
|
address_type_table[ MIN( (guint) a_type,
|
|
|
|
array_length( address_type_table)-1) ]);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
++offset;
|
|
|
|
|
|
|
|
if ( a_type == 1){ /* IPv4 address */
|
2001-10-30 10:40:38 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_ip_dst, tvb, offset,
|
|
|
|
4, FALSE);
|
2000-04-12 22:53:16 +00:00
|
|
|
offset += 4;
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( a_type == 3){ /* domain name address */
|
|
|
|
|
2002-04-11 09:38:03 +00:00
|
|
|
offset += display_string(tvb, offset, tree,
|
2000-04-12 22:53:16 +00:00
|
|
|
"Remote name");
|
|
|
|
}
|
|
|
|
else if ( a_type == 4){ /* IPv6 address */
|
2001-10-30 10:40:38 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_ip6_dst, tvb, offset,
|
|
|
|
16, FALSE);
|
2000-04-12 22:53:16 +00:00
|
|
|
offset += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
static int get_address_v5(tvbuff_t *tvb, int offset,
|
2000-04-12 22:53:16 +00:00
|
|
|
socks_hash_entry_t *hash_info) {
|
|
|
|
|
|
|
|
/* decode the v5 address and return offset of next byte */
|
2001-10-29 21:45:12 +00:00
|
|
|
/*XXX this needs to handle IPV6 and domain name addresses */
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
int a_type = tvb_get_guint8(tvb, offset++);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
if ( a_type == 1){ /* IPv4 address */
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
if ( hash_info)
|
2001-10-30 10:40:38 +00:00
|
|
|
tvb_memcpy(tvb, (guint8 *)&hash_info->dst_addr,
|
|
|
|
offset, 4);
|
2000-04-12 22:53:16 +00:00
|
|
|
offset += 4;
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( a_type == 4) /* IPv6 address */
|
|
|
|
offset += 16;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( a_type == 3) /* domain name address */
|
2001-10-29 21:45:12 +00:00
|
|
|
offset += tvb_get_guint8(tvb, offset) + 1;
|
2000-04-12 22:53:16 +00:00
|
|
|
return offset;
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/********************* V5 UDP Associate handlers ***********************/
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
static void
|
|
|
|
socks_udp_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* Conversation dissector called from UDP dissector. Decode and display */
|
|
|
|
/* the socks header, the pass the rest of the data to the udp port */
|
|
|
|
/* decode routine to handle the payload. */
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
int offset = 0;
|
2000-04-12 22:53:16 +00:00
|
|
|
guint32 *ptr;
|
|
|
|
socks_hash_entry_t *hash_info;
|
|
|
|
conversation_t *conversation;
|
|
|
|
proto_tree *socks_tree;
|
|
|
|
proto_item *ti;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2005-02-02 20:07:03 +00:00
|
|
|
conversation = find_conversation( pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
|
2001-10-29 21:45:12 +00:00
|
|
|
pinfo->srcport, pinfo->destport, 0);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2005-06-10 18:28:22 +00:00
|
|
|
DISSECTOR_ASSERT( conversation); /* should always find a conversation */
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-09-03 10:33:12 +00:00
|
|
|
hash_info = conversation_get_proto_data(conversation, proto_socks);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Socks");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "Version: 5, UDP Associated packet");
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
if ( tree) {
|
2002-01-24 09:20:54 +00:00
|
|
|
ti = proto_tree_add_protocol_format( tree, proto_socks, tvb,
|
|
|
|
offset, -1, "Socks" );
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
socks_tree = proto_item_add_subtree(ti, ett_socks);
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( socks_tree, tvb, offset, 2, "Reserved");
|
2000-04-12 22:53:16 +00:00
|
|
|
offset += 2;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2003-10-15 20:07:51 +00:00
|
|
|
proto_tree_add_text( socks_tree, tvb, offset, 1, "Fragment Number: %u", tvb_get_guint8(tvb, offset));
|
2000-04-12 22:53:16 +00:00
|
|
|
++offset;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2002-04-11 09:38:03 +00:00
|
|
|
offset = display_address( tvb, offset, socks_tree);
|
2001-10-29 21:45:12 +00:00
|
|
|
hash_info->udp_remote_port = tvb_get_ntohs(tvb, offset);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_uint( socks_tree, hf_socks_dstport, tvb,
|
2000-04-12 22:53:16 +00:00
|
|
|
offset, 2, hash_info->udp_remote_port);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
offset += 2;
|
|
|
|
}
|
|
|
|
else { /* no tree, skip past the socks header */
|
|
|
|
offset += 3;
|
2001-10-29 21:45:12 +00:00
|
|
|
offset = get_address_v5( tvb, offset, 0) + 2;
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* set pi src/dst port and call the udp sub-dissector lookup */
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
if ( pinfo->srcport == hash_info->port)
|
2001-10-29 21:45:12 +00:00
|
|
|
ptr = &pinfo->destport;
|
2000-04-12 22:53:16 +00:00
|
|
|
else
|
2001-10-29 21:45:12 +00:00
|
|
|
ptr = &pinfo->srcport;
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
*ptr = hash_info->udp_remote_port;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2004-01-22 20:43:17 +00:00
|
|
|
decode_udp_ports( tvb, offset, pinfo, tree, pinfo->srcport, pinfo->destport, -1);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
*ptr = hash_info->udp_port;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
|
|
|
|
static void
|
2001-10-29 21:45:12 +00:00
|
|
|
new_udp_conversation( socks_hash_entry_t *hash_info, packet_info *pinfo){
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2005-02-02 20:07:03 +00:00
|
|
|
conversation_t *conversation = conversation_new( pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
|
2001-09-03 10:33:12 +00:00
|
|
|
hash_info->udp_port, hash_info->port, 0);
|
|
|
|
|
2005-06-10 18:28:22 +00:00
|
|
|
DISSECTOR_ASSERT( conversation);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-09-03 10:33:12 +00:00
|
|
|
conversation_add_proto_data(conversation, proto_socks, hash_info);
|
2001-11-27 07:13:32 +00:00
|
|
|
conversation_set_dissector(conversation, socks_udp_handle);
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************** Protocol Tree Display routines ******************/
|
|
|
|
|
2002-04-11 09:38:03 +00:00
|
|
|
static void
|
2001-10-30 10:40:38 +00:00
|
|
|
display_socks_v4(tvbuff_t *tvb, int offset, packet_info *pinfo,
|
2002-04-11 09:38:03 +00:00
|
|
|
proto_tree *tree, socks_hash_entry_t *hash_info) {
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
2001-12-11 21:35:01 +00:00
|
|
|
/* Display the protocol tree for the V4 version. This routine uses the */
|
2000-04-12 22:53:16 +00:00
|
|
|
/* stored conversation information to decide what to do with the row. */
|
|
|
|
/* Per packet information would have been better to do this, but we */
|
|
|
|
/* didn't have that when I wrote this. And I didn't expect this to get */
|
|
|
|
/* so messy. */
|
|
|
|
|
|
|
|
|
2001-12-11 21:35:01 +00:00
|
|
|
guint command;
|
2004-06-03 08:04:07 +00:00
|
|
|
unsigned char ipaddr[4];
|
|
|
|
guint username_len, domainname_len;
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* Display command from client */
|
|
|
|
if (compare_packet( hash_info->connect_row)){
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, 1,
|
2003-10-15 20:07:51 +00:00
|
|
|
"Version: %u", hash_info->version);
|
2000-04-12 22:53:16 +00:00
|
|
|
++offset;
|
2001-10-29 21:45:12 +00:00
|
|
|
command = tvb_get_guint8(tvb, offset);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, 1,
|
2002-08-28 21:04:11 +00:00
|
|
|
"Command: %u (%s)", command,
|
2000-04-12 22:53:16 +00:00
|
|
|
get_command_name( command));
|
|
|
|
++offset;
|
|
|
|
|
|
|
|
/* Do remote port */
|
2001-10-30 10:40:38 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_dstport, tvb, offset, 2,
|
|
|
|
FALSE);
|
2000-04-12 22:53:16 +00:00
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
/* Do destination address */
|
2004-06-03 08:04:07 +00:00
|
|
|
tvb_memcpy(tvb, ipaddr, offset, 4);
|
2001-10-30 10:40:38 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_ip_dst, tvb, offset,
|
|
|
|
4, FALSE);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
offset += 4;
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
/*XXX check this, needs to do length checking */
|
2001-10-30 10:40:38 +00:00
|
|
|
/* Should perhaps do TCP reassembly as well */
|
|
|
|
if ( tvb_offset_exists(tvb, offset)) {
|
2000-04-12 22:53:16 +00:00
|
|
|
/* display user name */
|
2004-06-03 08:04:07 +00:00
|
|
|
username_len = tvb_strsize(tvb, offset);
|
|
|
|
proto_tree_add_item( tree, hf_user_name, tvb, offset,
|
|
|
|
username_len, FALSE);
|
|
|
|
offset += username_len;
|
|
|
|
if ( ipaddr[0] == 0 && ipaddr[1] == 0 &&
|
|
|
|
ipaddr[2] == 0 && ipaddr[3] != 0) {
|
|
|
|
/* 0.0.0.x , where x!=0 means v4a support */
|
|
|
|
domainname_len = tvb_strsize(tvb, offset);
|
|
|
|
proto_tree_add_item( tree, hf_v4a_dns_name,
|
|
|
|
tvb, offset, domainname_len,
|
|
|
|
FALSE);
|
|
|
|
}
|
2001-10-30 10:40:38 +00:00
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
/*Display command response from server*/
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( compare_packet( hash_info->cmd_reply_row)){
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-12-11 21:35:01 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_ver, tvb, offset, 1,
|
|
|
|
FALSE);
|
2000-04-12 22:53:16 +00:00
|
|
|
++offset;
|
|
|
|
/* Do results code */
|
2001-12-11 21:35:01 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_results_4, tvb, offset, 1, FALSE);
|
2002-03-09 22:54:27 +00:00
|
|
|
proto_tree_add_item_hidden(tree, hf_socks_results, tvb, offset, 1, FALSE);
|
2001-12-11 21:35:01 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
++offset;
|
|
|
|
|
|
|
|
/* Do remote port */
|
2001-10-30 10:40:38 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_dstport, tvb, offset, 2,
|
|
|
|
FALSE);
|
|
|
|
offset += 2;
|
2000-04-12 22:53:16 +00:00
|
|
|
/* Do remote address */
|
2001-10-30 10:40:38 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_ip_dst, tvb, offset, 4,
|
|
|
|
FALSE);
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( compare_packet( hash_info->v4_user_name_row)){
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-10-30 10:40:38 +00:00
|
|
|
/*XXX check this, needs to do length checking */
|
|
|
|
/* Should perhaps do TCP reassembly as well */
|
|
|
|
if ( tvb_offset_exists(tvb, offset)) {
|
|
|
|
proto_tree_add_text( tree, tvb, offset,
|
2002-06-07 11:27:54 +00:00
|
|
|
tvb_strsize(tvb, offset),
|
2001-10-29 21:45:12 +00:00
|
|
|
"User Name: %s", tvb_get_ptr(tvb, offset, -1));
|
2001-10-30 10:40:38 +00:00
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
static void
|
2001-10-29 21:45:12 +00:00
|
|
|
display_socks_v5(tvbuff_t *tvb, int offset, packet_info *pinfo,
|
2002-04-11 09:38:03 +00:00
|
|
|
proto_tree *tree, socks_hash_entry_t *hash_info) {
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
/* Display the protocol tree for the version. This routine uses the */
|
|
|
|
/* stored conversation information to decide what to do with the row. */
|
|
|
|
/* Per packet information would have been better to do this, but we */
|
|
|
|
/* didn't have that when I wrote this. And I didn't expect this to get */
|
|
|
|
/* so messy. */
|
|
|
|
|
2001-09-03 08:27:56 +00:00
|
|
|
unsigned int i, command;
|
2000-04-12 22:53:16 +00:00
|
|
|
guint temp;
|
2005-08-06 01:39:51 +00:00
|
|
|
const char *AuthMethodStr;
|
2004-02-12 21:04:05 +00:00
|
|
|
guint8 auth_status;
|
|
|
|
|
2003-10-15 19:57:27 +00:00
|
|
|
proto_tree_add_item( tree, hf_socks_ver, tvb, offset, 1, FALSE);
|
|
|
|
++offset;
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
if (compare_packet( hash_info->connect_row)){
|
|
|
|
|
|
|
|
proto_tree *AuthTree;
|
|
|
|
proto_item *ti;
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
temp = tvb_get_guint8(tvb, offset); /* Get Auth method count */
|
2000-04-12 22:53:16 +00:00
|
|
|
/* build auth tree */
|
2003-10-15 20:07:51 +00:00
|
|
|
ti = proto_tree_add_text( tree, tvb, offset, -1,
|
2000-04-12 22:53:16 +00:00
|
|
|
"Client Authentication Methods");
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
AuthTree = proto_item_add_subtree(ti, ett_socks_auth);
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( AuthTree, tvb, offset, 1,
|
2003-10-15 20:07:51 +00:00
|
|
|
"Count: %u", temp);
|
2000-04-12 22:53:16 +00:00
|
|
|
++offset;
|
|
|
|
|
|
|
|
for( i = 0; i < temp; ++i) {
|
|
|
|
|
|
|
|
AuthMethodStr = get_auth_method_name(
|
2003-10-15 20:07:51 +00:00
|
|
|
tvb_get_guint8( tvb, offset));
|
|
|
|
proto_tree_add_text( AuthTree, tvb, offset, 1,
|
|
|
|
"Method[%u]: %u (%s)", i,
|
|
|
|
tvb_get_guint8( tvb, offset), AuthMethodStr);
|
|
|
|
++offset;
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
2003-10-15 20:07:51 +00:00
|
|
|
proto_item_set_end( ti, tvb, offset);
|
2000-04-12 22:53:16 +00:00
|
|
|
return;
|
|
|
|
} /* Get accepted auth method */
|
|
|
|
else if (compare_packet( hash_info->auth_method_row)) {
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, 1,
|
|
|
|
"Accepted Auth Method: 0x%0x (%s)", tvb_get_guint8( tvb, offset),
|
|
|
|
get_auth_method_name( tvb_get_guint8( tvb, offset)));
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
} /* handle user/password auth */
|
|
|
|
else if (compare_packet( hash_info->user_name_auth_row)) {
|
|
|
|
|
2003-10-15 20:07:51 +00:00
|
|
|
/* process user name */
|
2002-04-11 09:38:03 +00:00
|
|
|
offset += display_string( tvb, offset, tree,
|
2000-04-12 22:53:16 +00:00
|
|
|
"User name");
|
|
|
|
/* process password */
|
2002-04-11 09:38:03 +00:00
|
|
|
offset += display_string( tvb, offset, tree,
|
2000-04-12 22:53:16 +00:00
|
|
|
"Password");
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
|
|
|
/* command to the server */
|
2000-04-12 22:53:16 +00:00
|
|
|
/* command response from server */
|
2004-02-12 20:47:27 +00:00
|
|
|
else if (compare_packet( hash_info->auth_version)) {
|
|
|
|
auth_status = tvb_get_guint8(tvb, offset);
|
|
|
|
if(auth_status != 0)
|
2004-02-12 21:04:05 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, 1, "Status: %u (failure)", auth_status);
|
2004-02-12 20:47:27 +00:00
|
|
|
else
|
2004-02-12 21:04:05 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, 1, "Status: success");
|
2004-02-12 20:47:27 +00:00
|
|
|
offset ++;
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
else if ((compare_packet( hash_info->command_row)) ||
|
2000-04-12 22:53:16 +00:00
|
|
|
(compare_packet( hash_info->cmd_reply_row)) ||
|
|
|
|
(compare_packet( hash_info->bind_reply_row))){
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
command = tvb_get_guint8(tvb, offset);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
if (compare_packet( hash_info->command_row))
|
2002-03-09 22:54:27 +00:00
|
|
|
proto_tree_add_uint( tree, hf_socks_cmd, tvb, offset, 1,
|
|
|
|
command);
|
2001-12-11 21:35:01 +00:00
|
|
|
|
|
|
|
else {
|
|
|
|
proto_tree_add_item( tree, hf_socks_results_5, tvb, offset, 1, FALSE);
|
2002-03-09 22:54:27 +00:00
|
|
|
proto_tree_add_item_hidden(tree, hf_socks_results, tvb, offset, 1, FALSE);
|
2001-12-11 21:35:01 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
++offset;
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, 1,
|
2002-08-28 21:04:11 +00:00
|
|
|
"Reserved: 0x%0x (should = 0x00)", tvb_get_guint8(tvb, offset));
|
2000-04-12 22:53:16 +00:00
|
|
|
++offset;
|
|
|
|
|
2002-04-11 09:38:03 +00:00
|
|
|
offset = display_address(tvb, offset, tree);
|
2001-12-11 21:35:01 +00:00
|
|
|
/*XXX Add remote port for search somehow */
|
2000-04-12 22:53:16 +00:00
|
|
|
/* Do remote port */
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, 2,
|
2003-10-15 20:07:51 +00:00
|
|
|
"%sPort: %u",
|
2000-04-12 22:53:16 +00:00
|
|
|
(compare_packet( hash_info->bind_reply_row) ?
|
|
|
|
"Remote Host " : ""),
|
2001-10-29 21:45:12 +00:00
|
|
|
tvb_get_ntohs(tvb, offset));
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
/**************** Decoder State Machines ******************/
|
|
|
|
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
static guint
|
2001-10-30 10:40:38 +00:00
|
|
|
state_machine_v4( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
|
|
|
|
int offset, packet_info *pinfo) {
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* Decode V4 protocol. This is done on the first pass through the */
|
|
|
|
/* list. Based upon the current state, decode the packet and determine */
|
|
|
|
/* what the next state should be. If we had per packet information, */
|
|
|
|
/* this would be the place to load them up. */
|
|
|
|
|
|
|
|
if ( hash_info->state == None) { /* new connection */
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, " Connect to server request");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
hash_info->state = Connecting; /* change state */
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
hash_info->command = tvb_get_guint8(tvb, offset + 1);
|
2000-04-12 22:53:16 +00:00
|
|
|
/* get remote port */
|
2002-08-28 21:04:11 +00:00
|
|
|
if ( hash_info->command == CONNECT_COMMAND)
|
2001-10-29 21:45:12 +00:00
|
|
|
hash_info->port = tvb_get_ntohs(tvb, offset + 2);
|
2000-04-12 22:53:16 +00:00
|
|
|
/* get remote address */
|
2001-10-30 10:40:38 +00:00
|
|
|
|
|
|
|
tvb_memcpy(tvb, (guint8 *)&hash_info->dst_addr, offset + 4, 4);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
/* save the packet pointer */
|
|
|
|
hash_info->connect_row = get_packet_ptr;
|
|
|
|
|
|
|
|
/* skip past this stuff */
|
|
|
|
hash_info->connect_offset = offset + 8;
|
|
|
|
|
|
|
|
offset += 8;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2002-06-07 11:37:05 +00:00
|
|
|
if ( !tvb_offset_exists(tvb, offset)) { /* if no user name */
|
2001-10-30 10:40:38 +00:00
|
|
|
/* change state */
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info->state = V4UserNameWait;
|
2002-06-07 11:37:05 +00:00
|
|
|
/*
|
|
|
|
* XXX - add 1, or leave it alone?
|
|
|
|
* We were adding "strlen(...) + 1".
|
|
|
|
*/
|
|
|
|
hash_info->connect_offset += 1;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Add in the length of the user name.
|
|
|
|
* XXX - what if the user name is split between
|
|
|
|
* TCP segments?
|
|
|
|
*/
|
|
|
|
hash_info->connect_offset += tvb_strsize(tvb, offset);
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
if ( !hash_info->dst_addr){ /* if no dest address */
|
|
|
|
/* if more data */
|
2001-10-30 10:40:38 +00:00
|
|
|
if ( tvb_offset_exists(tvb, hash_info->connect_offset)) {
|
2001-10-29 21:45:12 +00:00
|
|
|
/*XXX copy remote name here ??? */
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info->state = Connecting;
|
|
|
|
}
|
|
|
|
else
|
2002-08-28 21:04:11 +00:00
|
|
|
hash_info->state = V4NameWait;
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
/* waiting for V4 user name */
|
2002-08-28 21:04:11 +00:00
|
|
|
}else if ( hash_info->state == V4UserNameWait){
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, " Connect Request (User name)");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
hash_info->v4_user_name_row = get_packet_ptr;
|
2001-10-29 21:45:12 +00:00
|
|
|
/*XXX may need to check for domain name here */
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info->state = Connecting;
|
|
|
|
}
|
|
|
|
/* waiting for V4 domain name */
|
|
|
|
else if ( hash_info->state == V4NameWait){
|
|
|
|
|
|
|
|
hash_info->v4_name_row = get_packet_ptr;
|
|
|
|
hash_info->state = Connecting;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ( hash_info->state == Connecting){
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, " Connect Response");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* save packet pointer */
|
|
|
|
hash_info->cmd_reply_row = get_packet_ptr;
|
|
|
|
hash_info->state = Done; /* change state */
|
|
|
|
offset = offset + 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
static void
|
2001-10-30 10:40:38 +00:00
|
|
|
state_machine_v5( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
|
|
|
|
int offset, packet_info *pinfo) {
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* Decode V5 protocol. This is done on the first pass through the */
|
|
|
|
/* list. Based upon the current state, decode the packet and determine */
|
|
|
|
/* what the next state should be. If we had per packet information, */
|
|
|
|
/* this would be the place to load them up. */
|
|
|
|
|
|
|
|
|
|
|
|
int temp;
|
|
|
|
|
|
|
|
if ( hash_info->state == None) {
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, " Connect to server request");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
hash_info->state = Connecting; /* change state */
|
2002-08-28 21:04:11 +00:00
|
|
|
hash_info->connect_row = get_packet_ptr;
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
temp = tvb_get_guint8(tvb, offset + 1);
|
2000-04-12 22:53:16 +00:00
|
|
|
/* skip past auth methods */
|
|
|
|
offset = hash_info->connect_offset = offset + 1 + temp;
|
|
|
|
}
|
|
|
|
else if ( hash_info->state == Connecting){
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
guint AuthMethod = tvb_get_guint8(tvb, offset + 1);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, " Connect to server response");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
hash_info->auth_method_row = get_packet_ptr;
|
|
|
|
|
|
|
|
if ( AuthMethod == NO_AUTHENTICATION)
|
|
|
|
hash_info->state = V5Command;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( AuthMethod == USER_NAME_AUTHENTICATION)
|
|
|
|
hash_info->state = UserNameAuth;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( AuthMethod == GSS_API_AUTHENTICATION)
|
2001-10-29 21:45:12 +00:00
|
|
|
/*XXX should be this hash_info->state = GssApiAuth; */
|
2002-08-28 21:04:11 +00:00
|
|
|
hash_info->state = Done;
|
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else hash_info->state = Done; /*Auth failed or error*/
|
|
|
|
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( hash_info->state == V5Command) { /* Handle V5 Command */
|
|
|
|
|
|
|
|
guint temp;
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
hash_info->command = tvb_get_guint8(tvb, offset + 1); /* get command */
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, " Command Request - %s",
|
|
|
|
get_command_name(hash_info->command));
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
hash_info->state = V5Reply;
|
|
|
|
hash_info->command_row = get_packet_ptr;
|
|
|
|
|
|
|
|
offset += 3; /* skip to address type */
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
offset = get_address_v5(tvb, offset, hash_info);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
temp = tvb_get_guint8(tvb, offset);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
if (( hash_info->command == CONNECT_COMMAND) ||
|
2000-04-12 22:53:16 +00:00
|
|
|
( hash_info->command == UDP_ASSOCIATE_COMMAND))
|
|
|
|
/* get remote port */
|
2001-10-29 21:45:12 +00:00
|
|
|
hash_info->port = tvb_get_ntohs(tvb, offset);
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ( hash_info->state == V5Reply) { /* V5 Command Reply */
|
|
|
|
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, " Command Response - %s",
|
|
|
|
get_command_name(hash_info->command));
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
hash_info->cmd_reply_row = get_packet_ptr;
|
|
|
|
|
|
|
|
if (( hash_info->command == CONNECT_COMMAND) ||
|
|
|
|
(hash_info->command == PING_COMMAND) ||
|
|
|
|
(hash_info->command == TRACERT_COMMAND))
|
|
|
|
hash_info->state = Done;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( hash_info->command == BIND_COMMAND)
|
|
|
|
hash_info->state = V5BindReply;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( hash_info->command == UDP_ASSOCIATE_COMMAND){
|
|
|
|
offset += 3; /* skip to address type */
|
2001-10-29 21:45:12 +00:00
|
|
|
offset = get_address_v5(tvb, offset, hash_info);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-09-03 10:33:12 +00:00
|
|
|
/* save server udp port and create udp conversation */
|
2001-10-29 21:45:12 +00:00
|
|
|
hash_info->udp_port = tvb_get_ntohs(tvb, offset);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
if (!pinfo->fd->flags.visited)
|
|
|
|
new_udp_conversation( hash_info, pinfo);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
/*XXX may need else statement to handle unknows and generate error message */
|
2002-08-28 21:04:11 +00:00
|
|
|
|
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
else if ( hash_info->state == V5BindReply) { /* V5 Bind Second Reply */
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, " Command Response: Bind remote host info");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
hash_info->bind_reply_row = get_packet_ptr;
|
|
|
|
hash_info->state = Done;
|
|
|
|
}
|
|
|
|
else if ( hash_info->state == UserNameAuth) { /* Handle V5 User Auth*/
|
2004-02-12 20:47:27 +00:00
|
|
|
hash_info->auth_version = get_packet_ptr;
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO,
|
|
|
|
" User authentication request");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
hash_info->user_name_auth_row = get_packet_ptr;
|
|
|
|
hash_info->state = AuthReply;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ( hash_info->state == AuthReply){ /* V5 User Auth reply */
|
2004-02-12 20:47:27 +00:00
|
|
|
hash_info->auth_version = get_packet_ptr;
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2004-02-12 20:47:27 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, " User authentication reply");
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info->state = V5Command;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
static void
|
2001-10-29 21:45:12 +00:00
|
|
|
display_ping_and_tracert(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, socks_hash_entry_t *hash_info) {
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* Display the ping/trace_route conversation */
|
|
|
|
|
|
|
|
|
2002-08-02 23:36:07 +00:00
|
|
|
const guchar *data, *dataend;
|
|
|
|
const guchar *lineend, *eol;
|
2000-04-12 22:53:16 +00:00
|
|
|
int linelen;
|
|
|
|
|
|
|
|
/* handle the end command */
|
2001-10-29 21:45:12 +00:00
|
|
|
if ( pinfo->destport == TCP_PORT_SOCKS){
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, ", Terminate Request");
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
if ( tree)
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text(tree, tvb, offset, 1,
|
2000-04-12 22:53:16 +00:00
|
|
|
(hash_info->command == PING_COMMAND) ?
|
2004-02-12 20:47:27 +00:00
|
|
|
"Ping: End command" :
|
|
|
|
"Traceroute: End command");
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
else{ /* display the PING or Traceroute results */
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, ", Results");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
if ( tree){
|
2002-01-24 09:20:54 +00:00
|
|
|
proto_tree_add_text(tree, tvb, offset, -1,
|
2004-02-12 20:47:27 +00:00
|
|
|
(hash_info->command == PING_COMMAND) ?
|
|
|
|
"Ping Results:" :
|
|
|
|
"Traceroute Results");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
data = tvb_get_ptr(tvb, offset, -1);
|
|
|
|
dataend = data + tvb_length_remaining(tvb, offset);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
while (data < dataend) {
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
lineend = find_line_end(data, dataend, &eol);
|
|
|
|
linelen = lineend - data;
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( tree, tvb, offset, linelen,
|
2003-02-26 01:35:07 +00:00
|
|
|
"%s", format_text(data, linelen));
|
2000-04-12 22:53:16 +00:00
|
|
|
offset += linelen;
|
|
|
|
data = lineend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-29 19:05:40 +00:00
|
|
|
static void clear_in_socks_dissector_flag(void *dummy _U_)
|
|
|
|
{
|
|
|
|
in_socks_dissector_flag = 0; /* avoid recursive overflow */
|
|
|
|
}
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
static void call_next_dissector(tvbuff_t *tvb, int offset, packet_info *pinfo,
|
2003-12-30 00:03:48 +00:00
|
|
|
proto_tree *tree, proto_tree *socks_tree,
|
|
|
|
socks_hash_entry_t *hash_info)
|
|
|
|
{
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
/* Display the results for PING and TRACERT extensions or */
|
2001-10-30 10:40:38 +00:00
|
|
|
/* Call TCP dissector for the port that was passed during the */
|
2000-04-12 22:53:16 +00:00
|
|
|
/* connect process */
|
2001-10-30 10:40:38 +00:00
|
|
|
/* Load pointer to pinfo->XXXport depending upon the direction, */
|
|
|
|
/* change pinfo port to the remote port, call next dissecotr to decode */
|
|
|
|
/* the payload, and restore the pinfo port after that is done. */
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
guint32 *ptr;
|
2003-12-30 00:03:48 +00:00
|
|
|
struct tcpinfo *tcpinfo = pinfo->private_data;
|
|
|
|
guint16 save_can_desegment;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
if (( hash_info->command == PING_COMMAND) ||
|
|
|
|
( hash_info->command == TRACERT_COMMAND))
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
display_ping_and_tracert(tvb, offset, pinfo, tree, hash_info);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
else { /* call the tcp port decoder to handle the payload */
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
/*XXX may want to load dest address here */
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
if ( pinfo->destport == TCP_PORT_SOCKS)
|
|
|
|
ptr = &pinfo->destport;
|
2000-04-12 22:53:16 +00:00
|
|
|
else
|
2001-10-29 21:45:12 +00:00
|
|
|
ptr = &pinfo->srcport;
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
*ptr = hash_info->port;
|
2003-09-17 15:58:11 +00:00
|
|
|
|
|
|
|
/* 2003-09-18 JCFoster Fixed problem with socks tunnel in socks tunnel */
|
|
|
|
|
|
|
|
in_socks_dissector_flag = 1; /* avoid recursive overflow */
|
2003-12-29 19:05:40 +00:00
|
|
|
CLEANUP_PUSH(clear_in_socks_dissector_flag, NULL);
|
2003-09-17 15:58:11 +00:00
|
|
|
|
2003-12-30 00:03:48 +00:00
|
|
|
save_can_desegment = pinfo->can_desegment;
|
|
|
|
pinfo->can_desegment = pinfo->saved_can_desegment;
|
|
|
|
dissect_tcp_payload(tvb, pinfo, offset, tcpinfo->seq,
|
|
|
|
tcpinfo->nxtseq, pinfo->srcport, pinfo->destport,
|
|
|
|
tree, socks_tree);
|
|
|
|
pinfo->can_desegment = save_can_desegment;
|
2003-09-17 15:58:11 +00:00
|
|
|
|
2003-12-29 19:05:40 +00:00
|
|
|
CLEANUP_CALL_AND_POP;
|
2003-09-17 15:58:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
*ptr = TCP_PORT_SOCKS;
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-10-29 21:45:12 +00:00
|
|
|
dissect_socks(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
int offset = 0;
|
2003-12-30 00:03:48 +00:00
|
|
|
proto_tree *socks_tree = NULL;
|
2000-04-12 22:53:16 +00:00
|
|
|
proto_item *ti;
|
|
|
|
socks_hash_entry_t *hash_info;
|
|
|
|
conversation_t *conversation;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2003-09-17 15:58:11 +00:00
|
|
|
/* 2003-09-18 JCFoster Fixed problem with socks tunnel in socks tunnel */
|
|
|
|
|
|
|
|
/* avoid recursive overflow */
|
|
|
|
|
|
|
|
if ( in_socks_dissector_flag) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-02 20:07:03 +00:00
|
|
|
conversation = find_conversation( pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
|
2001-10-29 21:45:12 +00:00
|
|
|
pinfo->srcport, pinfo->destport, 0);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-09-03 10:33:12 +00:00
|
|
|
if ( !conversation){
|
2005-02-02 20:07:03 +00:00
|
|
|
conversation = conversation_new( pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
|
2001-10-29 21:45:12 +00:00
|
|
|
pinfo->srcport, pinfo->destport, 0);
|
2001-09-03 10:33:12 +00:00
|
|
|
}
|
|
|
|
hash_info = conversation_get_proto_data(conversation,proto_socks);
|
|
|
|
if ( !hash_info){
|
2005-08-12 21:21:49 +00:00
|
|
|
hash_info = se_alloc(sizeof(socks_hash_entry_t));
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info->start_done_row = G_MAXINT;
|
|
|
|
hash_info->state = None;
|
2001-10-29 21:45:12 +00:00
|
|
|
hash_info->port = 0;
|
|
|
|
hash_info->version = tvb_get_guint8(tvb, offset); /* get version*/
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
if (( hash_info->version != 4) && /* error test version */
|
|
|
|
( hash_info->version != 5))
|
|
|
|
hash_info->state = Done;
|
|
|
|
|
2001-09-03 10:33:12 +00:00
|
|
|
conversation_add_proto_data(conversation, proto_socks,
|
|
|
|
hash_info);
|
2001-01-10 10:59:11 +00:00
|
|
|
|
|
|
|
/* set dissector for now */
|
2001-11-27 07:13:32 +00:00
|
|
|
conversation_set_dissector(conversation, socks_handle);
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* display summary window information */
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Socks");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO)){
|
2000-04-12 22:53:16 +00:00
|
|
|
if (( hash_info->version == 4) || ( hash_info->version == 5)){
|
2001-12-10 00:26:21 +00:00
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "Version: %d",
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info->version);
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
2000-04-12 22:53:16 +00:00
|
|
|
else /* unknown version display error */
|
2001-12-10 00:26:21 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Unknown");
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
if ( hash_info->command == PING_COMMAND)
|
2001-12-10 00:26:21 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, ", Ping Req");
|
2000-04-12 22:53:16 +00:00
|
|
|
if ( hash_info->command == TRACERT_COMMAND)
|
2001-12-10 00:26:21 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, ", Traceroute Req");
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-11-27 07:41:39 +00:00
|
|
|
/*XXX if ( hash_info->port != -1) */
|
2001-10-29 21:45:12 +00:00
|
|
|
if ( hash_info->port != 0)
|
2003-10-15 20:07:51 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Remote Port: %u",
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info->port);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* run state machine if needed */
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
if ((hash_info->state != Done) && ( !pinfo->fd->flags.visited)){
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
if ( hash_info->version == 4)
|
2001-10-29 21:45:12 +00:00
|
|
|
state_machine_v4( hash_info, tvb, offset, pinfo);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
else if ( hash_info->version == 5)
|
2001-10-29 21:45:12 +00:00
|
|
|
state_machine_v5( hash_info, tvb, offset, pinfo);
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
if (hash_info->state == Done) { /* if done now */
|
2001-10-29 21:45:12 +00:00
|
|
|
hash_info->start_done_row = pinfo->fd->num;
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
/* if proto tree, decode and display */
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
if (tree) {
|
2002-01-24 09:20:54 +00:00
|
|
|
ti = proto_tree_add_item( tree, proto_socks, tvb, offset, -1,
|
|
|
|
FALSE );
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
socks_tree = proto_item_add_subtree(ti, ett_socks);
|
|
|
|
|
|
|
|
if ( hash_info->version == 4)
|
2002-04-11 09:38:03 +00:00
|
|
|
display_socks_v4(tvb, offset, pinfo, socks_tree,
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
else if ( hash_info->version == 5)
|
2002-04-11 09:38:03 +00:00
|
|
|
display_socks_v5(tvb, offset, pinfo, socks_tree,
|
2000-04-12 22:53:16 +00:00
|
|
|
hash_info);
|
|
|
|
|
|
|
|
/* if past startup, add the faked stuff */
|
2001-10-29 21:45:12 +00:00
|
|
|
if ( pinfo->fd->num > hash_info->start_done_row){
|
2000-04-12 22:53:16 +00:00
|
|
|
/* add info to tree */
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_text( socks_tree, tvb, offset, 0,
|
2000-04-12 22:53:16 +00:00
|
|
|
"Command: %d (%s)", hash_info->command,
|
|
|
|
get_command_name(hash_info->command));
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_ipv4( socks_tree, hf_socks_ip_dst, tvb,
|
2000-04-12 22:53:16 +00:00
|
|
|
offset, 0, hash_info->dst_addr);
|
|
|
|
|
|
|
|
/* no fake address for ping & traceroute */
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
if (( hash_info->command != PING_COMMAND) &&
|
|
|
|
( hash_info->command != TRACERT_COMMAND)){
|
2001-10-29 21:45:12 +00:00
|
|
|
proto_tree_add_uint( socks_tree, hf_socks_dstport, tvb,
|
2000-04-12 22:53:16 +00:00
|
|
|
offset, 0, hash_info->port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* call next dissector if ready */
|
|
|
|
|
2001-10-29 21:45:12 +00:00
|
|
|
if ( pinfo->fd->num > hash_info->start_done_row){
|
2003-12-30 00:03:48 +00:00
|
|
|
call_next_dissector(tvb, offset, pinfo, tree, socks_tree,
|
|
|
|
hash_info);
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_socks( void){
|
|
|
|
|
|
|
|
/*** Prep the socks protocol, register it and a initialization routine */
|
|
|
|
/* to clear the hash stuff. */
|
|
|
|
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_socks,
|
|
|
|
&ett_socks_auth,
|
|
|
|
&ett_socks_name
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static hf_register_info hf[] = {
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
{ &hf_socks_ver,
|
2001-12-11 21:35:01 +00:00
|
|
|
{ "Version", "socks.version", FT_UINT8, BASE_DEC, NULL,
|
2004-02-12 20:47:27 +00:00
|
|
|
0x0, "", HFILL
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{ &hf_socks_ip_dst,
|
|
|
|
{ "Remote Address", "socks.dst", FT_IPv4, BASE_NONE, NULL,
|
2004-02-12 20:47:27 +00:00
|
|
|
0x0, "", HFILL
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{ &hf_socks_ip6_dst,
|
2001-12-11 21:35:01 +00:00
|
|
|
{ "Remote Address(ipv6)", "socks.dstV6", FT_IPv6, BASE_NONE, NULL,
|
2004-02-12 20:47:27 +00:00
|
|
|
0x0, "", HFILL
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_user_name,
|
2004-06-03 08:04:07 +00:00
|
|
|
{ "User Name", "socks.username", FT_STRINGZ, BASE_NONE,
|
2001-06-18 02:18:27 +00:00
|
|
|
NULL, 0x0, "", HFILL
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
},
|
2004-06-03 08:04:07 +00:00
|
|
|
{ &hf_v4a_dns_name,
|
|
|
|
{ "SOCKS v4a Remote Domain Name", "socks.v4a_dns_name", FT_STRINGZ, BASE_NONE,
|
|
|
|
NULL, 0x0, "", HFILL
|
|
|
|
}
|
|
|
|
},
|
2000-04-12 22:53:16 +00:00
|
|
|
{ &hf_socks_dstport,
|
|
|
|
{ "Remote Port", "socks.dstport", FT_UINT16,
|
2001-06-18 02:18:27 +00:00
|
|
|
BASE_DEC, NULL, 0x0, "", HFILL
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
},
|
2001-12-11 21:35:01 +00:00
|
|
|
{ &hf_socks_cmd,
|
2002-03-09 22:54:27 +00:00
|
|
|
{ "Command", "socks.command", FT_UINT8,
|
2001-12-11 21:35:01 +00:00
|
|
|
BASE_DEC, VALS(cmd_strings), 0x0, "", HFILL
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ &hf_socks_results_4,
|
|
|
|
{ "Results(V4)", "socks.results_v4", FT_UINT8,
|
|
|
|
BASE_DEC, VALS(reply_table_v4), 0x0, "", HFILL
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ &hf_socks_results_5,
|
|
|
|
{ "Results(V5)", "socks.results_v5", FT_UINT8,
|
|
|
|
BASE_DEC, VALS(reply_table_v5), 0x0, "", HFILL
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ &hf_socks_results,
|
|
|
|
{ "Results(V5)", "socks.results", FT_UINT8,
|
2001-06-18 02:18:27 +00:00
|
|
|
BASE_DEC, NULL, 0x0, "", HFILL
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
proto_socks = proto_register_protocol (
|
2002-08-28 21:04:11 +00:00
|
|
|
"Socks Protocol", "Socks", "socks");
|
2000-04-12 22:53:16 +00:00
|
|
|
|
|
|
|
proto_register_field_array(proto_socks, hf, array_length(hf));
|
2002-08-28 21:04:11 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2001-11-27 07:13:32 +00:00
|
|
|
socks_udp_handle = create_dissector_handle(socks_udp_dissector,
|
|
|
|
proto_socks);
|
|
|
|
socks_handle = create_dissector_handle(dissect_socks, proto_socks);
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_socks(void) {
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
/* dissector install routine */
|
|
|
|
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_add("tcp.port", TCP_PORT_SOCKS, socks_handle);
|
2000-04-12 22:53:16 +00:00
|
|
|
}
|