Forum Discussion
Vince_Beltz_959
Nimbostratus
Oct 22, 2009Drop Doesn't
I've implemented the following iRule to filter out certain user agents from connecting to our servers. Testing with Firefox and the Modify Headers add-on, it seems to work - I get a disconnected message instead of a page when I add one of the filtered strings to my User-Agent field.
However, the guys running the servers have been testing with packet capture, and claim they're still seeing the connection attempts come through. The whole point of this is that we're trying to prevent these connections from hitting the servers at all. Is the drop/event disable/return not the best way to do this?
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::header "User-Agent"]] {
"*torrent*" -
"*azureus*" -
"*windows-media-player*" -
"*microsoft-webdav-miniredir*" {
drop
event disable
return }
}
HTTP::redirect http://targetsite.tld
}
- hoolio
Cirrostratus
Hi Vince, - Vince_Beltz_959
Nimbostratus
Tried changing the drop to TCP::close, and asked the server guys what they saw - here's the response they sent back (with URLs and IPs redacted). Is it just not possible to keep *any* connection request from making it across to the inside servers? - hoolio
Cirrostratus
Can you try this instead with added logging?when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri] with UA [HTTP::header User-Agent]" switch -glob [string tolower [HTTP::header "User-Agent"]] { "*torrent*" - "*azureus*" - "*windows-media-player*" - "*microsoft-webdav-miniredir*" { log local0. "[IP::client_addr]:[TCP::client_port]: Matched UA check. Closing TCP connection." TCP::close } default { log local0. "[IP::client_addr]:[TCP::client_port]: UA didn't check, redirecting." HTTP::redirect http://targetsite.tld } } }
- Vince_Beltz_959
Nimbostratus
Log excerpt below - seems to be working exactly as expected, first allowing a connection, then failing several times as I tested various User-Agent strings from the rule with the Modify Headers add-on. then working again when I disabled all the User-Agent mods. The log entries look exactly the same, just noting "Closing TCP Connection" regardless of the method used, TCP::close, drop, or reject. - hoolio
Cirrostratus
Those logs show that the iRule appears to be working. On the TCP connection from client port 38440, the client makes a request with a legal UA and is redirected. On the same TCP connection, the UA changes to Azuerus and the connection is closed. Did the server get an HTTP request from the "Azureus" client? Did the "Azureus" client get a response or just a TCP close?when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri] with UA [HTTP::header User-Agent]" switch -glob [string tolower [HTTP::header "User-Agent"]] { "*torrent*" - "*azureus*" - "*windows-media-player*" - "*microsoft-webdav-miniredir*" { log local0. "[IP::client_addr]:[TCP::client_port]: Matched UA check. Closing TCP connection." TCP::close } default { log local0. "[IP::client_addr]:[TCP::client_port]: UA check didn't match, redirecting." HTTP::redirect http://targetsite.tld } } } when SERVER_CONNECTED { log local0. "[IP::client_addr]:[TCP::client_port]: connection to [IP::server_addr]:[TCP::server_port]" } when HTTP_REQUEST_SEND { clientside { log local0. "[IP::client_addr]:[TCP::client_port]: UA [HTTP::header User-Agent], request to [HTTP::uri]" } }
- Vince_Beltz_959
Nimbostratus
Added the extra sections, but they don't seem to be writing anything to the log, even when the Firefox UA is unmodified and a successful connection to the redirect page is made. - hoolio
Cirrostratus
Can you clarify what you see from the client perspective and in tcpdumps on the client and serversides when using the above rule with TCP::close? From the logs you posted, it looks like it is working successfully. - Vince_Beltz_959
Nimbostratus
I'm working on getting captures from the server side, but here's one I just did from my workstation - even though the client browser just shows "connection reset", the trace does show that redirect is being sent back to the client, and a subsequent connection between the client and the redirect target. - hoolio
Cirrostratus
Thanks for posting the client trace. Can you post the LTM logs from the same test? - Vince_Beltz_959
Nimbostratus
Oddly, using the exact same iRule with log statements that I had been using in our Test LTM environment, the F5 logs from our Prod hardware (which is what I was hitting when I produced that packet capture) show nothing at all for this traffic. In Prod we have a VIP set up in the "Local Traffic" area of our GTM with the iRule attached, which bounces traffic to a partner and then back through a WIP set up on the same device.
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