2007-02-14 13:22:55 +00:00
|
|
|
/*
|
|
|
|
* Routines for the disassembly of the proprietary Cisco IPSEC in
|
|
|
|
* TCP encapsulation protocol
|
|
|
|
*
|
|
|
|
* 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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-02-14 13:22:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* - Find out the meaning of the (unknown) trailer
|
|
|
|
* - UDP checksum is wrong
|
|
|
|
* - Currently doesn't handle AH (lack of sample trace)
|
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2007-02-14 13:22:55 +00:00
|
|
|
|
|
|
|
#include <epan/packet.h>
|
2007-09-28 07:34:42 +00:00
|
|
|
#include "packet-ndmp.h"
|
2007-02-14 13:22:55 +00:00
|
|
|
|
2013-12-15 23:44:12 +00:00
|
|
|
void proto_register_tcpencap(void);
|
|
|
|
void proto_reg_handoff_tcpencap(void);
|
|
|
|
|
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 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
|
|
|
|
|
|
|
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
|
2012-09-10 21:40:21 +00:00
|
|
|
dissect_tcpencap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
|
2007-02-14 13:22:55 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
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 */
|
2017-01-10 06:18:49 +00:00
|
|
|
next_tvb = tvb_new_subset_length_caplen(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
|
|
|
|
2015-06-23 18:24:48 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2007-02-14 13:22:55 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 04:39:32 +00:00
|
|
|
static gboolean
|
|
|
|
dissect_tcpencap_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
|
|
|
|
{
|
|
|
|
guint32 reported_length = tvb_reported_length(tvb);
|
2015-06-24 04:30:15 +00:00
|
|
|
guint32 captured_length = tvb_captured_length(tvb);
|
2013-08-07 04:39:32 +00:00
|
|
|
|
|
|
|
if (reported_length <= TRAILERLENGTH + 8 ||
|
2013-11-09 21:30:33 +00:00
|
|
|
/* Ensure we have enough bytes for packet_is_tcpencap analysis */
|
2015-06-24 04:30:15 +00:00
|
|
|
(reported_length - captured_length) > (TRAILERLENGTH - 13) ||
|
2013-08-07 04:39:32 +00:00
|
|
|
!packet_is_tcpencap(tvb, pinfo, reported_length - TRAILERLENGTH) ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dissect_tcpencap(tvb, pinfo, tree, data);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2016-10-07 20:25:01 +00:00
|
|
|
proto_tcpencap = proto_register_protocol("TCP Encapsulation of IPsec Packets", "TCPENCAP", "tcpencap");
|
2007-02-14 13:22:55 +00:00
|
|
|
|
|
|
|
proto_register_field_array(proto_tcpencap, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:45:25 +00:00
|
|
|
void
|
|
|
|
proto_reg_handoff_tcpencap(void)
|
|
|
|
{
|
2016-10-07 20:25:01 +00:00
|
|
|
dissector_handle_t tcpencap_handle;
|
2009-07-27 14:45:25 +00:00
|
|
|
|
2016-10-07 20:25:01 +00:00
|
|
|
tcpencap_handle = create_dissector_handle(dissect_tcpencap, proto_tcpencap);
|
|
|
|
esp_handle = find_dissector_add_dependency("esp", proto_tcpencap);
|
|
|
|
udp_handle = find_dissector_add_dependency("udp", proto_tcpencap);
|
2013-08-07 04:39:32 +00:00
|
|
|
|
2016-10-07 20:25:01 +00:00
|
|
|
heur_dissector_add("tcp", dissect_tcpencap_heur, "TCP Encapsulation of IPsec Packets", "ipsec_tcp", proto_tcpencap, HEURISTIC_ENABLE);
|
2013-08-07 04:39:32 +00:00
|
|
|
|
|
|
|
/* Register TCP port for dissection */
|
2016-10-07 20:25:01 +00:00
|
|
|
dissector_add_for_decode_as_with_preference("tcp.port", tcpencap_handle);
|
2009-07-27 14:45:25 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 20:59:17 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|