Re: Jetty Session ID Prediction
Amit Klein wrote: > Chris Anley wrote: >> Hi folks, >> I've posted a paper that explains a little more here: >> http://www.ngssoftware.com/research/papers/Randomness.pdf > > > Nice paper. I do notice an enumeration loop over 2^16 possible 16-bit > values. This can be improved as following (note: this is probably > already discussed in mathematic literature - i.e. I probably did not > invent it...): > This should be much faster than looping over 2^16 values. Cheers Amit, that's cool and I'm sure it's faster. There are quite a few neat tricks in the literature - Knuth's paper on predicting lcg's where you're missing the low bits is good (I was trying to work out whether his technique and yours are equivalent; I'm still not sure...), and the paper Michal Zalewski recommended: http://dsns.csie.nctu.edu.tw/research/crypto/HTML/PDF/C89/138.PDF is also neat. One interesting (?) question is whether that technique applies to the mysql rand, which is wierd and custom, and used in the auth protocol prior to version 4.1. I don't think anyone's published the code for a totally generic predictor before, but I might be mistaken. If anyone knows, could they shout...? Anyhow, ultimately, it's a POC for a specific bug. I loop over 2^16 values because it's instant, and easy. :o) Cheers, -chris. -- E-MAIL DISCLAIMER The information contained in this email and any subsequent correspondence is private, is solely for the intended recipient(s) and may contain confidential or privileged information. For those other than the intended recipient(s), any disclosure, copying, distribution, or any other action taken, or omitted to be taken, in reliance on such information is prohibited and may be unlawful. If you are not the intended recipient and have received this message in error, please inform the sender and delete this mail and any attachments. The views expressed in this email do not necessarily reflect NGS policy. NGS accepts no liability or responsibility for any onward transmission or use of emails and attachments having left the NGS domain. NGS and NGSSoftware are trading names of Next Generation Security Software Ltd. Registered office address: 52 Throwley Way, Sutton, SM1 4BF with Company Number 04225835 and VAT Number 783096402
Re: Jetty Session ID Prediction
On Tue, 6 Feb 2007, Amit Klein wrote: > I don't think that the method described in the paper you referenced > above is applicable as-is [...] (only 32 bits out of the 48 are known). There are attacks published for just about any variant of LCG imaginable, including ones with missing MSB/LSB output bits, etc. But I had a chance to talk to David Litchfield and Chris Anley off the list, and they do use an algorithmic approach, not brute force - that was simply a poor choice of words. /mz
Re: Jetty Session ID Prediction
Chris Anley wrote: Hi folks, I've posted a paper that explains a little more here: http://www.ngssoftware.com/research/papers/Randomness.pdf Nice paper. I do notice an enumeration loop over 2^16 possible 16-bit values. This can be improved as following (note: this is probably already discussed in mathematic literature - i.e. I probably did not invent it...): Let us denote the initial state of the PRNG as 2^16*x1+y1, where x1 are the leftmost 32 bits, and y1 are the rightmost 16 bits. x1 is known, and y1 is not. Likewise, the next state is 2^16*x2+y2, where x2 is known and y2 is not. Of course, I'm ignoring small issues such as sign, the 7 possible base choices, etc. - my main focus is replacing the innermost brute-force loop. Now, the following holds (PRNG advance rule): 2^16*x2+y2 = 0x5DEECE66DL*(2^16*x1+y1)+0xBL (mod 2^48). Rearranging, we have: 0x5DEECE66DL*y1 =2^16*x2+y2-0x5DEECE66DL*2^16*x1-0xBL (mod 2^48) Let's further split y1 (a 16 bit quantity) into m*2^13+n (m is 3 bits, n is 13 bits), and re-arrange: 0x5DEECE66DL*n = -0x5DEECE66DL*2^13*m+2^16*x2+y2-0x5DEECE66DL*2^16*x1-0xBL (mod 2^48) Note that at the left hand side of the equation, we have an absolute quantity < 2^48 (n<2^13, 0x5DEECE66DL<2^35). Enumerating over all possible 8 values of m, we also know exactly the absolute value of the right hand side, up to y2, so if we write that as Z+y2, where Z is known (Z=-0x5DEECE66DL*2^13*m+2^16*x2-0x5DEECE66DL*2^16*x1-0xBL) and y2 is not, applying mod 2^48 means ((Z mod 2^48) + y2 ) mod 2^48. Only if (Z mod 2^48) > 2^48-2^16 will y2 make a significant difference, i.e. if (Z mod 2^48)>2^48-2^16 then we need to check for two options: (Z mod 2^48) and (Z mod 2^48) - 2^48. For simplicity, let's assume then that (Z mod 2^48) <=2^48-2^16, which means we can write the following *absolute* equation: 0x5DEECE66DL*n = (Z mod 2^48) + y2 Taking modulo 0x5DEECE66DL we solve y2 (note that y2 is a 16 bit quantity, much smaller than 0x5DEECE66DL): y2= (-(Z mod 2^48)) mod 0x5DEECE66DL If y2 is not a 16 bit quantity, then clearly m is incorrect. Assuming a correct y2, we can find n by dividing: n = ((Z mod 2^48) + y2) / 0x5DEECE66DL And since we have m, we know y1=m*2^13+n. To summarize, the proposed improvement is: Enumerate over all 2^3=8 possible values of m, for each calculate Z=(-0x5DEECE66DL*2^13*m+2^16*x2-0x5DEECE66DL*2^16*x1-0xBL) and in rare (1:2^32) cases, enumerate two possible (Z mod 2^48) values, then calculate y2= (-(Z mod 2^48)) mod 0x5DEECE66DL (reject m's with y2>=2^16) n = ((Z mod 2^48) + y2) / 0x5DEECE66DL y1=m*2^13+n This should be much faster than looping over 2^16 values. -Amit
Re: Jetty Session ID Prediction
On Tue, 6 Feb 2007, Chris Anley wrote: > http://www.ngssoftware.com/research/papers/Randomness.pdf Nice paper, and quite certainly helpful for security testers as far as showing the weakness of standard library PRNGs to others goes. > The idea is eventually to have a tool that performs point-and-click > identification, analysis and prediction of an unknown source of > "randomness", including LCGs but also more advanced generators such as > the Mersenne twister and SHA1PRNG. Now not that I want to be obtrusive than I already am (hi mom!), but http://lcamtuf.coredump.cx/stompy.tgz can very well tell LCGs from SHA1PRNGs - that and do a bunch of other tricks ;-) /mz
Re: Jetty Session ID Prediction
Michal Zalewski wrote: On Mon, 5 Feb 2007, NGSSoftware Insight Security Research wrote: Jetty generates a 64-bit session id by generating two 32-bit numbers in this way, so we end up with an encoded 64-bit integer. By decoding the integer and splitting it into its two component 32-bit integers, we can easily brute-force the generator's internal state. Why on earth would you want to brute-force it? http://www.springerlink.com/content/9jkp3179mj6fwh6m/s http://dsns.csie.nctu.edu.tw/research/crypto/HTML/PDF/C89/138.PDF I don't think that the method described in the paper you referenced above is applicable as-is, because the method requires that the state of the PRNG is known (the coefficients aren't), while in our situation, the coefficients are known, but the state isn't known in fullness (only 32 bits out of the 48 are known). -Amit
Re: Jetty Session ID Prediction
Hi folks, I've posted a paper that explains a little more here: http://www.ngssoftware.com/research/papers/Randomness.pdf The idea is eventually to have a tool that performs point-and-click identification, analysis and prediction of an unknown source of "randomness", including LCGs but also more advanced generators such as the Mersenne twister and SHA1PRNG. Cheers, -chris. -- E-MAIL DISCLAIMER The information contained in this email and any subsequent correspondence is private, is solely for the intended recipient(s) and may contain confidential or privileged information. For those other than the intended recipient(s), any disclosure, copying, distribution, or any other action taken, or omitted to be taken, in reliance on such information is prohibited and may be unlawful. If you are not the intended recipient and have received this message in error, please inform the sender and delete this mail and any attachments. The views expressed in this email do not necessarily reflect NGS policy. NGS accepts no liability or responsibility for any onward transmission or use of emails and attachments having left the NGS domain. NGS and NGSSoftware are trading names of Next Generation Security Software Ltd. Registered office address: 52 Throwley Way, Sutton, SM1 4BF with Company Number 04225835 and VAT Number 783096402
Re: Jetty Session ID Prediction
On Mon, 5 Feb 2007, NGSSoftware Insight Security Research wrote: > Jetty generates a 64-bit session id by generating two 32-bit numbers in > this way, so we end up with an encoded 64-bit integer. By decoding the > integer and splitting it into its two component 32-bit integers, we can > easily brute-force the generator's internal state. Why on earth would you want to brute-force it? http://www.springerlink.com/content/9jkp3179mj6fwh6m/s http://dsns.csie.nctu.edu.tw/research/crypto/HTML/PDF/C89/138.PDF Cheers, /mz
Re: Jetty Session ID Prediction
NGSSoftware Insight Security Research wrote: = Technical Details = java.util.random implements a linear congruential generator, of the following form: synchronized protected int next(int bits) { seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1); return (int)(seed >>> (48 - bits)); } Jetty generates a 64-bit session id by generating two 32-bit numbers in this way, so we end up with an encoded 64-bit integer. By decoding the integer and splitting it into its two component 32-bit integers, we can easily brute-force the generator's internal state. So it outputs the full 64 bit integer (encoded), huh? consider yourself lucky ;-) With Apache JServ, I had to deal with a session ID constructed in a similar manner, yet only the last 6 symbols were output (~31 bits out of the 64). You can read about this in my "Hacking Web Applications Using Cookie Poisoning" (April 2002) - http://www.cgisecurity.com/lib/CookiePoisoningByline.pdf Apache JServ is "example #2" in that text. You may find part of my analysis relevant to this (Jetty) case as well (BTW - do you plan to make your tool/source available?) Regards, -Amit