限制部分Postfix用户只能内部收发的例子(完整版) (已验证)

Friday, December 12, 2008

最近本来已经很太平的公司邮箱系统又开始有垃圾邮件了,而且还有羊毛文的。

经过几天的观察,大都是通过公司群发邮件列表发到每个用户邮箱的。

原因找到了,想到2个方案进行解决
1、修改公司群发邮件列表mail地址。
2、限定公司群发列表的收发权限。

最后还是采用了方案2,网上搜索了一下,并结合自己的内容,进行了测试。

以下是具体的实施步骤。

1)在main.cf里定义如下的smtpd_restriction_classes:
# restrictions
smtpd_restriction_classes=local_in_only local_out_only
local_in_only=check_sender_access hash:/usr/local/etc/postfix/local_domains,reject
local_out_only=check_recipient_access hash:/usr/local/etc/postfix/local_domains,reject

解释:
local_in_only=check_sender_access hash:/usr/local/etc/postfix/local_domains,reject
接收限制,规则外部发送者的域名hash表
local_out_only=check_recipient_access hash:/usr/local/etc/postfix/local_domains,reject
发送限制,规则外部接受者的域名hash表

注意要顶格写,否则会报错

2)将main.cf里的smtpd_recipient_restrctions定义为:
smtpd_recipient_restrictions =
check_recipient_access hash:/usr/local/etc/postfix/local_in_senders,
check_sender_access hash:/usr/local/etc/postfix/local_out_senders,

解释:
check_recipient_access hash:/usr/local/etc/postfix/local_in_senders,
接受限制,检查内部接受者是否在local_in_senders,接受限制表中
check_sender_access hash:/usr/local/etc/postfix/local_out_senders,
发送限制,检查内部接受者是否在local_iout_senders,发送限制表中

3)编辑/usr/local/etc/postfix/local_domains:
internal.foo.com OK
internal.bar.com OK

4)编辑/usr/local/etc/postfix/local_in_senders:
foo@extmail.org local_in_only
bar@extmail.org local_in_only

5)编辑/usr/local/etc/postfix/local_out_senders:
foo@extmail.org local_out_only
bar@extmail.org local_out_only

6)为3,4,5的文件建立hash
postmap hash:/usr/local/etc/postfix/local_domains
postmap hash:/usr/local/etc/postfix/local_in_senders
postmap hash:/usr/local/etc/postfix/local_out_senders

注意:最好用root生成上述hash

7)重启postfix
/usr/local/etc/rc.d/postfix restart

这样就定义了extmail.org域名里两个用户foo和bar,只允许和internal.foo.com和internel.bar.com 两个内部域的用户来往邮件,对于外部的邮件则没有收或发的能力。如果外部邮件企图给这2个用户发送,则遇到如下错误:


QUOTE:
554 5.7.1 : Recipient address rejected: Access denied

如果这2个内部用户要给外部用户发email,将遇到如下错误:


QUOTE:
554 5.7.1 : Sender address rejected: Access denied

目前这样的配置就可以比较完整的实现内部用户的功能需求了。其实这种配置的方法和之前的帖子道理一样,关键得分清楚什么阶段,调用什么restrictions即可。

参考:
1)http://blog.chinaunix.net/u1/54725/showart_437496.html
2)http://www.extmail.org/forum/viewthread.php?tid=524&extra=&page=1

Posted by Michael.Ding at 2:41 PM 0 comments

tomcat rewrite 实现

Wednesday, December 3, 2008

Check that users are using the correct domain name to get to your site. ie, users gong to http://example.com/blah will be redirected to http://www.example.com/blah


Domain Name Check
www.example.com
^/(.*)$
http://www.example.com/$1


if web server contains two hostnames, change the condition as following

example.com

done

reference:http://tuckey.org/urlrewrite/

Posted by Michael.Ding at 5:53 PM 0 comments

linux 和 window 上route命令使用

Thursday, October 9, 2008

linux:
route add -net 192.168.81.0 netmask 255.255.255.0 gw 172.168.100.2
window:
route add 192.168.81.0 mask 255.255.255.0 172.168.100.2 -p

Posted by Michael.Ding at 6:12 PM 0 comments

freebsd ports 使用http代理

ee /etc/make.conf
添加
FETCH_ENV?=HTTP_PROXY=http://user:password@proxyurl:proxyport

Posted by Michael.Ding at 5:46 PM 0 comments

iptables的ipp2p模块加载

Tuesday, October 7, 2008

reference:
http://wiki.centos.org/HowTos/I_need_the_Kernel_Source
http://sourceforge.net/project/showfiles.php?group_id=80085
http://blog.chinaunix.net/u/28814/showart.php?id=1220921
http://linux.chinaunix.net/bbs/thread-1032941-1-1.html
http://linux.chinaunix.net/bbs/viewthread.php?tid=914377

出现error
重启机器后发现dmesg
e1000 device eth0 does not seem to be present, delaying initialization.
处理方式
depmod -a
modprobe e1000
lsmod
service network restart

补充命令:lspci
本文介绍在Linux下使用lspci命令查看PCI设备详细信息,也可以认为是lspci命令的功能介绍。

当前很多常用硬件都是PCI(Peripheral Component Interconnect)设备,如声卡、网卡、USB控制器等,稍老一点的显卡一般也是PCI设备。很可能由于要安装驱动或其它的需要查看PCI设备的详细信息。linux中的lspci命令方便地实现了这一点。

lspci最简单的使用方法是:

$lspci

它显示出通常对我们最有用的信息。

如果要更的详细信息,可以:

$lspci -v
$lspci -vv
$lspci -vvv

如果有的项目不能正常翻译成人能理解的文字,可以

$update-pciids

请确认您已连到互联网,能访问国外网。

Posted by Michael.Ding at 1:41 PM 0 comments

Freebsd下普通用户使用sudo执行命令

cd /usr/ports/security/sudo
make install clean

ee /usr/local/etc/sudoers
修改
# %wheel ALL=(ALL) NOPASSWD: ALL

%wheel ALL=(ALL) NOPASSWD: ALL

这样whell组用户就可以通过sudo执行所有命令,且不需要输入密码。

给普通用户使用bash
cd /usr/ports/shells/bash
make install clean

默认bash路径为/usr/local/bin/bash
在用户home目录下建立.bash_profile和.bashrc提高用户使用bash的方便程度
ee .bash_profile
添加
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

ee .bashrc
添加
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ll='ls -lA'

source .bash_profile
source .bashrc

顺便提一下freebsd默认的csh是不带tab补全的,使用起来十分不方便,可以通过修改/etc/csh.cshrc
添加
set autolist

Posted by Michael.Ding at 11:46 AM 0 comments

使用chkrootkit工具保护服务器(转)

Saturday, October 4, 2008

在保护linux 服务器时除了Tripwire 这样强大工具外,还有一个简单又好用的工具–chkrootkit。chkrootkit 顾名思义是监测系统是否被安装了rootkit 的一个安全工具。

安装chkrootkit,你可以自己去 http://www.chkrootkit.org/download/ 下载源码包,然后自己编译,也可以和我一样偷懒用别人做好的二进制包.

centos 下用非官方源安装chkrootkit:
首先添加dag 源for centos(我的系统是centos5.2)

# vi /etc/yum.repos.d/dag.repo
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

# rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

yum 安装chkrootkit
# yum update
# yum install chkrootkit

chkrootkit的应用
chkrootkit 的使用非常简单直接运行 chkrootkit 命令,然后会有如下输出

ROOTDIR is `/’
Checking `amd’… not found
Checking `basename’… not infected
Checking `biff’… not found
Checking `chfn’… not infected
Checking `chsh’… not infected
Checking `cron’… not infected
Checking `crontab’… not infected
Checking `date’… not infected
Checking `du’… not infected
Checking `dirname’… not infected
Checking `echo’… not infected
Checking `egrep’… not infected
Checking `env’… not infected
.
.
.

如果有rootkit会报“INFECTED” 所以可以直接用chkrootkit -n|grep ‘INFECTED’更直接一些。

定时检测并在出问题时给管理员发邮件。
创建如下脚本chkrootkit.sh并放入crontab 定时运行。

# cat chkrootkit.sh
#!/bin/bash
PATH=/usr/bin:/bin

TMPLOG=`mktemp`

# Run the chkrootkit
/usr/bin/chkrootkit > $TMPLOG

# Output the log
cat $TMPLOG | logger -t chkrootkit

# bindshe of SMTPSllHow to do some wrongs
if [ ! -z "$(grep 465 $TMPLOG)" ] && \
[ -z $(/usr/sbin/lsof -i:465|grep bindshell) ]; then
sed -i ‘/465/d’ $TMPLOG
fi

# If the rootkit have been found,mail root
[ ! -z "$(grep INFECTED $TMPLOG)" ] && \
grep INFECTED $TMPLOG | mail -s “chkrootkit report in `hostname`” root

# chmod 700 chkroot.sh
# mv chkrootkit /etc/cron.daily

这样系统会每天运行chkrootkit 检测系统,并在检测到rootkit 时给root 发一封邮件。

把给root 用户的系统邮件转发的管理员的gmail 邮箱

虽然可以登陆到系统去看系统邮件,但显然能用gmail 查看是更方便的选择。
1.安装sendmail 邮件转发要用到sendmail,
# yum sendmail
# /etc/intit.d/sendmail start (sendmail服务)
2.设置转发,编辑/etc/aliases,在文件最后加入
root: youname@gmail.com 然后运行newaliases 命令更新aliases
这样系统就会把给root 的邮件转发的你gmail 邮箱里去了。

本文中严重参考入侵监测系统的构建( chkrootkit ) 一文,感谢该文作者的工作。

Posted by Michael.Ding at 1:40 AM 0 comments