2 * Routines for cisco tacacs/xtacacs/tacacs+ packet dissection
3 * Copyright 2001, Paul Ionescu <paul@acorp.ro>
5 * $Id: packet-tacacs.c,v 1.23 2002/08/28 21:00:35 jmayer Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * Copied from old packet-tacacs.c
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /* rfc-1492 for tacacs and xtacacs
30 * draft-grant-tacacs-00.txt for tacacs+ (tacplus)
41 #include <epan/packet.h>
43 static int proto_tacacs = -1;
44 static int hf_tacacs_version = -1;
45 static int hf_tacacs_type = -1;
46 static int hf_tacacs_nonce = -1;
47 static int hf_tacacs_userlen = -1;
48 static int hf_tacacs_passlen = -1;
49 static int hf_tacacs_response = -1;
50 static int hf_tacacs_reason = -1;
51 static int hf_tacacs_result1 = -1;
52 static int hf_tacacs_destaddr = -1;
53 static int hf_tacacs_destport = -1;
54 static int hf_tacacs_line = -1;
55 static int hf_tacacs_result2 = -1;
56 static int hf_tacacs_result3 = -1;
58 static gint ett_tacacs = -1;
60 #define VERSION_TACACS 0x00
61 #define VERSION_XTACACS 0x80
63 static const value_string tacacs_version_vals[] = {
64 { VERSION_TACACS, "TACACS" },
65 { VERSION_XTACACS, "XTACACS" },
69 #define TACACS_LOGIN 1
70 #define TACACS_RESPONSE 2
71 #define TACACS_CHANGE 3
72 #define TACACS_FOLLOW 4
73 #define TACACS_CONNECT 5
74 #define TACACS_SUPERUSER 6
75 #define TACACS_LOGOUT 7
76 #define TACACS_RELOAD 8
77 #define TACACS_SLIP_ON 9
78 #define TACACS_SLIP_OFF 10
79 #define TACACS_SLIP_ADDR 11
80 static const value_string tacacs_type_vals[] = {
81 { TACACS_LOGIN, "Login" },
82 { TACACS_RESPONSE, "Response" },
83 { TACACS_CHANGE, "Change" },
84 { TACACS_FOLLOW, "Follow" },
85 { TACACS_CONNECT, "Connect" },
86 { TACACS_SUPERUSER, "Superuser" },
87 { TACACS_LOGOUT, "Logout" },
88 { TACACS_RELOAD, "Reload" },
89 { TACACS_SLIP_ON, "SLIP on" },
90 { TACACS_SLIP_OFF, "SLIP off" },
91 { TACACS_SLIP_ADDR, "SLIP Addr" },
94 static const value_string tacacs_reason_vals[] = {
106 static const value_string tacacs_resp_vals[] = {
107 { 0 , "this is not a response" },
113 #define TAC_PLUS_AUTHEN 1
114 #define TAC_PLUS_AUTHOR 2
115 #define TAC_PLUS_ACCT 3
117 #define UDP_PORT_TACACS 49
118 #define TCP_PORT_TACACS 49
121 dissect_tacacs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
123 proto_tree *tacacs_tree;
125 guint8 txt_buff[256],version,type,userlen,passlen;
127 if (check_col(pinfo->cinfo, COL_PROTOCOL))
128 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TACACS");
129 if (check_col(pinfo->cinfo, COL_INFO))
130 col_clear(pinfo->cinfo, COL_INFO);
132 version = tvb_get_guint8(tvb,0);
134 if (check_col(pinfo->cinfo, COL_PROTOCOL))
135 col_set_str(pinfo->cinfo, COL_PROTOCOL, "XTACACS");
138 type = tvb_get_guint8(tvb,1);
139 if (check_col(pinfo->cinfo, COL_INFO))
140 col_add_str(pinfo->cinfo, COL_INFO,
141 val_to_str(type, tacacs_type_vals, "Unknown (0x%02x)"));
145 ti = proto_tree_add_protocol_format(tree, proto_tacacs,
146 tvb, 0, -1, version==0?"TACACS":"XTACACS");
147 tacacs_tree = proto_item_add_subtree(ti, ett_tacacs);
149 proto_tree_add_uint(tacacs_tree, hf_tacacs_version, tvb, 0, 1,
151 proto_tree_add_uint(tacacs_tree, hf_tacacs_type, tvb, 1, 1,
153 proto_tree_add_item(tacacs_tree, hf_tacacs_nonce, tvb, 2, 2,
158 if (type!=TACACS_RESPONSE)
160 userlen=tvb_get_guint8(tvb,4);
161 proto_tree_add_uint(tacacs_tree, hf_tacacs_userlen, tvb, 4, 1,
163 passlen=tvb_get_guint8(tvb,5);
164 proto_tree_add_uint(tacacs_tree, hf_tacacs_passlen, tvb, 5, 1,
166 tvb_get_nstringz0(tvb,6,userlen,txt_buff);
167 proto_tree_add_text(tacacs_tree, tvb, 6, userlen, "Username: %s",txt_buff);
168 tvb_get_nstringz0(tvb,6+userlen,passlen,txt_buff);
169 proto_tree_add_text(tacacs_tree, tvb, 6+userlen, passlen, "Password: %s",txt_buff);
173 proto_tree_add_item(tacacs_tree, hf_tacacs_response, tvb, 4, 1,
175 proto_tree_add_item(tacacs_tree, hf_tacacs_reason, tvb, 5, 1,
181 userlen=tvb_get_guint8(tvb,4);
182 proto_tree_add_uint(tacacs_tree, hf_tacacs_userlen, tvb, 4, 1,
184 passlen=tvb_get_guint8(tvb,5);
185 proto_tree_add_uint(tacacs_tree, hf_tacacs_passlen, tvb, 5, 1,
187 proto_tree_add_item(tacacs_tree, hf_tacacs_response, tvb, 6, 1,
189 proto_tree_add_item(tacacs_tree, hf_tacacs_reason, tvb, 7, 1,
191 proto_tree_add_item(tacacs_tree, hf_tacacs_result1, tvb, 8, 4,
193 proto_tree_add_item(tacacs_tree, hf_tacacs_destaddr, tvb, 12, 4,
195 proto_tree_add_item(tacacs_tree, hf_tacacs_destport, tvb, 16, 2,
197 proto_tree_add_item(tacacs_tree, hf_tacacs_line, tvb, 18, 2,
199 proto_tree_add_item(tacacs_tree, hf_tacacs_result2, tvb, 20, 4,
201 proto_tree_add_item(tacacs_tree, hf_tacacs_result3, tvb, 24, 2,
203 if (type!=TACACS_RESPONSE)
205 tvb_get_nstringz0(tvb,26,userlen,txt_buff);
206 proto_tree_add_text(tacacs_tree, tvb, 26, userlen, "Username: %s",txt_buff);
207 tvb_get_nstringz0(tvb,26+userlen,passlen,txt_buff);
208 proto_tree_add_text(tacacs_tree, tvb, 26+userlen, passlen, "Password; %s",txt_buff);
215 proto_register_tacacs(void)
217 static hf_register_info hf[] = {
218 { &hf_tacacs_version,
219 { "Version", "tacacs.version",
220 FT_UINT8, BASE_HEX, VALS(tacacs_version_vals), 0x0,
223 { "Type", "tacacs.type",
224 FT_UINT8, BASE_DEC, VALS(tacacs_type_vals), 0x0,
227 { "Nonce", "tacacs.nonce",
228 FT_UINT16, BASE_HEX, NULL, 0x0,
230 { &hf_tacacs_userlen,
231 { "Username length", "tacacs.userlen",
232 FT_UINT8, BASE_DEC, NULL, 0x0,
233 "Username length", HFILL }},
234 { &hf_tacacs_passlen,
235 { "Password length", "tacacs.passlen",
236 FT_UINT8, BASE_DEC, NULL, 0x0,
237 "Password length", HFILL }},
238 { &hf_tacacs_response,
239 { "Response", "tacacs.response",
240 FT_UINT8, BASE_DEC, VALS(tacacs_resp_vals), 0x0,
241 "Response", HFILL }},
243 { "Reason", "tacacs.reason",
244 FT_UINT8, BASE_DEC, VALS(tacacs_reason_vals), 0x0,
246 { &hf_tacacs_result1,
247 { "Result 1", "tacacs.result1",
248 FT_UINT32, BASE_HEX, NULL, 0x0,
249 "Result 1", HFILL }},
250 { &hf_tacacs_destaddr,
251 { "Destination address", "tacacs.destaddr",
252 FT_IPv4, BASE_NONE, NULL, 0x0,
253 "Destination address", HFILL }},
254 { &hf_tacacs_destport,
255 { "Destination port", "tacacs.destport",
256 FT_UINT16, BASE_DEC, NULL, 0x0,
257 "Destination port", HFILL }},
259 { "Line", "tacacs.line",
260 FT_UINT16, BASE_DEC, NULL, 0x0,
262 { &hf_tacacs_result2,
263 { "Result 2", "tacacs.result2",
264 FT_UINT32, BASE_HEX, NULL, 0x0,
265 "Result 2", HFILL }},
266 { &hf_tacacs_result3,
267 { "Result 3", "tacacs.result3",
268 FT_UINT16, BASE_HEX, NULL, 0x0,
269 "Result 3", HFILL }},
272 static gint *ett[] = {
275 proto_tacacs = proto_register_protocol("TACACS", "TACACS", "tacacs");
276 proto_register_field_array(proto_tacacs, hf, array_length(hf));
277 proto_register_subtree_array(ett, array_length(ett));
281 proto_reg_handoff_tacacs(void)
283 dissector_handle_t tacacs_handle;
285 tacacs_handle = create_dissector_handle(dissect_tacacs, proto_tacacs);
286 dissector_add("udp.port", UDP_PORT_TACACS, tacacs_handle);
289 static int proto_tacplus = -1;
290 static int hf_tacplus_response = -1;
291 static int hf_tacplus_request = -1;
292 static int hf_tacplus_majvers = -1;
293 static int hf_tacplus_minvers = -1;
294 static int hf_tacplus_type = -1;
295 static int hf_tacplus_seqno = -1;
296 static int hf_tacplus_flags = -1;
297 static int hf_tacplus_flags_payload_type = -1;
298 static int hf_tacplus_flags_connection_type = -1;
299 static int hf_tacplus_session_id = -1;
300 static int hf_tacplus_packet_len = -1;
302 static gint ett_tacplus = -1;
303 static gint ett_tacplus_flags = -1;
305 static const value_string tacplus_type_vals[] = {
306 { TAC_PLUS_AUTHEN , "Authentication" },
307 { TAC_PLUS_AUTHOR , "Authorization" },
308 { TAC_PLUS_ACCT , "Accounting" },
311 #define FLAGS_UNENCRYPTED 0x01
313 static const true_false_string payload_type = {
318 #define FLAGS_SINGLE 0x04
320 static const true_false_string connection_type = {
326 dissect_tacplus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
328 proto_tree *tacplus_tree;
330 guint8 version,flags;
331 proto_tree *flags_tree;
334 gboolean request=(pinfo->match_port == pinfo->destport);
336 if (check_col(pinfo->cinfo, COL_PROTOCOL))
337 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TACACS+");
339 if (check_col(pinfo->cinfo, COL_INFO))
341 col_set_str(pinfo->cinfo, COL_INFO,
342 request ? "Request" : "Response");
347 ti = proto_tree_add_protocol_format(tree, proto_tacplus,
348 tvb, 0, -1, "TACACS+");
350 tacplus_tree = proto_item_add_subtree(ti, ett_tacplus);
351 if (pinfo->match_port == pinfo->destport)
353 proto_tree_add_boolean_hidden(tacplus_tree,
354 hf_tacplus_request, tvb, 0, 0, TRUE);
358 proto_tree_add_boolean_hidden(tacplus_tree,
359 hf_tacplus_response, tvb, 0, 0, TRUE);
361 version = tvb_get_guint8(tvb,0);
362 proto_tree_add_uint_format(tacplus_tree, hf_tacplus_majvers, tvb, 0, 1,
365 (version&0xf0)==0xc0?"TACACS+":"Unknown Version");
366 proto_tree_add_uint(tacplus_tree, hf_tacplus_minvers, tvb, 0, 1,
368 proto_tree_add_item(tacplus_tree, hf_tacplus_type, tvb, 1, 1,
370 proto_tree_add_item(tacplus_tree, hf_tacplus_seqno, tvb, 2, 1,
372 flags = tvb_get_guint8(tvb,3);
373 tf = proto_tree_add_uint_format(tacplus_tree, hf_tacplus_flags,
375 "Flags: %s, %s (0x%02x)",
376 (flags&FLAGS_UNENCRYPTED) ? "Unencrypted payload" :
378 (flags&FLAGS_SINGLE) ? "Single connection" :
379 "Multiple Connections",
381 flags_tree = proto_item_add_subtree(tf, ett_tacplus_flags);
382 proto_tree_add_boolean(flags_tree, hf_tacplus_flags_payload_type,
384 proto_tree_add_boolean(flags_tree, hf_tacplus_flags_connection_type,
386 proto_tree_add_item(tacplus_tree, hf_tacplus_session_id, tvb, 4, 4,
388 len = tvb_get_ntohl(tvb,8);
389 proto_tree_add_uint(tacplus_tree, hf_tacplus_packet_len, tvb, 8, 4,
392 if (flags&FLAGS_UNENCRYPTED)
393 proto_tree_add_text(tacplus_tree, tvb, 12, len, "Payload");
395 proto_tree_add_text(tacplus_tree, tvb, 12, len, "Encrypted payload");
400 proto_register_tacplus(void)
402 static hf_register_info hf[] = {
403 { &hf_tacplus_response,
404 { "Response", "tacplus.response",
405 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
406 "TRUE if TACACS+ response", HFILL }},
407 { &hf_tacplus_request,
408 { "Request", "tacplus.request",
409 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
410 "TRUE if TACACS+ request", HFILL }},
411 { &hf_tacplus_majvers,
412 { "Major version", "tacplus.majvers",
413 FT_UINT8, BASE_DEC, NULL, 0x0,
414 "Major version number", HFILL }},
415 { &hf_tacplus_minvers,
416 { "Minor version", "tacplus.minvers",
417 FT_UINT8, BASE_DEC, NULL, 0x0,
418 "Minor version number", HFILL }},
420 { "Type", "tacplus.type",
421 FT_UINT8, BASE_DEC, VALS(tacplus_type_vals), 0x0,
424 { "Sequence number", "tacplus.seqno",
425 FT_UINT8, BASE_DEC, NULL, 0x0,
426 "Sequence number", HFILL }},
428 { "Flags", "tacplus.flags",
429 FT_UINT8, BASE_HEX, NULL, 0x0,
431 { &hf_tacplus_flags_payload_type,
432 { "Payload type", "tacplus.flags.payload_type",
433 FT_BOOLEAN, 8, TFS(&payload_type), FLAGS_UNENCRYPTED,
434 "Payload type (unencrypted or encrypted)", HFILL }},
435 { &hf_tacplus_flags_connection_type,
436 { "Connection type", "tacplus.flags.connection_type",
437 FT_BOOLEAN, 8, TFS(&connection_type), FLAGS_SINGLE,
438 "Connection type (single or multiple)", HFILL }},
439 { &hf_tacplus_session_id,
440 { "Session ID", "tacplus.session_id",
441 FT_UINT32, BASE_DEC, NULL, 0x0,
442 "Session ID", HFILL }},
443 { &hf_tacplus_packet_len,
444 { "Packet length", "tacplus.packet_len",
445 FT_UINT32, BASE_DEC, NULL, 0x0,
446 "Packet length", HFILL }}
449 static gint *ett[] = {
453 proto_tacplus = proto_register_protocol("TACACS+", "TACACS+", "tacplus");
454 proto_register_field_array(proto_tacplus, hf, array_length(hf));
455 proto_register_subtree_array(ett, array_length(ett));
459 proto_reg_handoff_tacplus(void)
461 dissector_handle_t tacplus_handle;
463 tacplus_handle = create_dissector_handle(dissect_tacplus,
465 dissector_add("tcp.port", TCP_PORT_TACACS, tacplus_handle);