I currenlty use an irule that I use to restrict traffic to certain paths:-
when HTTP_REQUEST {
if {([matchclass [HTTP::uri] starts_with $::securePaths]) and not ([matchclass [IP::client_addr] equals $::trustedAddresses])}{
log local0. “Untrusted IP ([IP::client_addr]) attempting to access secure path ([HTTP::uri])”
discard
} else {
log local0. “Allowing connection from [IP::client_addr] to [HTTP::uri]”
}
}
However I have just discovered that the paths I have in the data group appear to be case sensitive so \test\ as a restricted path can be circumvented by using \Test\. How do I get around this? I don’t wish to add every possible path upper and lower case to the datagroup - I will be here until next Christmas!
If you add the datagroup items in lower case, you can set the request to lower case before using matchclass to test the URI. Also, it would be more efficient to use HTTP::path versus HTTP::uri assuming you’re not looking for the query string in the URI.
when HTTP_REQUEST {
if {[matchclass [string tolower [HTTP::path]]...
If you’re doing this for security, you might want to consider the different ways malicious users could try to obfuscate the path. The simplest way to bypass your logic might be to prepend an extra forward slash. I think most versions of IIS will accept this. For example this request to MS’s main page works: http://www.microsoft.com//////////en/us/default.aspx. There are quite a few different encoding methods that would also be parsed as valid requests by the web server.
Hopefully you’re performing authentication/authorization on the application as well.
I don’t think you can use wildcards in a datagroup with matchclass or findclass. You’d need to loop through each datagroup element and use string match. Check this post on this for details/examples:
Thats looks an option but does not look like a particularly stright forward one to put together.
Adding the string tolower sorts out any case type issues but obviously it does not sort the ///// issues which is where it falls down from a security perspective. Is there a way I could write some logic so that if it see’s multiple slashes it replaces it with just one? Perhaps some sort of URI rewrite before the matchlass rule?
You could use regsub to handle multiple slashes (regsub -all /+ [HTTP::uri] result), but there are quite a few other techniques attackers could use to obfuscate the URI to bypass any blacklist.
Another example is using backslashes instead of forward slashes. IE and IIS accept this. Attackers can also break up the URI using periods for current directory and previous directory:
There are also different ways to encode the characters in the URI. Here is a PDF I found which describes these and other obfuscation methods (Click here)
Trying to handle every attack method in an iRule is going to be a losing battle. If you’re able to use a whitelist you’d be in a much better position.
Aplogies for sounding a bit dim here but what do you class as a whitelist?
I thought the irule we are using is already a whitelist in that it only allows access to Ip addresses contained in the data group for the URI specified in the other data group.
You could always change the equals in the HTTP::path matchclass to a contains, as long as nothing that shouldn’t be restricted contains the paths you’re storing in your class. That should account for the //. It’s not a precise workaround, but it should work.