Security related source code changes all too often to have but a few choice examples of attack and defense. The number of released example programs grows daily. Just go to BugTraq and do a download if that is your thing.
Papillon Solaris Security Module - this is a security module for Solaris 8. The code was inspired by Solar Designer's Openwall Kernel Patch for Linux and the HAP Linux Kernel Patch Papillon implements most mechanisms introduced by these two patches into the Solaris OE and therefore adds new security mechanisms to your Solaris system.Very cool!
Example of a simple exploit. I picked this one for it's simplicity, and as a good example of shell code for sparc solaris. For those intetrested, this is available on BugTraq. Should not need to be said, but please do not be an idiot and use this on a machine that is not yours.