2013-11-14 21:04:05 +00:00
|
|
|
/* packet-whois.c
|
|
|
|
* Routines for whois dissection (see http://tools.ietf.org/html/rfc3912)
|
|
|
|
* Copyright 2013, Christopher Maynard <Christopher.Maynard@gtech.com>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-12 11:23:27 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2013-11-14 21:04:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/conversation.h>
|
|
|
|
#include <epan/expert.h>
|
|
|
|
|
|
|
|
#define WHOIS_PORT 43 /* This is the registered IANA port (nicname) */
|
|
|
|
|
2013-12-10 17:41:57 +00:00
|
|
|
void proto_register_whois(void);
|
2013-11-14 21:04:05 +00:00
|
|
|
void proto_reg_handoff_whois(void);
|
|
|
|
|
|
|
|
static int proto_whois = -1;
|
|
|
|
static int hf_whois_query = -1;
|
|
|
|
static int hf_whois_answer = -1;
|
|
|
|
static int hf_whois_answer_in = -1;
|
|
|
|
static int hf_whois_answer_to = -1;
|
|
|
|
static int hf_whois_response_time = -1;
|
|
|
|
|
|
|
|
static expert_field ei_whois_nocrlf = EI_INIT;
|
|
|
|
|
|
|
|
static gint ett_whois = -1;
|
|
|
|
|
|
|
|
typedef struct _whois_transaction_t {
|
2013-12-13 00:44:32 +00:00
|
|
|
guint32 req_frame;
|
|
|
|
guint32 rep_frame;
|
2013-11-14 21:04:05 +00:00
|
|
|
nstime_t req_time;
|
|
|
|
} whois_transaction_t;
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_whois(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
|
|
|
void *data _U_)
|
|
|
|
{
|
2013-12-13 00:44:32 +00:00
|
|
|
proto_item *ti, *expert_ti;
|
|
|
|
proto_tree *whois_tree;
|
|
|
|
conversation_t *conversation;
|
2013-11-14 21:04:05 +00:00
|
|
|
whois_transaction_t *whois_trans;
|
2013-12-13 00:44:32 +00:00
|
|
|
gboolean is_query;
|
|
|
|
guint len;
|
2013-11-14 21:04:05 +00:00
|
|
|
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "WHOIS");
|
|
|
|
|
|
|
|
if (pinfo->destport == WHOIS_PORT) {
|
|
|
|
is_query = TRUE;
|
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Query");
|
|
|
|
} else {
|
|
|
|
is_query = FALSE;
|
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Answer");
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation = find_or_create_conversation(pinfo);
|
2013-11-14 21:20:49 +00:00
|
|
|
whois_trans = (whois_transaction_t *)conversation_get_proto_data(conversation, proto_whois);
|
2013-11-14 21:04:05 +00:00
|
|
|
if (whois_trans == NULL) {
|
|
|
|
whois_trans = wmem_new0(wmem_file_scope(), whois_transaction_t);
|
|
|
|
conversation_add_proto_data(conversation, proto_whois, whois_trans);
|
|
|
|
}
|
|
|
|
|
2014-07-04 15:28:46 +00:00
|
|
|
len = tvb_reported_length(tvb);
|
2013-11-14 21:04:05 +00:00
|
|
|
if (!PINFO_FD_VISITED(pinfo)) {
|
|
|
|
if (pinfo->can_desegment) {
|
|
|
|
if (is_query) {
|
|
|
|
if ((len < 2) || (tvb_memeql(tvb, len - 2, "\r\n", 2))) {
|
|
|
|
pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
|
|
|
|
pinfo->desegment_offset = 0;
|
2014-07-04 15:28:46 +00:00
|
|
|
return -1;
|
2013-11-14 21:04:05 +00:00
|
|
|
} else {
|
2016-01-24 03:40:51 +00:00
|
|
|
whois_trans->req_frame = pinfo->num;
|
2016-01-23 03:50:21 +00:00
|
|
|
whois_trans->req_time = pinfo->abs_ts;
|
2013-11-14 21:04:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pinfo->desegment_len = DESEGMENT_UNTIL_FIN;
|
|
|
|
pinfo->desegment_offset = 0;
|
2014-07-04 15:28:46 +00:00
|
|
|
return -1;
|
2013-11-14 21:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (is_query && (whois_trans->req_frame == 0)) {
|
2016-01-24 03:40:51 +00:00
|
|
|
whois_trans->req_frame = pinfo->num;
|
2016-01-23 03:50:21 +00:00
|
|
|
whois_trans->req_time = pinfo->abs_ts;
|
2013-11-14 21:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_query && (whois_trans->rep_frame == 0)) {
|
|
|
|
/* By comparing whois_trans->rep_frame to 0, if reassembly is turned
|
|
|
|
* on, whois_trans->rep_frame will be assigned to the reassembled frame
|
|
|
|
* number, and if reassembly is turned off, whois_trans->rep_frame will
|
|
|
|
* be assigned to the first frame number of the response. This seems
|
|
|
|
* to match other protocols' behavior. The alternative is:
|
2016-01-24 03:40:51 +00:00
|
|
|
* if (pinfo->num > whois_trans->rep_frame)
|
2013-11-14 21:04:05 +00:00
|
|
|
* which will give us the same frame number either way.
|
|
|
|
*/
|
2016-01-24 03:40:51 +00:00
|
|
|
whois_trans->rep_frame = pinfo->num;
|
2013-11-14 21:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ti = proto_tree_add_protocol_format(tree, proto_whois, tvb, 0, -1,
|
|
|
|
"WHOIS: %s", is_query ? "Query" : "Answer");
|
|
|
|
whois_tree = proto_item_add_subtree(ti, ett_whois);
|
|
|
|
|
|
|
|
if (is_query) {
|
2014-04-06 14:57:33 +00:00
|
|
|
expert_ti = proto_tree_add_item(whois_tree, hf_whois_query, tvb, 0, -1, ENC_ASCII|ENC_NA);
|
2013-11-14 21:04:05 +00:00
|
|
|
if ((len < 2) || (tvb_memeql(tvb, len - 2, "\r\n", 2))) {
|
|
|
|
/*
|
|
|
|
* From RFC3912, section 2:
|
|
|
|
* All requests are terminated with ASCII CR and then ASCII LF.
|
|
|
|
*/
|
|
|
|
expert_add_info(pinfo, expert_ti, &ei_whois_nocrlf);
|
|
|
|
}
|
|
|
|
if (tree && whois_trans->rep_frame) {
|
|
|
|
ti = proto_tree_add_uint(whois_tree, hf_whois_answer_in,
|
|
|
|
tvb, 0, 0, whois_trans->rep_frame);
|
2019-04-03 21:32:30 +00:00
|
|
|
proto_item_set_generated(ti);
|
2013-11-14 21:04:05 +00:00
|
|
|
}
|
|
|
|
} else if (tree && whois_trans->rep_frame) {
|
2014-04-06 14:57:33 +00:00
|
|
|
proto_tree_add_item(whois_tree, hf_whois_answer, tvb, 0, -1, ENC_ASCII|ENC_NA);
|
2013-11-14 21:04:05 +00:00
|
|
|
if (whois_trans->req_frame) {
|
|
|
|
nstime_t ns;
|
|
|
|
|
|
|
|
ti = proto_tree_add_uint(whois_tree, hf_whois_answer_to,
|
|
|
|
tvb, 0, 0, whois_trans->req_frame);
|
2019-04-03 21:32:30 +00:00
|
|
|
proto_item_set_generated(ti);
|
2013-11-14 21:04:05 +00:00
|
|
|
|
2016-01-24 03:40:51 +00:00
|
|
|
if (pinfo->num == whois_trans->rep_frame) {
|
2016-01-23 03:50:21 +00:00
|
|
|
nstime_delta(&ns, &pinfo->abs_ts, &whois_trans->req_time);
|
2013-11-14 21:04:05 +00:00
|
|
|
ti = proto_tree_add_time(whois_tree, hf_whois_response_time, tvb, 0, 0, &ns);
|
2019-04-03 21:32:30 +00:00
|
|
|
proto_item_set_generated(ti);
|
2013-11-14 21:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 15:28:46 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2013-11-14 21:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_whois(void)
|
|
|
|
{
|
|
|
|
expert_module_t *expert_whois;
|
|
|
|
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_whois_query,
|
|
|
|
{ "Query", "whois.query", FT_STRING, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_whois_answer,
|
|
|
|
{ "Answer", "whois.answer", FT_STRING, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_whois_answer_in,
|
|
|
|
{ "Answer In", "whois.answer_in", FT_FRAMENUM, BASE_NONE, NULL,
|
|
|
|
0x0, "The answer to this WHOIS query is in this frame",
|
|
|
|
HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_whois_answer_to,
|
|
|
|
{ "Query In", "whois.answer_to", FT_FRAMENUM, BASE_NONE, NULL,
|
|
|
|
0x0, "This is the answer to the WHOIS query in this frame",
|
|
|
|
HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_whois_response_time,
|
|
|
|
{ "Response Time", "whois.response_time", FT_RELATIVE_TIME,
|
|
|
|
BASE_NONE, NULL, 0x0,
|
|
|
|
"The time between the Query and the Answer", HFILL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_whois
|
|
|
|
};
|
|
|
|
|
|
|
|
static ei_register_info ei[] = {
|
|
|
|
{ &ei_whois_nocrlf,
|
|
|
|
{ "whois.nocrlf", PI_MALFORMED, PI_WARN, "Missing <CR><LF>", EXPFILL}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
proto_whois = proto_register_protocol("whois", "WHOIS", "whois");
|
|
|
|
proto_register_field_array(proto_whois, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
expert_whois = expert_register_protocol(proto_whois);
|
|
|
|
expert_register_field_array(expert_whois, ei, array_length(ei));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_whois(void)
|
|
|
|
{
|
|
|
|
static dissector_handle_t whois_handle;
|
|
|
|
|
2015-12-09 03:49:44 +00:00
|
|
|
whois_handle = create_dissector_handle(dissect_whois, proto_whois);
|
2016-10-07 20:25:01 +00:00
|
|
|
dissector_add_uint_with_preference("tcp.port", WHOIS_PORT, whois_handle);
|
2013-11-14 21:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
2013-12-13 00:44:32 +00:00
|
|
|
* tab-width: 8
|
2013-11-14 21:04:05 +00:00
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
2013-12-13 00:44:32 +00:00
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
2013-11-14 21:04:05 +00:00
|
|
|
*/
|
|
|
|
|