2007-02-14 13:22:55 +00:00
|
|
|
/*
|
|
|
|
* Routines for the disassembly of the proprietary Cisco IPSEC in
|
|
|
|
* TCP encapsulation protocol
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright 2007 Joerg Mayer (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* - Find out the meaning of the (unknown) trailer
|
|
|
|
* - UDP checksum is wrong
|
|
|
|
* - Currently doesn't handle AH (lack of sample trace)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/prefs.h>
|
2007-09-28 07:34:42 +00:00
|
|
|
#include "packet-ndmp.h"
|
2007-02-14 13:22:55 +00:00
|
|
|
|
|
|
|
static int hf_tcpencap_unknown = -1;
|
2007-02-15 08:40:18 +00:00
|
|
|
static int hf_tcpencap_zero = -1;
|
|
|
|
static int hf_tcpencap_seq = -1;
|
|
|
|
static int hf_tcpencap_ike_direction = -1;
|
|
|
|
static int hf_tcpencap_esp_zero = -1;
|
|
|
|
static int hf_tcpencap_magic = -1;
|
|
|
|
static int hf_tcpencap_proto = -1;
|
|
|
|
static int hf_tcpencap_magic2 = -1;
|
2007-02-14 13:22:55 +00:00
|
|
|
|
|
|
|
static int proto_tcpencap = -1;
|
|
|
|
static gint ett_tcpencap = -1;
|
2007-02-15 08:40:18 +00:00
|
|
|
static gint ett_tcpencap_unknown = -1;
|
|
|
|
|
|
|
|
static const value_string tcpencap_ikedir_vals[] = {
|
|
|
|
{ 0x0000, "Server to client" },
|
|
|
|
{ 0x4000, "Client to server" },
|
|
|
|
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string tcpencap_proto_vals[] = {
|
|
|
|
{ 0x11, "ISAKMP" },
|
|
|
|
{ 0x32, "ESP" },
|
|
|
|
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2007-02-14 13:22:55 +00:00
|
|
|
|
2010-07-05 23:21:58 +00:00
|
|
|
#define TRAILERLENGTH 16
|
2007-02-14 13:22:55 +00:00
|
|
|
#define TCP_CISCO_IPSEC 10000
|
|
|
|
static guint global_tcpencap_tcp_port = TCP_CISCO_IPSEC;
|
|
|
|
|
|
|
|
static dissector_handle_t esp_handle;
|
|
|
|
static dissector_handle_t udp_handle;
|
|
|
|
|
2007-02-15 08:40:18 +00:00
|
|
|
#define TCP_ENCAP_P_ESP 1
|
|
|
|
#define TCP_ENCAP_P_UDP 2
|
|
|
|
|
2007-09-28 07:34:42 +00:00
|
|
|
|
2010-07-05 23:21:58 +00:00
|
|
|
/* Another case of several companies creating protocols and
|
|
|
|
choosing an easy-to-remember port. Playing tonight: Cisco vs NDMP.
|
2007-09-28 07:34:42 +00:00
|
|
|
*/
|
|
|
|
static int
|
2010-07-05 23:21:58 +00:00
|
|
|
packet_is_tcpencap(tvbuff_t *tvb, packet_info *pinfo, guint32 offset)
|
2007-09-28 07:34:42 +00:00
|
|
|
{
|
2010-07-05 23:21:58 +00:00
|
|
|
if ( /* Must be zero */
|
|
|
|
tvb_get_ntohl(tvb, offset + 0) != 0 ||
|
|
|
|
/* Lower 12 bits must be zero */
|
|
|
|
(tvb_get_ntohs(tvb, offset + 6) & 0xfff) != 0 ||
|
|
|
|
/* Protocol must be UDP or ESP */
|
|
|
|
(tvb_get_guint8(tvb, offset + 13) != 17 &&
|
|
|
|
tvb_get_guint8(tvb, offset + 13) != 50)
|
|
|
|
) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-09-28 07:34:42 +00:00
|
|
|
if(check_if_ndmp(tvb, pinfo)){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-02-14 13:22:55 +00:00
|
|
|
/*
|
2011-10-21 02:10:19 +00:00
|
|
|
* TCP Encapsulation of IPsec Packets
|
2007-02-14 13:22:55 +00:00
|
|
|
* as supported by the cisco vpn3000 concentrator series
|
|
|
|
*/
|
2007-09-28 07:34:42 +00:00
|
|
|
static int
|
2007-02-14 13:22:55 +00:00
|
|
|
dissect_tcpencap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
proto_tree *tcpencap_tree = NULL;
|
2007-02-15 08:40:18 +00:00
|
|
|
proto_tree *tcpencap_unknown_tree = NULL;
|
|
|
|
|
|
|
|
proto_item *tree_item = NULL;
|
|
|
|
proto_item *unknown_item = NULL;
|
2007-02-14 13:22:55 +00:00
|
|
|
tvbuff_t *next_tvb;
|
|
|
|
guint32 reported_length = tvb_reported_length(tvb);
|
2007-02-15 08:40:18 +00:00
|
|
|
guint32 offset;
|
|
|
|
guint8 protocol;
|
2007-02-14 13:22:55 +00:00
|
|
|
|
2007-09-28 07:34:42 +00:00
|
|
|
/* verify that this looks like a tcpencap packet */
|
2010-07-05 23:21:58 +00:00
|
|
|
if (reported_length <= TRAILERLENGTH + 8 ||
|
|
|
|
!packet_is_tcpencap(tvb, pinfo, reported_length - TRAILERLENGTH) ) {
|
2007-09-28 07:34:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TCPENCAP");
|
2009-08-09 07:36:13 +00:00
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
2007-02-14 13:22:55 +00:00
|
|
|
|
|
|
|
/* If the first 4 bytes are 0x01f401f4 (udp src and dst port = 500)
|
|
|
|
we most likely have UDP (isakmp) traffic */
|
2011-10-21 02:10:19 +00:00
|
|
|
|
2007-02-15 08:40:18 +00:00
|
|
|
if (tvb_get_ntohl(tvb, 0) == 0x01f401f4) { /* UDP means ISAKMP */
|
|
|
|
protocol = TCP_ENCAP_P_UDP;
|
|
|
|
} else { /* Hopefully ESP */
|
|
|
|
protocol = TCP_ENCAP_P_ESP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tree) {
|
2011-10-21 02:10:19 +00:00
|
|
|
tree_item = proto_tree_add_item(tree, proto_tcpencap, tvb, 0, -1, ENC_NA);
|
2007-02-15 08:40:18 +00:00
|
|
|
tcpencap_tree = proto_item_add_subtree(tree_item, ett_tcpencap);
|
|
|
|
|
|
|
|
/* Dissect the trailer following the encapsulated IPSEC/ISAKMP packet */
|
2010-07-05 23:21:58 +00:00
|
|
|
offset = reported_length - TRAILERLENGTH;
|
2007-02-15 08:40:18 +00:00
|
|
|
unknown_item = proto_tree_add_item(tcpencap_tree, hf_tcpencap_unknown, tvb,
|
2011-10-04 22:44:31 +00:00
|
|
|
offset, TRAILERLENGTH, ENC_NA);
|
2007-02-15 08:40:18 +00:00
|
|
|
/* Try to guess the contents of the trailer */
|
|
|
|
tcpencap_unknown_tree = proto_item_add_subtree(unknown_item, ett_tcpencap_unknown);
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(tcpencap_unknown_tree, hf_tcpencap_zero, tvb, offset + 0, 4, ENC_NA);
|
2011-08-26 17:02:33 +00:00
|
|
|
proto_tree_add_item(tcpencap_unknown_tree, hf_tcpencap_seq, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
|
2007-02-15 08:40:18 +00:00
|
|
|
if (protocol == TCP_ENCAP_P_UDP) {
|
2011-08-26 17:02:33 +00:00
|
|
|
proto_tree_add_item(tcpencap_unknown_tree, hf_tcpencap_ike_direction, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
|
2007-02-15 08:40:18 +00:00
|
|
|
} else {
|
2011-08-26 17:02:33 +00:00
|
|
|
proto_tree_add_item(tcpencap_unknown_tree, hf_tcpencap_esp_zero, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
|
2007-02-15 08:40:18 +00:00
|
|
|
}
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(tcpencap_unknown_tree, hf_tcpencap_magic, tvb, offset + 8, 5, ENC_NA);
|
2011-08-26 17:02:33 +00:00
|
|
|
proto_tree_add_item(tcpencap_unknown_tree, hf_tcpencap_proto, tvb, offset + 13, 1, ENC_BIG_ENDIAN);
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(tcpencap_unknown_tree, hf_tcpencap_magic2, tvb, offset + 14, 2, ENC_NA);
|
2007-02-15 08:40:18 +00:00
|
|
|
}
|
|
|
|
|
2007-02-14 13:22:55 +00:00
|
|
|
/* Create the tvbuffer for the next dissector */
|
2010-07-05 23:21:58 +00:00
|
|
|
next_tvb = tvb_new_subset(tvb, 0, reported_length - TRAILERLENGTH , -1);
|
2007-02-15 08:40:18 +00:00
|
|
|
if (protocol == TCP_ENCAP_P_UDP) {
|
2007-02-14 13:22:55 +00:00
|
|
|
call_dissector(udp_handle, next_tvb, pinfo, tree);
|
|
|
|
} else { /* Hopefully ESP */
|
|
|
|
call_dissector(esp_handle, next_tvb, pinfo, tree);
|
|
|
|
}
|
2007-02-15 08:40:18 +00:00
|
|
|
|
2007-09-28 07:34:42 +00:00
|
|
|
return tvb_length(tvb);
|
2007-02-14 13:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_tcpencap(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
|
|
|
|
{ &hf_tcpencap_unknown,
|
2007-02-15 08:40:18 +00:00
|
|
|
{ "Unknown trailer", "tcpencap.unknown", FT_BYTES, BASE_NONE, NULL,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
0x0, NULL, HFILL }},
|
2007-02-15 08:40:18 +00:00
|
|
|
|
|
|
|
{ &hf_tcpencap_zero,
|
|
|
|
{ "All zero", "tcpencap.zero", FT_BYTES, BASE_NONE, NULL,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
0x0, NULL, HFILL }},
|
2007-02-15 08:40:18 +00:00
|
|
|
|
|
|
|
{ &hf_tcpencap_seq,
|
|
|
|
{ "Sequence number", "tcpencap.seq", FT_UINT16, BASE_HEX, NULL,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
0x0, NULL, HFILL }},
|
2007-02-15 08:40:18 +00:00
|
|
|
|
|
|
|
{ &hf_tcpencap_esp_zero,
|
|
|
|
{ "ESP zero", "tcpencap.espzero", FT_UINT16, BASE_HEX, NULL,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
0x0, NULL, HFILL }},
|
2007-02-15 08:40:18 +00:00
|
|
|
|
|
|
|
{ &hf_tcpencap_ike_direction,
|
|
|
|
{ "ISAKMP traffic direction", "tcpencap.ikedirection", FT_UINT16, BASE_HEX, VALS(tcpencap_ikedir_vals),
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
0x0, NULL, HFILL }},
|
2007-02-15 08:40:18 +00:00
|
|
|
|
|
|
|
{ &hf_tcpencap_magic,
|
|
|
|
{ "Magic number", "tcpencap.magic", FT_BYTES, BASE_NONE, NULL,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
0x0, NULL, HFILL }},
|
2007-02-15 08:40:18 +00:00
|
|
|
|
|
|
|
{ &hf_tcpencap_proto,
|
|
|
|
{ "Protocol", "tcpencap.proto", FT_UINT8, BASE_HEX, VALS(tcpencap_proto_vals),
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
0x0, NULL, HFILL }},
|
2007-02-15 08:40:18 +00:00
|
|
|
|
|
|
|
{ &hf_tcpencap_magic2,
|
|
|
|
{ "Magic 2", "tcpencap.magic2", FT_BYTES, BASE_NONE, NULL,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
0x0, NULL, HFILL }},
|
2007-02-15 08:40:18 +00:00
|
|
|
|
2007-02-14 13:22:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_tcpencap,
|
2007-02-15 08:40:18 +00:00
|
|
|
&ett_tcpencap_unknown,
|
2007-02-14 13:22:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module_t *tcpencap_module;
|
|
|
|
|
2009-07-27 14:45:25 +00:00
|
|
|
void proto_reg_handoff_tcpencap(void);
|
|
|
|
|
2007-02-14 13:22:55 +00:00
|
|
|
proto_tcpencap = proto_register_protocol(
|
|
|
|
"TCP Encapsulation of IPsec Packets", "TCPENCAP", "tcpencap");
|
|
|
|
proto_register_field_array(proto_tcpencap, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
tcpencap_module = prefs_register_protocol(proto_tcpencap, proto_reg_handoff_tcpencap);
|
|
|
|
prefs_register_uint_preference(tcpencap_module, "tcp.port", "IPSEC TCP Port",
|
|
|
|
"Set the port for IPSEC/ISAKMP messages"
|
|
|
|
"If other than the default of 10000)",
|
|
|
|
10, &global_tcpencap_tcp_port);
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:45:25 +00:00
|
|
|
void
|
|
|
|
proto_reg_handoff_tcpencap(void)
|
|
|
|
{
|
|
|
|
static dissector_handle_t tcpencap_handle;
|
|
|
|
static gboolean initialized = FALSE;
|
|
|
|
static guint tcpencap_tcp_port;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
tcpencap_handle = new_create_dissector_handle(dissect_tcpencap, proto_tcpencap);
|
|
|
|
esp_handle = find_dissector("esp");
|
|
|
|
udp_handle = find_dissector("udp");
|
|
|
|
initialized = TRUE;
|
|
|
|
} else {
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_delete_uint("tcp.port", tcpencap_tcp_port, tcpencap_handle);
|
2009-07-27 14:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tcpencap_tcp_port = global_tcpencap_tcp_port;
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("tcp.port", global_tcpencap_tcp_port, tcpencap_handle);
|
2009-07-27 14:45:25 +00:00
|
|
|
}
|
|
|
|
|