Forum Discussion
Regex in iRule
Im making a rule to catch bad code being in HTTP POST.
for some reason we have some sites trying to do some sort of XSS attack, but posting URL strings in the POST and then they get a 500error. Im trying to right a rule but cant get it sorted out.
when RULE_INIT {
set ::vDebug 1
}
when HTTP_REQUEST {
if { [HTTP::query] matches_regex {<[a-zA-Z!]} } {
if { $::vDebug } {
log local0. "Triggered by IP [IP::client_addr] with URI [HTTP::uri]"
}
reject
}
}
Not sure if Im even in the right ballpark on this one, I just want to catch in HTTP POST, not every connection.
Please see below for possible samples:
"
"
"
Thanks
- Mohamed_LrhaziAltocumulusIf you're asking how do I detect POST, then the answer is: https://devcentral.f5.com/wiki/iRules.http__method.ashx
- Kevin_StewartEmployeeHere's a rough example:
when HTTP_REQUEST { if { [HTTP::method] equals "POST" } { log local0. "query = [URI::decode [HTTP::query]]" if { [string match -nocase {*<[a-zA-Z!]*} [URI::decode [HTTP::query]]] } { log local0. "Gotcha!" reject } } }
- F5Hopper_28651Nimbostratusok thanks, I will check that out and post if that worked.
- F5Hopper_28651Nimbostratus
I just noticed that my samples didnt show in my main post. Im looking for samples in attached TXT file.
- Brian_69413NimbostratusYour session is probably still tied to the old version of the iRule
- Kevin_StewartEmployeeYour queries don't appear to have any of the characters you're looking for. How are you testing/posting?
- F5Hopper_28651NimbostratusI had my DEV guys generate the Regex.... I dont know it at all... I do know that the website gets hit every 5-10min with bad HTTP POSTs that start with my samples.
- Kevin_StewartEmployeeI'm specifically asking how you're testing the iRule. You wouldn't be able to just send a greater-than sign in the URI without encoding it, and the "Step" examples don't contain any greater-than signs.
- F5Hopper_28651NimbostratusI was really just waiting on the bad traffic to hit me and see what comes up.
Recent Discussions
Related Content
* 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