Drop 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

}

Hi Vince,

I was just testing the drop command with HTTP responses. What F5 came back with was that the command would prevent the response body from being sent to the client, but the HTTP headers which had already been parsed would be sent back to the client. I didn’t test calling drop from HTTP_REQUEST, but I’d guess that a similar behavior would be expected where the HTTP headers would be sent to the server, but any body from the request would be dropped. That’s just a guess though.

From C574762:

1. If I check a status code in HTTP_RESPONSE, see it’s one I don’t like, and call ‘drop’ or ‘discard’, does it just prevent the current payload from being sent to the client?

Calling “drop” or “discard” in the HTTP_RESPONSE event prevents LTM from accepting (ACKing) the TCP packet which contains the HTTP body (packet is processed); additionally, only the HTTP headers will be forwarded to the client and the client side of the connection will abort (RST).

In the tcpdumps on the server side (or on the server itself), do you see a connection attempt being made, or a connection attempt being made and HTTP headers being sent?

Maybe it would be better to close the clientside TCP connection using TCP::close rather than using drop? Could you try this and check the client and serverside behavior?

Thanks,

Aaron

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?

---

I set the user agent to “torrent” in Modify headers tool and accessed http://x.tld as as a test url.

Below are the request and response as seen in wireshark.

Request to VIP:

GET /as HTTP/1.1

Host: x.x.x.x

User-Agent: torrent

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Response from VIP

HTTP/1.0 302 Found

Location: http://x.tld

Server: BigIP

Connection: Keep-Alive

Content-Length: 0

So even if the TCP connection is closed and there is no body, the header “Location” and status code 302 makes the browser do a request to

http://x.tld

The redirect statement is still getting executed.

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 
       } 
    } 
 }

If TCP::close doesn’t work, can you try reject instead? This should trigger LTM to send a RST packet to the client.

Can you post anonymized copies of the logs from both TCP::close and reject?

Thanks,

Aaron

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.

Oct 22 15:19:19 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:38440: New GET request to x.x.x.x/ with UA Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)

Oct 22 15:19:19 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:38440: UA didn’t check, redirecting.

Oct 22 15:19:54 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:38440: New GET request to x.x.x.x/ with UA Azureus

Oct 22 15:19:54 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:38440: Matched UA check. Closing TCP connection.

Oct 22 15:19:54 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:39202: New GET request to x.x.x.x/ with UA Azureus

Oct 22 15:19:54 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:39202: Matched UA check. Closing TCP connection.

Oct 22 15:19:54 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:39207: New GET request to x.x.x.x/favicon.ico with UA Azureus

Oct 22 15:19:54 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:39207: Matched UA check. Closing TCP connection.

Oct 22 15:19:57 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:39235: New GET request to x.x.x.x/favicon.ico with UA Azureus

Oct 22 15:19:57 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:39235: Matched UA check. Closing TCP connection.

Oct 22 15:21:09 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:39925: New GET request to x.x.x.x/ with UA Windows-Media-Player

Oct 22 15:21:09 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:39925: Matched UA check. Closing TCP connection.

Oct 22 15:21:29 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:40201: New GET request to x.x.x.x/ with UA Torrent

Oct 22 15:21:29 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:40201: Matched UA check. Closing TCP connection.

Oct 22 15:21:36 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:40254: New GET request to x.x.x.x/ with UA Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)

Oct 22 15:21:36 tmm tmm[1121]: Rule filter.useragent : x.x.x.x:40254: UA didn’t check, redirecting.

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?

The rest of the logs seem to indicate that any restricted UA request is closed successfully.

If it’s not working, you could add more debug logging to show the server connection and request being sent:

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]" 
    } 
 }

Thanks,

Aaron

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.

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.

Thanks,

Aaron

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.

Thanks for posting the client trace. Can you post the LTM logs from the same test?

Aaron

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.

Can you try testing from the LTM command line using curl? Here is an example:

curl -v http://VIP_IP/uri -H “User-Agent: Azureus”

Thanks,

Aaron

Here’s what I got, still waiting to see if it eventually times out or just keeps hanging at the end of this (edit: it didn’t, 10min later I just ctrl-C’ed out):

[root@nap01gb01-1:Active] log curl -v http://67.63.55.3 -H “User-Agent: Azureus”

* About to connect() to 67.63.55.3:80

* Connected to 67.63.55.3 (67.63.55.3) port 80

> GET / HTTP/1.1

Host: 67.63.55.3

Pragma: no-cache

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

User-Agent: Azureus

If there isn’t a response to requests which should be closed, I’d say it looks like the TCP::close command is working.

Aaron

But that doesn’t agree with the client packet capture, or the guys running the servers in the pool this iRule (eventually) redirects to - both show that server connections are still being established. The reason this rule was written is to prevent those server connections, so even though the client sees nothing, the rule isn’t stopping the traffic it was intended to.

It might end up being easier if you’re able to capture tcpdumps on the client and server side VLANs along with LTM log output from the iRule and then open a case with F5 Support. They’ll be able to inspect the full traces and tell you how this should/could work. It might save you time in the troubleshooting process.

If I have a chance to test this, I’ll reply with any relevant info I come up with.

Aaron

Opened up a ticket with them yesterday, they’re seeing the same behavior, will update - thanks for the suggestions so far. :slight_smile:

Just an update (thanks for all your suggestions so far, Hoolio). I happen to be in an F5 iRule training this week, and rewrote the first part of the rule. In the process, I’ve pinned down the weirdness. The following rule *partially* works, when tested with the User-Agent value “Azureus” (note upper-case “A”) - instead of the full target redirect page, a “connection reset” page is displayed on the client, the redirect URL is shown in the address bar, and client tcpdump shows a server connection being established.

when RULE_INIT {

set ::uablock [list torrent azureus windows-media-player microsoft-webdav-miniredir “”]

}

when HTTP_REQUEST {

if { [matchclass [HTTP::header value “User-Agent”] contains $::uablock] } {

TCP::close

}

else {

HTTP::redirect http://domainnotfound.optimum.net/cablevassist/dnsassist/main/?domain=\[HTTP::host]

}

}

Since without a string tolower operation “Azureus” shouldn’t match “azureus”, I don’t know why the full normal redirect isn’t happening. Adding a string tolower function to the matchclass results in the exact same TCP::close doing what I want, dropping the connection immediately and completely.

when RULE_INIT {

set ::uablock [list torrent azureus windows-media-player microsoft-webdav-miniredir “”]

}

when HTTP_REQUEST {

if { [matchclass [string tolower [HTTP::header value “User-Agent”] ] contains $::uablock] } {

TCP::close

}

else {

HTTP::redirect http://domainnotfound.optimum.net/cablevassist/dnsassist/main/?domain=\[HTTP::host]

}

}

The other issue is that in order to easily apply the User-Agent filtering function to multiple VIPs using different redirects, I’d like to split these items into two separate iRules attached to the same VIP. Unfortunately, even with string tolower, this also triggers the TCP::close partial redirect behavior.

Rule 1

when RULE_INIT {

set ::uablock [list torrent azureus windows-media-player microsoft-webdav-miniredir “”]

}

when HTTP_REQUEST priority 500 {

if { [matchclass [string tolower [HTTP::header value “User-Agent”] ] contains $::uablock] } {

TCP::close

}

}

And this:

Rule 2

when HTTP_REQUEST priority 1000 {

HTTP::redirect http://domainnotfound.optimum.net/cablevassist/dnsassist/main/?domain=\[HTTP::host]

}

In still-further weirdness, it appears that the mere absence of the string tolower function triggers the partial redirect behavior of TCP::close (without it, both “Azureus” and “azureus”, as well as “Torrent” and “torrent”, etc., trigger the partial redirect). Some kind of timing issue getting triggered? Curiouser and curiouser.

Last note for the afternoon - adding “event disable all” after the TCP:close allows this to be broken into two rules the way I wanted it to be, so my problem is effectively solved (though removing string tolower still mysteriously breaks it). Thanks again, Hoolio.