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
http://www.modsecurity.org/download/
ModSecurity configuration directives are added to your configuration file (typically httpd.conf) directly.
<IfModule mod_security.c>
# mod_security configuration directives
# ...
</IfModule>
You can prevent the attacks by configuring it in following ways
Cross site scripting attacks
SecFilter "<script"
SecFilter "<.+>"
The first filter will protect only against JavaScript injection with the tag. The second filter is more general, and disallows any HTML code in parameters.
SQL/database attacks
SecFilter "delete[[:space:]]+from"
SecFilter "insert[[:space:]]+into"
SecFilter "select.+from"
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
http://modsecurity.org/documentation/modsecurity-apache/1.9.3/html-multipage/index.html