From 1395494e7a7fe4f5566dd7775de542f638351572 Mon Sep 17 00:00:00 2001 From: Nardi Ivan Date: Sat, 1 Aug 2020 21:23:52 +0200 Subject: [PATCH] STUN: add heuristic over CLASSICSTUN Change-Id: I83cd3fe82c546344b49419304914f1c4b69bb3a5 Reviewed-on: https://code.wireshark.org/review/38018 Petri-Dish: Alexis La Goutte Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/dissectors/packet-classicstun.c | 19 +++++++++++++++++++ epan/dissectors/packet-stun.c | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/epan/dissectors/packet-classicstun.c b/epan/dissectors/packet-classicstun.c index 27fa129295..c1cbca3788 100644 --- a/epan/dissectors/packet-classicstun.c +++ b/epan/dissectors/packet-classicstun.c @@ -19,6 +19,11 @@ void proto_register_classicstun(void); void proto_reg_handoff_classicstun(void); +/* heuristic subdissectors */ +static heur_dissector_list_t heur_subdissector_list; + +static dissector_handle_t data_handle; + /* Initialize the protocol and registered fields */ static int proto_classicstun = -1; @@ -456,6 +461,15 @@ dissect_classicstun(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d case DATA: proto_tree_add_item(att_tree, classicstun_att_data, tvb, offset, att_length, ENC_NA); + + tvbuff_t *next_tvb; + heur_dtbl_entry_t *hdtbl_entry; + next_tvb = tvb_new_subset_length(tvb, offset, att_length); + + if (!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, att_tree, &hdtbl_entry, NULL)) { + call_dissector_only(data_handle, next_tvb, pinfo, att_tree, NULL); + } + break; case UNKNOWN_ATTRIBUTES: @@ -679,6 +693,9 @@ proto_register_classicstun(void) proto_register_field_array(proto_classicstun, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); + /* heuristic subdissectors (used for the DATA field) */ + heur_subdissector_list = register_heur_dissector_list("classicstun", proto_classicstun); + register_dissector("classicstun", dissect_classicstun, proto_classicstun); register_dissector("classicstun-heur", dissect_classicstun_heur, proto_classicstun); } @@ -697,6 +714,8 @@ proto_reg_handoff_classicstun(void) #endif heur_dissector_add("udp", dissect_classicstun_heur, "Classic STUN over UDP", "classicstun_udp", proto_classicstun, HEURISTIC_ENABLE); heur_dissector_add("tcp", dissect_classicstun_heur, "Classic STUN over TCP", "classicstun_tcp", proto_classicstun, HEURISTIC_ENABLE); + + data_handle = find_dissector("data"); } /* diff --git a/epan/dissectors/packet-stun.c b/epan/dissectors/packet-stun.c index f094df262d..d49c053016 100644 --- a/epan/dissectors/packet-stun.c +++ b/epan/dissectors/packet-stun.c @@ -1766,8 +1766,10 @@ proto_reg_handoff_stun(void) heur_dissector_add("udp", dissect_stun_heur_udp, "STUN over UDP", "stun_udp", proto_stun, HEURISTIC_ENABLE); heur_dissector_add("tcp", dissect_stun_heur_tcp, "STUN over TCP", "stun_tcp", proto_stun, HEURISTIC_ENABLE); - /* STUN messages may be encapsulated in Send Indication or Channel Data message as DATA payload */ + /* STUN messages may be encapsulated in Send Indication or Channel Data message as DATA payload + * (in TURN and CLASSICSTUN, both) */ heur_dissector_add("stun", dissect_stun_heur_udp, "STUN over TURN", "stun_turn", proto_stun, HEURISTIC_DISABLE); + heur_dissector_add("classicstun", dissect_stun_heur_udp, "STUN over CLASSICSTUN", "stun_classicstun", proto_stun, HEURISTIC_DISABLE); data_handle = find_dissector("data"); }