I'm running this on my staging server for the first time and I think I did everything correctly. I can see entries in modsec_audit.log when I run nikto2 against it, but for the life of me I can't manually make mod_security block anything. I've dropped SQL into URLs, into forms, etc and I just got our typical user friendly HTML 404 page, not a block from mod_security, which should be a 403 error or an outright block.
I'm worried that its only detecting and not stopping. I've checked my config and its definitely set to stop attacks not just detect them. Any idea on how I can verify this thing is actually blocking attacks? Anyone have a test URL or something I can do that will prove to me that its actually working?
By default the engine will only be detecting mode:
You need to adjust
SecRuleEngine On
and restart Apache.
In your browser try to access a website hosted on that server like in this example:
Then check Modsecurity log and you'll have something similar (If you have WHM / cPanel -> check in WHM -> Modsecurity Tools to see the log):
The detailed log will be like:
If you'll see a similar log then you can be sure your Modsecurity is activated and working.
I found an answer to this. Just visit your site like so: example.com/etc/passwd
That'll bring up an instant 403 from mod_security and log it in its default log.
I have a check as below
If you get a
403
, then ModSecurity is working as expected.You could have a look at Rapid7 guide for basic configuration.
https://blog.rapid7.com/2017/04/09/how-to-configure-modsecurity-with-apache-on-ubuntu-linux/
There are a couple of test curls which should produce log entries. The log entries appear in both /var/log/apache2/access and /var/log/apache2/modsec_audit.log depending on your setup
XSS test
SQL injection
You can Google for some online 'XSS tester' or 'XSS scanner' and let the tool to carry out a few solicited attacks on your staging site. The tool might also provide you with a report detailing the outcome of the 'attack'.
You can then tail your logs to see if the entries match with the report, particularly the date, time and IP address if there's any.
Try this:
https://example.com/?id=1 and 'c'='c'
Replace example.com with your domain name. use the whole URL as highlighted above. This should return 403.