Atomicorp modsec rules

#1
There is a problem with rules skipping when it should not skip from what I understand.

This is explanation from atomi guys:

Thank you, we do have a pretty good working relationship with litespeed so yes we'll definitely be opening a bug report with them. So for your benefit here is what I'm seeing, this rule:

SecRule REQUEST_URI "(?:/(?:(?:wp-admin/(page|post|widgets|link|network/site-settings\.php|options|themes/basic/themify/img\.php\?src=|admin\.php?cf/cf\.php)|admin/(?:edittemplate|webpage_update|theme-options|add_edit_)|(?:signup|cpinquiry|profile))\.php|p(?:(?:hpbb\/install\/install\.ph|l\/download\?file=htt)p|roxy\/cb_proxy\.\?a=http:\/\/)|i(?:ndex\.php\/admin\/system_config\/save\/section\/payment\/|mp\/compose\.php)|tiki-(?:eek:bjectpermissions|editpage|view_cache)|jomsocial\/[a-z]+\/(?:edit|add))|^(?:\/(?:(?:[a-z0-9\-]+\/events\?(?:utm_|trk_)|node\/[0-9]+\/(?:edit|add)|[a-z]+\/unsubscribe)|(?:mysqldumper\/dump|xmlrpc)\.php$|go\.php\?u=affilorama&t=http:\/\/|\.services\/sitelogout)|/(?:b/ss/mxmacromedia|horde/services/go|node/add|cas/))|(?:(?:jw_allvideos_player|mod_mp3player)\?(?:file|playlist)=htt|ubbthreads\/admin\/dofeatures\.ph)p|ad-?server\/adjs|\?mode=addshout|^/administrator/index\.php\?option=com_rsform|^/index\.php/profile/register/registerprofile|^/[a-z]+/edit|^/(?:elements|admin/media)/(?:s(?:ave|ettings?)|appearance)/|^/panel\?comd=nlwebform|^/cocms/index\.php\?|^/ls_javascript_combine/|^/index\.php\?option=com_rsform|^/killboard/\?a=admin_idfeedsyndication|^/api/users|^/numo/module/form_handler/|^/admin/add_edit_document)" phase:2,id:333814,rev:6,pass,t:none,t:lowercase,nolog,skipAfter:END_INJECTION_RULES_1

Is a special rule, basically it looks for known cases where the application is known to work with things like url= http://www.example.com, and when the rules see this kind of app they skip over rules like the test you were running. In your case I see litespeed processing the rule, but not handling it normally:

2015-05-26 01:09:34.916 [INFO] [xx.xxx.xx.xxx:34099-0#APVH_xx.xx.xx.xx:80 xx.xx.xx.xx:80 xx.xx.xx.xx:80 xx.xxx.xxx.xx:80_xxxxxxxxxxxxxxxxxxxxxx] [SECURITY] [ID:333814] match [REQUEST_URI] against pattern [(?:/(?:(?:wp-admin/(page|post|widgets|link|network/site-settings\.php|options|themes/basic/themify/img\.php\?src=|admin\.php?cf/cf\.php)|admin/(?:edittemplate|webpage_update|theme-options|add_edit_)|(?:signup|cpinquiry|profile))\.php|p(?:(?:hpbb\/install\/install\.ph|l\/download\?file=htt)p|roxy\/cb_proxy\.\?a=http:\/\/)|i(?:ndex\.php\/admin\/system_config\/save\/section\/payment\/|mp\/compose\.php)|tiki-(?:eek:bjectpermissions|editpage|view_cache)|jomsocial\/[a-z]+\/(?:edit|add))|^(?:\/(?:(?:[a-z0-9\-]+\/events\?(?:utm_|trk_)|node\/[0-9]+\/(?:edit|add)|[a-z]+\/unsubscribe)|(?:mysqldumper\/dump|xmlrpc)\.php$|go\.php\?u=affilorama&t=http:\/\/|\.services\/sitelogout)|/(?:b/ss/mxmacromedia|horde/services/go|node/add|cas/))|(?:(?:jw_allvideos_player|mod_mp3player)\?(?:file|playlist)=htt|ubbthreads\/admin\/dofeatures\.ph)p|ad-?server\/adjs|\?mode=addshout|^/administrator/index\.php\?option=com_rsform|^/index\.php/profile/register/registerprofile|^/[a-z]+/edit|^/(?:elements|admin/media)/(?:s(?:ave|ettings?)|appearance)/|^/panel\?comd=nlwebform|^/cocms/index\.php\?|^/ls_javascript_combine/|^/index\.php\?option=com_rsform|^/killboard/\?a=admin_idfeedsyndication|^/api/users|^/numo/module/form_handler/|^/admin/add_edit_document)], result: 0

Which correctly returns a "no match", hence the "result: 0". Only if its a match should it skip to a mark in the rules (modsec has a GOTO type language) skipping over a bunch of rules. Since its not a match it should continue to process, but its not going on to the next rule, it seems to be skipping over it, which it shouldnt be doing. The next rule we should see processed is 340162, which sometimes we do see processed on your system:

grep 340162 debug_log | wc -l
2

So sometimes this is processed correctly, other times its not and even in those cases the same result: 0 on rule 333814. So something isnt working right in litespeed and it seems intermittent, 340162 sometimes gets processed, and sometimes it gets skipped. Which means other things are getting intermittently skipped if this internal test is failing.

As I said before, the litespeed guys have been pretty good at working with us when we report bugs to them in litespeed, so we'll open a bug report with them. You may want to do the same yourself just so you can track this issue.

We'll get to the bottom of this, and appreciate your patience as we work with them to find out why litespeed is doing this.
I submitted this 2 months ago to bug report email but received no reply. Is there anyone alive at ls who can tell me if it will be fixed or acknowledge the bug?
 

mistwang

LiteSpeed Staff
#4
What is the test case it failed? a request contain a url not pointing it its own domain. Please give us an example.
Is it failed to detect certain attack? or generate false positives?
 
#8
Test one worked but only when I created foo.php file - it means that ls is checking if file exists first. So one part of mystery is solved.

But joomla rule is still not triggered even when file exists. You should be able to check it on Your server without problem with files I provided.

Cant give access to server due to privacy laws and client contracts.
 

mistwang

LiteSpeed Staff
#10
That rule require "HEAD" method, so, you need to send a HEAD request when you test it.
#plugin_googlemap2_proxy.php?url=loxer.cf
SecRule REQUEST_METHOD "@streq HEAD" \
"phase:1,chain,log,drop,status:403,auditlog,t:none,id:336468,rev:1,severity:2,msg:'Atomicorp.com WAF Rules - Virtual Just In Time Patch: Google Maps plugin for Joomla probe'"
SecRule REQUEST_URI "plugin_googlemap(?:2_proxy|3_kmlprxy)\.php\?url=" "t:none,t:urlDecodeUni,t:lowercase"
 
#13
From modsec wiki

Note : Keep in mind that rules are executed according to phases, so even if two rules are adjacent in a configuration file, but are set to execute in different phases, they would not happen one after the other. The order of rules in the configuration file is important only within the rules of each phase. This is especially important when using the skip and skipAfter actions.

and

The skipAfter action works only within the current processing phase and not necessarily the order in which the rules appear in the configuration file. If you place a phase 2 rule after a phase 1 rule that uses skip, it will not skip over the phase 2 rule. It will skip over the next phase 1 rule that follows it in the phase.

So if rule 309200 that is phase 2 affects joomla rule from phase 1 it looks like this is not how it should work but i will ask atomi support for confirmation. To me it looks like a bug in mixing phases in litespeed if it really is skipping according to rule 309200.
 

mistwang

LiteSpeed Staff
#14
OK, I see.
The reason is that LiteSpeed combine Phase 1 and Phase 2 and process all rules in one round, when there is no request body.
Unless we do two round processing, which is slow, this problem cannot be avoided.
 
#15
Well this is broken modsec. If modsec processing is too slow for main thread maybe you can offload it on dedicated process/processes and keep main thread free for just processing http. Like email servers offload antispam processing to spamassasin demon and its subprocesses.

I think after so many years we need working modsec already. This is kind of important feature.
 

innovot

Well-Known Member
#16
Agree with OP on this, and also see the issue from mistwang. Without tight modsec rule processing then it does become mute as to what the benefits are to using them in LiteSpeed. Have mentioned on another thread about perhaps leveraging the libmodsecurity1 project, whom authors the ModSec main code base, instead of re-inventing the wheel with your own engine. They may well welcome you with open arms to help with code contribution. This is not a criticism, and would be difficult when we have not purchased licenses yet, but does effect whether we would consider purchasing or not. Security is paramount to our clients and it feels at present we may end up going backwards instead of forwards unless these issues are addressed.

1 https://github.com/SpiderLabs/ModSecurity/tree/libmodsecurity
 

mistwang

LiteSpeed Staff
#17
We will have it addressed.
Will use libmodsecurity with our openlitespeed product.
If it really have better performance than our own re-invented ModSecurity engine, we will switch over if the software license allows.
 

innovot

Well-Known Member
#18
Do appreciate when you say about performance, but if your engine is that much faster then does a double pass cause that much of an issue? Have seen quite a few threads about ModSec now, and a couple of RFEs from myself, so perhaps a roadmap on where you envisage this going would help others ?
 

mistwang

LiteSpeed Staff
#19
but if your engine is that much faster then does a double pass cause that much of an issue?
Probably not, Just wont go with the slower path if have a better choice.
Actually, in this case, we will completely separate the rules for different phases. wont mix them together at all. Still one pass processing.
Since ModSecurity project keep evolving, our goal is to keep up with it and make it compatible with popular rule sets.
A few missing features that will be added soon are: fileinspect and RBL lookup. Some other new operators added recently.
 
Top