Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2474983
  • 博文数量: 867
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 9800
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-27 14:44
文章分类

全部博文(867)

文章存档

2007年(6)

2006年(861)

我的朋友

分类:

2006-09-07 09:42:29

Solaris的安全配置可以从以下几个方面来考虑:
1. 本地安全增强
包括: 限制某些强大命令的访问
设置正确的文件权限
应用组和用户的概念
suid/sgid的文件最少
rw-rw-rw的文件最少等

2. 网络安全增强
包括: 使用安全的协议来管理
禁止所有不需要的服务
禁止系统间的信任关系
禁止不需要的帐号
增强认证需要的密码
保护存在危险的网络服务
限制访问等

3. 应用安全增强
包括: 限制用户的权限
限制进程所有者的权限
检查应用相关文件权限
限制访问其他系统资源
应用所依赖的suid/sgid文件最少
使用应用本身的安全特性
删除samples和其他无用的组件

4. 监控与警报
包括: 日志、完整性、入侵检测等一些使用工具等

下面就详细讲述具体的配置过程。

一、 操作系统配置
1. 安装
1.1 安装最新的补丁
  安装patches对系统稳定和安全十分重要。
看系统中安装了那些补丁   #showrev –p       
更新更安全的补丁在  

1.2 初始安装时需要创建 /var分区,日志文件存在/var分区
1.3 安装最小的系统

2. 打开审计功能
审计包括很多的内容,可以根据需求设置。可以参考本文档中的日志和监控部分。

3. 系统参数配置
3.1 eeprom安全
   “eeprom security=command”系统将改变安全级别,并提示输入密码
   对于一般用户,从硬盘启动,不需要输入密码
   如果选择从光盘启动,则需要密码。主要防止物理接触。
   此项为可选配置,视具体需求而定。

3.2 将coredump大小设置为0
在/etc/system中加入如下一行:
set sys:coredumpsize = 0
将每次重启产生的coredump大小设置为0,不需要无用的信息。可选

3.3 修正堆栈错误,防止溢出(只对2.6后有效)
hacker进入系统后大部分是利用buffer overflow取得root shell
为了防止基于堆栈的缓冲区溢出,在/etc/system文件中加入
      set  noexec_user_stack=1        防止在堆栈中执行
set  noexec_user_stack_log=1     当某人试图运行增加一个记录
然后改变文件权限:#chmod 644 /etc/system
        
3.4 只允许root进行电源管理(只对2.6及以后版本有效)
    编辑/etc/default/sys-suspend:
    将     PERMS=console-owner
    改为   PERMS=-
    并做 #/bin/chmod 0755 /usr/openwin/bin/sys-suspend
    此项防止SYN Flood攻击

3.5 设置/tmp目录粘滞位,mode 1777
           创建文件/etc/rc3.d/S79tmpfix:
/bin/cat << EOF >/etc/rc3.d/S79tmpfix
#!/bin/sh
#ident "@(#)tmpfix 1.0 95/09/14"
if [ -d /tmp ]
then
/usr/bin/chmod g-s /tmp
/usr/bin/chmod 1777 /tmp
/usr/bin/chgrp sys /tmp
/usr/bin/chown sys /tmp
fi
EOF
改变S79tmpfix文件权限:
#/usr/bin/chmod 755 /etc/rc3.d/S79tmpfix
          此项给/tmp加上粘滞位,只允许写而不允许删除。这样,当黑客往/tmp写.socket文件时不允许删除。

      3.6 禁止stop-‘A’键
          在/etc/default/kbd中,改变或加入 “KEYBOARD_ABORT=disable”
          此项防止启动后,按stop-‘A’或L1-‘A’得到ok提示符,使用启动盘可以进入单用户模式,防止黑客物理接触机器。但此项不禁止可以作为密码丢失时的应急处理

4. 用户管理
4.1 禁止所有不需要的系统帐户
编辑/etc/passwd,将需要禁止帐户的**用NP代替
Example: noaccess:NP:60002:60002:No Access User:/:/sbin/noshell
需要禁止的帐户有:
bin, daemon, adm, lp, smtp, sys, uucp, nuucp, nobody, noaccess

4.2 使用强密码 
4.3 设置密码相关参数
编辑/etc/default/passwd,设置:
PWMIN=1 # 最短改变时间
PWMAX=13 # 密码最长有效时间
PWWARN=4 # 密码失效前几天通知用户
PWLEN=8 # 最短密码长度

4.4 防止root远程登陆
   编辑/etc/default/login,加上:
   CONSOLE=/dev/console # If CONSOLE is set, root can only login on that device.

4.5 记录所有root登陆尝试
# SYSLOG determines whether the syslog(3) LOG_AUTH facility should be used
# to log all root logins at level LOG_NOTICE and multiple failed login
# attempts at LOG_C
SYSLOG=YES

4.6  设置session超时时间
         编辑/etc/default/login,加上:
          # TIMEOUT sets the number of seconds (between 0 and 900) to wait before
# abandoning a login session.
TIMEOUT=120

4.7  设置缺省umask
         编辑/etc/default/login,加上:
          # UMASK sets the initial shell file creation mode mask. See umask(1).
UMASK=027
权限设置为750. “rw--r------“
对于如下文件,同样加上缺省umask:
/etc/.login, /etc/profile ,/etc/skel/local.cshrc
/etc/skel/local.login, /etc/skel/local.profile

4.8  设置root的umask
检查root的.profile,确保umask为027或077

4.9  确保提示输入密码
         
         # PASSREQ determines if login requires a password.
PASSREQ=YES

4.10 设置Shell环境变量
          编辑/etc/default/login,加上:
          # ALTSHELL determines if the SHELL environment variable should be set
ALTSHELL=YES

4.11 检查是否每个用户都设置了密码
           检查/etc/passwd和/etc/shadow,
           每个用户的密码栏是否为空。

4.12 编辑使用useradd的缺省配置,满足密码策略
           编辑/etc/sadm/defadduser,需要满足密码策略,比如:
           Example:
defgroup=15
defgname=users
defparent=/export/home
defskel=/etc/skel
defshell=/usr/bin/ksh
definact=30
defexpire=

4.13 在所有path中,去掉所有”.”路径
         检查所有缺省启动脚本和root启动脚本,在所有路径变量中删除“.”路径
         包括以下文件:
          /.login ,/etc/.login, /etc/default/login, /.cshrc, /etc/skel/local.cshrc,
           /etc/skel/local.login, /etc/skel/local.profile, /.profile ,/etc/profile

4.14 使用sugroup来限制su,将可以su的用户添加到这个组
          在 /etc/group中创建特殊的组sugroup
将你的管理员帐号加到这个组
改变 /bin/su 的权限为: r-sr-sr-x 1 root sugroup
#chmod 550 /bin/su
#chmod +s /bin/su
#chown root:sugroup /bin/su
#ls -al /bin/su
-r-sr-s--- 1 root sugroup 18360 Jan 15 1998 /bin/su
#grep sugroup /etc/group
sugroup::600:root,httpadm,wspher
这样,只有sugroup组中的用户可以使用su,提升为超级用户
另外一个可行的方法是使用sudo来替代su

     5. 开放的服务(inetd)
5.1 禁止所有不需要的服务
    在/etc/inetd.conf中注释掉左右不需要的服务,比如
name ,   shell ,   login,    exec,   comsat,   talk
rusersd   printer  finger    uucp   所有以“r”开头的服务
对必须提供的服务采用tcpwapper来保护

5.2 编译安装Tcp wapper
    安装tcpd,编辑inetd.conf中的服务为:
          ftp stream tcp nowait root /usr/local/bin/tcpd in.ftpd
telnet stream tcp nowait root /usr/local/bin/tcpd in.telnetd

5.3 定义限制的地址
    检查hosts.allow和hosts.deny
/etc/hosts.deny 为
ALL:ALL
提供的服务在/etc/hosts.allow定义
:

5.4 使用xinetd替代
    xinetd中可以限制特殊的inetd服务到特定的端口

6. 启动时提供的服务(rc.x)
6.1 禁止所有不需要的服务
   在rc.x目录中将不需要的服务改名,比如
   Example: mv /etc/rc3.d/S92volmgt /etc/rc3.d/KS92volmgt
   以下服务应该禁止(根据需要自己决定):
snmpdx
autofs (Automounter)
volmgt (Volume Deamon)
lpsched (LP print service)
nscd (Name Service Cache Daemon)
Sendmail
keyserv (Keyserv Deamon is only used if NIS+ or NFS are installed, if used start with
–d option so that the defaults “nobody” key is not allowed)
     rpcbind提供远程呼叫,依靠远程系统的ip地址和远程用户的ID进行验证,这样很容易伪造和改变

6.2 禁止所有DMI服务
禁止所有DMI服务: mv /etc/rc3.d/S??dmi /etc/rc3.d/K??dmi
/etc/init.d/init.dmi中启动的dmi服务有:
/usr/lib/dmi/dmispd
/usr/lib/dmi/snmpXdmid
/etc/dmi/ciagent/ciinvoke

6.3 去掉mount系统的suid位
   在/etc/rmmount.conf中加上
          mount hsfs -o nosuid
mount ufs -o nosuid

6.4 检查所有的.rhosts文件
    .rhosts允许不要密码远程访问,
       预先生成 $HOME/.rhosts文件,并且设置为0000,防止被写入”+ +”。(攻击者经常使用类似符号链接或者利用ROOTSHELL写入)。
注:这种情况会导致一些如SSH的RCP命令无法使用(需要使用 $HOME/.rhosts文件的一些命令)
touch /.rhosts ;chmod 0 /.rhosts 

 .rhosts可以被普通用户所创建在个人目录下。推荐使用脚本来发现.rhosts文件。并且利用cron自动检查,报告给特定用户。
Script for Find.rhost:
#!/bin/sh
/usr/bin/find /home -name .rhosts | (cat <this only find .rhost:
EOF
cat
) | /bin/mailx -s "Content of .rhosts file audit report" yourmailbox

6.5 禁止使用.rhosts认证
在/etc/pam.conf中删除
rlogin auth sufficient /usr/lib/security/pam_rhosts_auth.so.1
将rsh的行改为:
rsh auth required /usr/lib/security/pam_unix.so.1

6.6 检查信任关系
检查/etc/hosts.equiv文件,确保为空

7.网络接口调整和安全优化
7.1 /etc/rc2.d/S??inet参数调整
在/etc/rc2.d/S??inet中做如下参数调整:
缩短ARP的cache保存时间:
ndd -set /dev/arp arp_cleanup_interval 60000 /* 1 min (default is 5 min*/
缩短ARP表中特定条目的保持时间:
ndd -set /dev/ip ip_ire_flush_interval 60000 /* 1 min (default is 20 min*/
关闭echo广播来防止ping攻击
ndd -set /dev/ip ip_respond_to_echo_broadcast 0 # default is 1
关闭原路由寻址
ndd -set /dev/ip ip_forward_src_routed 0 # default is 1
禁止系统转发IP包
ndd -set /dev/ip ip_forwarding 0 # default is 1
禁止系统转发定向广播包
ndd -set /dev/ip ip_forward_directed_broadcasts 0 # default is 1
使系统忽略重定向IP包
ndd -set /dev/ip ip_ignore_redirect 1 # default is 0
使系统限制多宿主机
ndd -set /dev/ip ip_strict_dst_multihoming 1 # default is 0
再次确保系统关闭ICMP广播响应
ndd -set /dev/ip ip_respond_to_address_mask_broadcast=0 # default is 1
关闭系统对ICMP时戳请求的响应
ndd -set /dev/ip ip_ip_respond_to_timestamp=0 # default is 1
关闭系统对ICMP时戳广播的响应
ndd -set /dev/ip ip_ip_respond_to_timestamp_broadcast=0 # default is 1
禁止系统发送ICMP重定向包
ndd -set /dev/ip ip_send_redirects=0 # default is 1

7.2 改变TCP序列号产生参数
在/etc/default/inetinit中改变
TCP_STRONG_ISS=2

7.3 设置in.routed运行在静态路由模式
创建文件/usr/sbin/in.routed为以下内容:
#! /bin/sh
/usr/sbin/in.routed.orig –q
改变文件属性:
chmod 0755 /usr/sbin/in.routed
# 动态路由可能会收到错误的路由信息,所以建议使用静态路由
Consider to use static routes (routes added via the route commands in startup files)
rather than the routing daemons

7.4 禁止路由功能
创建空文件notrouter: touch /etc/notrouter

7.5 利用ip-filter
ip-filter是Solaris系统的内核模块,可以完成简单包过滤

8. 文件权限
8.1 删除所有不使用的suid文件
列出系统中所有 suid 文件
find / -type f \( -perm -4000 \) –exec ls –al {} \;
find / -type f \( -perm -4000 \) –exec ls –al {} \; >  $HOME/search-4-suid-files.txt
首先备份 suid 文件:
mkdir /opt/backup/suid
find / -type f \( -perm -4000 \) -print |cpio -pudm /opt/backup/suid
删除前建立tar备份,不要删除suid-files.tar!!
cd /opt/backup; tar –cvpf suid-files.tar /opt/backup/suid/*
rm –r /opt/backup/suid
去除所有suid 文件中的suid 位
find / -type f \( -perm -4000 \) –exec chmod –s {} \;
  再查一遍
find / -type f \( -perm –4000 \) –exec ls –al {} \;
对一些常用文件建立suid 位
chmod u+s /usr/bin/su 
chmod u+s /usr/bin/passwd 
chmod u+s /usr/bin/ps 

8.2 删除所有不使用的sgid文件
列出系统中所有 suid 文件
find / -type f \( -perm -2000 \) –exec ls –al {} \;
find / -type f \( -perm -2000 \) –exec ls –al {} \; >  $HOME/search-4-sgid-files.txt
首先备份 sgid 文件:
mkdir /opt/backup/sgid
find / -type f \( -perm -2000 \) -print |cpio -pudm /opt/backup/sgid
删除前建立tar备份,不要删除sgid-files.tar!!
cd /opt/backup; tar –cvpf sgid-files.tar /opt/backup/sgid/*
rm –r /opt/backup/sgid
去除所有sgid 文件中的sgid 位
find / -type f \( -perm -2000 \) –exec chmod –s {} \;
  再查一遍
find / -type f \( -perm –2000 \) –exec ls –al {} \;
对一些常用文件建立sgid 位

8.3 删除/etc下所有组可写文件
find /etc -type f \( -perm -20 \) –exec ls –al {} \;
find /etc -type f \( -perm -20 \) –exec ls –al {} \; > search-4-group-writeable-in-etc.txt
/etc下不应有组可写文件,去掉写权限
find /etc -type f \( -perm –20 \) –exec chmod g-w {} \;

8.4 删除/etc下所有world可写文件
find /etc -type f \( -perm -2 \) –exec xargs ls –als {} \;
find /etc -type f \( -perm -2 \) –exec xargs ls –als {} \; > search-4-world-writeable-in-etc.txt
/etc下不应有world可写文件,去掉写权限
find /etc -type f \( -perm –2 \) –exec xargs chmod w-w {} \;

8.5 将权限为rw-rw-rw-的文件改为rw-r—r—
           find / -type f -perm 666 |xargs ls -al > perm-666-before-change.txt
decide if one of these files are critical
find / -type f -perm 666 –exec chmod 644 {} \;
find / -type f -perm 666 –exec xargs ls –al {} \; > perm-666-after-change.txt

8.6 改变rwxrwxrwx文件的权限 
           find / -type f -perm 777 –exec xargs ls -al {} \; > perm-777-before-change.txt
decide if one of these files are critical
find / -type f -perm 777 –exec xargs chmod 755 {} \;
find / -type f -perm 777 –exec xargs ls -al {} \; > perm-777-after-change.txt

8.7 查找world,group可写的目录
    find / -type d \( -perm 2 \) –print > search-4-world-writeable-directories.txt
     find /etc -type f \( -perm -20 \) –print > search-4-group-writeable-dir.txt

8.8 确保每个root启动的脚本属于root
           首先查找所有启动脚本的属主
           find /etc -type f -print | grep rc | egrep -v "skel|tty|mail|snmp|Mail" | xargs ls -al > rc-
files before change txt
    改变属主
           find /etc -type f -print | grep rc | egrep -v "skel|tty|mail|snmp|Mail" | xargs chown
root:root
find /etc -type f -print | grep rc | egrep -v "skel|tty|mail|snmp|Mail" | xargs ls -al > rc-files-after-change.txt
ls -al /etc/init.d > etc-init.d-before.change.txt
chown root:root /etc/init.d
ls -al /etc/init.d > etc-init.d-after-change.txt
   此项用于防止木马攻击
   (升级或打补丁后需要重做此项)

8.9 确保所有cron行为有记录
   在/etc/default/cron中 CRONLOG=YES
   删除/var/spool/cron/crontabs 目录中除了root文件外所有文件

8.10 改变utmp,utmpx的权限
    chmod 644 /var/adm/utmp

8.11 查找无用户文件
1) find / -type f -nouser > files-nouser-before-change
2) find / -type f -nouser | xargs chwon nobody:nobody
3) find / -type f -nouser > files-nouser-after-change

8.12 查找无组文件
           1) find / -type f -nogroup > files-nogroup-before-change
2) find / -type f -nogroup | xargs chgrp nobody
3) find / -type f -nogroup > files-nogroup-after-change

8.13 改变/var/cron权限
     chmod 700 /var/cron && chown root /var/cron && chgrp sys /var/cron

9.日志和监控
 9.1 将cron logfiles的大小设为2M
     /etc/cron.d/logchecker中 LIMIT=4096

 9.2 记录所有inetd服务
     编辑/etc/init.d/inetsvc,有如下条目
            /usr/sbin/ifconfig –au netmask + broadcast +
/usr/sbin/inetd -s –t

 9.3 修改syslog.conf
     编辑syslog.conf,增加
     *.debug /var/adm/compass.messages #记录debug信息
      auth.info /var/log/authlog

 9.4 创建/var/adm/loginlog来记录登陆失败信息
            touch /var/adm/loginlog
chmod 600 /var/adm/loginlog
chown root /var/adm/loginlog
chgrp sys /var/adm/loginlog
Modification

9.4 安装Tripwire
     Tripwire为完整性检查工具,能有效防止木马

 9.5 安装IDS工具,比如snort
 9.6 安装日志检测工具,比如swatch
 9.7 设置banner
     在/etc/issue中编辑警告banner

二、应用程序安全配置
1.总体安全考虑
  应用程序以非特权用户运行
  定义应用程序属主
  删除所有的samples
  chroot,改变进程的root目录
  具体应用考虑

2. NFS服务
   2.1 禁止nfs服务
杀掉如下NFS进程: lockd, nfsd, statd, mountd
   NFS是由/etc/dfs/dfstab文件控制,为了禁止NFS服务的后台程序
   将/etc/rc2.d/S15nfs.server文件改名 K15nfs.server
   将/etc/rc2.d/S73nfs.client文件改名 K13nfs.client
   /etc/dfs/dfstab 文件有几个选项
      share –F nfs –o [rw/ro]  /目录名         
client端有读写权限, ro是client端只有读权限 [建议使用ro选项]

   2.2 如必须使用,则设置nfs特殊tcp,udp端口
       ndd -set /dev/tcp tcp_extra_priv_ports_add 2049
        ndd -set /dev/udp udp_extra_priv_ports_add 2049

   2.3 打开nfs port monitoring功能
在/etc/system中加入
set nfssrv:nfs_portmon = 1
set nfs:nfs_portmon = 1

 3. NIS服务
   NIS是不安全的服务,建议卸载运行包,使用和设置NIS+会更安全

4. Ftp服务
4.1 在/etc/passwd文件中
ftp:x:30000:30000:Anonymous FTP:/ftp目录:/nosuchshell
4.2在/etc/shadow文件中
ftp:NP:6445::::::
4.3 FTP-server的配置文件/etc/ftpaccess
        class   local    real *              重定义真实用户为local
        class   remote  guest,anonymous *  重定义匿名用户为remote       
        limit   local  100   Any  /ftp目录/msgs/limit.local限制登录用户数
        limit   remote 100 Any / ftp目录/msgs/limit.remote  限制登录用户数
        banner  /ftp目录/msgs/msg.banner        
        loginfails 2   重试次数 
        readme  README*    login
        readme  README*    cwd=*
        message  /ftp目录/msgs/welcome.msg      login   local remote
        message  /ftp目录/msgs/cwd.msg          cwd=*   remote
        compress        yes             local,remote
        tar             yes             remote,local
        log commands real
        log transfers anonymous,real,guest inbound,outbound
        shutdown  /ftp目录/msgs/shutmsg

  4.4 创建ftp banner
      创建Banner文件 /etc/ftp-banner

  4.5 创建/etc/ftpusers文件
      将系统用户加入:root daemon sys bin adm lp smtp uucp nuucp listen
nobody noaccess news ingres audit admin sync nobody4
touch /etc/ftpusers
for user in root daemon bin sys nobody noaccess \
nobody4 uucp nuucp adm lp smtp listen
do
echo  $user >>/etc/ftpusers
done
chown root /etc/ftpusers
chgrp root /etc/ftpusers
chmod 600 /etc/ftpusers
Modification

5. Telnet服务
  5.1 删除/etc/default/telnetd的Banner内容
  5.2 尽量使用ssh来替代telnet 



求助
  如果你怀疑或确定系统已经被入侵,请迅速联系21vianet_CERT世纪互联安全紧急响应中心。
  EMail:  
  热线电话: 86010-84562121-????
  我们的紧急响应中心提供7*24小时的安全服务。



本文参考资料(主要为翻译整理)
Hardening_Solaris_CSNC_V1.0.pdf   Author: Ivan Buetler, Compass Security AG
UNIX Computer Security Checklist (Version 1.1)      by Australian CERT
Solaris Security Step by Step                        by sans.org
阅读(473) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~