Forum Discussion
Diego_19194
Nimbostratus
Jul 19, 2007SMTP modify a character in the packet
Hello people,
I have a problem that I need to send a MSISDM in a SMTP packet, but I must to modify the number, it meam remove one number.
Then only option we see is to create an iRule at Bigip, modifying SMTP information in order to modify destination address, originating address and also at the body of the msg removing the "9".
I want to convert for example:
RCPT TO:+5491158538565 -->RCPT TO:+541158538565
I found the irules attached where I will do a SMTP_proxy_iRule, and another sample that check some MSISDN in the body of the packet TCP. Due to the BIG-IP doesn't have libraries to modify the SMTP.
My question is simple, how can I modify the SMTP packet (header and body) to remove this number?
11 Replies
- Diego_19194
Nimbostratus
I was working ofr a few days with that and I found how can do the iRule.
Now, my problem is that I can not forward the traffic for the virtual IP.
The irules is implemented when the connection is established by a sendmail in the server side, then I am trying that all smtp traffic pass-through the BIGIP with a virtual server, it mean that I wrote the IP of a virtual server in configured in the BIGIP (/etc/hosts).
BIGIP recieved this connection, but when it tried to connect with the destination it is done by the SelfIP and not by the VIP.
Below is the configration:
pool test {
lb method member least conn
monitor test_smtp
member 192.168.19.50:25
}
virtual MMSC_SMTP_Personal {
destination 192.168.16.51:smtp
ip protocol tcp
pool test
rule remove_9_MSISDN
vlans C_internal external_m enable
}
Do you know why is wrong in the configuration and what is the correct way to configurated this? - hoolio
Cirrostratus
If you are trying to force the BIG-IP to use the VIP address as a source IP for traffic to the pool, you can create a SNAT pool with the VIP address and assign it under the VIP properties for SNAT. Or you could add the command 'snat 1.2.3.4' to your iRule where 1.2.3.4 is the VIP address.
If I've misunderstood what you're trying to do, let me know.
Aaron - Diego_19194
Nimbostratus
You didn't understand.
I am sorry but I am new writing iRules and I don't know where add this snat pool.
I have configured a snat pool:
snat translation 192.168.16.26 {
unit 2
}
snatpool snat-Pool-to-Mobile {
member 192.168.16.25 192.168.16.26
}
I must to use this snat pool.
But I have a doubt, do I need to add inside of the "when CLIENT_ACCEPTED" or I also need to add in "when SERVER_CONNECTED"?
Thanks for your help.
Diego - Diego_19194
Nimbostratus
I tested adding the "snatpool snat-Pool-to-Mobile" in "when CLIENT_ACCEPTED" and "when SERVER_CONNECTED", but the sender IP is wrong again. I think that when check in the virtual server the rule is not applied in the right moment.
My idea is:
SMTP MTA (198.18.24.1) ----> BIGIP virtual server (192.168.16.51) ----> BIGIP sender (192.168.16.25) -----> SMTP MTA (192.168.19.50)
Remember that the SMTP client to generate the connection is in the server side. - Diego_19194
Nimbostratus
Now, the connection is working. The problem is a line that say "node * monitor icmp", because of the server is not answer the ping then BIGIP established as down and it didn't forward traffic to it.
I have a problem with a regular expression. I am trying to remplace something but I have the error below:
Jul 25 16:30:08 tmm tmm[730]: 01220001:3: TCL error: Rule remove_9_MSISDN - couldn't compile regular expression pattern: quantifier operand invalid while executing "regsub -all "(+54)(9)(.*)(TYPE=PLMN)" $cdata "\\1\\3\\4" cdata"
Jul 25 17:12:21 tmm tmm[730]: 01220001:3: TCL error: Rule remove_9_MSISDN - couldn't compile regular expression pattern: quantifier operand invalid while executing "regsub -all $find $cdata $replace new_response"
I don't know where is the problem. Could you help me?
Thanks - hoolio
Cirrostratus
Good to hear that you got the network portion working as you want.
I'm not sure exactly what you're trying to replace with the regex, but the +54 portion is invalid. If you want to match a literal plus sign, you need to escape it:
(\+54)(9)(.*)(TYPE=PLMN)
Also, you might want to take a look at why you are capturing the literal string, '9' and the literal string 'TYPE=PLMN', into backreferences. You could just hard code these strings in the replacement variable.
\+549(.*)TYPE=PLMN
And actually, you could probably accomplish getting the data between two literal strings with string commands like 'string first' and 'string range' (Click here) or possibly scan (Click here).
Aaron - Diego_19194
Nimbostratus
Thank you very much.
Now, the parser is working, but I found that when I recieve the answer I need to add the 9, because of the communication with the other server is with 9, if not the answer will be "500 Command unrecognized".
I wrote:
set sdata [TCP::payload]
set digit_nine "9"
set find {(54)([0-9]*)(/TYPE)}
if { [regexp $find $sdata] > 0} {
regsub -all $find $sdata "\\1$digit_nine\\2\\3" sdata
TCP::payload replace 0 [string length $sdata] "$sdata"
}
And the error is "Jul 26 11:35:36 tmm tmm[730]: 01220001:3: TCL error: Rule remove_9_MSISDN - Out of bounds (line 1) invoked from within "TCP::payload replace 0 [string length $sdata] "$sdata"""
I know that this mean that I cannot add a new character in the payload, but then how can I do it? - hoolio
Cirrostratus
Hi,
Can you post the full rule you're currently testing and a sample of the source data you want to perform the replacement on and what you want it to look like afterwards?
You can indeed insert more data than was there in the payload to begin with. However, in versions before 9.4.0 (?), you need to set chunking to 're-chunk' in order to have BIG-IP recalculate the content-length correctly.
Aaron - Diego_19194
Nimbostratus
My rule:
when CLIENT_ACCEPTED {
snatpool snat-Pool-to-Mobile
set chelo ""
set cfrom ""
set crcpt ""
TCP::respond "220\r\n"
log local0. "client accepted"
TCP::collect
}
when CLIENT_DATA {
set cdata [TCP::payload]
set find {(54)(9)([0-9]*)(/TYPE)}
if { [ string length $cdata ] <= 0 } {
return
}
if { not ( $cdata contains "\r\n" ) } {
log local0. "get <$cdata> so far"
return
}
if { $cdata starts_with "HELO" } {
set chelo [TCP::payload]
log local0. "get helo <$cdata>"
TCP::respond "250 OK\r\n"
TCP::payload replace 0 [string length $chelo] ""
return
}
if { $cdata starts_with "MAIL FROM:" } {
set cfrom [TCP::payload]
log local0. "get from <$cfrom>"
TCP::respond "250 OK\r\n"
regsub -all "(+54)(9)(.*)(/TYPE)" $cfrom "\\1\\3\\4" cfrom
TCP::payload replace 0 [string length $cfrom] $cfrom
TCP::payload replace 0 [string length $cfrom] ""
log local0. "despues de cambiar <$cfrom>"
return
}
if { $cdata starts_with "RCPT TO:" } {
set crcpt "$crcpt[TCP::payload]"
log local0. "get rcpt <$crcpt>"
TCP::respond "250 OK\r\n"
regsub -all "(+54)(9)(.*)(/TYPE)" $cfrom "\\1\\3\\4" cfrom
TCP::payload replace 0 [string length [TCP::payload]] ""
TCP::payload replace 0 [string length [TCP::payload]] ""
log local0. "despues de cambiar <$crcpt>"
return
}
if { $cdata starts_with "DATA" } {
log local0. "get data <$cdata>"
TCP::payload replace 0 0 $chelo$cfrom$crcpt
}
if { [regexp $find $cdata] > 0} {
regsub -all $find $cdata "\\1\\3\\4" cdata
TCP::payload replace 0 [string length $cdata] "$cdata"
}
log local0. "payload client [TCP::payload]"
TCP::release
TCP::collect
}
when SERVER_CONNECTED {
snatpool snat-Pool-to-Mobile
log "server connected"
TCP::collect
}
when SERVER_DATA {
set sdata [TCP::payload]
set digit_nine "9"
set find {(54)([0-9]*)(/TYPE)}
if { $sdata starts_with "220" } {
log local0. "get data <$sdata>"
TCP::payload replace 0 [string length $sdata] ""
return
}
if { $sdata contains "\r\n354 " } {
log local0. "get data <$sdata>"
TCP::payload replace 0 [string length $sdata] "354\r\n"
}
if { [ string length $sdata ] <= 0 } {
return
}
if { [regexp $find $sdata] > 0} {
regsub -all $find $sdata "\\1$digit_nine\\2\\3" sdata
TCP::payload replace 0 [string length $sdata] "$sdata"
}
log local0. "payload server <[TCP::payload]>"
TCP::release
TCP::collect
}
when CLIENT_CLOSED {
log local0. "client closed"
}
It is a SMTP connection and send a MSISDN as "MAIL From:<+5491150027236/TYPE=PLMN@mm4.mms.movil.com>"
My version is 9.1 - Deb_Allen_18Historic F5 AccountSince you're replacing the original payload, you have to replace the original data length, not the length of the new data. Try using this for the TCP::payload replacement commands instead:
TCP::payload replace 0 [TCP::payload length] $sdata
HTH
/deb
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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