Showing posts with label sequence. Show all posts
Showing posts with label sequence. Show all posts

Tuesday, December 2, 2008

Predicting Solaris 10 TCP Sequence Numbers Part 1: Initial Discovery

Hey there,

Note: All examples today were produced using Solaris 10. As such, commands like snoop may need to be replaced with ethereal or tcpdump, etc, depending on your OS and/or preference.

Today, we're going to look at a subject that gets plenty of attention (but, maybe not as much publicity) in the world of Unix and Linux network computing: TCP packet sequence number prediction, how it's used to protect network transmissions and whether or not, with the advent of packet checksumming, etc, it's even a factor in basic network security anymore. See here, or at the very bottom of the post, for something potentially interesting about the latest Solaris' network protocol enhancements including SDP.

Not all that long ago (which might mean a long time ago to you, since I'm growin' old ;) TCP number sequencing was pretty simple to predict. In essence, the sequence numbering of TCP packets is required since TCP does its own error-correction and will attempt to resend packets that it doesn't "know" reached their specified endpoint. Numbering, at the most basic level, was/is a great way to ensure that all packets sent actually get received. And, believe it or not, at one point in time that numbering was simply incremental. That means that, given a point-to-point TCP transaction, a simple transmission (from the sender's point-of-view, for instance) might consist of 15 packets. If the first packet was numbered 1 (a gross oversimplification, to be sure, but not too far from being exact ;), the next would be numbered 2, then 3 and so forth until the 15th packet (numbered 15) was successfully sent.

Given the above scenario, and with the aid of hindsight, TCP connection hijacking and other spoofing-based attacks were made quite a bit simpler than they might have been. Of course, once all this "bad" activity began happening, the specifications for TCP packet sequence numbering began to change and become more complicated. Many proprietary OS manufacturer's also began to implement their own proprietary sequence numbering algorithms (in accordance with standards so they could communicate with "unlike" systems). Unfortunately, most of these next-gen specifications were based on simplistic rules like (another gross oversimplification) simple mathematic derivations which didn't use any sort of "outside influence" to affect (or make more unpredictable) the sequence numbering. If you could figure out the equation, you could easily guess what packet number would be next, given one or two sequential packets, and then the whole mess would start all over again. Wikipedia actually has a very nice page on TCP with links to all the relevant RFC's.

This is actually still true today, although OS manufacturers, the Open Source community and white/black-hat hackers are stepping up their games to greater degrees and at a much more condensed pace (by which I mean things now, generally, change more often within a shorter period of time - another gross oversimplification ;)

So, now that it's the present, let's take a look at Solaris 10 and check out what they're doing with regard to this matter (From release 10/08 - the most recent to this date, as far as I know). Assuming we have a connection established with a Solaris 10 server (simple SSH), we can use snoop to gather the information we need to even begin attempting to figure out the TCP packet sequence numbering algorithm they're using (assuming - thinking positive thoughts :) that we can. A simple chunk of output is shown below:

host # snoop -r -d eri0 from 10.99.99.99 to 10.98.98.98
Using device /dev/eri (promiscuous mode)
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625835 Seq=673983919 Len=52 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625887 Seq=673983971 Len=52 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625939 Seq=673984023 Len=52 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625939 Seq=673984075 Len=340 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625939 Seq=673984415 Len=148 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625939 Seq=673984563 Len=148 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625939 Seq=673984711 Len=148 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625939 Seq=673984859 Len=148 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625939 Seq=673985007 Len=148 Win=50400
10.99.99.99 -> 10.98.98.98 TCP D=2782 S=22 Push Ack=2865625939 Seq=673985155 Len=148 Win=50400


Of course, the column we're most interested in (at first, anyway) is the 9th column from the left (assuming spaces and tabs as the default field separator). The column beginning with "Seq=" is what we'll look at first. For the sake of this exercise, we've saved all the packets in a file called "packets." We didn't use -o on the command line, but this is a pretty simple cut-and-paste ;). To isolate those sequence numbers, we could just do the following:

host # awk '{print $9}' packets|sed 's/Seq=//'
673983919
673983971
673984023
673984075
673984415
673984563
673984711
673984859
673985007
673985155


And, here's where it becomes difficult. The first test of a reasonably stable (by which I mean, unpredictable) sequence numbering algorithm is to subject it two basic tests. That is to say, is it really secure or is it just a simple numeric or mathematic progression in sheep's clothing?

As we bring part 1 of this endeavour to an end, we'll do the quick and dirty testing (If Solaris fails these, then I may have made a big mistake when I named this post before I finished writing it ;)

1. Are the numbers in simple sequence (e.g. +1 or +2) over and over again?
Answer: No. The numeric difference between the packet pairs (1-2, 2-3, etc) are not infinitely exact.
Proof: The 9 differences in order:
673983971-673983919 = 52
673984023-673983971 = 52
673984075-673984023 = 52
673984415-673984075 = 340
673984563-673984415 = 148
673984711-673984563 = 148
673984859-673984711 = 148
673985007-673984859 = 148
673985155-673985007 = 148


2. Is there any direct correlation between the differences between packet sequence numbers and any other property of the packets?
Answer: Yes. If we scroll up the page and look at the basic snoop output, we can see that the difference in sequence numbers correlates exactly with the length of the packet.
Proof: The packet lengths in order:
host # awk '{print $10}' packets|sed 's/Len=//'
52
52
52
340
148
148
148
148
148
148


It seems as though we have something going here, but it must be harder than this to guess the sequence numbers. It's possible, also, that additional measures are being used that obviate the somewhat-flimsy dependence on convoluted number sequences to safeguard a transmission from "packet injection" or hijacking. For instance, Solaris 10 now makes use of SDP as part of its data transmission security (see, also, the Sockets Direct Protocol Manpage). It may also be that Devil is in the details and we only looked at a surface scan of our packets. We'll look at all of these possibilities in a near-future post. This isn't over yet :)

Cheers,

, Mike




Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Wednesday, September 10, 2008

Brain Teaser: Seemingly Random Number List Selection

Hey there,

We're just about done with this series of somewhat disjointed posts on number pools and guaranteed matches. Hopefully, each post in the series has been somewhat entertaining and far enough removed from the starting post that we kept up some sense of originality. It wasn't too hard (unless we screwed up ;) since there were so many unique concepts to cover within the realm of reaching the Objective of the original post. Please refer back to our post on number pools for definitions of all the major terms and a listing of the Objective (although that definition is repeated in a few other posts along the way).

We're just about at the end of the road, so I thought I'd make today's post a bit of a Brain Teaser. The answer to this is actually pretty interesting and (from my struggling with it) you'll either get it right away or it'll take you a good amount of time (kind of like the M I U Puzzle). I, for one, spent way too much time reading up on number sequences and probability. I'm not an engineering major, so I actually had to reference other materials to decipher the Greek alphabet notation. It was interesting for me (especially the insomniac in me), but not something I'd recommend doing unless you're really into it. One thing I noticed, although this is slightly off topic; when people see you sitting in your easy chair chugging diet Pepsi, popping Diphenhydramine and typing in your terminal window with your lap covered with shreds of paper with interpretive numeric scrawl written all over them, they tend to not ask too many questions. It's a great way to guarantee you'll have the evening to yourself ;)

Anyway; for this post's meat: The brain teaser we have today is pretty straightforward, by way of explanation. Here's the setup:

1. Like we did in our posts on deriving list permutations, sorting lists and sorting lists within lists (not necessarily in that order), we've generated a list of 56 5 digit lists using an 8 digit pool of numbers (1, 2, 3, 4, 5, 6, 7, 8). This list represents all possible permutations of the 8 digit list within 5 digit lists while "absolutely removing duplicates" (i.e. "1, 2, 3, 4, 5" and " 5, 3, 2, 4, 1" would be considered equal and would both be removed). That list of numbers follows here (Note that each line is numbered):

1 1 2 3 4 5
2 1 2 3 4 6
3 1 2 3 4 7
4 1 2 3 4 8
5 1 2 3 5 6
6 1 2 3 5 7
7 1 2 3 5 8
8 1 2 3 6 7
9 1 2 3 6 8
10 1 2 3 7 8
11 1 2 4 5 6
12 1 2 4 5 7
13 1 2 4 5 8
14 1 2 4 6 7
15 1 2 4 6 8
16 1 2 4 7 8
17 1 2 5 6 7
18 1 2 5 6 8
19 1 2 5 7 8
20 1 2 6 7 8
21 1 3 4 5 6
22 1 3 4 5 7
23 1 3 4 5 8
24 1 3 4 6 7
25 1 3 4 6 8
26 1 3 4 7 8
27 1 3 5 6 7
28 1 3 5 6 8
29 1 3 5 7 8
30 1 3 6 7 8
31 1 4 5 6 7
32 1 4 5 6 8
33 1 4 5 7 8
34 1 4 6 7 8
35 1 5 6 7 8
36 2 3 4 5 6
37 2 3 4 5 7
38 2 3 4 5 8
39 2 3 4 6 7
40 2 3 4 6 8
41 2 3 4 7 8
42 2 3 5 6 7
43 2 3 5 6 8
44 2 3 5 7 8
45 2 3 6 7 8
46 2 4 5 6 7
47 2 4 5 6 8
48 2 4 5 7 8
49 2 4 6 7 8
50 2 5 6 7 8
51 3 4 5 6 7
52 3 4 5 6 8
53 3 4 5 7 8
54 3 4 6 7 8
55 3 5 6 7 8
56 4 5 6 7 8


2. Using the technique we looked at in our post on determining maximum sets of lists within pools using binomial coefficients, we've deduced that, since we want to guarantee (within the lists in this list of lists) unique 3 digit combinations, we can do so most economically by selecting 8 of the 5 digit lists from the 56. This is not the exact formula we followed in the noted post (as it showed that the binomial coefficient of 8 over 3 is 56). In fairly loose terms, if we want to maximize the odds that we'll get any given 3 digit list (and not use all 56 lists, which works, but is expensive), we can do so with a minimum of 8 5 digit lists. Those 8 lists follow here:

1 2 3 4 6
1 2 3 5 8
1 2 4 7 8
1 3 6 7 8
1 4 5 6 7
2 3 4 5 7
2 5 6 7 8
3 4 5 6 8


3. Using the numbers from point 1 and 2, above, the following chart shows you at what line (in the list of 5 digit lists) each of the 8 lists we determined would give us the best odds of getting a maximum return on a 3 digit list match up.

2 1 2 3 4 6 1 2 3 4 6
7 1 2 3 5 8 1 2 3 5 8
16 1 2 4 7 8 1 2 4 7 8
30 1 3 6 7 8 1 3 6 7 8
31 1 4 5 6 7 1 4 5 6 7
37 2 3 4 5 7 2 3 4 5 7
50 2 5 6 7 8 2 5 6 7 8
52 3 4 5 6 8 3 4 5 6 8


4. Using the numbers from point 1 and 2, above, the following chart shows you at what line (in the list of 5 digit lists) each of the 20 lists we can also determine would give us the best odds of getting a maximum return on a 4 digit list match (We never covered this, but I just added it to give you some frame of reference if the above 3 points aren't enough - BTW, I generated this list because they weren't enough for me, so no offense intended :)

1 1 2 3 4 5 1 2 3 4 5
8 1 2 3 6 7 1 2 3 6 7
9 1 2 3 6 8 1 2 3 6 8
14 1 2 4 6 7 1 2 4 6 7
15 1 2 4 6 8 1 2 4 6 8
18 1 2 5 6 8 1 2 5 6 8
19 1 2 5 7 8 1 2 5 7 8
21 1 3 4 5 6 1 3 4 5 6
22 1 3 4 5 7 1 3 4 5 7
23 1 3 4 5 8 1 3 4 5 8
26 1 3 4 7 8 1 3 4 7 8
35 1 5 6 7 8 1 5 6 7 8
38 2 3 4 5 8 2 3 4 5 8
39 2 3 4 6 7 2 3 4 6 7
42 2 3 5 6 7 2 3 5 6 7
45 2 3 6 7 8 2 3 6 7 8
46 2 4 5 6 7 2 4 5 6 7
49 2 4 6 7 8 2 4 6 7 8
52 3 4 5 6 8 3 4 5 6 8
53 3 4 5 7 8 3 4 5 7 8


Now, here's the fun part. Considering that:

a) no matter how many times we do this using the exact parameters, the results (the lists and the placement of the 8 most economical choices) are totally consistent.
b) If we change anything (like make our list of "1, 2, 3, 4, 5, 6, 7, 8" into "1, 4, 3, 2, 5, 6, 7, 8") about our 8 digit list (assuming that we don't resort everything to numeric order before generating our 8 best 5 digit lists), the outcome will be affected in that the 8 lists will not only contain different numerals, but also end up matching at different numbered locations on master list of 56 lists.

Considering that, how am I determining where to place my 8 5 digit lists in relation to my 56 list list. Or, in other terms, how am I picking the 8 5 digit lists I feel will give me the best odds of matching a 3 digit combination of any 3 unique digits from the 8 digit list used to seed these 5 digit selections?

Think about it, but not too hard. This is only fun if you're having fun with it. If it starts to upset you, watch something violent, yet satisfying (like a good revenge flick), on television and get some sleep ;)

Cheers,

, Mike




Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.