aboutsummaryrefslogtreecommitdiff
path: root/en_US.ISO8859-1/books/handbook/security/chapter.sgml
blob: 5f6ba7b72d849c1cab24d570707f980cff4d9f6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
<!--
     The FreeBSD Documentation Project

     $FreeBSD$
-->

<chapter id="security">
  <chapterinfo>
    <authorgroup>
      <author>
	<firstname>Matthew</firstname>
	<surname>Dillon</surname>
	<contrib>Much of this chapter has been taken from the
	security(7) manual page by </contrib>
      </author>
    </authorgroup>
  </chapterinfo>

  <title>Security</title>
  <indexterm><primary>security</primary></indexterm>

  <sect1 id="security-synopsis">
    <title>Synopsis</title>

    <para>This chapter will provide a basic introduction to system security
      concepts, some general good rules of thumb, and some advanced topics
      under &os;.  A lot of the topics covered here can be applied
      to system and Internet security in general as well.  The Internet
      is no longer a <quote>friendly</quote> place in which everyone
      wants to be your kind neighbor.  Securing your system is imperative
      to protect your data, intellectual property, time, and much more
      from the hands of hackers and the like.</para>

    <para>FreeBSD provides an array of utilities and mechanisms to
      ensure the integrity and security of your system and
      network.</para>

    <para>After reading this chapter, you will know:</para>

    <itemizedlist>
      <listitem>
	<para>Basic system security concepts, in respect to &os;.</para>
      </listitem>

      <listitem>
	<para>About the various crypt mechanisms available in &os;,
	  such as <acronym>DES</acronym> and <acronym>MD5</acronym>.</para>
      </listitem>

      <listitem>
	<para>How to set up one-time password authentication.</para>
      </listitem>

      <listitem>
	<para>How to set up <application>KerberosIV</application> on &os;
	  releases prior to 5.0.</para>
      </listitem>

      <listitem>
	<para>How to set up <application>Kerberos5</application> on
	  post &os; 5.0 releases.</para>
      </listitem>

      <listitem>
	<para>How to create firewalls using <acronym>IPFW</acronym>.</para>
      </listitem>

      <listitem>
	<para>How to configure IPsec and create a <acronym>VPN</acronym> between
	&os;/&windows; machines.</para>
      </listitem>
     
      <listitem>
	<para>How to configure and use <application>OpenSSH</application>, &os;'s <acronym>SSH</acronym>
	  implementation.</para>
      </listitem>

      <listitem>
	<para>How to configure and load access control extension
	  modules using the TrustedBSD <acronym>MAC</acronym> Framework.</para>
      </listitem>

      <listitem>
	<para>What file system <acronym>ACL</acronym>s are and how to use them.</para>
      </listitem>

      <listitem>
	<para>How to utililize the &os; security advisories
	  publications.</para>
      </listitem>

    </itemizedlist>

    <para>Before reading this chapter, you should:</para>

    <itemizedlist>
      <listitem>
	<para>Understand basic &os; and Internet concepts.</para>
      </listitem>
    </itemizedlist>

  </sect1>

  <sect1 id="security-intro">
    <title>Introduction</title>

    <para>Security is a function that begins and ends with the system
      administrator.  While all BSD &unix; multi-user systems have some
      inherent security, the job of building and maintaining additional
      security mechanisms to keep those users <quote>honest</quote> is
      probably one of the single largest undertakings of the sysadmin.
      Machines are only as secure as you make them, and security concerns
      are ever competing with the human necessity for convenience.  &unix;
      systems, in general, are capable of running a huge number of
      simultaneous processes and many of these processes operate as
      servers &ndash; meaning that external entities can connect and talk
      to them.  As yesterday's mini-computers and mainframes become
      today's desktops, and as computers become networked and
      internetworked, security becomes an even bigger issue.</para>

    <para>Security is best implemented through a layered
      <quote>onion</quote> approach.  In a nutshell, what you want to do is
      to create as many layers of security as are convenient and then
      carefully monitor the system for intrusions.  You do not want to
      overbuild your security or you will interfere with the detection
      side, and detection is one of the single most important aspects of
      any security mechanism.  For example, it makes little sense to set
      the <literal>schg</literal> flags (see &man.chflags.1;) on every 
      system binary because
      while this may temporarily protect the binaries, it prevents an
      attacker who has broken in from making an easily detectable change
      that may result in your security mechanisms not detecting the attacker
      at all.</para>

    <para>System security also pertains to dealing with various forms of
      attack, including attacks that attempt to crash, or otherwise make a
      system unusable, but do not attempt to compromise the
      <username>root</username> account (<quote>break root</quote>).
      Security concerns
      can be split up into several categories:</para>

    <orderedlist>
      <listitem>
	<para>Denial of service attacks.</para>
      </listitem>

      <listitem>
	<para>User account compromises.</para>
      </listitem>

      <listitem>
	<para>Root compromise through accessible servers.</para>
      </listitem>

      <listitem>
	<para>Root compromise via user accounts.</para>
      </listitem>

      <listitem>
	<para>Backdoor creation.</para>
      </listitem>
    </orderedlist>

    <indexterm>
      <primary>DoS attacks</primary>
      <see>Denial of Service (DoS)</see>
    </indexterm>
    <indexterm>
      <primary>security</primary>
      <secondary>DoS attacks</secondary>
      <see>Denial of Service (DoS)</see>
    </indexterm>
    <indexterm><primary>Denial of Service (DoS)</primary></indexterm>

    <para>A denial of service attack is an action that deprives the
      machine of needed resources.  Typically, DoS attacks are
      brute-force mechanisms that attempt to crash or otherwise make a
      machine unusable by overwhelming its servers or network stack.  Some
      DoS attacks try to take advantage of bugs in the networking
      stack to crash a machine with a single packet.  The latter can only
      be fixed by applying a bug fix to the kernel.  Attacks on servers
      can often be fixed by properly specifying options to limit the load
      the servers incur on the system under adverse conditions.
      Brute-force network attacks are harder to deal with.  A
      spoofed-packet attack, for example, is nearly impossible to stop,
      short of cutting your system off from the Internet.  It may not be
      able to take your machine down, but it can saturate your
      Internet connection.</para>

    <indexterm>
      <primary>security</primary>
      <secondary>account compromises</secondary>
    </indexterm>

    <para>A user account compromise is even more common than a DoS
      attack.  Many sysadmins still run standard 
      <application>telnetd</application>, <application>rlogind</application>,
      <application>rshd</application>,
      and <application>ftpd</application> servers on their machines.
      These servers, by default, do
      not operate over encrypted connections.  The result is that if you
      have any moderate-sized user base, one or more of your users logging
      into your system from a remote location (which is the most common
      and convenient way to login to a system) will have his or her
      password sniffed.  The attentive system admin will analyze his
      remote access logs looking for suspicious source addresses even for
      successful logins.</para>

    <para>One must always assume that once an attacker has access to a
      user account, the attacker can break <username>root</username>.
      However, the reality is that in a well secured and maintained system,
      access to a user account does not necessarily give the attacker
      access to <username>root</username>.  The distinction is important
      because without access to <username>root</username> the attacker
      cannot generally hide his tracks and may, at best, be able to do
      nothing more than mess with the user's files, or crash the machine.
      User account compromises are very common because users tend not to
      take the precautions that sysadmins take.</para>

    <indexterm>
      <primary>security</primary>
      <secondary>backdoors</secondary>
    </indexterm>

    <para>System administrators must keep in mind that there are
      potentially many ways to break <username>root</username> on a machine.
      The attacker may know the <username>root</username> password,
      the attacker may find a bug in a root-run server and be able
      to break <username>root</username> over a network
      connection to that server, or the attacker may know of a bug in
      a suid-root program that allows the attacker to break
      <username>root</username> once he has broken into a user's account.
      If an attacker has found a way to break <username>root</username>
      on a machine, the attacker may not have a need
      to install a backdoor.  Many of the <username>root</username> holes
      found and closed to date involve a considerable amount of work
      by the attacker to cleanup after himself, so most attackers install
      backdoors.  A backdoor provides the attacker with a way to easily
      regain <username>root</username> access to the system, but it
      also gives the smart system administrator a convenient way
      to detect the intrusion.
      Making it impossible for an attacker to install a backdoor may
      actually be detrimental to your security, because it will not
      close off the hole the attacker found to break in the first
      place.</para>


    <para>Security remedies should always be implemented with a
      multi-layered <quote>onion peel</quote> approach and can be
      categorized as follows:</para>

    <orderedlist>
      <listitem>
	<para>Securing <username>root</username> and staff accounts.</para>
      </listitem>

      <listitem>
	<para>Securing <username>root</username> &ndash; root-run servers
	  and suid/sgid binaries.</para>
      </listitem>

      <listitem>
	<para>Securing user accounts.</para>
      </listitem>

      <listitem>
	<para>Securing the password file.</para>
      </listitem>

      <listitem>
	<para>Securing the kernel core, raw devices, and
	  filesystems.</para>
      </listitem>

      <listitem>
	<para>Quick detection of inappropriate changes made to the
	  system.</para>
      </listitem>

      <listitem>
	<para>Paranoia.</para>
      </listitem>
    </orderedlist>

    <para>The next section of this chapter will cover the above bullet
      items in greater depth.</para>
  </sect1>

  <sect1 id="securing-freebsd">
    <title>Securing FreeBSD</title>
    <indexterm>
      <primary>security</primary>
      <secondary>securing FreeBSD</secondary>
    </indexterm>

    <note>
      <title>Command vs. Protocol</title>
      <para>Throughout this document, we will use
       <application>bold</application> text to refer to a command or
       application.  This is used for instances such as ssh, since it is
       a protocol as well as command.</para>
    </note>

    <para>The sections that follow will cover the methods of securing your
      FreeBSD system that were mentioned in the <link
        linkend="security-intro">last section</link> of this chapter.</para>

    <sect2 id="securing-root-and-staff">
      <title>Securing the <username>root</username> Account and
	Staff Accounts</title>
      <indexterm>
        <primary><command>su</command></primary>
      </indexterm>

      <para>First off, do not bother securing staff accounts if you have
	not secured the <username>root</username> account.
	Most systems have a password assigned to the <username>root</username>
	account.  The first thing you do is assume
	that the password is <emphasis>always</emphasis> compromised.
	This does not mean that you should remove the password.  The
	password is almost always necessary for console access to the
	machine.  What it does mean is that you should not make it
	possible to use the password outside of the console or possibly
	even with the &man.su.1; command.  For example, make sure that
	your pty's are specified as being insecure in the
	<filename>/etc/ttys</filename> file so that direct
	<username>root</username> logins
	via <command>telnet</command> or <command>rlogin</command> are
	disallowed.  If using other login services such as
        <application>sshd</application>, make sure that direct
	<username>root</username> logins are disabled there as well.
	You can do this by editing
        your <filename>/etc/ssh/sshd_config</filename> file, and making
        sure that <literal>PermitRootLogin</literal> is set to
        <literal>NO</literal>.  Consider every access method &ndash;
        services such as FTP often fall through the cracks.
	Direct <username>root</username> logins should only be allowed
	via the system console.</para>
      <indexterm>
        <primary><groupname>wheel</groupname></primary>
      </indexterm>

      <para>Of course, as a sysadmin you have to be able to get to
	<username>root</username>, so we open up a few holes.
	But we make sure these holes require additional password
	verification to operate.  One way to make <username>root</username>
	accessible is to add appropriate staff accounts to the
	<groupname>wheel</groupname> group (in
	<filename>/etc/group</filename>).  The staff members placed in the
	<groupname>wheel</groupname> group are allowed to
	<command>su</command> to <username>root</username>.
	You should never give staff
	members native <groupname>wheel</groupname> access by putting them in the
	<groupname>wheel</groupname> group in their password entry.  Staff
	accounts should be placed in a <groupname>staff</groupname> group, and
	then added to the <groupname>wheel</groupname> group via the
	<filename>/etc/group</filename> file.  Only those staff members
	who actually need to have <username>root</username> access
	should be placed in the
	<groupname>wheel</groupname> group.  It is also possible, when using
	an authentication method such as Kerberos, to use Kerberos'
	<filename>.k5login</filename> file in the <username>root</username>
	account to allow a &man.ksu.1; to <username>root</username>
	without having to place anyone at all in the
	<groupname>wheel</groupname> group.  This may be the better solution
	since the <groupname>wheel</groupname> mechanism still allows an
	intruder to break <username>root</username> if the intruder
	has gotten hold of your
	password file and can break into a staff account.  While having
	the <groupname>wheel</groupname> mechanism is better than having
	nothing at all, it is not necessarily the safest option.</para>

      <para>An indirect way to secure staff accounts, and ultimately
        <username>root</username> access is to use an alternative
	login access method and
        do what is known as <quote>starring</quote> out the encrypted
        password for the staff accounts.  Using the &man.vipw.8;
        command, one can replace each instance of an encrypted password
        with a single <quote><literal>*</literal></quote> character.
	This command will update the <filename>/etc/master.passwd</filename>
	file and user/password database to disable password-authenticated
        logins.</para>

      <para>A staff account entry such as:</para>

      <programlisting>foobar:R9DT/Fa1/LV9U:1000:1000::0:0:Foo Bar:/home/foobar:/usr/local/bin/tcsh</programlisting>

      <para>Should be changed to this:</para>

      <programlisting>foobar:*:1000:1000::0:0:Foo Bar:/home/foobar:/usr/local/bin/tcsh</programlisting>

      <para>This change will prevent normal logins from occurring,
        since the encrypted password will never match
        <quote><literal>*</literal></quote>.  With this done,
	staff members must use
        another mechanism to authenticate themselves such as
        &man.kerberos.1; or &man.ssh.1; using a public/private key
        pair.  When using something like Kerberos, one generally must
        secure the machines which run the Kerberos servers and your
        desktop workstation.  When using a public/private key pair
        with ssh, one must generally secure
        the machine used to login <emphasis>from</emphasis> (typically
        one's workstation).  An additional layer of protection can be
        added to the key pair by password protecting the key pair when
        creating it with &man.ssh-keygen.1;.  Being able to
        <quote>star</quote> out the passwords for staff accounts also
        guarantees that staff members can only login through secure
        access methods that you have set up.  This forces all staff
        members to use secure, encrypted connections for all of their
        sessions, which closes an important hole used by many
        intruders: sniffing the network from an unrelated,
        less secure machine.</para>

      <para>The more indirect security mechanisms also assume that you are
	logging in from a more restrictive server to a less restrictive
	server.  For example, if your main box is running all sorts of
	servers, your workstation should not be running any.  In order for
	your workstation to be reasonably secure you should run as few
	servers as possible, up to and including no servers at all, and
	you should run a password-protected screen blanker.  Of course,
	given physical access to a workstation an attacker can break any
	sort of security you put on it.  This is definitely a problem that
	you should consider, but you should also consider the fact that the
	vast majority of break-ins occur remotely, over a network, from
	people who do not have physical access to your workstation or
	servers.</para>
      <indexterm><primary>KerberosIV</primary></indexterm>

      <para>Using something like Kerberos also gives you the ability to
	disable or change the password for a staff account in one place,
	and have it immediately effect all the machines on which the staff
	member may have an account.  If a staff member's account gets
	compromised, the ability to instantly change his password on all
	machines should not be underrated.  With discrete passwords,
	changing a password on N machines can be a mess.  You can also
	impose re-passwording restrictions with Kerberos:  not only can a
	Kerberos ticket be made to timeout after a while, but the Kerberos
	system can require that the user choose a new password after a
	certain period of time (say, once a month).</para>
    </sect2>

    <sect2>
      <title>Securing Root-run Servers and SUID/SGID Binaries</title>

      <indexterm>
        <primary><command>ntalk</command></primary>
      </indexterm>
      <indexterm>
        <primary><command>comsat</command></primary>
      </indexterm>
      <indexterm>
        <primary><command>finger</command></primary>
      </indexterm>
      <indexterm>
        <primary>sandboxes</primary>
      </indexterm>
      <indexterm>
        <primary><application>sshd</application></primary>
      </indexterm>
      <indexterm>
        <primary><application>telnetd</application></primary>
      </indexterm>
      <indexterm>
        <primary><application>rshd</application></primary>
      </indexterm>
      <indexterm>
        <primary><application>rlogind</application></primary>
      </indexterm>

      <para>The prudent sysadmin only runs the servers he needs to, no
	more, no less.  Be aware that third party servers are often the
	most bug-prone.  For example, running an old version of
	<application>imapd</application> or
	<application>popper</application> is like giving a universal
	<username>root</username> ticket out to the entire world.
	Never run a server that you have not checked out carefully.
	Many servers do not need to be run as <username>root</username>.
	For example, the <application>ntalk</application>,
	<application>comsat</application>, and
	<application>finger</application> daemons can be run in special
	user <firstterm>sandboxes</firstterm>.  A sandbox is not perfect,
	unless you go through a large amount of trouble, but the onion
	approach to security still stands: If someone is able to break
	in through a server running in a sandbox, they still have to
	break out of the sandbox.  The more layers the attacker must
	break through, the lower the likelihood of his success.  Root
	holes have historically been found in virtually every server
	ever run as <username>root</username>, including basic system servers.
	If you are running a machine through which people only login via
	<application>sshd</application> and never login via
	<application>telnetd</application> or
	<application>rshd</application> or
	<application>rlogind</application>, then turn off those
	services!</para>
      
      <para>FreeBSD now defaults to running
	<application>ntalkd</application>,
	<application>comsat</application>, and
	<application>finger</application> in a sandbox.  Another program
	which may be a candidate for running in a sandbox is &man.named.8;.
	<filename>/etc/defaults/rc.conf</filename> includes the arguments
	necessary to run <application>named</application> in a sandbox in a
	commented-out form.  Depending on whether you are installing a new
	system or upgrading an existing system, the special user accounts
	used by these sandboxes may not be installed.  The prudent
	sysadmin would research and implement sandboxes for servers
	whenever possible.</para>
      <indexterm>
        <primary><application>sendmail</application></primary>
      </indexterm>

      <para>There are a number of other servers that typically do not run
	in sandboxes: <application>sendmail</application>,
	<application>popper</application>,
	<application>imapd</application>, <application>ftpd</application>,
	and others.  There are alternatives to some of these, but
	installing them may require more work than you are willing to
	perform (the convenience factor strikes again).  You may have to
	run these servers as <username>root</username> and rely on other
	mechanisms to detect break-ins that might occur through them.</para>

      <para>The other big potential <username>root</username> holes in a
	system are the
	suid-root and sgid binaries installed on the system.  Most of
	these binaries, such as <application>rlogin</application>, reside
	in <filename>/bin</filename>, <filename>/sbin</filename>,
	<filename>/usr/bin</filename>, or <filename>/usr/sbin</filename>.
	While nothing is 100% safe, the system-default suid and sgid
	binaries can be considered reasonably safe.  Still,
	<username>root</username> holes are occasionally found in these
	binaries.  A <username>root</username> hole was found in
	<literal>Xlib</literal> in 1998 that made
	<application>xterm</application> (which is typically suid)
	vulnerable.  It is better to be safe than sorry and the prudent
	sysadmin will restrict suid binaries, that only staff should run,
	to a special group that only staff can access, and get rid of
	(<command>chmod 000</command>) any suid binaries that nobody uses.
	A server with no display generally does not need an
	<application>xterm</application> binary.  Sgid binaries can be
	almost as dangerous.  If an intruder can break an sgid-kmem binary,
	the intruder might be able to read <filename>/dev/kmem</filename>
	and thus read the encrypted password file, potentially compromising
	any passworded account.  Alternatively an intruder who breaks
	group <literal>kmem</literal> can monitor keystrokes sent through
	pty's, including pty's used by users who login through secure
	methods.  An intruder that breaks the <groupname>tty</groupname>
	group can write to
	almost any user's tty.  If a user is running a terminal program or
	emulator with a keyboard-simulation feature, the intruder can
	potentially generate a data stream that causes the user's terminal
	to echo a command, which is then run as that user.</para>
    </sect2>

    <sect2 id="secure-users">
      <title>Securing User Accounts</title>

      <para>User accounts are usually the most difficult to secure.  While
	you can impose Draconian access restrictions on your staff and
	<quote>star</quote> out their passwords, you may not be able to
	do so with any general user accounts you might have.  If you do
	have sufficient control, then you may win out and be able to secure
	the user accounts properly.  If not, you simply have to be more
	vigilant in your monitoring of those accounts.  Use of
	ssh and Kerberos for user accounts is
	more problematic, due to the extra administration and technical
	support required, but still a very good solution compared to a
	crypted password file.</para>
    </sect2>

    <sect2>
      <title>Securing the Password File</title>

      <para>The only sure fire way is to <literal>*</literal> out as many
	passwords as you can and use ssh or
	Kerberos for access to those accounts.  Even though the encrypted
	password file (<filename>/etc/spwd.db</filename>) can only be read
	by <username>root</username>, it may be possible for an intruder
	to obtain read access to that file even if the attacker cannot
	obtain root-write access.</para>

      <para>Your security scripts should always check for and report
	changes to the password file (see the <link
	  linkend="security-integrity">Checking file integrity</link> section
	below).</para>
    </sect2>

    <sect2>
      <title>Securing the Kernel Core, Raw Devices, and
	Filesystems</title>

      <para>If an attacker breaks <username>root</username> he can do
        just about anything, but
	there are certain conveniences.  For example, most modern kernels
	have a packet sniffing device driver built in.  Under FreeBSD it
	is called the <devicename>bpf</devicename> device.  An intruder
	will commonly attempt to run a packet sniffer on a compromised
	machine.  You do not need to give the intruder the capability and
	most systems do not have the need for the
	<devicename>bpf</devicename> device compiled in.</para>

      <indexterm>
        <primary><command>sysctl</command></primary>
      </indexterm>
      <para>But even if you turn off the <devicename>bpf</devicename>
	device, you still have
	<devicename>/dev/mem</devicename> and 
	<devicename>/dev/kmem</devicename>
	to worry about.  For that matter, the intruder can still write to
	raw disk devices.  Also, there is another kernel feature called
	the module loader, &man.kldload.8;.  An enterprising intruder can
	use a KLD module to install his own <devicename>bpf</devicename>
	device, or other sniffing
	device, on a running kernel.  To avoid these problems you have to
	run the kernel at a higher secure level, at least securelevel 1.
	The securelevel can be set with a <command>sysctl</command> on
	the <varname>kern.securelevel</varname> variable.  Once you have
	set the securelevel to 1, write access to raw devices will be
	denied and special <command>chflags</command> flags,
	such as <literal>schg</literal>,
	will be enforced.  You must also ensure that the
	<literal>schg</literal> flag is set on critical startup binaries,
	directories, and script files &ndash; everything that gets run up
	to the point where the securelevel is set.  This might be overdoing
	it, and upgrading the system is much more difficult when you
	operate at a higher secure level.  You may compromise and run the
	system at a higher secure level but not set the
	<literal>schg</literal> flag for every system file and directory
	under the sun.  Another possibility is to simply mount
	<filename>/</filename> and <filename>/usr</filename> read-only.
	It should be noted that being too Draconian in what you attempt to
	protect may prevent the all-important detection of an
	intrusion.</para>
    </sect2>

    <sect2 id="security-integrity">
      <title>Checking File Integrity: Binaries, Configuration Files,
	Etc.</title>

      <para>When it comes right down to it, you can only protect your core
	system configuration and control files so much before the
	convenience factor rears its ugly head.  For example, using
	<command>chflags</command> to set the <literal>schg</literal> bit
	on most of the files in <filename>/</filename> and
	<filename>/usr</filename> is probably counterproductive, because
	while it may protect the files, it also closes a detection window.
	The last layer of your security onion is perhaps the most
	important &ndash; detection.  The rest of your security is pretty
	much useless (or, worse, presents you with a false sense of
	safety) if you cannot detect potential incursions.  Half the job
	of the onion is to slow down the attacker, rather than stop him, in
	order to give the detection side of the equation a chance to catch
	him in the act.</para>

      <para>The best way to detect an incursion is to look for modified,
	missing, or unexpected files.  The best way to look for modified
	files is from another (often centralized) limited-access system.
	Writing your security scripts on the extra-secure limited-access
	system makes them mostly invisible to potential attackers, and this
	is important.  In order to take maximum advantage you generally
	have to give the limited-access box significant access to the
	other machines in the business, usually either by doing a
	read-only NFS export of the other machines to the limited-access
	box, or by setting up ssh key-pairs to
	allow the limited-access box to ssh to
	the other machines.  Except for its network traffic, NFS is the
	least visible method &ndash; allowing you to monitor the
	filesystems on each client box virtually undetected.  If your
	limited-access server is connected to the client boxes through a
	switch, the NFS method is often the better choice.  If your
	limited-access server is connected to the client boxes through a
	hub, or through several layers of routing, the NFS method may be
	too insecure (network-wise) and using
	ssh may be the better choice even with
	the audit-trail tracks that ssh
	lays.</para>

      <para>Once you give a limited-access box, at least read access to the
	client systems it is supposed to monitor, you must write scripts
	to do the actual monitoring.  Given an NFS mount, you can write
	scripts out of simple system utilities such as &man.find.1; and
	&man.md5.1;.  It is best to physically md5 the client-box files
	at least once a day, and to test control files such as those
	found in <filename>/etc</filename> and
	<filename>/usr/local/etc</filename> even more often.  When
	mismatches are found, relative to the base md5 information the
	limited-access machine knows is valid, it should scream at a
	sysadmin to go check it out.  A good security script will also
	check for inappropriate suid binaries and for new or deleted files
	on system partitions such as <filename>/</filename> and
	<filename>/usr</filename>.</para>

      <para>When using ssh rather than NFS,
	writing the security script is much more difficult.   You
	essentially have to <command>scp</command> the scripts to the client 
	box in order to
	run them, making them visible, and for safety you also need to
	<command>scp</command> the binaries (such as find) that those
	scripts use.  The <application>ssh</application> client on the
	client box may already be compromised.  All in all, using
	ssh may be necessary when running over
	insecure links, but it is also a lot harder to deal with.</para>

      <para>A good security script will also check for changes to user and
	staff members access configuration files:
	<filename>.rhosts</filename>, <filename>.shosts</filename>,
	<filename>.ssh/authorized_keys</filename> and so forth&hellip;
	files that might fall outside the purview of the
	<literal>MD5</literal> check.</para>

      <para>If you have a huge amount of user disk space, it may take too
	long to run through every file on those partitions.  In this case,
	setting mount flags to disallow suid binaries and devices on those
	partitions is a good idea.  The <literal>nodev</literal> and
	<literal>nosuid</literal> options (see &man.mount.8;) are what you
	want to look into.  You should probably scan them anyway, at least
	once a week, since the object of this layer is to detect a break-in
	whether or not the break-in is effective.</para>

      <para>Process accounting (see &man.accton.8;) is a relatively
	low-overhead feature of the operating system which might help
	as a post-break-in evaluation mechanism.  It is especially
	useful in tracking down how an intruder has actually broken into
	a system, assuming the file is still intact after the break-in
	occurs.</para>

      <para>Finally, security scripts should process the log files, and the
	logs themselves should be generated in as secure a manner as
	possible &ndash; remote syslog can be very useful.  An intruder
	tries to cover his tracks, and log files are critical to the
	sysadmin trying to track down the time and method of the initial
	break-in.  One way to keep a permanent record of the log files is
	to run the system console to a serial port and collect the
	information on a continuing basis through a secure machine
	monitoring the consoles.</para>
    </sect2>

    <sect2>
      <title>Paranoia</title>

      <para>A little paranoia never hurts.  As a rule, a sysadmin can add
	any number of security features, as long as they do not effect
	convenience, and can add security features that
	<emphasis>do</emphasis> effect convenience with some added thought.
	Even more importantly, a security administrator should mix it up a
	bit &ndash; if you use recommendations such as those given by this
	document verbatim, you give away your methodologies to the
	prospective attacker who also has access to this document.</para>
    </sect2>

    <sect2>
      <title>Denial of Service Attacks</title>
      <indexterm><primary>Denial of Service (DoS)</primary></indexterm>

      <para>This section covers Denial of Service attacks.  A DoS attack
	is typically a packet attack.  While there is not much you can do
	about modern spoofed packet attacks that saturate your network,
	you can generally limit the damage by ensuring that the attacks
	cannot take down your servers.</para>

      <orderedlist>
	<listitem>
	  <para>Limiting server forks.</para>
	</listitem>

	<listitem>
	  <para>Limiting springboard attacks (ICMP response attacks, ping
	    broadcast, etc.).</para>
	</listitem>

	<listitem>
	  <para>Kernel Route Cache.</para>
	</listitem>
      </orderedlist>

      <para>A common DoS attack is against a forking server that attempts
	to cause the server to eat processes, file descriptors, and memory,
	until the machine dies.  <application>inetd</application>
	(see &man.inetd.8;) has several
	options to limit this sort of attack.  It should be noted that
	while it is possible to prevent a machine from going down, it is
	not generally possible to prevent a service from being disrupted
	by the attack.  Read the <application>inetd</application> manual
	page carefully and pay
	specific attention to the <option>-c</option>, <option>-C</option>,
	and <option>-R</option> options.  Note that spoofed-IP attacks
	will circumvent the <option>-C</option> option to 
	<application>inetd</application>, so
	typically a combination of options must be used.  Some standalone
	servers have self-fork-limitation parameters.</para>

      <para><application>Sendmail</application> has its
	<option>-OMaxDaemonChildren</option> option, which tends to work
	much better than trying to use sendmail's load limiting options
	due to the load lag.  You should specify a
	<literal>MaxDaemonChildren</literal> parameter, when you start
	<application>sendmail</application>, high enough to handle your
	expected load, but not so high that the computer cannot handle that
	number of <application>sendmails</application> without falling on
	its face.  It is also prudent to run sendmail in queued mode
	(<option>-ODeliveryMode=queued</option>) and to run the daemon
	(<command>sendmail -bd</command>) separate from the queue-runs
	(<command>sendmail -q15m</command>).  If you still want real-time
	delivery you can run the queue at a much lower interval, such as
	<option>-q1m</option>, but be sure to specify a reasonable
	<literal>MaxDaemonChildren</literal> option for
	<emphasis>that</emphasis> sendmail to prevent cascade failures.</para>

      <para><application>Syslogd</application> can be attacked directly
	and it is strongly recommended that you use the <option>-s</option>
	option whenever possible, and the <option>-a</option> option
	otherwise.</para>

      <para>You should also be fairly careful with connect-back services
	such as <application>tcpwrapper</application>'s reverse-identd,
	which can be attacked directly.  You generally do not want to use
	the reverse-ident feature of
	<application>tcpwrappers</application> for this reason.</para>

      <para>It is a very good idea to protect internal services from
	external access by firewalling them off at your border routers.
	The idea here is to prevent saturation attacks from outside your
	LAN, not so much to protect internal services from network-based
	<username>root</username> compromise.
	Always configure an exclusive firewall, i.e.,
	<quote>firewall everything <emphasis>except</emphasis> ports A, B,
	C, D, and M-Z</quote>.  This way you can firewall off all of your
	low ports except for certain specific services such as
	<application>named</application> (if you are primary for a zone),
	<application>ntalkd</application>,
	<application>sendmail</application>, and other Internet-accessible
	services.  If you try to configure the firewall the other way
	&ndash; as an inclusive or permissive firewall, there is a good
	chance that you will forget to <quote>close</quote> a couple of
	services, or that you will add a new internal service and forget
	to update the firewall.  You can still open up the high-numbered
	port range on the firewall, to allow permissive-like operation,
	without compromising your low ports.  Also take note that FreeBSD
	allows you to control the range of port numbers used for dynamic
	binding, via the various <varname>net.inet.ip.portrange</varname>
	<command>sysctl</command>'s (<command>sysctl -a | fgrep
	portrange</command>), which can also ease the complexity of your
	firewall's configuration.  For example, you might use a normal
	first/last range of 4000 to 5000, and a hiport range of 49152 to
	65535, then block off everything under 4000 in your firewall
	(except for certain specific Internet-accessible ports, of
	course).</para>

      <indexterm><primary>ICMP_BANDLIM</primary></indexterm>

      <para>Another common DoS attack is called a springboard attack
	&ndash; to attack a server in a manner that causes the server to
	generate responses which overloads the server, the local
	network, or some other machine.  The most common attack of this
	nature is the <emphasis>ICMP ping broadcast attack</emphasis>.
	The attacker spoofs ping packets sent to your LAN's broadcast
	address with the source IP address set to the actual machine they
	wish to attack.  If your border routers are not configured to
	stomp on ping's to broadcast addresses, your LAN winds up
	generating sufficient responses to the spoofed source address to
	saturate the victim, especially when the attacker uses the same
	trick on several dozen broadcast addresses over several dozen
	different networks at once.  Broadcast attacks of over a hundred
	and twenty megabits have been measured.  A second common
	springboard attack is against the ICMP error reporting system.
	By constructing packets that generate ICMP error responses, an
	attacker can saturate a server's incoming network and cause the
	server to saturate its outgoing network with ICMP responses.  This
	type of attack can also crash the server by running it out of
	mbuf's, especially if the server cannot drain the ICMP responses
	it generates fast enough.  The FreeBSD kernel has a new kernel
	compile option called <option>ICMP_BANDLIM</option>
	which limits the effectiveness
	of these sorts of attacks.  The last major class of springboard
	attacks is related to certain internal 
	<application>inetd</application> services such as the
	udp echo service.  An attacker simply spoofs a UDP packet with the
	source address being server A's echo port, and the destination
	address being server B's echo port, where server A and B are both
	on your LAN.  The two servers then bounce this one packet back and
	forth between each other.  The attacker can overload both servers
	and their LANs simply by injecting a few packets in this manner.
	Similar problems exist with the internal 
	<application>chargen</application> port.  A
	competent sysadmin will turn off all of these inetd-internal test
	services.</para>

      <para>Spoofed packet attacks may also be used to overload the kernel
	route cache.  Refer to the <varname>net.inet.ip.rtexpire</varname>,
	<varname>rtminexpire</varname>, and <varname>rtmaxcache</varname>
	<command>sysctl</command> parameters.  A spoofed packet attack
	that uses a random source IP will cause the kernel to generate a
	temporary cached route in the route table, viewable with
	<command>netstat -rna | fgrep W3</command>.  These routes
	typically timeout in 1600 seconds or so.  If the kernel detects
	that the cached route table has gotten too big it will dynamically
	reduce the <varname>rtexpire</varname> but will never decrease it 
	to less than <varname>rtminexpire</varname>.  There are two 
	problems:</para>
	
      <orderedlist>
	<listitem>
	  <para>The kernel does not react quickly enough when a lightly
	    loaded server is suddenly attacked.</para>
	</listitem>
	
	<listitem>
	  <para>The <varname>rtminexpire</varname> is not low enough for
	    the kernel to survive a sustained attack.</para>
	</listitem>
      </orderedlist>
      
      <para>If your servers are connected to the Internet via a T3 or
        better, it may be prudent to manually override both
	<varname>rtexpire</varname> and <varname>rtminexpire</varname>
	via &man.sysctl.8;.  Never set either parameter to zero (unless
	you want to crash the machine).  Setting both
	parameters to 2 seconds should be sufficient to protect the route
	table from attack.</para>
    </sect2>

    <sect2>
      <title>Access Issues with Kerberos and SSH</title>
      <indexterm><primary><command>ssh</command></primary></indexterm>
      <indexterm><primary>KerberosIV</primary></indexterm>

      <para>There are a few issues with both Kerberos and
	ssh that need to be addressed if
	you intend to use them.  Kerberos V is an excellent
	authentication protocol, but there are bugs in the kerberized
	<application>telnet</application> and
	<application>rlogin</application> applications that make them
	unsuitable for dealing with binary streams.  Also, by default
	Kerberos does not encrypt a session unless you use the
	<option>-x</option> option.  <application>ssh</application>
	encrypts everything by default.</para>

      <para>ssh works quite well in every
	respect except that it forwards encryption keys by default.  What
	this means is that if you have a secure workstation holding keys
	that give you access to the rest of the system, and you
	ssh to an insecure machine, your keys
	are usable.  The actual keys themselves are not exposed, but
	ssh installs a forwarding port for the
	duration of your login, and if an attacker has broken
	<username>root</username> on the
	insecure machine he can utilize that port to use your keys to gain
	access to any other machine that your keys unlock.</para>

      <para>We recommend that you use ssh in
	combination with Kerberos whenever possible for staff logins.
	<application>ssh</application> can be compiled with Kerberos
	support.  This reduces your reliance on potentially exposable
	ssh keys while at the same time
	protecting passwords via Kerberos.  ssh
	keys should only be used for automated tasks from secure machines
	(something that Kerberos is unsuited to do).  We also recommend that
	you either turn off key-forwarding in the
	ssh configuration, or that you make use
	of the <literal>from=IP/DOMAIN</literal> option that
	ssh allows in its
	<filename>authorized_keys</filename> file to make the key only
	usable to entities logging in from specific machines.</para>
    </sect2>
  </sect1>

  <sect1 id="crypt">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Bill</firstname>
	  <surname>Swingle</surname>
	  <contrib>Parts rewritten and updated by </contrib>
	</author>
      </authorgroup>
      <!-- 21 Mar 2000 -->
    </sect1info>

    <title>DES, MD5, and Crypt</title>
    <indexterm>
      <primary>security</primary>
      <secondary>crypt</secondary>
    </indexterm>

    <indexterm><primary>crypt</primary></indexterm>
    <indexterm><primary>DES</primary></indexterm>
    <indexterm><primary>MD5</primary></indexterm>

    <para>Every user on a &unix; system has a password associated with
      their account.  It seems obvious that these passwords need to be
      known only to the user and the actual operating system.  In
      order to keep these passwords secret, they are encrypted with
      what is known as a <quote>one-way hash</quote>, that is, they can
      only be easily encrypted but not decrypted.  In other words, what
      we told you a moment ago was obvious is not even true:  the
      operating system itself does not <emphasis>really</emphasis> know
      the password.  It only knows the <emphasis>encrypted</emphasis>
      form of the password.  The only way to get the
      <quote>plain-text</quote> password is by a brute force search of the
      space of possible passwords.</para>

    <para>Unfortunately the only secure way to encrypt passwords when
      &unix; came into being was based on DES, the Data Encryption
      Standard.  This was not such a problem for users resident in
      the US, but since the source code for DES could not be exported
      outside the US, FreeBSD had to find a way to both comply with
      US law and retain compatibility with all the other &unix;
      variants that still used DES.</para>

    <para>The solution was to divide up the encryption libraries 
      so that US users could install the DES libraries and use
      DES but international users still had an encryption method
      that could be exported abroad.  This is how FreeBSD came to
      use MD5 as its default encryption method.  MD5 is believed to
      be more secure than DES, so installing DES is offered primarily
      for compatibility reasons.</para>

    <sect2>
      <title>Recognizing Your Crypt Mechanism</title>

      <para>Before FreeBSD&nbsp;4.4 <filename>libcrypt.a</filename> was a
	symbolic link pointing to the library which was used for
	encryption.  FreeBSD&nbsp;4.4 changed <filename>libcrypt.a</filename> to
	provide a configurable password authentication hash library.
	Currently the library supports DES, MD5 and Blowfish hash
	functions.  By default FreeBSD uses MD5 to encrypt
	passwords.</para>

      <para>It is pretty easy to identify which encryption method 
	FreeBSD is set up to use.  Examining the encrypted passwords in
	the <filename>/etc/master.passwd</filename> file is one way.
	Passwords encrypted with the MD5 hash are longer than those
	encrypted with the DES hash and also begin with the characters
	<literal>&dollar;1&dollar;</literal>.  Passwords starting with
	<literal>&dollar;2&dollar;</literal> are encrypted with the
	Blowfish hash function.  DES password strings do not
	have any particular identifying characteristics, but they are
	shorter than MD5 passwords, and are coded in a 64-character
	alphabet which does not include the <literal>&dollar;</literal>
	character, so a relatively short string which does not begin with
	a dollar sign is very likely a DES password.</para>

      <para>The password format used for new passwords is controlled
	by the <literal>passwd_format</literal> login capability in
	<filename>/etc/login.conf</filename>, which takes values of
	<literal>des</literal>, <literal>md5</literal> or
	<literal>blf</literal>.  See the &man.login.conf.5; manual page
	for more information about login capabilities.</para>

    </sect2>
  </sect1>

  <sect1 id="one-time-passwords">
    <title>One-time Passwords</title>
    <indexterm><primary>one-time passwords</primary></indexterm>
    <indexterm>
      <primary>security</primary>
      <secondary>one-time passwords</secondary>
    </indexterm>

    <para>S/Key is a one-time password scheme based on a one-way hash
      function.  FreeBSD uses the MD4 hash for compatibility but other
      systems have used MD5 and DES-MAC.  S/Key has been part of the
      FreeBSD base system since version 1.1.5 and is also used on a
      growing number of other operating systems.  S/Key is a registered
      trademark of Bell Communications Research, Inc.</para>

    <para>From version 5.0 of FreeBSD, S/Key has been replaced with
      the functionally equivalent OPIE (One-time Passwords In
      Everything).  OPIE uses the MD5 hash by default.</para>

    <para>There are three different sorts of passwords which we will discuss
      below.  The first is your usual &unix; style or
      Kerberos password; we will call this a <quote>&unix; password</quote>.
      The second sort is the one-time password which is generated by the
      S/Key <command>key</command> program or the OPIE
      &man.opiekey.1; program and accepted by the
      <command>keyinit</command> or &man.opiepasswd.1; programs
      and the login prompt; we will
      call this a <quote>one-time password</quote>.  The final sort of
      password is the secret password which you give to the
      <command>key</command>/<command>opiekey</command> programs (and
      sometimes the
      <command>keyinit</command>/<command>opiepasswd</command> programs)
      which it uses to generate
      one-time passwords; we will call it a <quote>secret password</quote>
      or just unqualified <quote>password</quote>.</para>

    <para>The secret password does not have anything to do with your &unix;
      password; they can be the same but this is not recommended.  S/Key
      and OPIE secret passwords are not limited to 8 characters like old
      &unix; passwords<footnote><para>Under &os; the standard login
      password may be up to 128 characters in length.</para></footnote>,
      they can be as long as you like.  Passwords of six or
      seven word long phrases are fairly common.  For the most part, the
      S/Key or OPIE system operates completely independently of the &unix;
      password system.</para>

    <para>Besides the password, there are two other pieces of data that
      are important to S/Key and OPIE.  One is what is known as the
      <quote>seed</quote> or <quote>key</quote>, consisting of two letters
      and five digits.  The other is what is called the <quote>iteration
      count</quote>, a number between 1 and 100.  S/Key creates the
      one-time password by concatenating the seed and the secret password,
      then applying the MD4/MD5 hash as many times as specified by the
      iteration count and turning the result into six short English words.
      These six English words are your one-time password.  The
      authentication system (primarily PAM) keeps
      track of the last one-time password used, and the user is
      authenticated if the hash of the user-provided password is equal to
      the previous password.  Because a one-way hash is used it is
      impossible to generate future one-time passwords if a successfully
      used password is captured; the iteration count is decremented after
      each successful login to keep the user and the login program in
      sync.  When the iteration count gets down to 1, S/Key and OPIE must be
      reinitialized.</para>

    <para>There are three programs involved in each system
      which we will discuss below.  The <command>key</command> and
      <command>opiekey</command> programs accept an iteration
      count, a seed, and a secret password, and generate a one-time
      password or a consecutive list of one-time passwords.  The
      <command>keyinit</command> and <command>opiepasswd</command>
      programs are used to initialize S/Key and OPIE respectively,
      and to change passwords, iteration counts, or seeds; they
      take either a secret passphrase, or an iteration count,
      seed, and one-time password.  The <command>keyinfo</command>
      and <command>opieinfo</command> programs examine the
      relevant credentials files (<filename>/etc/skeykeys</filename> or
      <filename>/etc/opiekeys</filename>) and print out the invoking user's
      current iteration count and seed.</para>

    <para>There are four different sorts of operations we will cover.  The
      first is using <command>keyinit</command> or
      <command>opiepasswd</command> over a secure connection to set up
      one-time-passwords for the first time,  or to change your password
      or seed.  The second operation is using <command>keyinit</command>
      or <command>opiepasswd</command> over an insecure connection, in
      conjunction with <command>key</command> or <command>opiekey</command>
      over a secure connection,  to do the same.  The third is using
      <command>key</command>/<command>opiekey</command> to log in over
      an insecure connection.  The fourth is using <command>key</command>
      or <command>opiekey</command> to generate a number of keys which
      can be written down or printed out to carry with you when going to
      some location without secure connections to anywhere.</para>

    <sect2>
      <title>Secure Connection Initialization</title>

      <para>To initialize S/Key for the first time, change your password,
	or change your seed while logged in over a secure connection
	(e.g., on the console of a machine or via <application>ssh</application>), use the
	<command>keyinit</command> command without any parameters while
	logged in as yourself:</para>

      <screen>&prompt.user; <userinput>keyinit</userinput>
Adding unfurl:
Reminder - Only use this method if you are directly connected.
If you are using telnet or rlogin exit with no password and use keyinit -s.
Enter secret password: 
Again secret password: 

ID unfurl s/key is 99 to17757
DEFY CLUB PRO NASH LACE SOFT</screen>

      <para>For OPIE, <command>opiepasswd</command> is used instead:</para>

      <screen>&prompt.user; <userinput>opiepasswd -c</userinput>
[grimreaper] ~ $ opiepasswd -f -c
Adding unfurl:
Only use this method from the console; NEVER from remote. If you are using
telnet, xterm, or a dial-in, type ^C now or exit with no password.
Then run opiepasswd without the -c parameter.
Using MD5 to compute responses.
Enter new secret pass phrase:
Again new secret pass phrase:
ID unfurl OTP key is 499 to4268
MOS MALL GOAT ARM AVID COED
</screen>

      <para>At the <prompt>Enter new secret pass phrase:</prompt> or
        <prompt>Enter secret password:</prompt> prompts, you
	should enter a password or phrase.  Remember, this is not the
	password that you will use to login with, this is used to generate
	your one-time login keys.  The <quote>ID</quote> line gives the
	parameters of your particular instance: your login name, the
        iteration count, and seed.  When logging in the system
	will remember these parameters and present them back to you so you
	do not have to remember them.  The last line gives the particular
	one-time password which corresponds to those parameters and your
	secret password; if you were to re-login immediately, this
	one-time password is the one you would use.</para>
    </sect2>

    <sect2>
      <title>Insecure Connection Initialization</title>
      
      <para>To initialize or change your secret password over an
	insecure connection, you will need to already have a secure
	connection to some place where you can run <command>key</command>
        or <command>opiekey</command>; this might be in the form of a
	desk accessory on a &macintosh;, or a shell prompt on a machine you
	trust.  You will also need to make up an iteration count (100 is
	probably a good value), and you may make up your own seed or use a
	randomly-generated one.  Over on the insecure connection (to the
	machine you are initializing), use the <command>keyinit
	-s</command> command:</para>

      <screen>&prompt.user; <userinput>keyinit -s</userinput>
Updating unfurl:
Old key: to17758
Reminder you need the 6 English words from the key command.
Enter sequence count from 1 to 9999: <userinput>100</userinput>
Enter new key [default to17759]: 
s/key 100 to 17759
s/key access password:
s/key access password:<userinput>CURE MIKE BANE HIM RACY GORE</userinput>
</screen>

      <para>For OPIE, you need to use <command>opiepasswd</command>:</para>

      <screen>&prompt.user; <userinput>opiepasswd</userinput>

Updating unfurl:
You need the response from an OTP generator.
Old secret pass phrase:
        otp-md5 498 to4268 ext
        Response: GAME GAG WELT OUT DOWN CHAT
New secret pass phrase:
        otp-md5 499 to4269
        Response: LINE PAP MILK NELL BUOY TROY

ID mark OTP key is 499 gr4269
LINE PAP MILK NELL BUOY TROY
</screen>

      <para>To accept the default seed (which the
	<command>keyinit</command> program confusingly calls a
	<literal>key</literal>), press <keycap>Return</keycap>.
	Then before entering an
	access password, move over to your secure connection or S/Key desk
	accessory, and give it the same parameters:</para>

      <screen>&prompt.user; <userinput>key 100 to17759</userinput>
Reminder - Do not use this program while logged in via telnet or rlogin.
Enter secret password: <userinput>&lt;secret password&gt;</userinput>
CURE MIKE BANE HIM RACY GORE</screen>

      <para>Or for OPIE:</para>

      <screen>&prompt.user; <userinput>opiekey 498 to4268</userinput>
Using the MD5 algorithm to compute response.
Reminder: Don't use opiekey from telnet or dial-in sessions.
Enter secret pass phrase:
GAME GAG WELT OUT DOWN CHAT
</screen>

      <para>Now switch back over to the insecure connection, and copy the
	one-time password generated over to the relevant program.</para>
    </sect2>

    <sect2>
      <title>Generating a Single One-time Password</title>

      <para>Once you have initialized S/Key or OPIE, when you login you will be 
	presented with a prompt like this:</para>

<screen>&prompt.user; <userinput>telnet example.com</userinput>
Trying 10.0.0.1...
Connected to example.com
Escape character is '^]'.

FreeBSD/i386 (example.com) (ttypa)

login: <userinput>&lt;username&gt;</userinput>
s/key 97 fw13894
Password: </screen>

      <para>Or for OPIE:</para>

<screen>&prompt.user; <userinput>telnet example.com</userinput>
Trying 10.0.0.1...
Connected to example.com
Escape character is '^]'.

FreeBSD/i386 (example.com) (ttypa)

login: <userinput>&lt;username&gt;</userinput>
otp-md5 498 gr4269 ext
Password: </screen>

      <para>As a side note, the S/Key and OPIE prompts have a useful feature
	(not shown here): if you press <keycap>Return</keycap>
	at the password prompt, the
	prompter will turn echo on, so you can see what you are
	typing.  This can be extremely useful if you are attempting to
	type in a password by hand, such as from a printout.</para>

      <indexterm><primary>MS-DOS</primary></indexterm>
      <indexterm><primary>Windows</primary></indexterm>
      <indexterm><primary>MacOS</primary></indexterm>

      <para>At this point you need to generate your one-time password to
	answer this login prompt.  This must be done on a trusted system
	that you can run <command>key</command> or
        <command>opiekey</command> on.  (There are versions of these for DOS,
	&windows; and &macos; as well.) They need both the iteration count and
	the seed as command line options.  You can cut-and-paste these
        right from the login prompt on the machine that you are logging
        in to.</para>

      <para>On the trusted system:</para>

      <screen>&prompt.user; <userinput>key 97 fw13894</userinput>
Reminder - Do not use this program while logged in via telnet or rlogin.
Enter secret password: 
WELD LIP ACTS ENDS ME HAAG</screen>

      <para>For OPIE:</para>

      <screen>&prompt.user; <userinput>opiekey 498 to4268</userinput>
Using the MD5 algorithm to compute response.
Reminder: Don't use opiekey from telnet or dial-in sessions.
Enter secret pass phrase:
GAME GAG WELT OUT DOWN CHAT</screen>

      <para>Now that you have your one-time password you can continue
	logging in:</para>

      <screen>login: <userinput>&lt;username&gt;</userinput>
s/key 97 fw13894
Password: <userinput>&lt;return to enable echo&gt;</userinput>
s/key 97 fw13894
Password [echo on]: WELD LIP ACTS ENDS ME HAAG
Last login: Tue Mar 21 11:56:41 from 10.0.0.2 ... </screen>

    </sect2>

    <sect2>
      <title>Generating Multiple One-time Passwords</title>

      <para>Sometimes you have to go places where you do not have
	access to a trusted machine or secure connection.  In this case,
	it is possible to use the <command>key</command> and
	<command>opiekey</command> commands to
	generate a number of one-time passwords beforehand to be printed
	out and taken with you.  For example:</para>

      <screen>&prompt.user; <userinput>key -n 5 30 zz99999</userinput>
Reminder - Do not use this program while logged in via telnet or rlogin.
Enter secret password: <userinput>&lt;secret password&gt;</userinput>
26: SODA RUDE LEA LIND BUDD SILT 
27: JILT SPY DUTY GLOW COWL ROT  
28: THEM OW COLA RUNT BONG SCOT  
29: COT MASH BARR BRIM NAN FLAG  
30: CAN KNEE CAST NAME FOLK BILK</screen>

      <para>Or for OPIE:</para>

      <screen>&prompt.user; <userinput>opiekey -n 5 30 zz99999</userinput>
Using the MD5 algorithm to compute response.
Reminder: Don't use opiekey from telnet or dial-in sessions.
Enter secret pass phrase: <userinput>&lt;secret password&gt;</userinput>
26: JOAN BORE FOSS DES NAY QUIT
27: LATE BIAS SLAY FOLK MUCH TRIG
28: SALT TIN ANTI LOON NEAL USE
29: RIO ODIN GO BYE FURY TIC
30: GREW JIVE SAN GIRD BOIL PHI</screen>

      <para>The <option>-n 5</option> requests five keys in sequence, the
	<option>30</option> specifies what the last iteration number
	should be.  Note that these are printed out in
	<emphasis>reverse</emphasis> order of eventual use.  If you are
	really paranoid, you might want to write the results down by hand;
	otherwise you can cut-and-paste into <command>lpr</command>.  Note
	that each line shows both the iteration count and the one-time
	password; you may still find it handy to scratch off passwords as
	you use them.</para>
    </sect2>

    <sect2>
      <title>Restricting Use of &unix; Passwords</title>

      <para>S/Key can place restrictions on the use of &unix; passwords based
	on the host name, user name, terminal port, or IP address of a
	login session.  These restrictions can be found in the
	configuration file <filename>/etc/skey.access</filename>.  The
	&man.skey.access.5; manual page has more information on the complete
	format of the file and also details some security cautions to be
	aware of before depending on this file for security.</para>

      <para>If there is no <filename>/etc/skey.access</filename> file
	(this is the default on FreeBSD 4.X systems), then all users will
	be allowed to use &unix; passwords.  If the file exists, however,
	then all users will be required to use S/Key unless explicitly
	permitted to do otherwise by configuration statements in the
	<filename>skey.access</filename> file.  In all cases, &unix;
	passwords are permitted on the console.</para>

      <para>Here is a sample <filename>skey.access</filename> configuration
	file which illustrates the three most common sorts of configuration
	statements:</para>

      <programlisting>permit internet 192.168.0.0 255.255.0.0
permit user fnord
permit port ttyd0</programlisting>

      <para>The first line (<literal>permit internet</literal>) allows
	users whose IP source address (which is vulnerable to spoofing)
	matches the specified value and mask, to use &unix; passwords.  This
	should not be considered a security mechanism, but rather, a means
	to remind authorized users that they are using an insecure network
	and need to use S/Key for authentication.</para>

      <para>The second line (<literal>permit user</literal>) allows the
	specified username, in this case <username>fnord</username>, to use
	&unix; passwords at any time.  Generally speaking, this should only
	be used for people who are either unable to use the
	<command>key</command> program, like those with dumb terminals, or
	those who are uneducable.</para>

      <para>The third line (<literal>permit port</literal>) allows all
	users logging in on the specified terminal line to use &unix;
	passwords; this would be used for dial-ups.</para>

      <para>OPIE can restrict the use of &unix; passwords based on the IP
	address of a login session just like S/Key does.  The relevant file
	is <filename>/etc/opieaccess</filename>, which is present by default
	on FreeBSD 5.0 and newer systems.  Please check &man.opieaccess.5;
	for more information on this file and which security considerations
	you should be aware of when using it.</para>
	
      <para>Here is a sample <filename>opieaccess</filename> file:</para>

      <programlisting>permit 192.168.0.0 255.255.0.0</programlisting>

      <para>This line allows users whose IP source address (which is
	vulnerable to spoofing) matches the specified value and mask,
	to use &unix; passwords at any time.</para>
	
      <para>If no rules in <filename>opieaccess</filename> are matched,
	the default is to deny non-OPIE logins.</para>

    </sect2>
  </sect1>

  <sect1 id="kerberosIV">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Mark</firstname>
	  <surname>Murray</surname>
	  <contrib>Contributed by </contrib>
	</author>
      </authorgroup>
      <authorgroup>
	<author>
	  <firstname>Mark</firstname>
	  <surname>Dapoz</surname>
	  <contrib>Based on a contribution by </contrib>
	</author>
      </authorgroup>
    </sect1info>

    <title>KerberosIV</title>

    <para>Kerberos is a network add-on system/protocol that allows users to
      authenticate themselves through the services of a secure server.
      Services such as remote login, remote copy, secure inter-system file
      copying and other high-risk tasks are made considerably safer and more
      controllable.</para>

    <para>The following instructions can be used as a guide on how to set up
      Kerberos as distributed for FreeBSD.  However, you should refer to the
      relevant manual pages for a complete description.</para>

    <sect2>
      <title>Installing KerberosIV</title>

      <indexterm><primary>MIT</primary></indexterm>
      <indexterm>
	<primary>KerberosIV</primary>
	<secondary>Installing</secondary>
      </indexterm>
      <para>Kerberos is an optional component of &os;.  The easiest
        way to install this software is by selecting the <literal>krb4</literal> or
        <literal>krb5</literal> distribution in <application>sysinstall</application>
        during the initial installation of FreeBSD.  This will install
        the <quote>eBones</quote> (KerberosIV) or <quote>Heimdal</quote> (Kerberos5)
        implementation of Kerberos.  These implementations are
        included because they are developed outside the USA/Canada and
        were thus available to system owners outside those countries
        during the era of restrictive export controls on cryptographic
        code from the USA.</para>

      <para>Alternatively, the MIT implementation of Kerberos is
        available from the ports collection as
        <filename role="package">security/krb5</filename>.</para>
    </sect2>

    <sect2>
      <title>Creating the Initial Database</title>
      
      <para>This is done on the Kerberos server only.  First make sure that
	you do not have any old Kerberos databases around.  You should change
	to the directory <filename>/etc/kerberosIV</filename> and check that
	only the following files are present:</para>
	  
      <screen>&prompt.root; <userinput>cd /etc/kerberosIV</userinput>
&prompt.root; <userinput>ls</userinput>
README		krb.conf        krb.realms</screen>
	  
      <para>If any additional files (such as <filename>principal.*</filename>
	or <filename>master_key</filename>) exist, then use the
	<command>kdb_destroy</command> command to destroy the old Kerberos
	database, or if Kerberos is not running, simply delete the extra
	files.</para>
	  
      <para>You should now edit the <filename>krb.conf</filename> and
	<filename>krb.realms</filename> files to define your Kerberos realm.
	In this case the realm will be <literal>EXAMPLE.COM</literal> and the
	server is <hostid role="fqdn">grunt.example.com</hostid>.  We edit
	or create the <filename>krb.conf</filename> file:</para>
	  
      <screen>&prompt.root; <userinput>cat krb.conf</userinput>
EXAMPLE.COM
EXAMPLE.COM grunt.example.com admin server
CS.BERKELEY.EDU okeeffe.berkeley.edu
ATHENA.MIT.EDU kerberos.mit.edu
ATHENA.MIT.EDU kerberos-1.mit.edu
ATHENA.MIT.EDU kerberos-2.mit.edu
ATHENA.MIT.EDU kerberos-3.mit.edu
LCS.MIT.EDU kerberos.lcs.mit.edu
TELECOM.MIT.EDU bitsy.mit.edu
ARC.NASA.GOV trident.arc.nasa.gov</screen>
	  
      <para>In this case, the other realms do not need to be there.  They are
	here as an example of how a machine may be made aware of multiple
	realms.  You may wish to not include them for simplicity.</para>
	  
      <para>The first line names the realm in which this system works.  The
	other lines contain realm/host entries.  The first item on a line is a
	realm, and the second is a host in that realm that is acting as a
	<quote>key distribution center</quote>.  The words <literal>admin
	  server</literal> following a host's name means that host also
	provides an administrative database server.  For further explanation
	of these terms, please consult the Kerberos manual pages.</para>
	  
      <para>Now we have to add <hostid role="fqdn">grunt.example.com</hostid>
	to the <literal>EXAMPLE.COM</literal> realm and also add an entry to
	put all hosts in the <hostid role="domainname">.example.com</hostid>
	domain in the <literal>EXAMPLE.COM</literal> realm.  The
	<filename>krb.realms</filename> file would be updated as
	follows:</para>
	  
      <screen>&prompt.root; <userinput>cat krb.realms</userinput>
grunt.example.com EXAMPLE.COM
.example.com EXAMPLE.COM
.berkeley.edu CS.BERKELEY.EDU
.MIT.EDU ATHENA.MIT.EDU
.mit.edu ATHENA.MIT.EDU</screen>
	  
      <para>Again, the other realms do not need to be there.  They are here as
	an example of how a machine may be made aware of multiple realms.  You
	may wish to remove them to simplify things.</para>
	  
      <para>The first line puts the <emphasis>specific</emphasis> system into
	the named realm.  The rest of the lines show how to default systems of
	a particular subdomain to a named realm.</para>
	  
      <para>Now we are ready to create the database.  This only needs to run
	on the Kerberos server (or Key Distribution Center).  Issue the
	<command>kdb_init</command> command to do this:</para>
	  
      <screen>&prompt.root; <userinput>kdb_init</userinput>
<prompt>Realm name [default  ATHENA.MIT.EDU ]:</prompt> <userinput>EXAMPLE.COM</userinput>
You will be prompted for the database Master Password.
It is important that you NOT FORGET this password.
		
<prompt>Enter Kerberos master key:</prompt> </screen>
	  
      <para>Now we have to save the key so that servers on the local machine
	can pick it up.  Use the <command>kstash</command> command to do
	this:</para>
	
      <screen>&prompt.root; <userinput>kstash</userinput>
	      
<prompt>Enter Kerberos master key:</prompt>

Current Kerberos master key version is 1.

Master key entered. BEWARE!</screen>
	
      <para>This saves the encrypted master password in
	<filename>/etc/kerberosIV/master_key</filename>.</para>
    </sect2>
    
    <sect2>
      <title>Making It All Run</title>
	
      <indexterm>
	<primary>KerberosIV</primary>
	<secondary>Inital Startup</secondary>
      </indexterm>

      <para>Two principals need to be added to the database for
	<emphasis>each</emphasis> system that will be secured with Kerberos.
	Their names are <literal>kpasswd</literal> and <literal>rcmd</literal>.
	These two principals are made for each system, with the instance being
	the name of the individual system.</para>
	  
      <para>These daemons, <application>kpasswd</application> and
	<application>rcmd</application> allow other systems to change Kerberos
	passwords and run commands like &man.rcp.1;,
	&man.rlogin.1; and &man.rsh.1;.</para>
	  
      <para>Now let us add these entries:</para>
	    
      <screen>&prompt.root; <userinput>kdb_edit</userinput>
Opening database...

<prompt>Enter Kerberos master key:</prompt>

Current Kerberos master key version is 1.

Master key entered.  BEWARE!
Previous or default values are in [brackets] ,
enter return to leave the same, or new value.

<prompt>Principal name:</prompt> <userinput>passwd</userinput>
<prompt>Instance:</prompt> <userinput>grunt</userinput>

&lt;Not found&gt;, <prompt>Create [y] ?</prompt> <userinput>y</userinput>

Principal: passwd, Instance: grunt, kdc_key_ver: 1
<prompt>New Password:</prompt>                    &lt;---- enter RANDOM here
Verifying password

<prompt>New Password:</prompt> &lt;---- enter RANDOM here

<prompt>Random password [y] ?</prompt> <userinput>y</userinput>

Principal's new key version = 1
<prompt>Expiration date (enter yyyy-mm-dd) [ 2000-01-01 ] ?</prompt>
<prompt>Max ticket lifetime (*5 minutes) [ 255 ] ?</prompt>
<prompt>Attributes [ 0 ] ?</prompt>
Edit O.K.
<prompt>Principal name:</prompt> <userinput>rcmd</userinput>
<prompt>Instance:</prompt> <userinput>grunt</userinput>

&lt;Not found&gt;, <prompt>Create [y] ?</prompt>

Principal: rcmd, Instance: grunt, kdc_key_ver: 1
<prompt>New Password:</prompt>		&lt;---- enter RANDOM here
Verifying password

<prompt>New Password:</prompt>           &lt;---- enter RANDOM here

<prompt>Random password [y] ?</prompt>

Principal's new key version = 1
<prompt>Expiration date (enter yyyy-mm-dd) [ 2000-01-01 ] ?</prompt>
<prompt>Max ticket lifetime (*5 minutes) [ 255 ] ?</prompt>
<prompt>Attributes [ 0 ] ?</prompt>
Edit O.K.
<prompt>Principal name:</prompt>         &lt;---- null entry here will cause an exit</screen>
    </sect2>

    <sect2>
      <title>Creating the Server File</title>
      
      <para>We now have to extract all the instances which define the
	services on each machine.  For this we use the
	<command>ext_srvtab</command> command.  This will create a file
	which must be copied or moved <emphasis>by secure
	  means</emphasis> to each Kerberos client's
	<filename>/etc/kerberosIV</filename> directory.  This file must
	be present on each server and client, and is crucial to the
	operation of Kerberos.</para>
	  
	  
      <screen>&prompt.root; <userinput>ext_srvtab grunt</userinput>
<prompt>Enter Kerberos master key:</prompt>
		
Current Kerberos master key version is 1.

Master key entered. BEWARE!
Generating 'grunt-new-srvtab'....</screen>
	  
      <para>Now, this command only generates a temporary file which must be
	renamed to <filename>srvtab</filename> so that all the servers can pick
	it up.  Use the &man.mv.1; command to move it into place on
	the original system:</para>
	  
      <screen>&prompt.root; <userinput>mv grunt-new-srvtab srvtab</userinput></screen>
	  
      <para>If the file is for a client system, and the network is not deemed
	safe, then copy the
	<filename><replaceable>client</replaceable>-new-srvtab</filename> to
	removable media and transport it by secure physical means.  Be sure to
	rename it to <filename>srvtab</filename> in the client's
	<filename>/etc/kerberosIV</filename> directory, and make sure it is
	mode 600:</para>
	  
      <screen>&prompt.root; <userinput>mv grumble-new-srvtab srvtab</userinput>
&prompt.root; <userinput>chmod 600 srvtab</userinput></screen>
    </sect2>
    
    <sect2>
      <title>Populating the Database</title>
      
      <para>We now have to add some user entries into the database.  First
	let us create an entry for the user <username>jane</username>.  Use the
	<command>kdb_edit</command> command to do this:</para>
	  
      <screen>&prompt.root; <userinput>kdb_edit</userinput>
Opening database...

<prompt>Enter Kerberos master key:</prompt>

Current Kerberos master key version is 1.

Master key entered.  BEWARE!
Previous or default values are in [brackets] ,
enter return to leave the same, or new value.

<prompt>Principal name:</prompt> <userinput>jane</userinput>
<prompt>Instance:</prompt>

&lt;Not found&gt;, <prompt>Create [y] ?</prompt> <userinput>y</userinput>

Principal: jane, Instance: , kdc_key_ver: 1
<prompt>New Password:</prompt>                &lt;---- enter a secure password here
Verifying password

<prompt>New Password:</prompt>                &lt;---- re-enter the password here
Principal's new key version = 1
<prompt>Expiration date (enter yyyy-mm-dd) [ 2000-01-01 ] ?</prompt>
<prompt>Max ticket lifetime (*5 minutes) [ 255 ] ?</prompt>
<prompt>Attributes [ 0 ] ?</prompt>
Edit O.K.
<prompt>Principal name:</prompt>		   &lt;---- null entry here will cause an exit</screen>
    </sect2>

    <sect2>
      <title>Testing It All Out</title>
      
      <para>First we have to start the Kerberos daemons.  Note that if you
	have correctly edited your <filename>/etc/rc.conf</filename> then this
	will happen automatically when you reboot.  This is only necessary on
	the Kerberos server.  Kerberos clients will automatically get what
	they need from the <filename>/etc/kerberosIV</filename>
	directory.</para>
	  
      <screen>&prompt.root; <userinput>kerberos &amp;</userinput>
Kerberos server starting
Sleep forever on error
Log file is /var/log/kerberos.log
Current Kerberos master key version is 1.

Master key entered. BEWARE!

Current Kerberos master key version is 1
Local realm: EXAMPLE.COM
&prompt.root; <userinput>kadmind -n &amp;</userinput>
KADM Server KADM0.0A initializing
Please do not use 'kill -9' to kill this job, use a
regular kill instead

Current Kerberos master key version is 1.

Master key entered.  BEWARE!</screen>
	  
      <para>Now we can try using the <command>kinit</command> command to get a
	ticket for the ID <username>jane</username> that we created
	above:</para>
	  
      <screen>&prompt.user; <userinput>kinit jane</userinput>
MIT Project Athena (grunt.example.com)
Kerberos Initialization for "jane"
<prompt>Password:</prompt> </screen>
	  
      <para>Try listing the tokens using <command>klist</command> to see if we
	really have them:</para>
	  
      <screen>&prompt.user; <userinput>klist</userinput>
Ticket file:    /tmp/tkt245
Principal:      jane@EXAMPLE.COM

  Issued           Expires          Principal
Apr 30 11:23:22  Apr 30 19:23:22  krbtgt.EXAMPLE.COM@EXAMPLE.COM</screen>
	  
      <para>Now try changing the password using &man.passwd.1; to
	check if the <application>kpasswd</application> daemon can get 
	authorization to the Kerberos database:</para>
	  
      <screen>&prompt.user; <userinput>passwd</userinput>
realm EXAMPLE.COM
<prompt>Old password for jane:</prompt>
<prompt>New Password for jane:</prompt>
Verifying password
<prompt>New Password for jane:</prompt>
Password changed.</screen>
    </sect2>

    <sect2>
      <title>Adding <command>su</command> Privileges</title>
      
      <para>Kerberos allows us to give <emphasis>each</emphasis> user
	who needs <username>root</username> privileges their own
	<emphasis>separate</emphasis> &man.su.1; password.
	We could now add an ID which is authorized to
	&man.su.1; to <username>root</username>.  This is
	controlled by having an instance of <username>root</username>
	associated with a principal.  Using <command>kdb_edit</command>
	we can create the entry <literal>jane.root</literal> in the
	Kerberos database:</para>
	  
      <screen>&prompt.root; <userinput>kdb_edit</userinput>
Opening database...

<prompt>Enter Kerberos master key:</prompt>

Current Kerberos master key version is 1.

Master key entered.  BEWARE!
Previous or default values are in [brackets] ,
enter return to leave the same, or new value.

<prompt>Principal name:</prompt> <userinput>jane</userinput>
<prompt>Instance:</prompt> <userinput>root</userinput>

&lt;Not found&gt;, Create [y] ? y

Principal: jane, Instance: root, kdc_key_ver: 1
<prompt>New Password:</prompt>                    &lt;---- enter a SECURE password here
Verifying password

<prompt>New Password:</prompt>    	 	 &lt;---- re-enter the password here

Principal's new key version = 1
<prompt>Expiration date (enter yyyy-mm-dd) [ 2000-01-01 ] ?</prompt>
<prompt>Max ticket lifetime (*5 minutes) [ 255 ] ?</prompt> <userinput>12</userinput> &lt;--- Keep this short!
<prompt>Attributes [ 0 ] ?</prompt>
Edit O.K.
<prompt>Principal name:</prompt>		         &lt;---- null entry here will cause an exit</screen>
	  
      <para>Now try getting tokens for it to make sure it works:</para>
      
      <screen>&prompt.root; <userinput>kinit jane.root</userinput>
MIT Project Athena (grunt.example.com)
Kerberos Initialization for "jane.root"
<prompt>Password:</prompt></screen>
	  
      <para>Now we need to add the user to <username>root</username>'s
	  <filename>.klogin</filename> file:</para>
	  
      <screen>&prompt.root; <userinput>cat /root/.klogin</userinput>
jane.root@EXAMPLE.COM</screen>
	  
      <para>Now try doing the &man.su.1;:</para>
	  
      <screen>&prompt.user; <userinput>su</userinput>
<prompt>Password:</prompt></screen>
	  
      <para>and take a look at what tokens we have:</para>
	  
      <screen>&prompt.root; <userinput>klist</userinput>
Ticket file:	/tmp/tkt_root_245
Principal:      jane.root@EXAMPLE.COM

  Issued           Expires          Principal
May  2 20:43:12  May  3 04:43:12  krbtgt.EXAMPLE.COM@EXAMPLE.COM</screen>
    </sect2>

    <sect2>
      <title>Using Other Commands</title>
      
      <para>In an earlier example, we created a principal called
	<literal>jane</literal> with an instance <literal>root</literal>.
	This was based on a user with the same name as the principal, and this
	is a Kerberos default; that a
	<literal>&lt;principal&gt;.&lt;instance&gt;</literal> of the form
	<literal>&lt;username&gt;.</literal><username>root</username> will allow
	that <literal>&lt;username&gt;</literal> to &man.su.1; to
	<username>root</username> if the necessary entries are in the
	<filename>.klogin</filename> file in <username>root</username>'s
	home directory:</para>
	  
      <screen>&prompt.root; <userinput>cat /root/.klogin</userinput>
jane.root@EXAMPLE.COM</screen>
      
      <para>Likewise, if a user has in their own home directory lines of the
	form:</para>
      
      <screen>&prompt.user; <userinput>cat ~/.klogin</userinput>
jane@EXAMPLE.COM
jack@EXAMPLE.COM</screen>
	  
      <para>This allows anyone in the <literal>EXAMPLE.COM</literal> realm
	who has authenticated themselves as <username>jane</username> or
	<username>jack</username> (via <command>kinit</command>, see above)
	to access to <username>jane</username>'s
	account or files on this system (<hostid>grunt</hostid>) via
	&man.rlogin.1;, &man.rsh.1; or
	&man.rcp.1;.</para>
	  
      <para>For example, <username>jane</username> now logs into another system using
	Kerberos:</para>
	  
	    <screen>&prompt.user; <userinput>kinit</userinput>
MIT Project Athena (grunt.example.com)
<prompt>Password:</prompt>
&prompt.user; <userinput>rlogin grunt</userinput>
Last login: Mon May  1 21:14:47 from grumble
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
        The Regents of the University of California.   All rights reserved.

FreeBSD BUILT-19950429 (GR386) #0: Sat Apr 29 17:50:09 SAT 1995</screen>
	  
      <para>Or <username>jack</username> logs into <username>jane</username>'s account on the same machine
	(<username>jane</username> having
	set up the <filename>.klogin</filename> file as above, and the person
	in charge of Kerberos having set up principal
	<emphasis>jack</emphasis> with a null instance):</para>
	  
      <screen>&prompt.user; <userinput>kinit</userinput>
&prompt.user; <userinput>rlogin grunt -l jane</userinput>
MIT Project Athena (grunt.example.com)
<prompt>Password:</prompt>
Last login: Mon May  1 21:16:55 from grumble
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
        The Regents of the University of California.   All rights reserved.
FreeBSD BUILT-19950429 (GR386) #0: Sat Apr 29 17:50:09 SAT 1995</screen>
    </sect2>
  </sect1>

  <sect1 id="kerberos5">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Tillman</firstname>
	  <surname>Hodgson</surname>
	  <contrib>Contributed by </contrib>
	</author>
      </authorgroup>
      <authorgroup>
	<author>
	  <firstname>Mark</firstname>
	  <surname>Murray</surname>
	  <contrib>Based on a contribution by </contrib>
	</author>
      </authorgroup>
    </sect1info>

    <title><application>Kerberos5</application></title>

    <para>Every &os; release beyond &os;-5.1 includes support
      only for <application>Kerberos5</application>.  Hence
      <application>Kerberos5</application> is the only version
      included, and its configuration is similar in many aspects
      to that of <application>KerberosIV</application>.  The following
      information only applies to
      <application>Kerberos5</application> in post &os;-5.0
      releases.  Users who wish to use the
      <application>KerberosIV</application> package may install the
      <filename role="package">security/krb4</filename> port.</para>

    <para><application>Kerberos</application> is a network add-on
      system/protocol that allows users to authenticate themselves
      through the services of a secure server.  Services such as remote
      login, remote copy, secure inter-system file copying and other
      high-risk tasks are made considerably safer and more
      controllable.</para>

    <para><application>Kerberos</application> can be described as an
      identity-verifying proxy system.  It can also be described as a
      trusted third-party authentication system.
      <application>Kerberos</application> provides only one
      function &mdash; the secure authentication of users on the network.
      It does not provide authorization functions (what users are
      allowed to do) or auditing functions (what those users did).
      After a client and server have used
      <application>Kerberos</application> to prove their identity, they
      can also encrypt all of their communications to assure privacy
      and data integrity as they go about their business.</para>

    <para>Therefore it is highly recommended that
      <application>Kerberos</application> be used with other security
      methods which provide authorization and audit services.</para>

    <para>The following instructions can be used as a guide on how to set
      up <application>Kerberos</application> as distributed for &os;.
      However, you should refer to the relevant manual pages for a complete
      description.</para>

    <para>For purposes of demonstrating a <application>Kerberos</application>
      installation, the various namespaces will be handled as follows:</para>

    <itemizedlist>
      <listitem>
	<para>The <acronym>DNS</acronym> domain (<quote>zone</quote>)
	  will be example.org.</para>
      </listitem>

      <listitem>
	<para>The <application>Kerberos</application> realm will be
	  EXAMPLE.ORG.</para>
      </listitem>
    </itemizedlist>

    <note>
      <para>Please use real domain names when setting up
	<application>Kerberos</application> even if you intend to run
	it internally.  This avoids <acronym>DNS</acronym> problems
	and assures inter-operation with other
	<application>Kerberos</application> realms.</para>
    </note>

    <sect2>
      <title>History</title>
      <indexterm>
	<primary>Kerberos5</primary>
	<secondary>History</secondary>
      </indexterm>

      <para><application>Kerberos</application> was created by
	<acronym>MIT</acronym> as a solution to network security problems.
	The <application>Kerberos</application> protocol uses strong
	cryptography so that a client can prove its identity to a server
	(and vice versa) across an insecure network connection.</para>

      <para><application>Kerberos</application> is both the name of a
	network authentication protocol and an adjective to describe
	programs that implement the program
	(<application>Kerberos</application> telnet, for example).  The
	current version of the protocol is version 5, described in
	<acronym>RFC</acronym>&nbsp;1510.</para>

      <para>Several free implementations of this protocol are available,
	covering a wide range of operating systems.  The Massachusetts
	Institute of Technology (<acronym>MIT</acronym>), where
	<application>Kerberos</application> was originally developed,
	continues to develop their <application>Kerberos</application>
	package.  It is commonly used in the <acronym>US</acronym>
	as a cryptography product, as such it
	has historically been affected by <acronym>US</acronym> export
	regulations.  The <acronym>MIT</acronym>
	<application>Kerberos</application> is available as a port
	(<filename role="package">security/krb5</filename>).  Heimdal
	<application>Kerberos</application> is another version 5
	implementation, and was explicitly developed outside of the
	<acronym>US</acronym> to avoid export
	regulations (and is thus often included in non-commercial &unix;
	variants).  The Heimdal <application>Kerberos</application>
	distribution is available as a port
	(<filename role="package">security/heimdal</filename>), and a
	minimal installation of it is included in the base &os;
	install.</para>

    <para>In order to reach the widest audience, these instructions assume
	the use of the Heimdal distribution included in &os;.</para>

    </sect2>

    <sect2>
      <title>Setting up a Heimdal <acronym>KDC</acronym></title>
      <indexterm>
	<primary>Kerberos5</primary>
	<secondary>Key Distribution Center Configuration</secondary>
      </indexterm>

      <para>The Key Distribution Center (<acronym>KDC</acronym>) is the
	centralized authentication service that
	<application>Kerberos</application> provides &mdash; it is the
	computer that issues <application>Kerberos</application> tickets.
	The <acronym>KDC</acronym> is considered <quote>trusted</quote> by
	all other computers in the <application>Kerberos</application>
	realm, and thus has heightened security concerns.</para>

    <para>Note that while running the <application>Kerberos</application>
	server requires very few computing resources, a dedicated machine
	acting only as a <acronym>KDC</acronym> is recommended for security
	reasons.</para>

    <para>To begin setting up a <acronym>KDC</acronym>, ensure that your
	<filename>/etc/rc.conf</filename> file contains the correct
	settings to act as a <acronym>KDC</acronym> (you may need to adjust
	paths to reflect your own system):</para>

    <programlisting>kerberos5_server_enable="YES"
kadmind5_server_enable="YES"
kerberos_stash="YES"</programlisting>

      <note>
	<para>The <option>kerberos_stash</option> is only available in
	  &os; 4.X.</para>
      </note>

      <para>Next we will set up your <application>Kerberos</application>
	config file, <filename>/etc/krb5.conf</filename>:</para>

      <programlisting>[libdefaults]
    default_realm = EXAMPLE.ORG
[realms]
    EXAMPLE.ORG = {
        kdc = kerberos.example.org
    }
[domain_realm]
    .example.org = EXAMPLE.ORG</programlisting>

      <para>Note that this <filename>/etc/krb5.conf</filename> file implies
	that your <acronym>KDC</acronym> will have the fully-qualified
	hostname of <hostid role="fqdn">kerberos.example.org</hostid>.
	You will need to add a CNAME (alias) entry to your zone file to
	accomplish this if your <acronym>KDC</acronym> has a different
	hostname.</para>

      <note>
	<para>For large networks with a properly configured
	  <acronym>BIND</acronym> <acronym>DNS</acronym> server, the
	  above example could be trimmed to:</para>

	<programlisting>[libdefaults]
      default_realm = EXAMPLE.ORG</programlisting>

	<para>With the following lines being appended to the
	  <hostid role="fqdn">example.org</hostid> zonefile:</para>

	<programlisting>_kerberos._udp      IN  SRV     01 00 88 kerberos.example.org.
_kerberos._tcp      IN  SRV     01 00 88 kerberos.example.org.
_kpasswd._udp       IN  SRV     01 00 464 kerberos.example.org.
_kerberos-adm._tcp  IN  SRV     01 00 749 kerberos.example.org.
_kerberos           IN  TXT     EXAMPLE.ORG.</programlisting></note>

      <para>Next we will create the <application>Kerberos</application>
	database.  This database contains the keys of all principals encrypted
	with a master password.  You are not
	required to remember this password, it will be stored in a file
	(<filename>/var/heimdal/m-key</filename>).  To create the master
	key, run <command>kstash</command> and enter a password.</para>

      <para>Once the master key has been created, you can initialize the
	database using the <command>kadmin</command> program with the
	<literal>-l</literal> option (standing for <quote>local</quote>).
	This option instructs <command>kadmin</command> to modify the
	database files directly rather than going through the
	<command>kadmind</command> network service.  This handles the
	chicken-and-egg problem of trying to connect to the database
	before it is created.  Once you have the <command>kadmin</command>
	prompt, use the <command>init</command> command to create your
	realms initial database.</para>

      <para>Lastly, while still in <command>kadmin</command>, create your
	first principal using the <command>add</command> command.  Stick
	to the defaults options for the principal for now, you can always
	change them later with the <command>modify</command> command.
	Note that you can use the <literal>?</literal> command at any
	prompt to see the available options.</para>

      <para>A sample database creation session is shown below:</para>

      <screen>&prompt.root; <userinput>kstash</userinput>
Master key: <userinput>xxxxxxxx</userinput>
Verifying password - Master key: <userinput>xxxxxxxx</userinput>

&prompt.root; <userinput>kadmin -l</userinput>
kadmin> <userinput>init EXAMPLE.ORG</userinput>
Realm max ticket life [unlimited]:
kadmin> <userinput>add tillman</userinput>
Max ticket life [unlimited]:
Max renewable life [unlimited]:
Attributes []:
Password: <userinput>xxxxxxxx</userinput>
Verifying password - Password: <userinput>xxxxxxxx</userinput></screen>

      <para>Now it is time to start up the <acronym>KDC</acronym> services.
	Run <command>/etc/rc.d/kerberos start</command> and
	<command>/etc/rc.d/kadmind start</command> to bring up the
	services.  Note that you won't have any kerberized daemons running
	at this point but you should be able to confirm the that the
	<acronym>KDC</acronym> is functioning by obtaining and listing a
	ticket for the principal (user) that you just created from the
	command-line of the <acronym>KDC</acronym> itself:</para>

      <screen>&prompt.user; <userinput>k5init <replaceable>tillman</replaceable></userinput>
tillman@EXAMPLE.ORG's Password:

&prompt.user; <userinput>k5list</userinput>
Credentials cache: FILE:<filename>/tmp/krb5cc_500</filename>
	Principal: tillman@EXAMPLE.ORG

  Issued           Expires          Principal
Aug 27 15:37:58  Aug 28 01:37:58  krbtgt/EXAMPLE.ORG@EXAMPLE.ORG</screen>

      </sect2>

      <sect2>
	<title><application>Kerberos</application> enabling a server with
	  Heimdal services</title>

        <indexterm>
	  <primary>Kerberos5</primary>
	  <secondary>Enabling Services</secondary>
        </indexterm>

	<para>First, we need a copy of the <application>Kerberos</application>
	  configuration file, <filename>/etc/krb5.conf</filename>.  To do
	  so, simply copy it over to the client computer from the
	  <acronym>KDC</acronym> in a secure fashion (using network utilities,
	  such as &man.scp.1;, or physically via a
	  floppy disk).</para>

	<para>Next you need a <filename>/etc/krb5.keytab</filename> file.
	  This is the major difference between a server providing
	  <application>Kerberos</application> enabled daemons and a
	  workstation &mdash; the server must have a
	  <filename>keytab</filename> file.  This file
	  contains the servers host key, which allows it and the
	  <acronym>KDC</acronym> to verify each others identity.  It
	  must be transmitted to the server in a secure fashion, as the
	  security of the server can be broken if the key is made public.
	  This explicitly means that transferring it via a clear text
	  channel, such as <acronym>FTP</acronym>, is a very bad idea.</para>

	<para>Typically, you transfer to the <filename>keytab</filename>
	  to the server using the <command>kadmin</command> program.
	  This is handy because you also need to create the host principal
	  (the <acronym>KDC</acronym> end of the
	  <filename>krb5.keytab</filename>) using
	  <command>kadmin</command>.</para>

	<para>Note that you must have already obtained a ticket and that this
	  ticket must be allowed to use the <command>kadmin</command>
	  interface in the <filename>kadmind.acl</filename>.  See the section
	  titled <quote>Remote administration</quote> in the Heimdal info
	  pages (<command>info heimdal</command>) for details on designing
	  access control lists.  If you do not want to enable remote
	  <command>kadmin</command> access, you can simply securely connect
	  to the <acronym>KDC</acronym> (via local console,
	  &man.ssh.1; or <application>Kerberos</application>
	  &man.telnet.1;) and perform administration locally
	  using <command>kadmin -l</command>.</para>

	<para>After installing the <filename>/etc/krb5.conf</filename> file,
	  you can use <command>kadmin</command> from the
	  <application>Kerberos</application> server.  The
	  <command>add --random-key</command> command will let you add the
	  servers host principal, and the <command>ext</command> command
	  will allow you to extract the servers host principal to its own
	  keytab.  For example:</para>

	<screen>&prompt.root; <userinput>kadmin</userinput>
kadmin><userinput> add --random-key host/myserver.example.org</userinput>
Max ticket life [unlimited]:
Max renewable life [unlimited]:
Attributes []:
kadmin><userinput> ext host/myserver.example.org</userinput>
kadmin><userinput> exit</userinput></screen>

	<para>Note that the <command>ext</command> command (short for
	  <quote>extract</quote>) stores the extracted key in
	  <filename>/etc/krb5.keytab</filename> by default.</para>

	<para>If you do not have <command>kadmind</command> running on the
	  <acronym>KDC</acronym> (possibly for security reasons) and thus
	  do not have access to <command>kadmin</command> remotely, you
	  can add the host principal
	  (<username>host/myserver.EXAMPLE.ORG</username>) directly on the
	  <acronym>KDC</acronym> and then extract it to a temporary file
	  (to avoid over-writing the <filename>/etc/krb5.keytab</filename>
	  on the <acronym>KDC</acronym>) using something like this:</para>

	<screen>&prompt.root; <userinput>kadmin</userinput>
kadmin><userinput> ext --keytab=/tmp/example.keytab host/myserver.example.org</userinput>
kadmin><userinput> exit</userinput></screen>

	<para>You can then securely copy the keytab to the server
	  computer (using <command>scp</command> or a floppy, for
	  example).  Be sure to specify a non-default keytab name
	  to avoid over-writing the keytab on the
	  <acronym>KDC</acronym>.</para>

	<para>At this point your server can communicate with the
	  <acronym>KDC</acronym> (due to its <filename>krb5.conf</filename>
	  file) and it can prove its own identity (due to the
	  <filename>krb5.keytab</filename> file).  It is now ready for
	  you to enable some <application>Kerberos</application> services.
	  For this example we will enable the <command>telnet</command>
	  service by putting a line like this into your
	  <filename>/etc/inetd.conf</filename> and then restarting the
	  &man.inetd.8; service with
	  <command>/etc/rc.d/inetd restart</command>:</para>

	<programlisting>telnet    stream  tcp     nowait  root    /usr/libexec/telnetd  telnetd -a user</programlisting>

	<para>The critical bit is that the <command>-a</command>
	  (for authentication) type is set to user.  Consult the
	  &man.telnetd.8; manual page for more details.</para>

      </sect2>

      <sect2>
	<title><application>Kerberos</application> enabling a client with Heimdal</title>

	<indexterm>
	  <primary>Kerberos5</primary>
	  <secondary>Client Configuration</secondary>
	</indexterm>

	<para>Setting up a client computer is almost trivially easy.  As
	  far as <application>Kerberos</application> configuration goes,
	  you only need the <application>Kerberos</application>
	  configuration file, located at <filename>/etc/krb5.conf</filename>.
	  Simply securely copy it over to the client computer from the
	  <acronym>KDC</acronym>.</para>

	<para>Test your client computer by attempting to use
	  <command>kinit</command>, <command>klist</command>, and
	  <command>kdestroy</command> from the client to obtain, show, and
	  then delete a ticket for the principal you created above.  You
	  should also be able to use <application>Kerberos</application>
	  applications to connect to <application>Kerberos</application>
	  enabled servers, though if that does not work and obtaining a
	  ticket does the problem is likely with the server and not with
	  the client or the <acronym>KDC</acronym>.</para>

	<para>When testing an application like <command>telnet</command>,
	  try using a packet sniffer (such as &man.tcpdump.1;)
	  to confirm that your password is not sent in the clear.  Try
	  using <command>telnet</command> with the <literal>-x</literal>
	  option, which encrypts the entire data stream (similar to
	  <command>ssh</command>).</para>

	<para>The core <application>Kerberos</application> client applications
	  (traditionally named <command>kinit</command>,
	  <command>klist</command>, <command>kdestroy</command>, and
	  <command>kpasswd</command>) are installed in
	  the base &os; install. Note that &os; versions prior to 5.0
	  renamed them to <command>k5init</command>,
	  <command>k5list</command>, <command>k5destroy</command>,
	  <command>k5passwd</command>, and <command>k5stash</command>
	  (though it is typically only used once).</para>

	<para>Various non-core <application>Kerberos</application> client
	  applications are also installed by default.  This is where the
	  <quote>minimal</quote> nature of the base Heimdal installation is
	  felt: <command>telnet</command> is the only
	  <application>Kerberos</application> enabled service.</para>

	<para>The Heimdal port adds some of the missing client applications:
	  <application>Kerberos</application> enabled versions of
	  <command>ftp</command>, <command>rsh</command>,
	  <command>rcp</command>, <command>rlogin</command>, and a few
	  other less common programs. The <acronym>MIT</acronym> port also
	  contains a full suite of <application>Kerberos</application>
	  client applications.</para>

      </sect2>

      <sect2>
	<title>User configuration files: <filename>.k5login</filename> and <filename>.k5users</filename></title>

	<indexterm>
	  <primary>Kerberos5</primary>
	  <secondary>User Configuration Files</secondary>
	</indexterm>

	<para>Users within a realm typically have their
	  <application>Kerberos</application> principal (such as
	  <username>tillman@EXAMPLE.ORG</username>) mapped to a local
	  user account (such as a local account named
	  <username>tillman</username>).  Client applications such as
	  <command>telnet</command> usually do not require a user name
	  or a principal.</para>

	<para>Occasionally, however, you want to grant access to a local
	  user account to someone who does not have a matching
	  <application>Kerberos</application> principal.  For example,
	  <username>tillman@EXAMPLE.ORG</username> may need access to the
	  local user account <username>webdevelopers</username>.  Other
	  principals may also need access to that local account.</para>

	<para>The <filename>.k5login</filename> and
	  <filename>.k5users</filename> files, placed in a users home
	  directory, can be used similar to a powerful combination of
	  <filename>.hosts</filename> and <filename>.rhosts</filename>,
	  solving this problem. For example, if a
	  <filename>.k5login</filename> with the following
	  contents:</para>

	<screen>tillman@example.org
jdoe@example.org</screen>

	<para>Were to be placed into the home directory of the local user
	  <username>webdevelopers</username> then both principals listed
	  would have access to that account without requiring a shared
	  password.</para>

	<para>Reading the man pages for these commands is recommended.
	  Note that the <command>ksu</command> man page covers
	  <filename>.k5users</filename>.</para>

      </sect2>

      <sect2>
	<title><application>Kerberos</application> Tips, Tricks, and Troubleshooting</title>

	<indexterm>
	  <primary>Kerberos5</primary>
	  <secondary>Troubleshooting</secondary>
	</indexterm>

	<itemizedlist>
	  <listitem>
	    <para>When using either the Heimdal or <acronym>MIT</acronym>
	      <application>Kerberos</application> ports ensure that your
	      <envar>PATH</envar> environment variable lists the
	      <application>Kerberos</application> versions of the client
	      applications before the system versions.</para>
	  </listitem>

	  <listitem>
	    <para>Is your time in sync? Are you sure? If the time is not in
	      sync (typically within five minutes) authentication will
	      fail.</para>
	  </listitem>

	  <listitem>
	    <para><acronym>MIT</acronym> and Heimdal inter-operate nicely.
	      Except for <command>kadmin</command>, the protocol for
	      which is not standardized.</para>
	  </listitem>

	  <listitem>
	    <para>If you change your hostname, you also need to change your
	      <username>host/</username> principal and update your keytab.
	      This also applies to special keytab entries like the
	      <username>www/</username> principal used for Apache's
	      <filename role="package">www/mod_auth_kerb</filename>.</para>
	  </listitem>

	  <listitem>
	    <para>All hosts in your realm must be resolvable (both forwards
	      and reverse) in <acronym>DNS</acronym> (or
	      <filename>/etc/hosts</filename> as a minimum).  CNAMEs
	      will work, but the A and PTR records must be correct and in
	      place. The error message isn't very intuitive:
	      <errorname>Kerberos5 refuses authentication because Read req
	      failed: Key table entry not found</errorname>.</para>
	  </listitem>

	  <listitem>
	    <para>Some operating systems that may being acting as clients
	      to your <acronym>KDC</acronym> do not set the permissions
	      for <command>ksu</command> to be setuid
	      <username>root</username>.  This means that
	      <command>ksu</command> does not work, which is a good
	      security idea but annoying. This is not a
	      <acronym>KDC</acronym> error.</para>
	  </listitem>

	  <listitem>
	    <para>With <acronym>MIT</acronym>
	      <application>Kerberos</application>, if you want to allow a
	      principal to have a ticket life longer than the default ten
	      hours, you must use <command>modify_principal</command> in
	      <command>kadmin</command> to change the maxlife of both the
	      principal in question and the <username>krbtgt</username>
	      principal.  Then the principal can use the
	      <literal>-l</literal> option with <command>kinit</command>
	      to request a ticket with a longer lifetime.</para>
	  </listitem>

	  <listitem>
	    <note><para>If you run a packet sniffer on your
	      <acronym>KDC</acronym> to add in troubleshooting and then
	      run <command>kinit</command> from a workstation, you will
	      notice that your <acronym>TGT</acronym> is sent
	      immediately upon running <command>kinit</command> &mdash;
	      even before you type your password!  The explanation is
	      that the <application>Kerberos</application> server freely
	      transmits a <acronym>TGT</acronym> (Ticket Granting
	      Ticket) to any unauthorized request;  however, every
	      <acronym>TGT</acronym> is encrypted in a key derived from
	      the user's password.  Therefore, when a user types their
	      password it is not being sent to the <acronym>KDC</acronym>,
	      it is being used to decrypt the <acronym>TGT</acronym> that
	      <command>kinit</command> already obtained. If the decryption
	      process results in a valid ticket with a valid time stamp,
	      the user has valid <application>Kerberos</application>
	      credentials.  These credentials include a session key for
	      establishing secure communications with the
	      <application>Kerberos</application> server in the future, as
	      well as the actual ticket-granting ticket, which is actually
	      encrypted with the <application>Kerberos</application>
	      server's own key.  This second layer of encryption is
	      unknown to the user, but it is what allows the
	      <application>Kerberos</application> server to verify
	      the authenticity of each <acronym>TGT</acronym>.</para></note>
	  </listitem>

	  <listitem>
	    <para>You have to keep the time in sync between all the
	      computers in your realm.  <acronym>NTP</acronym> is
	      perfect for this.  For more information on
	      <acronym>NTP</acronym>, see
	      <xref linkend="network-ntp">.</para>
	  </listitem>

	  <listitem>
	    <para>If you want to use long ticket lifetimes (a week, for
	      example) and you are using <application>OpenSSH</application>
	      to connect to the machine where your ticket is stored, make
	      sure that <application>Kerberos</application>
	      <option>TicketCleanup</option> is set to <literal>no</literal>
	      in your <filename>sshd_config</filename> or else your tickets
	      will be deleted when you log out.</para>
	  </listitem>

	  <listitem>
	    <para>Remember that host principals can have a longer ticket
	      lifetime as well.  If your user principal has a lifetime of a
	      week but the host you are connecting to has a lifetime of nine
	      hours, you will have an expired host principal in your cache
	      and the ticket cache will not work as expected.</para>
	  </listitem>

	  <listitem>
	    <para>When setting up a <filename>krb5.dict</filename> file to
	    prevent specific bad passwords from being used (the manual page
	    for <command>kadmind</command> covers this briefly), remember
	    that it only applies to principals that have a password policy
	    assigned to them.  The <filename>krb5.dict</filename> files
	    format is simple: one string per line.  Creating a symbolic
	    link to <filename>/usr/share/dict/words</filename> might be
	    useful.</para>
	  </listitem>
        </itemizedlist>

      </sect2>

      <sect2>
	<title>Differences with the <acronym>MIT</acronym> port</title>

	<para>The major difference between the <acronym>MIT</acronym>
	  and Heimdal installs relates to the <command>kadmin</command>
	  program which has a different (but equivalent) set of commands
	  and uses a different protocol.  This has a large implications
	  if your <acronym>KDC</acronym> is <acronym>MIT</acronym> as you
	  will not be able to use the Heimdal <command>kadmin</command>
	  program to administer your <acronym>KDC</acronym> remotely
	  (or vice versa, for that matter).</para>

	<para>The client applications may also take slightly different
	  command line options to accomplish the same tasks.  Following
	  the instructions on the <acronym>MIT</acronym>
	  <application>Kerberos</application> web site
	  (<ulink url="http://web.mit.edu/Kerberos/www/"></ulink>)
	  is recommended. Be careful of path issues: the
	  <acronym>MIT</acronym> port installs into
	  <filename>/usr/local/</filename> by default, and the
	  <quote>normal</quote> system applications may be run instead
	  of <acronym>MIT</acronym> if your <envar>PATH</envar>
	  environment variable lists the system directories first.</para>

	<note><para>With the <acronym>MIT</acronym>
	  <filename role="package">security/krb5</filename> port
	  that is provided by &os;, be sure to read the
	  <filename>/usr/local/share/doc/krb5/README.FreeBSD</filename>
	  file installed by the port if you want to understand why logins
	  via <command>telnetd</command> and <command>klogind</command>
	  behave somewhat oddly.  Most importantly, correcting the
	  <quote>incorrect permissions on cache file</quote> behavior
	  requires that the <command>login.krb5</command> binary be used
	  for authentication so that it can properly change ownership for
	  the forwarded credentials.</para></note>

      </sect2>

      <sect2>
	<title>Mitigating limitations found in <application>Kerberos</application></title>

	<indexterm>
	  <primary>Kerberos5</primary>
	  <secondary>Limitations and Shortcomings</secondary>
	</indexterm>

	<sect3>
	 <title><application>Kerberos</application> is an all-or-nothing approach</title>

	  <para>Every service enabled on the network must be modified to
	    work with <application>Kerberos</application> (or be otherwise
	    secured against network attacks) or else the users credentials
	    could be stolen and re-used.  An example of this would be
	    <application>Kerberos</application> enabling all remote shells
	    (via <command>rsh</command> and <command>telnet</command>, for
	    example) but not converting the <acronym>POP3</acronym> mail
	    server which sends passwords in plaintext.</para>

	</sect3>

	<sect3>
	  <title><application>Kerberos</application> is intended for single-user workstations</title>

	  <para>In a multi-user environment,
	    <application>Kerberos</application> is less secure.
	    This is because it stores the tickets in the
	    <filename>/tmp</filename> directory, which is readable by all
	    users.  If a user is sharing a computer with several other
	    people simultaneously (i.e. multi-user), it is possible that
	    the user's tickets can be stolen (copied) by another
	    user.</para>

	  <para>This can be overcome with the <literal>-c</literal>
	    filename command-line option or (preferably) the
	    <envar>KRB5CCNAME</envar> environment variable, but this
	    is rarely done. In principal, storing the ticket in the users
	    home directory and using simple file permissions can mitigate
	    this problem.</para>

	</sect3>

	<sect3>
	  <title>The KDC is a single point of failure</title>

	  <para>By design, the <acronym>KDC</acronym> must be as secure as
	    the master password database is contained on it.  The
	    <acronym>KDC</acronym> should have absolutely no other
	    services running on it and should be physically secured.  The
	    danger is high because <application>Kerberos</application>
	    stores all passwords encrypted with the same key (the
	    <quote>master</quote> key), which in turn is stored as a file
	    on the <acronym>KDC</acronym>.</para>

	  <para>As a side note, a compromised master key is not quite as
	    bad as one might normally fear.  The master key is only used
	    to encrypt the <application>Kerberos</application> database
	    and as a seed for the random number generator.  As long as
	    access to your <acronym>KDC</acronym> is secure, an attacker
	    cannot do much with the master key.</para>

	  <para>Additionally, if the <acronym>KDC</acronym> is unavailable
	    (perhaps due to a denial of service attack or network problems)
	    the network services are unusable as authentication can not be
	    performed, a recipe for a denial-of-service attack.  This can
	    alleviated with multiple <acronym>KDC</acronym>s (a single
	    master and one or more slaves) and with careful implementation
	    of secondary or fall-back authentication
	    (<acronym>PAM</acronym> is excellent for this).</para>

	</sect3>

	<sect3>
	  <title><application>Kerberos</application> Shortcomings</title>

	  <para><application>Kerberos</application> allows users, hosts
	    and services to authenticate between themselves.  It does not
	    have a mechanism to authenticate the <acronym>KDC</acronym>
	    to the users, hosts or services.  This means that a trojanned
	    <command>kinit</command> (for example) could record all user
	    names and passwords.  Something like
	    <filename role="package">security/tripwire</filename> or
	    other file system integrity checking tools can alleviate
	    this.</para>

	</sect3>
      </sect2>

      <sect2>
	<title>Resources and further information</title>

	<indexterm>
	  <primary>Kerberos5</primary>
	  <secondary>External Resources</secondary>
	</indexterm>

	<itemizedlist>
	  <listitem>
	  <para><ulink
	    url="http://www.faqs.org/faqs/Kerberos-faq/general/preamble.html">
	    The <application>Kerberos</application> FAQ</ulink></para>
	</listitem>

	<listitem>
	  <para><ulink url="http://web.mit.edu/Kerberos/www/dialogue.html">Designing
	    an Authentication System: a Dialogue in Four Scenes</ulink></para>
	</listitem>

	<listitem>
	  <para><ulink url="http://www.ietf.org/rfc/rfc1510.txt?number=1510">RFC 1510,
	    The <application>Kerberos</application> Network Authentication Service
	    (V5)</ulink></para>
	</listitem>

	<listitem>
	  <para><ulink url="http://web.mit.edu/Kerberos/www/"><acronym>MIT</acronym>
	    <application>Kerberos</application> home page</ulink></para>
	</listitem>

	<listitem>
	<para><ulink url="http://www.pdc.kth.se/heimdal/">Heimdal
	  <application>Kerberos</application> home page</ulink></para>
	</listitem>

	</itemizedlist>
    </sect2>
  </sect1>

  <sect1 id="firewalls">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Gary</firstname>
	  <surname>Palmer</surname>
	  <contrib>Contributed by </contrib>
	</author>
	<author>
	  <firstname>Alex</firstname>
	  <surname>Nash</surname>
	</author>
      </authorgroup>
    </sect1info>

    <title>Firewalls</title>
    <indexterm><primary>firewall</primary></indexterm>
    <indexterm>
      <primary>security</primary>
      <secondary>firewalls</secondary>
    </indexterm>

    <para>Firewalls are an area of increasing interest for people who are
      connected to the Internet, and are even finding applications on private
      networks to provide enhanced security.  This section will hopefully
      explain what firewalls are, how to use them, and how to use the
      facilities provided in the FreeBSD kernel to implement them.</para>

    <note>
      <para>People often think that having a firewall between your
	internal network and the <quote>Big Bad Internet</quote> will solve all
	your security problems.  It may help, but a poorly set up firewall
	system is more of a security risk than not having one at all.  A
	firewall can add another layer of security to your systems, but it
	cannot stop a really determined cracker from penetrating your internal
	network.  If you let internal security lapse because you believe your
	firewall to be impenetrable, you have just made the crackers job that
	much easier.</para>
    </note>

    <sect2>
      <title>What Is a Firewall?</title>
      
      <para>There are currently two distinct types of firewalls in common use
	on the Internet today.  The first type is more properly called a
	<emphasis>packet filtering router</emphasis>.  This type of
	firewall utilizes a multi-homed machine and a set of rules to
	determine whether to forward or block individual packets.  A
	multi-homed machine is simply a device with multiple network
	interfaces.
        The second type, known as a <emphasis>proxy
	  server</emphasis>, relies on daemons to provide authentication and to
	forward packets, possibly on a multi-homed machine which has kernel
	packet forwarding disabled.</para>
	  
      <para>Sometimes sites combine the two types of firewalls, so that only a
	certain machine (known as a <emphasis>bastion host</emphasis>) is
	allowed to send packets through a packet filtering router onto an
	internal network.  Proxy services are run on the bastion host, which
	are generally more secure than normal authentication
	mechanisms.</para>
	  
      <para>FreeBSD comes with a kernel packet filter (known as
	IPFW), which is what the rest of this
	section will concentrate on.  Proxy servers can be built on FreeBSD
	from third party software, but there is such a variety of proxy
	servers available that it would be impossible to cover them in this
	section.</para>
	  
      <sect3 id="firewalls-packet-filters">
	<title>Packet Filtering Routers</title>

	<para>A router is a machine which forwards packets between two or more
	  networks.  A packet filtering router is programmed to
	  compare each packet to a list of rules before
	  deciding if it should be forwarded or not.  Most modern IP routing
	  software includes packet filtering functionality that defaults to
	  forwarding all packets.  To enable the filters, you need to define a
	  set of rules.</para>
	    
	<para>To decide whether a packet should be passed on, the firewall looks
	  through its set of rules for a rule which matches the contents of
	  the packet's headers.  Once a match is found, the rule action is
	  obeyed.  The rule action could be to drop the packet, to forward the
	  packet, or even to send an ICMP message back to the originator.
	  Only the first match counts, as the rules are searched in order.
	  Hence, the list of rules can be referred to as a <quote>rule
	  chain</quote>.</para>
	    
	<para>The packet-matching criteria varies depending on the software
	  used, but typically you can specify rules which depend on the source
	  IP address of the packet, the destination IP address, the source
	  port number, the destination port number (for protocols which
	  support ports), or even the packet type (UDP, TCP, ICMP,
	  etc).</para>
      </sect3>
	  
      <sect3 id="firewalls-proxy-servers">
	<title>Proxy Servers</title>
	    
	<para>Proxy servers are machines which have had the normal system
	  daemons (<application>telnetd</application>, 
	  <application>ftpd</application>, etc) replaced with special servers.
	  These
	  servers are called <emphasis>proxy servers</emphasis>, as they
	  normally only allow onward connections to be made.  This enables you
	  to run (for example) a proxy <application>telnet</application> server on your firewall host,
	  and people can <application>telnet</application> in to your firewall from the outside, go
	  through some authentication mechanism, and then gain access to the
	  internal network (alternatively, proxy servers can be used for
	  signals coming from the internal network and heading out).</para>
	    
	<para>Proxy servers are normally more secure than normal servers, and
	  often have a wider variety of authentication mechanisms available,
	  including <quote>one-shot</quote> password systems so that even if
	  someone manages to discover what password you used, they will not be
	  able to use it to gain access to your systems as the password
	  expires immediately after the first use.  As they do not actually give users access to the
	  host machine, it becomes a lot more difficult for someone to install
	  backdoors around your security system.</para>
	    
	<para>Proxy servers often have ways of restricting access further, so
	  that only certain hosts can gain access to the servers.
          Most will also allow the administrator to specify which
	  users can talk to which destination machines.
          Again, what facilities are available
	  depends largely on what proxy software you choose.</para>
      </sect3>
    </sect2>

    <sect2>
      <title>What Does IPFW Allow Me to Do?</title>
      <indexterm><primary><command>ipfw</command></primary></indexterm>
      
      <para>IPFW, the software supplied with
	FreeBSD, is a packet filtering and accounting system which resides in
	the kernel, and has a user-land control utility,
	    &man.ipfw.8;.  Together, they allow you to define and query the
	rules used by the kernel in its routing decisions.</para>
	  
      <para>There are two related parts to IPFW.
	The firewall section performs packet filtering.  There is
	also an IP accounting section which tracks usage of the
	router, based on rules similar to those used in the firewall
	section.  This allows
	the administrator to monitor how much traffic the router is
	getting from a certain machine, or how much WWW traffic it is
	forwarding, for example.</para>
	  
      <para>As a result of the way that IPFW is
	designed, you can use IPFW on non-router
	machines to perform packet filtering on incoming and outgoing
	connections.  This is a special case of the more general use of
	IPFW, and the same commands and techniques
	should be used in this situation.</para>
    </sect2>

    <sect2>
      <title>Enabling IPFW on FreeBSD</title>
      <indexterm>
        <primary><command>ipfw</command></primary>
        <secondary>enabling</secondary>
      </indexterm>
      
      <para>As the main part of the IPFW system
	lives in the kernel, you will need to add one or more options to your
	kernel configuration file, depending on what facilities you want, and
	recompile your kernel.  See "Reconfiguring your Kernel" (<xref
	linkend="kernelconfig">)
	for more details on how to recompile your
	kernel.</para>

      <warning>
	<para>IPFW defaults to a policy of <literal>deny ip from any to
	  any</literal>.  If you do not add other rules during startup to
	  allow access, <emphasis>you will lock yourself out</emphasis> of the
	  server upon rebooting into a firewall-enabled kernel.  We suggest
	  that you set <literal>firewall_type=open</literal> in your
	  <filename>/etc/rc.conf</filename> file when first enabling this
	  feature, then refining the firewall rules in
	  <filename>/etc/rc.firewall</filename> after you have tested that the
	  new kernel feature works properly.  To be on the safe side, you may
	  wish to consider performing the initial firewall configuration from
	  the local console rather than via
	  <application>ssh</application>.  Another option is to build a kernel
	  using both the <literal>IPFIREWALL</literal> and
	  <literal>IPFIREWALL_DEFAULT_TO_ACCEPT</literal> options.  This will
	  change the default rule of IPFW to <literal>allow ip from any to
	  any</literal> and avoid the possibility of a lockout.</para>
      </warning>

      <para>There are currently four kernel configuration options relevant to
	IPFW:</para>
	  
      <variablelist>
	<varlistentry>
	  <term><literal>options IPFIREWALL</literal></term>

	  <listitem>
	    <para>Compiles into the kernel the code for packet
	      filtering.</para>
	  </listitem>
	</varlistentry>
	      
	<varlistentry>
	  <term><literal>options IPFIREWALL_VERBOSE</literal></term>
		
	  <listitem>
	    <para>Enables code to allow logging of packets through
		&man.syslogd.8;.  Without this option, even if you specify
	      that packets should be logged in the filter rules, nothing will
	      happen.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>options IPFIREWALL_VERBOSE_LIMIT=10</literal></term>
		
	  <listitem>
	    <para>Limits the number of packets logged through
		&man.syslogd.8; on a per entry basis.  You may wish to use
	      this option in hostile environments in which you want to log
	      firewall activity, but do not want to be open to a denial of
	      service attack via syslog flooding.</para>

	    <para>When a chain entry reaches the packet limit specified,
	      logging is turned off for that particular entry.  To resume
	      logging, you will need to reset the associated counter using the
		&man.ipfw.8; utility:</para>
	    
	    <screen>&prompt.root; <userinput>ipfw zero 4500</userinput></screen>
	    <para>Where 4500 is the chain entry you wish to continue
	      logging.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>options IPFIREWALL_DEFAULT_TO_ACCEPT</literal></term>

	  <listitem>
	    <para>This changes the default rule action from <quote>deny</quote>
	      to <quote>allow</quote>.  This avoids the possibility of locking
	      yourself out if you happen to boot a kernel with
	      <literal>IPFIREWALL</literal> support but have not configured
	      your firewall yet.  It is also very useful if you often use
	      &man.ipfw.8; as a filter for specific problems as they arise.
	      Use with care though, as this opens up the firewall and changes
	      the way it works.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
      
      <note><para>Previous versions of FreeBSD contained an
	<literal>IPFIREWALL_ACCT</literal>  option.  This is now obsolete as
	the firewall code automatically  includes accounting
	facilities.</para>
      </note>
    </sect2>

    <sect2>
      <title>Configuring IPFW</title>
      <indexterm>
        <primary><command>ipfw</command></primary>
        <secondary>configuring</secondary>
      </indexterm>
      
      <para>The configuration of the IPFW software
	is done through the &man.ipfw.8; utility.  The syntax for this
	command looks quite complicated, but it is relatively simple once you
	understand its structure.</para>

      <para>There are currently four different command categories used by the
	utility: addition/deletion, listing, flushing, and clearing.
	Addition/deletion is used to build the rules that control how packets
	are accepted, rejected, and logged.  Listing is used to examine the
	contents of your rule set (otherwise known as the chain) and packet
	counters (accounting).  Flushing is used to remove all entries from
	the chain.  Clearing is used to zero out one or more accounting
	entries.</para>
	  
      <sect3>
	<title>Altering the IPFW Rules</title>

	<para>The syntax for this form of the command is:
	  <cmdsynopsis>
	    <command>ipfw</command>
	    <arg>-N</arg>
	    <arg choice="plain">command</arg>
	    <arg>index</arg>
	    <arg choice="plain">action</arg>
	    <arg>log</arg>
	    <arg choice="plain">protocol</arg>
	    <arg choice="plain">addresses</arg>
	    <arg>options</arg>
	  </cmdsynopsis></para>

	<para>There is one valid flag when using this form of the
	  command:</para>

	<variablelist>
	  <varlistentry>
	    <term>-N</term>

	    <listitem>
	      <para>Resolve addresses and service names in output.</para>
	    </listitem>
	  </varlistentry>
	</variablelist>

	<para>The <emphasis>command</emphasis> given can be shortened to the
	  shortest unique form.  The valid <emphasis>commands</emphasis>
	  are:</para>
	    
	<variablelist>
	  <varlistentry>
	    <term>add</term>

	    <listitem>
	      <para>Add an entry to the firewall/accounting rule list</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>delete</term>
	    
	    <listitem>
	      <para>Delete an entry from the firewall/accounting rule
		list</para>
	    </listitem>
	  </varlistentry>
	</variablelist>

	<para>Previous versions of IPFW used
	  separate firewall and accounting entries.  The present version
	  provides packet accounting with each firewall entry.</para>
	    
	<para>If an <emphasis>index</emphasis> value is supplied, it is used to
	  place the entry at a specific point in the chain.  Otherwise, the
	  entry is placed at the end of the chain at an index 100 greater than
	  the last chain entry (this does not include the default policy, rule
	  65535, deny).</para>
	    
	<para>The <literal>log</literal> option causes matching rules to be
	  output to the system console if the kernel was compiled with
	  <literal>IPFIREWALL_VERBOSE</literal>.</para>
	    
	<para>Valid <emphasis>actions</emphasis> are:</para>
	    
	<variablelist>
	  <varlistentry>
	    <term>reject</term>

	    <listitem>
	      <para>Drop the packet, and send an ICMP host or port unreachable
		(as appropriate) packet to the source.</para>
	    </listitem>
	  </varlistentry>
		
	  <varlistentry>
	    <term>allow</term>
	    
	    <listitem>
	      <para>Pass the packet on as normal.  (aliases:
		<literal>pass</literal>, <literal>permit</literal>, and
		<literal>accept</literal>)</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>deny</term>
	    
	    <listitem>
	      <para>Drop the packet.  The source is not notified via an
		ICMP message (thus it appears that the packet never
		arrived at the destination).</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>count</term>
	    
	    <listitem>
	      <para>Update packet counters but do not allow/deny the packet
		based on this rule.  The search continues with the next chain
		entry.</para>
	    </listitem>
	  </varlistentry>
	</variablelist>

	<para>Each <emphasis>action</emphasis> will be recognized by the
	  shortest unambiguous prefix.</para>
	    
	<para>The <emphasis>protocols</emphasis> which can be specified
	  are:</para>
	    
	<variablelist>
	  <varlistentry>
	    <term>all</term>

	    <listitem>
	      <para>Matches any IP packet</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>icmp</term>
	    
	    <listitem>
	      <para>Matches ICMP packets</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>tcp</term>
	    
	    <listitem>
	      <para>Matches TCP packets</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>udp</term>
	    
	    <listitem>
	      <para>Matches UDP packets</para>
	    </listitem>
	  </varlistentry>
	</variablelist>

	<para>The <emphasis>address</emphasis> specification is:</para>

	<cmdsynopsis>
	  <arg choice="plain">from</arg>
	  <arg choice="plain"><replaceable>address/mask</replaceable></arg><arg><replaceable>port</replaceable></arg>
	  <arg choice="plain">to</arg>
	  <arg choice="plain"><replaceable>address/mask</replaceable></arg><arg><replaceable>port</replaceable></arg>
	  <arg>via <replaceable>interface</replaceable></arg>
	</cmdsynopsis>
	    
	<para>You can only specify <replaceable>port</replaceable> in
	  conjunction with <emphasis>protocols</emphasis> which support ports
	  (UDP and TCP).</para>
	    
	<para>The <option>via</option> is optional and may specify the IP
	  address or domain name of a local IP interface, or an interface name
	  (e.g.  <devicename>ed0</devicename>) to match only packets coming
	  through this interface.  Interface unit numbers can be specified
	  with an optional wildcard.  For example, <literal>ppp*</literal>
	  would match all kernel PPP interfaces.</para>
	    
	<para>The syntax used to specify an
	  <replaceable>address/mask</replaceable> is:
	  
	  <screen><replaceable>address</replaceable></screen>
	      
	  or
	      
	  <screen><replaceable>address</replaceable>/<replaceable>mask-bits</replaceable></screen>
	      
	  or
	      
	  <screen><replaceable>address</replaceable>:<replaceable>mask-pattern</replaceable></screen>
	</para>

	<para>A valid hostname may be specified in place of the IP address.
	  <option><replaceable>mask-bits</replaceable></option> is a decimal
	  number representing how many bits in the address mask should be set.
	  e.g.  specifying <hostid role="netmask">192.216.222.1/24</hostid>
	  will create a
	  mask which will allow any address in a class C subnet (in this case,
	  <hostid role="ipaddr">192.216.222</hostid>) to be matched.
	  <option><replaceable>mask-pattern</replaceable></option> is an IP
	  address which will be logically AND'ed with the address given.  The
	  keyword <literal>any</literal> may be used to specify <quote>any IP
	  address</quote>.</para>
	    
	<para>The port numbers to be blocked are specified as:
	  
	  <cmdsynopsis>
	    <arg choice="plain"><replaceable>port</replaceable><arg>,<replaceable>port</replaceable><arg>,<replaceable>port</replaceable><arg>&hellip;</arg></arg></arg></arg>
	  </cmdsynopsis>

	  to specify either a single port or a list of ports, or
	  
	  <cmdsynopsis>
	    <arg choice="plain"><replaceable>port</replaceable>-<replaceable>port</replaceable></arg>
	  </cmdsynopsis>

	  to specify a range of ports.  You may also combine a single range
	  with a list, but the range must always be specified first.</para>
	    
	<para>The <emphasis>options</emphasis> available are:</para>

	<variablelist>
	  <varlistentry>
	    <term>frag</term>

	    <listitem>
	      <para>Matches if the packet is not the first fragment of the
		datagram.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>in</term>
	    
	    <listitem>
	      <para>Matches if the packet is on the way in.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>out</term>
	    
	    <listitem>
	      <para>Matches if the packet is on the way out.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>ipoptions <replaceable>spec</replaceable></term>
	    
	    <listitem>
	      <para>Matches if the IP header contains the comma separated list
		of options specified in <replaceable>spec</replaceable>.  The
		supported IP options are: <literal>ssrr</literal>
		(strict source route), <literal>lsrr</literal> (loose source
		route), <literal>rr</literal> (record packet route), and
		<literal>ts</literal> (time stamp).  The absence of a
		particular option may be specified with a leading
		<literal>!</literal>.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>established</term>
	    
	    <listitem>
	      <para>Matches if the packet is part of an already established
		TCP connection (i.e. it has the RST or ACK bits set).  You can
		optimize the performance of the firewall by placing
		<emphasis>established</emphasis> rules early in the
		chain.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>setup</term>
	    
	    <listitem>
	      <para>Matches if the packet is an attempt to establish a TCP
		connection (the SYN bit is set but the ACK bit is
		not).</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>tcpflags <replaceable>flags</replaceable></term>
	    
	    <listitem>
	      <para>Matches if the TCP header contains the comma separated
		list of <replaceable>flags</replaceable>.  The supported flags
		are <literal>fin</literal>, <literal>syn</literal>,
		<literal>rst</literal>, <literal>psh</literal>,
		<literal>ack</literal>, and <literal>urg</literal>.  The
		absence of a particular flag may be indicated by a leading
		<literal>!</literal>.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>icmptypes <replaceable>types</replaceable></term>
	    
	    <listitem>
	      <para>Matches if the ICMP type is present in the list
		<replaceable>types</replaceable>.  The list may be specified
		as any combination of ranges and/or individual types separated
		by commas.  Commonly used ICMP types are: <literal>0</literal>
		echo reply (ping reply), <literal>3</literal> destination
		unreachable, <literal>5</literal> redirect,
		<literal>8</literal> echo request (ping request), and
		<literal>11</literal> time exceeded (used to indicate TTL
		expiration as with &man.traceroute.8;).</para>
	    </listitem>
	  </varlistentry>
	</variablelist>
      </sect3>
      
      <sect3>
	<title>Listing the IPFW Rules</title>

	<para>The syntax for this form of the command is:
	  <cmdsynopsis>
	    <command>ipfw</command>
	    <arg>-a</arg>
	    <arg>-c</arg>
	    <arg>-d</arg>
	    <arg>-e</arg>
	    <arg>-t</arg>
	    <arg>-N</arg>
	    <arg>-S</arg>
	    <arg choice="plain">list</arg>
	  </cmdsynopsis></para>

	<para>There are seven valid flags when using this form of the
	  command:</para>
	    
	<variablelist>
	  <varlistentry>
	    <term>-a</term>

	    <listitem>
	      <para>While listing, show counter values.  This option is the
		only way to see accounting counters.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>-c</term>

	    <listitem>
	      <para>List rules in compact form.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>-d</term>

	    <listitem>
	      <para>Show dynamic rules in addition to static rules.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>-e</term>

	    <listitem>
	      <para>If <option>-d</option> was specified, also show expired
		dynamic rules.</para>
	    </listitem>
	  </varlistentry>
	  
          <varlistentry>
	    <term>-t</term>
	    
	    <listitem>
	      <para>Display the last match times for each chain entry.  The
		time listing is incompatible with the input syntax used by the
		  &man.ipfw.8; utility.</para>
	    </listitem>
	  </varlistentry>
	  
	  <varlistentry>
	    <term>-N</term>
	    
	    <listitem>
	      <para>Attempt to resolve given addresses and service
		names.</para>
	    </listitem>
	  </varlistentry>
	  
          <varlistentry>
	    <term>-S</term>
	    
	    <listitem>
	      <para>Show the set each rule belongs to. If this flag is not
		specified, disabled rules will not be listed.</para>
	    </listitem>
	  </varlistentry>
	</variablelist>
      </sect3>
      
      <sect3>
	<title>Flushing the IPFW Rules</title>

	<para>The syntax for flushing the chain is:
	  <cmdsynopsis>
	    <command>ipfw</command>
	    <arg choice="plain">flush</arg>
	  </cmdsynopsis></para>

	<para>This causes all entries in the firewall chain to be removed
	  except the fixed default policy enforced by the kernel (index
	  65535).  Use caution when flushing rules; the default deny policy
	  will leave your system cut off from the network until allow entries
	  are added to the chain.</para>
      </sect3>
      
      <sect3>
	<title>Clearing the IPFW Packet Counters</title>

	<para>The syntax for clearing one or more packet counters is:
	  <cmdsynopsis>
	    <command>ipfw</command>
	    <arg choice="plain">zero</arg>
	    <arg choice="opt"><replaceable>index</replaceable></arg>
	  </cmdsynopsis></para>

	<para>When used without an <replaceable>index</replaceable> argument,
	  all packet counters are cleared.  If an
	  <replaceable>index</replaceable> is supplied, the clearing operation
	  only affects a specific chain entry.</para>
      </sect3>
    </sect2>

    <sect2>
      <title>Example Commands for <application>ipfw</application></title>
      
      <para>This command will deny all packets from the host <hostid
	  role="fqdn">evil.crackers.org</hostid> to the telnet port of the
	host <hostid role="fqdn">nice.people.org</hostid>:</para>
	  	  
      <screen>&prompt.root; <userinput>ipfw add deny tcp from evil.crackers.org to nice.people.org 23</userinput></screen>
	  
      <para>The next example denies and logs any TCP traffic from the entire
	<hostid role="domainname">crackers.org</hostid> network (a class C) to
	the <hostid role="fqdn">nice.people.org</hostid> machine (any
	port).</para>
	  
      <screen>&prompt.root; <userinput>ipfw add deny log tcp from evil.crackers.org/24 to nice.people.org</userinput></screen>
	  
      <para>If you do not want people sending X sessions to your internal
	network (a subnet of a class C), the following command will do the
	necessary filtering:</para>
	  
      <screen>&prompt.root; <userinput>ipfw add deny tcp from any to my.org/28 6000 setup</userinput></screen>
	  
      <para>To see the accounting records:
	    
	<screen>&prompt.root; <userinput>ipfw -a list</userinput></screen>

	or in the short form
	    
	<screen>&prompt.root; <userinput>ipfw -a l</userinput></screen>
      </para>

      <para>You can also see the last time a chain entry was matched
	with:</para>
      
      <screen>&prompt.root; <userinput>ipfw -at l</userinput></screen>
    </sect2>
    
    <sect2>
      <title>Building a Packet Filtering Firewall</title>
      
      <note>
	<para>The following suggestions are just that: suggestions.  The
	  requirements of each firewall are different and we cannot tell you
	  how to build a firewall to meet your particular requirements.</para>
      </note>
	  
      <para>When initially setting up your firewall, unless you have a test
	bench setup where you can configure your firewall host in a controlled
	environment, it is strongly recommend you use the logging version of the
	commands and enable logging in the kernel.  This will allow you to
	quickly identify problem areas and cure them without too much
	disruption.  Even after the initial setup phase is complete, I
	recommend using the logging for `deny' as it allows tracing of
	possible attacks and also modification of the firewall rules if your
	requirements alter.</para>
	  
      <note>
	<para>If you use the logging versions of the <command>accept</command>
	  command, be aware that it can generate
	  <emphasis>large</emphasis> amounts of log data.  One log
	  entry will be generated for every packet that passes 
          through the firewall, so large FTP/http transfers, etc, will really
	  slow the system down.  It also increases the latencies on those
	  packets as it requires more work to be done by the kernel before the
	  packet can be passed on.  <application>syslogd</application> will 
	  also start using up a lot
	  more processor time as it logs all the extra data to disk, and it
	  could quite easily fill the partition <filename>/var/log</filename>
	  is located on.</para>
      </note>
	  
      <para>You should enable your firewall from
	<filename>/etc/rc.conf.local</filename> or
	<filename>/etc/rc.conf</filename>.  The associated manual page explains
	which knobs to fiddle and lists some preset firewall configurations.
	If you do not use a preset configuration, <command>ipfw list</command>
	will output the current ruleset into a file that you can
	pass to <filename>rc.conf</filename>.  If you do not use
	<filename>/etc/rc.conf.local</filename> or
	<filename>/etc/rc.conf</filename> to enable your firewall,
	it is important to make sure your firewall is enabled before
	any IP interfaces are configured.</para>
	  
      <para>The next problem is what your firewall should actually
	<emphasis>do</emphasis>! This is largely dependent on what access to
	your network you want to allow from the outside, and how much access
	to the outside world you want to allow from the inside.  Some general
	rules are:</para>
      
      <itemizedlist>
	<listitem>
	  <para>Block all incoming access to ports below 1024 for TCP.  This is
	    where most of the security sensitive services are, like finger,
	    SMTP (mail) and telnet.</para>
	</listitem>

	<listitem>
	  <para>Block <emphasis>all</emphasis> incoming UDP traffic.  There
	    are very few useful services that travel over UDP, and what useful
	    traffic there is, is normally a security threat (e.g. Suns RPC and
	    NFS protocols).  This has its disadvantages also, since UDP is a
	    connectionless protocol, denying incoming UDP traffic also blocks
	    the replies to outgoing UDP traffic.  This can cause a problem for
	    people (on the inside) using external archie (prospero) servers.
	    If you want to allow access to archie, you will have to allow
	    packets coming from ports 191 and 1525 to any internal UDP port
	    through the firewall.  <application>ntp</application> is another
	    service you may consider allowing through, which comes from port
	    123.</para>
	</listitem>
	      
	<listitem>
	  <para>Block traffic to port 6000 from the outside.  Port 6000 is the
	    port used for access to X11 servers, and can be a security threat
	    (especially if people are in the habit of doing <command>xhost
	      +</command> on their workstations).  X11 can actually use a
	    range of ports starting at 6000, the upper limit being how many X
	    displays you can run on the machine.  The upper limit as defined
	    by RFC 1700 (Assigned Numbers) is 6063.</para>
	</listitem>
	      
	<listitem>
	  <para>Check what ports any internal servers use (e.g. SQL servers,
	    etc).  It is probably a good idea to block those as well, as they
	    normally fall outside the 1-1024 range specified above.</para>
	</listitem>
      </itemizedlist>
	  
      <para>Another checklist for firewall configuration is available from
	CERT at <ulink
	  url="http://www.cert.org/tech_tips/packet_filtering.html"></ulink></para>
	  
      <para>As stated above, these are only <emphasis>guidelines</emphasis>.
	You will have to decide what filter rules you want to use on your
	firewall yourself.  We cannot accept ANY responsibility if someone
	breaks into your network, even if you follow the advice given
	above.</para>
    </sect2>

    <sect2 id="ipfw-overhead">
      <title>IPFW Overhead and Optimization</title>

      <para>Many people want to know how much overhead IPFW adds to a
	system.  The answer to this depends mostly on your rule set and
	processor speed.  For most applications dealing with Ethernet
	and small rule sets, the answer is
	<quote>negligible</quote>.  For those of you that need actual
	measurements to satisfy your curiosity, read on.</para>

      <para>The following measurements were made using 2.2.5-STABLE on
	a 486-66.  (While IPFW has changed slightly in later releases
	of FreeBSD, it still performs with similar speed.) IPFW was
	modified to measure the time spent within the
	<literal>ip_fw_chk</literal> routine, displaying the results
	to the console every 1000 packets.</para>

      <para>Two rule sets, each with 1000 rules, were tested.  The
	first set was designed to demonstrate a worst case scenario by
	repeating the rule:</para>

      <screen>&prompt.root; <userinput>ipfw add deny tcp from any to any 55555</userinput></screen>

      <para>This demonstrates a worst case scenario by causing most of IPFW's
	packet check routine to be executed before finally deciding
	that the packet does not match the rule (by virtue of the port
	number).  Following the 999th iteration of this rule was an
	<literal>allow ip from any to any</literal>.</para>

      <para>The second set of rules were designed to abort the rule
	check quickly:</para>

      <screen>&prompt.root; <userinput>ipfw add deny ip from 1.2.3.4 to 1.2.3.4</userinput></screen>

      <para>The non-matching source IP address for the above rule
	causes these rules to be skipped very quickly.  As before, the
	1000th rule was an <literal>allow ip from any to
	any</literal>.</para>

      <para>The per-packet processing overhead in the former case was
	approximately 2.703&nbsp;ms/packet, or roughly 2.7&nbsp;microseconds per
	rule.  Thus the theoretical packet processing limit with these
	rules is around 370&nbsp;packets per second.  Assuming 10&nbsp;Mbps
	Ethernet and a ~1500&nbsp;byte packet size, we would only be able
	to achieve 55.5% bandwidth utilization.</para>

      <para>For the latter case each packet was processed in
	approximately 1.172&nbsp;ms, or roughly 1.2&nbsp;microseconds per rule.
	The theoretical packet processing limit here would be about
	853&nbsp;packets per second, which could consume 10&nbsp;Mbps Ethernet
	bandwidth.</para>

      <para>The excessive number of rules tested and the nature of
	those rules do not provide a real-world scenario -- they were
	used only to generate the timing information presented here.
	Here are a few things to keep in mind when building an
	efficient rule set:</para>

      <itemizedlist>
	<listitem>
	  <para>Place an <literal>established</literal> rule early on
	    to handle the majority of TCP traffic.  Do not put any
	    <literal>allow tcp</literal> statements before this
	    rule.</para>
	</listitem>

	<listitem>
	  <para>Place heavily triggered rules earlier in the rule set
	    than those rarely used (<emphasis>without changing the
	    permissiveness of the firewall</emphasis>, of course).
	    You can see which rules are used most often by examining
	    the packet counting statistics with <command>ipfw -a
	    l</command>.</para>
	</listitem>
      </itemizedlist>
    </sect2>
  </sect1>

  <sect1 id="openssl">
    <title>OpenSSL</title>
    <indexterm>
      <primary>security</primary>
      <secondary>OpenSSL</secondary>
    </indexterm>
    <indexterm><primary>OpenSSL</primary></indexterm>

    <para>As of FreeBSD&nbsp;4.0, the OpenSSL toolkit is a part of the base
      system.  <ulink url="http://www.openssl.org/">OpenSSL</ulink>
      provides a general-purpose cryptography library, as well as the
      Secure Sockets Layer v2/v3 (SSLv2/SSLv3) and Transport Layer
      Security v1 (TLSv1) network security protocols.</para>

    <para>However, one of the algorithms (specifically IDEA)
      included in OpenSSL is protected by patents in the USA and
      elsewhere, and is not available for unrestricted use.
      IDEA is included in the OpenSSL sources in FreeBSD, but it is not
      built by default.  If you wish to use it, and you comply with the
      license terms, enable the <makevar>MAKE_IDEA</makevar> switch in
      <filename>/etc/make.conf</filename> and
      rebuild your sources using <command>make world</command>.</para>

    <para>Today, the RSA algorithm is free for use in USA and other
      countries.  In the past it was protected by a patent.</para>

    <indexterm>
      <primary>OpenSSL</primary>
      <secondary>install</secondary>
    </indexterm>

    <sect2>
      <title>Source Code Installations</title>
      
      <para>OpenSSL is part of the <literal>src-crypto</literal> and
	<literal>src-secure</literal> <application>CVSup</application> collections.  See the <link
	linkend="mirrors">Obtaining FreeBSD</link> section for more
	information about obtaining and updating FreeBSD source
	code.</para>
    </sect2>
  </sect1>

  <sect1 id="ipsec">
    <sect1info>
      <authorgroup>
        <author>
  	  <firstname>Nik</firstname>
	  <surname>Clayton</surname>
	  <affiliation>
	    <address><email>nik@FreeBSD.org</email></address>
          </affiliation>
          <contrib>Written by </contrib>
        </author>
      </authorgroup>
    </sect1info>

    <title>VPN over IPsec</title>
    <para>Creating a VPN between two networks, separated by the
      Internet, using FreeBSD gateways.</para>
 
    <sect2>
      <sect2info>
        <authorgroup>
          <author>
            <firstname>Hiten M.</firstname>
            <surname>Pandya</surname>
	    <affiliation>
	      <address><email>hmp@FreeBSD.org</email></address>
	    </affiliation>
	    <contrib>Written by </contrib>
	  </author>
	</authorgroup>
      </sect2info>

      <title>Understanding IPsec</title>

      <para>This section will guide you through the process of setting
	up IPsec, and to use it in an environment which consists of
	FreeBSD and <application>&microsoft.windows; 2000/XP</application>
	machines, to make them communicate securely.  In order to set up
	IPsec, it is necessary that you are familiar with the concepts
	of building a custom kernel (see
	<xref linkend="kernelconfig">).</para>
    
      <para><emphasis>IPsec</emphasis> is a protocol which sits on top
	of the Internet Protocol (IP) layer.  It allows two or more
	hosts to communicate in a secure manner (hence the name).  The
	FreeBSD IPsec <quote>network stack</quote> is based on the
	<ulink url="http://www.kame.net/">KAME</ulink> implementation,
	which has support for both protocol families, IPv4 and
	IPv6.</para>

      <note>
        <para>FreeBSD 5.X contains a <quote>hardware
        accelerated</quote> IPsec stack, known as <quote>Fast
        IPsec</quote>, that was obtained from OpenBSD.  It employs
        cryptographic hardware (whenever possible) via the
        &man.crypto.4; subsystem to optimize the performance of IPsec.
        This subsystem is new, and does not support all the features
        that are available in the KAME version of IPsec.  However, in
        order to enable hardware-accelerated IPsec, the following
        kernel option has to be added to your kernel configuration
        file:</para>

        <screen>
options	  FAST_IPSEC  # new IPsec (cannot define w/ IPSEC)
        </screen>

        <para> Note, that it is not currently possible to use the
	  <quote>Fast IPsec</quote> subsystem in lue with the KAME
	  implementation of IPsec.  Consult the &man.fast.ipsec.4;
	  manual page for more information.</para>

      </note>
  
      <para>IPsec consists of two sub-protocols:</para>

      <itemizedlist>
        <listitem>
          <para><emphasis>Encapsulated Security Payload
	      (ESP)</emphasis>, protects the IP packet data from third
	    party interference, by encrypting the contents using
	    symmetric cryptography algorithms (like Blowfish,
	    3DES).</para>
        </listitem>
        <listitem>
          <para><emphasis>Authentication Header (AH)</emphasis>,
	    protects the IP packet header from third party interference
	    and spoofing, by computing a cryptographic checksum and
	    hashing the IP packet header fields with a secure hashing
	    function.  This is then followed by an additional header
	    that contains the hash, to allow the information in the
	    packet to be authenticated.</para>
        </listitem>
      </itemizedlist>
      
      <para><acronym>ESP</acronym> and <acronym>AH</acronym> can
	either be used together or separately, depending on the
	environment.</para>
      
      <para>IPsec can either be used to directly encrypt the traffic
	between two hosts (known as <emphasis>Transport
	  Mode</emphasis>); or to build <quote>virtual tunnels</quote>
	between two subnets, which could be used for secure
	communication between two corporate networks (known as
	<emphasis>Tunnel Mode</emphasis>).  The latter is more commonly
	known as a <emphasis>Virtual Private Network (VPN)</emphasis>.
	The &man.ipsec.4; manual page should be consulted for detailed
	information on the IPsec subsystem in FreeBSD.</para>
      
      <para>To add IPsec support to your kernel, add the following
	options to your kernel configuration file:</para>
      
      <screen>
options   IPSEC        #IP security
options   IPSEC_ESP    #IP security (crypto; define w/ IPSEC)
      </screen>

      <para>If IPsec debugging support is desired, the following
	kernel option should also be added:</para>

      <screen>
options   IPSEC_DEBUG  #debug for IP security
      </screen>
    </sect2>

    <sect2>
      <title>The Problem</title>
 
      <para>There's no standard for what constitutes a VPN.  VPNs can
	be implemented using a number of different technologies, each of
	which have their own strengths and weaknesses.  This article
	presents a number of scenarios, and strategies for implementing a
	VPN for each scenario.</para>
    </sect2>
    
    <sect2> 
      <title>Scenario #1: Two networks, connected to the Internet, to
        behave as one</title>
      
      <para>This is the scenario that caused me to first investigating
        VPNs.  The premise is as follows:</para>
      
      <itemizedlist>
        <listitem>
          <para>You have at least two sites</para>
        </listitem>
        <listitem>
          <para>Both sites are using IP internally</para>
        </listitem>
        <listitem>
          <para>Both sites are connected to the Internet, through a
            gateway that is running FreeBSD.</para>
        </listitem>
        <listitem>
          <para>The gateway on each network has at least one public IP
            address.</para>
        </listitem>
        <listitem>
          <para>The internal addresses of the two networks can be
            public or private IP addresses, it doesn't matter.  You can
            be running NAT on the gateway machine if necessary.</para>
        </listitem>
        <listitem>
          <para>The internal IP addresses of the two networks
            <emphasis>do not collide</emphasis>.  While I expect it is
            theoretically possible to use a combination of VPN
            technology and NAT to get this to work, I expect it to be a
            configuration nightmare.</para>
        </listitem>
      </itemizedlist>
      
      <para>If you find that you are trying to connect two networks,
        both of which, internally, use the same private IP address range
        (e.g., both of them use <hostid
        role="ipaddr">192.168.1.x</hostid>), then one of the networks will
        have to be renumbered.</para>
 
      <para>The network topology might look something like this:</para>
 
      <mediaobject>
	<imageobject>
	  <imagedata fileref="security/ipsec-network" align="center">
	</imageobject>

	<textobject>
<literallayout class="monospaced">Network #1            [ Internal Hosts ]    Private Net, 192.168.1.2-254
                      [   Win9x/NT/2K  ]
                      [      UNIX      ]
                               |
                               |
                        .---[fxp1]---.      Private IP, 192.168.1.1
                        |   FreeBSD  |
                        `---[fxp0]---'      Public IP, A.B.C.D
                               |
                               |
                      -=-=- Internet -=-=-
                               |
                               |
                        .---[fxp0]---.      Public IP, W.X.Y.Z
                        |   FreeBSD  |
                        `---[fxp1]---'      Private IP, 192.168.2.1
                               |
                               |
Network #2            [ Internal Hosts ]
                      [   Win9x/NT/2K  ]    Private Net, 192.168.2.2-254
                      [      UNIX      ]</literallayout>
	</textobject>
      </mediaobject>
 
      <para>Notice the two public IP addresses.  I'll use the letters to
        refer to them in the rest of this article.  Anywhere you see those
        letters in this article, replace them with your own public IP
        addresses.  Note also that that internally, the two gateway
        machines have .1 IP addresses, and that the two networks have
        different private IP address (<hostid
        role="ipaddr">192.168.1.x</hostid> and <hostid
        role="ipaddr">192.168.2.x</hostid> respectively).  All the
        machines on the private networks have been configured to use the
        <hostid role="ipaddr">.1</hostid> machine as their default
        gateway.</para>
 
      <para>The intention is that, from a network point of view, each
        network should view the machines on the other network as though
        they were directly attached the same router -- albeit a slightly
        slow router with an occasional tendency to drop packets.</para>
 
      <para>This means that (for example), machine <hostid
        role="ipaddr">192.168.1.20</hostid> should be able to run</para>
 
      <programlisting>ping 192.168.2.34</programlisting>
 
      <para>and have it work, transparently.  &windows; machines should
        be able to see the machines on the other network, browse file
        shares, and so on, in exactly the same way that they can browse
        machines on the local network.</para>
 
      <para>And the whole thing has to be secure.  This means that
        traffic between the two networks has to be encrypted.</para>
 
      <para>Creating a VPN between these two networks is a multi-step
        process.  The stages are as follows:</para>
 
      <orderedlist>
        <listitem>
          <para>Create a <quote>virtual</quote> network link between the two
            networks, across the Internet.  Test it, using tools like
            &man.ping.8;, to make sure it works.</para>
        </listitem>
 
        <listitem>
          <para>Apply security policies to ensure that traffic between
            the two networks is transparently encrypted and decrypted as
            necessary.  Test this, using tools like &man.tcpdump.1;, to
            ensure that traffic is encrypted.</para>
        </listitem>

        <listitem>
          <para>Configure additional software on the FreeBSD gateways,
            to allow &windows; machines to see one another across the
            VPN.</para>
        </listitem>
      </orderedlist>

    <sect3>
      <title>Step 1: Creating and testing a <quote>virtual</quote>
        network link</title>
 
      <para>Suppose that you were logged in to the gateway machine on
        network #1 (with public IP address <hostid
        role="ipaddr">A.B.C.D</hostid>, private IP address <hostid
        role="ipaddr">192.168.1.1</hostid>), and you ran <command>ping
        192.168.2.1</command>, which is the private address of the machine
        with IP address <hostid role="ipaddr">W.X.Y.Z</hostid>.  What
        needs to happen in order for this to work?</para>

      <orderedlist>
        <listitem>
          <para>The gateway machine needs to know how to reach <hostid
            role="ipaddr">192.168.2.1</hostid>.  In other words, it needs
            to have a route to <hostid
            role="ipaddr">192.168.2.1</hostid>.</para>
        </listitem>
        <listitem>
          <para>Private IP addresses, such as those in the <hostid
            role="ipaddr">192.168.x</hostid> range are not supposed to
            appear on the Internet at large.  Instead, each packet you
            send to <hostid role="ipaddr">192.168.2.1</hostid> will need
            to be wrapped up inside another packet.  This packet will need
            to appear to be from <hostid role="ipaddr">A.B.C.D</hostid>,
            and it will have to be sent to <hostid
            role="ipaddr">W.X.Y.Z</hostid>.  This process is called
            <firstterm>encapsulation</firstterm>.</para>
        </listitem>
        <listitem>
          <para>Once this packet arrives at <hostid
            role="ipaddr">W.X.Y.Z</hostid> it will need to
            <quote>unencapsulated</quote>, and delivered to <hostid
            role="ipaddr">192.168.2.1</hostid>.</para>
	</listitem>
      </orderedlist>
 
      <para>You can think of this as requiring a <quote>tunnel</quote>
        between the two networks.  The two <quote>tunnel mouths</quote> are the IP
        addresses <hostid role="ipaddr">A.B.C.D</hostid> and <hostid
        role="ipaddr">W.X.Y.Z</hostid>, and the tunnel must be told the
        addresses of the private IP addresses that will be allowed to pass
        through it.  The tunnel is used to transfer traffic with private
        IP addresses across the public Internet.</para>
 
      <para>This tunnel is created by using the generic interface, or
        <devicename>gif</devicename> devices on FreeBSD.  As you can
        imagine, the <devicename>gif</devicename> interface on each
        gateway host must be configured with four IP addresses; two for
        the public IP addresses, and two for the private IP
        addresses.</para>
 
      <para>Support for the gif device must be compiled in to the
        FreeBSD kernel on both machines.  You can do this by adding the
        line:</para>
 
      <programlisting>pseudo-device gif</programlisting>
 
      <para>to the kernel configuration files on both machines, and
        then compile, install, and reboot as normal.</para>
 
      <para>Configuring the tunnel is a two step process.  First the
        tunnel must be told what the outside (or public) IP addresses
        are, using &man.gifconfig.8;.  Then the private IP addresses must be
        configured using &man.ifconfig.8;.</para>
 
      <para>On the gateway machine on network #1 you would run the
        following two commands to configure the tunnel.</para>
 
      <programlisting>gifconfig gif0 A.B.C.D W.X.Y.Z
ifconfig gif0 inet 192.168.1.1 192.168.2.1 netmask 0xffffffff
      </programlisting>
 
      <para>On the other gateway machine you run the same commands,
        but with the order of the IP addresses reversed.</para>
 
      <programlisting>gifconfig gif0 W.X.Y.Z A.B.C.D
ifconfig gif0 inet 192.168.2.1 192.168.1.1 netmask 0xffffffff
      </programlisting>
 
      <para>You can then run:</para>
 
      <programlisting>gifconfig gif0</programlisting>
 
      <para>to see the configuration.  For example, on the network #1
        gateway, you would see this:</para>
 
      <screen>&prompt.root; <userinput>gifconfig gif0</userinput>
gif0: flags=8011&lt;UP,POINTTOPOINT,MULTICAST&gt; mtu 1280
inet 192.168.1.1 --&gt; 192.168.2.1 netmask 0xffffffff
physical address inet A.B.C.D --&gt; W.X.Y.Z
      </screen>
 
      <para>As you can see, a tunnel has been created between the
        physical addresses <hostid role="ipaddr">A.B.C.D</hostid> and
        <hostid role="ipaddr">W.X.Y.Z</hostid>, and the traffic allowed
        through the tunnel is that between <hostid
        role="ipaddr">192.168.1.1</hostid> and <hostid
        role="ipaddr">192.168.2.1</hostid>.</para>
 
      <para>This will also have added an entry to the routing table
        on both machines, which you can examine with the command <command>netstat -rn</command>.
        This output is from the gateway host on network #1.</para>
 
      <screen>&prompt.root; <userinput>netstat -rn</userinput>
Routing tables
 
Internet:
Destination      Gateway       Flags    Refs    Use    Netif  Expire
...
192.168.2.1      192.168.1.1   UH        0        0    gif0
...
      </screen>
 
      <para>As the <quote>Flags</quote> value indicates, this is a
        host route, which means that each gateway knows how to reach the
        other gateway, but they do not know how to reach the rest of
        their respective networks.  That problem will be fixed
        shortly.</para>
 
      <para>It is likely that you are running a firewall on both
        machines.  This will need to be circumvented for your VPN
        traffic.  You might want to allow all traffic between both
        networks, or you might want to include firewall rules that
        protect both ends of the VPN from one another.</para>
 
      <para>It greatly simplifies testing if you configure the
        firewall to allow all traffic through the VPN.  You can always
        tighten things up later.  If you are using &man.ipfw.8; on the
        gateway machines then a command like</para>

      <programlisting>ipfw add 1 allow ip from any to any via gif0</programlisting>
 
      <para>will allow all traffic between the two end points of the
        VPN, without affecting your other firewall rules.  Obviously
        you will need to run this command on both gateway hosts.</para>
 
      <para>This is sufficient to allow each gateway machine to ping
        the other.  On <hostid role="ipaddr">192.168.1.1</hostid>, you
        should be able to run</para>
 
      <programlisting>ping 192.168.2.1</programlisting>
 
      <para>and get a response, and you should be able to do the same
        thing on the other gateway machine.</para>
 
      <para>However, you will not be able to reach internal machines
        on either network yet.  This is because of the routing --
        although the gateway machines know how to reach one another,
        they do not know how to reach the network behind each one.</para>
 
      <para>To solve this problem you must add a static route on each
        gateway machine.  The command to do this on the first gateway
        would be:</para>
 
      <programlisting>route add 192.168.2.0 192.168.2.1 netmask 0xffffff00
      </programlisting>
 
      <para>This says <quote>In order to reach the hosts on the
        network <hostid role="ipaddr">192.168.2.0</hostid>, send the
        packets to the host <hostid
        role="ipaddr">192.168.2.1</hostid></quote>.  You will need to
        run a similar command on the other gateway, but with the
        <hostid role="ipaddr">192.168.1.x</hostid> addresses
        instead.</para>
 
      <para>IP traffic from hosts on one network will now be able to
        reach hosts on the other network.</para>
 
      <para>That has now created two thirds of a VPN between the two
        networks, in as much as it is <quote>virtual</quote> and it is a
        <quote>network</quote>.  It is not private yet.  You can test
        this using &man.ping.8; and &man.tcpdump.1;.  Log in to the
        gateway host and run</para>
 
      <programlisting>tcpdump dst host 192.168.2.1</programlisting>

      <para>In another log in session on the same host run</para>

      <programlisting>ping 192.168.2.1</programlisting>
 
      <para>You will see output that looks something like this:</para>
 
      <programlisting>
16:10:24.018080 192.168.1.1 &gt; 192.168.2.1: icmp: echo request
16:10:24.018109 192.168.1.1 &gt; 192.168.2.1: icmp: echo reply
16:10:25.018814 192.168.1.1 &gt; 192.168.2.1: icmp: echo request
16:10:25.018847 192.168.1.1 &gt; 192.168.2.1: icmp: echo reply
16:10:26.028896 192.168.1.1 &gt; 192.168.2.1: icmp: echo request
16:10:26.029112 192.168.1.1 &gt; 192.168.2.1: icmp: echo reply
      </programlisting>
 
      <para>As you can see, the ICMP messages are going back and forth
        unencrypted.  If you had used the <option>-s</option> parameter to
        &man.tcpdump.1; to grab more bytes of data from the packets you
        would see more information.</para>
 
      <para>Obviously this is unacceptable.  The next section will
        discuss securing the link between the two networks so that it
        all traffic is automatically encrypted.</para>
 
      <itemizedlist>
        <title>Summary:</title>
        <listitem>
          <para>Configure both kernels with <quote>pseudo-device
          gif</quote>.</para>
        </listitem>
        <listitem>
          <para>Edit <filename>/etc/rc.conf</filename> on gateway host
            #1 and add the following lines (replacing IP addresses as
            necessary).</para>
          <programlisting>gifconfig_gif0="A.B.C.D W.X.Y.Z"
ifconfig_gif0="inet 192.168.1.1 192.168.2.1 netmask 0xffffffff"
static_routes="vpn"
route_vpn="192.168.2.0 192.168.2.1 netmask 0xffffff00"
          </programlisting>
        </listitem>

        <listitem>
          <para>Edit your firewall script
          (<filename>/etc/rc.firewall</filename>, or similar) on both
          hosts, and add</para>

          <programlisting>ipfw add 1 allow ip from any to any via gif0</programlisting>
        </listitem>
        <listitem>
          <para>Make similar changes to
            <filename>/etc/rc.conf</filename> on gateway host #2,
            reversing the order of IP addresses.</para>
        </listitem>
      </itemizedlist>
    </sect3>

    <sect3>
      <title>Step 2: Securing the link</title>
 
      <para>To secure the link we will be using IPsec.  IPsec provides
        a mechanism for two hosts to agree on an encryption key, and to
        then use this key in order to encrypt data between the two
        hosts.</para>
 
      <para>The are two areas of configuration to be considered here.</para>
 
      <orderedlist>
        <listitem>
          <para>There must be a mechanism for two hosts to agree on the
            encryption mechanism to use.  Once two hosts have agreed on
            this mechanism there is said to be a <quote>security association</quote>
            between them.</para>
        </listitem>
        <listitem>
          <para>There must be a mechanism for specifying which traffic
            should be encrypted.  Obviously, you don't want to encrypt
            all your outgoing traffic -- you only want to encrypt the
            traffic that is part of the VPN.  The rules that you put in
            place to determine what traffic will be encrypted are called
            <quote>security policies</quote>.</para>
         </listitem>
       </orderedlist>
 
       <para>Security associations and security policies are both
         maintained by the kernel, and can be modified by userland
         programs.  However, before you can do this you must configure the
         kernel to support IPsec and the Encapsulated Security Payload
         (ESP) protocol.  This is done by configuring a kernel with:</para>
 
       <programlisting>options IPSEC
options IPSEC_ESP
       </programlisting>
 
       <para>and recompiling, reinstalling, and rebooting.  As before
         you will need to do this to the kernels on both of the gateway
         hosts.</para>
 
       <para>You have two choices when it comes to setting up security
         associations.  You can configure them by hand between two hosts,
         which entails choosing the encryption algorithm, encryption keys,
         and so forth, or you can use daemons that implement the Internet
         Key Exchange protocol (IKE) to do this for you.</para>
 
       <para>I recommend the latter.  Apart from anything else, it is
         easier to set up.</para>
 
       <para>Editing and displaying security policies is carried out
         using &man.setkey.8;.  By analogy, <command>setkey</command> is
         to the kernel's security policy tables as &man.route.8; is to
         the kernel's routing tables.  <command>setkey</command> can
         also display the current security associations, and to continue
         the analogy further, is akin to <command>netstat -r</command>
         in that respect.</para>
 
       <para>There are a number of choices for daemons to manage
         security associations with FreeBSD.  This article will describe
         how to use one of these, racoon.  racoon is in the FreeBSD ports
         collection, in the security/ category, and is installed in the
         usual way.</para>
 
       <para>racoon must be run on both gateway hosts.  On each host it
         is configured with the IP address of the other end of the VPN,
         and a secret key (which you choose, and must be the same on both
         gateways).</para>
 
       <para>The two daemons then contact one another, confirm that they
         are who they say they are (by using the secret key that you
         configured).  The daemons then generate a new secret key, and use
         this to encrypt the traffic over the VPN.  They periodically
         change this secret, so that even if an attacker were to crack one
         of the keys (which is as theoretically close to unfeasible as it
         gets) it won't do them much good -- by the time they've cracked
         the key the two daemons have chosen another one.</para>
 
       <para>racoon's configuration is stored in
         <filename>${PREFIX}/etc/racoon</filename>.  You should find a
         configuration file there, which should not need to be changed
         too much.  The other component of racoon's configuration,
         which you will need to change, is the <quote>pre-shared
         key</quote>.</para>
 
       <para>The default racoon configuration expects to find this in
         the file <filename>${PREFIX}/etc/racoon/psk.txt</filename>.  It is important to note
         that the pre-shared key is <emphasis>not</emphasis> the key that will be used to
         encrypt your traffic across the VPN link, it is simply a token
         that allows the key management daemons to trust one another.</para>

       <para><filename>psk.txt</filename> contains a line for each
         remote site you are dealing with.  In this example, where there
         are two sites, each <filename>psk.txt</filename> file will contain one line (because
         each end of the VPN is only dealing with one other end).</para>
 
       <para>On gateway host #1 this line should look like this:</para>
 
       <programlisting>W.X.Y.Z            secret</programlisting>
 
       <para>That is, the <emphasis>public</emphasis> IP address of the remote end,
         whitespace, and a text string that provides the secret.
         Obviously, you shouldn't use <quote>secret</quote> as your key -- the normal
         rules for choosing a password apply.</para>
 
       <para>On gateway host #2 the line would look like this</para>
 
       <programlisting>A.B.C.D            secret</programlisting>
 
       <para>That is, the public IP address of the remote end, and the
         same secret key.  <filename>psk.txt</filename> must be mode
         <literal>0600</literal> (i.e., only read/write to
         <username>root</username>) before racoon will run.</para>
 
       <para>You must run racoon on both gateway machines.  You will
         also need to add some firewall rules to allow the IKE traffic,
         which is carried over UDP to the ISAKMP (Internet Security Association
         Key Management Protocol) port.  Again, this should be fairly early in
         your firewall ruleset.</para>
 
       <programlisting>ipfw add 1 allow udp from A.B.C.D to W.X.Y.Z isakmp
ipfw add 1 allow udp from W.X.Y.Z to A.B.C.D isakmp
       </programlisting>
 
       <para>Once racoon is running you can try pinging one gateway host
         from the other.  The connection is still not encrypted, but
         racoon will then set up the security associations between the two
         hosts -- this might take a moment, and you may see this as a
         short delay before the ping commands start responding.</para>
 
       <para>Once the security association has been set up you can
         view it using &man.setkey.8;.  Run</para>
 
       <programlisting>setkey -D</programlisting>
 
       <para>on either host to view the security association information.</para>
 
       <para>That's one half of the problem.  They other half is setting
         your security policies.</para>
 
       <para>To create a sensible security policy, let's review what's
         been set up so far.  This discussions hold for both ends of the
         link.</para>
 
       <para>Each IP packet that you send out has a header that contains
         data about the packet.  The header includes the IP addresses of
         both the source and destination.  As we already know, private IP
         addresses, such as the <hostid role="ipaddr">192.168.x.y</hostid>
         range are not supposed to appear on the public Internet.
         Instead, they must first be encapsulated inside another packet.
         This packet must have the public source and destination IP
         addresses substituted for the private addresses.</para>
 
       <para>So if your outgoing packet started looking like this:</para>
 
	<mediaobject>
	  <imageobject>
	    <imagedata fileref="security/ipsec-out-pkt" align="center">
	  </imageobject>

	  <textobject>
	    <literallayout class="monospaced">
  .----------------------.
  | Src: 192.168.1.1     |
  | Dst: 192.168.2.1     |
  | &lt;other header info&gt;  |
  +----------------------+
  | &lt;packet data&gt;        |
  `----------------------'</literallayout>
	  </textobject>
	</mediaobject>
 
       <para>Then it will be encapsulated inside another packet, looking
         something like this:</para>
 
	<mediaobject>
	  <imageobject>
	    <imagedata fileref="security/ipsec-encap-pkt" align="center">
	  </imageobject>

	  <textobject>
	    <literallayout class="monospaced">
  .--------------------------.
  | Src: A.B.C.D             |
  | Dst: W.X.Y.Z             |
  | &lt;other header info&gt;      |
  +--------------------------+
  | .----------------------. |
  | | Src: 192.168.1.1     | |
  | | Dst: 192.168.2.1     | |
  | | &lt;other header info&gt;  | |
  | +----------------------+ |
  | | &lt;packet data&gt;        | |
  | `----------------------' |
  `--------------------------'</literallayout>
	  </textobject>
	</mediaobject>
 
       <para>This encapsulation is carried out by the
         <devicename>gif</devicename> device.  As
         you can see, the packet now has real IP addresses on the outside,
         and our original packet has been wrapped up as data inside the
         packet that will be put out on the Internet.</para>
 
       <para>Obviously, we want all traffic between the VPNs to be
         encrypted.  You might try putting this in to words, as:</para>

       <para><quote>If a packet leaves from <hostid
         role="ipaddr">A.B.C.D</hostid>, and it is destined for <hostid
         role="ipaddr">W.X.Y.Z</hostid>, then encrypt it, using the
         necessary security associations.</quote></para>
 
       <para><quote>If a packet arrives from <hostid
         role="ipaddr">W.X.Y.Z</hostid>, and it is destined for <hostid
         role="ipaddr">A.B.C.D</hostid>, then decrypt it, using the
         necessary security associations.</quote></para>
 
       <para>That's close, but not quite right.  If you did this, all
         traffic to and from <hostid role="ipaddr">W.X.Y.Z</hostid>, even
         traffic that was not part of the VPN, would be encrypted.  That's
         not quite what you want.  The correct policy is as follows</para>
 
       <para><quote>If a packet leaves from <hostid
         role="ipaddr">A.B.C.D</hostid>, and that packet is encapsulating
         another packet, and it is destined for <hostid
         role="ipaddr">W.X.Y.Z</hostid>, then encrypt it, using the
         necessary security associations.</quote></para>
 
       <para><quote>If a packet arrives from <hostid
         role="ipaddr">W.X.Y.Z</hostid>, and that packet is encapsulating
         another packet, and it is destined for <hostid
         role="ipaddr">A.B.C.D</hostid>, then encrypt it, using the
         necessary security associations.</quote></para>
 
       <para>A subtle change, but a necessary one.</para>
 
       <para>Security policies are also set using &man.setkey.8;.
         &man.setkey.8; features a configuration language for defining the
         policy.  You can either enter configuration instructions via
         stdin, or you can use the <option>-f</option> option to specify a
         filename that contains configuration instructions.</para>
 
       <para>The configuration on gateway host #1 (which has the public
         IP address <hostid role="ipaddr">A.B.C.D</hostid>) to force all
         outbound traffic to <hostid role="ipaddr">W.X.Y.Z</hostid> to be
         encrypted is:</para>
 
       <programlisting>
spdadd A.B.C.D/32 W.X.Y.Z/32 ipencap -P out ipsec esp/tunnel/A.B.C.D-W.X.Y.Z/require;
       </programlisting>
 
       <para>Put these commands in a file (e.g.,
       <filename>/etc/ipsec.conf</filename>) and then run</para>

       <screen>&prompt.root; <userinput>setkey -f /etc/ipsec.conf</userinput></screen>
 
       <para><option>spdadd</option> tells &man.setkey.8; that we want
         to add a rule to the secure policy database.  The rest of this
         line specifies which packets will match this policy.  <hostid
         role="ipaddr">A.B.C.D/32</hostid> and <hostid
         role="ipaddr">W.X.Y.Z/32</hostid> are the IP addresses and
         netmasks that identify the network or hosts that this policy will
         apply to.  In this case, we want it to apply to traffic between
         these two hosts.  <option>ipencap</option> tells the kernel that
         this policy should only apply to packets that encapsulate other
         packets.  <option>-P out</option> says that this policy applies
         to outgoing packets, and <option>ipsec</option> says that the
         packet will be secured.</para>
 
       <para>The second line specifies how this packet will be
         encrypted.  <option>esp</option> is the protocol that will be
         used, while <option>tunnel</option> indicates that the packet
         will be further encapsulated in an IPsec packet.  The repeated
         use of <hostid role="ipaddr">A.B.C.D</hostid> and <hostid
         role="ipaddr">W.X.Y.Z</hostid> is used to select the security
         association to use, and the final <option>require</option>
         mandates that packets must be encrypted if they match this
         rule.</para>
 
       <para>This rule only matches outgoing packets.  You will need a
         similar rule to match incoming packets.</para>
 
       <programlisting>spdadd W.X.Y.Z/32 A.B.C.D/32 ipencap -P in ipsec esp/tunnel/W.X.Y.Z-A.B.C.D/require;</programlisting>
 
       <para>Note the <option>in</option> instead of
         <option>out</option> in this case, and the necessary reversal of
         the IP addresses.</para>
 
       <para>The other gateway host (which has the public IP address
         <hostid role="ipaddr">W.X.Y.Z</hostid>) will need similar rules.</para>
 
       <programlisting>spdadd W.X.Y.Z/32 A.B.C.D/32 ipencap -P out ipsec esp/tunnel/W.X.Y.Z-A.B.C.D/require;
       spdadd A.B.C.D/32 W.X.Y.Z/32 ipencap -P in ipsec esp/tunnel/A.B.C.D-W.X.Y.Z/require;</programlisting>
 
       <para>Finally, you need to add firewall rules to allow ESP and
        IPENCAP packets back and forth.  These rules will need to be
        added to both hosts.</para>
 
       <programlisting>ipfw add 1 allow esp from A.B.C.D to W.X.Y.Z
ipfw add 1 allow esp from W.X.Y.Z to A.B.C.D
ipfw add 1 allow ipencap from A.B.C.D to W.X.Y.Z
ipfw add 1 allow ipencap from W.X.Y.Z to A.B.C.D
       </programlisting>
 
       <para>Because the rules are symmetric you can use the same rules
         on each gateway host.</para>
 
       <para>Outgoing packets will now look something like this:</para>
 
	<mediaobject>
	  <imageobject>
	    <imagedata fileref="security/ipsec-crypt-pkt" align="center">
	  </imageobject>

	  <textobject>
	    <literallayout class="monospaced">
  .------------------------------.  --------------------------.
  | Src: A.B.C.D                 |                            |
  | Dst: W.X.Y.Z                 |                            |
  | &lt;other header info&gt;          |                            |  Encrypted
  +------------------------------+                            |  packet.
  | .--------------------------. |  -------------.            |  contents
  | | Src: A.B.C.D             | |               |            |  are
  | | Dst: W.X.Y.Z             | |               |            |  completely
  | | &lt;other header info&gt;      | |               |            |- secure
  | +--------------------------+ |               |  Encap'd   |  from third
  | | .----------------------. | |  -.           |  packet    |  party
  | | | Src: 192.168.1.1     | | |   |  Original |- with real |  snooping
  | | | Dst: 192.168.2.1     | | |   |  packet,  |  IP addr   |
  | | | &lt;other header info&gt;  | | |   |- private  |            |
  | | +----------------------+ | |   |  IP addr  |            |
  | | | &lt;packet data&gt;        | | |   |           |            |
  | | `----------------------' | |  -'           |            |
  | `--------------------------' |  -------------'            |
  `------------------------------'  --------------------------'
	    </literallayout>
	  </textobject>
	</mediaobject>

       <para>When they are received by the far end of the VPN they will
         first be decrypted (using the security associations that have
         been negotiated by racoon).  Then they will enter the
         <devicename>gif</devicename> interface, which will unwrap
         the second layer, until you are left with the innermost
         packet, which can then travel in to the inner network.</para>
 
       <para>You can check the security using the same &man.ping.8; test from
         earlier.  First, log in to the
         <hostid role="ipaddr">A.B.C.D</hostid> gateway machine, and
         run:</para>
 
       <programlisting>tcpdump dst host 192.168.2.1</programlisting>
 
       <para>In another log in session on the same host run</para>
 
       <programlisting>ping 192.168.2.1</programlisting>
 
       <para>This time you should see output like the following:</para>
 
       <programlisting>XXX tcpdump output</programlisting>
 
       <para>Now, as you can see, &man.tcpdump.1; shows the ESP packets.  If
         you try and examine them with the <option>-s</option> option you will see
         (apparently) gibberish, because of the encryption.</para>
 
      <para>Congratulations.  You have just set up a VPN between two
        remote sites.</para>
 
      <itemizedlist>
        <title>Summary</title>
        <listitem>
          <para>Configure both kernels with:</para>
 
          <programlisting>options IPSEC
options IPSEC_ESP
          </programlisting>
        </listitem>
        <listitem>
          <para>Install <filename
            role="package">security/racoon</filename>.  Edit
            <filename>${PREFIX}/etc/racoon/psk.txt</filename> on both
            gateway hosts, adding an entry for the remote host's IP
            address and a secret key that they both know.  Make sure
            this file is mode 0600.</para>
        </listitem>
        <listitem>
          <para>Add the following lines to
            <filename>/etc/rc.conf</filename> on each host:</para>
 
          <programlisting>ipsec_enable="YES"
ipsec_file="/etc/ipsec.conf"
          </programlisting>
        </listitem>
        <listitem>
          <para>Create an <filename>/etc/ipsec.conf</filename> on each
            host that contains the necessary spdadd lines.  On gateway
            host #1 this would be:</para>
 
          <programlisting>
spdadd A.B.C.D/32 W.X.Y.Z/32 ipencap -P out ipsec
  esp/tunnel/A.B.C.D-W.X.Y.Z/require;
spdadd W.X.Y.Z/32 A.B.C.D/32 ipencap -P in ipsec
  esp/tunnel/W.X.Y.Z-A.B.C.D/require;
</programlisting>
 
          <para>On gateway host #2 this would be:</para>
 
<programlisting>
spdadd W.X.Y.Z/32 A.B.C.D/32 ipencap -P out ipsec
  esp/tunnel/W.X.Y.Z-A.B.C.D/require;
spdadd A.B.C.D/32 W.X.Y.Z/32 ipencap -P in ipsec
  esp/tunnel/A.B.C.D-W.X.Y.Z/require;
</programlisting>
        </listitem>
        <listitem>
          <para>Add firewall rules to allow IKE, ESP, and IPENCAP
            traffic to both hosts:</para>
 
          <programlisting>
ipfw add 1 allow udp from A.B.C.D to W.X.Y.Z isakmp
ipfw add 1 allow udp from W.X.Y.Z to A.B.C.D isakmp
ipfw add 1 allow esp from A.B.C.D to W.X.Y.Z
ipfw add 1 allow esp from W.X.Y.Z to A.B.C.D
ipfw add 1 allow ipencap from A.B.C.D to W.X.Y.Z
ipfw add 1 allow ipencap from W.X.Y.Z to A.B.C.D
          </programlisting>
        </listitem>
      </itemizedlist>

      <para>The previous two steps should suffice to get the VPN up and
        running.  Machines on each network will be able to refer to one
        another using IP addresses, and all traffic across the link will
        be automatically and securely encrypted.</para>
    </sect3> 
    </sect2> 
  </sect1>

  <sect1 id="openssh">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Chern</firstname>
	  <surname>Lee</surname>
	  <contrib>Contributed by </contrib>
	</author>
	<!-- 21 April 2001 -->
      </authorgroup>
    </sect1info>

    <title>OpenSSH</title>
    <indexterm><primary>OpenSSH</primary></indexterm>
    <indexterm>
      <primary>security</primary>
      <secondary>OpenSSH</secondary>
    </indexterm>

    <para><application>OpenSSH</application> is a set of network connectivity tools used to
      access remote machines securely.  It can be used as a direct
      replacement for <command>rlogin</command>,
      <command>rsh</command>, <command>rcp</command>, and
      <command>telnet</command>.  Additionally, any other TCP/IP
      connections can be tunneled/forwarded securely through SSH.
      <application>OpenSSH</application> encrypts all traffic to effectively eliminate eavesdropping,
      connection hijacking, and other network-level attacks.</para>

    <para><application>OpenSSH</application> is maintained by the OpenBSD project, and is based
      upon SSH v1.2.12 with all the recent bug fixes and updates.  It
      is compatible with both SSH protocols 1 and 2.  <application>OpenSSH</application> has been
      in the base system since FreeBSD&nbsp;4.0.</para>

    <sect2>
      <title>Advantages of Using OpenSSH</title>
  
      <para>Normally, when using &man.telnet.1; or &man.rlogin.1;,
        data is sent over the network in an clear, un-encrypted form.
        Network sniffers anywhere in between the client and server can
        steal your user/password information or data transferred in
        your session.  <application>OpenSSH</application> offers a variety of authentication and
        encryption methods to prevent this from happening.</para>
    </sect2>

    <sect2>
      <title>Enabling sshd</title>
      <indexterm>
        <primary>OpenSSH</primary>
        <secondary>enabling</secondary>
      </indexterm>

      <para>Be sure to make the following addition to your 
        <filename>rc.conf</filename> file:</para>
      <screen>sshd_enable="YES"</screen>
      <para>This will load &man.sshd.8;, the daemon program for <application>OpenSSH</application>,
	the next time your system initializes.  Alternatively, you can
	simply run directly the <application>sshd</application> daemon by typing <command>sshd</command> on the command line.</para>
    </sect2>

    <sect2>
      <title>SSH Client</title>
      <indexterm>
        <primary>OpenSSH</primary>
        <secondary>client</secondary>
      </indexterm>

      <para>The &man.ssh.1; utility works similarly to 
        &man.rlogin.1;.</para>

      <screen>&prompt.root; <userinput>ssh <replaceable>user@example.com</replaceable></userinput>
Host key not found from the list of known hosts.
Are you sure you want to continue connecting (yes/no)? <userinput>yes</userinput>
Host 'example.com' added to the list of known hosts.
user@example.com's password: <userinput>*******</userinput></screen>

      <para>The login will continue just as it would have if a session was
        created using <command>rlogin</command> or
        <command>telnet</command>.  SSH utilizes a key fingerprint
        system for verifying the authenticity of the server when the 
        client connects.  The user is prompted to enter
	<literal>yes</literal> only when
        connecting for the first time.  Future attempts to login are all
        verified against the saved fingerprint key.  The SSH client
        will alert you if the saved fingerprint differs from the
        received fingerprint on future login attempts.  The fingerprints
        are saved in <filename>~/.ssh/known_hosts</filename>, or
	<filename>~/.ssh/known_hosts2</filename> for SSH v2
	fingerprints.</para>

      <para>By default, <application>OpenSSH</application> servers are configured to accept both
	SSH v1 and SSH v2 connections.  The client, however, can choose
	between the two.  Version 2 is known to be more robust and
	secure than its predecessor.</para>

      <para>The &man.ssh.1; command can be forced to use either protocol
	by passing it the <option>-1</option> or <option>-2</option> argument
	for v1 and v2, respectively.</para>
    </sect2>
    
    <sect2>
      <title>Secure Copy</title>
      <indexterm>
        <primary>OpenSSH</primary>
        <secondary>secure copy</secondary>
      </indexterm>
      <indexterm><primary><command>scp</command></primary></indexterm>

      <para>The &man.scp.1; command works similarly to
	&man.rcp.1;; it copies a file to or from a remote machine,
	except in a secure fashion.</para>

      <screen>&prompt.root; <userinput> scp <replaceable>user@example.com:/COPYRIGHT COPYRIGHT</replaceable></userinput>
user@example.com's password: <userinput>*******</userinput>
COPYRIGHT            100% |*****************************|  4735       
00:00    
&prompt.root;</screen>
      <para>Since the fingerprint was already saved for this host in the
        previous example, it is verified when using &man.scp.1;
        here.</para>

      <para>The arguments passed to &man.scp.1; are similar
	to &man.cp.1;, with the file or files in the first
	argument, and the destination in the second.  Since the file is
	fetched over the network, through SSH, one or more of the file
	arguments takes on the form
	<option>user@host:&lt;path_to_remote_file&gt;</option>.</para>

    </sect2>

    <sect2>
      <title>Configuration</title>
      <indexterm>
        <primary>OpenSSH</primary>
        <secondary>configuration</secondary>
      </indexterm>

      <para>The system-wide configuration files for both the <application>OpenSSH</application> 
        daemon and client reside within the <filename>/etc/ssh</filename> 
        directory.</para>

      <para><filename>ssh_config</filename> configures the client 
        settings, while <filename>sshd_config</filename> configures the 
        daemon.</para>

      <para>Additionally, the <option>sshd_program</option>
	(<filename>/usr/sbin/sshd</filename> by default), and
	<option>sshd_flags</option> <filename>rc.conf</filename>
	options can provide more levels of configuration.</para>
    </sect2>

    <sect2>
      <title>ssh-keygen</title>

      <para>Instead of using passwords, &man.ssh-keygen.1; can
        be used to generate RSA keys to authenticate a user:</para>

      <screen>&prompt.user; <userinput>ssh-keygen -t <replaceable>rsa1</replaceable></userinput>
Initializing random number generator...
Generating p:  .++ (distance 66)
Generating q:  ..............................++ (distance 498)
Computing the keys...
Key generation complete.
Enter file in which to save the key (/home/user/.ssh/identity):
Enter passphrase:
Enter the same passphrase again:
Your identification has been saved in /home/user/.ssh/identity.
...</screen>

      <para>&man.ssh-keygen.1; will create a public and private
        key pair for use in authentication.  The private key is stored in
        <filename>~/.ssh/identity</filename>, whereas the public key is
        stored in <filename>~/.ssh/identity.pub</filename>.  The public
        key must be placed in <filename>~/.ssh/authorized_keys</filename>
        of the remote machine in order for the setup to work.</para>

      <para>This will allow connection to the remote machine based upon
        RSA authentication instead of passwords.</para>

      <note><para>The <option>-t rsa1</option> option will create RSA
	keys for use by SSH protocol version 1.  If you want to use
	RSA keys with the SSH protocol version 2, you have to use the
	command <command>ssh-keygen -t rsa</command>.</para></note>

      <para>If a passphrase is used in &man.ssh-keygen.1;, the user
        will be prompted for a password each time in order to use the private
        key.</para>

      <para>A SSH protocol version 2 DSA key can be created for the same purpose by using
	the <command>ssh-keygen -t dsa</command> command.
	This will
	create a public/private DSA key for use in SSH protocol version 2 sessions only.
	The public key is stored in <filename>~/.ssh/id_dsa.pub</filename>,
	while the private key is in <filename>~/.ssh/id_dsa</filename>.</para>

      <para>DSA public keys are also placed in
	<filename>~/.ssh/authorized_keys</filename> on the remote
	machine.</para>

      <para>&man.ssh-agent.1; and &man.ssh-add.1; are 
        utilities used in managing multiple passworded private keys.</para>

      <warning><para>The various options and files can be different
	according to the <application>OpenSSH</application> version you have on your system, to
	avoid problems you should consult the &man.ssh-keygen.1;
	manual page.</para></warning>
    </sect2>

    <sect2>
      <title>SSH Tunneling</title>
      <indexterm>
        <primary>OpenSSH</primary>
        <secondary>tunneling</secondary>
      </indexterm>

      <para><application>OpenSSH</application> has the ability to create a tunnel to encapsulate
        another protocol in an encrypted session.</para>

      <para>The following command tells &man.ssh.1; to create a tunnel 
         for <application>telnet</application>:</para>

       <screen>&prompt.user; <userinput>ssh -2 -N -f -L <replaceable>5023:localhost:23 user@foo.example.com</replaceable></userinput>
&prompt.user;</screen>

      <para>The <command>ssh</command> command is used with the
	following options:</para>

      <variablelist>
	<varlistentry>
	  <term><option>-2</option></term>
	  
	  <listitem>
	    <para>Forces <command>ssh</command> to use version 2 of
	      the protocol. (Do not use if you are working with older
	      SSH servers)</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>-N</option></term>

	  <listitem>
	    <para>Indicates no command, or tunnel only.  If omitted,
	      <command>ssh</command> would initiate a normal
	      session.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>-f</option></term>

	  <listitem>
	    <para>Forces <command>ssh</command> to run in the
	      background.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>-L</option></term>

	  <listitem>
	    <para>Indicates a local tunnel in
	      <replaceable>localport:remotehost:remoteport</replaceable>
	      fashion.</para>
	  </listitem>
	  </varlistentry>

	<varlistentry>
	  <term><option>user@foo.example.com</option></term>

	  <listitem>
	    <para>The remote SSH server.</para>
	  </listitem>
	</varlistentry>
      </variablelist>


      <para>An SSH tunnel works by creating a listen socket on
	<hostid>localhost</hostid> on the specified port.
	It then forwards any connection received
	on the local host/port via the SSH connection to the specified
	remote host and port.</para>

      <para>In the example, port <replaceable>5023</replaceable> on
	<hostid>localhost</hostid> is being forwarded to port
	<replaceable>23</replaceable> on <hostid>localhost</hostid>
	of the remote machine.  Since <replaceable>23</replaceable> is <application>telnet</application>,
	this would create a secure <application>telnet</application> session through an SSH tunnel.</para>

      <para>This can be used to wrap any number of insecure TCP protocols 
        such as SMTP, POP3, FTP, etc.</para>

      <example>
	<title>Using SSH to Create a Secure Tunnel for SMTP</title>

        <screen>&prompt.user; <userinput>ssh -2 -N -f -L <replaceable>5025:localhost:25 user@mailserver.example.com</replaceable></userinput>
user@mailserver.example.com's password: <userinput>*****</userinput>
&prompt.user; <userinput>telnet localhost 5025</userinput>
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mailserver.example.com ESMTP</screen>     

        <para>This can be used in conjunction with an
          &man.ssh-keygen.1; and additional user accounts to create a
          more seamless/hassle-free SSH tunneling environment.  Keys
          can be used in place of typing a password, and the tunnels
          can be run as a separate user.</para>
      </example>

      <sect3>
	<title>Practical SSH Tunneling Examples</title>

	<sect4>
	  <title>Secure Access of a POP3 Server</title>

	  <para>At work, there is an SSH server that accepts
	    connections from the outside.  On the same office network
	    resides a mail server running a POP3 server.  The network,
	    or network path between your home and office may or may not
	    be completely trustable.  Because of this, you need to check
	    your e-mail in a secure manner.  The solution is to create
	    an SSH connection to your office's SSH server, and tunnel
	    through to the mail server.</para>

	  <screen>&prompt.user; <userinput>ssh -2 -N -f -L <replaceable>2110:mail.example.com:110 user@ssh-server.example.com</replaceable></userinput>
user@ssh-server.example.com's password: <userinput>******</userinput></screen>

	  <para>When the tunnel is up and running, you can point your
	    mail client to send POP3 requests to <hostid>localhost</hostid>
	    port 2110.  A connection here will be forwarded securely across
	    the tunnel to <hostid>mail.example.com</hostid>.</para>
	</sect4>

	<sect4>
	  <title>Bypassing a Draconian Firewall</title>

	  <para>Some network administrators impose extremely draconian
	    firewall rules, filtering not only incoming connections,
	    but outgoing connections.  You may be only given access
	    to contact remote machines on ports 22 and 80 for SSH
	    and web surfing.</para>

	  <para>You may wish to access another (perhaps non-work
	    related) service, such as an Ogg Vorbis server to stream
	    music.  If this Ogg Vorbis server is streaming on some other
	    port than 22 or 80, you will not be able to access it.</para>

	  <para>The solution is to create an SSH connection to a machine
	    outside of your network's firewall, and use it to tunnel to
	    the Ogg Vorbis server.</para>

	  <screen>&prompt.user; <userinput>ssh -2 -N -f -L <replaceable>8888:music.example.com:8000 user@unfirewalled-system.example.org</replaceable></userinput>
user@unfirewalled-system.example.org's password: <userinput>*******</userinput></screen>

	  <para>Your streaming client can now be pointed to
	    <hostid>localhost</hostid> port 8888, which will be
	    forwarded over to <hostid>music.example.com</hostid> port
	    8000, successfully evading the firewall.</para>
        </sect4>
      </sect3>
    </sect2>

    <sect2>
      <title>Further Reading</title>
      <para><ulink url="http://www.openssh.com/">OpenSSH</ulink></para>
      <para>&man.ssh.1; &man.scp.1; &man.ssh-keygen.1; 
        &man.ssh-agent.1; &man.ssh-add.1;</para>
      <para>&man.sshd.8; &man.sftp-server.8;</para>
    </sect2>
  </sect1>

  <sect1 id="mac">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Robert</firstname>
	  <surname>Watson</surname>
	  <contrib>Sponsored by DARPA and Network Associates Laboratories.
	    Contributed by </contrib>
	</author>
      </authorgroup>
    </sect1info>
    <indexterm>
      <primary>MAC</primary>
    </indexterm>
    <title>Mandatory Access Control (MAC)</title>

    <para>FreeBSD 5.0 includes a new kernel security framework, the
      TrustedBSD MAC Framework.  The MAC Framework permits compile-time,
      boot-time, and run-time extension of the kernel access control
      policy, and can be used to load support for Mandatory Access
      Control (<acronym>MAC</acronym>), and custom security modules
      such as hardening modules.  The MAC Framework is currently
      considered to be an experimental feature, and should not yet
      be used in production environments without careful consideration.
      It is anticipated that the MAC Framework will be appropriate for
      more widespread production use by FreeBSD 5.2.</para>

    <para>When configured into a kernel, the MAC Framework permits
      security modules to augment the existing kernel access control
      model, restricting access to system services and objects.  For
      example, the &man.mac.bsdextended.4; module augments file system
      access control, permitting administrators to provide a
      firewall-like ruleset constraining access to file system objects
      based on user ids and group membership.  Some modules require
      little or no configuration, such as &man.mac.seeotheruids.4,
      whereas others perform ubiquitous object labeling, such as
      &man.mac.biba.4; and &man.mac.mls.4;, and require extensive
      configuration.</para>

    <para>To enable the MAC Framework in your system kernel, you must
      add the following entry to your kernel configuration:</para>

    <programlisting>options MAC</programlisting>

    <para>Security policy modules shipped with the base system may
     be loaded using &man.kldload.8; or in the boot &man.loader.8;
     They may also be compiled directly into the kernel using the
     following options, if the use of modules is not desired.</para>

    <para>Different MAC policies may be configured in different ways;
      frequently, MAC policy modules export configuration parameters
      using the &man.sysctl.8; <acronym>MIB</acronym> using the
      <varname>security.mac</varname> namespace.  Policies relying on
      file system or other labels may require a configuration step
      that involves assigning initial labels to system objects or
      creating a policy configuration file.  For information on how to
      configure and use each policy module, see its man page.</para>

    <para>A variety of tools are available to configure the MAC Framework
      and labels maintained by various policies.  Extensions have been
      made to the login and credential management mechanisms
      (&man.setusercontext.3;) to support initial user labeling using
      &man.login.conf.5;.  In addition, modifications have been made
      to &man.su.1;, &man.ps.1;, &man.ls.1;, and &man.ifconfig.8; to
      inspect and set labels on processes, files, and interfaces.  In
      addition, several new tools have been added to manage labels
      on objects, including &man.getfmac.8;, &man.setfmac.8;, and
      &man.setfsmac.8; to manage labels on files, and &man.getpmac.8; and
      &man.setpmac.8;.</para>

    <para>What follows is a list of policy modules shipped with FreeBSD
      5.0.</para>
    <sect2 id="mac-policy-biba">
      <title>Biba Integrity Policy (mac_biba)</title>
      <indexterm>
	<primary>Biba Integrity Policy</primary>
      </indexterm>
      <para>Vendor: TrustedBSD Project</para>
      <para>Module name: mac_biba.ko</para>
      <para>Kernel option: <literal>MAC_BIBA</literal></para>
      <indexterm>
	<primary>TCB</primary>
      </indexterm>
      <para>The Biba Integrity Policy (&man.mac.biba.4;) provides
	for hierarchical and non-hierarchical labeling of all system
	objects with integrity data, and the strict enforcement of
	an information flow policy to prevent corruption of high
	integrity subjects and data by low-integrity subjects.
	Integrity is enforced by preventing high integrity
	subjects (generally processes) from reading low integrity
	objects (often files), and preventing low integrity
	subjects from writing to high integrity objects.
	This security policy is frequently used in commercial
	trusted systems to provide strong protection for the
	Trusted Code Base (<acronym>TCB</acronym>).  Because it
	provides ubiquitous labeling, the Biba integrity policy
	must be compiled into the kernel or loaded at boot.</para>
    </sect2>
    <sect2 id="mac-policy-bsdextended">
      <title>File System Firewall Policy (mac_bsdextended)</title>
      <indexterm>
	<primary>File System Firewall Policy</primary>
      </indexterm>
      <para>Vendor: TrustedBSD Project</para>
      <para>Module name: mac_bsdextended.ko</para>
      <para>Kernel option: <literal>MAC_BSDEXTENDED</literal></para>
      <para> The File System Firewall Policy (&man.mac.bsdextended.4;)
	provides an extension to the BSD file system permission model,
	permitting the administrator to define a set of firewall-like
	rules for limiting access to file system objects owned by
	other users and groups.  Managed using &man.ugidfw.8;, rules
	may limit access to files and directories based on the uid
	and gids of the process attempting the access, and the owner
	and group of the target of the access attempt.  All rules
	are restrictive, so they may be placed in any order.  This policy
	requires no prior configuration or labeling, and may be
	appropriate in multi-user environments where mandatory limits
	on inter-user data exchange are required.  Caution should be
	exercised in limiting access to files owned by the super-user or
	other system user ids, as many useful programs and directories
	are owned by these users.  As with a network firewall,
	improper application of file system firewall rules may render
	the system unusable.  New tools to manage the rule set may be
	easily written using the &man.libugidfw.3; library.</para>
    </sect2>
    <sect2 id="mac-policy-ifoff">
      <title>Interface Silencing Policy (mac_ifoff)</title>
      <indexterm>
	<primary>Interface Silencing Policy</primary>
      </indexterm>
      <para>Vendor: TrustedBSD Project</para>
      <para>Module name: mac_ifoff.ko</para>
      <para>Kernel option: <literal>MAC_IFOFF</literal></para>
      <para>The interface silencing policy (&man.mac.ifoff.4;)
	prohibits the use of network interfaces during the boot
	until explicitly enabled, preventing spurious stack output
	stack response to incoming packets.  This is appropriate
	for use in environments where the monitoring of packets
	is required, but no traffic may be generated.</para>
    </sect2>
    <sect2 id="mac-policy-lomac">
      <title>Low-Watermark Mandatory Access Control (LOMAC)
	(mac_lomac)</title>
      <indexterm>
	<primary>MAC</primary>
	<secondary>Low-Watermark</secondary>
      </indexterm>
      <indexterm>
	<primary>LOMAC</primary>
      </indexterm>
      <para>Vendor: Network Associates Laboratories</para>
      <para>Module name: mac_lomac.ko</para>
      <para>Kernel option: <literal>MAC_LOMAC</literal></para>
      <para>Similar to the Biba Integrity Policy, the LOMAC
	policy (&man.mac.lomac.4;) relies on the ubiquitous
	labeling of all system objects with integrity labels.
	Unlike Biba, LOMAC permits high integrity subjects to
	read from low integrity objects, but then downgrades the
	label on the subject to prevent future writes to high
	integrity objects.  This policy may provide for greater
	compatibility, as well as require less initial
	configuration than Biba.  However, as with Biba, it
	ubiquitously labels objects and must therefore be
	compiled into the kernel or loaded at boot.</para>
    </sect2>

    <sect2 id="mac-policy-mls">
      <title>Multi-Level Security Policy (MLS) (mac_mls)</title>
      <indexterm>
	<primary>Multi-Level Security Policy</primary>
      </indexterm>
      <indexterm>
	<primary>MAC</primary>
	<secondary>Multi-Level</secondary>
      </indexterm>

      <para>Vendor: TrustedBSD Project</para>
      <para>Module name: mac_mls.ko</para>
      <para>Kernel option: <literal>MAC_MLS</literal></para>
      <para>Multi-Level Security (<acronym>MLS</acronym>)
        (&man.mac.mls.4;) provides for hierarchical and non-hierarchical
        labeling of all system objects with sensitivity data, and the
        strict enforcement of an information flow policy to prevent
        the leakage of confidential data to untrusted parties.  The
        logical conjugate of the Biba Integrity Policy,
        <acronym>MLS</acronym> is frequently shipped in commercial
        trusted operating systems to protect data secrecy in
        multi-user environments.  Hierarchal labels provide support
        for the notion of clearances and classifications in
        traditional parlance; non-hierarchical labels provide support
        for <quote>need-to-know.</quote>  As with Biba, ubiquitous
        labeling of objects occurs, and it must therefore be compiled
        into the kernel or loaded at boot.  As with Biba, extensive
        initial configuration may be required.</para>
    </sect2>
    <sect2 id="mac-policy-none">
      <title>MAC Stub Policy (mac_none)</title>
      <indexterm>
	<primary>MAC Stub Policy</primary>
      </indexterm>
      <para>Vendor: TrustedBSD Project</para>
      <para>Module name: mac_none.ko</para>
      <para>Kernel option: <literal>MAC_NONE</literal></para>
      <para>The None policy (&man.mac.none.4;) provides a stub
	sample policy for developers, implementing all entry
	points, but not changing the system access control
	policy.  Running this on a production system would
	not be highly beneficial.</para>
    </sect2>
    <sect2 id="mac-policy-partition">
      <title>Process Partition Policy (mac_partition)</title>
      <indexterm>
	<primary>Process Partition Policy</primary>
      </indexterm>
      <para>Vendor: TrustedBSD Project</para>
      <para>Module name: mac_partition.ko</para>
      <para>Kernel option: <literal>MAC_PARTITION</literal></para>
      <para>The Partition policy (&man.mac.partition.4;) provides for a
	simple process visibility limitation, assigning labels to
	processes identifying what numeric system partition they
	are present in.  If none, all other processes are visible
	using standard monitoring tools; if a partition identifier
	is present, then only other processes in the same
	partition are visible.  This policy may be compiled into
	the kernel, loaded at boot, or loaded at run-time.</para>
    </sect2>
    <sect2 id="mac-policy-seeotheruids">
      <title>See Other Uids Policy (mac_seeotheruids)</title>
      <indexterm>
	<primary>See Other Uids Policy</primary>
      </indexterm>
      <para>Vendor: TrustedBSD Project</para>
      <para>Module name: mac_seeotheruids.ko</para>
      <para>Kernel option: <literal>MAC_SEEOTHERUIDS</literal></para>
      <para>The See Other Uids policy (&man.mac.seeotheruids.4;)
        implements a similar process visibility model to
        mac_partition, except that it relies on process credentials to
        control visibility of processes, rather than partition labels.
        This policy may be configured to exempt certain users and
        groups, including permitting system operators to view all
        processes without special privilege.  This policy may be
        compiled into the kernel, loaded at boot, or loaded at
        run-time.</para>
    </sect2>
    <sect2 id="mac-policy-test">
      <title>MAC Framework Test Policy (mac_test)</title>
      <indexterm>
	<primary>MAC Framework Test Policy</primary>
      </indexterm>
      <para>Vendor: TrustedBSD Project</para>
      <para>Module name: mac_test.ko</para>
      <para>Kernel option: <literal>MAC_TEST</literal></para>
      <para>The Test policy (&man.mac.test.4;) provides a regression
        test environment for the MAC Framework, and will cause a
        fail-stop in the event that internal MAC Framework assertions
        about proper data labeling fail.  This module can be used to
        detect failures to properly label system objects in the kernel
        implementation.  This policy may be compiled into the kernel,
        loaded at boot, or loaded at run-time.</para>
    </sect2>

  </sect1>

    <sect1 id="fs-acl">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Tom</firstname>
	  <surname>Rhodes</surname>
	  <contrib>Contributed by </contrib>
	</author>
      </authorgroup>
    </sect1info>
    <indexterm>
      <primary>ACL</primary>
    </indexterm>
    <title>File System Access Control Lists</title>

    <para>In conjunction with file system enhancements like snapshots, FreeBSD 5.0
      and later offers the security of File System Access Control Lists
      (<acronym>ACLs</acronym>).</para>

    <para>Access Control Lists extend the standard &unix;
      permission model in a highly compatible (&posix;.1e) way.  This feature
      permits an administrator to make use of and take advantage of a
      more sophisticated security model.</para>

    <para>To enable <acronym>ACL</acronym> support for <acronym>UFS</acronym>
      file systems, the following:</para>

    <programlisting>options UFS_ACL</programlisting>

    <para>must be compiled into the kernel.  If this option has
      not been compiled in, a warning message will be displayed
      when attempting to mount a file system supporting <acronym>ACLs</acronym>.
      This option is included in the <filename>GENERIC</filename> kernel.
      <acronym>ACLs</acronym> rely on extended attributes being enabled on
      the file system.  Extended attributes are natively supported in the next generation
      &unix; file system, <acronym>UFS2</acronym>.</para>

    <note><para>A higher level of administrative overhead is required to
      configure extended attributes on <acronym>UFS1</acronym> than on
      <acronym>UFS2</acronym>.  The performance of extended attributes
      on <acronym>UFS2</acronym> is also substantially higher.  As a
      result, <acronym>UFS2</acronym> is generally recommended in preference
      to <acronym>UFS1</acronym> for use with access control lists.</para></note>

    <para><acronym>ACLs</acronym> are enabled by the mount-time administrative
      flag, <option>acls</option>, which may be added to <filename>/etc/fstab</filename>.
      The mount-time flag can also be automatically set in a persistent manner using
      &man.tunefs.8; to modify a superblock <acronym>ACLs</acronym> flag in the
      file system header.  In general, it is preferred to use the superblock flag
      for several reasons:</para>

    <itemizedlist>
      <listitem>
	<para>The mount-time <acronym>ACLs</acronym> flag cannot be changed by a
	remount (&man.mount.8; <option>-u</option>), only by means of a complete
	&man.umount.8; and fresh &man.mount.8;.  This means that
	<acronym>ACLs</acronym> cannot be enabled on the root file system after boot.
	It also means that you cannot change the disposition of a file system once
	it is in use.</para>
      </listitem>

      <listitem>
	<para>Setting the superblock flag will cause the file system to always be
	mounted with <acronym>ACLs</acronym> enabled even if there is not an
	<filename>fstab</filename> entry or if the devices re-order.  This prevents
	accidental mounting of the file system without <acronym>ACLs</acronym>
	enabled, which can result in <acronym>ACLs</acronym> being improperly enforced,
	and hence security problems.</para>
      </listitem>
    </itemizedlist>

    <note><para>We may change the <acronym>ACLs</acronym> behavior to allow the flag to
      be enabled without a complete fresh &man.mount.8;, but we consider it desirable to
      discourage accidental mounting without <acronym>ACLs</acronym> enabled, because you
      can shoot your feet quite nastily if you enable <acronym>ACLs</acronym>, then disable
      them, then re-enable them without flushing the extended attributes.  In general, once
      you have enabled <acronym>ACLs</acronym> on a file system, they should not be disabled,
      as the resulting file protections may not be compatible with those intended by the
      users of the system, and re-enabling <acronym>ACLs</acronym> may re-attach the previous
      <acronym>ACLs</acronym> to files that have since had their permissions changed,
      resulting in other unpredictable behavior.</para></note>
      
    <para>File systems with <acronym>ACLs</acronym> enabled will show a <literal>+</literal>
      (plus) sign in their permission settings when viewed.  For example:</para>

    <programlisting>drwx------  2 robert  robert  512 Dec 27 11:54 private
drwxrwx---+ 2 robert  robert  512 Dec 23 10:57 directory1
drwxrwx---+ 2 robert  robert  512 Dec 22 10:20 directory2
drwxrwx---+ 2 robert  robert  512 Dec 27 11:57 directory3
drwxr-xr-x  2 robert  robert  512 Nov 10 11:54 public_html</programlisting>

    <para>Here we see that the <filename>directory1</filename>,
      <filename>directory2</filename>, and <filename>directory3</filename>
      directories are all taking advantage of <acronym>ACLs</acronym>.  The
      <filename>public_html</filename> directory is not.</para>

    <sect2>
      <title>Making Use of <acronym>ACL</acronym>s</title>

      <para>The file system <acronym>ACL</acronym>s can be viewed by the
	&man.getfacl.1; utility.  For instance, to view the
	<acronym>ACL</acronym> settings on the <filename>test</filename>
	file, one would use the command:</para>

      <screen>&prompt.user; <userinput>getfacl <filename>test</filename></userinput>
	#file:test
	#owner:1001
	#group:1001
	user::rw-
	group::r--
	other::r--</screen>

      <para>To change the <acronym>ACL</acronym> settings on this file,
	invoke the &man.setfacl.1; utility.  Observe:</para>

      <screen>&prompt.user; <userinput>setfacl -k <filename>test</filename></userinput></screen>

      <para>The <option>-k</option> flag will remove all of the
	currently defined <acronym>ACL</acronym>s from a file or file
	system.  The more preferable method would be to use
	<option>-b</option> as it leaves the basic fields required for
	<acronym>ACL</acronym>s to work.</para>

      <screen>&prompt.user; <userinput>setfacl -m u:trhodes:rwx,group:web:r--,o::--- <filename>test</filename></userinput></screen>

      <para>In the aforementioned command, the <option>-m</option>
	option was used to modify the default <acronym>ACL</acronym>
	entries.  Since there were no pre-defined entries, as they were
	removed by the previous command, this will restore the default
	options and assign the options listed.  Take care to notice that
	if you add a user or group which does not exist on the system,
	an <errorname>Invalid argument</errorname> error will be printed
	to <devicename>stdout</devicename>.</para>
    </sect2>
  </sect1>

  <sect1 id="security-advisories">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Tom</firstname>
	  <surname>Rhodes</surname>
	  <contrib>Contributed by </contrib>
	</author>
      </authorgroup>
    </sect1info>
    <indexterm>
      <primary>FreeBSD Security Advisories</primary>
    </indexterm>
    <title>&os; Security Advisories</title>

    <para>Like many production quality operating systems, &os; publishes
      <quote>Security Advisories</quote>.  These advisories are usually
      mailed to the security lists and noted in the Errata only
      after the appropriate releases have been patched.  This section
      will work to explain what an advisory is, how to understand it,
      and what measures to take in order to patch a system.</para>

    <sect2>
      <title>What does an advisory look like?</title>

      <para>The &os; security advisories look similar to the one below,
	taken from the &a.security-notifications.name; mailing list.</para>

      <programlisting>=============================================================================
&os;-SA-XX:XX.UTIL                                     Security Advisory
                                                          The &os; Project

Topic:          denial of service due to some problem<co id="co-topic">

Category:       core<co id="co-category">
Module:         sys<co id="co-module">
Announced:      2003-09-23<co id="co-announce">
Credits:        Person@EMAIL-ADDRESS<co id="co-credit">
Affects:        All releases of &os;<co id="co-affects">
                &os; 4-STABLE prior to the correction date
Corrected:      2003-09-23 16:42:59 UTC (RELENG_4, 4.9-PRERELEASE)
                2003-09-23 20:08:42 UTC (RELENG_5_1, 5.1-RELEASE-p6)
                2003-09-23 20:07:06 UTC (RELENG_5_0, 5.0-RELEASE-p15)
                2003-09-23 16:44:58 UTC (RELENG_4_8, 4.8-RELEASE-p8)
                2003-09-23 16:47:34 UTC (RELENG_4_7, 4.7-RELEASE-p18)
                2003-09-23 16:49:46 UTC (RELENG_4_6, 4.6-RELEASE-p21)
                2003-09-23 16:51:24 UTC (RELENG_4_5, 4.5-RELEASE-p33)
                2003-09-23 16:52:45 UTC (RELENG_4_4, 4.4-RELEASE-p43)
                2003-09-23 16:54:39 UTC (RELENG_4_3, 4.3-RELEASE-p39)<co id="co-corrected">
&os; only:   NO<co id="co-only">

For general information regarding FreeBSD Security Advisories,
including descriptions of the fields above, security branches, and the
following sections, please visit
http://www.freebsd.org/security/.

I.   Background<co id="co-backround">


II.  Problem Description<co id="co-descript">


III. Impact<co id="co-impact">


IV.  Workaround<co id="co-workaround">


V.   Solution<co id="co-solution">


VI.  Correction details<co id="co-details">


VII. References<co id="co-ref"></programlisting>


      <calloutlist>
	<callout arearefs="co-topic">
	  <para>The <literal>Topic</literal> field indicates exactly what the problem is.
	    It is basically an introduction to the current security
	    advisory and notes the utility with the
	    vulnerability.</para>
	</callout>

	<callout arearefs="co-category">
	  <para>The <literal>Category</literal> refers to the affected part of the system
	    which may be one of <literal>core</literal>, <literal>contrib</literal>, or <literal>ports</literal>.  The <literal>core</literal>
	    category means that the vulnerability affects a core
	    component of the &os; operating system.  The <literal>contrib</literal>
	    category means that the vulnerability affects software
	    contributed to the &os; Project, such as
	    <application>sendmail</application>.  Finally the <literal>ports</literal>
	    category indicates that the vulnerability affects add on
	    software available as part of the ports collection.</para>
	</callout>

	<callout arearefs="co-module">
	  <para>The <literal>Module</literal> field refers to the component location, for
	    instance <literal>sys</literal>.  In this example, we see that the module,
	    <literal>sys</literal>, is affected; therefore, this vulnerability
	    affects a component used within the kernel.</para>
	</callout>

	<callout arearefs="co-announce">
	  <para>The <literal>Announced</literal> field reflects the date said security
	    advisory was published, or announced to the world.  This
	    means that the security team has verified that the problem
	    does exist and that a patch has been committed to the &os;
	    source code repository.</para>
	</callout>

	<callout arearefs="co-credit">
	  <para>The <literal>Credits</literal> field gives credit to the individual or
	    organization who noticed the vulnerability and reported
	    it.</para>
	</callout>

	<callout arearefs="co-affects">
	  <para>The <literal>Affects</literal> field explains which releases of &os; are
	    affected by this vulnerability.  For the kernel, a quick
	    look over the output from <command>ident</command> on the
	    affected files will help in determining the revision.
	    For ports, the version number is listed after the port name
	    in <filename>/var/db/pkg</filename>.  If the system does not
	    sync with the &os; <acronym>CVS</acronym> repository and rebuild
	    daily, chances are that it is affected.</para>
	</callout>

	<callout arearefs="co-corrected">
	  <para>The <literal>Corrected</literal> field indicates the date, time, time
	    offset, and release that was corrected.</para>
	</callout>

	<callout arearefs="co-only">
	  <para>The <literal>&os; only</literal> field indicates whether this vulnerability
	    affects just &os;, or if it affects other operating systems
	    as well.</para>
	</callout>

	<callout arearefs="co-backround">
	  <para>The <literal>Background</literal> field gives information on exactly what
	    the affected utility is.  Most of the time this is why
	    the utility exists in &os;, what it is used for, and a bit
	    of information on how the utility came to be.</para>
	</callout>

	<callout arearefs="co-descript">
	  <para>The <literal>Problem Description</literal> field explains the security hole
	    in depth.  This can include information on flawed code, or
	    even how the utility could be maliciously used to open
	    a security hole.</para>
	</callout>

	<callout arearefs="co-impact">
	  <para>The <literal>Impact</literal> field describes what type of impact the
	    problem could have on a system.  For example, this could
	    be anything from a denial of service attack, to extra
	    privileges available to users, or even giving the attacker
	    superuser access.</para>
	</callout>

	<callout arearefs="co-workaround">
	  <para>The <literal>Workaround</literal> field offers a feasible workaround to
	    system administrators who may be incapable of upgrading
	    the system.  This may be due to time constraints, network
	    availability, or a slew of other reasons.  Regardless,
	    security should not be taken lightly, and an affected system
	    should either be patched or the security hole workaround
	    should be implemented.</para>
	</callout>

	<callout arearefs="co-solution">
	  <para>The <literal>Solution</literal> field offers instructions on patching the
	    affected system.  This is a step by step tested and verified
	    method for getting a system patched and working
	    securely.</para>
	</callout>

	<callout arearefs="co-details">
	  <para>The <literal>Correction Details</literal> field displays the
	    <acronym>CVS</acronym> branch or release name with the
	    periods changed to underscore characters.  It also shows
	    the revision number of the affected files within each
	    branch.</para>

	<callout arearefs="co-ref">
	  <para>The <literal>References</literal> field usually offers sources of other
	    information.  This can included web <acronym>URL</acronym>s,
	    books, mailing lists, and newsgroups.</para>
	</callout>
      </calloutlist>
    </sect2>
  </sect1>
</chapter>

<!--
     Local Variables:
     mode: sgml
     sgml-declaration: "../chapter.decl"
     sgml-indent-data: t
     sgml-omittag: nil
     sgml-always-quote-attributes: t
     sgml-parent-document: ("../book.sgml" "part" "chapter")
     End:
-->