2013-06-17 07:35:30 +00:00
|
|
|
/* packet-http-urlencoded.c
|
|
|
|
* Routines for dissection of HTTP urlecncoded form, based on packet-text-media.c (C) Olivier Biot, 2004.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-08-17 08:59:19 +00:00
|
|
|
#define NEW_PROTO_TREE_API
|
|
|
|
|
2013-06-17 07:35:30 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
2014-01-08 00:28:13 +00:00
|
|
|
#include <wsutil/str_util.h>
|
2013-06-17 07:35:30 +00:00
|
|
|
|
2013-12-15 23:44:12 +00:00
|
|
|
void proto_register_http_urlencoded(void);
|
|
|
|
void proto_reg_handoff_http_urlencoded(void);
|
|
|
|
|
2013-08-17 08:59:19 +00:00
|
|
|
static dissector_handle_t form_urlencoded_handle;
|
|
|
|
|
|
|
|
static header_field_info *hfi_urlencoded = NULL;
|
|
|
|
|
|
|
|
#define URLENCODED_HFI_INIT HFI_INIT(proto_urlencoded)
|
|
|
|
|
|
|
|
static header_field_info hfi_form_key URLENCODED_HFI_INIT =
|
|
|
|
{ "Key", "urlencoded-form.key", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL };
|
|
|
|
|
|
|
|
static header_field_info hfi_form_value URLENCODED_HFI_INIT =
|
|
|
|
{ "Value", "urlencoded-form.value", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL };
|
2013-06-17 07:35:30 +00:00
|
|
|
|
|
|
|
static gint ett_form_urlencoded = -1;
|
|
|
|
static gint ett_form_keyvalue = -1;
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_form_key_value(tvbuff_t *tvb, char **ptr, int offset, char stop)
|
|
|
|
{
|
|
|
|
const int orig_offset = offset;
|
|
|
|
char *tmp;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
while (tvb_reported_length_remaining(tvb, offset) > 0) {
|
|
|
|
guint8 ch;
|
|
|
|
|
|
|
|
ch = tvb_get_guint8(tvb, offset);
|
|
|
|
if (!ch)
|
|
|
|
return -1;
|
|
|
|
if (ch == stop)
|
|
|
|
break;
|
|
|
|
if (ch == '%') {
|
|
|
|
offset++;
|
|
|
|
ch = tvb_get_guint8(tvb, offset);
|
2014-01-08 00:28:13 +00:00
|
|
|
if (ws_xton(ch) == -1)
|
2013-06-17 07:35:30 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
offset++;
|
|
|
|
ch = tvb_get_guint8(tvb, offset);
|
2014-01-08 00:28:13 +00:00
|
|
|
if (ws_xton(ch) == -1)
|
2013-06-17 07:35:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
len++;
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
2013-06-17 14:18:23 +00:00
|
|
|
*ptr = tmp = (char*)wmem_alloc(wmem_packet_scope(), len + 1);
|
2013-06-17 07:35:30 +00:00
|
|
|
tmp[len] = '\0';
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
offset = orig_offset;
|
|
|
|
while (tvb_reported_length_remaining(tvb, offset) > 0) {
|
|
|
|
guint8 ch;
|
|
|
|
|
|
|
|
ch = tvb_get_guint8(tvb, offset);
|
|
|
|
if (!ch)
|
|
|
|
return -1;
|
|
|
|
if (ch == stop)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ch == '%') {
|
|
|
|
guint8 ch1, ch2;
|
2013-10-13 19:56:52 +00:00
|
|
|
|
2013-06-17 07:35:30 +00:00
|
|
|
offset++;
|
|
|
|
ch1 = tvb_get_guint8(tvb, offset);
|
|
|
|
|
|
|
|
offset++;
|
|
|
|
ch2 = tvb_get_guint8(tvb, offset);
|
|
|
|
|
2014-01-08 00:28:13 +00:00
|
|
|
tmp[len] = ws_xton(ch1) << 4 | ws_xton(ch2);
|
2013-06-17 07:35:30 +00:00
|
|
|
|
|
|
|
} else if (ch == '+')
|
|
|
|
tmp[len] = ' ';
|
2013-10-13 19:56:52 +00:00
|
|
|
else
|
2013-06-17 07:35:30 +00:00
|
|
|
tmp[len] = ch;
|
|
|
|
|
|
|
|
len++;
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-02 13:05:58 +00:00
|
|
|
static int
|
|
|
|
dissect_form_urlencoded(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
|
2013-06-17 07:35:30 +00:00
|
|
|
{
|
|
|
|
proto_tree *url_tree;
|
|
|
|
proto_tree *sub;
|
|
|
|
proto_item *ti;
|
|
|
|
gint offset = 0, next_offset;
|
|
|
|
const char *data_name;
|
|
|
|
|
|
|
|
data_name = pinfo->match_string;
|
|
|
|
if (! (data_name && data_name[0])) {
|
|
|
|
/*
|
|
|
|
* No information from "match_string"
|
|
|
|
*/
|
2013-11-02 13:05:58 +00:00
|
|
|
data_name = (char *)data;
|
2013-06-17 07:35:30 +00:00
|
|
|
if (! (data_name && data_name[0])) {
|
|
|
|
/*
|
2013-11-02 13:05:58 +00:00
|
|
|
* No information from dissector data
|
2013-06-17 07:35:30 +00:00
|
|
|
*/
|
2014-11-23 00:24:06 +00:00
|
|
|
data_name = NULL;
|
2013-06-17 07:35:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data_name)
|
|
|
|
col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "(%s)", data_name);
|
|
|
|
|
2013-08-17 08:59:19 +00:00
|
|
|
ti = proto_tree_add_item(tree, hfi_urlencoded, tvb, 0, -1, ENC_NA);
|
2013-06-17 07:35:30 +00:00
|
|
|
if (data_name)
|
|
|
|
proto_item_append_text(ti, ": %s", data_name);
|
|
|
|
url_tree = proto_item_add_subtree(ti, ett_form_urlencoded);
|
|
|
|
|
|
|
|
while (tvb_reported_length_remaining(tvb, offset) > 0) {
|
|
|
|
const int start_offset = offset;
|
|
|
|
char *key, *value;
|
|
|
|
|
2016-02-21 19:24:11 +00:00
|
|
|
sub = proto_tree_add_subtree(url_tree, tvb, offset, 0, ett_form_keyvalue, &ti, "Form item");
|
2013-06-17 07:35:30 +00:00
|
|
|
|
|
|
|
next_offset = get_form_key_value(tvb, &key, offset, '=');
|
|
|
|
if (next_offset == -1)
|
|
|
|
break;
|
2013-08-17 08:59:19 +00:00
|
|
|
proto_tree_add_string(sub, &hfi_form_key, tvb, offset, next_offset - offset, key);
|
2013-06-17 07:35:30 +00:00
|
|
|
proto_item_append_text(sub, ": \"%s\"", key);
|
|
|
|
|
|
|
|
offset = next_offset+1;
|
|
|
|
|
|
|
|
next_offset = get_form_key_value(tvb, &value, offset, '&');
|
|
|
|
if (next_offset == -1)
|
|
|
|
break;
|
2013-08-17 08:59:19 +00:00
|
|
|
proto_tree_add_string(sub, &hfi_form_value, tvb, offset, next_offset - offset, value);
|
2013-06-17 07:35:30 +00:00
|
|
|
proto_item_append_text(sub, " = \"%s\"", value);
|
|
|
|
|
|
|
|
offset = next_offset+1;
|
|
|
|
|
|
|
|
proto_item_set_len(ti, offset - start_offset);
|
|
|
|
}
|
2013-11-02 13:05:58 +00:00
|
|
|
|
2015-06-23 18:24:48 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2013-06-17 07:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_http_urlencoded(void)
|
|
|
|
{
|
2013-11-07 20:14:18 +00:00
|
|
|
#ifndef HAVE_HFI_SECTION_INIT
|
2013-08-17 08:59:19 +00:00
|
|
|
static header_field_info *hfi[] = {
|
|
|
|
&hfi_form_key,
|
|
|
|
&hfi_form_value,
|
2013-06-17 07:35:30 +00:00
|
|
|
};
|
2013-11-07 20:14:18 +00:00
|
|
|
#endif
|
2013-06-17 07:35:30 +00:00
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_form_urlencoded,
|
|
|
|
&ett_form_keyvalue
|
|
|
|
};
|
|
|
|
|
2013-08-17 08:59:19 +00:00
|
|
|
int proto_urlencoded;
|
2013-06-17 07:35:30 +00:00
|
|
|
|
|
|
|
proto_urlencoded = proto_register_protocol("HTML Form URL Encoded", "URL Encoded Form Data", "urlencoded-form");
|
2013-08-17 08:59:19 +00:00
|
|
|
hfi_urlencoded = proto_registrar_get_nth(proto_urlencoded);
|
|
|
|
|
2015-12-09 04:04:01 +00:00
|
|
|
form_urlencoded_handle = register_dissector("urlencoded-form", dissect_form_urlencoded, proto_urlencoded);
|
2013-06-17 07:35:30 +00:00
|
|
|
|
2013-08-17 08:59:19 +00:00
|
|
|
proto_register_fields(proto_urlencoded, hfi, array_length(hfi));
|
2013-06-17 07:35:30 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_http_urlencoded(void)
|
|
|
|
{
|
|
|
|
dissector_add_string("media_type", "application/x-www-form-urlencoded", form_urlencoded_handle);
|
|
|
|
}
|
2013-06-17 14:18:23 +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:
|
|
|
|
*/
|