Linux系统安全

时间:2007-10-02 10:16:47   来源:chinaitzhe.com  作者:ChinaITzhe  编辑:gaopoadmin


  Linux 系统安全讲座
  
  ---------------
  大纲
  
  * 注:
  授课内容主要以<>为主□
  再配以网页资料为副。
  ---------------
  
  网路安全层次
  网路
  服务
  系统
  
  系统安全
  物理保安
  地理防御
  门禁制度
  社交工程 P2-13
  机房保护
  机柜
  主机
  电源
  键盘
  荧幕
  开机保护
  钥匙
  电源按钮
  BIOS
  启动设备:
  硬碟
  软碟
  光碟
  OS Loader
  LILO P8-2
  GRUB info grub (参考范例一)
  
  开机程式 (run level & rc) P7-1
  系统登录
  Login
  PAM P1-20
  ls /usr/share/doc/pam-0.75/
  Limit more /etc/security/limits.conf
  Nologin touch /etc/nologin
  Consol vs remote more /etc/securetty
  L istfile (参考范例二)
  帐号管理
  帐号名称和 UID P1-5
  群组 P2-2~P2-7
  帐号密码 P2-12
  Crack / John
  shadow P1-11
  chage info change
  usermod info usermod
  gpasswd info gpasswd
  权限管理
  ugo & rwx P3-8
  档案 vs 目录 x ?
  木马与病毒 root or non-root?
  SUID & SGID & Sticky Bit P4-2
  档案 vs 目录
  侦查技巧 P4-4
  su vs sudo
  su 缺失 passwd? privilege?
  sudoers 设计 info sudoers
  档案属性 P4-8
  appand only
  read only
  档案系统设计
  file type P3-2
  inode & block P3-6
  http://www.study-area.org/linux/system/linux_fs.htm#fstab
  mount point
  quota http://www.study-area.org/linux/system/linux_fs.htm#fquota
  read only /usr/bin /usr/sbin...
  no dev /home
  no suid / no sgid
  no exec
  安全下载
  信任网站 rpmfind, sourceforge...
  GPG 签章 *.sign
  MD5 checksum info md5sum
  软体测试
  执行码
  生成档
  连线/生成封包
  源码追踪
  入侵侦测
  异常行为
  多余连线
  记录档残缺
  档案替换
  档案权限改变
  隐藏档
  拥有者变更
  suid / sgid
  设备档
  工具:
  chkrootkit
  http://linux.tnc.edu.tw/techdoc/check-rootkit-by-u-self.htm
  tripwire
  http://www.study-area.org/tips/tripwire.htm
  tiger
  ftp://coast.cs.purdue.edu/pub/tools/unix/TAMU
  日志保护
  延增属性 chattr +a
  存取权限 (root only)
  size 控制 logrotate
  http://www.study-area.org/linux/system/linux_conf.htm#log
  真实性 (防止修改) @central / printer
  记录分析
  工具:
  logcheck
  logwatch
  资料备份
  原始备份
  系统备份 vs 资料备份
  完整备份 vs 差异备份
  http://www.study-area.org/linux/system/linux_conf.htm#backup
  备份媒体 & 保存
  备份抽样 tar, cpio/apio
  灾后复原
  风险评估
  容错等级
  复原程度
  容错方案/设备:
  连线:
  redundent connection
  load balance
  cluster
  内容:
  RAIDS
  SAN & NAS
  Mirror & rsync
  修补 P14-3
  版本选择
  最安全版本□ ftp://linux.sinica.edu.tw/
  更新 mirror / APT / rhn
  测试
  
  ------------
  网路安全
  安全资讯
  网站
  http://www.cert.org.tw
  http://www.vtcif.telstra.com.au/info/security.html
  http://www.redhat.com/apps/support/errata/
  wu-ftp
  zlib
  UW imap
  openssh
  ssnldap
  .....
  http://www.securityfocus.com/
  http://safe.ip-market.com/
  讨论群组/新闻组
  news:comp.security.announce
  Mail List / 技术论坛
  listserv@securityfocus.com
  digest@sams.org
  杂志
  服务程式漏洞与修补
  服务程式数量 P12-3
  集中 vs 分散
  版本更新 wu-ftp, bind, sendmail
  测试
  chroot 技巧
  使用时机
  可行软体
  http://www.study-area.org/tips/dns_chr.htm
  困难点
  tcpwrapper 之应用
  Compile time vs run time
  Supper daemon vs tcp_wrapper P15-2
  Inetd vs xinetd P11-2
  hosts.allow vs hosts.deny P15-9
  services * 附录一
  防火墙和 NAT
  防火墙种类
  proxy vs filtering P16-1 / P17-1
  防火墙工作原理
  http://www.study-area.org/network/network_fw.htm
  基础知识
  http://www.study-area.org/linux/servers/linux_nat.htm
  防火墙规则设计
  ACL vs state list
  NAT 之应用场合
  NAT 种类
  SNAT vs DNAT
  Statice vs Dynamic
  http://www.study-area.org/tips/NAT-HOWTO/NAT-HOWTO-chn-3.html
  网路架构之设计与部署
  信任网路 vs 非信任网路
  DMZ 应用
  物理区隔
  Protocol Switching
  常见攻击方法
  DoS
  Ping of death P13-2
  Syn Flood P13-6
  其他 P13-8
  因应 P13-9
  自我攻击测试
  netstat
  http://www.study-area.org/linux/servers/linux_net.htm#network
  nmap P25-8
  portsentry / snort
  -------------
  资讯加密
  明文 vs 密文
  荧幕显示 vs 封包内容
  http://www.study-area.org/network/network_enscp.htm
  窃听技巧与防范
  窃听前提 packet?
  窃听工具
  tcpdump
  sniffit
  拦截点 routing ?
  Hub vs Swtich CSMA/CD?
  加密手段和原理
  加密原理
  原始加密方法
  http://www.study-area.org/network/network_enscp.htm
  演算法
  技术专利
  加密技术
  对称密钥 vs 非对称密钥
  http://www.study-area.org/network/network_enscp.htm
  美国之出口限制
  电子签章
  纸张 vs 电子
  可确认性/非抵赖性
  电子交易之现况与将来
  安全连连线
  ssl & ssh
  破解成本
  http://www.study-area.org/tips/security.htm
  (http://www.nchu.edu.tw/trnc/90-2/firewall.ppt)
  ssh 工作原理
  http://www.study-area.org/tips/security.htm
  vpn 之建置
  VPN 原理
  应用场合
  VPN 方案:
  ssh
  vpnd
  http://www.study-area.org/tips/vpn.htm
  ipsec P21-3
  网路设计 vs 实作技术 subnet/routing?
  
  实作参考
  安全的伺服器环境(1)
  http://safe.ip-market.com/article.php?sid=5
  确保Linux安全的十招
  http://safe.ip-market.com/article.php?sid=26
  Linux安全设置手册(转贴)
  http://phorum.study-area.org/viewtopic.php?t=5080&highlight=time-out%3D00
  
  ---------------
  
  * 范例一: GRUB 密码保护
  
  1) 输入 grub 进入其中产生 MD5 密码:
  grub> md5crypt
  Password: **********
  Encrypted: $1$U$JK7xFegdxWH6VuppCUSIb.
  ** 完成后请用滑鼠左键将密码选取,并输入 quit 退出 grub 。
  
  2) 修改 /etc/grub.conf 进行密码保护设定:
  password --md5 $1$U$JK7xFegdxWH6VuppCUSIb.
  ** 请用滑鼠中键将密码贴上。
  title Red Hat Linux 7.3 (2.4.18-3)
  lock
  root (hd0,1)
  kernel /vmlinuz-2.4.18-3 ro root=/dev/hda12
  initrd /initrd-2.4.18-3.img
  
  3) 在开机的时候输入 p 和密码。
  
  
  * 范例二: PAM 之 listfile (ssh)
  
  1) 参考 ftp 之现成设定:
  grep listfile /etc/pam.d/ftp
  
  2) 模仿之并在 ssh 中设定:
  vi /etc/pam.d/sshd
  在前面加入:
  auth required /lib/security/pam_listfile.so item=user /
  sense=deny file=/etc/sshusers onerr=succeed
  
  
  ---------------
  附录一: 系统服务建议
  finger 强烈建议关闭
  ftp 如果不需要□尽量关闭。尤其 anonymous 更应关闭。
  gopher 关闭
  imap 如果不需要□尽量关闭。
  pop2 关闭
  pop3 如果不需要□尽量关闭。
  talk 关闭
  ntalk 关闭
  telnet 如果不需要□尽量关闭。请以 ssh 取代之。
  uucp 关闭
  
  samba 只对内部开放
  nfs/nis 只对内部开放
  r-command 尽量关闭□以 ssh 取代。
  x-protocol 只对内部开放
  
  
  
  * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~
  
  -----------------------
  Linux 系统安全实作
  -----------------------
  
  目标:
  透过实作加强 Linux 系统的安全防御能力。
  并以此举一反三□提高管理员的安全意识和技巧。
  
  作业平台环境:
  OS: RedHat7.3
  安装选项: 伺服器模式
  
  范例帐号资料:
  sysop: 系统管理员
  u1: 普通帐号
  u2: 受限制帐号
  
  范例网路规划:
  分组模拟:
  WAN: 10.0.1.x
  LAN: 192.168.1.x ~ 192.168.254.x
  闸道主机环境:
  外部界面: eth0
  外部IP: 10.0.1.#
  GATEWAY: 10.0.1.254
  内部界面: eth1
  内部 IP: 192.168.#.254
  主机名称: gw.g#.test.edu
  内部主机环境:
  界面: eth0
  IP: 192.168.1.#.2
  GATEWAY: 192.168.#.254
  主机名称: server.g#.test.edu
  
  
  主要项目:
  * clock
  * Firewall
  * tcpwrapper
  * PAM
  * service
  * system
  * VPN
  * NAT + T_PROXY
  * Intrusion detection
  * Package Upgrade
  
  
  -----------------------
  实作步骤:
  
  注∶ # 开头的句子基本上为一行一个命令□若在 vi 命令中则为注解符号。
  ^ 为 Ctrl 键( ^D 就是同时按下 Ctrl 和 D 键)
  
  
  一□修正时间
  
  # vi /etc/cron.daily/clock
  echo
  ntpdate time.stdtime.gov.tw
  clock -w
  echo
  echo
  # chmod +x /etc/cron.daily/clock
  # sh /etc/cron.daily/clock
  
  二□防火墙
  
  1) 关闭 ipchains:
  # service ipchains stop
  # rmmod ipchains
  # chkconfig --del ipchains
  # chkconfig --add iptables
  # chkconfig iptables on
  # mv /etc/sysconfig/ipchains /etc/sysconfig/ipchains.bak
  (** 以上若干命令若执行失败可置之不理)
  2) 启动 iptalbes:
  # for MOD in ip_tables iptable_filter ip_conntrack ip_conntrack_ftp; do
  > modprobe $MOD
  > done
  3) 设定规则:
  # service iptables stop
  # for PORT in 20 21 22 25 53 80 110 113 143 220 443 465 993 995; do
  > iptables -A INPUT -p tcp --dport $PORT -j ACCEPT
  > done
  # iptables -A INPUT -p udp --dport 53 -j ACCEPT
  # for TYPE in 0 3 3/4 4 11 12 14 16 18; do
  > iptables -A INPUT -p icmp --icmp-type $TYPE -j ACCEPT
  > done
  # iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  # iptables -A INPUT -i lo -j ACCEPT
  # iptables -A INPUT -j DROP
  4) 保存设定规则:
  # mv /etc/sysconfig/iptables /etc/sysconfig/iptables.bak
  (以上命令若执行失败可置之不理)
  # iptables-save > /etc/sysconfig/iptables
  # chkconfig iptables on
  
  
  三□TCPWRAPPER
  
  1) 备份:
  # cp /etc/hosts.allow /etc/hosts.allow.bak
  # cp /etc/hosts.deny /etc/hosts.deny.bak
  2) 关闭所有:
  # echo "ALL: ALL" >> /etc/hosts.deny
  3) 视个别开放:
  # vi /etc/hosts.allow
  ALL: 127.0.0.1, localhost
  sshd: ALL
  in.ftpd: ALL
  sendmail: ALL
  ipop3d: 192.168.
  * 注: 这样的设计并不对外提供 pop 服务。
  如果 pop 主机不是和内部网路直接相连接□
  同时内部网路透过 NAT 连线至 pop 主机的话□
  请将 192.168. 改为 NAT 主机的外部 IP 。
  
  
  四□PAM
  
  1) 设定 ssh: (可参考前文之范例二)
  
  # vi /etc/pam.d/sshd (** 在档案前面加入如下: )
  auth required /lib/security/pam_listfile.so item=user /
  sense=allow file=/etc/sshusers onerr=fail
  # echo "root" >> /etc/sshusers
  # echo "sysop" >> /etc/sshusers
  2) 限制 su 群组:
  # vi /etc/pam.d/su (** 取消如下注解: )
  auth required /lib/security/pam_wheel.so use_uid
  
  五□SERVICE
  
  * FTP
  1) 取消 anonymous FTP
  # rpm -e anonftp
  # cp /etc/ftpusers /etc/ftpusers.bak
  # echo "ftp" >> /etc/ftpusers
  2) 取消部份 user 之 guest 限制:
  # vi /etc/ftpaccess (** 在 # realuser user1,user2 句子下面增加如下: )
  realuser sysop u1
  ** sysop 与 u1 仅作范例,请改用您的真实帐号。
  * POP / IMAP
  1) 安装 imap (请先 mount 好 rh7.3 第二片 CDROM )
  # rpm -ivh /mnt/cdrom/RedHat/RPMS/imap-*
  2) 开启 pop3s
  # vi /etc/xinetd.d/pop3s
  disable = no
  ** 如下 ipop3 则视需要而定□除非不能用 ssl □否则不建议开启:
  # vi /etc/xinetd.d/ipop3
  disable = no
  3) 重新启动 xinetd:
  # service xinetd restart
  4) 设定 ssl 认证:
  # cd /usr/share/ssl/certs
  # make ipop3d.pem
  # /usr/bin/openssl req -newkey rsa:1024 -keyout /root/1.pem -nodes -x509 -days 365 -out /root/2.pem
  Using configuration from /usr/share/ssl/openssl.cnf
  Generating a 1024 bit RSA private key
  .....++++++
  ....++++++
  writing new private key to '/root/1.pem'
  -----
  You are about to be asked to enter information that will be incorporated
  into your certificate request.
  What you are about to enter is what is called a Distinguished Name or a DN.
  There are quite a few fields but you can leave some blank
  For some fields there will be a default value,
  If you enter '.', the field will be left blank.
  -----
  Country Name (2 letter code) [GB]:TW # 输入国家代码
  State or Province Name (full name) [Berkshire]:Taiwan # 输入省名
  Locality Name (eg, city) [Newbury]:TaiChung # 输入市名
  Organization Name (eg, company) [My Company Ltd]:Test Edu # 输入工作单位
  Organizational Unit Name (eg, section) []:G1 # 输入部门
  Common Name (eg, your name or your server's hostname) []:server.g1.test.edu # 主机名
  Email Address []:sysop@server.g1.test.edu # 邮件信箱
  # cat /root/1.pem > ipop3d.pem
  # echo "" >> ipop3d.pem
  # cat /root/2.pem >> ipop3d.pem
  5) 设定 Client (OutLook Express 为例):
  工具->帐号->邮件->内容->进阶->下面的pop3
  [ V ] 此服务器要求安全连结(ssl)
  ** 注意: “伺服器”名称一栏不能使用 IP □必须为 DNS 能解释的名称。
  
  * SMTP (AUTH)
  1) 设定 sendmail:
  # chkconfig sendmail on
  # cd /etc/mail
  # vi sendmail.mc (** 取消两行注解 dnl ,另再注解末行∶ )
  TRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  ......
  dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
  # cp -a /etc/sendmail.cf /etc/sendmail.cf.orig
  # m4 sendmail.mc > /etc/sendmail.cf
  # echo '192.168 RELAY' >> /etc/mail/access
  # makemap hash /etc/mail/access.db < /etc/mail/access
  ** 注意: 请每天使用 sysop 帐号来收 root 的信件,否则不需要设定如下两行。
  # echo 'root: sysop' >> /etc/aliases
  # newaliases
  2) 重新启动 sendmail
  # service sendmail stop
  # service sendmail stop
  # service sendmail start
  
  3) 设定 client 端( AUTH SMTP)
  工具->帐号->邮件->内容->伺服器
  [ V ] 我的伺服器需要查验身份(v)
  ** 注意: 可惜目前还不支援 SSL 的连线□为安全其见□别透过 ineternet 使用密码。
  ** 或参考如下实作完成∶
  http://www.study-area.org/tips/ssl_email.htm
  
  * HTTP
  1) 设定 server
  预设即可□需要特别留意 CGI 的权限设定。
  在网页设计上□遇到密码验证的提示网页□尽量使用 https 。
  
  * 其它服务
  1) 关闭不需要的服务:
  # for SRV in autofs isdn lpd netfs nfs nfslock portmap rhnsd sgi_fam; do
  > chkconfig $SRV off
  > done
  ** 注意: 上述服务尽量不对外提供。
  
  
  六□系统
  
  * BIOS
  1) 设定 BIOS 系统和设定密码
  2) 将开机设备设定为硬碟优先
  3) 开机时输入密码
  
  * BOOT LOADER
  1) 设定 grub (参考另文之范例一):
  # grub
  grub> md5crypt
  Password: **********
  Encrypted: $1$U$JK7xFegdxWH6VuppCUSIb.
  ** 完成后请用滑鼠左键将密码选取,并输入 quit 退出 grub 。
  # vi /etc/grub.conf
  password --md5 $1$U$JK7xFegdxWH6VuppCUSIb.
  ** 请用滑鼠中键将密码贴上。
  title Red Hat Linux 7.3 (2.4.18-3)
  lock
  root (hd0,1)
  kernel /vmlinuz-2.4.18-3 ro root=/dev/hda1
  initrd /initrd-2.4.18-3.img
  (**注意∶请勿修改 title, root, kernel, initrd 等句子,只需在 title 下加入 lock 设定。)
  
  2) 在开机的时候输入 p 和密码。
  
  * SYSTEM ACCOUNT
  1) 删除不必要的帐号/群组:
  # for FILE in /etc/group /etc/passwd /etc/shadow; do
  > cp -a $FILE ${FILE}.orig
  > done
  # for UG in lp sync shutdown halt news uucp operator games gopher rpc rpcuser; do
  > userdel $UG
  > groupdel $UG
  > done
  ** 注意: 帐号名称以实际的机器用途为准。当前范例主要以“非 LAN server” 为准。
  2) 增加密码长度限制:
  # vi /etc/login.defs
  PASS_MIN_LEN 8
  3) 设定自动登离时间:
  # vi /etc/profile
  export TMOUT=1800
  4) 取消普通帐号之 console 程式:
  # mv /etc/security/console.apps /etc/security/console.apps.orig
  5) 设定预设 RunLevel □并取消 Ctrl+Alt+Del 键之 reboot 功能:
  # vi /etc/inittab
  id:3:initdefault:
  #ca::ctrlaltdel:/sbin/shutdown -t3 -r now
  (注∶为上行注解,请在退出 vi 之前完成)
  重新读入 inittab 设定:
  # /sbin/init q
  6) 修改登录提示
  # vi /etc/issue
  WARNING: This system is open to authorized users only.
  Please do NOT bleak in and all activity is logged.
  # cat /etc/issue > /etc/issue.net
  7) 设定 sudoers (本例增加 sysop ):
  # visudo
  ** 取消如下注解∶
  %wheel ALL=(ALL) ALL
  # gpasswd -a sysop wheel
  8) 修改 logroate 的设定(档案属性):
  # vi /etc/logrotate.d/syslog
  /var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
  prerotate
  chattr -a /var/log/messages
  chattr -a /var/log/secure
  chattr -a /var/log/maillog
  chattr -a /var/log/spooler
  chattr -a /var/log/boot.log
  chattr -a /var/log/cron
  endscript
  sharedscripts
  postrotate
  /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
  chattr +a /var/log/messages
  chattr +a /var/log/secure
  chattr +a /var/log/maillog
  chattr +a /var/log/spooler
  chattr +a /var/log/boot.log
  chattr +a /var/log/cron
  endscript
  }
  9) 修改 fstab :
  ** 这里仅作范例,请依实际情况调整。若没此设定要求,请略过。
  # vi /etc/fstab
  LABEL=/home /home ext3 defaults,nodev,noexec,nosuid 1 2
  LABEL=/tmp /tmp ext3 defaults,noexec,nosuid 1 2
  # cd
  # umount /home
  # mount -a
  
  
  
  七□VPN
  
  (模拟机器将转移到‘闸道主机’中进行)
  
  --------------
  测试环境(假设):
  
  remote 端(g1):
  real: 201.0.1.1
  vpn: 192.168.1.254
  local 端 (g2):
  real: 202.0.2.2
  vpn: 192.168.2.254
  
  --------------
  设定步骤:
  
  1) 在 201.0.1.1 上设定 SSH
  # mkdir /etc/skel/.ssh
  # useradd -m vpn1
  2) 在 202.0.2.2 上执行:
  # ssh-keygen -t rsa
  # 按三下 Enter 不设定密码
  3) 转回 201.0.1.1 上面执行:
  # cd ~vpn1/.ssh
  # scp 202.0.2.2:/root/.ssh/id_rsa.pub ./
  # cat id_rsa.pub >> authorized_keys
  # chown -R vpn1.vpn1 ~vpn1/.ssh
  # chmod 711 ~vpn1/.ssh
  # chmod 644 ~vpn1/.ssh/authorized_keys
  4) 再到 202.0.2.2 上面测试 ssh 的 RSA 连线□确定无需密码:
  # ssh -l vpn1 201.0.1.1
  
  * 设定 remote 端
  
  1) 在 201.0.1.1 上执行 visudo □增加如下数行:
  User_Alias VPNUSER=root,vpn1
  Cmnd_Alias VPN=/usr/sbin/pppd,/sbin/route
  VPNUSER ALL=(ALL) NOPASSWD: VPN
  2) 在 /usr/local/sbin 里面建立一个可执行的 script □取名为 vpn-ppp :
  #!/bin/bash
  exec sudo /usr/sbin/pppd
  ** 注意: 请记得执行: chmod +x /usr/local/sbin/vpn-ppp
  3) 修改 vpn1 的 shell :
  usermod -s /usr/local/sbin/vpn-ppp vpn1
  
  * 设定 local 端
  
  1) 下载 pty-redir-0.1.tgz 到 202.0.2.2 机器□并将档案解至 /usr/local 内:
  # wget http://www.study-area.org/linux/src/pty-redir-0.1.tgz
  # tar zxvf pty-redir-0.1.tgz
  # mv pty-redir-0.1 /usr/local
  # cd /usr/local/pty-redir-0.1
  # make
  # cp pty-redir /usr/local/sbin
  2)复制 vpnd 至 init.d 目录:
  # cp vpnd /etc/rc.d/init.d
  
  3) 修改其中的内容:
  LOCALIP=192.168.2.254
  LOCALNET=192.168.2.0/24
  REMOTEIP=192.168.1.254
  REMOTENET=192.168.1.0/24
  SSHSERVER=201.0.1.1
  $REDIR $SSH -q -t -l $SSHACC $SSHSERVER > $DEVNAME
  ps -ax | grep "ssh -q -t -l $SSHACC " | grep -v grep /
  # ** 注: 最后两行只是将其中的 -1 拿掉而已□请务必注意。
  
  4) 进行连线:
  # /etc/rc.d/init.d/vpnd start
  如果需要开机就启动 vpnd 的话□请执行如下命令□否则略:
  chkconfig --add vpnd
  chkconfig vpnd on
  断线则输入:
  # /etc/rc.d/init.d/vpnd stop
  
  5) 设路由:
  当连线建立好之后□在 201.0.1.1 上面执行:
  # route add -net 192.168.2.0/24 dev ppp0
  在 202.0.2.2 上面执行:
  # route add -net 192.168.1.0/24 dev ppp0
  
  
  
  八□ NAT + Transparent Proxy
  
  ** 模拟机器将转移到‘闸道主机’中进行□这里以 group1 为例子。
  ** 且注意∶gateway 上并不提供任何 service ,单纯作 firewall & nat 。
  
  闸道主机环境(假设):
  对外界面: eth0
  对外 IP: 201.0.1.1
  GATEWAY: 201.0.1.254
  对内界面: eth1
  对内 IP: 192.168.1.254
  内部服务主机 IP (假设) : 192.168.1.1
  
  * T_PROXY
  1) 修改 /etc/squid/squid.conf □增加如下两行(可以先搜寻同组设定组态):
  acl g1 src 192.168.1.0/255.255.255.0
  http_access allow g1
  2) 修改如下句子(第一行需要新增):
  httpd_accel_host virtual
  httpd_accel_port 0
  httpd_accel_with_proxy on
  httpd_accel_uses_host_header on
  3) 重新启动 squid :
  # service squid restart
  # chkconfig squid on
  
  
  * NAT
  
  1) 与前面的主机放火墙略有不同□可下载如下 script 进行设定:
  # mkdir /etc/fw
  # chmod u+x,go-x /etc/fw
  # cd /etc/fw
  # wget http://www.study-area.org/linux/src/ipt_nat.tgz
  # tar zxvf ip_nat.tgz
  2) 修改设定参数:
  EXT_IF=eth0
  INT_IF=eth1
  DMZ_IF=eth1 (** 若您没设 DMZ ,请用内部届面 )
  DMZ_SERVER="192.168.1.1"
  3) 执行 script:
  # /etc/fw/ipt_nat
  4) 保存设定:
  # vi /etc/rc.d/rc.loal
  if [ -x /etc/fw/ipt_nat ]; then
  /etc/fw/ipt_nat
  fi
  
  九□入侵侦测
  
  * SUID/SGID:
  1) 建立原始列表:
  # find / -perm +u+s -exec ls -l {} /; > /root/suid.list
  # chattr +i /root/suid.list
  2) 修改 crontab 进行检查:
  # vi /etc/cron.daily/chk_suid.sh
  #!/bin/bash
  ORIG_LIST=/root/suid.list
  NEW_LIST=/root/suid.new
  echo
  find / -perm +u+s -exec ls -l {} /; > $NEW_LIST
  if diff $ORIG_LIST $NEW_LIST
  then
  echo "Looks fine: no new suid files found."
  else
  echo "WARNING: new suid files found!"
  fi
  echo
  echo
  # chmod +x /etc/cron.daily/chk_suid.sh
  # /etc/cron.daily/chk_suid.sh
  * 提示: 该结果每天会 email 到 root 的信箱。
  ** 注意: 如果确定新增的 suid 档案是安全的□请更新 suid.list:
  # chattr -i /root/suid.list
  # find / -perm +u+s -exec ls -l {} /; > /root/suid.list
  # chattr +i /root/suid.list
  
  
  * TRIPWIRE (可参考: http://www.study-area.org/tips/tripwire.htm):
  
  1) 取得 tripwire 的安装套件(rh7.2 第二片光碟)□并进行安装:
  # rpm -ivh /mnt/cdrom/RedHat/RPMS/tripwire-2.3.0-58.i386.rpm
  * 提示: 如果没有 CDROM □可以从网路抓:
  # wget ftp://linux.sinica.edu.tw/pub1/redhat/redhat-7.3/en/os/i386/RedHat/RPMS/tripwire-2.3.1-10.i386.rpm
  2) 进行初始化设定
  # /etc/tripwire/twinstall.sh
  # 输入多次密码 ( site & local)
  
  3) 进行一些针对性修改
  # cd /etc/tripwire
  # /usr/sbin/tripwire --init
  # /usr/sbin/tripwire --check | grep Filename > twnotfound.txt
  # vi twfilter.sh (** 或抓: # wget http://www.study-area.org/linux/src/twfilter.sh)
  #!/bin/bash
  orig_file=/etc/tripwire/twpol.txt
  not_file=twnotfound.txt
  tmp_file=tmp.txt
  new_file=new.txt
  cat $orig_file > $tmp_file
  for i in $(cat $not_file | cut -d ":" -f 2); do
  grep -v $i $tmp_file > $new_file
  cat $new_file > $tmp_file
  done
  mv $orig_file $orig_file.bak
  cat $new_file > $orig_file
  rm -f $new_file
  rm -f $tmp_file
  #-- end of script --#
  4) 执行 script :
  # chmod +x twfilter.sh
  # sh twfilter.sh
  
  5) 重新建立资料库:
  # /usr/sbin/twadmin -m P /etc/tripwire/twpol.txt
  # /usr/sbin/tripwire -m i
  
  6) 执行如下命令检查:
  # /usr/sbin/tripwire --check
  ** 提示: 该结果每天会 email 到 root 的信箱。
  7) 如果要对资料库进行过更新□读入最新 report 档案
  # /usr/sbin/tripwire -m u -r /var/lib/tripwire/report/your.machine.name-2002xxxx-xxxxx.twr
  # 退出 vi 模式 并输入密码
  
  * CHKROOTKIT:
  1) 下载 chkrootkit:
  # cd /root
  # wget http://www.study-area.org/linux/src/chkrootkit.tar.gz
  
  2) 安装 chkrootkit:
  # tar zxvf chkrootkit.tar.gz
  # cd chkrootkit-0.35
  # make sense
  3) 设定 chkrootkit:
  # vi /etc/cron.daily/chkrootkit
  #!/bin/bash
  echo
  echo "checking rootkit..."
  /root/chkrootkit-0.35/chkrootkit
  echo
  echo
  # chmod +x /etc/cron.daily/chkrootkit
  # /etc/cron.daily/chkrootkit
  * 提示: 该结果每天会 email 到 root 的信箱。
  
  十□套件更新
  
  1) 架设 mirror:
  (说明一下: 之所以使用 mirror □是针对单一 LAN 环境中□
  同时有多台主机需要 Upgrade 的情况下使用。
  虽然第一次 mirror 比较吃频宽□但长期而言□
  每次 upgrade 事实上只有一次对外频宽的需求而已□
  其它的机器集中到 local server 上抓取就是了。
  )
  # mkdir /usr/local/mirror
  # cd /usr/local/mirror
  # wget http://www.study-area.org/linux/src/mirror-2.9.tar.gz
  # tar zxvf mirror-2.9.tar.gz
  # vi packages/redhat73
  package=redhat73
  comment=Updates for Redhat Linux 7.3
  site=linux.sinica.edu.tw
  remote_dir=/redhat/updates/7.3
  local_dir=/var/www/html/apt/redhat/updates/7.3
  # vi /etc/cron.daily/mirror
  #!/bin/bash
  echo
  perl /usr/local/mirror/mirror.pl /usr/local/mirror/packages/redhat73
  echo
  echo
  # chmod +x /etc/cron.daily/mirror
  # /etc/cron.daily/mirror
  ** 注意: 在进行 mirror 之前□请尽可能礼貌性知会对方的管理员。
  2) 架设 APT SERVER:
  # cd /usr/local/src
  # wget ftp://cle.linux.org.tw/pub/CLE/i386/RedHat/RPMS/apt*.rpm
  # rpm -ivh apt-*.rpm
  # cd /var/www/html/apt
  # ln -s redhat/updates/7.3/en/os/SRPMS SRPMS.73
  # cd redhat/
  # ln -s updates/7.3/en/os/i386 RPMS.73
  # mkdir base
  # sh /usr/bin/genbasedir /var/www/html/apt
  # sh /usr/bin/genbasedir /var/www/html/apt/redhat
  ** 注意: 测试成功后□将上两行命令增加至 /etc/cron.daily/mirror 中。
  也就是接在那两行 perl 句子后面就可以了。
  这样才能顺利更新 APT server 里面的 package list 。
  
  3) 安装 APT CLIENT:
  # cd /usr/local/src
  # wget ftp://cle.linux.org.tw/pub/CLE/i386/RedHat/RPMS/apt*.rpm
  # rpm -ivh apt*.rpm
  # mv /etc/apt/sources.list /etc/apt/sources.list.bak
  # vi /etc/apt/sources.list
  rpm http://ADDRESS.OF.YOUR-APT-SERVER/apt redhat 73
  rpm-src http://ADDRESS.OF.YOUR-APT-SERVER/apt redhat 73
  
  ** 注∶若您并没建置自己的 APT server ,将 /etc/apt/source.list 换成如下则可∶
  rpm ftp://linux.nctu.edu.tw/dists/redhat/apt i386 redhat-7.3-updates
  rpm-src ftp://linux.nctu.edu.tw/dists/redhat/apt i386 redhat-7.3-updates
  rpm ftp://linux.nctu.edu.tw/dists/redhat/apt i386 redhat-7.3
  rpm-src ftp://linux.nctu.edu.tw/dists/redhat/apt i386 redhat-7.3
  
  4) 执行 APT:
  # apt-get update
  # atp-get check
  如果要更新全部套件:
  # apt-get upgrade
  如果是单独安装某套件(例如 my-package):
  # apt-get install my-pakage
  如果是取得某套件之 source rpm (例如 my-package):
  # apt-get source my-pakage
  如果想每天自动更新全部套件:
  # vi /etc/cron.daily/apt-get
  #!/bin/bash
  echo
  apt-get upgrade
  echo
  echo
  # chmod +x /etc/cron.daily/apt-get
  ** 提示: 以上介绍的 apt-get 命令□在有问题的时候□不妨加上 -f 参数来修正。
  
  5) 关于 CLE
  如果网路环境中只有极少数的系统需要更新□并且都是 CLE 版本的话□
  不妨参考如下两篇文章:
  http://cle.linux.org.tw/~candyz/index.htm
  ftp://cle.linux.org.tw/pub/CLE/APT-HOWTO_CLE.txt
  (最后一篇文章□在不需要架设 server 的情况下□只需参考 client 端设定就可以了。)
  
  

关键字:Linux系统安全

相关文章

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面