2 * Copyright (C) 2000 Alfredo Andres Omella. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
14 * 3. The names of the authors may not be used to endorse or promote
15 * products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Radius printer routines as specified on:
26 * "Remote Authentication Dial In User Service (RADIUS)"
32 * "RADIUS Accounting Modifications for Tunnel Protocol Support"
35 * "RADIUS Attributes for Tunnel Protocol Support"
40 * Alfredo Andres Omella (aandres@s21sec.com) v0.1 2000/09/15
42 * TODO: Among other things to print ok MacIntosh and Vendor values
46 static const char rcsid[] _U_ =
47 "$Id: print-radius.c,v 1.28 2005-09-26 01:01:55 guy Exp $";
54 #include <tcpdump-stdinc.h>
60 #include "interface.h"
61 #include "addrtoname.h"
65 #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )
67 #define PRINT_HEX(bytes_len, ptr_data) \
70 printf("%02X", *ptr_data ); \
76 /* Radius packet codes */
77 #define RADCMD_ACCESS_REQ 1 /* Access-Request */
78 #define RADCMD_ACCESS_ACC 2 /* Access-Accept */
79 #define RADCMD_ACCESS_REJ 3 /* Access-Reject */
80 #define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */
81 #define RADCMD_ACCOUN_RES 5 /* Accounting-Response */
82 #define RADCMD_ACCESS_CHA 11 /* Access-Challenge */
83 #define RADCMD_STATUS_SER 12 /* Status-Server */
84 #define RADCMD_STATUS_CLI 13 /* Status-Client */
85 #define RADCMD_RESERVED 255 /* Reserved */
87 static struct tok radius_command_values[] = {
88 { RADCMD_ACCESS_REQ, "Access Request" },
89 { RADCMD_ACCESS_ACC, "Access Accept" },
90 { RADCMD_ACCESS_REJ, "Access Reject" },
91 { RADCMD_ACCOUN_REQ, "Accounting Request" },
92 { RADCMD_ACCOUN_RES, "Accounting Response" },
93 { RADCMD_ACCESS_CHA, "Access Challenge" },
94 { RADCMD_STATUS_SER, "Status Server" },
95 { RADCMD_STATUS_CLI, "Status Client" },
96 { RADCMD_RESERVED, "Reserved" },
100 /********************************/
101 /* Begin Radius Attribute types */
102 /********************************/
105 #define LOG_IPHOST 14
106 #define LOG_SERVICE 15
108 #define SESSION_TIMEOUT 27
109 #define IDLE_TIMEOUT 28
110 #define FRM_ATALK_LINK 37
111 #define FRM_ATALK_NETWORK 38
113 #define ACCT_DELAY 41
114 #define ACCT_SESSION_TIME 46
116 #define TUNNEL_TYPE 64
117 #define TUNNEL_MEDIUM 65
118 #define TUNNEL_CLIENT_END 66
119 #define TUNNEL_SERVER_END 67
120 #define TUNNEL_PASS 69
123 #define ARAP_FEATURES 71
125 #define TUNNEL_PRIV_GROUP 81
126 #define TUNNEL_ASSIGN_ID 82
127 #define TUNNEL_PREFERENCE 83
129 #define ARAP_CHALLENGE_RESP 84
130 #define ACCT_INT_INTERVAL 85
132 #define TUNNEL_CLIENT_AUTH 90
133 #define TUNNEL_SERVER_AUTH 91
134 /********************************/
135 /* End Radius Attribute types */
136 /********************************/
139 static void print_attr_string(register u_char *, u_int, u_short );
140 static void print_attr_num(register u_char *, u_int, u_short );
141 static void print_vendor_attr(register u_char *, u_int, u_short );
142 static void print_attr_address(register u_char *, u_int, u_short);
143 static void print_attr_time(register u_char *, u_int, u_short);
144 static void print_attr_strange(register u_char *, u_int, u_short);
147 struct radius_hdr { u_int8_t code; /* Radius packet code */
148 u_int8_t id; /* Radius packet id */
149 u_int16_t len; /* Radius total length */
150 u_int8_t auth[16]; /* Authenticator */
153 #define MIN_RADIUS_LEN 20
155 struct radius_attr { u_int8_t type; /* Attribute type */
156 u_int8_t len; /* Attribute length */
160 /* Service-Type Attribute standard values */
161 static const char *serv_type[]={ NULL,
170 "Callback NAS Prompt",
172 "Callback Administrative",
175 /* Framed-Protocol Attribute standard values */
176 static const char *frm_proto[]={ NULL,
180 "Gandalf proprietary",
185 /* Framed-Routing Attribute standard values */
186 static const char *frm_routing[]={ "None",
192 /* Framed-Compression Attribute standard values */
193 static const char *frm_comp[]={ "None",
199 /* Login-Service Attribute standard values */
200 static const char *login_serv[]={ "Telnet",
203 "PortMaster(proprietary)",
212 /* Termination-Action Attribute standard values */
213 static const char *term_action[]={ "Default",
217 /* NAS-Port-Type Attribute standard values */
218 static const char *nas_port_type[]={ "Async",
225 "HDLC Clear Channel",
237 "Wireless - IEEE 802.11",
240 /* Acct-Status-Type Accounting Attribute standard values */
241 static const char *acct_status[]={ NULL,
255 "Tunnel-Link-Reject",
259 /* Acct-Authentic Accounting Attribute standard values */
260 static const char *acct_auth[]={ NULL,
266 /* Acct-Terminate-Cause Accounting Attribute standard values */
267 static const char *acct_term[]={ NULL,
282 "Service Unavailable",
288 /* Tunnel-Type Attribute standard values */
289 static const char *tunnel_type[]={ NULL,
301 "IP-in-IP Tunneling",
304 /* Tunnel-Medium-Type Attribute standard values */
305 static const char *tunnel_medium[]={ NULL,
320 "E.164 with NSAP subaddress",
323 /* ARAP-Zone-Access Attribute standard values */
324 static const char *arap_zone[]={ NULL,
325 "Only access to dfl zone",
326 "Use zone filter inc.",
328 "Use zone filter exc.",
331 static const char *prompt[]={ "No Echo",
336 struct attrtype { const char *name; /* Attribute name */
337 const char **subtypes; /* Standard Values (if any) */
338 u_char siz_subtypes; /* Size of total standard values */
339 u_char first_subtype; /* First standard value is 0 or 1 */
340 void (*print_func)(register u_char *, u_int, u_short );
343 { NULL, NULL, 0, 0, NULL },
344 { "Username", NULL, 0, 0, print_attr_string },
345 { "Password", NULL, 0, 0, NULL },
346 { "CHAP Password", NULL, 0, 0, NULL },
347 { "NAS IP Address", NULL, 0, 0, print_attr_address },
348 { "NAS Port", NULL, 0, 0, print_attr_num },
349 { "Service Type", serv_type, TAM_SIZE(serv_type)-1, 1, print_attr_num },
350 { "Framed Protocol", frm_proto, TAM_SIZE(frm_proto)-1, 1, print_attr_num },
351 { "Framed IP Address", NULL, 0, 0, print_attr_address },
352 { "Framed IP Network", NULL, 0, 0, print_attr_address },
353 { "Framed Routing", frm_routing, TAM_SIZE(frm_routing), 0, print_attr_num },
354 { "Filter ID", NULL, 0, 0, print_attr_string },
355 { "Framed MTU", NULL, 0, 0, print_attr_num },
356 { "Framed Compression", frm_comp, TAM_SIZE(frm_comp), 0, print_attr_num },
357 { "Login IP Host", NULL, 0, 0, print_attr_address },
358 { "Login Service", login_serv, TAM_SIZE(login_serv), 0, print_attr_num },
359 { "Login TCP Port", NULL, 0, 0, print_attr_num },
360 { "Unassigned", NULL, 0, 0, NULL }, /*17*/
361 { "Reply", NULL, 0, 0, print_attr_string },
362 { "Callback-number", NULL, 0, 0, print_attr_string },
363 { "Callback-ID", NULL, 0, 0, print_attr_string },
364 { "Unassigned", NULL, 0, 0, NULL }, /*21*/
365 { "Framed Route", NULL, 0, 0, print_attr_string },
366 { "Framed IPX Network", NULL, 0, 0, print_attr_num },
367 { "State", NULL, 0, 0, print_attr_string },
368 { "Class", NULL, 0, 0, print_attr_string },
369 { "Vendor Specific", NULL, 0, 0, print_vendor_attr },
370 { "Session Timeout", NULL, 0, 0, print_attr_num },
371 { "Idle Timeout", NULL, 0, 0, print_attr_num },
372 { "Termination Action", term_action, TAM_SIZE(term_action), 0, print_attr_num },
373 { "Called Station", NULL, 0, 0, print_attr_string },
374 { "Calling Station", NULL, 0, 0, print_attr_string },
375 { "NAS ID", NULL, 0, 0, print_attr_string },
376 { "Proxy State", NULL, 0, 0, print_attr_string },
377 { "Login LAT Service", NULL, 0, 0, print_attr_string },
378 { "Login LAT Node", NULL, 0, 0, print_attr_string },
379 { "Login LAT Group", NULL, 0, 0, print_attr_string },
380 { "Framed Appletalk Link", NULL, 0, 0, print_attr_num },
381 { "Framed Appltalk Net", NULL, 0, 0, print_attr_num },
382 { "Framed Appletalk Zone", NULL, 0, 0, print_attr_string },
383 { "Accounting Status", acct_status, TAM_SIZE(acct_status)-1, 1, print_attr_num },
384 { "Accounting Delay", NULL, 0, 0, print_attr_num },
385 { "Accounting Input Octets", NULL, 0, 0, print_attr_num },
386 { "Accounting Output Octets", NULL, 0, 0, print_attr_num },
387 { "Accounting Session ID", NULL, 0, 0, print_attr_string },
388 { "Accounting Authentication", acct_auth, TAM_SIZE(acct_auth)-1, 1, print_attr_num },
389 { "Accounting Session Time", NULL, 0, 0, print_attr_num },
390 { "Accounting Input Packets", NULL, 0, 0, print_attr_num },
391 { "Accounting Output Packets", NULL, 0, 0, print_attr_num },
392 { "Accounting Termination Cause", acct_term, TAM_SIZE(acct_term)-1, 1, print_attr_num },
393 { "Accounting Multilink Session ID", NULL, 0, 0, print_attr_string },
394 { "Accounting Link Count", NULL, 0, 0, print_attr_num },
395 { "Accounting Input Giga", NULL, 0, 0, print_attr_num },
396 { "Accounting Output Giga", NULL, 0, 0, print_attr_num },
397 { "Unassigned", NULL, 0, 0, NULL }, /*54*/
398 { "Event Timestamp", NULL, 0, 0, print_attr_time },
399 { "Unassigned", NULL, 0, 0, NULL }, /*56*/
400 { "Unassigned", NULL, 0, 0, NULL }, /*57*/
401 { "Unassigned", NULL, 0, 0, NULL }, /*58*/
402 { "Unassigned", NULL, 0, 0, NULL }, /*59*/
403 { "CHAP challenge", NULL, 0, 0, print_attr_string },
404 { "NAS Port Type", nas_port_type, TAM_SIZE(nas_port_type), 0, print_attr_num },
405 { "Port Limit", NULL, 0, 0, print_attr_num },
406 { "Login LAT Port", NULL, 0, 0, print_attr_string }, /*63*/
407 { "Tunnel Type", tunnel_type, TAM_SIZE(tunnel_type)-1, 1, print_attr_num },
408 { "Tunnel Medium", tunnel_medium, TAM_SIZE(tunnel_medium)-1, 1, print_attr_num },
409 { "Tunnel Client End", NULL, 0, 0, print_attr_string },
410 { "Tunnel Server End", NULL, 0, 0, print_attr_string },
411 { "Accounting Tunnel connect", NULL, 0, 0, print_attr_string },
412 { "Tunnel Password", NULL, 0, 0, print_attr_string },
413 { "ARAP Password", NULL, 0, 0, print_attr_strange },
414 { "ARAP Feature", NULL, 0, 0, print_attr_strange },
415 { "ARAP Zone Acces", arap_zone, TAM_SIZE(arap_zone)-1, 1, print_attr_num }, /*72*/
416 { "ARAP Security", NULL, 0, 0, print_attr_string },
417 { "ARAP Security Data", NULL, 0, 0, print_attr_string },
418 { "Password Retry", NULL, 0, 0, print_attr_num },
419 { "Prompt", prompt, TAM_SIZE(prompt), 0, print_attr_num },
420 { "Connect Info", NULL, 0, 0, print_attr_string },
421 { "Config Token", NULL, 0, 0, print_attr_string },
422 { "EAP Message", NULL, 0, 0, print_attr_string },
423 { "Message Authentication", NULL, 0, 0, print_attr_string }, /*80*/
424 { "Tunnel Private Group", NULL, 0, 0, print_attr_string },
425 { "Tunnel Assigned ID", NULL, 0, 0, print_attr_string },
426 { "Tunnel Preference", NULL, 0, 0, print_attr_num },
427 { "ARAP Challenge Response", NULL, 0, 0, print_attr_strange },
428 { "Accounting Interim Interval", NULL, 0, 0, print_attr_num },
429 { "Accounting Tunnel packets lost", NULL, 0, 0, print_attr_num }, /*86*/
430 { "NAS Port ID", NULL, 0, 0, print_attr_string },
431 { "Framed Pool", NULL, 0, 0, print_attr_string },
432 { "Unassigned", NULL, 0, 0, NULL },
433 { "Tunnel Client Authentication ID", NULL, 0, 0, print_attr_string },
434 { "Tunnel Server Authentication ID", NULL, 0, 0, print_attr_string },
435 { "Unassigned", NULL, 0, 0, NULL }, /*92*/
436 { "Unassigned", NULL, 0, 0, NULL } /*93*/
440 /*****************************/
441 /* Print an attribute string */
442 /* value pointed by 'data' */
443 /* and 'length' size. */
444 /*****************************/
445 /* Returns nothing. */
446 /*****************************/
448 print_attr_string(register u_char *data, u_int length, u_short attr_code )
452 TCHECK2(data[0],length);
459 printf(" [|radius]");
462 if (*data && (*data <=0x1F) )
463 printf("Tag %u, ",*data);
466 printf("Salt %u ",EXTRACT_16BITS(data) );
470 case TUNNEL_CLIENT_END:
471 case TUNNEL_SERVER_END:
472 case TUNNEL_PRIV_GROUP:
473 case TUNNEL_ASSIGN_ID:
474 case TUNNEL_CLIENT_AUTH:
475 case TUNNEL_SERVER_AUTH:
480 printf(" [|radius]");
483 printf("Tag %u",*data);
490 for (i=0; *data && i < length ; i++, data++)
491 printf("%c",(*data < 32 || *data > 128) ? '.' : *data );
496 printf(" [|radius]");
500 * print vendor specific attributes
504 print_vendor_attr(register u_char *data, u_int length, u_short attr_code _U_)
514 vendor_id = EXTRACT_32BITS(data);
518 printf("Vendor: %s (%u)",
519 tok2str(smi_values,"Unknown",vendor_id),
522 while (length >= 2) {
525 vendor_type = *(data);
526 vendor_length = *(data+1);
528 if (vendor_length < 2)
530 printf("\n\t Vendor Attribute: %u, Length: %u (bogus, must be >= 2)",
535 if (vendor_length > length)
537 printf("\n\t Vendor Attribute: %u, Length: %u (bogus, goes past end of vendor-specific attribute)",
545 TCHECK2(*data, vendor_length);
547 printf("\n\t Vendor Attribute: %u, Length: %u, Value: ",
550 for (idx = 0; idx < vendor_length ; idx++, data++)
551 printf("%c",(*data < 32 || *data > 128) ? '.' : *data );
552 length-=vendor_length;
557 printf(" [|radius]");
562 /******************************/
563 /* Print an attribute numeric */
564 /* value pointed by 'data' */
565 /* and 'length' size. */
566 /******************************/
567 /* Returns nothing. */
568 /******************************/
570 print_attr_num(register u_char *data, u_int length, u_short attr_code )
577 printf("ERROR: length %u != 4", length);
582 /* This attribute has standard values */
583 if (attr_type[attr_code].siz_subtypes)
585 static const char **table;
586 u_int32_t data_value;
587 table = attr_type[attr_code].subtypes;
589 if ( (attr_code == TUNNEL_TYPE) || (attr_code == TUNNEL_MEDIUM) )
592 printf("Tag[Unused]");
594 printf("Tag[%d]", *data);
596 data_value = EXTRACT_24BITS(data);
600 data_value = EXTRACT_32BITS(data);
602 if ( data_value <= (u_int32_t)(attr_type[attr_code].siz_subtypes - 1 +
603 attr_type[attr_code].first_subtype) &&
604 data_value >= attr_type[attr_code].first_subtype )
605 printf("%s",table[data_value]);
607 printf("#%u",data_value);
611 switch(attr_code) /* Be aware of special cases... */
614 if (EXTRACT_32BITS( data) == 0xFFFFFFFE )
615 printf("NAS Select");
617 printf("%d",EXTRACT_32BITS( data) );
620 case SESSION_TIMEOUT:
623 case ACCT_SESSION_TIME:
624 case ACCT_INT_INTERVAL:
625 timeout = EXTRACT_32BITS( data);
627 printf( "%02d secs", timeout);
630 if ( timeout < 3600 )
631 printf( "%02d:%02d min",
632 timeout / 60, timeout % 60);
634 printf( "%02d:%02d:%02d hours",
635 timeout / 3600, (timeout % 3600) / 60,
641 if (EXTRACT_32BITS(data) )
642 printf("%d",EXTRACT_32BITS(data) );
644 printf("Unnumbered" );
647 case FRM_ATALK_NETWORK:
648 if (EXTRACT_32BITS(data) )
649 printf("%d",EXTRACT_32BITS(data) );
651 printf("NAS assigned" );
654 case TUNNEL_PREFERENCE:
658 printf("Tag (Unused) %d",EXTRACT_24BITS(data) );
660 printf("Tag (%d) %d", tag, EXTRACT_24BITS(data) );
664 printf("%d",EXTRACT_32BITS( data) );
674 printf(" [|radius]");
678 /*****************************/
679 /* Print an attribute IPv4 */
680 /* address value pointed by */
681 /* 'data' and 'length' size. */
682 /*****************************/
683 /* Returns nothing. */
684 /*****************************/
686 print_attr_address(register u_char *data, u_int length, u_short attr_code )
690 printf("ERROR: length %u != 4", length);
700 if (EXTRACT_32BITS(data) == 0xFFFFFFFF )
701 printf("User Selected");
703 if (EXTRACT_32BITS(data) == 0xFFFFFFFE )
704 printf("NAS Select");
706 printf("%s",ipaddr_string(data));
710 printf("%s",ipaddr_string(data) );
717 printf(" [|radius]");
721 /*************************************/
722 /* Print an attribute of 'secs since */
723 /* January 1, 1970 00:00 UTC' value */
724 /* pointed by 'data' and 'length' */
726 /*************************************/
727 /* Returns nothing. */
728 /*************************************/
729 static void print_attr_time(register u_char *data, u_int length, u_short attr_code _U_)
736 printf("ERROR: length %u != 4", length);
742 attr_time = EXTRACT_32BITS(data);
743 strlcpy(string, ctime(&attr_time), sizeof(string));
744 /* Get rid of the newline */
746 printf("%.24s", string);
750 printf(" [|radius]");
754 /***********************************/
755 /* Print an attribute of 'strange' */
756 /* data format pointed by 'data' */
757 /* and 'length' size. */
758 /***********************************/
759 /* Returns nothing. */
760 /***********************************/
761 static void print_attr_strange(register u_char *data, u_int length, u_short attr_code)
770 printf("ERROR: length %u != 16", length);
773 printf("User_challenge (");
776 PRINT_HEX(len_data, data);
777 printf(") User_resp(");
780 PRINT_HEX(len_data, data);
787 printf("ERROR: length %u != 14", length);
792 printf("User can change password");
794 printf("User cannot change password");
797 printf(", Min password length: %d",*data);
799 printf(", created at: ");
802 PRINT_HEX(len_data, data);
803 printf(", expires in: ");
806 PRINT_HEX(len_data, data);
807 printf(", Current Time: ");
810 PRINT_HEX(len_data, data);
813 case ARAP_CHALLENGE_RESP:
816 printf("ERROR: length %u != 8", length);
821 PRINT_HEX(len_data, data);
827 printf(" [|radius]");
833 radius_attrs_print(register const u_char *attr, u_int length)
835 register const struct radius_attr *rad_attr = (struct radius_attr *)attr;
836 const char *attr_string;
844 if (rad_attr->type > 0 && rad_attr->type < TAM_SIZE(attr_type))
845 attr_string = attr_type[rad_attr->type].name;
847 attr_string = "Unknown";
848 if (rad_attr->len < 2)
850 printf("\n\t %s Attribute (%u), length: %u (bogus, must be >= 2)",
856 if (rad_attr->len > length)
858 printf("\n\t %s Attribute (%u), length: %u (bogus, goes past end of packet)",
864 printf("\n\t %s Attribute (%u), length: %u, Value: ",
869 if (rad_attr->type < TAM_SIZE(attr_type))
871 if (rad_attr->len > 2)
873 if ( attr_type[rad_attr->type].print_func )
874 (*attr_type[rad_attr->type].print_func)(
875 ((u_char *)(rad_attr+1)),
876 rad_attr->len - 2, rad_attr->type);
879 /* do we also want to see a hex dump ? */
881 print_unknown_data((u_char *)rad_attr+2,"\n\t ",(rad_attr->len)-2);
883 length-=(rad_attr->len);
884 rad_attr = (struct radius_attr *)( ((char *)(rad_attr))+rad_attr->len);
889 printf(" [|radius]");
894 radius_print(const u_char *dat, u_int length)
896 register const struct radius_hdr *rad;
899 TCHECK2(*dat, MIN_RADIUS_LEN);
900 rad = (struct radius_hdr *)dat;
901 len = EXTRACT_16BITS(&rad->len);
903 if (len < MIN_RADIUS_LEN)
905 printf(" [|radius]");
913 printf("RADIUS, %s (%u), id: 0x%02x length: %u",
914 tok2str(radius_command_values,"Unknown Command",rad->code),
921 printf("RADIUS, length: %u\n\t%s (%u), id: 0x%02x, Authenticator: ",
923 tok2str(radius_command_values,"Unknown Command",rad->code),
927 for(auth_idx=0; auth_idx < 16; auth_idx++)
928 printf("%02x", rad->auth[auth_idx] );
931 if (len > MIN_RADIUS_LEN)
932 radius_attrs_print( dat + MIN_RADIUS_LEN, len - MIN_RADIUS_LEN);
936 printf(" [|radius]");