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
|
/*
This file is part of Kismet
Kismet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kismet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "packetracker.h"
#include "networksort.h"
#include "server_globals.h"
#include "kismet_server.h"
#include "packetsignatures.h"
#include "packet.h"
// Aref array indexes
#define NETSTUMBLER_AREF 0
#define DEAUTHFLOOD_AREF 1
#define LUCENTTEST_AREF 2
#define WELLENREITER_AREF 3
#define CHANCHANGE_AREF 4
#define BCASTDISCON_AREF 5
#define AIRJACKSSID_AREF 6
#define NULLPROBERESP_AREF 7
#define MSFBCOMSSID_AREF 8
#define LONGSSID_AREF 9
#define MSFDLINKRATE_AREF 10
#define MSFNETGEARBCN_AREF 11
#define DISCONCODE_AREF 12
#define DEAUTHCODE_AREF 13
#define MAX_AREF 14
extern mac_addr broadcast_mac;
// Masked opcode MAC used to match metasploit opcode src fields
mac_addr msfopcode_mac = mac_addr("90:E9:75:00:00:00/FF:FF:FF:00:00:00");
// Get this out of kismet_server (yeah, yeah, globals bad)
extern int netcryptdetect, waypointformat;
extern int limit_nets;
extern int track_ivs;
Packetracker::Packetracker() {
alertracker = NULL;
num_networks = num_packets = num_dropped = num_noise =
num_crypt = num_interesting = num_cisco = 0;
best_signal = worst_signal = 0;
errstr[0] = '\0';
filter_export_bssid = filter_export_source = filter_export_dest = NULL;
filter_export_bssid_invert = filter_export_source_invert = filter_export_dest_invert = NULL;
filter_export = 0;
arefs = new int[MAX_AREF];
for (unsigned int ref = 0; ref < MAX_AREF; ref++)
arefs[ref] = -1;
}
Packetracker::~Packetracker() {
for (unsigned int x = 0; x < network_list.size(); x++) {
for (unsigned int y = 0; y < network_list[x]->client_vec.size(); y++)
delete network_list[x]->client_vec[y];
delete network_list[x];
}
delete[] arefs;
}
vector<wireless_network *> Packetracker::FetchNetworks() {
vector<wireless_network *> ret_vec = network_list;
return ret_vec;
}
void Packetracker::AddAlertracker(Alertracker *in_tracker) {
alertracker = in_tracker;
}
int Packetracker::EnableAlert(string in_alname, alert_time_unit in_unit,
int in_rate, alert_time_unit in_bunit,
int in_burstrate) {
if (alertracker == NULL) {
snprintf(errstr, 1024, "No registered alert tracker.");
return -1;
}
int ret = -1;
string lname = StrLower(in_alname);
if (lname == "netstumbler") {
// register netstumbler alert
ret = arefs[NETSTUMBLER_AREF] =
alertracker->RegisterAlert("NETSTUMBLER", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "deauthflood") {
// register deauth flood
ret = arefs[DEAUTHFLOOD_AREF] =
alertracker->RegisterAlert("DEAUTHFLOOD", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "lucenttest") {
// register lucent test
ret = arefs[LUCENTTEST_AREF] =
alertracker->RegisterAlert("LUCENTTEST", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "wellenreiter") {
// register wellenreiter test
ret = arefs[WELLENREITER_AREF] =
alertracker->RegisterAlert("WELLENREITER", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "chanchange") {
// register channel changing
ret = arefs[CHANCHANGE_AREF] =
alertracker->RegisterAlert("CHANCHANGE", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "bcastdiscon") {
// Register broadcast disconnect
ret = arefs[BCASTDISCON_AREF] =
alertracker->RegisterAlert("BCASTDISCON", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "airjackssid") {
// Register airjack SSID alert
ret = arefs[AIRJACKSSID_AREF] =
alertracker->RegisterAlert("AIRJACKSSID", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "nullproberesp") {
// Register 0-len probe response alert
ret = arefs[NULLPROBERESP_AREF] =
alertracker->RegisterAlert("NULLPROBERESP", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "msfbcomssid") {
// Register MSF broadcom SSID alert
ret = arefs[MSFBCOMSSID_AREF] =
alertracker->RegisterAlert("MSFBCOMSSID", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "msfdlinkrate") {
// Register MSF dlink rate alert
ret = arefs[MSFDLINKRATE_AREF] =
alertracker->RegisterAlert("MSFDLINKRATE", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "msfnetgearbeacon") {
// Register MSF dlink rate alert
ret = arefs[MSFNETGEARBCN_AREF] =
alertracker->RegisterAlert("MSFNETGEARBEACON", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "longssid") {
// Register generic over-long SSID alert
ret = arefs[LONGSSID_AREF] =
alertracker->RegisterAlert("LONGSSID", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "disconcodeinvalid") {
ret = arefs[DEAUTHCODE_AREF] =
alertracker->RegisterAlert("DISCONCODEINVALID", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "deauthcodeinvalid") {
ret = arefs[DISCONCODE_AREF] =
alertracker->RegisterAlert("DEAUTHCODEINVALID", in_unit, in_rate,
in_bunit, in_burstrate);
} else if (lname == "probenojoin") {
ProbeNoJoinAutomata *pnja =
new ProbeNoJoinAutomata(this, alertracker, in_unit, in_rate,
in_bunit, in_burstrate);
fsa_vec.push_back(pnja);
ret = pnja->FetchAlertRef();
} else if (lname == "disassoctraffic") {
DisassocTrafficAutomata *dta =
new DisassocTrafficAutomata(this, alertracker, in_unit, in_rate,
in_bunit, in_burstrate);
fsa_vec.push_back(dta);
ret = dta->FetchAlertRef();
} else if (lname == "bsstimestamp") {
BssTimestampAutomata *bta =
new BssTimestampAutomata(this, alertracker, in_unit, in_rate,
in_bunit, in_burstrate);
fsa_vec.push_back(bta);
ret = bta->FetchAlertRef();
} else {
snprintf(errstr, 1024, "Unknown alert type %s, not processing.", lname.c_str());
return 0;
}
if (ret == -1)
snprintf(errstr, 1024, "Alert '%s' already processed, duplicate.", in_alname.c_str());
return ret;
}
void Packetracker::AddExportFilters(macmap<int> *bssid_map,
macmap<int> *source_map,
macmap<int> *dest_map, int *bssid_invert,
int *source_invert, int *dest_invert) {
filter_export = 1;
filter_export_bssid = bssid_map;
filter_export_bssid_invert = bssid_invert;
filter_export_source = source_map;
filter_export_source_invert = source_invert;
filter_export_dest = dest_map;
filter_export_dest_invert = dest_invert;
}
// Is a string blank?
bool Packetracker::IsBlank(const char *s) {
int len, i;
if (NULL == s) { return true; }
if (0 == (len = strlen(s))) { return true; }
for (i = 0; i < len; ++i) {
if (' ' != s[i]) { return false; }
}
return true;
}
// Periodic tick to handle events. We expect this once a second.
int Packetracker::Tick() {
for (unsigned int x = 0; x < network_list.size(); x++) {
wireless_network *net = network_list[x];
// Decay 10 disconnects per second
if (net->client_disconnects != 0) {
net->client_disconnects -= 10;
if (net->client_disconnects < 0)
net->client_disconnects = 0;
}
}
return 1;
}
wireless_network *Packetracker::MatchNetwork(const packet_info *info) {
map<mac_addr, wireless_network *>::iterator bsmapitr;
bsmapitr = bssid_map.find(info->bssid_mac);
// If it's a broadcast (From and To DS == 1) try to match it to an existing network
if ((info->type == packet_data && info->subtype == packet_sub_data) &&
info->distrib == inter_distribution && bsmapitr == bssid_map.end()) {
if ((bsmapitr = bssid_map.find(info->source_mac)) != bssid_map.end()) {
// info->bssid_mac = info->source_mac;
bsmapitr = bssid_map.find(info->source_mac);
} else if ((bsmapitr = bssid_map.find(info->dest_mac)) != bssid_map.end()) {
// info->bssid_mac = info->dest_mac;
bsmapitr = bssid_map.find(info->dest_mac);
}
} else if (info->type == packet_management &&
info->subtype == packet_sub_probe_req && track_probenets) {
// If it's a probe request, see if we already know who it should belong to
if (probe_map.find(info->bssid_mac) != probe_map.end()) {
// info->bssid_mac = probe_map[info->bssid_mac];
bsmapitr = bssid_map.find(probe_map[info->bssid_mac]);
}
}
if (bsmapitr != bssid_map.end())
return bsmapitr->second;
return NULL;
}
wireless_client *Packetracker::CreateClient(const packet_info *info,
wireless_network *net,
int destclient) {
#if 0
/* Main data handler doesn't like NULL client values */
/* If an attacker use a tool similar to Fake AP to create zillions
* fake clients, it can DoS Kismet and/or the underlying system.
* Basically, we will exhaust the system memory.
* Let's limit the number of clients to avoid that...
* There is one way to recover : restart Kismet. We may want to
* consider client expiry...
* Jean II */
if(limit_nets > 0)
if(net->client_vec.size() > (unsigned int) limit_nets) {
/* We should trigger an alert and log this condition */
/* Don't create this client. */
return NULL;
}
#endif
mac_addr climac;
map<mac_addr, wireless_client *>::iterator cmi;
if (destclient == 0) {
climac = info->source_mac;
} else {
climac = info->dest_mac;
}
if ((cmi = net->client_map.find(climac)) != net->client_map.end())
return cmi->second;
wireless_client *client = new wireless_client;
// Add it to the map
net->client_map[climac] = client;
// Add it to the vec
net->client_vec.push_back(client);
client->first_time = time(0);
client->mac = climac;
client->manuf_ref = MatchBestManuf(&client_manuf_map, client->mac, "", 0, 0, 0,
&client->manuf_score);
client->metric = net->metric;
if (info->gps_fix >= 2) {
client->gps_fixed = info->gps_fix;
client->min_lat = client->max_lat = info->gps_lat;
client->min_lon = client->max_lon = info->gps_lon;
client->min_alt = client->max_alt = info->gps_alt;
client->min_spd = client->max_spd = info->gps_spd;
client->aggregate_lat = info->gps_lat;
client->aggregate_lon = info->gps_lon;
client->aggregate_alt = info->gps_alt;
client->aggregate_points = 1;
}
// Classify the client. We'll call no-distrib packets (lucent)
// inter-distrib clients since it's not an end-user bridge into the
// network, it's a lucent AP talking to another one.
//
// If we're a destclient, we get classified as a sendto, and then
// some later packet from us will get reclassified by the main component
if (destclient) {
client->type = client_sendto;
} else if (info->distrib == from_distribution)
client->type = client_fromds;
else if (info->distrib == to_distribution)
client->type = client_tods;
else if (info->distrib == inter_distribution)
client->type = client_interds;
else if (info->distrib == no_distribution)
client->type = client_interds;
if (bssid_ip_map.find(climac) != bssid_ip_map.end()) {
memcpy(&net->ipdata, &bssid_ip_map[climac], sizeof(net_ip_data));
}
KisLocalNewclient(client, net);
return client;
}
void Packetracker::ProcessPacket(kis_packet *packet, packet_info *info,
macmap<wep_key_info *> *bssid_wep_map,
unsigned char *identity) {
wireless_network *net;
char status[STATUS_MAX];
int newnet = 0;
// string bssid_mac;
num_packets++;
// Check the SSID length before checking corrupt state -- when we get
// a long SSID (longer than 32) in the packet decoder we blow it up and
// kick it to here
if (info->ssid_len > 32) {
if (alertracker->PotentialAlert(arefs[LONGSSID_AREF])) {
snprintf(status, STATUS_MAX, "Illegal SSID length (%d > 32) from %s",
info->ssid_len, info->source_mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[LONGSSID_AREF], info->source_mac,
info->source_mac, 0, 0, info->channel, status);
}
}
// Catch our explicit flags from the packet dissector (total hack, wait
// for newcore to do properly)
if (info->ids_msfdlinkrate) {
if (alertracker->PotentialAlert(arefs[MSFDLINKRATE_AREF])) {
snprintf(status, STATUS_MAX, "MSF-style poisoned 802.11 rate field in "
"beacon %s for D-Link driver attack",
info->source_mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[MSFDLINKRATE_AREF], info->source_mac,
info->source_mac, 0, 0, info->channel, status);
}
}
if (info->ids_msfnetgearbeacon) {
if (alertracker->PotentialAlert(arefs[MSFNETGEARBCN_AREF])) {
snprintf(status, STATUS_MAX, "MSF-style poisoned 802.11 over-sized "
"options beacon %s for Netgear driver attack",
info->source_mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[MSFNETGEARBCN_AREF], info->source_mac,
info->source_mac, 0, 0, info->channel, status);
}
}
// Feed it through the finite state alert processors
for (unsigned int x = 0; x < fsa_vec.size(); x++) {
fsa_vec[x]->ProcessPacket(info);
}
// Junk unknown, pure noise, and corrupt packets
if (info->type == packet_noise || info->corrupt == 1) {
num_dropped++;
num_noise++;
return;
} else if (info->type == packet_unknown) {
// UNknown frames get dropped and counted
num_dropped++;
return;
} else if (info->type == packet_phy) {
// We unceremoniously junk phy layer packets for now too but
// don't count them as dropped
return;
} else if (info->type == packet_data && info->subtype != 0) {
// Drop data frames of non-data types since they don't get
// handled in a useful way
return;
}
net = MatchNetwork(info);
// Find out if we have this network -- Every network that actually
// gets added has a bssid, so we'll use that to search. We've filtered
// everything else out by this point so we're safe to just work off bssid
if (net == NULL) {
/* If an attacker use a tool such a Fake AP to create zillions
* of fake networks, it can DoS Kismet and/or the underlying system.
* Basically, we will exhaust the system memory.
* Let's limit the number of network to avoid that...
* There is two ways to recover : restart Kismet, or set logexpiry.
* Jean II */
if (limit_nets > 0)
if(network_list.size() > (unsigned int) limit_nets) {
/* We should trigger an alert and log this condition */
/* Don't create this network. */
return;
}
// Make a network for them
net = new wireless_network;
if (bssid_ip_map.find(info->bssid_mac) != bssid_ip_map.end()) {
memcpy(&net->ipdata, &bssid_ip_map[info->bssid_mac], sizeof(net_ip_data));
}
if (info->type == packet_management &&
(info->subtype == packet_sub_beacon ||
info->subtype == packet_sub_probe_req ||
info->subtype == packet_sub_probe_resp ||
info->subtype == packet_sub_authentication)) {
if (IsBlank(info->ssid)) {
if (bssid_cloak_map.find(info->bssid_mac) != bssid_cloak_map.end()) {
net->ssid = bssid_cloak_map[info->bssid_mac];
// If it's a beacon and empty then we're cloaked and we found our
// ssid so fill it in
if (info->type == packet_management &&
info->subtype == packet_sub_beacon) {
net->cloaked = 1;
} else {
net->cloaked = 0;
}
} else {
net->ssid = NOSSID;
net->cloaked = 0;
}
} else {
net->ssid = info->ssid;
net->cloaked = 0;
bssid_cloak_map[info->bssid_mac] = info->ssid;
}
} else {
net->ssid = NOSSID;
net->cloaked = 0;
}
net->bssid = info->bssid_mac;
net->channel = info->channel;
net->crypt_set |= (int) info->crypt_set;
if (info->type == packet_management && info->subtype == packet_sub_probe_req) {
net->type = network_probe;
} else if (info->distrib == adhoc_distribution) {
net->type = network_adhoc;
} else {
net->type = network_ap;
}
net->beacon = info->beacon;
//net->bssid = Mac2String(info->bssid_mac, ':');
// Put us in the master list
network_list.push_back(net);
net->listed = 1;
net->first_time = time(0);
net->maxrate = info->maxrate;
net->bss_timestamp = info->timestamp;
if (strlen(info->beacon_info) != 0)
net->beacon_info = info->beacon_info;
newnet = 1;
if (net->type == network_probe) {
snprintf(status, STATUS_MAX, "Found new probed network \"%s\" bssid %s",
net->ssid.c_str(), net->bssid.Mac2String().c_str());
KisLocalStatus(status);
} else {
// printf("debug - pack %d\n", num_packets);
snprintf(status, STATUS_MAX, "Found new network \"%s\" bssid %s Crypt %c Ch "
"%d @ %.2f mbit",
net->ssid.c_str(), net->bssid.Mac2String().c_str(),
net->crypt_set ? 'Y' : 'N',
net->channel, net->maxrate);
KisLocalStatus(status);
}
if (info->gps_fix >= 2) {
net->gps_fixed = info->gps_fix;
net->min_lat = net->max_lat = info->gps_lat;
net->min_lon = net->max_lon = info->gps_lon;
net->min_alt = net->max_alt = info->gps_alt;
net->min_spd = net->max_spd = info->gps_spd;
net->aggregate_lat = info->gps_lat;
net->aggregate_lon = info->gps_lon;
net->aggregate_alt = info->gps_alt;
net->aggregate_points = 1;
}
// Find out what we can from what we know now...
if (net->type != network_adhoc && net->type != network_probe) {
net->manuf_ref = MatchBestManuf(&ap_manuf_map, net->bssid, net->ssid,
net->channel, net->crypt_set,
net->cloaked, &net->manuf_score);
if (net->manuf_score == manuf_max_score)
memcpy(&net->ipdata, &net->manuf_ref->ipdata, sizeof(net_ip_data));
} else {
net->manuf_ref = MatchBestManuf(&client_manuf_map, net->bssid,
net->ssid, net->channel,
net->crypt_set, net->cloaked,
&net->manuf_score);
}
num_networks++;
// And add us to the map
bssid_map[net->bssid] = net;
} else {
if (net->listed == 0) {
network_list.push_back(net);
net->listed = 1;
}
}
if (info->crypt_set)
net->crypt_set |= (int) info->crypt_set;
net->last_time = time(0);
// update the sequence for the owner of the bssid
if (info->source_mac == net->bssid)
net->last_sequence = info->sequence_number;
if (info->signal != 0)
net->signal = info->signal;
// Record best signal level so far for this network
if (info->signal != 0 &&
(info->signal > net->best_signal || net->best_signal == 0)) {
net->best_signal = info->signal;
if (info->gps_fix >= 2) {
net->best_lat = info->gps_lat;
net->best_lon = info->gps_lon;
net->best_alt = info->gps_alt;
}
}
// Record best and worst signal levels ever seen on any network
if (info->signal != 0) {
if (info->signal > best_signal || best_signal == 0)
best_signal = info->signal;
if (info->signal < worst_signal)
worst_signal = info->signal;
}
// Fake RSSI against a floating ceiling. FIXME - get RSSI from driver.
if (info->signal < 0) {
// dbM signal level
double strength =
(double)(info->signal - worst_signal) /
(double)(best_signal - worst_signal);
net->rssi = (int)(strength * 100);
net->rssi_max = 100;
}
else {
// absolute, driver-specific signal level
net->rssi = info->signal;
net->rssi_max = best_signal == 0 ? 100 : best_signal;
}
if (info->noise != 0)
net->noise = info->noise;
// Record the "best" (aka 'worst') noise level
if (info->noise != 0 &&
(info->noise < net->best_noise || net->best_noise == 0))
net->best_noise = info->noise;
if (info->gps_fix >= 2) {
// Don't aggregate slow-moving packets to prevent average "pulling"..
if (info->gps_spd <= 0.3) {
net->aggregate_lat += info->gps_lat;
net->aggregate_lon += info->gps_lon;
net->aggregate_alt += info->gps_alt;
net->aggregate_points += 1;
}
net->gps_fixed = info->gps_fix;
if (info->gps_lat < net->min_lat || net->min_lat == -90)
net->min_lat = info->gps_lat;
if (info->gps_lat > net->max_lat || net->max_lat == 90)
net->max_lat = info->gps_lat;
if (info->gps_lon < net->min_lon || net->min_lon == -180)
net->min_lon = info->gps_lon;
if (info->gps_lon > net->max_lon || net->max_lon == 180)
net->max_lon = info->gps_lon;
if (info->gps_alt < net->min_alt || net->min_alt == 0)
net->min_alt = info->gps_alt;
if (info->gps_alt > net->max_alt || net->max_alt == 0)
net->max_alt = info->gps_alt;
if (info->gps_spd < net->min_spd || net->min_spd == 0)
net->min_spd = info->gps_spd;
if (info->gps_spd > net->max_spd || net->max_spd == 0)
net->max_spd = info->gps_spd;
} else {
net->gps_fixed = 0;
}
// Handle the IV sets. 4-byte compare IV is fine
// Only do this if we track IVs, which costs a lot of memory
if (info->encrypted && track_ivs) {
if (net->iv_map == NULL)
net->iv_map = new map<uint32_t, int>;
map<uint32_t, int>::iterator ivitr = net->iv_map->find(info->ivset);
if (ivitr != net->iv_map->end()) {
ivitr->second++;
net->dupeiv_packets++;
} else {
(*net->iv_map)[info->ivset] = 1;
}
}
if (info->timestamp != 0)
net->bss_timestamp = info->timestamp;
// Assign the carrier types in this network. There will likely be only one, but you
// never know...
net->carrier_set |= (1 << (int) info->carrier);
// Assign the encoding types in this network, there can quite likely be more than
// one...
net->encoding_set |= (1 << (int) info->encoding);
// Assign the highest seen datarate
if (info->datarate > net->maxseenrate)
net->maxseenrate = info->datarate;
if (info->type == packet_management && info->subtype == packet_sub_beacon &&
!strncmp(info->ssid, "AirJack", SSID_SIZE)) {
if (alertracker->PotentialAlert(arefs[AIRJACKSSID_AREF])) {
snprintf(status, STATUS_MAX, "Beacon for SSID 'AirJack' from %s",
info->source_mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[AIRJACKSSID_AREF], info->source_mac,
info->source_mac, 0, 0, info->channel, status);
}
}
// MSF opcode-in-MAC
if (info->type == packet_management &&
(info->subtype == packet_sub_beacon ||
info->subtype == packet_sub_probe_resp) &&
info->source_mac == msfopcode_mac) {
if (alertracker->PotentialAlert(arefs[MSFBCOMSSID_AREF])) {
snprintf(status, STATUS_MAX,
"MSF-style poisoned exploit packet for Broadcom drivers");
alertracker->RaiseAlert(arefs[MSFBCOMSSID_AREF], info->source_mac,
info->source_mac, 0, 0, info->channel, status);
}
}
if (info->type == packet_management &&
(info->subtype == packet_sub_disassociation ||
info->subtype == packet_sub_deauthentication) &&
info->dest_mac == broadcast_mac) {
if (alertracker->PotentialAlert(arefs[BCASTDISCON_AREF]) > 0) {
snprintf(status, STATUS_MAX, "Broadcast %s on %s",
info->subtype == packet_sub_disassociation ?
"disassociation" : "deauthentication",
net->bssid.Mac2String().c_str());
alertracker->RaiseAlert(arefs[BCASTDISCON_AREF], net->bssid,
0, 0, 0, info->channel, status);
}
}
if (info->type == packet_management &&
(info->subtype == packet_sub_disassociation ||
info->subtype == packet_sub_deauthentication)) {
if ((info->reason_code >= 25 && info->reason_code <= 31) ||
(info->reason_code > 45)) {
if (info->subtype == packet_sub_disassociation &&
alertracker->PotentialAlert(arefs[DISCONCODE_AREF]) > 0) {
snprintf(status, STATUS_MAX, "Unknown disassociation reason "
"code 0x%X from %s", info->reason_code,
info->source_mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[DISCONCODE_AREF], info->bssid_mac,
info->source_mac, info->dest_mac, 0,
info->channel, status);
} else if (info->subtype == packet_sub_deauthentication &&
alertracker->PotentialAlert(arefs[DEAUTHCODE_AREF]) > 0) {
snprintf(status, STATUS_MAX, "Unknown deauthentication reason "
"code 0x%X from %s", info->reason_code,
info->source_mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[DEAUTHCODE_AREF], info->bssid_mac,
info->source_mac, info->dest_mac, 0,
info->channel, status);
}
}
}
if ((info->type == packet_management) || (info->proto.type == proto_iapp)) {
if (info->type == packet_management)
net->llc_packets++;
// If it's a probe request shortcut to handling it like a client once we've
// established what network it belongs to
if (info->subtype == packet_sub_probe_req && net->type == network_probe) {
if (net->ssid != info->ssid) {
if (IsBlank(info->ssid))
net->ssid = NOSSID;
else
net->ssid = info->ssid;
}
if (probe_map.find(info->source_mac) != probe_map.end() && track_probenets) {
ProcessDataPacket(packet, info, net, bssid_wep_map, identity);
if (newnet == 1)
KisLocalNewnet(net);
return;
}
}
if (info->subtype == packet_sub_beacon && strlen(info->beacon_info) != 0 &&
IsBlank(net->beacon_info.c_str())) {
net->beacon_info = info->beacon_info;
}
if (info->subtype == packet_sub_deauthentication ||
info->subtype == packet_sub_disassociation) {
net->client_disconnects++;
if (net->client_disconnects > 10) {
if (alertracker->PotentialAlert(arefs[DEAUTHFLOOD_AREF]) > 0) {
snprintf(status, STATUS_MAX, "Deauthenticate/Disassociate flood on %s",
net->bssid.Mac2String().c_str());
alertracker->RaiseAlert(arefs[DEAUTHFLOOD_AREF], net->bssid,
0, 0, 0, info->channel, status);
}
}
}
// Update the ssid record if we got a beacon for a data network
if (info->subtype == packet_sub_beacon) {
// If we have a beacon for an established AP network and it's not the
// right channel, raise an alert.
if (net->type == network_ap && info->channel != net->channel &&
net->channel != 0 && info->channel != 0) {
if (alertracker->PotentialAlert(arefs[CHANCHANGE_AREF]) > 0) {
snprintf(status, STATUS_MAX, "Beacon on %s (%s) for channel %d, network previously detected on channel %d",
net->bssid.Mac2String().c_str(), net->ssid.c_str(),
info->channel, net->channel);
alertracker->RaiseAlert(arefs[CHANCHANGE_AREF], net->bssid,
0, 0, 0, info->channel, status);
}
}
// If we're updating the network record, update the manufacturer info -
// if we just "became" an AP or if we've changed channel, we may have
// changed state as well
if (net->channel != info->channel || net->type != network_ap ||
(net->ssid != info->ssid && !IsBlank(info->ssid))) {
net->manuf_ref = MatchBestManuf(&ap_manuf_map, net->bssid, info->ssid,
info->channel, net->crypt_set,
net->cloaked, &net->manuf_score);
// Update our IP range info too if we're a default
if (net->manuf_score == manuf_max_score && net->ipdata.atype == address_none)
memcpy(&net->ipdata, &net->manuf_ref->ipdata, sizeof(net_ip_data));
}
if (net->ssid != info->ssid && !IsBlank(info->ssid)) {
net->ssid = info->ssid;
bssid_cloak_map[net->bssid] = info->ssid;
snprintf(status, STATUS_MAX, "Found SSID \"%s\" for network BSSID %s",
net->ssid.c_str(), net->bssid.Mac2String().c_str());
KisLocalStatus(status);
}
net->channel = info->channel;
if (info->crypt_set & crypt_wep)
net->crypt_set |= (int) crypt_wep;
if (info->distrib != adhoc_distribution)
net->type = network_ap;
}
// If it's a probe response with no SSID, something funny is happening,
// raise an alert
if (info->subtype == packet_sub_probe_resp && info->ssid_len == 0) {
if (alertracker->PotentialAlert(arefs[NULLPROBERESP_AREF]) > 0) {
snprintf(status, STATUS_MAX, "Probe response with 0-length SSID "
"detected from %s", info->source_mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[NULLPROBERESP_AREF], info->bssid_mac, info->source_mac,
info->dest_mac, 0, info->channel, status);
}
}
// If this is a probe response and the ssid we have is blank, update it.
// With "closed" networks, this is our chance to see the real ssid.
// (Thanks to Jason Luther <jason@ixid.net> for this "closed network" detection)
if ((info->subtype == packet_sub_probe_resp ||
info->subtype == packet_sub_reassociation_resp ||
info->proto.type == proto_iapp) && !IsBlank(info->ssid)) {
if (net->ssid == NOSSID) {
net->cloaked = 1;
net->ssid = info->ssid;
net->channel = info->channel;
if (info->crypt_set & crypt_wep)
net->crypt_set |= (int) crypt_wep;
net->manuf_ref = MatchBestManuf(&ap_manuf_map, net->bssid, net->ssid,
net->channel, net->crypt_set,
net->cloaked, &net->manuf_score);
// Update our IP range info too if we're a default
if (net->manuf_score == manuf_max_score &&
net->ipdata.atype == address_none)
memcpy(&net->ipdata, &net->manuf_ref->ipdata, sizeof(net_ip_data));
bssid_cloak_map[net->bssid] = info->ssid;
snprintf(status, STATUS_MAX, "Found SSID \"%s\" for cloaked "
"network BSSID %s", net->ssid.c_str(),
net->bssid.Mac2String().c_str());
KisLocalStatus(status);
} else if (info->ssid != bssid_cloak_map[net->bssid]) {
bssid_cloak_map[net->bssid] = info->ssid;
net->ssid = info->ssid;
if (info->crypt_set & crypt_wep)
net->crypt_set |= (int) crypt_wep;
net->manuf_ref = MatchBestManuf(&ap_manuf_map, net->bssid, net->ssid,
net->channel, net->crypt_set,
net->cloaked, &net->manuf_score);
// Update our IP range info too if we're a default
if (net->manuf_score == manuf_max_score &&
net->ipdata.atype == address_none)
memcpy(&net->ipdata, &net->manuf_ref->ipdata, sizeof(net_ip_data));
}
// If we have a probe request network, absorb it into the main network
//string resp_mac = Mac2String(info->dest_mac, ':');
//probe_map[resp_mac] = net->bssid;
if (track_probenets) {
probe_map[info->dest_mac] = net->bssid;
// If we have any networks that match the response already in existance,
// we should add them to the main network and kill them off
if (bssid_map.find(info->dest_mac) != bssid_map.end()) {
wireless_network *pnet = bssid_map[info->dest_mac];
if (pnet->type == network_probe) {
net->llc_packets += pnet->llc_packets;
net->data_packets += pnet->data_packets;
net->crypt_packets += pnet->crypt_packets;
net->interesting_packets += pnet->interesting_packets;
pnet->type = network_remove;
pnet->last_time = time(0);
snprintf(status, STATUS_MAX, "Associated probe network \"%s\" "
"with \"%s\" via probe response.",
pnet->bssid.Mac2String().c_str(),
net->bssid.Mac2String().c_str());
KisLocalStatus(status);
CreateClient(info, net, 0);
num_networks--;
}
}
}
}
if (net->type != network_ap && info->distrib == adhoc_distribution) {
net->type = network_adhoc;
}
}
if (info->type != packet_management) {
// Process data packets
// We feed them into the data packet processor along with the network
// they belong to, so that clients can be tracked.
ProcessDataPacket(packet, info, net, bssid_wep_map, identity);
} // data packet
if (newnet == 1) {
KisLocalNewnet(net);
// Put it in itself as a client... I don't like defining the client
// all the way down here, but it does need to have the network in the
// client records first, so.... such it goes.
if (net->type == network_probe)
CreateClient(info, net, 0);
}
return;
}
void Packetracker::ProcessDataPacket(kis_packet *packet, packet_info *info,
wireless_network *net,
macmap<wep_key_info *> *bssid_wep_map,
unsigned char *identity) {
wireless_client *client = NULL;
wireless_client *sendclient = NULL;
char status[STATUS_MAX];
// Blow right out of this if we're funky data non-data frames
if (info->type == packet_data && info->subtype != packet_sub_data)
return;
// Try to match up orphan probe networks
wireless_network *pnet = NULL;
if (info->type == packet_management && info->subtype == packet_sub_probe_req) {
if (probe_map.find(info->source_mac) != probe_map.end()) {
info->dest_mac = probe_map[info->source_mac];
info->bssid_mac = info->dest_mac;
} else {
return;
}
}
if (track_probenets) {
if (bssid_map.find(info->dest_mac) != bssid_map.end()) {
pnet = bssid_map[info->dest_mac];
probe_map[info->source_mac] = pnet->bssid;
} else if (bssid_map.find(info->source_mac) != bssid_map.end()) {
pnet = bssid_map[info->source_mac];
probe_map[info->dest_mac] = pnet->bssid;
}
if (pnet != NULL) {
if (pnet->type == network_probe) {
net->llc_packets += pnet->llc_packets;
net->data_packets += pnet->data_packets;
net->crypt_packets += pnet->crypt_packets;
net->interesting_packets += pnet->interesting_packets;
pnet->type = network_remove;
pnet->last_time = time(0);
snprintf(status, STATUS_MAX, "Associated probe network \"%s\" with "
"\"%s\" via data.", pnet->bssid.Mac2String().c_str(),
net->bssid.Mac2String().c_str());
KisLocalStatus(status);
CreateClient(info, net, 0);
num_networks--;
}
}
}
// Find the client or make one
if (net->client_map.find(info->source_mac) == net->client_map.end()) {
client = CreateClient(info, net, 0);
} else {
client = net->client_map[info->source_mac];
if ((client->type == client_fromds && info->distrib == to_distribution) ||
(client->type == client_tods && info->distrib == from_distribution)) {
client->type = client_established;
}
}
if (net->client_map.find(info->dest_mac) == net->client_map.end()) {
sendclient = CreateClient(info, net, 1);
}
if (info->gps_fix >= 2) {
if (info->gps_spd <= 0.3) {
client->aggregate_lat += info->gps_lat;
client->aggregate_lon += info->gps_lon;
client->aggregate_alt += info->gps_alt;
client->aggregate_points += 1;
}
client->gps_fixed = info->gps_fix;
if (info->gps_lat < client->min_lat || client->min_lat == -90)
client->min_lat = info->gps_lat;
if (info->gps_lat > client->max_lat || client->max_lat == 90)
client->max_lat = info->gps_lat;
if (info->gps_lon < client->min_lon || client->min_lon == -180)
client->min_lon = info->gps_lon;
if (info->gps_lon > client->max_lon == 180)
client->max_lon = info->gps_lon;
if (info->gps_alt < client->min_alt || client->min_alt == 0)
client->min_alt = info->gps_alt;
if (info->gps_alt > client->max_alt || client->min_alt == 0)
client->max_alt = info->gps_alt;
if (info->gps_spd < client->min_spd || client->min_spd == 0)
client->min_spd = info->gps_spd;
if (info->gps_spd > client->max_spd || client->max_spd == 0)
client->max_spd = info->gps_spd;
} else {
client->gps_fixed = 0;
}
if (info->signal >= 0) {
client->signal = info->signal;
if (info->signal > client->best_signal || client->best_signal == 0) {
client->best_signal = info->signal;
if (info->gps_fix >= 2) {
client->best_lat = info->gps_lat;
client->best_lon = info->gps_lon;
client->best_alt = info->gps_alt;
}
}
net->noise = info->noise;
if ((info->noise < net->best_noise && info->noise != 0) ||
net->best_noise == 0)
net->best_noise = info->noise;
}
if (info->type == packet_management &&
(info->subtype == packet_sub_probe_req ||
info->subtype == packet_sub_association_req)) {
if (info->maxrate > client->maxrate)
client->maxrate = info->maxrate;
}
client->last_time = time(0);
if (sendclient != NULL)
sendclient->last_time = client->last_time;
client->last_sequence = info->sequence_number;
// Add data to the owning network and to the client
net->datasize += info->datasize;
client->datasize += info->datasize;
// If it isn't known to be encrypted already and we want to do classifier-based
// encryption, we should shunt it back in
if (info->encrypted == 0 && net->crypt_set != 0 && netcryptdetect != 0) {
// Run it through the same packetcrypto handler
ProcessPacketCrypto(packet, info, bssid_wep_map, identity);
// Extract the tcp layer info if we just decoded it
if (info->encrypted == 0 || info->decoded == 1) {
GetProtoInfo(packet, info);
}
}
// We modify our client and our network concurrently to save on CPU cycles.
// Easier to update them in sync than it is to process the map as a list.
if (info->encrypted) {
net->crypt_packets++;
client->crypt_packets++;
num_crypt++;
}
// Flag the client and network as decrypted if we decrypted the packet
if (info->decoded) {
client->decrypted = 1;
net->decrypted = 1;
}
if (info->interesting) {
net->interesting_packets++;
client->interesting_packets++;
num_interesting++;
}
if (info->type != packet_management) {
net->data_packets++;
client->data_packets++;
}
// Assign the encoding types in this network, there can quite likely be more than
// one...
client->encoding_set |= (1 << (int) info->encoding);
// Assign the encryption types from the protocol field
if (info->proto.type == proto_leap) {
client->crypt_set |= ((int) crypt_leap);
net->crypt_set |= ((int) crypt_leap);
} else if (info->proto.type == proto_ttls) {
client->crypt_set |= ((int) crypt_ttls);
net->crypt_set |= ((int) crypt_ttls);
} else if (info->proto.type == proto_tls) {
client->crypt_set |= ((int) crypt_tls);
net->crypt_set |= ((int) crypt_tls);
} else if (info->proto.type == proto_peap) {
client->crypt_set |= ((int) crypt_peap);
net->crypt_set |= ((int) crypt_peap);
} else if (info->proto.type == proto_isakmp) {
client->crypt_set |= ((int) crypt_isakmp & (int) crypt_layer3);
net->crypt_set |= ((int) crypt_isakmp & (int) crypt_layer3);
} else if (info->proto.type == proto_pptp) {
client->crypt_set |= ((int) crypt_pptp & (int) crypt_layer3);
net->crypt_set |= ((int) crypt_pptp);
}
if (info->datarate > client->maxseenrate)
client->maxseenrate = info->datarate;
// Record a cisco device
if (info->proto.type == proto_cdp) {
if (net->cisco_equip == NULL)
net->cisco_equip = new vector<cdp_packet>;
int matched = 0;
for (unsigned int x = 0; x < net->cisco_equip->size(); x++) {
if ((*net->cisco_equip)[x].dev_id == info->proto.cdp.dev_id) {
(*net->cisco_equip)[x] = info->proto.cdp;
matched = 1;
break;
}
}
if (matched == 0)
net->cisco_equip->push_back(info->proto.cdp);
num_cisco++;
}
unsigned int ipdata_dirty = 0;
char *means = NULL;
if (info->proto.type == proto_dhcp_server &&
(client->ipdata.atype < address_dhcp ||
client->ipdata.load_from_store == 1)) {
// DHCP is canonical data for the network, it's pretty safe to trust it
// If we have a DHCP packet and we didn't before, turn it into a full record
// in the client and flag us dirty.
client->ipdata.atype = address_dhcp;
// We only care about the source in the actual client record, but we need to
// record the rest so that we can form a network record
memcpy(client->ipdata.ip, info->proto.misc_ip, 4);
means = "DHCP";
ipdata_dirty = 1;
} else if (info->proto.type == proto_arp && (client->ipdata.atype < address_arp ||
client->ipdata.load_from_store == 1)
&& info->proto.source_ip[0] != 0x00) {
// Arp data is pretty canonical too, unless someone is playing silly buggers
// with arp spoofing foreign addresses.
client->ipdata.atype = address_arp;
memcpy(client->ipdata.ip, info->proto.source_ip, 4);
means = "ARP";
ipdata_dirty = 1;
} else if ((info->proto.type == proto_udp) &&
#if 0
||
info->proto.type == proto_netbios ||
info->proto.type == proto_iapp) &&
#endif
(client->ipdata.atype < address_udp ||
client->ipdata.load_from_store == 1) &&
info->proto.source_ip[0] != 0x00 &&
info->source_mac != net->bssid) {
// We only process UDP if its from a client, not the AP to prevent routers
// from getting us with foreign addresses
client->ipdata.atype = address_udp;
memcpy(client->ipdata.ip, info->proto.source_ip, 4);
means = "UDP";
ipdata_dirty = 1;
} else if ((info->proto.type == proto_misc_tcp) &&
#if 0
||
info->proto.type == proto_netbios_tcp) &&
#endif
(client->ipdata.atype < address_tcp ||
client->ipdata.load_from_store == 1) &&
info->proto.source_ip[0] != 0x00 &&
info->source_mac != net->bssid) {
// We only process TCP if its from a client on our network, not the AP, to
// prevent AP/Routers from getting us with foreign addresses.
// printf("debug - got IP %d.%d.%d.%d from s-%s b-%s d-%s net %s pack %d\n", client->ipdata.ip[0], client->ipdata.ip[1], client->ipdata.ip[2], client->ipdata.ip[3], info->source_mac.Mac2String().c_str(), info->bssid_mac.Mac2String().c_str(), info->dest_mac.Mac2String().c_str(), net->bssid.Mac2String().c_str(), num_packets);
client->ipdata.atype = address_tcp;
memcpy(client->ipdata.ip, info->proto.source_ip, 4);
means = "TCP";
ipdata_dirty = 1;
}
// Don't get the IP ranges if the network is encrypted
if (ipdata_dirty && net->crypt_set == 0) {
// printf("packet %d t %d s %d\n", num_packets, info->type, info->subtype);
snprintf(status, STATUS_MAX, "Found IP %d.%d.%d.%d for %s::%s via %s",
client->ipdata.ip[0], client->ipdata.ip[1],
client->ipdata.ip[2], client->ipdata.ip[3],
net->ssid.c_str(), info->source_mac.Mac2String().c_str(), means);
KisLocalStatus(status);
client->ipdata.load_from_store = 0;
UpdateIpdata(net);
}
if (info->proto.type == proto_turbocell) {
// Handle lucent outdoor routers
net->cloaked = 1;
if (info->turbocell_mode != turbocell_unknown) {
net->turbocell_mode = info->turbocell_mode;
net->turbocell_sat = info->turbocell_sat;
net->turbocell_nid = info->turbocell_nid;
if (!IsBlank(info->ssid))
net->turbocell_name = info->ssid;
}
char turbossid[32];
snprintf(turbossid, 32, "%d %s", net->turbocell_nid,
(net->turbocell_name.length() > 0) ? net->turbocell_name.c_str() : "Unknown");
net->ssid = turbossid;
net->type = network_turbocell;
} else if (info->proto.type == proto_netstumbler) {
// Handle netstumbler packets
if (alertracker->PotentialAlert(arefs[NETSTUMBLER_AREF]) > 0) {
char *nsversion;
switch (info->proto.prototype_extra) {
case 22:
nsversion = "3.22";
break;
case 23:
nsversion = "3.23";
break;
case 30:
nsversion = "3.30";
break;
default:
nsversion = "unknown";
break;
}
snprintf(status, STATUS_MAX, "NetStumbler (%s) probe detected from %s",
nsversion, client->mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[NETSTUMBLER_AREF], 0, client->mac,
0, 0, info->channel, status);
}
} else if (info->proto.type == proto_leap || info->proto.type == proto_peap ||
info->proto.type == proto_ttls || info->proto.type == proto_tls) {
// Handle EAP packets
char *eapcode;
char *eaptype;
switch (info->proto.prototype_extra) {
case EAP_CODE_REQUEST:
eapcode = "Authentication Request";
break;
case EAP_CODE_RESPONSE:
eapcode = "Authentication Response";
break;
case EAP_CODE_SUCCESS:
eapcode = "Authentication Success";
break;
case EAP_CODE_FAILURE:
eapcode = "Authentication Failure";
break;
default: // Should never happen
eapcode = "unknown";
break;
}
switch (info->proto.type) {
case proto_leap:
eaptype = "LEAP";
break;
case proto_ttls:
eaptype = "TTLS";
break;
case proto_tls:
eaptype = "TLS";
break;
case proto_peap:
eaptype = "PEAP";
break;
default: // Should never happen
eaptype = "UNKNOWN";
break;
}
snprintf(status, STATUS_MAX, "%s Traffic - %s - from %s", eaptype, eapcode,
info->source_mac.Mac2String().c_str());
KisLocalStatus(status);
/* Prints too many status entries - annoying
} else if (info->proto.type == proto_pptp) {
// Handle PPTP traffic
snprintf(status, STATUS_MAX, "PPTP Traffic from %s",
info->source_mac.Mac2String().c_str());
KisLocalStatus(status);
*/
} else if (info->proto.type == proto_isakmp) {
// Handle ISAKMP traffic
char *isakmpcode;
switch (info->proto.prototype_extra) {
case ISAKMP_EXCH_NONE:
isakmpcode = "NONE";
break;
case ISAKMP_EXCH_BASE:
isakmpcode = "Base";
break;
case ISAKMP_EXCH_IDPROT:
isakmpcode = "Identity Protection (Main Mode)";
break;
case ISAKMP_EXCH_AUTHONLY:
isakmpcode = "Authentication Only";
break;
case ISAKMP_EXCH_AGGRESS:
isakmpcode = "Aggressive";
break;
case ISAKMP_EXCH_INFORM:
isakmpcode = "Informational";
break;
case ISAKMP_EXCH_TRANS:
isakmpcode = "Transaction (Config Mode)";
break;
case ISAKMP_EXCH_QUICK:
isakmpcode = "Quick Mode";
break;
case ISAKMP_EXCH_NEWGRP:
isakmpcode = "New Group Mode";
break;
default:
if (info->proto.prototype_extra < 32) {
isakmpcode = "Reserved for Future Use";
break;
}
if (info->proto.prototype_extra < 240) {
isakmpcode = "DOI Specific Use";
break;
}
isakmpcode = "Private Use";
break;
}
snprintf(status, STATUS_MAX, "ISAKMP Traffic, Exchange type: %s - from %s", isakmpcode,
info->source_mac.Mac2String().c_str());
KisLocalStatus(status);
} else if (info->proto.type == proto_lucenttest) {
// Handle lucent test packets
if (alertracker->PotentialAlert(arefs[LUCENTTEST_AREF]) > 0) {
snprintf(status, STATUS_MAX, "Lucent link test detected from %s",
client->mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[LUCENTTEST_AREF], 0, client->mac,
0, 0, info->channel, status);
}
} else if (info->proto.type == proto_wellenreiter) {
// Handle wellenreiter packets
if (alertracker->PotentialAlert(arefs[WELLENREITER_AREF]) > 0) {
snprintf(status, STATUS_MAX, "Wellenreiter probe detected from %s",
client->mac.Mac2String().c_str());
alertracker->RaiseAlert(arefs[WELLENREITER_AREF], 0, client->mac,
0, 0, info->channel, status);
}
}
return;
}
void Packetracker::UpdateIpdata(wireless_network *net) {
memset(&net->ipdata, 0, sizeof(net_ip_data));
wireless_client *client = NULL;
if (net->client_map.size() == 0)
return;
// Zero out our range knowledge. This will get grafted in from the client
// aggregates. Keep us if we're a factory config, we get handled specially.
if (net->ipdata.atype != address_factory)
memset(&net->ipdata, 0, sizeof(net->ipdata));
for (unsigned int y = 0; y < net->client_vec.size(); y++) {
client = net->client_vec[y];
// We treat all non-dhcp client addresses equally. We compare what we have
// already (net->ipdata.range_ip) to the client source address to see what the
// difference is, and form the new address range. If the new address range
// takes precedence, we set the network address type appropriately.
// We favor the IP of the previous clients, for no good reason.
uint8_t new_range[4];
memset(new_range, 0, 4);
if (client->ipdata.ip[0] != 0x00) {
/*
if (net->ipdata.atype == address_factory) {
memset(&net->ipdata, 0, sizeof(net_ip_data));
}
*/
int oct;
for (oct = 0; oct < 4; oct++) {
if (net->ipdata.range_ip[oct] != client->ipdata.ip[oct] &&
net->ipdata.range_ip[oct] != 0x00) {
break;
}
new_range[oct] = client->ipdata.ip[oct];
}
if ((oct < net->ipdata.octets || net->ipdata.octets == 0) &&
client->ipdata.atype > net->ipdata.atype) {
net->ipdata.octets = oct;
net->ipdata.atype = client->ipdata.atype;
memcpy(net->ipdata.range_ip, new_range, 4);
bssid_ip_map[net->bssid] = net->ipdata;
}
}
}
}
int Packetracker::ExpireNetworks(int expiry) {
time_t current_time = time(0);
time_t oldest_time = current_time - expiry;
/* We may be shrinking the list, so start from the end to avoid
* messing with our iteration... And we need a signed int to
* avoid the boundary test to be useless... Jean II */
unsigned int net_len = network_list.size();
for (signed int i = net_len - 1; i >= 0; i--) {
wireless_network *net = network_list[i];
/* Time may wrap around, especially that embedded typically boot
* at time(0) = 0;, don't have CMOS clock or NTP.
* Let the compiler optimise the condition. Jean II */
bool expired;
if (current_time > oldest_time)
expired = net->last_time < oldest_time;
else
expired = ((net->last_time < oldest_time)
&& (net->last_time > current_time));
/* If expired, remove it. We don't use RemoveNetwork to avoid
* another list interation. Also, RemoveNetwork does not seem
* be do complete cleanup ? Jean II */
if(expired) {
// Remove data in secondary hashes
map<mac_addr, net_ip_data>::iterator bimi = bssid_ip_map.find(net->bssid);
if (bimi != bssid_ip_map.end())
bssid_ip_map.erase(bimi);
map<mac_addr, string>::iterator bcmi = bssid_cloak_map.find(net->bssid);
if (bcmi != bssid_cloak_map.end())
bssid_cloak_map.erase(bcmi);
/* Should do something about probe_map ? */
// Remove data about clients
for (unsigned int y = 0; y < net->client_vec.size(); y++)
delete net->client_vec[y];
// Remove data about CDP devices
if (net->cisco_equip != NULL)
delete net->cisco_equip;
// Remove us from the main hash
map<mac_addr, wireless_network *>::iterator bmi = bssid_map.find(net->bssid);
if (bmi != bssid_map.end())
bssid_map.erase(bmi);
// Remove us from the vector the fast and efficient way
network_list.erase(network_list.begin() + i);
/* Final cleanup */
delete net;
}
}
return 1;
}
int Packetracker::WriteNetworks(string in_fname) {
string fname_temp = in_fname + ".temp";
FILE *netfile;
/* Test if we can open the file, using read+write mode (r+).
* Using write mode (w+) would truncate the file, which means that during
* update the log would be empty.
* Using append mode (a+) would force to seek to the end of file, which
* is slower. Jean II */
if ((netfile = fopen(in_fname.c_str(), "r+")) == NULL) {
snprintf(errstr, 1024, "Could not open %s for writing: %s", in_fname.c_str(),
strerror(errno));
return -1;
}
fclose(netfile);
if (unlink(fname_temp.c_str()) == -1) {
if (errno != ENOENT) {
snprintf(errstr, 1024, "Could not unlink temp file %s: %s",
fname_temp.c_str(), strerror(errno));
return -1;
}
}
if ((netfile = fopen(fname_temp.c_str(), "wx")) == NULL) {
snprintf(errstr, 1024, "Could not open %s for writing even though "
"we could unlink it: %s", fname_temp.c_str(), strerror(errno));
return -1;
}
int netnum = 1;
if (network_list.size() > 0)
stable_sort(network_list.begin(), network_list.end(), SortFirstTimeLT());
for (unsigned int i = 0; i < network_list.size(); i++) {
wireless_network *net = network_list[i];
if (filter_export) {
macmap<int>::iterator fitr = filter_export_bssid->find(net->bssid);
// In the list and we've got inverted filtering - kill it
if (fitr != filter_export_bssid->end() &&
*filter_export_bssid_invert == 1)
continue;
// Not in the list and we've got normal filtering - kill it
if (fitr == filter_export_bssid->end() &&
*filter_export_bssid_invert == 0)
continue;
}
char lt[25];
char ft[25];
snprintf(lt, 25, "%s", ctime(&net->last_time));
snprintf(ft, 25, "%s", ctime(&net->first_time));
char type[15];
if (net->type == network_ap)
snprintf(type, 15, "infrastructure");
else if (net->type == network_adhoc)
snprintf(type, 15, "ad-hoc");
else if (net->type == network_probe)
snprintf(type, 15, "probe");
else if (net->type == network_data)
snprintf(type, 15, "data");
else if (net->type == network_turbocell)
snprintf(type, 15, "turbocell");
else
snprintf(type, 15, "unknown");
char carrier[15];
if (net->carrier_set & (1 << (int) carrier_80211b))
snprintf(carrier, 15, "802.11b");
else if (net->carrier_set & (1 << (int) carrier_80211bplus))
snprintf(carrier, 15, "802.11b+");
else if (net->carrier_set & (1 << (int) carrier_80211a))
snprintf(carrier, 15, "802.11a");
else if (net->carrier_set & (1 << (int) carrier_80211g))
snprintf(carrier, 15, "802.11g");
else if (net->carrier_set & (1 << (int) carrier_80211fhss))
snprintf(carrier, 15, "802.11 FHSS");
else if (net->carrier_set & (1 << (int) carrier_80211dsss))
snprintf(carrier, 15, "802.11 DSSS");
else if (net->carrier_set & (1 << (int) carrier_80211n20))
snprintf(carrier, 15, "802.11n 20MHz");
else if (net->carrier_set & (1 << (int) carrier_80211n40))
snprintf(carrier, 15, "802.11n 40MHz");
else
snprintf(carrier, 15, "unknown");
string crypt;
if (net->crypt_set == 0)
crypt = "None";
if (net->crypt_set & crypt_wep)
crypt += "WEP ";
if (net->crypt_set & crypt_layer3)
crypt += "Layer3 ";
if (net->crypt_set & crypt_wep40)
crypt += "WEP40 ";
if (net->crypt_set & crypt_wep104)
crypt += "WEP104 ";
if (net->crypt_set & crypt_tkip)
crypt += "TKIP ";
if (net->crypt_set & crypt_wpa)
crypt += "WPA ";
if (net->crypt_set & crypt_psk)
crypt += "PSK ";
if (net->crypt_set & crypt_aes_ocb)
crypt += "AES-OCB ";
if (net->crypt_set & crypt_aes_ccm)
crypt += "AES-CCM ";
if (net->crypt_set & crypt_leap)
crypt += "LEAP ";
if (net->crypt_set & crypt_ttls)
crypt += "TTLS ";
if (net->crypt_set & crypt_tls)
crypt += "TLS ";
if (net->crypt_set & crypt_peap)
crypt += "PEAP ";
if (net->crypt_set & crypt_isakmp)
crypt += "ISAKMP ";
if (net->crypt_set & crypt_pptp)
crypt += "PPTP ";
if (net->crypt_set & crypt_ccmp)
crypt += "CCMP ";
if (crypt.length() == 0)
crypt = "Unknown";
fprintf(netfile, "Network %d: \"%s\" BSSID: \"%s\"\n"
" Type : %s\n"
" Carrier : %s\n"
" Info : \"%s\"\n"
" Channel : %02d\n"
" Encryption : \"%s\"\n"
" Maxrate : %2.1f\n"
" LLC : %d\n"
" Data : %d\n"
" Crypt : %d\n"
" Weak : %d\n"
" Dupe IV : %d\n"
" Total : %d\n"
" First : \"%s\"\n"
" Last : \"%s\"\n",
netnum,
net->ssid.c_str(), net->bssid.Mac2String().c_str(), type, carrier,
net->beacon_info == "" ? "None" : net->beacon_info.c_str(),
net->channel,
crypt.c_str(),
net->maxrate,
net->llc_packets, net->data_packets,
net->crypt_packets, net->interesting_packets,
net->dupeiv_packets,
(net->llc_packets + net->data_packets),
ft, lt);
if (net->gps_fixed != -1)
fprintf(netfile,
" Min Loc: Lat %f Lon %f Alt %f Spd %f\n"
" Max Loc: Lat %f Lon %f Alt %f Spd %f\n",
net->min_lat, net->min_lon,
metric ? net->min_alt / 3.3 : net->min_alt,
metric ? net->min_spd * 1.6093 : net->min_spd,
net->max_lat, net->max_lon,
metric ? net->max_alt / 3.3 : net->max_alt,
metric ? net->max_spd * 1.6093 : net->max_spd);
if (net->ipdata.atype == address_dhcp)
fprintf(netfile, " Address found via DHCP %d.%d.%d.%d \n",
net->ipdata.range_ip[0], net->ipdata.range_ip[1],
net->ipdata.range_ip[2], net->ipdata.range_ip[3]
);
else if (net->ipdata.atype == address_arp)
fprintf(netfile, " Address found via ARP %d.%d.%d.%d\n",
net->ipdata.range_ip[0], net->ipdata.range_ip[1],
net->ipdata.range_ip[2], net->ipdata.range_ip[3]);
else if (net->ipdata.atype == address_udp)
fprintf(netfile, " Address found via UDP %d.%d.%d.%d\n",
net->ipdata.range_ip[0], net->ipdata.range_ip[1],
net->ipdata.range_ip[2], net->ipdata.range_ip[3]);
else if (net->ipdata.atype == address_tcp)
fprintf(netfile, " Address found via TCP %d.%d.%d.%d\n",
net->ipdata.range_ip[0], net->ipdata.range_ip[1],
net->ipdata.range_ip[2], net->ipdata.range_ip[3]);
fprintf(netfile, "\n");
netnum++;
}
fclose(netfile);
/* Move the temporary file on the regular file in one "atomic" operation.
* The idea here is that the log file is always available and always
* a complete and valid file, users of that file can access it with
* confidence. The old file will be unlinked automatically. Jean II */
if (rename(fname_temp.c_str(), in_fname.c_str()) == -1) {
snprintf(errstr, 1024, "Unable to rename %s to %s: %s",
fname_temp.c_str(), in_fname.c_str(),
strerror(errno));
return -1;
}
return 1;
}
// Write out the cisco information
int Packetracker::WriteCisco(string in_fname) {
string fname_temp = in_fname + ".temp";
FILE *netfile;
/* Test if we can open the file, using read+write mode (r+).
* Using write mode (w+) would truncate the file, which means that during
* update the log would be empty.
* Using apend mode (a+) would force to seek to the end of file, which
* is slower. Jean II */
if ((netfile = fopen(in_fname.c_str(), "r+")) == NULL) {
snprintf(errstr, 1024, "Could not open %s for writing: %s", in_fname.c_str(),
strerror(errno));
return -1;
}
fclose(netfile);
if (unlink(fname_temp.c_str()) == -1) {
if (errno != ENOENT) {
snprintf(errstr, 1024, "Could not unlink temp file %s: %s",
fname_temp.c_str(), strerror(errno));
return -1;
}
}
if ((netfile = fopen(fname_temp.c_str(), "wx")) == NULL) {
snprintf(errstr, 1024, "Could not open %s for writing even though "
"we could unlink it: %s", fname_temp.c_str(), strerror(errno));
return -1;
}
/*
vector<wireless_network *> bssid_vec;
// Convert the map to a vector and sort it
for (map<mac_addr, wireless_network *>::const_iterator i = bssid_map.begin();
i != bssid_map.end(); ++i)
bssid_vec.push_back(i->second);
stable_sort(bssid_vec.begin(), bssid_vec.end(), SortFirstTimeLT());
*/
if (network_list.size() > 0)
stable_sort(network_list.begin(), network_list.end(), SortFirstTimeLT());
for (unsigned int i = 0; i < network_list.size(); i++) {
wireless_network *net = network_list[i];
if (net->cisco_equip == NULL)
continue;
if (net->cisco_equip->size() == 0)
continue;
if (filter_export) {
macmap<int>::iterator fitr = filter_export_bssid->find(net->bssid);
// In the list and we've got inverted filtering - kill it
if (fitr != filter_export_bssid->end() &&
*filter_export_bssid_invert == 1)
continue;
// Not in the list and we've got normal filtering - kill it
if (fitr == filter_export_bssid->end() &&
*filter_export_bssid_invert == 0)
continue;
}
fprintf(netfile, "Network: \"%s\" BSSID: \"%s\"\n",
net->ssid.c_str(), net->bssid.Mac2String().c_str());
int devnum = 1;
for (unsigned int x = 0; x < net->cisco_equip->size(); x++) {
cdp_packet cdp = (*net->cisco_equip)[x];
fprintf(netfile, "CDP Broadcast Device %d\n", devnum);
fprintf(netfile, " Device ID : %s\n", cdp.dev_id);
fprintf(netfile, " Capability: %s%s%s%s%s%s%s\n",
cdp.cap.level1 ? "Level 1 " : "" ,
cdp.cap.igmp_forward ? "IGMP forwarding " : "",
cdp.cap.nlp ? "Network-layer protocols " : "",
cdp.cap.level2_switching ? "Level 2 switching " : "",
cdp.cap.level2_sourceroute ? "Level 2 source-route bridging " : "",
cdp.cap.level2_transparent ? "Level 2 transparent bridging " : "",
cdp.cap.level3 ? "Level 3 routing " : "");
fprintf(netfile, " Interface : %s\n", cdp.interface);
fprintf(netfile, " IP : %d.%d.%d.%d\n",
cdp.ip[0], cdp.ip[1], cdp.ip[2], cdp.ip[3]);
fprintf(netfile, " Platform : %s\n", cdp.platform);
fprintf(netfile, " Software : %s\n", cdp.software);
fprintf(netfile, "\n");
devnum++;
} // cdp
} // net
fclose(netfile);
/* Move the temporary file on the regular file in one "atomic" operation.
* The idea here is that the log file is always available and always
* a complete and valid file, users of that file can access it with
* confidence. The old file will be unlinked automatically. Jean II */
if (rename(fname_temp.c_str(), in_fname.c_str()) == -1) {
snprintf(errstr, 1024, "Unable to rename %s to %s: %s",
fname_temp.c_str(), in_fname.c_str(),
strerror(errno));
return -1;
}
return 1;
}
// Sanitize data not to contain ';'.
string Packetracker::SanitizeCSV(string in_data) {
string ret;
for (unsigned int x = 0; x < in_data.length(); x++) {
if (in_data[x] == ';')
ret += ' ';
else
ret += in_data[x];
}
return ret;
}
/* CSV support
* Author: Reyk Floeter <reyk@synack.de>
* Date: 2002/03/13
*/
int Packetracker::WriteCSVNetworks(string in_fname) {
string fname_temp = in_fname + ".temp";
FILE *netfile;
/* Test if we can open the file, using read+write mode (r+).
* Using write mode (w+) would truncate the file, which means that during
* update the log would be empty.
* Using apend mode (a+) would force to seek to the end of file, which
* is slower. Jean II */
if ((netfile = fopen(in_fname.c_str(), "r+")) == NULL) {
snprintf(errstr, 1024, "Could not open %s for writing: %s", in_fname.c_str(),
strerror(errno));
return -1;
}
fclose(netfile);
if (unlink(fname_temp.c_str()) == -1) {
if (errno != ENOENT) {
snprintf(errstr, 1024, "Could not unlink temp file %s: %s",
fname_temp.c_str(), strerror(errno));
return -1;
}
}
if ((netfile = fopen(fname_temp.c_str(), "wx")) == NULL) {
snprintf(errstr, 1024, "Could not open %s for writing even though "
"we could unlink it: %s", fname_temp.c_str(), strerror(errno));
return -1;
}
int netnum = 1;
fprintf(netfile, "Network;NetType;ESSID;BSSID;Info;Channel;Cloaked;Encryption;Decrypted;MaxRate;MaxSeenRate;Beacon;"
"LLC;Data;Crypt;Weak;Total;Carrier;Encoding;FirstTime;LastTime;BestQuality;BestSignal;BestNoise;"
"GPSMinLat;GPSMinLon;GPSMinAlt;GPSMinSpd;GPSMaxLat;GPSMaxLon;GPSMaxAlt;GPSMaxSpd;"
"GPSBestLat;GPSBestLon;GPSBestAlt;DataSize;IPType;IP;\r\n");
if (network_list.size() > 0)
stable_sort(network_list.begin(), network_list.end(), SortFirstTimeLT());
for (unsigned int i = 0; i < network_list.size(); i++) {
wireless_network *net = network_list[i];
if (filter_export) {
macmap<int>::iterator fitr = filter_export_bssid->find(net->bssid);
// In the list and we've got inverted filtering - kill it
if (fitr != filter_export_bssid->end() &&
*filter_export_bssid_invert == 1)
continue;
// Not in the list and we've got normal filtering - kill it
if (fitr == filter_export_bssid->end() &&
*filter_export_bssid_invert == 0)
continue;
}
char lt[25];
char ft[25];
snprintf(lt, 25, "%s", ctime(&net->last_time));
snprintf(ft, 25, "%s", ctime(&net->first_time));
char type[15];
if (net->type == network_ap)
snprintf(type, 15, "infrastructure");
else if (net->type == network_adhoc)
snprintf(type, 15, "ad-hoc");
else if (net->type == network_probe)
snprintf(type, 15, "probe");
else if (net->type == network_data)
snprintf(type, 15, "data");
else if (net->type == network_turbocell)
snprintf(type, 15, "turbocell");
else
snprintf(type, 15, "unknown");
string carrier;
if (net->carrier_set & (1 << (int) carrier_80211b)) {
carrier += "IEEE 802.11b";
}
if (net->carrier_set & (1 << (int) carrier_80211bplus)) {
if (carrier != "")
carrier += ",";
carrier += "TI 802.11b+";
}
if (net->carrier_set & (1 << (int) carrier_80211a)) {
if (carrier != "")
carrier += ",";
carrier += "IEEE 802.11a";
}
if (net->carrier_set & (1 << (int) carrier_80211g)) {
if (carrier != "")
carrier += ",";
carrier += "IEEE 802.11g";
}
if (net->carrier_set & (1 << (int) carrier_80211fhss)) {
if (carrier != "")
carrier += ",";
carrier += "IEEE 802.11 FHSS";
}
if (net->carrier_set & (1 << (int) carrier_80211dsss)) {
if (carrier != "")
carrier += ",";
carrier += "IEEE 802.11 DSSS";
}
if (net->carrier_set & (1 << (int) carrier_80211n20)) {
if (carrier != "")
carrier += ",";
carrier += "IEEE 802.11n 20MHz";
}
if (net->carrier_set & (1 << (int) carrier_80211n40)) {
if (carrier != "")
carrier += ",";
carrier += "IEEE 802.11n 40MHz";
}
string encoding;
if (net->encoding_set & (1 << (int) encoding_cck)) {
encoding = "CCK";
}
if (net->encoding_set & (1 << (int) encoding_pbcc)) {
if (encoding != "")
encoding += ",";
encoding += "PBCC";
}
if (net->encoding_set & (1 << (int) encoding_ofdm)) {
if (encoding != "")
encoding += ",";
encoding += "OFDM";
}
string iptype = "None";
if (net->ipdata.atype == address_dhcp)
iptype = "DHCP";
else if (net->ipdata.atype == address_arp)
iptype = "ARP";
else if (net->ipdata.atype == address_udp)
iptype = "UDP";
else if (net->ipdata.atype == address_tcp)
iptype = "TCP";
string crypt;
if (net->crypt_set == 0)
crypt = "None";
if (net->crypt_set & crypt_wep) {
if (crypt != "")
crypt += ",";
crypt += "WEP";
}
if (net->crypt_set & crypt_layer3) {
if (crypt != "")
crypt += ",";
crypt += "Layer3";
}
if (net->crypt_set & crypt_wep40) {
if (crypt != "")
crypt += ",";
crypt += "WEP40";
}
if (net->crypt_set & crypt_wep104) {
if (crypt != "")
crypt += ",";
crypt += "WEP104";
}
if (net->crypt_set & crypt_tkip) {
if (crypt != "")
crypt += ",";
crypt += "TKIP";
}
if (net->crypt_set & crypt_wpa) {
if (crypt != "")
crypt += ",";
crypt += "WPA";
}
if (net->crypt_set & crypt_psk) {
if (crypt != "")
crypt += ",";
crypt += "PSK";
}
if (net->crypt_set & crypt_aes_ocb) {
if (crypt != "")
crypt += ",";
crypt += "AES-OCB";
}
if (net->crypt_set & crypt_aes_ccm) {
if (crypt != "")
crypt += ",";
crypt += "AES-CCM";
}
if (net->crypt_set & crypt_leap) {
if (crypt != "")
crypt += ",";
crypt += "LEAP";
}
if (net->crypt_set & crypt_ttls) {
if (crypt != "")
crypt += ",";
crypt += "TTLS";
}
if (net->crypt_set & crypt_tls) {
if (crypt != "")
crypt += ",";
crypt += "TLS";
}
if (net->crypt_set & crypt_peap) {
if (crypt != "")
crypt += ",";
crypt += "PEAP";
}
if (net->crypt_set & crypt_isakmp) {
if (crypt != "")
crypt += ",";
crypt += "ISAKMP";
}
if (net->crypt_set & crypt_pptp) {
if (crypt != "")
crypt += ",";
crypt += "PPTP";
}
if (net->crypt_set & crypt_ccmp) {
if (crypt != "")
crypt += ",";
crypt += "CCMP";
}
if (crypt.length() == 0)
crypt = "Unknown";
fprintf(netfile,
"%d;%s;%s;%s;%s;"
"%d;%s;%s;%s;"
"%2.1f;%ld;%d;"
"%d;%d;%d;%d;%d;"
"%s;%s;%s;%s;"
"%d;%d;%d;"
"%f;%f;%f;%f;"
"%f;%f;%f;%f;"
"%f;%f;%f;"
"%ld;%s;"
"%hu.%hu.%hu.%hu;\r\n",
netnum, type, SanitizeCSV(net->ssid).c_str(),
net->bssid.Mac2String().c_str(),
SanitizeCSV(net->beacon_info).c_str(),
net->channel, net->cloaked ? "Yes" : "No", crypt.c_str(),
net->decrypted ? "Yes" : "No",
net->maxrate, (long) net->maxseenrate * 100, net->beacon,
net->llc_packets, net->data_packets, net->crypt_packets,
net->interesting_packets,
(net->llc_packets + net->data_packets),
carrier.c_str(), encoding.c_str(), ft, lt,
net->best_quality, net->best_signal, net->best_noise,
net->min_lat, net->min_lon, net->min_alt, net->min_spd,
net->max_lat, net->max_lon, net->max_alt, net->max_spd,
net->best_lat, net->best_lon, net->best_alt,
net->datasize, iptype.c_str(),
net->ipdata.range_ip[0], net->ipdata.range_ip[1],
net->ipdata.range_ip[2], net->ipdata.range_ip[3]);
netnum++;
}
fclose(netfile);
/* Move the temporary file on the regular file in one "atomic" operation.
* The idea here is that the log file is always available and always
* a complete and valid file, users of that file can access it with
* confidence. The old file will be unlinked automatically. Jean II */
if (rename(fname_temp.c_str(), in_fname.c_str()) == -1) {
snprintf(errstr, 1024, "Unable to rename %s to %s: %s",
fname_temp.c_str(), in_fname.c_str(),
strerror(errno));
return -1;
}
return 1;
}
string Packetracker::SanitizeXML(string in_data) {
string ret;
for (unsigned int x = 0; x < in_data.length(); x++) {
if (in_data[x] == '&')
ret += "&";
else if (in_data[x] == '<')
ret += "<";
else if (in_data[x] == '>')
ret += ">";
else
ret += in_data[x];
}
return ret;
}
// Write an XML-formatted output conforming to our DTD at
// http://kismetwireless.net/kismet-1.0.dtd
int Packetracker::WriteXMLNetworks(string in_fname) {
string fname_temp = in_fname + ".temp";
FILE *netfile;
/* Test if we can open the file, using read+write mode (r+).
* Using write mode (w+) would truncate the file, which means that during
* update the log would be empty.
* Using apend mode (a+) would force to seek to the end of file, which
* is slower. Jean II */
if ((netfile = fopen(in_fname.c_str(), "r+")) == NULL) {
snprintf(errstr, 1024, "Could not open %s for writing: %s", in_fname.c_str(),
strerror(errno));
return -1;
}
fclose(netfile);
if (unlink(fname_temp.c_str()) == -1) {
if (errno != ENOENT) {
snprintf(errstr, 1024, "Could not unlink temp file %s: %s",
fname_temp.c_str(), strerror(errno));
return -1;
}
}
if ((netfile = fopen(fname_temp.c_str(), "wx")) == NULL) {
snprintf(errstr, 1024, "Could not open %s for writing even though "
"we could unlink it: %s", fname_temp.c_str(), strerror(errno));
return -1;
}
int netnum = 1;
//vector<wireless_network *> bssid_vec;
fprintf(netfile, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
fprintf(netfile, "<!DOCTYPE detection-run SYSTEM \"http://kismetwireless.net/kismet-2005-03.dtd\">\n");
fprintf(netfile, "\n\n");
char lt[25];
char ft[25];
snprintf(ft, 25, "%s", ctime(&start_time));
time_t cur_time = time(0);
snprintf(lt, 25, "%s", ctime(&cur_time));
fprintf(netfile, "<detection-run kismet-version=\"%s.%s.%s\" start-time=\"%s\" end-time=\"%s\">\n",
VERSION_MAJOR, VERSION_MINOR, VERSION_TINY, ft, lt);
/*
// Convert the map to a vector and sort it
for (map<mac_addr, wireless_network *>::const_iterator i = bssid_map.begin();
i != bssid_map.end(); ++i)
bssid_vec.push_back(i->second);
stable_sort(bssid_vec.begin(), bssid_vec.end(), SortFirstTimeLT());
*/
if (network_list.size() > 0)
stable_sort(network_list.begin(), network_list.end(), SortFirstTimeLT());
for (unsigned int i = 0; i < network_list.size(); i++) {
wireless_network *net = network_list[i];
if (filter_export) {
macmap<int>::iterator fitr = filter_export_bssid->find(net->bssid);
// In the list and we've got inverted filtering - kill it
if (fitr != filter_export_bssid->end() &&
*filter_export_bssid_invert == 1)
continue;
// Not in the list and we've got normal filtering - kill it
if (fitr == filter_export_bssid->end() &&
*filter_export_bssid_invert == 0)
continue;
}
snprintf(lt, 25, "%s", ctime(&net->last_time));
snprintf(ft, 25, "%s", ctime(&net->first_time));
char type[15];
if (net->type == network_ap)
snprintf(type, 15, "infrastructure");
else if (net->type == network_adhoc)
snprintf(type, 15, "ad-hoc");
else if (net->type == network_probe)
snprintf(type, 15, "probe");
else if (net->type == network_data)
snprintf(type, 15, "data");
else if (net->type == network_turbocell)
snprintf(type, 15, "turbocell");
else
snprintf(type, 15, "unknown");
fprintf(netfile, " <wireless-network number=\"%d\" type=\"%s\" wep=\"%s\" cloaked=\"%s\" first-time=\"%s\" last-time=\"%s\">\n",
netnum, type, net->crypt_set ? "true" : "false",
net->cloaked ? "true" : "false",
ft, lt);
if (net->ssid != NOSSID)
fprintf(netfile, " <SSID>%s</SSID>\n", SanitizeXML(net->ssid).c_str());
fprintf(netfile, " <BSSID>%s</BSSID>\n", net->bssid.Mac2String().c_str());
if (net->beacon_info != "")
fprintf(netfile, " <info>%s</info>\n", SanitizeXML(net->beacon_info).c_str());
fprintf(netfile, " <channel>%d</channel>\n", net->channel);
fprintf(netfile, " <maxrate>%2.1f</maxrate>\n", net->maxrate);
fprintf(netfile, " <maxseenrate>%ld</maxseenrate>\n", (long) net->maxseenrate * 100);
if (net->carrier_set & (1 << (int) carrier_80211b))
fprintf(netfile, " <carrier>IEEE 802.11b</carrier>\n");
if (net->carrier_set & (1 << (int) carrier_80211bplus))
fprintf(netfile, " <carrier>TI 802.11b+</carrier>\n");
if (net->carrier_set & (1 << (int) carrier_80211a))
fprintf(netfile, " <carrier>IEEE 802.11a</carrier>\n");
if (net->carrier_set & (1 << (int) carrier_80211g))
fprintf(netfile, " <carrier>IEEE 802.11g</carrier>\n");
if (net->carrier_set & (1 << (int) carrier_80211fhss))
fprintf(netfile, " <carrier>IEEE 802.11 FHSS</carrier>\n");
if (net->carrier_set & (1 << (int) carrier_80211dsss))
fprintf(netfile, " <carrier>IEEE 802.11 FSSS</carrier>\n");
if (net->encoding_set & (1 << (int) encoding_cck))
fprintf(netfile, " <encoding>CCK</encoding>\n");
if (net->encoding_set & (1 << (int) encoding_pbcc))
fprintf(netfile, " <encoding>PBCC</encoding>\n");
if (net->encoding_set & (1 << (int) encoding_ofdm))
fprintf(netfile, " <encoding>OFDM</encoding>\n");
if (net->carrier_set & (1 << (int) carrier_80211n20))
fprintf(netfile, " <encoding>802.11n 20MHz</encoding>\n");
if (net->carrier_set & (1 << (int) carrier_80211n40))
fprintf(netfile, " <encoding>802.11n 40MHz</encoding>\n");
if (net->crypt_set == 0)
fprintf(netfile, " <encryption>None</encryption>\n");
if (net->crypt_set & crypt_wep)
fprintf(netfile, " <encryption>WEP</encryption>\n");
if (net->crypt_set & crypt_layer3)
fprintf(netfile, " <encryption>Layer3</encryption>\n");
if (net->crypt_set & crypt_wep40)
fprintf(netfile, " <encryption>WEP40</encryption>\n");
if (net->crypt_set & crypt_wep104)
fprintf(netfile, " <encryption>WEP104</encryption>\n");
if (net->crypt_set & crypt_tkip)
fprintf(netfile, " <encryption>TKIP</encryption>\n");
if (net->crypt_set & crypt_wpa)
fprintf(netfile, " <encryption>WPA</encryption>\n");
if (net->crypt_set & crypt_psk)
fprintf(netfile, " <encryption>PSK</encryption>\n");
if (net->crypt_set & crypt_aes_ocb)
fprintf(netfile, " <encryption>AES-OCB</encryption>\n");
if (net->crypt_set & crypt_aes_ccm)
fprintf(netfile, " <encryption>AES-CCM</encryption>\n");
if (net->crypt_set & crypt_leap)
fprintf(netfile, " <encryption>LEAP</encryption>\n");
if (net->crypt_set & crypt_ttls)
fprintf(netfile, " <encryption>TTLS</encryption>\n");
if (net->crypt_set & crypt_tls)
fprintf(netfile, " <encryption>TLS</encryption>\n");
if (net->crypt_set & crypt_peap)
fprintf(netfile, " <encryption>PEAP</encryption>\n");
if (net->crypt_set & crypt_isakmp)
fprintf(netfile, " <encryption>ISAKMP</encryption>\n");
if (net->crypt_set & crypt_pptp)
fprintf(netfile, " <encryption>PPTP</encryption>\n");
if (net->crypt_set & crypt_ccmp)
fprintf(netfile, " <encryption>CCMP</encryption>\n");
fprintf(netfile, " <packets>\n");
fprintf(netfile, " <LLC>%d</LLC>\n", net->llc_packets);
fprintf(netfile, " <data>%d</data>\n", net->data_packets);
fprintf(netfile, " <crypt>%d</crypt>\n", net->crypt_packets);
fprintf(netfile, " <weak>%d</weak>\n", net->interesting_packets);
fprintf(netfile, " <dupeiv>%d</dupeiv>\n", net->dupeiv_packets);
fprintf(netfile, " <total>%d</total>\n",
(net->llc_packets + net->data_packets));
fprintf(netfile, " </packets>\n");
fprintf(netfile, " <datasize>%ld</datasize>\n", net->datasize);
if (net->gps_fixed != -1) {
fprintf(netfile, " <gps-info unit=\"%s\">\n", metric ? "metric" : "english");
fprintf(netfile, " <min-lat>%f</min-lat>\n", net->min_lat);
fprintf(netfile, " <min-lon>%f</min-lon>\n", net->min_lon);
fprintf(netfile, " <min-alt>%f</min-alt>\n",
metric ? net->min_alt / 3.3 : net->min_alt);
fprintf(netfile, " <min-spd>%f</min-spd>\n",
metric ? net->min_spd * 1.6093 : net->min_spd);
fprintf(netfile, " <max-lat>%f</max-lat>\n", net->max_lat);
fprintf(netfile, " <max-lon>%f</max-lon>\n", net->max_lon);
fprintf(netfile, " <max-alt>%f</max-alt>\n",
metric ? net->max_alt / 3.3 : net->max_alt);
fprintf(netfile, " <max-spd>%f</max-spd>\n",
metric ? net->max_spd * 1.6093 : net->max_spd);
fprintf(netfile, " </gps-info>\n");
}
if (net->ipdata.atype > address_factory) {
char *addrtype;
switch (net->ipdata.atype) {
case address_dhcp:
addrtype = "dhcp";
break;
case address_arp:
addrtype = "arp";
break;
case address_udp:
addrtype = "udp";
break;
case address_tcp:
addrtype = "tcp";
break;
default:
addrtype = "unknown";
break;
}
fprintf(netfile, " <ip-address type=\"%s\">\n", addrtype);
fprintf(netfile, " <ip-range>%d.%d.%d.%d</ip-range>\n",
net->ipdata.range_ip[0], net->ipdata.range_ip[1],
net->ipdata.range_ip[2], net->ipdata.range_ip[3]);
fprintf(netfile, " </ip-address>\n");
}
netnum++;
int clinum = 1;
for (unsigned int cltr = 0; cltr < net->client_vec.size(); cltr++) {
wireless_client *cli = net->client_vec[cltr];
char *clitype;
switch (cli->type) {
case client_fromds:
clitype = "fromds";
break;
case client_tods:
clitype = "tods";
break;
case client_interds:
clitype = "interds";
break;
case client_established:
clitype = "established";
break;
case client_sendto:
clitype = "sendto";
break;
default:
clitype = "unknown";
break;
}
snprintf(lt, 25, "%s", ctime(&cli->last_time));
snprintf(ft, 25, "%s", ctime(&cli->first_time));
fprintf(netfile, " <wireless-client number=\"%d\" type=\"%s\" "
"wep=\"%s\" first-time=\"%s\" last-time=\"%s\">\n",
clinum, clitype, cli->crypt_set ? "true" : "false", ft, lt);
fprintf(netfile, " <client-mac>%s</client-mac>\n", cli->mac.Mac2String().c_str());
fprintf(netfile, " <client-packets>\n");
fprintf(netfile, " <client-data>%d</client-data>\n", cli->data_packets);
fprintf(netfile, " <client-crypt>%d</client-crypt>\n", cli->crypt_packets);
fprintf(netfile, " <client-weak>%d</client-weak>\n", cli->interesting_packets);
fprintf(netfile, " </client-packets>\n");
if (cli->crypt_set == 0)
fprintf(netfile, " <client-encryption>None</client-encryption>\n");
if (cli->crypt_set & crypt_wep)
fprintf(netfile, " <client-encryption>WEP</client-encryption>\n");
if (cli->crypt_set & crypt_layer3)
fprintf(netfile, " <client-encryption>Layer3</client-encryption>\n");
if (cli->crypt_set & crypt_wep40)
fprintf(netfile, " <client-encryption>WEP40</client-encryption>\n");
if (cli->crypt_set & crypt_wep104)
fprintf(netfile, " <client-encryption>WEP104</client-encryption>\n");
if (cli->crypt_set & crypt_tkip)
fprintf(netfile, " <client-encryption>TKIP</client-encryption>\n");
if (cli->crypt_set & crypt_wpa)
fprintf(netfile, " <client-encryption>WPA</client-encryption>\n");
if (cli->crypt_set & crypt_psk)
fprintf(netfile, " <client-encryption>PSK</client-encryption>\n");
if (cli->crypt_set & crypt_aes_ocb)
fprintf(netfile, " <client-encryption>AES-OCB</client-encryption>\n");
if (cli->crypt_set & crypt_aes_ccm)
fprintf(netfile, " <client-encryption>AES-CCM</client-encryption>\n");
if (cli->crypt_set & crypt_leap)
fprintf(netfile, " <client-encryption>LEAP</client-encryption>\n");
if (cli->crypt_set & crypt_ttls)
fprintf(netfile, " <client-encryption>TTLS</client-encryption>\n");
if (cli->crypt_set & crypt_tls)
fprintf(netfile, " <client-encryption>TLS</client-encryption>\n");
if (cli->crypt_set & crypt_peap)
fprintf(netfile, " <client-encryption>PEAP</client-encryption>\n");
if (cli->crypt_set & crypt_isakmp)
fprintf(netfile, " <client-encryption>ISAKMP</client-encryption>\n");
if (cli->crypt_set & crypt_pptp)
fprintf(netfile, " <client-encryption>PPTP</client-encryption>\n");
if (cli->crypt_set & crypt_ccmp)
fprintf(netfile, " <client-encryption>CCMP</client-encryption>\n");
if (cli->gps_fixed != -1) {
fprintf(netfile, " <client-gps-info unit=\"%s\">\n", metric ? "metric" : "english");
fprintf(netfile, " <client-min-lat>%f</client-min-lat>\n", cli->min_lat);
fprintf(netfile, " <client-min-lon>%f</client-min-lon>\n", cli->min_lon);
fprintf(netfile, " <client-min-alt>%f</client-min-alt>\n",
metric ? cli->min_alt / 3.3 : cli->min_alt);
fprintf(netfile, " <client-min-spd>%f</client-min-spd>\n",
metric ? cli->min_spd * 1.6093 : cli->min_spd);
fprintf(netfile, " <client-max-lat>%f</client-max-lat>\n", cli->max_lat);
fprintf(netfile, " <client-max-lon>%f</client-max-lon>\n", cli->max_lon);
fprintf(netfile, " <client-max-alt>%f</client-max-alt>\n",
metric ? cli->max_alt / 3.3 : cli->max_alt);
fprintf(netfile, " <client-max-spd>%f</client-max-spd>\n",
metric ? cli->max_spd * 1.6093 : cli->max_spd);
fprintf(netfile, " </client-gps-info>\n");
}
fprintf(netfile, " <client-datasize>%ld</client-datasize>\n", cli->datasize);
fprintf(netfile, " <client-maxrate>%2.1f</client-maxrate>\n", cli->maxrate);
fprintf(netfile, " <client-maxseenrate>%ld</client-maxseenrate>\n", (long) cli->maxseenrate * 100);
if (net->encoding_set & (1 << (int) encoding_cck))
fprintf(netfile, " <client-encoding>CCK</client-encoding>\n");
if (net->encoding_set & (1 << (int) encoding_pbcc))
fprintf(netfile, " <client-encoding>PBCC</client-encoding>\n");
if (net->encoding_set & (1 << (int) encoding_ofdm))
fprintf(netfile, " <client-encoding>OFDM</client-encoding>\n");
if (cli->ipdata.atype > address_factory) {
char *addrtype;
switch (cli->ipdata.atype) {
case address_dhcp:
addrtype = "dhcp";
break;
case address_arp:
addrtype = "arp";
break;
case address_udp:
addrtype = "udp";
break;
case address_tcp:
addrtype = "tcp";
break;
default:
addrtype = "unknown";
break;
}
fprintf(netfile, " <client-ip-address type=\"%s\">%hu.%hu.%hu.%hu</client-ip-address>\n",
addrtype, cli->ipdata.ip[0], cli->ipdata.ip[1], cli->ipdata.ip[2], cli->ipdata.ip[3]);
}
fprintf(netfile, " </wireless-client>\n");
clinum++;
}
int devnum = 1;
if (net->cisco_equip != NULL) {
for (unsigned int x = 0; x < net->cisco_equip->size(); x++) {
cdp_packet cdp = (*net->cisco_equip)[x];
fprintf(netfile, " <cisco number=\"%d\">\n", devnum);
fprintf(netfile, " <cdp-device-id>%s</cdp-device-id>\n",
cdp.dev_id);
fprintf(netfile, " <cdp-capability level1=\"%s\" igmp-forward=\"%s\" netlayer=\"%s\" "
"level2-switching=\"%s\" level2-sourceroute=\"%s\" level2-transparent=\"%s\" "
"level3-routing=\"%s\"/>\n",
cdp.cap.level1 ? "true" : "false",
cdp.cap.igmp_forward ? "true" : "false",
cdp.cap.nlp ? "true" : "false",
cdp.cap.level2_switching ? "true" : "false",
cdp.cap.level2_sourceroute ? "true" : "false",
cdp.cap.level2_transparent ? "true" : "false",
cdp.cap.level3 ? "true" : "false");
fprintf(netfile, " <cdp-interface>%s</cdp-interface>\n", cdp.interface);
fprintf(netfile, " <cdp-ip>%d.%d.%d.%d</cdp-ip>\n",
cdp.ip[0], cdp.ip[1], cdp.ip[2], cdp.ip[3]);
fprintf(netfile, " <cdp-platform>%s</cdp-platform>\n", cdp.platform);
fprintf(netfile, " <cdp-software>%s</cdp-software>\n", cdp.software);
fprintf(netfile, " </cisco>\n");
devnum++;
} // cdp
} // cdp exists
fprintf(netfile, " </wireless-network>\n");
} // net
fprintf(netfile, "</detection-run>\n");
fclose(netfile);
/* Move the temporary file on the regular file in one "atomic" operation.
* The idea here is that the log file is always available and always
* a complete and valid file, users of that file can access it with
* confidence. The old file will be unlinked automatically. Jean II */
if (rename(fname_temp.c_str(), in_fname.c_str()) == -1) {
snprintf(errstr, 1024, "Unable to rename %s to %s: %s",
fname_temp.c_str(), in_fname.c_str(),
strerror(errno));
return -1;
}
return 1;
}
void Packetracker::ReadSSIDMap(FILE *in_file) {
char dline[8192];
mac_addr bssid;
char name[1024];
char bssid_str[18];
while (!feof(in_file)) {
if (fgets(dline, 8192, in_file) == NULL ||
feof(in_file)) break;
if (sscanf(dline, "%17s %1023[^\n]\n",
bssid_str, name) < 2)
continue;
bssid = bssid_str;
bssid_cloak_map[bssid] = name;
}
return;
}
void Packetracker::WriteSSIDMap(FILE *in_file) {
if (fseek(in_file, 0L, SEEK_SET) == -1 ||
ftruncate(fileno(in_file), 0) == -1)
abort(); // HACK: implement better error-handling
char format[64];
snprintf(format, 64, "%%.%ds %%.%ds\n", MAC_STR_LEN, SSID_SIZE);
for (map<mac_addr, string>::iterator x = bssid_cloak_map.begin();
x != bssid_cloak_map.end(); ++x) {
// Find us in the map - if we don't have a current record, we get written out,
// if we do have a current record and it's not something we like, we don't get
// written out
map<mac_addr, wireless_network *>::iterator wnitr = bssid_map.find(x->first);
if (wnitr != bssid_map.end())
if (wnitr->second->type != network_ap && wnitr->second->type != network_data)
continue;
fprintf(in_file, format, x->first.Mac2String().c_str(), x->second.c_str());
}
return;
}
void Packetracker::ReadIPMap(FILE *in_file) {
char dline[8192];
mac_addr bssid;
char bssid_str[18];
net_ip_data dat;
while (!feof(in_file)) {
if (fgets(dline, 8192, in_file) == NULL ||
feof(in_file)) break;
memset(&dat, 0, sizeof(net_ip_data));
short int range[4];
int tmpatype;
/*
, mask[4], gate[4];
*/
// Fetch the line and continue if we're invalid...
if (sscanf(dline, "%17s %d %d %hd %hd %hd %hd",
bssid_str,
&tmpatype, &dat.octets,
&range[0], &range[1], &range[2], &range[3]
) < 7)
continue;
dat.atype = static_cast<address_type>(tmpatype);
for (int x = 0; x < 4; x++) {
dat.range_ip[x] = (uint8_t) range[x];
}
dat.load_from_store = 1;
bssid = bssid_str;
if (bssid.error == 1)
continue;
memcpy(&bssid_ip_map[bssid], &dat, sizeof(net_ip_data));
}
return;
}
void Packetracker::WriteIPMap(FILE *in_file) {
if (fseek(in_file, 0L, SEEK_SET) == -1 ||
ftruncate(fileno(in_file), 0) == -1)
abort(); // HACK: better error-handling
for (map<mac_addr, net_ip_data>::iterator x = bssid_ip_map.begin();
x != bssid_ip_map.end(); ++x) {
if (x->second.atype <= address_factory || x->second.octets == 0)
continue;
fprintf(in_file, "%s %d %d %hu %hu %hu %hu\n",
x->first.Mac2String().c_str(),
x->second.atype, x->second.octets,
x->second.range_ip[0], x->second.range_ip[1],
x->second.range_ip[2], x->second.range_ip[3]);
}
for (unsigned int x = 0; x < network_list.size(); x++) {
for (unsigned int y = 0; y < network_list[x]->client_vec.size(); y++) {
wireless_client *cli = network_list[x]->client_vec[y];
if (cli->ipdata.atype <= address_factory)
continue;
fprintf(in_file, "%s %d %d %hu %hu %hu %hu\n",
cli->mac.Mac2String().c_str(),
cli->ipdata.atype, cli->ipdata.octets,
cli->ipdata.ip[0], cli->ipdata.ip[1],
cli->ipdata.ip[2], cli->ipdata.ip[3]);
}
}
return;
}
// These are just dropthroughs to the manuf stuff
void Packetracker::ReadAPManufMap(FILE *in_file) {
ReadManufMap(in_file, 1, &ap_manuf_map);
}
void Packetracker::ReadClientManufMap(FILE *in_file) {
ReadManufMap(in_file, 0, &client_manuf_map);
}
void Packetracker::RemoveNetwork(mac_addr in_bssid) {
// Remove us from the vector the slow and painful way
for (unsigned int x = 0; x < network_list.size(); x++) {
if (network_list[x]->bssid == in_bssid) {
network_list.erase(network_list.begin() + x);
break;
}
}
// Remove us from the hash
map<mac_addr, wireless_network *>::iterator bmi = bssid_map.find(in_bssid);
if (bmi != bssid_map.end()) {
delete bmi->second;
bssid_map.erase(bmi);
}
}
// Write a gpsdrive compatable waypoint file
int Packetracker::WriteGpsdriveWaypt(FILE *in_file) {
if (fseek(in_file, 0L, SEEK_SET) == -1 ||
ftruncate(fileno(in_file), 0) == -1)
abort(); // HACK: better error-handling
// Convert the map to a vector and sort it
for (map<mac_addr, wireless_network *>::const_iterator i = bssid_map.begin();
i != bssid_map.end(); ++i) {
wireless_network *net = i->second;
float lat, lon;
lat = (net->min_lat + net->max_lat) / 2;
lon = (net->min_lon + net->max_lon) / 2;
fprintf(in_file, "%s\t%f %f\n", waypointformat == 1 ? net->ssid.c_str() : net->bssid.Mac2String().c_str(), lat, lon);
}
fflush(in_file);
return 1;
}
|