http: Add dissection of HTTP2-Settings

Closes #17370
This commit is contained in:
Anders Broman 2021-05-07 17:29:33 +02:00 committed by AndersBroman
parent 1dc5579366
commit 71e6b0498a
7 changed files with 212 additions and 5 deletions

View File

@ -340,6 +340,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
dissect_h225_RasMessage@Base 1.9.1
dissect_h225_ReleaseCompleteReason@Base 1.9.1
dissect_h245_H223Capability@Base 1.9.1
dissect_http2_settings_ext@Base 3.5.0
dissect_isup_called_party_number_parameter@Base 1.9.1
dissect_isup_calling_geodetic_location_parameter@Base 3.1.0
dissect_isup_calling_party_number_parameter@Base 1.9.1

View File

@ -33,8 +33,11 @@
#include <epan/req_resp_hdrs.h>
#include <epan/proto_data.h>
#include <epan/export_object.h>
#include <epan/exceptions.h>
#include <epan/show_exception.h>
#include "packet-http.h"
#include "packet-http2.h"
#include "packet-tcp.h"
#include "packet-tls.h"
#include "packet-acdr.h"
@ -112,6 +115,7 @@ static int hf_http_sec_websocket_version = -1;
static int hf_http_set_cookie = -1;
static int hf_http_last_modified = -1;
static int hf_http_x_forwarded_for = -1;
static int hf_http_http2_settings = -1;
static int hf_http_request_in = -1;
static int hf_http_response_in = -1;
static int hf_http_next_request_in = -1;
@ -124,6 +128,7 @@ static int hf_http_chunk_boundary = -1;
static int hf_http_chunked_trailer_part = -1;
static int hf_http_file_data = -1;
static int hf_http_unknown_header = -1;
static int hf_http_http2_settings_uri = -1;
static gint ett_http = -1;
static gint ett_http_ntlmssp = -1;
@ -135,6 +140,7 @@ static gint ett_http_chunked_response = -1;
static gint ett_http_chunk_data = -1;
static gint ett_http_encoded_entity = -1;
static gint ett_http_header_item = -1;
static gint ett_http_http2_settings_item = -1;
static expert_field ei_http_chat = EI_INIT;
static expert_field ei_http_te_and_length = EI_INIT;
@ -2778,6 +2784,7 @@ typedef struct {
#define HDR_WEBSOCKET_EXTENSIONS 11
#define HDR_REFERER 12
#define HDR_LOCATION 13
#define HDR_HTTP2_SETTINGS 14
static const header_info headers[] = {
{ "Authorization", &hf_http_authorization, HDR_AUTHORIZATION },
@ -2809,6 +2816,7 @@ static const header_info headers[] = {
{ "Set-Cookie", &hf_http_set_cookie, HDR_NO_SPECIAL },
{ "Last-Modified", &hf_http_last_modified, HDR_NO_SPECIAL },
{ "X-Forwarded-For", &hf_http_x_forwarded_for, HDR_NO_SPECIAL },
{ "HTTP2-Settings", &hf_http_http2_settings, HDR_HTTP2_SETTINGS },
};
/*
@ -3334,10 +3342,24 @@ process_header(tvbuff_t *tvb, int offset, int next_offset,
case HDR_LOCATION:
if (conv_data->request_uri){
stat_info->location_target = wmem_strndup(wmem_packet_scope(), value, value_len);
stat_info->location_target = wmem_strndup(wmem_packet_scope(), value, value_offset);
stat_info->location_base_uri = wmem_strdup(wmem_packet_scope(), conv_data->full_uri);
}
break;
case HDR_HTTP2_SETTINGS:
{
proto_tree* settings_tree = proto_item_add_subtree(hdr_item, ett_http_http2_settings_item);
tvbuff_t* new_tvb = base64uri_tvb_to_new_tvb(tvb, value_offset, value_len);
add_new_data_source(pinfo, new_tvb, "Base64uri decoded");
TRY{
dissect_http2_settings_ext(new_tvb, pinfo, settings_tree, 0);
} CATCH_ALL{
show_exception(tvb, pinfo, settings_tree, EXCEPT_CODE, GET_MESSAGE);
}
ENDTRY;
break;
}
}
}
}
@ -4047,6 +4069,10 @@ proto_register_http(void)
{ "X-Forwarded-For", "http.x_forwarded_for",
FT_STRING, BASE_NONE, NULL, 0x0,
"HTTP X-Forwarded-For", HFILL }},
{ &hf_http_http2_settings,
{ "HTTP2-Settings", "http.http2_settings",
FT_STRING, BASE_NONE, NULL, 0x0,
NULL, HFILL }},
{ &hf_http_request_in,
{ "Request in frame", "http.request_in",
FT_FRAMENUM, BASE_NONE, FRAMENUM_TYPE(FT_FRAMENUM_REQUEST), 0,
@ -4095,6 +4121,10 @@ proto_register_http(void)
{ "Unknown header", "http.unknown_header",
FT_STRING, BASE_NONE, NULL, 0,
NULL, HFILL }},
{ &hf_http_http2_settings_uri,
{ "HTTP2 Settings URI", "http.http2_settings_uri",
FT_BYTES, BASE_NONE, NULL, 0,
NULL, HFILL }},
};
static gint *ett[] = {
&ett_http,
@ -4106,7 +4136,8 @@ proto_register_http(void)
&ett_http_chunked_response,
&ett_http_chunk_data,
&ett_http_encoded_entity,
&ett_http_header_item
&ett_http_header_item,
&ett_http_http2_settings_item
};
static ei_register_info ei[] = {

View File

@ -3050,9 +3050,9 @@ dissect_http2_rst_stream(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *http
/* Settings */
static int
#ifdef HAVE_NGHTTP2
dissect_http2_settings(tvbuff_t *tvb, packet_info *pinfo _U_, http2_session_t* h2session, proto_tree *http2_tree, guint offset, guint8 flags)
dissect_http2_settings(tvbuff_t* tvb, packet_info* pinfo _U_, http2_session_t* h2session, proto_tree* http2_tree, guint offset, guint8 flags)
#else
dissect_http2_settings(tvbuff_t *tvb, packet_info *pinfo _U_, http2_session_t* h2session _U_, proto_tree *http2_tree, guint offset, guint8 flags _U_)
dissect_http2_settings(tvbuff_t* tvb, packet_info* pinfo _U_, http2_session_t* h2session _U_, proto_tree* http2_tree, guint offset, guint8 flags _U_)
#endif
{
guint32 settingsid;
@ -3116,7 +3116,7 @@ dissect_http2_settings(tvbuff_t *tvb, packet_info *pinfo _U_, http2_session_t* h
}
#ifdef HAVE_NGHTTP2
if(!PINFO_FD_VISITED(pinfo)) {
if(!PINFO_FD_VISITED(pinfo)&&(h2session != NULL)) {
if(flags & HTTP2_FLAGS_ACK) {
apply_and_pop_settings(pinfo, h2session);
@ -3137,6 +3137,11 @@ dissect_http2_settings(tvbuff_t *tvb, packet_info *pinfo _U_, http2_session_t* h
return offset;
}
void
dissect_http2_settings_ext(tvbuff_t* tvb, packet_info* pinfo _U_, proto_tree* http2_tree, guint offset) {
dissect_http2_settings(tvb, pinfo, NULL, http2_tree, offset, 0);
}
/* Push Promise */
static int
#ifdef HAVE_NGHTTP2

View File

@ -50,6 +50,9 @@ http2_get_stream_id_le(guint streamid, guint sub_stream_id, guint *sub_stream_id
WS_DLL_PUBLIC gboolean
http2_get_stream_id_ge(guint streamid, guint sub_stream_id, guint *sub_stream_id_out);
WS_DLL_PUBLIC void
dissect_http2_settings_ext(tvbuff_t* tvb, packet_info* pinfo _U_, proto_tree* http2_tree, guint offset);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -1103,6 +1103,7 @@ extern tvbuff_t* base64_to_tvb(tvbuff_t *parent, const char *base64);
*/
extern tvbuff_t* base64_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length);
extern tvbuff_t* base64uri_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length);
/**
* Extract a variable length integer from a tvbuff.
* Each byte in a varint, except the last byte, has the most significant bit (msb)

View File

@ -15,6 +15,156 @@
#include <epan/tvbuff.h>
#include "proto.h"
/* Copy of glib function modified for base64uri */
static const unsigned char mime_base64uri_rank[256] = {
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255, 255,255,63,255,255,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255, 0,255,255,
255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255, 63,
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
};
/**
* Copy of glib function modified for base64uri
* g_base64uri_decode_step: (skip)
* @in: (array length=len) (element-type guint8): binary input data
* @len: max length of @in data to decode
* @out: (out caller-allocates) (array) (element-type guint8): output buffer
* @state: (inout): Saved state between steps, initialize to 0
* @save: (inout): Saved state between steps, initialize to 0
*
* Incrementally decode a sequence of binary data from its Base-64 stringified
* representation. By calling this function multiple times you can convert
* data in chunks to avoid having to have the full encoded data in memory.
*
* The output buffer must be large enough to fit all the data that will
* be written to it. Since base64 encodes 3 bytes in 4 chars you need
* at least: (@len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero
* state).
*
* Returns: The number of bytes of output that was written
*
* Since: 2.12
**/
static gsize
g_base64uri_decode_step(const gchar* in,
gsize len,
guchar* out,
gint* state,
guint* save)
{
const guchar* inptr;
guchar* outptr;
const guchar* inend;
guchar c, rank;
guchar last[2];
unsigned int v;
int i;
g_return_val_if_fail(in != NULL || len == 0, 0);
g_return_val_if_fail(out != NULL, 0);
g_return_val_if_fail(state != NULL, 0);
g_return_val_if_fail(save != NULL, 0);
if (len == 0)
return 0;
inend = (const guchar*)in + len;
outptr = out;
/* convert 4 base64 bytes to 3 normal bytes */
v = *save;
i = *state;
last[0] = last[1] = 0;
/* we use the sign in the state to determine if we got a padding character
in the previous sequence */
if (i < 0)
{
i = -i;
last[0] = '=';
}
inptr = (const guchar*)in;
while (inptr < inend)
{
c = *inptr++;
rank = mime_base64uri_rank[c];
if (rank != 0xff)
{
last[1] = last[0];
last[0] = c;
v = (v << 6) | rank;
i++;
if (i == 4)
{
*outptr++ = v >> 16;
if (last[1] != '=')
*outptr++ = v >> 8;
if (last[0] != '=')
*outptr++ = v;
i = 0;
}
}
}
*save = v;
*state = last[0] == '=' ? -i : i;
return outptr - out;
}
/**
* Copy of glib function modified for base64uri
* g_base64uri_decode:
* @text: (not nullable): zero-terminated string with base64 text to decode
* @out_len: (out): The length of the decoded data is written here
*
* Decode a sequence of Base-64 encoded text into binary data. Note
* that the returned binary data is not necessarily zero-terminated,
* so it should not be used as a character string.
*
* Returns: (transfer full) (array length=out_len) (element-type guint8):
* newly allocated buffer containing the binary data
* that @text represents. The returned buffer must
* be freed with g_free().
*
* Since: 2.12
*/
static guchar*
g_base64uri_decode(const gchar* text,
gsize* out_len)
{
guchar* ret;
gsize input_length;
gint state = 0;
guint save = 0;
g_return_val_if_fail(text != NULL, NULL);
g_return_val_if_fail(out_len != NULL, NULL);
input_length = strlen(text);
/* We can use a smaller limit here, since we know the saved state is 0,
+1 used to avoid calling g_malloc0(0), and hence returning NULL */
ret = (guchar * )g_malloc0((input_length / 4) * 3 + 1);
*out_len = g_base64uri_decode_step(text, input_length, ret, &state, &save);
return ret;
}
tvbuff_t *
base64_to_tvb(tvbuff_t *parent, const char *base64)
{
@ -44,6 +194,21 @@ base64_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length)
return tvb;
}
tvbuff_t*
base64uri_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length)
{
tvbuff_t* tvb;
char* data;
gsize len = 0;
data = g_base64uri_decode(tvb_get_string_enc(wmem_packet_scope(), parent, offset, length, ENC_ASCII), &len);
tvb = tvb_new_child_real_data(parent, (const guint8*)data, (gint)len, (gint)len);
tvb_set_free_cb(tvb, g_free);
return tvb;
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*

View File

@ -24,3 +24,4 @@ tools/lemon/*
wsutil/file_util.h
wsutil/strptime.c
wsutil/getopt_long.c
epan/dissectors/packet-http.c