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...
16 #include <epan/packet.h>
17 #include <epan/addr_resolv.h>
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
;
45 dissect_fortinet_sso(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
48 proto_tree
*fsso_tree
;
49 uint32_t payload_length
, client_ip
;
50 int string_length
= -1;
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
);
64 proto_tree_add_item(fsso_tree
, hf_fsso_timestamp
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
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
);
71 proto_tree_add_item_ret_uint(fsso_tree
, hf_fsso_payload_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
, &payload_length
);
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
);
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
);
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
);
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
);
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
);
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
);
117 if(tvb_reported_length_remaining(tvb
, offset
)) {
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
);
126 proto_tree_add_item(fsso_tree
, hf_fsso_unknown_ipv4
, tvb
, offset
, 4, ENC_NA
);
129 proto_tree_add_item(fsso_tree
, hf_fsso_unknown
, tvb
, offset
, 6, ENC_NA
);
132 proto_tree_add_item(fsso_tree
, hf_fsso_unknown_ipv4
, tvb
, offset
, 4, ENC_NA
);
135 proto_tree_add_item(fsso_tree
, hf_fsso_unknown
, tvb
, offset
, 1, ENC_NA
);
138 proto_tree_add_item(fsso_tree
, hf_fsso_unknown
, tvb
, offset
, 15, ENC_NA
);
141 proto_tree_add_item(fsso_tree
, hf_fsso_unknown
, tvb
, offset
, 5, ENC_NA
);
144 proto_tree_add_item(fsso_tree
, hf_fsso_unknown
, tvb
, offset
, 6, ENC_NA
);
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
);
151 while (number_port_range
) {
153 proto_tree_add_item(fsso_tree
, hf_fsso_tsagent_port_range_min
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
156 proto_tree_add_item(fsso_tree
, hf_fsso_tsagent_port_range_max
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
159 number_port_range
--;
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) {
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
)
186 //always send with UDP Destination Port 80002
187 if(pinfo
->destport
!= UDP_FSSO
)
192 dissect_fortinet_sso(tvb
, pinfo
, tree
, data
);
197 proto_register_fortinet_sso(void)
199 static hf_register_info hf
[] = {
201 { "Length", "fortinet_sso.length", FT_UINT16
, BASE_DEC
, NULL
, 0x0,
204 { &hf_fsso_timestamp
,
205 { "Timestamp", "fortinet_sso.timestamp", FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0,
208 { &hf_fsso_client_ip
,
209 { "Client IP", "fortinet_sso.client_ip", FT_IPv4
, BASE_NONE
, NULL
, 0x0,
212 { &hf_fsso_payload_length
,
213 { "Payload Length", "fortinet_sso.payload_length", FT_UINT16
, BASE_DEC
, NULL
, 0x0,
217 { "String", "fortinet_sso.string", FT_STRING
, BASE_NONE
, NULL
, 0x0,
221 { "User", "fortinet_sso.user", FT_STRING
, BASE_NONE
, NULL
, 0x0,
225 { "Domain", "fortinet_sso.domain", FT_STRING
, BASE_NONE
, NULL
, 0x0,
229 { "Host", "fortinet_sso.host", FT_STRING
, BASE_NONE
, NULL
, 0x0,
233 { "Version", "fortinet_sso.version", FT_STRING
, BASE_NONE
, NULL
, 0x0,
236 { &hf_fsso_tsagent_number_port_range
,
237 { "Number of Port Range", "fortinet_sso.tsagent.port_range.number", FT_UINT16
, BASE_DEC
, NULL
, 0x0,
240 { &hf_fsso_tsagent_port_range_min
,
241 { "Port Range (Min)", "fortinet_sso.tsagent.port_range.min", FT_UINT16
, BASE_DEC
, NULL
, 0x0,
244 { &hf_fsso_tsagent_port_range_max
,
245 { "Port Range (Max)", "fortinet_sso.tsagent.port_range.max", FT_UINT16
, BASE_DEC
, NULL
, 0x0,
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
[] = {
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
));
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
283 * indent-tabs-mode: nil
286 * vi: set shiftwidth=4 tabstop=8 expandtab:
287 * :indentSize=4:tabSize=8:noTabs=true: