it's projection geometry. You create a geometry object with the earth's surface shape. Another with the moon's surface shape. Then, a light source that emits from a sun's shape. All objects are placed at the appropriate distances, and made to rotate and translate through space according to normal orbits.
Then, you project the light from the sun onto the earth, with the moon in-between. This creates the 2D shape on the earth's surface corresponding to the shadow.
I've set up something very similar to this in Blender, although its floating point precision was too low, so I had to fudge things a bit.