ModSecurity(TM) is an open source intrusion detection and prevention engine for web applications. It can also be called an web application firewall. It operates embedded into the web server, acting as a powerful umbrella, shielding applications from attacks.
You can download the mod_security from
ModSecurity configuration directives are added to your configuration file (typically httpd.conf) directly.
# mod_security configuration directives
You can prevent the attacks by configuring it in following ways
Cross site scripting attacks
It can protect you from most SQL-related attacks. These are only examples, you need to craft your filters carefully depending on the actual database engine you use.
A filter like this:
SecFilterSelective ARGS "bin/"
will detect attempts to execute binaries residing in various folders on a Unix-related operating system.
Buffer overflow attacks
SecFilterByteRange 32 126
it will only accept requests that consists of bytes from this range.
If you want to support multiple ranges, regular expressions come to rescue. You can use something like:
SecFilterSelective THE_REQUEST "!^[\x0a\x0d\x20-\x7f]+$"
For further information regarding mod_security, please refer following URL