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 static const char tstr
[] = " [|radius]";
67 #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )
69 #define PRINT_HEX(bytes_len, ptr_data) \
72 printf("%02X", *ptr_data ); \
78 /* Radius packet codes */
79 #define RADCMD_ACCESS_REQ 1 /* Access-Request */
80 #define RADCMD_ACCESS_ACC 2 /* Access-Accept */
81 #define RADCMD_ACCESS_REJ 3 /* Access-Reject */
82 #define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */
83 #define RADCMD_ACCOUN_RES 5 /* Accounting-Response */
84 #define RADCMD_ACCESS_CHA 11 /* Access-Challenge */
85 #define RADCMD_STATUS_SER 12 /* Status-Server */
86 #define RADCMD_STATUS_CLI 13 /* Status-Client */
87 #define RADCMD_RESERVED 255 /* Reserved */
89 static const struct tok radius_command_values
[] = {
90 { RADCMD_ACCESS_REQ
, "Access Request" },
91 { RADCMD_ACCESS_ACC
, "Access Accept" },
92 { RADCMD_ACCESS_REJ
, "Access Reject" },
93 { RADCMD_ACCOUN_REQ
, "Accounting Request" },
94 { RADCMD_ACCOUN_RES
, "Accounting Response" },
95 { RADCMD_ACCESS_CHA
, "Access Challenge" },
96 { RADCMD_STATUS_SER
, "Status Server" },
97 { RADCMD_STATUS_CLI
, "Status Client" },
98 { RADCMD_RESERVED
, "Reserved" },
102 /********************************/
103 /* Begin Radius Attribute types */
104 /********************************/
107 #define LOG_IPHOST 14
108 #define LOG_SERVICE 15
110 #define SESSION_TIMEOUT 27
111 #define IDLE_TIMEOUT 28
112 #define FRM_ATALK_LINK 37
113 #define FRM_ATALK_NETWORK 38
115 #define ACCT_DELAY 41
116 #define ACCT_SESSION_TIME 46
118 #define TUNNEL_TYPE 64
119 #define TUNNEL_MEDIUM 65
120 #define TUNNEL_CLIENT_END 66
121 #define TUNNEL_SERVER_END 67
122 #define TUNNEL_PASS 69
125 #define ARAP_FEATURES 71
127 #define TUNNEL_PRIV_GROUP 81
128 #define TUNNEL_ASSIGN_ID 82
129 #define TUNNEL_PREFERENCE 83
131 #define ARAP_CHALLENGE_RESP 84
132 #define ACCT_INT_INTERVAL 85
134 #define TUNNEL_CLIENT_AUTH 90
135 #define TUNNEL_SERVER_AUTH 91
136 /********************************/
137 /* End Radius Attribute types */
138 /********************************/
141 static void print_attr_string(register u_char
*, u_int
, u_short
);
142 static void print_attr_num(register u_char
*, u_int
, u_short
);
143 static void print_vendor_attr(register u_char
*, u_int
, u_short
);
144 static void print_attr_address(register u_char
*, u_int
, u_short
);
145 static void print_attr_time(register u_char
*, u_int
, u_short
);
146 static void print_attr_strange(register u_char
*, u_int
, u_short
);
149 struct radius_hdr
{ u_int8_t code
; /* Radius packet code */
150 u_int8_t id
; /* Radius packet id */
151 u_int16_t len
; /* Radius total length */
152 u_int8_t auth
[16]; /* Authenticator */
155 #define MIN_RADIUS_LEN 20
157 struct radius_attr
{ u_int8_t type
; /* Attribute type */
158 u_int8_t len
; /* Attribute length */
162 /* Service-Type Attribute standard values */
163 static const char *serv_type
[]={ NULL
,
172 "Callback NAS Prompt",
174 "Callback Administrative",
177 /* Framed-Protocol Attribute standard values */
178 static const char *frm_proto
[]={ NULL
,
182 "Gandalf proprietary",
187 /* Framed-Routing Attribute standard values */
188 static const char *frm_routing
[]={ "None",
194 /* Framed-Compression Attribute standard values */
195 static const char *frm_comp
[]={ "None",
201 /* Login-Service Attribute standard values */
202 static const char *login_serv
[]={ "Telnet",
205 "PortMaster(proprietary)",
214 /* Termination-Action Attribute standard values */
215 static const char *term_action
[]={ "Default",
219 /* NAS-Port-Type Attribute standard values */
220 static const char *nas_port_type
[]={ "Async",
227 "HDLC Clear Channel",
239 "Wireless - IEEE 802.11",
242 /* Acct-Status-Type Accounting Attribute standard values */
243 static const char *acct_status
[]={ NULL
,
257 "Tunnel-Link-Reject",
261 /* Acct-Authentic Accounting Attribute standard values */
262 static const char *acct_auth
[]={ NULL
,
268 /* Acct-Terminate-Cause Accounting Attribute standard values */
269 static const char *acct_term
[]={ NULL
,
284 "Service Unavailable",
290 /* Tunnel-Type Attribute standard values */
291 static const char *tunnel_type
[]={ NULL
,
303 "IP-in-IP Tunneling",
306 /* Tunnel-Medium-Type Attribute standard values */
307 static const char *tunnel_medium
[]={ NULL
,
322 "E.164 with NSAP subaddress",
325 /* ARAP-Zone-Access Attribute standard values */
326 static const char *arap_zone
[]={ NULL
,
327 "Only access to dfl zone",
328 "Use zone filter inc.",
330 "Use zone filter exc.",
333 static const char *prompt
[]={ "No Echo",
338 struct attrtype
{ const char *name
; /* Attribute name */
339 const char **subtypes
; /* Standard Values (if any) */
340 u_char siz_subtypes
; /* Size of total standard values */
341 u_char first_subtype
; /* First standard value is 0 or 1 */
342 void (*print_func
)(register u_char
*, u_int
, u_short
);
345 { NULL
, NULL
, 0, 0, NULL
},
346 { "Username", NULL
, 0, 0, print_attr_string
},
347 { "Password", NULL
, 0, 0, NULL
},
348 { "CHAP Password", NULL
, 0, 0, NULL
},
349 { "NAS IP Address", NULL
, 0, 0, print_attr_address
},
350 { "NAS Port", NULL
, 0, 0, print_attr_num
},
351 { "Service Type", serv_type
, TAM_SIZE(serv_type
)-1, 1, print_attr_num
},
352 { "Framed Protocol", frm_proto
, TAM_SIZE(frm_proto
)-1, 1, print_attr_num
},
353 { "Framed IP Address", NULL
, 0, 0, print_attr_address
},
354 { "Framed IP Network", NULL
, 0, 0, print_attr_address
},
355 { "Framed Routing", frm_routing
, TAM_SIZE(frm_routing
), 0, print_attr_num
},
356 { "Filter ID", NULL
, 0, 0, print_attr_string
},
357 { "Framed MTU", NULL
, 0, 0, print_attr_num
},
358 { "Framed Compression", frm_comp
, TAM_SIZE(frm_comp
), 0, print_attr_num
},
359 { "Login IP Host", NULL
, 0, 0, print_attr_address
},
360 { "Login Service", login_serv
, TAM_SIZE(login_serv
), 0, print_attr_num
},
361 { "Login TCP Port", NULL
, 0, 0, print_attr_num
},
362 { "Unassigned", NULL
, 0, 0, NULL
}, /*17*/
363 { "Reply", NULL
, 0, 0, print_attr_string
},
364 { "Callback-number", NULL
, 0, 0, print_attr_string
},
365 { "Callback-ID", NULL
, 0, 0, print_attr_string
},
366 { "Unassigned", NULL
, 0, 0, NULL
}, /*21*/
367 { "Framed Route", NULL
, 0, 0, print_attr_string
},
368 { "Framed IPX Network", NULL
, 0, 0, print_attr_num
},
369 { "State", NULL
, 0, 0, print_attr_string
},
370 { "Class", NULL
, 0, 0, print_attr_string
},
371 { "Vendor Specific", NULL
, 0, 0, print_vendor_attr
},
372 { "Session Timeout", NULL
, 0, 0, print_attr_num
},
373 { "Idle Timeout", NULL
, 0, 0, print_attr_num
},
374 { "Termination Action", term_action
, TAM_SIZE(term_action
), 0, print_attr_num
},
375 { "Called Station", NULL
, 0, 0, print_attr_string
},
376 { "Calling Station", NULL
, 0, 0, print_attr_string
},
377 { "NAS ID", NULL
, 0, 0, print_attr_string
},
378 { "Proxy State", NULL
, 0, 0, print_attr_string
},
379 { "Login LAT Service", NULL
, 0, 0, print_attr_string
},
380 { "Login LAT Node", NULL
, 0, 0, print_attr_string
},
381 { "Login LAT Group", NULL
, 0, 0, print_attr_string
},
382 { "Framed Appletalk Link", NULL
, 0, 0, print_attr_num
},
383 { "Framed Appltalk Net", NULL
, 0, 0, print_attr_num
},
384 { "Framed Appletalk Zone", NULL
, 0, 0, print_attr_string
},
385 { "Accounting Status", acct_status
, TAM_SIZE(acct_status
)-1, 1, print_attr_num
},
386 { "Accounting Delay", NULL
, 0, 0, print_attr_num
},
387 { "Accounting Input Octets", NULL
, 0, 0, print_attr_num
},
388 { "Accounting Output Octets", NULL
, 0, 0, print_attr_num
},
389 { "Accounting Session ID", NULL
, 0, 0, print_attr_string
},
390 { "Accounting Authentication", acct_auth
, TAM_SIZE(acct_auth
)-1, 1, print_attr_num
},
391 { "Accounting Session Time", NULL
, 0, 0, print_attr_num
},
392 { "Accounting Input Packets", NULL
, 0, 0, print_attr_num
},
393 { "Accounting Output Packets", NULL
, 0, 0, print_attr_num
},
394 { "Accounting Termination Cause", acct_term
, TAM_SIZE(acct_term
)-1, 1, print_attr_num
},
395 { "Accounting Multilink Session ID", NULL
, 0, 0, print_attr_string
},
396 { "Accounting Link Count", NULL
, 0, 0, print_attr_num
},
397 { "Accounting Input Giga", NULL
, 0, 0, print_attr_num
},
398 { "Accounting Output Giga", NULL
, 0, 0, print_attr_num
},
399 { "Unassigned", NULL
, 0, 0, NULL
}, /*54*/
400 { "Event Timestamp", NULL
, 0, 0, print_attr_time
},
401 { "Unassigned", NULL
, 0, 0, NULL
}, /*56*/
402 { "Unassigned", NULL
, 0, 0, NULL
}, /*57*/
403 { "Unassigned", NULL
, 0, 0, NULL
}, /*58*/
404 { "Unassigned", NULL
, 0, 0, NULL
}, /*59*/
405 { "CHAP challenge", NULL
, 0, 0, print_attr_string
},
406 { "NAS Port Type", nas_port_type
, TAM_SIZE(nas_port_type
), 0, print_attr_num
},
407 { "Port Limit", NULL
, 0, 0, print_attr_num
},
408 { "Login LAT Port", NULL
, 0, 0, print_attr_string
}, /*63*/
409 { "Tunnel Type", tunnel_type
, TAM_SIZE(tunnel_type
)-1, 1, print_attr_num
},
410 { "Tunnel Medium", tunnel_medium
, TAM_SIZE(tunnel_medium
)-1, 1, print_attr_num
},
411 { "Tunnel Client End", NULL
, 0, 0, print_attr_string
},
412 { "Tunnel Server End", NULL
, 0, 0, print_attr_string
},
413 { "Accounting Tunnel connect", NULL
, 0, 0, print_attr_string
},
414 { "Tunnel Password", NULL
, 0, 0, print_attr_string
},
415 { "ARAP Password", NULL
, 0, 0, print_attr_strange
},
416 { "ARAP Feature", NULL
, 0, 0, print_attr_strange
},
417 { "ARAP Zone Acces", arap_zone
, TAM_SIZE(arap_zone
)-1, 1, print_attr_num
}, /*72*/
418 { "ARAP Security", NULL
, 0, 0, print_attr_string
},
419 { "ARAP Security Data", NULL
, 0, 0, print_attr_string
},
420 { "Password Retry", NULL
, 0, 0, print_attr_num
},
421 { "Prompt", prompt
, TAM_SIZE(prompt
), 0, print_attr_num
},
422 { "Connect Info", NULL
, 0, 0, print_attr_string
},
423 { "Config Token", NULL
, 0, 0, print_attr_string
},
424 { "EAP Message", NULL
, 0, 0, print_attr_string
},
425 { "Message Authentication", NULL
, 0, 0, print_attr_string
}, /*80*/
426 { "Tunnel Private Group", NULL
, 0, 0, print_attr_string
},
427 { "Tunnel Assigned ID", NULL
, 0, 0, print_attr_string
},
428 { "Tunnel Preference", NULL
, 0, 0, print_attr_num
},
429 { "ARAP Challenge Response", NULL
, 0, 0, print_attr_strange
},
430 { "Accounting Interim Interval", NULL
, 0, 0, print_attr_num
},
431 { "Accounting Tunnel packets lost", NULL
, 0, 0, print_attr_num
}, /*86*/
432 { "NAS Port ID", NULL
, 0, 0, print_attr_string
},
433 { "Framed Pool", NULL
, 0, 0, print_attr_string
},
434 { "Unassigned", NULL
, 0, 0, NULL
},
435 { "Tunnel Client Authentication ID", NULL
, 0, 0, print_attr_string
},
436 { "Tunnel Server Authentication ID", NULL
, 0, 0, print_attr_string
},
437 { "Unassigned", NULL
, 0, 0, NULL
}, /*92*/
438 { "Unassigned", NULL
, 0, 0, NULL
} /*93*/
442 /*****************************/
443 /* Print an attribute string */
444 /* value pointed by 'data' */
445 /* and 'length' size. */
446 /*****************************/
447 /* Returns nothing. */
448 /*****************************/
450 print_attr_string(register u_char
*data
, u_int length
, u_short attr_code
)
454 TCHECK2(data
[0],length
);
464 if (*data
&& (*data
<=0x1F) )
465 printf("Tag %u, ",*data
);
468 printf("Salt %u ",EXTRACT_16BITS(data
) );
472 case TUNNEL_CLIENT_END
:
473 case TUNNEL_SERVER_END
:
474 case TUNNEL_PRIV_GROUP
:
475 case TUNNEL_ASSIGN_ID
:
476 case TUNNEL_CLIENT_AUTH
:
477 case TUNNEL_SERVER_AUTH
:
485 printf("Tag %u",*data
);
492 for (i
=0; *data
&& i
< length
; i
++, data
++)
493 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
502 * print vendor specific attributes
506 print_vendor_attr(register u_char
*data
, u_int length
, u_short attr_code _U_
)
516 vendor_id
= EXTRACT_32BITS(data
);
520 printf("Vendor: %s (%u)",
521 tok2str(smi_values
,"Unknown",vendor_id
),
524 while (length
>= 2) {
527 vendor_type
= *(data
);
528 vendor_length
= *(data
+1);
530 if (vendor_length
< 2)
532 printf("\n\t Vendor Attribute: %u, Length: %u (bogus, must be >= 2)",
537 if (vendor_length
> length
)
539 printf("\n\t Vendor Attribute: %u, Length: %u (bogus, goes past end of vendor-specific attribute)",
547 TCHECK2(*data
, vendor_length
);
549 printf("\n\t Vendor Attribute: %u, Length: %u, Value: ",
552 for (idx
= 0; idx
< vendor_length
; idx
++, data
++)
553 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
554 length
-=vendor_length
;
564 /******************************/
565 /* Print an attribute numeric */
566 /* value pointed by 'data' */
567 /* and 'length' size. */
568 /******************************/
569 /* Returns nothing. */
570 /******************************/
572 print_attr_num(register u_char
*data
, u_int length
, u_short attr_code
)
579 printf("ERROR: length %u != 4", length
);
584 /* This attribute has standard values */
585 if (attr_type
[attr_code
].siz_subtypes
)
587 static const char **table
;
588 u_int32_t data_value
;
589 table
= attr_type
[attr_code
].subtypes
;
591 if ( (attr_code
== TUNNEL_TYPE
) || (attr_code
== TUNNEL_MEDIUM
) )
594 printf("Tag[Unused]");
596 printf("Tag[%d]", *data
);
598 data_value
= EXTRACT_24BITS(data
);
602 data_value
= EXTRACT_32BITS(data
);
604 if ( data_value
<= (u_int32_t
)(attr_type
[attr_code
].siz_subtypes
- 1 +
605 attr_type
[attr_code
].first_subtype
) &&
606 data_value
>= attr_type
[attr_code
].first_subtype
)
607 printf("%s",table
[data_value
]);
609 printf("#%u",data_value
);
613 switch(attr_code
) /* Be aware of special cases... */
616 if (EXTRACT_32BITS( data
) == 0xFFFFFFFE )
617 printf("NAS Select");
619 printf("%d",EXTRACT_32BITS( data
) );
622 case SESSION_TIMEOUT
:
625 case ACCT_SESSION_TIME
:
626 case ACCT_INT_INTERVAL
:
627 timeout
= EXTRACT_32BITS( data
);
629 printf( "%02d secs", timeout
);
632 if ( timeout
< 3600 )
633 printf( "%02d:%02d min",
634 timeout
/ 60, timeout
% 60);
636 printf( "%02d:%02d:%02d hours",
637 timeout
/ 3600, (timeout
% 3600) / 60,
643 if (EXTRACT_32BITS(data
) )
644 printf("%d",EXTRACT_32BITS(data
) );
646 printf("Unnumbered" );
649 case FRM_ATALK_NETWORK
:
650 if (EXTRACT_32BITS(data
) )
651 printf("%d",EXTRACT_32BITS(data
) );
653 printf("NAS assigned" );
656 case TUNNEL_PREFERENCE
:
660 printf("Tag (Unused) %d",EXTRACT_24BITS(data
) );
662 printf("Tag (%d) %d", tag
, EXTRACT_24BITS(data
) );
666 printf("%d",EXTRACT_32BITS( data
) );
680 /*****************************/
681 /* Print an attribute IPv4 */
682 /* address value pointed by */
683 /* 'data' and 'length' size. */
684 /*****************************/
685 /* Returns nothing. */
686 /*****************************/
688 print_attr_address(register u_char
*data
, u_int length
, u_short attr_code
)
692 printf("ERROR: length %u != 4", length
);
702 if (EXTRACT_32BITS(data
) == 0xFFFFFFFF )
703 printf("User Selected");
705 if (EXTRACT_32BITS(data
) == 0xFFFFFFFE )
706 printf("NAS Select");
708 printf("%s",ipaddr_string(data
));
712 printf("%s",ipaddr_string(data
) );
723 /*************************************/
724 /* Print an attribute of 'secs since */
725 /* January 1, 1970 00:00 UTC' value */
726 /* pointed by 'data' and 'length' */
728 /*************************************/
729 /* Returns nothing. */
730 /*************************************/
731 static void print_attr_time(register u_char
*data
, u_int length
, u_short attr_code _U_
)
738 printf("ERROR: length %u != 4", length
);
744 attr_time
= EXTRACT_32BITS(data
);
745 strlcpy(string
, ctime(&attr_time
), sizeof(string
));
746 /* Get rid of the newline */
748 printf("%.24s", string
);
756 /***********************************/
757 /* Print an attribute of 'strange' */
758 /* data format pointed by 'data' */
759 /* and 'length' size. */
760 /***********************************/
761 /* Returns nothing. */
762 /***********************************/
763 static void print_attr_strange(register u_char
*data
, u_int length
, u_short attr_code
)
772 printf("ERROR: length %u != 16", length
);
775 printf("User_challenge (");
778 PRINT_HEX(len_data
, data
);
779 printf(") User_resp(");
782 PRINT_HEX(len_data
, data
);
789 printf("ERROR: length %u != 14", length
);
794 printf("User can change password");
796 printf("User cannot change password");
799 printf(", Min password length: %d",*data
);
801 printf(", created at: ");
804 PRINT_HEX(len_data
, data
);
805 printf(", expires in: ");
808 PRINT_HEX(len_data
, data
);
809 printf(", Current Time: ");
812 PRINT_HEX(len_data
, data
);
815 case ARAP_CHALLENGE_RESP
:
818 printf("ERROR: length %u != 8", length
);
823 PRINT_HEX(len_data
, data
);
835 radius_attrs_print(register const u_char
*attr
, u_int length
)
837 register const struct radius_attr
*rad_attr
= (struct radius_attr
*)attr
;
838 const char *attr_string
;
846 if (rad_attr
->type
> 0 && rad_attr
->type
< TAM_SIZE(attr_type
))
847 attr_string
= attr_type
[rad_attr
->type
].name
;
849 attr_string
= "Unknown";
850 if (rad_attr
->len
< 2)
852 printf("\n\t %s Attribute (%u), length: %u (bogus, must be >= 2)",
858 if (rad_attr
->len
> length
)
860 printf("\n\t %s Attribute (%u), length: %u (bogus, goes past end of packet)",
866 printf("\n\t %s Attribute (%u), length: %u, Value: ",
871 if (rad_attr
->type
< TAM_SIZE(attr_type
))
873 if (rad_attr
->len
> 2)
875 if ( attr_type
[rad_attr
->type
].print_func
)
876 (*attr_type
[rad_attr
->type
].print_func
)(
877 ((u_char
*)(rad_attr
+1)),
878 rad_attr
->len
- 2, rad_attr
->type
);
881 /* do we also want to see a hex dump ? */
883 print_unknown_data(gndo
,(u_char
*)rad_attr
+2,"\n\t ",(rad_attr
->len
)-2);
885 length
-=(rad_attr
->len
);
886 rad_attr
= (struct radius_attr
*)( ((char *)(rad_attr
))+rad_attr
->len
);
896 radius_print(const u_char
*dat
, u_int length
)
898 register const struct radius_hdr
*rad
;
901 TCHECK2(*dat
, MIN_RADIUS_LEN
);
902 rad
= (struct radius_hdr
*)dat
;
903 len
= EXTRACT_16BITS(&rad
->len
);
905 if (len
< MIN_RADIUS_LEN
)
915 printf("RADIUS, %s (%u), id: 0x%02x length: %u",
916 tok2str(radius_command_values
,"Unknown Command",rad
->code
),
923 printf("RADIUS, length: %u\n\t%s (%u), id: 0x%02x, Authenticator: ",
925 tok2str(radius_command_values
,"Unknown Command",rad
->code
),
929 for(auth_idx
=0; auth_idx
< 16; auth_idx
++)
930 printf("%02x", rad
->auth
[auth_idx
] );
933 if (len
> MIN_RADIUS_LEN
)
934 radius_attrs_print( dat
+ MIN_RADIUS_LEN
, len
- MIN_RADIUS_LEN
);