DevCentral Groups
   
You are here: Community > Group Details > iRules

Get Connected with DevCentral

Sign up and Join this Group today!

Connect with your peers with the click of a button. Become a member of this group to post questions, sign up for notifications, provide comments, answer questions, access downloads and receive lots of other great documentation relevant to your interests. Connect with your community today!

  

Group Details

iRules

F5 DevCentral Topic Group dedicated to open discussion and collaboration related to F5's unique and incredibly powerful iRules scripting language.
iRules
Upcoming Events
There are no events currently connected to this group. Click here to search all F5 Events.

Having trouble posting to this forum? Click the "Join Group" button above to get access!

TCP payload match and logging
Last Post 12/08/2010 01:16 PM by Colin Walker. 15 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
Please login or join DevCentral to post a reply.
 
PrevPrev NextNext
Author Messages
mattrm
mattrm
Post Count: 11
Active Member


--
07/27/2010 06:29 PM  
Hi All, I'm trying to reference TCP client data and look for userid and timestamp and log these values, I also need to log which LB Select. I have the first part, (i think), but what do I do to find those values in client data and the log those values. when CLIENT_ACCEPTED { TCP::collect } when CLIENT_DATA { if { [TCP::payload] contains "userid=", "timestamp=" } { } }


Hamish
Hamish
Post Count: 1145
MVP - 7


--
07/29/2010 03:50 AM  
That's probably almost right if you're doing the searching yourself. Except you'll need to consider boundary conditions as well. For example the "userid=" string may be split across the border of the TCP data payload that you've gathered.

Perhaps an easier way would be to use stream processing. Setup a stream that looks for the patterns you're interested in, and trigger on the STREAM_MATCHED event. In there you can pull and log the values. (You can either define the stream in a profile, and attach it, or define the stream you're looking for at run time the way the ProxyPass iRule does... In fact for a good example of stream processing see the ProxyPass iRule).

H


mattrm
mattrm
Post Count: 11
Active Member


--
07/29/2010 08:23 AM  
Interesting, never thought of using stream profile for that. What is the default logging mechanism for stream? As the entire purpose of the iRule is to log the values out of the payload, (being userid and timestamp as well as lb selected), if I can do that effectively via stream, far easier for me then an irule. M


mattrm
mattrm
Post Count: 11
Active Member


--
08/01/2010 04:42 PM  
Okay - So I've created the stream profile, with the following source values: userid= password= timestamp= Then the irule which triggers on stream match: when STREAM_MATCHED { # Log each match found by the stream filter log local0. "Stream filter matched: [STREAM::match]" } Thoughts?


mattrm
mattrm
Post Count: 11
Active Member


--
08/05/2010 02:54 PM  
I have the stream profile matching as per my irule, however it is not returning the match value, rather it's telling me its matched and "when STREAM_MATCHED priority 32768000 " I was expecting the match value to be the userid value?? Any help would be greatly appreciated.

M



mattrm
mattrm
Post Count: 11
Active Member


--
08/05/2010 03:43 PM  
I now have the stream match working with @ However its base64 encoded, is there a way to decode this?

M


mattrm
mattrm
Post Count: 11
Active Member


--
08/10/2010 02:09 PM  
Got this working with regex, however probably not the best way going forward. I'd like to use findstr or matchstr instead, but having some teething issues around that.

 when STREAM_MATCHED {
 # log each match found by the stream filter
 log local0. "Stream filter matched:[STREAM::match]"
  set myvar [STREAM::match]
  set 4 "blah"
  regexp {Username=(.+)\sUserpassword=(.+)\sUseremail=(.+)\sUserhomefolder=(.+)\s} $myvar matched sub1 sub2 sub3
  log local0. "Username=[b64decode $sub1] Userpassword=[b64decode $sub2] Usermail=[b64decode $sub3]"
}
when LB_SELECTED  {        
 set serverIP [LB::server addr]
 log local0. "LB Server IP $serverIP"
}


Colin Walker
Colin Walker
Post Count: 2310
DC Team - 7


--
08/11/2010 02:56 PM  
You should definitely check out the scan command as well for doing some complex matching.  It's highly efficient and should be able to get done what you're looking to do.  Not exactly intuitive, though.

Click Here

If you run into problems don't hesitate to ask.

#Colin


With iRules you can...
mattrm
mattrm
Post Count: 11
Active Member


--
08/22/2010 02:21 PM  
Thanks for that Colin, having a look at it now. I have another question for you :-), I'm trying to match a null value in stream and replace with a value that will cause the login to fail,
 @Userpassword="null"@Userpassword="000"


I'm trying to make sure that I only match and replace on null password values and not any valid password, however a blank field and a null value doesnt seem to work.

M


Colin Walker
Colin Walker
Post Count: 2310
DC Team - 7


--
08/25/2010 03:08 PM  
Interesting. Are you having trouble matching the null value or replacing it? If you're having trouble matching it then you'd want to do a dump or log and inspect what's actually being passed. It's like userpassword="" or something. That'll help you know what to tweak in your regex.

#Colin


With iRules you can...
mattrm
mattrm
Post Count: 11
Active Member


--
08/25/2010 03:42 PM  
Hi Colin,

Trying to match the null value in
 Userpassword=\"\"
however this didnt match.
My question is can Stream match a null value?

M


Colin Walker
Colin Walker
Post Count: 2310
DC Team - 7


--
08/25/2010 04:08 PM  
Have you tried the simple version?

@Userpassword=" "@Userpassword="000"



I assume so...but had to ask.

That's how I'd try it first.

#Colin


With iRules you can...
mattrm
mattrm
Post Count: 11
Active Member


--
08/31/2010 04:00 PM  
Hi Colin, Yeah tried that, I've attached the tcpdump and highlighted the values I want to match and also replace when null. Any advice would be greatly appreciated. When using the stream value, I'm matching the name in the tcpdump. M

tcpdump.txt

mattrm
mattrm
Post Count: 11
Active Member


--
09/01/2010 03:24 PM  
Currently I'm matching the value
 Userpassword=
however I'm rewriting actual passwords as well as null or empty ones. Sigh :-)

M


mattrm
mattrm
Post Count: 11
Active Member


--
12/06/2010 06:00 PM  
Hi Just an update to the iRule, below is the working version:

Using the following stream profile:

@Username.*Userpassword=\n@@

when STREAM_MATCHED {
# log each match found by the stream filter
scan [STREAM::match] "Username=%s" user
log local0. "Username [b64decode $user] had password 

replaced"
STREAM::replace "Username=$user\nUserpassword=0000=\n"
}
when LB_SELECTED  {        
 set serverIP [LB::server addr]
 log local0. "LB Server IP $serverIP"
}

Matt


Colin Walker
Colin Walker
Post Count: 2310
DC Team - 7


--
12/08/2010 01:16 PM  
Very cool, thanks for sharing!

#Colin


With iRules you can...
Please login or join DevCentral to post a reply.

  

93,050 Members in 191 Countries and Growing!

Join DevCentral Today!

About DevCentral

F5 DevCentral is your source for the best technical documentation, discussion forums, blogs, media and more related to application delivery networking.

So dive in, meet your peers, and get familiar with DevCentral. We hope it makes your job easier and helps you get more from your F5 investment. If new to DevCentral, check out the Getting Started section. And if you have any problems, or think something could be easier to use, let us know.

Got It !

We've received your comment and transmitted it directly to DevCentral HQ.

Thanks for taking time to let us know what's on your mind. At DevCentral | Community Matters!

Get In Touch With Us

Have questions, suggestions or just want to get something off your chest?

Use our handy form below to Direct Connect with DevCentral Mission Control.

Send Us Feedback      or