Forum Discussion
DarkSideOfTheQ_
Nimbostratus
Sep 16, 2009Restrict access based off source network
Hello All,
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.
Pages to block:
http://our.domain.com/templates/Test.jsp
http://our.domain.com/templates/Stats.jsp
Data Group "internal-ips"
1.1.1.0/24
2.2.2.0/24
3.3.3.0/24
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
}
}
TIA,
DarkSide
- hoolio
Cirrostratus
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: - The_Bhattman
Nimbostratus
Hi Darkside,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 } }
when HTTP_REQUEST { if { !([matchclass [IP::client_addr] equals $::internal-ips]) } { switch -glob [string tolower [HTTP::uri]] { "*test.jsp" - "*stats.jsp" { discard } } } }
- DarkSideOfTheQ_
Nimbostratus
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. - hoolio
Cirrostratus
Also, if you use a hyphen in a class name, you need to reference it using curly braces ${::class-name}. It's easier to just use underscores. - hoolio
Cirrostratus
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. - The_Bhattman
Nimbostratus
Hi Darkside, - DarkSideOfTheQ_
Nimbostratus
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? - The_Bhattman
Nimbostratus
If you do that you would have to add the datagroup within the switch. It all depends on what condition you want to see evaluated first. - DarkSideOfTheQ_
Nimbostratus
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]" } }
- hoolio
Cirrostratus
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 } }
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects