Forum Discussion
Scott_Albrech_8
Nimbostratus
Feb 03, 2005regexp looking for email addresses in iRule
Toying with some stuff and thought I'd like to scan TCP payload for email addresses, preferably in the "MAIL FROM", but I'm starting much bigger for sake of easing into this. Anyhoo, not having much luck. Here's what I *thought* would work:
when CLIENT_DATA {
if { [regexp -nocase {*@somedomain.com} [TCP::payload]] } {
reject
}
}
Am I missing something here?
- Scott_Albrech_8
Nimbostratus
I should add, I'm running v9.04. I saw there was a snag if using 9.01. - rapmaster_c_127Historic F5 AccountHi,
- Scott_Albrech_8
Nimbostratus
Ooops, sorry about mis-posting. I don't see any way to move the thread, can a moderator do that? - rapmaster_c_127Historic F5 AccountI've moved it over for you. I have a bunch of meetings right now, but hopefully someone will see this and get creative! (Yes there are ways to do this; it's actually a fun little project.)
- unRuleY_95363Historic F5 AccountI'm not sure what your ultimate goal is, but here is a very simple example rule that will scan for something (like an e-mail address) in a connection and reset it if found (however, it will not find strings that span TCP packets, but this should not be a problem with most SMTP clients):
when CLIENT_ACCEPTED { TCP::collect } when CLIENT_DATA { if { [TCP::payload] contains "joe@foobar.com" } { reject } else { Release the current payload onto the server TCP::release But still collect the next data from the client TCP::collect } }
- unRuleY_95363Historic F5 AccountI should also add, that when using this approach, you can't use it to select the pool based on the search. You will likely want to have the pool already on the virtual server.
- Scott_Albrech_8
Nimbostratus
I don't know what I'm trying to accomplish with this yet either, aside from having a lot of fun thinking about possibilities. iRules are very powerful and a lot of fun to play around with! - Scott_Albrech_8
Nimbostratus
Well, that has the same result I was seeing before. I hangs the SMTP session. I moved the TCP::release around and get a bit of interaction but still not a totally interactive SMTP session. I don't know if I understand the whole mechanism well enough to fiddle too much. But I tried this which made some headway:when CLIENT_ACCEPTED { TCP::collect 100 TCP::release } when CLIENT_DATA { if { [TCP::payload] contains "joe@foobar.com" } { reject } else { Release the current payload onto the server TCP::release But still collect the next data from the client TCP::collect 500 } }
- Scott_Albrech_8
Nimbostratus
I figured out my issue. My understanding of what was vaguely written in the manual led me to the following, which got past the hanging of the SMTP session on first connect (waiting for the 220 on client_accepted):when CLIENT_ACCEPTED { TCP::collect TCP::release } when CLIENT_DATA { if { [regexp -nocase {mail from:} [TCP::payload]] } { TCP::respond "554 Message Rejected\r\n" reject } else { Release the current payload onto the server TCP::release But still collect the next data from the client TCP::collect } }
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