News for hackers. Stuff that matters.
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by tptacek on Friday August 16, 2013 @06:24PM (#6227066)
I thought the approach they took to permuting the address space was particularly clever, but was quickly schooled on Twitter by how bog-standard the approach apparently is (I very much concede the point!). In the interest of honesty about how easily impressed I am, and because I still think it's a neat little trick:

You want to generate a permutation of the entire IPv4 address space, but you don't simply want to shuffle every possible IP address because that would require you to keep an insane amount of state. So instead, work in the multiplicative group modulo p for prime p > 2^32, find an appropriate generator, and iterate by multiplying with the generator mod p. Remember the prime, the generator, the starting address, and your current address and you can detect a complete traversal of the space when the starting address recurs.

There are a number of simpler ways to do this (after sheepishly conceding that this is pretty fundamental stuff, I played with using PRFs and card shuffling to do it; DrHoney suggested Gray codes), but I liked how immediately obvious the multiplicative group solution was, and that I could code it from a simple description.

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by aortega on Saturday August 17, 2013 @12:28AM (#6228160)
The problem of generating a non-repeating (2^n)-1 n-bit numbers permutation is equivalent to generating a m-sequence (http://en.wikipedia.org/wiki/Maximum_length_sequence) and the simplest way is a n-bit LFSR with a primitive poly, called maximal LFSR. It's so much simpler and faster (some XORs and n bits of memory), I cannot see why they chose that weird prime multiplication algorithm, in fact right now I'm not completely sure that algorithm is correct.
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by aortega on Saturday August 17, 2013 @01:14AM (#6228238)
Furthermore, is not that a way to describe a Linear Congruential Generator (You know, rand()?) http://en.wikipedia.org/wiki/Linear_congruential_generator by looking at the source (https://github.com/zmap/zmap/blob/master/src/cyclic.c#L164) it really looks like it, specifically a Lehmer random number generator. That would mean the period of the generator is not exactly 2^32 but it repeats 15 IPs... EDIT: Now I see it, it actually generates numbers over 2^32 but the code just skips them...nasty! I'm surely missing something, or else that's a usenix paper wasting 2 pages explaining rand()
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by tptacek on Saturday August 17, 2013 @10:29AM (#6229169)
It's not literally rand, but is a form of LCG, just tuned for IP addresses.

I agree with you about the formal impact of the "math" here. The irony is that I'm not impressed by the scanner stuff, and easily impressed by simple math!

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by pbsd on Saturday August 17, 2013 @12:04PM (#6229433)
A 32-bit LFSR generates a sequence of bits with period 2^32-1; what you really want is a Lehmer-like generator using arithmetic in GF(2^32).
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by tptacek on Saturday August 17, 2013 @02:01PM (#6229781)
You mathematicians, with your... understanding of the basic mathematics behind things we developers already use every day, you all think you're better than us, don't you? DON'T YOU?!

Can't I just be left to be impressed by a direct use of the math behind a crappy textbook random number generator in peace?

-.-

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by pbsd on Saturday August 17, 2013 @07:38PM (#6230804)
I'm not 100% sure if that was tongue-in-cheek or not, so I'll clarify: I was disagreeing with aortega. This is not a typical PRNG, where the seed generally marks the initial point of the same sequence. Choosing a random generator matters, because we want a different permutation every time, not simply a different starting point. It is akin to running a block cipher in OFB mode with a different key each time.

What they are doing modulo 2^32 + 15 is IMO the simplest way to achieve that goal. Yes, you could do it without overflowing 2^32 using a binary field; you could also cook your own mini block-cipher. But that increases the complexity of the code and is not really faster everywhere.

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by tptacek on Saturday August 17, 2013 @07:55PM (#6230875)
It was 100% tongue-in-cheek, but I'm happy to be extracting even more information from you by having my poor attempts at humor misconstrued. :)
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by aortega on Monday August 19, 2013 @12:42PM (#6238155)
>Choosing a random generator matters, because we want a different permutation every time, not simply a different starting point.

Ah thanks, now it makes more sense, I knew I was missing something. What about choosing different prime polys for a galois lfsr? I believe you will get the same result.

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by aortega on Monday August 19, 2013 @06:36PM (#6240361)
Also you could XOR the LFSR output with any number to get a different permutation each time.
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by tga_d on Sunday August 18, 2013 @09:11PM (#6235053)
What does "GF(2^32)" mean in this context?
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by pbsd on Sunday August 18, 2013 @10:12PM (#6235220)
It's the finite field with 2^32 elements. There are several equivalent representations, but we typically work with it as the polynomials with coefficients modulo 2 modulo an irreducible polynomial of degree 32, e.g., x^32 + x^7 + x^3 + x^2 + 1. For more, see [1].

[1] https://en.wikipedia.org/wiki/Finite_field_arithmetic

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by xyzzy123 on Friday August 16, 2013 @10:42PM (#6227985)
I used skip32.c, but I like their approach too.
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by buddydvd on Saturday August 17, 2013 @05:56AM (#6228661)
+1 for skip32.c since it's O(1) space and O(1) time. With the prime approach, you may need to call it multiple times to reject numbers greater than 2^32-1. Also, a generalized Feistel algorithm may be used to generate permutations with fewer than 32 bits with the same constant space/time requirement and may be helpful in skipping specific IP ranges.
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by xyzzy123 on Sunday August 18, 2013 @04:22AM (#6232092)
Thanks, the theory of generating secure-ish permutations of arbitrary size (at least, small ones) isn't that well developed and I hadn't considered generalizing feistel structures to other bit sizes. It's an interesting research topic IMHO. '

I have to admit that I'm slightly chagrined by the disparity of approach between a lame-ass pentester and an associate professor and two PHD candidates. Reverse elitism, it lives.

I still find the decision to release to be an interesting choice; I didn't because I felt that it would lead to an increase in Internet background radiation, and that basically it's an obvious approach and anyone working in this area will come to exactly the same conclusions. Beer soaked napkin calculations will lead everyone to exactly the same scanner. From my POV there was little benefit in giving this crap to people who wouldn't make the same calculations and write the same code.

What amused me for a while was how long we could get away with being the top "malicious" source on DShield [hint, this requires a ridiculously high packet rate - but it was less than 50k PPS :]. But if you use zmq and distribute your targets that way between a bunch of scan agents, you can get off the top 10 list. Also you can do a scanner like this with a lot less SLOC. The correct architecture is "ip distributor", "scan agent", "listener". They're sort of conflating.

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by tptacek on Saturday August 17, 2013 @10:33AM (#6229181)
FWIW:

http://www.cs.ucdavis.edu/~rogaway/papers/subset.pdf

(Marsh Ray tweeted this yesterday; it's an easy read)

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by buddydvd on Sunday August 18, 2013 @05:19AM (#6232166)
Thanks for the link. Awhile back, I had implemented an n-bit cipher (where 1 <= n <=64) with an unbalanced Feistel network and used hash function as the basis of the round functions. I then wrap it within a cycle-walking function to form a cipher for any number smaller than 2^64. I did all this so I can generate scrambled 5-char path IDs of short URLs (e.g. test.com/xA7bc) with domain size of 62^5.
Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by wmf on Friday August 16, 2013 @11:30PM (#6228068)
work in the multiplicative group modulo p for prime p > 2^32, find an appropriate generator, and iterate by multiplying with the generator mod p

Is that the same as a PRNG with period 2^32-1? I thought I read that idea in the Warhol Worm paper, but looking again it uses a block cipher so I was probably thinking of the Witty worm.

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by tptacek on Saturday August 17, 2013 @10:30AM (#6229171)
Well, it's obviously a PRNG. :)

The Sapphire worm used a similar approach, and got the math so distinctively wrong that Vern Paxson was able to fingerprint it, reverse the generator, and take a stab at "patient zero" (I think I'm remembering this correctly).

Re:ZMap: Internet scanner maps all of IPv4 in 45 minutes by wepple on Sunday August 18, 2013 @09:15PM (#6235069)
What kind of math knowledge is required to understand this? Abstract Algebra?

I've noticed recently I'm coming unstuck on particular CS problems (notably crypto as well), and have realised I need to further my math knowledge greatly.