2006-07-13 08:42:34 +00:00
|
|
|
/* packet-kismet.c
|
|
|
|
* Routines for kismet packet dissection
|
|
|
|
* Copyright 2006, Krzysztof Burghardt <krzysztof@burghardt.pl>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-pop.c
|
|
|
|
*
|
|
|
|
* 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.
|
2006-07-13 08:42:34 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2006-07-13 08:42:34 +00:00
|
|
|
|
2009-08-26 19:27:49 +00:00
|
|
|
#include <stdlib.h>
|
2006-07-13 08:42:34 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/packet.h>
|
2013-12-21 17:23:17 +00:00
|
|
|
#include <epan/to_str.h>
|
2006-07-13 08:42:34 +00:00
|
|
|
#include <epan/strutil.h>
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
|
|
|
|
static int proto_kismet = -1;
|
|
|
|
static int hf_kismet_response = -1;
|
|
|
|
static int hf_kismet_request = -1;
|
2014-09-26 23:28:01 +00:00
|
|
|
static int hf_kismet_version = -1;
|
|
|
|
static int hf_kismet_start_time = -1;
|
|
|
|
static int hf_kismet_server_name = -1;
|
|
|
|
static int hf_kismet_build_revision = -1;
|
|
|
|
static int hf_kismet_unknown_field = -1;
|
|
|
|
static int hf_kismet_extended_version_string = -1;
|
|
|
|
static int hf_kismet_time = -1;
|
2006-07-13 08:42:34 +00:00
|
|
|
|
|
|
|
static gint ett_kismet = -1;
|
|
|
|
static gint ett_kismet_reqresp = -1;
|
|
|
|
|
|
|
|
static dissector_handle_t data_handle;
|
|
|
|
|
|
|
|
#define TCP_PORT_KISMET 2501
|
|
|
|
|
|
|
|
static guint global_kismet_tcp_port = TCP_PORT_KISMET;
|
|
|
|
|
2006-07-14 07:55:53 +00:00
|
|
|
static gboolean response_is_continuation(const guchar * data);
|
|
|
|
void proto_reg_handoff_kismet(void);
|
|
|
|
void proto_register_kismet(void);
|
2006-07-13 08:42:34 +00:00
|
|
|
|
2014-07-04 15:46:56 +00:00
|
|
|
static int
|
2012-09-10 21:40:21 +00:00
|
|
|
dissect_kismet(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data _U_)
|
2006-07-13 08:42:34 +00:00
|
|
|
{
|
2006-07-14 07:55:53 +00:00
|
|
|
gboolean is_request;
|
|
|
|
gboolean is_continuation;
|
|
|
|
proto_tree *kismet_tree=NULL, *reqresp_tree=NULL;
|
|
|
|
proto_item *ti;
|
|
|
|
proto_item *tmp_item;
|
|
|
|
gint offset = 0;
|
|
|
|
const guchar *line;
|
|
|
|
gint next_offset;
|
|
|
|
int linelen;
|
|
|
|
int tokenlen;
|
|
|
|
int i;
|
|
|
|
const guchar *next_token;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the end of the first line.
|
|
|
|
*
|
|
|
|
* Note that "tvb_find_line_end()" will return a value that is
|
|
|
|
* not longer than what's in the buffer, so the "tvb_get_ptr()"
|
|
|
|
* call won't throw an exception.
|
|
|
|
*/
|
|
|
|
linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
|
|
|
|
line = tvb_get_ptr(tvb, offset, linelen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if it is an ASCII based protocol with reasonable length
|
|
|
|
* packets, if not return, and try annother dissector.
|
|
|
|
*/
|
|
|
|
if (linelen < 8) {
|
|
|
|
/*
|
|
|
|
* Packet is too short
|
|
|
|
*/
|
2014-07-04 15:46:56 +00:00
|
|
|
return 0;
|
2006-07-14 07:55:53 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
/*
|
|
|
|
* Packet contains non-ASCII data
|
|
|
|
*/
|
|
|
|
if (line[i] < 32 || line[i] > 128)
|
2014-07-04 15:46:56 +00:00
|
|
|
return 0;
|
2006-07-14 07:55:53 +00:00
|
|
|
}
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
2006-07-14 07:55:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If it is Kismet traffic set COL_PROTOCOL.
|
|
|
|
*/
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "kismet");
|
2006-07-14 07:55:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if it is request, reply or continuation.
|
|
|
|
*/
|
2010-12-20 05:35:29 +00:00
|
|
|
if (pinfo->match_uint == pinfo->destport) {
|
2006-07-14 07:55:53 +00:00
|
|
|
is_request = TRUE;
|
|
|
|
is_continuation = FALSE;
|
|
|
|
} else {
|
|
|
|
is_request = FALSE;
|
|
|
|
is_continuation = response_is_continuation (line);
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 01:02:11 +00:00
|
|
|
/*
|
|
|
|
* Put the first line from the buffer into the summary
|
|
|
|
* if it's a kismet request or reply (but leave out the
|
|
|
|
* line terminator).
|
|
|
|
* Otherwise, just call it a continuation.
|
|
|
|
*/
|
|
|
|
if (is_continuation)
|
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
|
|
|
|
else
|
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
|
2006-07-14 07:55:53 +00:00
|
|
|
is_request ? "Request" : "Response",
|
|
|
|
format_text(line, linelen));
|
|
|
|
|
|
|
|
if (tree) {
|
2011-10-21 02:10:19 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_kismet, tvb, offset, -1, ENC_NA);
|
2006-07-14 07:55:53 +00:00
|
|
|
kismet_tree = proto_item_add_subtree(ti, ett_kismet);
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
2006-07-14 07:55:53 +00:00
|
|
|
|
|
|
|
if (is_continuation) {
|
|
|
|
/*
|
|
|
|
* Put the whole packet into the tree as data.
|
|
|
|
*/
|
|
|
|
call_dissector(data_handle, tvb, pinfo, kismet_tree);
|
2014-07-04 15:46:56 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2006-07-14 07:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_request) {
|
|
|
|
tmp_item = proto_tree_add_boolean(kismet_tree,
|
|
|
|
hf_kismet_request, tvb, 0, 0, TRUE);
|
|
|
|
} else {
|
|
|
|
tmp_item = proto_tree_add_boolean(kismet_tree,
|
|
|
|
hf_kismet_response, tvb, 0, 0, TRUE);
|
|
|
|
}
|
|
|
|
PROTO_ITEM_SET_GENERATED (tmp_item);
|
|
|
|
|
|
|
|
while (tvb_offset_exists(tvb, offset)) {
|
|
|
|
/*
|
|
|
|
* Find the end of the line.
|
|
|
|
*/
|
|
|
|
linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
|
|
|
|
|
|
|
|
if (linelen) {
|
2006-07-13 08:42:34 +00:00
|
|
|
/*
|
2006-07-14 07:55:53 +00:00
|
|
|
* Put this line.
|
2006-07-13 08:42:34 +00:00
|
|
|
*/
|
2014-06-29 21:00:12 +00:00
|
|
|
reqresp_tree = proto_tree_add_subtree(kismet_tree, tvb, offset,
|
|
|
|
next_offset - offset, ett_kismet_reqresp, NULL,
|
2006-07-14 07:55:53 +00:00
|
|
|
tvb_format_text(tvb, offset,
|
|
|
|
next_offset - offset - 1));
|
|
|
|
tokenlen = get_token_len(line, line + linelen, &next_token);
|
|
|
|
if (tokenlen != 0) {
|
|
|
|
guint8 *reqresp;
|
2014-06-17 15:30:58 +00:00
|
|
|
reqresp = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, tokenlen, ENC_ASCII);
|
2006-07-14 07:55:53 +00:00
|
|
|
if (is_request) {
|
|
|
|
/*
|
|
|
|
* No request dissection
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* *KISMET: {Version} {Start time} \001{Server name}\001 {Build Revision}
|
|
|
|
* two fields left undocumented: {???} {?ExtendedVersion?}
|
|
|
|
*/
|
2007-03-28 21:55:11 +00:00
|
|
|
if (!strncmp(reqresp, "*KISMET", 7)) {
|
2009-04-06 00:08:46 +00:00
|
|
|
offset += (gint) (next_token - line);
|
|
|
|
linelen -= (int) (next_token - line);
|
2006-07-14 07:55:53 +00:00
|
|
|
line = next_token;
|
|
|
|
tokenlen = get_token_len(line, line + linelen, &next_token);
|
2014-09-26 23:28:01 +00:00
|
|
|
proto_tree_add_string(reqresp_tree, hf_kismet_version, tvb, offset,
|
|
|
|
tokenlen, format_text(line, tokenlen));
|
2006-07-14 07:55:53 +00:00
|
|
|
|
2009-04-06 00:08:46 +00:00
|
|
|
offset += (gint) (next_token - line);
|
|
|
|
linelen -= (int) (next_token - line);
|
2006-07-14 07:55:53 +00:00
|
|
|
line = next_token;
|
|
|
|
tokenlen = get_token_len(line, line + linelen, &next_token);
|
2014-09-26 23:28:01 +00:00
|
|
|
proto_tree_add_string(reqresp_tree, hf_kismet_start_time, tvb, offset,
|
|
|
|
tokenlen, format_text(line, tokenlen));
|
2006-07-14 07:55:53 +00:00
|
|
|
|
2009-04-06 00:08:46 +00:00
|
|
|
offset += (gint) (next_token - line);
|
|
|
|
linelen -= (int) (next_token - line);
|
2006-07-14 07:55:53 +00:00
|
|
|
line = next_token;
|
|
|
|
tokenlen = get_token_len(line, line + linelen, &next_token);
|
2014-09-26 23:28:01 +00:00
|
|
|
proto_tree_add_string(reqresp_tree, hf_kismet_server_name, tvb, offset,
|
|
|
|
tokenlen, format_text(line + 1, tokenlen - 2));
|
2006-07-14 07:55:53 +00:00
|
|
|
|
2009-04-06 00:08:46 +00:00
|
|
|
offset += (gint) (next_token - line);
|
|
|
|
linelen -= (int) (next_token - line);
|
2006-07-14 07:55:53 +00:00
|
|
|
line = next_token;
|
|
|
|
tokenlen = get_token_len(line, line + linelen, &next_token);
|
2014-09-26 23:28:01 +00:00
|
|
|
proto_tree_add_string(reqresp_tree, hf_kismet_build_revision, tvb, offset,
|
|
|
|
tokenlen, format_text(line, tokenlen));
|
2006-07-14 07:55:53 +00:00
|
|
|
|
2009-04-06 00:08:46 +00:00
|
|
|
offset += (gint) (next_token - line);
|
|
|
|
linelen -= (int) (next_token - line);
|
2006-07-14 07:55:53 +00:00
|
|
|
line = next_token;
|
|
|
|
tokenlen = get_token_len(line, line + linelen, &next_token);
|
2014-09-26 23:28:01 +00:00
|
|
|
proto_tree_add_string(reqresp_tree, hf_kismet_unknown_field, tvb, offset,
|
|
|
|
tokenlen, format_text(line, tokenlen));
|
2006-07-14 07:55:53 +00:00
|
|
|
|
2009-04-06 00:08:46 +00:00
|
|
|
offset += (gint) (next_token - line);
|
|
|
|
linelen -= (int) (next_token - line);
|
2006-07-14 07:55:53 +00:00
|
|
|
line = next_token;
|
|
|
|
tokenlen = get_token_len(line, line + linelen, &next_token);
|
2014-09-26 23:28:01 +00:00
|
|
|
proto_tree_add_string(reqresp_tree, hf_kismet_extended_version_string, tvb, offset,
|
|
|
|
tokenlen, format_text(line, tokenlen));
|
2006-07-14 07:55:53 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* *TIME: {Time}
|
|
|
|
*/
|
2007-03-28 21:55:11 +00:00
|
|
|
if (!strncmp(reqresp, "*TIME", 5)) {
|
2014-09-26 23:28:01 +00:00
|
|
|
nstime_t t;
|
2006-07-14 07:55:53 +00:00
|
|
|
char *ptr;
|
|
|
|
|
2009-04-06 00:08:46 +00:00
|
|
|
offset += (gint) (next_token - line);
|
|
|
|
linelen -= (int) (next_token - line);
|
2006-07-14 07:55:53 +00:00
|
|
|
line = next_token;
|
|
|
|
tokenlen = get_token_len(line, line + linelen, &next_token);
|
|
|
|
|
2014-09-26 23:28:01 +00:00
|
|
|
/* Convert form ascii to nstime */
|
|
|
|
t.secs = atoi(format_text (line, tokenlen));
|
|
|
|
t.nsecs = 0;
|
2006-07-14 07:55:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Format ascii representaion of time
|
|
|
|
*/
|
2014-09-26 23:28:01 +00:00
|
|
|
ptr = abs_time_secs_to_str(wmem_packet_scope(), t.secs, ABSOLUTE_TIME_LOCAL, TRUE);
|
|
|
|
proto_tree_add_time_format_value(reqresp_tree, hf_kismet_time, tvb, offset, tokenlen, &t, "%s", ptr);
|
2006-07-14 07:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-29 21:59:53 +00:00
|
|
|
/*offset += (gint) (next_token - line);
|
|
|
|
linelen -= (int) (next_token - line);*/
|
2006-07-14 07:55:53 +00:00
|
|
|
line = next_token;
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-14 07:55:53 +00:00
|
|
|
offset = next_offset;
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
2011-10-21 02:10:19 +00:00
|
|
|
|
2014-07-04 15:46:56 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2006-07-14 07:55:53 +00:00
|
|
|
response_is_continuation(const guchar * data)
|
2006-07-13 08:42:34 +00:00
|
|
|
{
|
2007-03-28 21:55:11 +00:00
|
|
|
if (!strncmp(data, "*", 1))
|
2006-07-14 07:55:53 +00:00
|
|
|
return FALSE;
|
2006-07-13 08:42:34 +00:00
|
|
|
|
2007-03-28 21:55:11 +00:00
|
|
|
if (!strncmp(data, "!", 1))
|
2006-07-14 07:55:53 +00:00
|
|
|
return FALSE;
|
2006-07-13 08:42:34 +00:00
|
|
|
|
2006-07-14 07:55:53 +00:00
|
|
|
return TRUE;
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-07-14 07:55:53 +00:00
|
|
|
proto_register_kismet(void)
|
2006-07-13 08:42:34 +00:00
|
|
|
{
|
2006-07-14 07:55:53 +00:00
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{&hf_kismet_response,
|
2011-10-21 02:10:19 +00:00
|
|
|
{"Response", "kismet.response", FT_BOOLEAN, BASE_NONE,
|
2006-07-14 07:55:53 +00:00
|
|
|
NULL, 0x0, "TRUE if kismet response", HFILL}},
|
|
|
|
|
|
|
|
{&hf_kismet_request,
|
2011-10-21 02:10:19 +00:00
|
|
|
{"Request", "kismet.request", FT_BOOLEAN, BASE_NONE,
|
2014-09-26 23:28:01 +00:00
|
|
|
NULL, 0x0, "TRUE if kismet request", HFILL}},
|
|
|
|
|
|
|
|
{&hf_kismet_version,
|
|
|
|
{"Version", "kismet.version", FT_STRING, BASE_NONE,
|
|
|
|
NULL, 0x0, NULL, HFILL}},
|
|
|
|
|
|
|
|
{&hf_kismet_start_time,
|
|
|
|
{"Start time", "kismet.start_time", FT_STRING, BASE_NONE,
|
|
|
|
NULL, 0x0, NULL, HFILL}},
|
|
|
|
|
|
|
|
{&hf_kismet_server_name,
|
|
|
|
{"Server name", "kismet.server_name", FT_STRING, BASE_NONE,
|
|
|
|
NULL, 0x0, NULL, HFILL}},
|
|
|
|
|
|
|
|
{&hf_kismet_build_revision,
|
|
|
|
{"Build revision", "kismet.build_revision", FT_STRING, BASE_NONE,
|
|
|
|
NULL, 0x0, NULL, HFILL}},
|
|
|
|
|
|
|
|
{&hf_kismet_unknown_field,
|
|
|
|
{"Unknown field", "kismet.unknown_field", FT_STRING, BASE_NONE,
|
|
|
|
NULL, 0x0, NULL, HFILL}},
|
|
|
|
|
|
|
|
{&hf_kismet_extended_version_string,
|
|
|
|
{"Extended version string", "kismet.extended_version_string", FT_STRING, BASE_NONE,
|
|
|
|
NULL, 0x0, NULL, HFILL}},
|
|
|
|
|
|
|
|
{&hf_kismet_time,
|
|
|
|
{"Time", "kismet.time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
|
|
|
|
NULL, 0x0, NULL, HFILL}},
|
2006-07-14 07:55:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_kismet,
|
|
|
|
&ett_kismet_reqresp,
|
|
|
|
};
|
|
|
|
module_t *kismet_module;
|
|
|
|
|
|
|
|
proto_kismet = proto_register_protocol("Kismet Client/Server Protocol", "Kismet", "kismet");
|
|
|
|
proto_register_field_array(proto_kismet, hf, array_length (hf));
|
|
|
|
proto_register_subtree_array(ett, array_length (ett));
|
|
|
|
|
|
|
|
/* Register our configuration options for Kismet, particularly our port */
|
|
|
|
|
|
|
|
kismet_module = prefs_register_protocol(proto_kismet, proto_reg_handoff_kismet);
|
|
|
|
|
|
|
|
prefs_register_uint_preference(kismet_module, "tcp.port",
|
|
|
|
"Kismet Server TCP Port",
|
|
|
|
"Set the port for Kismet Client/Server messages (if other"
|
|
|
|
" than the default of 2501)", 10,
|
|
|
|
&global_kismet_tcp_port);
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-07-14 07:55:53 +00:00
|
|
|
proto_reg_handoff_kismet(void)
|
2006-07-13 08:42:34 +00:00
|
|
|
{
|
2008-09-03 16:42:35 +00:00
|
|
|
static gboolean kismet_prefs_initialized = FALSE;
|
2006-07-14 07:55:53 +00:00
|
|
|
static dissector_handle_t kismet_handle;
|
2008-09-03 16:42:35 +00:00
|
|
|
static guint tcp_port;
|
2006-07-14 07:55:53 +00:00
|
|
|
|
|
|
|
if (!kismet_prefs_initialized) {
|
|
|
|
kismet_handle = new_create_dissector_handle(dissect_kismet, proto_kismet);
|
2008-09-03 16:42:35 +00:00
|
|
|
data_handle = find_dissector("data");
|
2006-07-14 07:55:53 +00:00
|
|
|
kismet_prefs_initialized = TRUE;
|
|
|
|
} else {
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_delete_uint("tcp.port", tcp_port, kismet_handle);
|
2006-07-14 07:55:53 +00:00
|
|
|
}
|
2006-07-13 08:42:34 +00:00
|
|
|
|
2006-07-14 07:55:53 +00:00
|
|
|
/* Set our port number for future use */
|
|
|
|
tcp_port = global_kismet_tcp_port;
|
2006-07-13 08:42:34 +00:00
|
|
|
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("tcp.port", global_kismet_tcp_port, kismet_handle);
|
2006-07-13 08:42:34 +00:00
|
|
|
}
|
2014-07-04 15:46:56 +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:
|
|
|
|
*/
|