The technology would be similar to that used in hearing aids and noise-cancelling headphones. But it is also probably an order of magnitude or two more expensive just because the primary customers are tax-funded.
Without electronics, I could also conceive of an earplug with a winding channel bored through it, past flaps that can block the channel by moving too far in either direction and forming a seal with the outer wall of the channel. Sound energy above a certain level would push the flaps closed as the air vibrated, and would thus attenuate louder sounds to a greater extent than quieter ones. If the flaps were tuned to different sound energies, the loudest sounds would push closed the most flaps.
That would require some precise machining to fit inside the outer ear canal. The electronic filter might actually be cheaper.