Skip to contentSkip to conversation

logging port 25

DISCUSSION Scott Mayo 4 participants 6 messages Oct 18, 2005 – Oct 19, 2005

lore
Share & tools
lore

Scott Mayo

author
#0 lore raw

I have a private network behind my firewall. My email server is on the outside. What rules do I need to set in my firewall, so that any mail that is destined for my mail server through port 25 is alright, but any mail that is destined for port 25 that is not going to my mail server, gets logged and dropeed.

I am trying to do this in case I get a virus that uses its own smtp to send out mail.

IE:

Internal network:  192.168.x.x
Internal Ip of Nic on firewall: 192.168.0.254
Public Ip of Nic: 68.68.68.68
Ip of mail server:  78.78.78.78

What would I need to put in for my rules? I thought that I had it down correctly, but I am not getting anything in the log. It does log this to /var/log/messages doesn't it?

Thanks for any input.

Signature · 9 lines
Scott Mayo
Technology Coordinator
Bloomfield Schools
PH: 573-568-5669
FA: 573-568-4565
Pager: 800-264-2535 X2549

Duct tape is like the force, it has a light side and a dark side and it
holds the universe together.
#1 lore raw

Hi Scott Mayo,

Quoted 1 line

I am trying to do this in case I get a virus that uses its own smtp to send out mail.

First use a virusscanner to kill the virus/worm from your server. After that you can think about creating rules to handle smtp.

Regards,
Ruprecht

------------------------------------------------------------------------------------------
Ruprecht Helms IT-Service & Softwareentwicklung

Tel./Fax +49[0]7621 16 99 16
Web: htp://www.rheyn.de

#2 lore raw
In reply to Scott Mayo
Quoted 7 lines · Scott Mayo

the outside. What rules do I need to set in my firewall, so that any mail that is destined for my mail server through port 25 is alright, but any mail that is destined for port 25 that is not going to my mail server, gets logged and dropeed.

I am trying to do this in case I get a virus that uses its own smtp to send out mail.

Good idea. You probably already have some.

Quoted 1 line

What would I need to put in for my rules? I thought that I had it

Tell us what you tried and I will tell you why it was wrong. My crystal ball thinks you put the rules in INPUT. Was it right?

Quoted 2 lines

down correctly, but I am not getting anything in the log. It does log this to /var/log/messages doesn't it?

It logs according to the configuration of your system syslogd. It might also log to different places depending upon --log-level if specified in the rule[s] which you did not post. IINM the default syslog facility and priority is kern.info, but /proc settings can change the priority too.

Signature · 2 lines
    mail to this address is discarded unless "/dev/rob0"
    or "not-spam" is in Subject: header
author
#3 lore raw
Quoted 7 lines · /dev/rob0 wrote:
Quoted 5 lines · Scott Mayo

the outside. What rules do I need to set in my firewall, so that any mail that is destined for my mail server through port 25 is alright, but any mail that is destined for port 25 that is not going to my mail server, gets logged and dropeed.

Quoted 5 lines
Quoted 2 lines

I am trying to do this in case I get a virus that uses its own smtp to send out mail.

Good idea. You probably already have some.

Well, I have virus protections on most things, but uses seem to get them turned off once in a while. :)

Quoted 6 lines
Quoted 3 lines

What would I need to put in for my rules? I thought that I had it

Tell us what you tried and I will tell you why it was wrong. My crystal ball thinks you put the rules in INPUT. Was it right?

I was not sure, so I put the rules in both the INPUT and FORWARD chain.

Quoted 6 lines
Quoted 3 lines

down correctly, but I am not getting anything in the log. It does log this to /var/log/messages doesn't it?

It logs according to the configuration of your system syslogd. It might also log to different places depending upon --log-level if specified in the rule[s] which you did not post. IINM the default syslog facility and priority is kern.info, but /proc settings can change the priority too.

Here is what I added in:
The firewall has two different NICS in it.

INT_IP_RANGE="10.0.0/16"
INT_IP_RANGE2="192.168.0.0/24"

$IPTABLES -A INPUT -p tcp -d mail_server_IP --dport 25 -j ACCEPT $IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE --dport 25 -j LOG --log-level debug $IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE --dport 25 -j LOG --log-prefix "EMAIL:" $IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE --dport 25 -j LOG --log-tcp-sequence $IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE --dport 25 -j LOG --log-ip-options $IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE2 --dport 25 -j LOG --log-level debug $IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE2 --dport 25 -j LOG --log-prefix "EMAIL:" $IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE2 --dport 25 -j LOG --log-tcp-sequence $IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE2 --dport 25 -j LOG --log-ip-options

I did the same thing for the FORWARD chain, except changed teh INPUT to FORWARD obviously. :)

Thanks for any help.

Signature · 9 lines
Scott Mayo
Technology Coordinator
Bloomfield Schools
PH: 573-568-5669
FA: 573-568-4565
Pager: 800-264-2535 X2549

Duct tape is like the force, it has a light side and a dark side and it
holds the universe together.
#4 lore raw
Quoted 7 lines · Scott Mayo
Quoted 4 lines
Quoted 2 lines

I am trying to do this in case I get a virus that uses its own smtp to send out mail.

Good idea. You probably already have some.

Well, I have virus protections on most things, but uses seem to get them turned off once in a while. :)

It's impossible to truly secure Windows, especially with the clueless users you so often have on it.

Quoted 5 lines
Quoted 2 lines

Tell us what you tried and I will tell you why it was wrong. My crystal ball thinks you put the rules in INPUT. Was it right?

I was not sure, so I put the rules in both the INPUT and FORWARD chain.

local = IP address bound on the iptables machine itself
INPUT = destination is local
OUTPUT = source is local
FORWARD = neither is local

Every packet hits exactly one chain, except loopback traffic hits OUTPUT, then INPUT.

Quoted 1 line

INT_IP_RANGE="10.0.0/16"

And you got a syntax error here. You have to specify all 4 quads:
"10.0.0.0/16".

Quoted 3 lines

INT_IP_RANGE2="192.168.0.0/24"

$IPTABLES -A INPUT -p tcp -d mail_server_IP --dport 25 -j ACCEPT

If mail_server_IP is not local, this rule is never matched.

Quoted 8 lines

$IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE --dport 25 -j LOG --log-level debug
$IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE --dport 25 -j LOG --log-prefix "EMAIL:"
$IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE --dport 25 -j LOG --log-tcp-sequence
$IPTABLES -A INPUT -p tcp -s $INT_IP_RANGE --dport 25 -j LOG --log-ip-options

snip $INT_IP_RANGE2 commands

You're wanting *4* separate log entries for EACH smtp packet? Wow. I don't think you really want that. You probably want to consolidate all those options in a single -j LOG rule. Further I would suggest limiting it, either or both "--syn" or "-m state --state NEW". You only need one packet logged per connection attempt.

Quoted 2 lines

I did the same thing for the FORWARD chain, except changed teh INPUT to FORWARD obviously. :)

If mail_server_IP is not local, these rules are matched in FORWARD ... unless of course some other terminating rule matched it before they come up. And that is beyond the ability of my crystal ball. :)

One (and perhaps only one) way in which "iptables -L" is useful is in conjunction with "-v", where you get packet counters. Perhaps you will see that these rules are not being hit at all; otherwise your logs would be inundated by a spam zombie. 2-3 zombies could conceivably DoS your firewall, or at least crash your syslogd.

Put corrected rules in INPUT or FORWARD (FORWARD I guess from what you said, the mail_server_IP not being behind your firewall) and test from a firewalled client: "telnet some.other.mail.server 25", see if you get out (I presume there is a -j DROP rule or -P DROP following, although you might consider a -j REJECT for these) and/or are logged.

Signature · 2 lines
    mail to this address is discarded unless "/dev/rob0"
    or "not-spam" is in Subject: header
#5 lore raw
Quoted 3 lines

Further I would suggest limiting it, either or both "--syn" or "-m state --state NEW". You only need one packet logged per connection attempt.

Wouldn't putting the rules in the nat table instead of the filter table, achieve that same thing and avoid evaluating the rules for every packet?

Andrew

-----------------------------------
Andrew Cant
Developer
LogiSense Corporation
"IP Billing and Traffic Management"

e: [email protected]
p: 1-519-249-0508 x4108
w: www.logisense.com
weblog: http://blog.logisense.com
forum: https://ssl.logisense.com/support/forum