2010-04-04 20:30:33 +00:00
|
|
|
/* packet-git.c
|
|
|
|
* Routines for git packet dissection
|
|
|
|
* Copyright 2010, Jelmer Vernooij <jelmer@samba.org>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-pop.c
|
|
|
|
*
|
2018-02-12 11:23:27 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2010-04-04 20:30:33 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2010-04-04 20:30:33 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
2021-02-24 00:44:40 +00:00
|
|
|
#include <epan/expert.h>
|
2010-04-04 20:30:33 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include "packet-tcp.h"
|
|
|
|
|
2013-12-14 12:45:57 +00:00
|
|
|
void proto_register_git(void);
|
|
|
|
void proto_reg_handoff_git(void);
|
|
|
|
|
2013-11-16 01:10:05 +00:00
|
|
|
static dissector_handle_t git_handle;
|
|
|
|
|
2010-04-04 20:30:33 +00:00
|
|
|
static int proto_git = -1;
|
2021-02-24 00:44:40 +00:00
|
|
|
static expert_field ei_git_bad_pkt_len = EI_INIT;
|
2021-01-28 20:15:03 +00:00
|
|
|
static expert_field ei_git_malformed = EI_INIT;
|
2010-04-04 20:30:33 +00:00
|
|
|
|
|
|
|
static gint ett_git = -1;
|
|
|
|
|
2021-01-08 00:47:06 +00:00
|
|
|
static gint hf_git_protocol_version = -1;
|
2021-02-03 01:45:35 +00:00
|
|
|
static gint hf_git_packet_type = -1;
|
2010-04-04 20:30:33 +00:00
|
|
|
static gint hf_git_packet_len = -1;
|
|
|
|
static gint hf_git_packet_data = -1;
|
2020-12-09 22:46:04 +00:00
|
|
|
static gint hf_git_sideband_control_code = -1;
|
2021-01-28 20:15:03 +00:00
|
|
|
static gint hf_git_upload_pack_adv = -1;
|
|
|
|
static gint hf_git_upload_pack_req = -1;
|
|
|
|
static gint hf_git_upload_pack_res = -1;
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2015-09-16 20:51:08 +00:00
|
|
|
#define PNAME "Git Smart Protocol"
|
|
|
|
#define PSNAME "Git"
|
|
|
|
#define PFNAME "git"
|
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
#define TCP_PORT_GIT 9418
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2021-02-03 01:45:35 +00:00
|
|
|
static const value_string packet_type_vals[] = {
|
|
|
|
{ 0, "Flush" },
|
|
|
|
{ 1, "Delimiter" },
|
|
|
|
{ 2, "Response end" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2021-01-08 00:47:06 +00:00
|
|
|
static const value_string version_vals[] = {
|
|
|
|
{ '1', "Git protocol version 1" },
|
|
|
|
{ '2', "Git protocol version 2" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2020-12-09 22:46:04 +00:00
|
|
|
#define SIDEBAND_PACKFILE_DATA 0x01
|
|
|
|
#define SIDEBAND_PROGRESS_INFO 0x02
|
|
|
|
#define SIDEBAND_ERROR_INFO 0x03
|
|
|
|
static const value_string sideband_vals[] = {
|
|
|
|
{ SIDEBAND_PACKFILE_DATA, "Git packfile data" },
|
|
|
|
{ SIDEBAND_PROGRESS_INFO, "Git progress data" },
|
|
|
|
{ SIDEBAND_ERROR_INFO, "Git error data" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2010-04-04 20:30:33 +00:00
|
|
|
/* desegmentation of Git over TCP */
|
|
|
|
static gboolean git_desegment = TRUE;
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
static gboolean get_packet_length(tvbuff_t *tvb, int offset,
|
2014-09-30 23:12:26 +00:00
|
|
|
guint16 *length)
|
2010-04-04 20:30:33 +00:00
|
|
|
{
|
2014-09-30 23:12:26 +00:00
|
|
|
guint8 *lenstr;
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
lenstr = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 4, ENC_ASCII);
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
return (sscanf(lenstr, "%hx", length) == 1);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
2015-01-25 19:30:13 +00:00
|
|
|
get_git_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
|
2010-04-04 20:30:33 +00:00
|
|
|
{
|
2014-09-30 23:12:26 +00:00
|
|
|
guint16 plen;
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
if (!get_packet_length(tvb, offset, &plen))
|
|
|
|
return 0; /* No idea what this is */
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2021-02-24 00:44:40 +00:00
|
|
|
return plen < 4
|
|
|
|
? 4 // Special packet (e.g., flush-pkt)
|
|
|
|
: plen;
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 01:39:56 +00:00
|
|
|
/* Parse pkt-lines one-by-one
|
|
|
|
*
|
|
|
|
* @param tvb The buffer to dissect.
|
2021-02-24 00:44:40 +00:00
|
|
|
* @param pinfo Packet info associated to this buffer.
|
2021-02-10 01:39:56 +00:00
|
|
|
* @param git_tree The git protocol subtree.
|
|
|
|
* @param offset The offset at which to start the dissection.
|
|
|
|
* @return bool After successful/unsuccessful parsing.
|
|
|
|
*
|
|
|
|
* This new helper takes the contents of the tvbuffer, updates the
|
|
|
|
* offset, and returns to the caller for subsequent processing of the
|
|
|
|
* remainder of the data.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2021-02-24 00:44:40 +00:00
|
|
|
dissect_pkt_line(tvbuff_t *tvb, packet_info *pinfo, proto_tree *git_tree,
|
|
|
|
int *offset)
|
2010-04-04 20:30:33 +00:00
|
|
|
{
|
|
|
|
guint16 plen;
|
|
|
|
|
2021-02-03 01:45:35 +00:00
|
|
|
// what type of pkt-line is it?
|
2021-02-23 19:58:44 +00:00
|
|
|
if (!get_packet_length(tvb, *offset, &plen))
|
2021-02-10 01:39:56 +00:00
|
|
|
return FALSE;
|
2021-02-24 00:44:40 +00:00
|
|
|
if (plen < 4) { // a special packet (e.g., flush-pkt)
|
|
|
|
proto_item *ti =
|
|
|
|
proto_tree_add_uint(git_tree, hf_git_packet_type, tvb,
|
|
|
|
*offset, 4, plen);
|
2021-02-10 01:39:56 +00:00
|
|
|
*offset += 4;
|
2021-02-24 00:44:40 +00:00
|
|
|
|
|
|
|
if (!try_val_to_str(plen, packet_type_vals))
|
|
|
|
expert_add_info(pinfo, ti, &ei_git_bad_pkt_len);
|
2021-02-10 01:39:56 +00:00
|
|
|
return TRUE;
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 01:39:56 +00:00
|
|
|
proto_tree_add_uint(git_tree, hf_git_packet_len, tvb, *offset, 4, plen);
|
|
|
|
*offset += 4;
|
2020-12-09 22:46:04 +00:00
|
|
|
plen -= 4;
|
|
|
|
|
2021-01-08 00:47:06 +00:00
|
|
|
/*
|
|
|
|
* Parse out the version of the Git Protocol
|
|
|
|
*
|
|
|
|
* The initial server response contains the version of the Git Protocol in use;
|
|
|
|
* 1 or 2. Parsing out this information helps identify the capabilities and
|
|
|
|
* information that can be used with the protocol.
|
|
|
|
*/
|
2021-02-10 01:39:56 +00:00
|
|
|
if (plen >= 9 && !tvb_strneql(tvb, *offset, "version ", 8)) {
|
|
|
|
proto_tree_add_item(git_tree, hf_git_protocol_version, tvb, *offset + 8,
|
2021-01-08 00:47:06 +00:00
|
|
|
1, ENC_NA);
|
|
|
|
}
|
|
|
|
|
2020-12-09 22:46:04 +00:00
|
|
|
/*
|
|
|
|
* Parse out the sideband control code.
|
|
|
|
*
|
|
|
|
* Not all pkt-lines have a sideband control code. With more context from the rest of
|
|
|
|
* the request or response, we would be able to tell whether sideband is expected here;
|
|
|
|
* lacking that, let's assume for now that all pkt-lines starting with \1, \2, or \3
|
|
|
|
* are using sideband.
|
|
|
|
*/
|
2021-02-10 01:39:56 +00:00
|
|
|
int sideband_code = tvb_get_guint8(tvb, *offset);
|
2020-12-09 22:46:04 +00:00
|
|
|
|
|
|
|
if (1 <= sideband_code && sideband_code <= 3) {
|
2021-02-10 01:39:56 +00:00
|
|
|
proto_tree_add_uint(git_tree, hf_git_sideband_control_code, tvb, *offset, 1,
|
2020-12-09 22:46:04 +00:00
|
|
|
sideband_code);
|
2021-02-10 01:39:56 +00:00
|
|
|
(*offset)++;
|
2020-12-09 22:46:04 +00:00
|
|
|
plen--;
|
2013-11-09 17:46:28 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 01:39:56 +00:00
|
|
|
proto_tree_add_item(git_tree, hf_git_packet_data, tvb, *offset, plen, ENC_NA);
|
|
|
|
*offset += plen;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_git_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
|
|
|
|
{
|
|
|
|
proto_tree *git_tree;
|
|
|
|
proto_item *ti;
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, PSNAME);
|
|
|
|
|
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, PNAME);
|
|
|
|
|
|
|
|
ti = proto_tree_add_item(tree, proto_git, tvb, offset, -1, ENC_NA);
|
|
|
|
git_tree = proto_item_add_subtree(ti, ett_git);
|
|
|
|
|
2021-02-24 00:44:40 +00:00
|
|
|
if (!dissect_pkt_line(tvb, pinfo, git_tree, &offset))
|
2021-02-10 01:39:56 +00:00
|
|
|
return 0;
|
2020-12-09 22:46:04 +00:00
|
|
|
|
2015-06-23 18:13:21 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:15:03 +00:00
|
|
|
/* Parse http packs
|
|
|
|
*
|
|
|
|
* @param tvb The buffer to dissect.
|
|
|
|
* @param pinfo The Packet Info.
|
|
|
|
* @param tree The protocol tree.
|
|
|
|
* @param hfindex The type of http pack.
|
|
|
|
* @return tvb_length The amount of captured data in the buffer,
|
|
|
|
* returns 0 if parsing failed.
|
|
|
|
*
|
|
|
|
* This new helper takes the contents of the tvbuffer sent by http
|
|
|
|
* dissectors, adds the packs to the git subtree and returns the amount
|
|
|
|
* of consumed bytes in the tvb buffer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
dissect_http_pkt_lines(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int hfindex)
|
|
|
|
{
|
|
|
|
proto_tree *git_tree;
|
|
|
|
proto_item *ti;
|
|
|
|
int offset = 0;
|
|
|
|
int total_len = 0;
|
|
|
|
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, PSNAME);
|
|
|
|
|
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, PNAME);
|
|
|
|
|
|
|
|
ti = proto_tree_add_item(tree, proto_git, tvb, offset, -1, ENC_NA);
|
|
|
|
git_tree = proto_item_add_subtree(ti, ett_git);
|
|
|
|
|
|
|
|
proto_tree_add_item(git_tree, hfindex, tvb, offset,
|
|
|
|
tvb_captured_length(tvb), ENC_NA);
|
|
|
|
|
|
|
|
total_len = tvb_reported_length(tvb);
|
|
|
|
while (offset < total_len) {
|
|
|
|
/* Add expert info if there is trouble parsing part-way through */
|
|
|
|
if (!dissect_pkt_line(tvb, pinfo, git_tree, &offset)) {
|
|
|
|
proto_tree_add_expert(git_tree, pinfo, &ei_git_malformed, tvb, offset, -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tvb_captured_length(tvb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_git_upload_pack_adv(tvbuff_t *tvb, packet_info *pinfo,
|
|
|
|
proto_tree *tree, void *data _U_)
|
|
|
|
{
|
|
|
|
return dissect_http_pkt_lines(tvb, pinfo, tree, hf_git_upload_pack_adv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_git_upload_pack_req(tvbuff_t *tvb, packet_info *pinfo,
|
|
|
|
proto_tree *tree, void *data _U_)
|
|
|
|
{
|
|
|
|
return dissect_http_pkt_lines(tvb, pinfo, tree, hf_git_upload_pack_req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_git_upload_pack_res(tvbuff_t *tvb, packet_info *pinfo,
|
|
|
|
proto_tree *tree, void *data _U_)
|
|
|
|
{
|
|
|
|
return dissect_http_pkt_lines(tvb, pinfo, tree, hf_git_upload_pack_res);
|
|
|
|
}
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
static int
|
|
|
|
dissect_git(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
|
2010-04-04 20:30:33 +00:00
|
|
|
{
|
2014-09-30 23:12:26 +00:00
|
|
|
tcp_dissect_pdus(tvb, pinfo, tree, git_desegment, 4, get_git_pdu_len,
|
|
|
|
dissect_git_pdu, data);
|
2015-06-23 18:13:21 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_git(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
2021-01-08 00:47:06 +00:00
|
|
|
{ &hf_git_protocol_version,
|
|
|
|
{ "Git Protocol Version", "git.version", FT_UINT8, BASE_NONE, VALS(version_vals),
|
|
|
|
0, NULL, HFILL },
|
|
|
|
},
|
2021-02-03 01:45:35 +00:00
|
|
|
{ &hf_git_packet_type,
|
|
|
|
{ "Git Packet Type", "git.packet_type", FT_UINT8, BASE_NONE, VALS(packet_type_vals),
|
|
|
|
0, NULL, HFILL },
|
|
|
|
},
|
2014-09-30 23:12:26 +00:00
|
|
|
{ &hf_git_packet_len,
|
|
|
|
{ "Packet length", "git.length", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
|
|
|
|
},
|
|
|
|
{ &hf_git_packet_data,
|
|
|
|
{ "Packet data", "git.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
|
|
|
|
},
|
2020-12-09 22:46:04 +00:00
|
|
|
{ &hf_git_sideband_control_code,
|
|
|
|
{ "Sideband control code", "git.sideband_control_code", FT_UINT8,
|
|
|
|
BASE_HEX, VALS(sideband_vals), 0, NULL, HFILL },
|
|
|
|
},
|
2021-01-28 20:15:03 +00:00
|
|
|
{ &hf_git_upload_pack_adv,
|
|
|
|
{ "Upload Pack Advertisement", "git.upload_pack_advertisement",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
|
|
|
|
},
|
|
|
|
{ &hf_git_upload_pack_req,
|
|
|
|
{ "Upload Pack Request", "git.upload_pack_request",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
|
|
|
|
},
|
|
|
|
{ &hf_git_upload_pack_res,
|
|
|
|
{ "Upload Pack Result", "git.upload_pack_result",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
|
|
|
|
},
|
2010-04-04 20:30:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_git,
|
|
|
|
};
|
|
|
|
|
2021-02-24 00:44:40 +00:00
|
|
|
static ei_register_info ei[] = {
|
|
|
|
{ &ei_git_bad_pkt_len,
|
|
|
|
{ "git.bad_pkt_len", PI_PROTOCOL, PI_ERROR,
|
|
|
|
"unrecognized special pkt-len value", EXPFILL }
|
2021-01-28 20:15:03 +00:00
|
|
|
},
|
|
|
|
{ &ei_git_malformed,
|
|
|
|
{ "git.malformed", PI_MALFORMED, PI_ERROR,
|
|
|
|
"malformed packet", EXPFILL }
|
|
|
|
},
|
2021-02-24 00:44:40 +00:00
|
|
|
};
|
|
|
|
|
2010-04-04 20:30:33 +00:00
|
|
|
module_t *git_module;
|
2021-02-24 00:44:40 +00:00
|
|
|
expert_module_t *expert_git;
|
2013-11-16 01:10:05 +00:00
|
|
|
|
2015-09-16 20:51:08 +00:00
|
|
|
proto_git = proto_register_protocol(PNAME, PSNAME, PFNAME);
|
2010-04-04 20:30:33 +00:00
|
|
|
proto_register_field_array(proto_git, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
|
2021-02-24 00:44:40 +00:00
|
|
|
expert_git = expert_register_protocol(proto_git);
|
|
|
|
expert_register_field_array(expert_git, ei, array_length(ei));
|
|
|
|
|
2015-12-09 04:04:01 +00:00
|
|
|
git_handle = register_dissector(PFNAME, dissect_git, proto_git);
|
2013-11-16 01:10:05 +00:00
|
|
|
|
2010-04-04 20:30:33 +00:00
|
|
|
git_module = prefs_register_protocol(proto_git, NULL);
|
|
|
|
|
|
|
|
prefs_register_bool_preference(git_module, "desegment",
|
2014-09-30 23:12:26 +00:00
|
|
|
"Reassemble GIT messages spanning multiple TCP segments",
|
|
|
|
"Whether the GIT dissector should reassemble messages spanning multiple TCP segments."
|
|
|
|
" To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
|
|
|
|
&git_desegment);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_git(void)
|
|
|
|
{
|
2021-01-28 20:15:03 +00:00
|
|
|
/*
|
|
|
|
* Add the dissectors for GIT over HTTP
|
|
|
|
*
|
|
|
|
* Reference documentation at
|
|
|
|
* https://www.kernel.org/pub/software/scm/git/docs//technical/http-protocol.txt
|
|
|
|
*/
|
|
|
|
dissector_handle_t git_upload_pack_adv_handle;
|
|
|
|
dissector_handle_t git_upload_pack_req_handle;
|
|
|
|
dissector_handle_t git_upload_pack_res_handle;
|
|
|
|
|
|
|
|
git_upload_pack_adv_handle = create_dissector_handle(dissect_git_upload_pack_adv,
|
|
|
|
proto_git);
|
|
|
|
|
|
|
|
git_upload_pack_req_handle = create_dissector_handle(dissect_git_upload_pack_req,
|
|
|
|
proto_git);
|
|
|
|
|
|
|
|
git_upload_pack_res_handle = create_dissector_handle(dissect_git_upload_pack_res,
|
|
|
|
proto_git);
|
|
|
|
|
|
|
|
dissector_add_string("media_type",
|
|
|
|
"application/x-git-upload-pack-advertisement",
|
|
|
|
git_upload_pack_adv_handle);
|
|
|
|
dissector_add_string("media_type",
|
|
|
|
"application/x-git-upload-pack-request",
|
|
|
|
git_upload_pack_req_handle);
|
|
|
|
dissector_add_string("media_type",
|
|
|
|
"application/x-git-upload-pack-result",
|
|
|
|
git_upload_pack_res_handle);
|
|
|
|
|
2016-10-07 20:25:01 +00:00
|
|
|
dissector_add_uint_with_preference("tcp.port", TCP_PORT_GIT, git_handle);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
2014-09-30 23:12:26 +00:00
|
|
|
|
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2014-09-30 23:12:26 +00:00
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=2 tabstop=8 expandtab:
|
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|