Forum Discussion
Marc_Bergeron_5
Nimbostratus
Aug 15, 2007Process POST data
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"} {
set newPayload [string map {< "" > "" % ""} [HTTP::payload]]
HTTP::payload replace 0 [HTTP::payload length] $newPayload
HTTP::release
log local0. "new payload: $newPayload"
}
}
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:
redirect=®_id=0&ie55sp1=false&membername=marcb&password=marcb
- Kirk_Bauer_1018
Nimbostratus
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. - Deb_Allen_18Historic F5 AccountMaybe this?
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" } }
- Marc_Bergeron_5
Nimbostratus
That doesn't seem to be working. I'm not well versed in regex, but there seems to be a handful of issues:regsub {("&password=)(.*?)(&)?} $newPayload {\1$pw\3} newPayload
regsub {(&password=)(.*?)?} $newPayload {\1$pw\3} newPayload
- hoolio
Cirrostratus
Here is a regex that will match just the password parameter value: - Marc_Bergeron_5
Nimbostratus
Aaron;regsub {(?<=password=).*?(?=&|$)} $newPayload {\1$pw\3} newPayload
- Marc_Bergeron_5
Nimbostratus
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:regsub {(password=)(.*?)(&|$)} $newPayload password=$pw newPayload
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