Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-fortinet-sso.c
blob1e3f5f7da3151bf2358d97c74c6afe637df98094
1 /* packet-fortinet-sso.c
2 * Routines for Fortinet Single Sign-On
3 * Copyright 2020, Alexis La Goutte <alexis.lagoutte at gmail dot com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
11 * No spec/doc is available based on reverse/analysis of protocol...
14 #include "config.h"
16 #include <epan/packet.h>
17 #include <epan/addr_resolv.h>
19 #define UDP_FSSO 8002
21 void proto_register_fortinet_sso(void);
22 void proto_reg_handoff_fortinet_sso(void);
24 static int proto_fortinet_sso;
25 static int ett_fortinet_sso;
27 static int hf_fsso_length;
28 static int hf_fsso_timestamp;
29 static int hf_fsso_client_ip;
30 static int hf_fsso_payload_length;
31 static int hf_fsso_string;
32 static int hf_fsso_domain;
33 static int hf_fsso_user;
34 static int hf_fsso_host;
35 static int hf_fsso_version;
36 static int hf_fsso_tsagent_number_port_range;
37 static int hf_fsso_tsagent_port_range_min;
38 static int hf_fsso_tsagent_port_range_max;
39 static int hf_fsso_unknown;
40 static int hf_fsso_unknown_ipv4;
42 static dissector_handle_t fortinet_sso_handle;
44 static int
45 dissect_fortinet_sso(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
47 proto_tree *ti;
48 proto_tree *fsso_tree;
49 uint32_t payload_length, client_ip;
50 int string_length = -1;
51 const char *string;
52 int32_t len;
53 int offset = 0;
55 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FSSO");
56 col_set_str(pinfo->cinfo, COL_INFO, "Fortinet Single Sign-On");
58 ti = proto_tree_add_item(tree, proto_fortinet_sso, tvb, 0, -1, ENC_NA);
59 fsso_tree = proto_item_add_subtree(ti, ett_fortinet_sso);
61 proto_tree_add_item(fsso_tree, hf_fsso_length, tvb, offset, 2, ENC_BIG_ENDIAN);
62 offset += 2;
64 proto_tree_add_item(fsso_tree, hf_fsso_timestamp, tvb, offset, 4, ENC_BIG_ENDIAN);
65 offset += 4;
67 proto_tree_add_item(fsso_tree, hf_fsso_client_ip, tvb, offset, 4, ENC_BIG_ENDIAN);
68 client_ip = tvb_get_ipv4(tvb, offset);
69 offset += 4;
71 proto_tree_add_item_ret_uint(fsso_tree, hf_fsso_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN, &payload_length);
72 offset += 2;
74 string = tvb_get_stringz_enc(pinfo->pool, tvb, offset, &string_length, ENC_ASCII);
75 proto_tree_add_item(fsso_tree, hf_fsso_string, tvb, offset, string_length, ENC_ASCII);
76 col_set_str(pinfo->cinfo, COL_INFO, string);
78 if(client_ip == 0xFFFFFFFF) { //if client_ip equal 255.255.255.255 (0xFFFFFFFF) is KeepAlive packet
79 /* Domain / KeepAlive (User) / Version */
80 len = tvb_find_uint8(tvb, offset, string_length, '/') - offset;
81 proto_tree_add_item(fsso_tree, hf_fsso_domain, tvb, offset, len, ENC_ASCII);
82 offset += (len + 1);
83 string_length -= (len + 1);
85 len = tvb_find_uint8(tvb, offset, string_length, '/') - offset;
86 proto_tree_add_item(fsso_tree, hf_fsso_user, tvb, offset, len, ENC_ASCII);
87 offset += (len + 1);
88 string_length -= (len + 1);
90 proto_tree_add_item(fsso_tree, hf_fsso_version, tvb, offset, string_length, ENC_ASCII);
91 offset += (string_length);
93 } else {
94 /* Host / Domain / User */
95 len = tvb_find_uint8(tvb, offset, string_length, '/') - offset;
96 proto_tree_add_item(fsso_tree, hf_fsso_host, tvb, offset, len, ENC_ASCII);
97 offset += (len + 1);
98 string_length -= (len + 1);
100 len = tvb_find_uint8(tvb, offset, string_length, '/') - offset;
101 proto_tree_add_item(fsso_tree, hf_fsso_domain, tvb, offset, len, ENC_ASCII);
102 offset += (len + 1);
103 string_length -= (len + 1);
105 proto_tree_add_item(fsso_tree, hf_fsso_user, tvb, offset, string_length, ENC_ASCII);
106 offset += (string_length);
109 if(tvb_reported_length_remaining(tvb, offset) == 4) {
111 /* There is some packet with extra IPv4 address... */
112 proto_tree_add_item(fsso_tree, hf_fsso_unknown_ipv4, tvb, offset, 4, ENC_NA);
113 offset += 4;
115 } else {
117 if(tvb_reported_length_remaining(tvb, offset)) {
118 uint16_t value;
119 uint32_t number_port_range;
120 value = tvb_get_ntohs(tvb, offset);
122 if(value == 0x2002) { /* Not a TS Agent additional Data */
123 proto_tree_add_item(fsso_tree, hf_fsso_unknown, tvb, offset, 2, ENC_NA);
124 offset += 2;
126 proto_tree_add_item(fsso_tree, hf_fsso_unknown_ipv4, tvb, offset, 4, ENC_NA);
127 offset += 4;
129 proto_tree_add_item(fsso_tree, hf_fsso_unknown, tvb, offset, 6, ENC_NA);
130 offset += 6;
132 proto_tree_add_item(fsso_tree, hf_fsso_unknown_ipv4, tvb, offset, 4, ENC_NA);
133 offset += 4;
135 proto_tree_add_item(fsso_tree, hf_fsso_unknown, tvb, offset, 1, ENC_NA);
136 offset += 1;
137 } else {
138 proto_tree_add_item(fsso_tree, hf_fsso_unknown, tvb, offset, 15, ENC_NA);
139 offset += 15;
141 proto_tree_add_item(fsso_tree, hf_fsso_unknown, tvb, offset, 5, ENC_NA);
142 offset += 5;
144 proto_tree_add_item(fsso_tree, hf_fsso_unknown, tvb, offset, 6, ENC_NA);
145 offset += 6;
147 /* Port Range assigned to user for TS Agent (RDP/Citrix) */
148 proto_tree_add_item_ret_uint(fsso_tree, hf_fsso_tsagent_number_port_range, tvb, offset, 2, ENC_BIG_ENDIAN, &number_port_range);
149 offset += 2;
151 while (number_port_range) {
153 proto_tree_add_item(fsso_tree, hf_fsso_tsagent_port_range_min, tvb, offset, 2, ENC_BIG_ENDIAN);
154 offset += 2;
156 proto_tree_add_item(fsso_tree, hf_fsso_tsagent_port_range_max, tvb, offset, 2, ENC_BIG_ENDIAN);
157 offset += 2;
159 number_port_range --;
166 return offset;
169 static bool
170 dissect_fortinet_fsso_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
172 uint32_t length_remaining, length;
174 if (tvb_captured_length(tvb) < 2) {
175 return false;
178 length_remaining = tvb_reported_length_remaining(tvb, 0);
179 //first bytes is the length of payload
180 length = tvb_get_ntohs(tvb, 0);
181 if(length_remaining != length)
183 return false;
186 //always send with UDP Destination Port 80002
187 if(pinfo->destport != UDP_FSSO)
189 return false;
192 dissect_fortinet_sso(tvb, pinfo, tree, data);
193 return true;
196 void
197 proto_register_fortinet_sso(void)
199 static hf_register_info hf[] = {
200 { &hf_fsso_length,
201 { "Length", "fortinet_sso.length", FT_UINT16, BASE_DEC, NULL, 0x0,
202 NULL, HFILL}},
204 { &hf_fsso_timestamp,
205 { "Timestamp", "fortinet_sso.timestamp", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
206 NULL, HFILL}},
208 { &hf_fsso_client_ip,
209 { "Client IP", "fortinet_sso.client_ip", FT_IPv4, BASE_NONE, NULL, 0x0,
210 NULL, HFILL}},
212 { &hf_fsso_payload_length,
213 { "Payload Length", "fortinet_sso.payload_length", FT_UINT16, BASE_DEC, NULL, 0x0,
214 NULL, HFILL}},
216 { &hf_fsso_string,
217 { "String", "fortinet_sso.string", FT_STRING, BASE_NONE, NULL, 0x0,
218 NULL, HFILL}},
220 { &hf_fsso_user,
221 { "User", "fortinet_sso.user", FT_STRING, BASE_NONE, NULL, 0x0,
222 NULL, HFILL}},
224 { &hf_fsso_domain,
225 { "Domain", "fortinet_sso.domain", FT_STRING, BASE_NONE, NULL, 0x0,
226 NULL, HFILL}},
228 { &hf_fsso_host,
229 { "Host", "fortinet_sso.host", FT_STRING, BASE_NONE, NULL, 0x0,
230 NULL, HFILL}},
232 { &hf_fsso_version,
233 { "Version", "fortinet_sso.version", FT_STRING, BASE_NONE, NULL, 0x0,
234 NULL, HFILL}},
236 { &hf_fsso_tsagent_number_port_range,
237 { "Number of Port Range", "fortinet_sso.tsagent.port_range.number", FT_UINT16, BASE_DEC, NULL, 0x0,
238 NULL, HFILL}},
240 { &hf_fsso_tsagent_port_range_min,
241 { "Port Range (Min)", "fortinet_sso.tsagent.port_range.min", FT_UINT16, BASE_DEC, NULL, 0x0,
242 NULL, HFILL}},
244 { &hf_fsso_tsagent_port_range_max,
245 { "Port Range (Max)", "fortinet_sso.tsagent.port_range.max", FT_UINT16, BASE_DEC, NULL, 0x0,
246 NULL, HFILL}},
248 { &hf_fsso_unknown,
249 { "Unknown", "fortinet_sso.unknown", FT_BYTES, BASE_NONE, NULL, 0x0,
250 "Unknown Data...", HFILL}},
252 { &hf_fsso_unknown_ipv4,
253 { "Unknown IPv4", "fortinet_sso.unknown.ipv4", FT_IPv4, BASE_NONE, NULL, 0x0,
254 "Unknown Data...", HFILL}},
258 static int *ett[] = {
259 &ett_fortinet_sso,
262 proto_fortinet_sso = proto_register_protocol("Fortinet Single Sign On", "fortinet_sso", "fortinet_sso");
263 fortinet_sso_handle = register_dissector("fortinet_sso", dissect_fortinet_sso, proto_fortinet_sso);
265 proto_register_field_array(proto_fortinet_sso, hf, array_length(hf));
266 proto_register_subtree_array(ett, array_length(ett));
270 void
271 proto_reg_handoff_fortinet_sso(void)
273 dissector_add_uint_with_preference("udp.port", 0, fortinet_sso_handle);
274 heur_dissector_add("udp", dissect_fortinet_fsso_heur, "Fortinet SSO over UDP", "fortinet_sso", proto_fortinet_sso, HEURISTIC_ENABLE);
278 * Editor modelines - https://www.wireshark.org/tools/modelines.html
280 * Local variables:
281 * c-basic-offset: 4
282 * tab-width: 8
283 * indent-tabs-mode: nil
284 * End:
286 * vi: set shiftwidth=4 tabstop=8 expandtab:
287 * :indentSize=4:tabSize=8:noTabs=true: