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
49 #include <tcpdump-stdinc.h>
55 #include "interface.h"
56 #include "addrtoname.h"
60 static const char tstr
[] = " [|radius]";
62 #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )
64 #define PRINT_HEX(bytes_len, ptr_data) \
67 printf("%02X", *ptr_data ); \
73 /* Radius packet codes */
74 #define RADCMD_ACCESS_REQ 1 /* Access-Request */
75 #define RADCMD_ACCESS_ACC 2 /* Access-Accept */
76 #define RADCMD_ACCESS_REJ 3 /* Access-Reject */
77 #define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */
78 #define RADCMD_ACCOUN_RES 5 /* Accounting-Response */
79 #define RADCMD_ACCESS_CHA 11 /* Access-Challenge */
80 #define RADCMD_STATUS_SER 12 /* Status-Server */
81 #define RADCMD_STATUS_CLI 13 /* Status-Client */
82 #define RADCMD_RESERVED 255 /* Reserved */
84 static const struct tok radius_command_values
[] = {
85 { RADCMD_ACCESS_REQ
, "Access Request" },
86 { RADCMD_ACCESS_ACC
, "Access Accept" },
87 { RADCMD_ACCESS_REJ
, "Access Reject" },
88 { RADCMD_ACCOUN_REQ
, "Accounting Request" },
89 { RADCMD_ACCOUN_RES
, "Accounting Response" },
90 { RADCMD_ACCESS_CHA
, "Access Challenge" },
91 { RADCMD_STATUS_SER
, "Status Server" },
92 { RADCMD_STATUS_CLI
, "Status Client" },
93 { RADCMD_RESERVED
, "Reserved" },
97 /********************************/
98 /* Begin Radius Attribute types */
99 /********************************/
102 #define LOG_IPHOST 14
103 #define LOG_SERVICE 15
105 #define SESSION_TIMEOUT 27
106 #define IDLE_TIMEOUT 28
107 #define FRM_ATALK_LINK 37
108 #define FRM_ATALK_NETWORK 38
110 #define ACCT_DELAY 41
111 #define ACCT_SESSION_TIME 46
113 #define TUNNEL_TYPE 64
114 #define TUNNEL_MEDIUM 65
115 #define TUNNEL_CLIENT_END 66
116 #define TUNNEL_SERVER_END 67
117 #define TUNNEL_PASS 69
120 #define ARAP_FEATURES 71
122 #define TUNNEL_PRIV_GROUP 81
123 #define TUNNEL_ASSIGN_ID 82
124 #define TUNNEL_PREFERENCE 83
126 #define ARAP_CHALLENGE_RESP 84
127 #define ACCT_INT_INTERVAL 85
129 #define TUNNEL_CLIENT_AUTH 90
130 #define TUNNEL_SERVER_AUTH 91
131 /********************************/
132 /* End Radius Attribute types */
133 /********************************/
136 static void print_attr_string(register u_char
*, u_int
, u_short
);
137 static void print_attr_num(register u_char
*, u_int
, u_short
);
138 static void print_vendor_attr(register u_char
*, u_int
, u_short
);
139 static void print_attr_address(register u_char
*, u_int
, u_short
);
140 static void print_attr_time(register u_char
*, u_int
, u_short
);
141 static void print_attr_strange(register u_char
*, u_int
, u_short
);
144 struct radius_hdr
{ u_int8_t code
; /* Radius packet code */
145 u_int8_t id
; /* Radius packet id */
146 u_int16_t len
; /* Radius total length */
147 u_int8_t auth
[16]; /* Authenticator */
150 #define MIN_RADIUS_LEN 20
152 struct radius_attr
{ u_int8_t type
; /* Attribute type */
153 u_int8_t len
; /* Attribute length */
157 /* Service-Type Attribute standard values */
158 static const char *serv_type
[]={ NULL
,
167 "Callback NAS Prompt",
169 "Callback Administrative",
172 /* Framed-Protocol Attribute standard values */
173 static const char *frm_proto
[]={ NULL
,
177 "Gandalf proprietary",
182 /* Framed-Routing Attribute standard values */
183 static const char *frm_routing
[]={ "None",
189 /* Framed-Compression Attribute standard values */
190 static const char *frm_comp
[]={ "None",
196 /* Login-Service Attribute standard values */
197 static const char *login_serv
[]={ "Telnet",
200 "PortMaster(proprietary)",
209 /* Termination-Action Attribute standard values */
210 static const char *term_action
[]={ "Default",
214 /* NAS-Port-Type Attribute standard values */
215 static const char *nas_port_type
[]={ "Async",
222 "HDLC Clear Channel",
234 "Wireless - IEEE 802.11",
237 /* Acct-Status-Type Accounting Attribute standard values */
238 static const char *acct_status
[]={ NULL
,
252 "Tunnel-Link-Reject",
256 /* Acct-Authentic Accounting Attribute standard values */
257 static const char *acct_auth
[]={ NULL
,
263 /* Acct-Terminate-Cause Accounting Attribute standard values */
264 static const char *acct_term
[]={ NULL
,
279 "Service Unavailable",
285 /* Tunnel-Type Attribute standard values */
286 static const char *tunnel_type
[]={ NULL
,
298 "IP-in-IP Tunneling",
301 /* Tunnel-Medium-Type Attribute standard values */
302 static const char *tunnel_medium
[]={ NULL
,
317 "E.164 with NSAP subaddress",
320 /* ARAP-Zone-Access Attribute standard values */
321 static const char *arap_zone
[]={ NULL
,
322 "Only access to dfl zone",
323 "Use zone filter inc.",
325 "Use zone filter exc.",
328 static const char *prompt
[]={ "No Echo",
333 struct attrtype
{ const char *name
; /* Attribute name */
334 const char **subtypes
; /* Standard Values (if any) */
335 u_char siz_subtypes
; /* Size of total standard values */
336 u_char first_subtype
; /* First standard value is 0 or 1 */
337 void (*print_func
)(register u_char
*, u_int
, u_short
);
340 { NULL
, NULL
, 0, 0, NULL
},
341 { "Username", NULL
, 0, 0, print_attr_string
},
342 { "Password", NULL
, 0, 0, NULL
},
343 { "CHAP Password", NULL
, 0, 0, NULL
},
344 { "NAS IP Address", NULL
, 0, 0, print_attr_address
},
345 { "NAS Port", NULL
, 0, 0, print_attr_num
},
346 { "Service Type", serv_type
, TAM_SIZE(serv_type
)-1, 1, print_attr_num
},
347 { "Framed Protocol", frm_proto
, TAM_SIZE(frm_proto
)-1, 1, print_attr_num
},
348 { "Framed IP Address", NULL
, 0, 0, print_attr_address
},
349 { "Framed IP Network", NULL
, 0, 0, print_attr_address
},
350 { "Framed Routing", frm_routing
, TAM_SIZE(frm_routing
), 0, print_attr_num
},
351 { "Filter ID", NULL
, 0, 0, print_attr_string
},
352 { "Framed MTU", NULL
, 0, 0, print_attr_num
},
353 { "Framed Compression", frm_comp
, TAM_SIZE(frm_comp
), 0, print_attr_num
},
354 { "Login IP Host", NULL
, 0, 0, print_attr_address
},
355 { "Login Service", login_serv
, TAM_SIZE(login_serv
), 0, print_attr_num
},
356 { "Login TCP Port", NULL
, 0, 0, print_attr_num
},
357 { "Unassigned", NULL
, 0, 0, NULL
}, /*17*/
358 { "Reply", NULL
, 0, 0, print_attr_string
},
359 { "Callback-number", NULL
, 0, 0, print_attr_string
},
360 { "Callback-ID", NULL
, 0, 0, print_attr_string
},
361 { "Unassigned", NULL
, 0, 0, NULL
}, /*21*/
362 { "Framed Route", NULL
, 0, 0, print_attr_string
},
363 { "Framed IPX Network", NULL
, 0, 0, print_attr_num
},
364 { "State", NULL
, 0, 0, print_attr_string
},
365 { "Class", NULL
, 0, 0, print_attr_string
},
366 { "Vendor Specific", NULL
, 0, 0, print_vendor_attr
},
367 { "Session Timeout", NULL
, 0, 0, print_attr_num
},
368 { "Idle Timeout", NULL
, 0, 0, print_attr_num
},
369 { "Termination Action", term_action
, TAM_SIZE(term_action
), 0, print_attr_num
},
370 { "Called Station", NULL
, 0, 0, print_attr_string
},
371 { "Calling Station", NULL
, 0, 0, print_attr_string
},
372 { "NAS ID", NULL
, 0, 0, print_attr_string
},
373 { "Proxy State", NULL
, 0, 0, print_attr_string
},
374 { "Login LAT Service", NULL
, 0, 0, print_attr_string
},
375 { "Login LAT Node", NULL
, 0, 0, print_attr_string
},
376 { "Login LAT Group", NULL
, 0, 0, print_attr_string
},
377 { "Framed Appletalk Link", NULL
, 0, 0, print_attr_num
},
378 { "Framed Appltalk Net", NULL
, 0, 0, print_attr_num
},
379 { "Framed Appletalk Zone", NULL
, 0, 0, print_attr_string
},
380 { "Accounting Status", acct_status
, TAM_SIZE(acct_status
)-1, 1, print_attr_num
},
381 { "Accounting Delay", NULL
, 0, 0, print_attr_num
},
382 { "Accounting Input Octets", NULL
, 0, 0, print_attr_num
},
383 { "Accounting Output Octets", NULL
, 0, 0, print_attr_num
},
384 { "Accounting Session ID", NULL
, 0, 0, print_attr_string
},
385 { "Accounting Authentication", acct_auth
, TAM_SIZE(acct_auth
)-1, 1, print_attr_num
},
386 { "Accounting Session Time", NULL
, 0, 0, print_attr_num
},
387 { "Accounting Input Packets", NULL
, 0, 0, print_attr_num
},
388 { "Accounting Output Packets", NULL
, 0, 0, print_attr_num
},
389 { "Accounting Termination Cause", acct_term
, TAM_SIZE(acct_term
)-1, 1, print_attr_num
},
390 { "Accounting Multilink Session ID", NULL
, 0, 0, print_attr_string
},
391 { "Accounting Link Count", NULL
, 0, 0, print_attr_num
},
392 { "Accounting Input Giga", NULL
, 0, 0, print_attr_num
},
393 { "Accounting Output Giga", NULL
, 0, 0, print_attr_num
},
394 { "Unassigned", NULL
, 0, 0, NULL
}, /*54*/
395 { "Event Timestamp", NULL
, 0, 0, print_attr_time
},
396 { "Unassigned", NULL
, 0, 0, NULL
}, /*56*/
397 { "Unassigned", NULL
, 0, 0, NULL
}, /*57*/
398 { "Unassigned", NULL
, 0, 0, NULL
}, /*58*/
399 { "Unassigned", NULL
, 0, 0, NULL
}, /*59*/
400 { "CHAP challenge", NULL
, 0, 0, print_attr_string
},
401 { "NAS Port Type", nas_port_type
, TAM_SIZE(nas_port_type
), 0, print_attr_num
},
402 { "Port Limit", NULL
, 0, 0, print_attr_num
},
403 { "Login LAT Port", NULL
, 0, 0, print_attr_string
}, /*63*/
404 { "Tunnel Type", tunnel_type
, TAM_SIZE(tunnel_type
)-1, 1, print_attr_num
},
405 { "Tunnel Medium", tunnel_medium
, TAM_SIZE(tunnel_medium
)-1, 1, print_attr_num
},
406 { "Tunnel Client End", NULL
, 0, 0, print_attr_string
},
407 { "Tunnel Server End", NULL
, 0, 0, print_attr_string
},
408 { "Accounting Tunnel connect", NULL
, 0, 0, print_attr_string
},
409 { "Tunnel Password", NULL
, 0, 0, print_attr_string
},
410 { "ARAP Password", NULL
, 0, 0, print_attr_strange
},
411 { "ARAP Feature", NULL
, 0, 0, print_attr_strange
},
412 { "ARAP Zone Acces", arap_zone
, TAM_SIZE(arap_zone
)-1, 1, print_attr_num
}, /*72*/
413 { "ARAP Security", NULL
, 0, 0, print_attr_string
},
414 { "ARAP Security Data", NULL
, 0, 0, print_attr_string
},
415 { "Password Retry", NULL
, 0, 0, print_attr_num
},
416 { "Prompt", prompt
, TAM_SIZE(prompt
), 0, print_attr_num
},
417 { "Connect Info", NULL
, 0, 0, print_attr_string
},
418 { "Config Token", NULL
, 0, 0, print_attr_string
},
419 { "EAP Message", NULL
, 0, 0, print_attr_string
},
420 { "Message Authentication", NULL
, 0, 0, print_attr_string
}, /*80*/
421 { "Tunnel Private Group", NULL
, 0, 0, print_attr_string
},
422 { "Tunnel Assigned ID", NULL
, 0, 0, print_attr_string
},
423 { "Tunnel Preference", NULL
, 0, 0, print_attr_num
},
424 { "ARAP Challenge Response", NULL
, 0, 0, print_attr_strange
},
425 { "Accounting Interim Interval", NULL
, 0, 0, print_attr_num
},
426 { "Accounting Tunnel packets lost", NULL
, 0, 0, print_attr_num
}, /*86*/
427 { "NAS Port ID", NULL
, 0, 0, print_attr_string
},
428 { "Framed Pool", NULL
, 0, 0, print_attr_string
},
429 { "Unassigned", NULL
, 0, 0, NULL
},
430 { "Tunnel Client Authentication ID", NULL
, 0, 0, print_attr_string
},
431 { "Tunnel Server Authentication ID", NULL
, 0, 0, print_attr_string
},
432 { "Unassigned", NULL
, 0, 0, NULL
}, /*92*/
433 { "Unassigned", NULL
, 0, 0, NULL
} /*93*/
437 /*****************************/
438 /* Print an attribute string */
439 /* value pointed by 'data' */
440 /* and 'length' size. */
441 /*****************************/
442 /* Returns nothing. */
443 /*****************************/
445 print_attr_string(register u_char
*data
, u_int length
, u_short attr_code
)
449 TCHECK2(data
[0],length
);
459 if (*data
&& (*data
<=0x1F) )
460 printf("Tag %u, ",*data
);
463 printf("Salt %u ",EXTRACT_16BITS(data
) );
467 case TUNNEL_CLIENT_END
:
468 case TUNNEL_SERVER_END
:
469 case TUNNEL_PRIV_GROUP
:
470 case TUNNEL_ASSIGN_ID
:
471 case TUNNEL_CLIENT_AUTH
:
472 case TUNNEL_SERVER_AUTH
:
480 printf("Tag %u",*data
);
487 for (i
=0; *data
&& i
< length
; i
++, data
++)
488 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
497 * print vendor specific attributes
501 print_vendor_attr(register u_char
*data
, u_int length
, u_short attr_code _U_
)
511 vendor_id
= EXTRACT_32BITS(data
);
515 printf("Vendor: %s (%u)",
516 tok2str(smi_values
,"Unknown",vendor_id
),
519 while (length
>= 2) {
522 vendor_type
= *(data
);
523 vendor_length
= *(data
+1);
525 if (vendor_length
< 2)
527 printf("\n\t Vendor Attribute: %u, Length: %u (bogus, must be >= 2)",
532 if (vendor_length
> length
)
534 printf("\n\t Vendor Attribute: %u, Length: %u (bogus, goes past end of vendor-specific attribute)",
542 TCHECK2(*data
, vendor_length
);
544 printf("\n\t Vendor Attribute: %u, Length: %u, Value: ",
547 for (idx
= 0; idx
< vendor_length
; idx
++, data
++)
548 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
549 length
-=vendor_length
;
559 /******************************/
560 /* Print an attribute numeric */
561 /* value pointed by 'data' */
562 /* and 'length' size. */
563 /******************************/
564 /* Returns nothing. */
565 /******************************/
567 print_attr_num(register u_char
*data
, u_int length
, u_short attr_code
)
574 printf("ERROR: length %u != 4", length
);
579 /* This attribute has standard values */
580 if (attr_type
[attr_code
].siz_subtypes
)
582 static const char **table
;
583 u_int32_t data_value
;
584 table
= attr_type
[attr_code
].subtypes
;
586 if ( (attr_code
== TUNNEL_TYPE
) || (attr_code
== TUNNEL_MEDIUM
) )
589 printf("Tag[Unused]");
591 printf("Tag[%d]", *data
);
593 data_value
= EXTRACT_24BITS(data
);
597 data_value
= EXTRACT_32BITS(data
);
599 if ( data_value
<= (u_int32_t
)(attr_type
[attr_code
].siz_subtypes
- 1 +
600 attr_type
[attr_code
].first_subtype
) &&
601 data_value
>= attr_type
[attr_code
].first_subtype
)
602 printf("%s",table
[data_value
]);
604 printf("#%u",data_value
);
608 switch(attr_code
) /* Be aware of special cases... */
611 if (EXTRACT_32BITS( data
) == 0xFFFFFFFE )
612 printf("NAS Select");
614 printf("%d",EXTRACT_32BITS( data
) );
617 case SESSION_TIMEOUT
:
620 case ACCT_SESSION_TIME
:
621 case ACCT_INT_INTERVAL
:
622 timeout
= EXTRACT_32BITS( data
);
624 printf( "%02d secs", timeout
);
627 if ( timeout
< 3600 )
628 printf( "%02d:%02d min",
629 timeout
/ 60, timeout
% 60);
631 printf( "%02d:%02d:%02d hours",
632 timeout
/ 3600, (timeout
% 3600) / 60,
638 if (EXTRACT_32BITS(data
) )
639 printf("%d",EXTRACT_32BITS(data
) );
641 printf("Unnumbered" );
644 case FRM_ATALK_NETWORK
:
645 if (EXTRACT_32BITS(data
) )
646 printf("%d",EXTRACT_32BITS(data
) );
648 printf("NAS assigned" );
651 case TUNNEL_PREFERENCE
:
655 printf("Tag (Unused) %d",EXTRACT_24BITS(data
) );
657 printf("Tag (%d) %d", tag
, EXTRACT_24BITS(data
) );
661 printf("%d",EXTRACT_32BITS( data
) );
675 /*****************************/
676 /* Print an attribute IPv4 */
677 /* address value pointed by */
678 /* 'data' and 'length' size. */
679 /*****************************/
680 /* Returns nothing. */
681 /*****************************/
683 print_attr_address(register u_char
*data
, u_int length
, u_short attr_code
)
687 printf("ERROR: length %u != 4", length
);
697 if (EXTRACT_32BITS(data
) == 0xFFFFFFFF )
698 printf("User Selected");
700 if (EXTRACT_32BITS(data
) == 0xFFFFFFFE )
701 printf("NAS Select");
703 printf("%s",ipaddr_string(data
));
707 printf("%s",ipaddr_string(data
) );
718 /*************************************/
719 /* Print an attribute of 'secs since */
720 /* January 1, 1970 00:00 UTC' value */
721 /* pointed by 'data' and 'length' */
723 /*************************************/
724 /* Returns nothing. */
725 /*************************************/
726 static void print_attr_time(register u_char
*data
, u_int length
, u_short attr_code _U_
)
733 printf("ERROR: length %u != 4", length
);
739 attr_time
= EXTRACT_32BITS(data
);
740 strlcpy(string
, ctime(&attr_time
), sizeof(string
));
741 /* Get rid of the newline */
743 printf("%.24s", string
);
751 /***********************************/
752 /* Print an attribute of 'strange' */
753 /* data format pointed by 'data' */
754 /* and 'length' size. */
755 /***********************************/
756 /* Returns nothing. */
757 /***********************************/
758 static void print_attr_strange(register u_char
*data
, u_int length
, u_short attr_code
)
767 printf("ERROR: length %u != 16", length
);
770 printf("User_challenge (");
773 PRINT_HEX(len_data
, data
);
774 printf(") User_resp(");
777 PRINT_HEX(len_data
, data
);
784 printf("ERROR: length %u != 14", length
);
789 printf("User can change password");
791 printf("User cannot change password");
794 printf(", Min password length: %d",*data
);
796 printf(", created at: ");
799 PRINT_HEX(len_data
, data
);
800 printf(", expires in: ");
803 PRINT_HEX(len_data
, data
);
804 printf(", Current Time: ");
807 PRINT_HEX(len_data
, data
);
810 case ARAP_CHALLENGE_RESP
:
813 printf("ERROR: length %u != 8", length
);
818 PRINT_HEX(len_data
, data
);
830 radius_attrs_print(register const u_char
*attr
, u_int length
)
832 register const struct radius_attr
*rad_attr
= (struct radius_attr
*)attr
;
833 const char *attr_string
;
841 if (rad_attr
->type
> 0 && rad_attr
->type
< TAM_SIZE(attr_type
))
842 attr_string
= attr_type
[rad_attr
->type
].name
;
844 attr_string
= "Unknown";
845 if (rad_attr
->len
< 2)
847 printf("\n\t %s Attribute (%u), length: %u (bogus, must be >= 2)",
853 if (rad_attr
->len
> length
)
855 printf("\n\t %s Attribute (%u), length: %u (bogus, goes past end of packet)",
861 printf("\n\t %s Attribute (%u), length: %u, Value: ",
866 if (rad_attr
->type
< TAM_SIZE(attr_type
))
868 if (rad_attr
->len
> 2)
870 if ( attr_type
[rad_attr
->type
].print_func
)
871 (*attr_type
[rad_attr
->type
].print_func
)(
872 ((u_char
*)(rad_attr
+1)),
873 rad_attr
->len
- 2, rad_attr
->type
);
876 /* do we also want to see a hex dump ? */
878 print_unknown_data(gndo
,(u_char
*)rad_attr
+2,"\n\t ",(rad_attr
->len
)-2);
880 length
-=(rad_attr
->len
);
881 rad_attr
= (struct radius_attr
*)( ((char *)(rad_attr
))+rad_attr
->len
);
891 radius_print(const u_char
*dat
, u_int length
)
893 register const struct radius_hdr
*rad
;
896 TCHECK2(*dat
, MIN_RADIUS_LEN
);
897 rad
= (struct radius_hdr
*)dat
;
898 len
= EXTRACT_16BITS(&rad
->len
);
900 if (len
< MIN_RADIUS_LEN
)
910 printf("RADIUS, %s (%u), id: 0x%02x length: %u",
911 tok2str(radius_command_values
,"Unknown Command",rad
->code
),
918 printf("RADIUS, length: %u\n\t%s (%u), id: 0x%02x, Authenticator: ",
920 tok2str(radius_command_values
,"Unknown Command",rad
->code
),
924 for(auth_idx
=0; auth_idx
< 16; auth_idx
++)
925 printf("%02x", rad
->auth
[auth_idx
] );
928 if (len
> MIN_RADIUS_LEN
)
929 radius_attrs_print( dat
+ MIN_RADIUS_LEN
, len
- MIN_RADIUS_LEN
);