I’m looking to patch a security issue in our application until our developers have time to do their thing, and I’m hoping to do it with iRules.
What I have is a log-in page, login.asp, that doesn’t validate any of its 3 fields: username, password, email. I successfully made a rule to remove brackets, slashes, and whatever else from the POST data, then realized that users may have these characters in their passwords. This example removes <, >, or % from posts and replaces them with NULL, in turn invaliding their attempt:
when HTTP_REQUEST_DATA {
if {[string tolower [HTTP::path]] contains “login.asp”} {
In order to ignore the password field, I figure I need to parse the POST data, scrub all submit data except for the Password, then reassemble it back into HTTP:payload. Is there a simple way to do this. My typical payload looks like this:
I think you will have to do it that way unfortunately and I don’t have any examples. If you have a 6400 or higher you could always add the Application Security Manager which is made to do these kinds of things.
when HTTP_REQUEST_DATA {
if {[string tolower [HTTP::path]] contains "login.asp"} {
save original password value
set pw [findstr [HTTP::payload] "&password=" 10 &]
strip special characters from entire payload
set newPayload [string map {< "" > "" % ""} [HTTP::payload]]
if original pw value was changed, replace original value
if {[string first &password=$pw $newPayload] < 0 }{
regsub {("&password=)(.*?)(&)?} $newPayload {\1$pw\3} newPayload
}
HTTP::payload replace 0 [HTTP::payload length] $newPayload
HTTP::release
log local0. "new payload: $newPayload"
}
}
Should work regardless of password parameter position.
There’s an extra double-quote at the beginning of the expression and the (&) only matches if the payload has variables after the password, correct? I found that removing the stray double-quote returned this payload while filtering out @ and using password 1111@: membername=marcb&password=$pw1111
Closer, but not quite there. I need it to expect that there may be more variables, so the (&) needs to be (&|\n) or something to that effect, but I can’t figure out what it should be. Next, I need to figure out why the $pw variable is printing instead of its value.
I’m not sure what you mean by wouldn’t need to use the backreferences, but I tried your regex in my regsub and got couldn’t compile regular expression pattern: invalid embedded option.
Seems like a got a handle on it. For some reason, regsub won’t fill in the variable is it’s in curly brackets, but removing them was returning membername=marcb&1111@ (the word password= is gone). I simply added password= to the subSpec part of regsub this way: