Is the bad string found in a parameter value (/dir/1315?param=bad2144)? If so, you might want to verify whether the application accepts the same parameter in the payload of a POST request. A malicious user could potentially use an interception proxy to modify the request from a GET to a POST and include the parameter in the POST data. Also, for the URI check, you could be more specific using HTTP::query.
If you want to only check for the bad2144 string for a specific URI, you could add a check:
if {[HTTP::uri] starts_with “/some/path” && [HTTP::query] contains “bad2144”}{
If the app is not case sensitive, you could set the URI to lower case:
if {[string tolower [HTTP::uri]] starts_with “/some/path” && [HTTP::query] contains “bad2144”}{
The class definitions aren’t part of the iRule itself. You’d need to create those separately, either through bigpipe commands or in the management interface.
Note, “class” is also known as “data group”. Either term can mean the same thing. I believe the management interface lists them as Data groups.
I get a page instead of a dropped connection. Do you where the logging is done for big-IP? I checked all the logs on Big-IP but don’t see anything being logged for dropped connections.
Can you log the value of the class from the iRule to see what’s been added (log local0. “class \$::badStrings: $::badStrings”. Or more accurately, can you list the contents using ‘b class badStrings list’? You may need to escape the ; with \. If you use log local0. “some string”, the output is written by default to /var/log/ltm. TCL errors from iRules would also be written to the ltm log file.
There were actually a few syntax and logic errors in the rule. There needs to be a space between local0. and the start of the log text. The open parenthesis shouldn’t be there. And IP::server_addr is invalid in HTTP_REQUEST as no server side connection has been established. Assuming you want to check the client IP against the Host datagroup, you can try this:
when HTTP_REQUEST {
Log a debug message with client IP:port and the class contents
log local0. "[IP::client_addr]:[TCP::client_port]: class \$::badStrings: $::badStrings"
Check if the client IP is part of the hosts datagroup
if { [matchclass [IP::server_addr] equals $::Hosts]}{
Log a debug message indicating the client IP matched the Hosts class
log local0. "[IP::client_addr]:[TCP::client_port]: matched Hosts class \$::Hosts: $::Hosts"
Check if the requested URI contains any known bad strings
if { [matchclass [string tolower [HTTP::uri]] contains $::badStrings]}{
Log a debug message indicating the client matched the Host class and had a bad string in the URI
log local0. "Matched server IP and found bad string in [HTTP::uri]: entry [matchclass [string tolower [HTTP::uri]] contains $::badStrings]"
Drop the TCP connection
drop
}
}
}
I added more logging so you can follow what’s happening if it doesn’t work. Once you’ve tested the rule, you should comment out or remove the log statements to save disk space and CPU resources.