Sanity check…I’m trying to block access to specific pages based off the source network the client is coming from. The rest of the site should remain available to anyone. I *think* I’ve got the irule down, but am not 100% sure and would appreciate some more knowledgeable input.
when HTTP_REQUEST {
if { ([HTTP::uri] contains "Test.jsp") or ([HTTP::uri] contains "Stats.jsp") and not ([matchclass [IP::client_addr] equals [$::internal-ips]]) } {
discard
}
}
That will technically work. However, even with java-based platforms there are methods an attacker can use to obfuscate their request. We discussed this in a recent post:
I think your logic looks sound. I would put a open and close parentheses around the URI conditional evaluations so they are evaluated together before the matchclass evaluation. I would also lose the square brackets around $::inernal-ips and lowercase the URI
Like so
when HTTP_REQUEST {
if { !([matchclass [IP::client_addr] equals $::internal-ips]) and ((string tolower [[HTTP::uri]] contains "test.jsp") or (string tolower[HTTP::uri]] contains "stats.jsp")) } {
discard
}
}
I wrote it the way above because I thought the first thing you want to evaluate is the Datagroup. if nothing matches then don’t evaluate any further. In theory, it would make evaluations much faster then having to evaluate 3 conditions expressions in an IF clause.
Aaron - good post, not sure how i missed that in my earlier search. I didn’t even think about obfuscation as I don’t think the page is all that “secret”, so a basic discard should suffice, but I’ll have to ask.
CB - In your examples, (I’m probably misinterpreting them) it looks like the logic would discard if the client IP matches the data group, is that right?
The idea behind obfuscation is that an attacker could request /test.jsp as /%74%65%73%74.jsp using URL encoding, possibly use unicode as / \ x 74 \ x 65 \ x 73 \ x 74.jsp (without the spaces) and/or other encoding methods and the web server would potentially parse them all as /test.jsp even though the iRule doesn’t.
Aaron - In that other post you linked me to, you mention an irule isn’t the best approach to dealing with obfuscation. How would you recommend handling that if I am told they want it secured better?
CB - I figured I wasn’t interpreting it correctly, not seeing ‘else’ mentioned in there threw me off. In terms of making evaluations faster, could i put the ‘switch -glob…’ part before the data group? In theory, it would stop processing if it didn’t see ‘test.jsp’ or ‘stats.jsp’, correct?
OK - i’m officially lost here. I put in the irule I first posted. However, it seemed to discard anything, I couldn’t get to the page from a host specified by network or specifically. I added in the log value and saw it in the logs, but the page no workie. I removed the discard piece and could access the pages. Unfortunately, I could access them from hosts not specified in my datagroup. Where is this breaking down???
when HTTP_REQUEST {
if { ([HTTP::uri] contains "Test.jsp") or ([HTTP::uri] contains "Stats.jsp") and not ([matchclass [IP::client_addr] equals [$::ips_internal]]) } {
log local0. "test connection from [IP::client_addr] to [HTTP::uri]" }
}
From log:
Sep 16 16:46:07 tmm tmm[959]: Rule secure_test : test connection from to /templates/Test.jsp
Sep 16 16:46:31 tmm tmm[959]: Rule secure_test : test connection from to /templates/Test.jsp
Goal: restrict access to the ‘test.jsp’ and ‘stats.jsp’ from anyone except specific internal networks, rest of site needs to remain open to anyone.
Edit: Actually, since I removed the ‘discard’ for testing, I know that’s why it’s allowing anyone not in my datagroup to access those pages. However, shouldn’t I only see in the logs, hosts/networks specified in my datagroup?
You could add more logging to find out what’s happening:
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::local_port]: Request to [HTTP::uri]"
if { ([HTTP::uri] contains "Test.jsp") or ([HTTP::uri] contains "Stats.jsp") and not ([matchclass [IP::client_addr] equals $::ips_internal]) } {
log local0. "[IP::client_addr]:[TCP::local_port]: Discarding request to [HTTP::uri]"
discard
}
}
Also, as CB pointed out, you should remove the square braces around the datagroup name. That would probably trigger a runtime TCL error as you’d be trying to execute the contents of the class. If that still doesn’t work, you could break up the URI and IP address checks into separate if statements with more logging.
I removed the braces around the datagroup as CB suggested and it still didn’t work. Added in the extra logging as you suggested, which was helpful as it appears to be ignoring the datagroup alltogether.
Can you list the contents of the class (using ‘b class ips_internal list all’) and your client IP address. If you want to anonymise the IP’s, just change the first two or three octets.
Here is an example of the default private_net datagroup on a 9.4.8 unit:
b class private_net list all
class private_net {
type ip
filename none
mode rw
partition Common
network 10.0.0.0/8
network 172.16.0.0/12
network 192.168.0.0/16
none
none
}
Thanks,
Aaron
Sep 17 10:04:09 tmm tmm[959]: Rule secure_test : 99.99.220.62:80: Matched IP check. Discarding request to /templates/Test.jsp
The first log line, should that log client info for ONLY members of the datagroup? It’s logging client info for any request made and even mentions the dg parameter, so I’m a bit confused on that.
Sep 17 10:03:47 tmm tmm[959]: Rule secure_test : 2.60.0.104:80: Request to /resources with dg: {1.1.0.0/20} {2.2.0.0/22}
*2.60.x.x is a vpn range in the 2.2.0.0 office (i changed first two octets)
when HTTP_REQUEST {
if { [HTTP::uri] contains "Test.jsp" or [HTTP::uri] contains "Stats.jsp" }{
if {not [matchclass [IP::client_addr] equals $::ips_internal]} {
log local0. "[IP::client_addr]:[TCP::local_port]: Matched IP check. Discarding request to [HTTP::uri]"
discard
}
}
}
In anticipation of them adding more pages they want secured, I tried the ‘-glob’ mechanism, but the GUI tells me “line 5: [missing an expression] [ ]” but not sure what’s missing???
when HTTP_REQUEST {
switch -glob [HTTP::uri] {
"Test.jsp" -
"Stats.jsp"
if {not [matchclass [IP::client_addr] equals $::ips_internal]} {
log local0. "[IP::client_addr]:[TCP::local_port]: Matched IP check. Discarding request to [HTTP::uri]"
discard
}
}
}
Help is appreciated, my irule kung-fu isn’t so strong.