2013年9月28日

Solaris (10) 安裝注意事項及資安規範實作

這篇是 Solaris (10) 的注意事項。

l   系統環境設定
n   設定主機使用規範提示訊息
u  /etc/motd
n   安裝額外套件
u  sunfreeware已經轉為營利性質,Solaris packages可找舊的mirror site,可試試  http://solaris-freeware.saix.net(下載連結均為FTP)
u  安裝sudo相關套件:libgcc, libiconv, libintl, sudo
u  安裝lsof套件:lsof
n   關閉非必要的service (port)
u  dtlogin (for X Window)
/usr/dt/bin/dtconfig -kill; /usr/dt/bin/dtconfig -d; lsof -I -nP|grep dtlogin; ps -ef|grep dtlogin;
Reference: http://www.cyberciti.biz/tips/solaris-starting-and-stopping-dtlogin-cde.html
u  (root身分執行) 可用lsof -i -nP來檢查 (lsof工具Solaris需額外安裝),若有port找不到process,可能是被RPC mappingport,可用rpcinfo -p來查。查到後若是不需要的 daemon 就可關掉了。
u  RPC (rpcbind, portmapper) 控制很多服務 (例如 NFS),建議不確定時不要關
u  其他通常可關閉的service:
svcadm disable svc:/network/rpc/gss:default
svcadm disable svc:/network/rpc/meta:default
svcadm disable svc:/network/rpc/rstat:default
svcadm disable svc:/network/rpc/mdcomm:default
svcadm disable svc:/network/rpc/metamed:default
svcadm disable svc:/network/rpc/metamh:default
svcadm disable svc:/network/rpc/cde-calendar-manager:default
svcadm disable svc:/network/rpc/cde-ttdbserver:tcp
svcadm disable svc:/network/rpc/smserver:default
svcadm disable svc:/network/rpc/rusers:default
svcadm disable svc:/network/rpc-100235_1/rpc_ticotsord:default
svcadm disable svc:/network/routing/ndp:default
n   SSH 設定:vi /etc/ssh/sshd_config
u  Disable root ssh:
PermitRootLogin no
u  閒置X秒斷線:
ClientAliveInterval X
ClientAliveCountMax 0
vi /etc/profile
TMOUT X; export TMOUT
u  登入失敗三次即斷線:
MaxAuthTries 3
u  以上設定完畢後需重起 ssh servicesvcadm restart ssh
n   啟用系統內建防火牆:ipfilter
確認pfil以及ipfilter服務皆已啟用:
svcs pfil ipfilter
STATE沒有顯示online,則以svcadm enable [service_name] 來啟動指定的服務 (pfil預設為啟用,ipfilter預設為disabled)
n   檢查ipfilter rules: ipfstat -io
n   cronjob:
u  執行後需將stderrstdout一併紀錄於log,如:
30 1 * * * /home/backup/XXX.sh >> /var/log/XXX.log 2>&1
n   SFTP設定 (以內建的FTP Daemon為例):
u  確認關閉FTP service,僅允許以SFTP方式連線(ssh會通,sftp就會通)
svcadm disable ftp; svcs –a | grep ftp;
u  若因特殊業務需求要開放ftp連線,則禁止該ftp使用者/群組以ssh方式登入,僅允許登入ftp (參考資料)
edit /etc/ssh/sshd_config
DenyUsers ftpuser1 ftpuser2
DenyGroups ftpgroup
u  若要限制多個帳號,每個帳號需單獨寫一行,如:
guestuser user1
guestuser user2
n   設定允許使用ssh登入主機的網域白名單(防止維護廠商透過80 portssh/telnet over HTTP的方式遠端登入有開放到公網的設備,並以該設備作為跳板進行維護/異動)
u  vi /etc/ssh/sshd_config
AllowUsers *@XX.XX.XX.XX
n    [Optional] 評估是否採用 Solaris Volume Manager (SVM) 來管理磁碟空間,以減少需要處理Nagios disk warning的狀況
n   [Optional] 啟用TCP_Wrappers來控管可存取此主機的hosts
l   帳號設定
n   shell預設為bash
u  新增帳號範例:useradd -d /export/home/account -s /usr/bin/bash -m account; passwd account
(
一次新增多筆帳號:echo account1\naccount2” | xargs –I useradd –d /export/home/{} –s /usr/bin/bash -m {}; passwd {} )
u  可直接編輯 /etc/passwd 以修改現有帳號的 default shell
n   通行碼管理
u  帳號使用之密碼滿90天需強迫變更,到期前30天提醒:
passwd -x 90 -w 30 account
(
一次設定多筆帳號:echo account1\naccount2” | xargs -i passwd -x 90 -w 30 {})

設定完成後,再修改 /etc/shadow,將最後變更密碼日期改成今天。(可先變更某一帳號的密碼,以得知今天是自1970/01/01開始累積的第幾天)
u  密碼重設不可使用3代以內的密碼、密碼長度至少為12碼、密碼需符合複雜度限制、帳戶密碼最大使用期限不可超過90天、帳戶密碼最小使用期限不可超過60天:
vi /etc/default/passwd

HISTORY=3
MAXWEEKS=12
MINWEEKS=8
PASSLENGTH=12
MINUPPER=1
MINLOWER=1
MAXREPEATS=1
MIINSPECIAL=1
MINDIGIT=1
u  密碼輸入錯誤三次鎖定 (不支援自動解鎖)
l   vi /etc/default/login:
RETRIES=3
l   vi /etc/security/policy.conf:
#can be overridden by /etc/user_attr
LOCK_AFTER_RETRIES=YES
CRYPT_DEFAULT=1
l   check fail count: grep [account] /etc/shadow , 最後一個欄位是錯誤次數,被鎖住的帳號開頭顯示為 *LK*
l   unlock account: passwd –u [account]
u  密碼不得與帳號相同:
此為OS本來就有的限制,不需要調整設定
l   NTP設定
n   設定root排程定期執行ntpdate指令
l   SNMP設定
n   編輯 /etc/snmp/conf/snmpd.conf,設定「read-community XXX
n   重起 SNMP Servicesvcadm restart svc:/application/management/sma:default
(
可先用 svcs -a | grep sma 來確認 SNMP 服務的完整名稱)

2013年9月24日

RHEL/CentOS 安裝注意事項及資安規範實作

終於整理到一個段落了,趁有空po上來。



  • 確認主機啟動時使用runlevel 3
    • /etc/inittab: id:3:initdefault: #預設為5,手動改成3
  • 設定主機使用規範提示訊息
    • /etc/motd
  • 關閉非必要的service (port)
    • Disable SELinux:
      1. vi /etc/sysconfig/selinux:
        SELINUX=disabled
    • Disable ip6tables:
      1. service ip6tables stop; service ip6tables status;
      2. chkconfig ip6tables off; chkconfig--list ip6tables
    • Disable vsftpd (FTP):
      1. service vsftpd stop; service vsftpd status;
      2. chkconfig vsftpd off; chkconfig --list vsftpd;
    • 關閉常見的service (RHEL 4/5: sendmail, RHEL 6: postfix):
      1. service stap-server stop; service cups stop; service qpidd stop; service avahi-daemon stop; service tog-pegasus stop; service ntpd stop; service postfix stop; service sendmail stop; service ntpd stop;
      2. service stap-server status; service cups status; service qpidd status; service avahi-daemon status; service tog-pegasus status; service ntpd status; service postfix status; service sendmail status; service ntpd status;
      3. chkconfig stap-server off; chkconfig cups off; chkconfig qpidd off; chkconfig avahi-daemon off; chkconfig tog-pegasus off; chkconfig ntpd off; chkconfig postfix off; chkconfig sendmail off; chkconfig ntpd off;
      4. chkconfig --list stap-server; chkconfig --list cups; chkconfig --list qpidd; chkconfig --list avahi-daemon; chkconfig --list tog-pegasus; chkconfig --list ntpd; chkconfig --list postfix; chkconfig --list sendmail; chkconfig --list ntpd;
  • SSH 設定:vi /etc/ssh/sshd_config
    • Disable root ssh:
      PermitRootLogin no
    • 閒置X秒斷線:
      ClientAliveInterval X
      ClientAliveCountMax 0
      vi /etc/profile
      TMOUT 2700; export TMOUT
    • 登入失敗三次即斷線:
      MaxAuthTries 3
    • 以上設定完畢後需重起sshd serviceservice sshd restart
  • 網路設定 (NIC Bonding)-for RHEL 4.x/5.x
    • 設定primary網卡為eth0,在failovereth1之後,若eth0回復就會切回eth0
      vi /etc/modprobe.conf
      alias bond0 bonding
      options bond0 miimon=100 mode=1 primary=eth0

      設定完成後需reboot才會生效。
    • 查看bonding狀態:cat /proc/net/bonding/bond0,應顯示「Primary Slave:eth0」,並應手動插拔網路線,或者執行ifconfig eth0 down/up指令來確認是否有正確failover/failback
  • 網路設定 (NIC Bonding)-for RHEL 6.x
    • 設定開機時啟動bond0 interface:
      vi /etc/modprobe.d/bonding.conf
      alias bond0 bonding
    • 設定primary網卡為eth0,在failovereth1之後,若eth0回復就會切回eth0
      vi /etc/sysconfig/network-scripts/ifcfg-bond0
      BONDING_OPTS=”miimon=100 mode=active-backup primary=eth0”
      設定完成後需reboot才會生效。
    • 查看bonding狀態:cat /proc/net/bonding/bond0,應顯示「Primary Slave:eth0」,並應手動插拔網路線,或者執行ifconfig eth0 down/up指令來確認是否有正確failover/failback
  • 啟用系統內建防火牆 (iptables for IPv4)
    • 預設系統會自動啟用iptables & ip6tables,保留iptables,關閉ip6tables
    • service iptables start; service iptables status;
    • chkconfig iptables on; chkconfig --list iptables;
    • check iptables status: service iptables status,若內容太多,再依序執行以下指令:
      iptables -F; iptables -X; iptables -Z; iptables-save; service iptables restart;
    • 檢查iptables rules: iptables -L -n -v
  • 設定檔:/etc/sysconfig/iptables,reboot 後可自動載入rules。

      • cronjob:
        • 執行後需將stderrstdout一併紀錄於log,如:
          30 1 * * * /backup/XXX.sh >> /var/log/XXX.log 2>&1
      • 設定允許使用ssh登入主機的網域白名單(防止維護廠商透過80 portssh/telnet over HTTP的方式遠端登入有開放到公網的設備,並以該設備作為跳板進行維護/異動)
        • 確認系統內建的sshd是否支援TCP Wrapper: 執行ldd /usr/sbin/sshd | grep libwrap, 若出現以下 output 代表有支援(sshd可使用libwrap函式庫):
          libwrap.so.0 => /usr/lib/libwrap.so.0 (0x00b22000)
        • 編輯/etc/hosts.allow (不可使用 10.1.0.0/16 表示法):
          sshd:XX.XX.XX.XX
        • 編輯/etc/hosts.deny (不可使用 10.1.0.0/16 表示法):
          sshd:ALL
        • 設定完畢後不需重起sshd,會立刻生效
        • 查看是否有違法連線的紀錄,log 位置在 /var/log/secure,範例如下:
          [root@XXX    ~]# grep refused /var/log/secure
          Feb 17 17:26:53 XXX    sshd[3034]: refused connect from ::ffff:XX.XX.XX.XX    (::ffff:XX.XX.XX.XX)
      • [Optional] 評估是否採用 Logical Volume Manager (LVM) 來管理磁碟空間,以減少需要處理磁碟空間不足的狀況
    • 帳號設定
      • shell預設為bash
        • 新增帳號範例:useradd -d /home/account -s /usr/bin/bash -m account; passwd account(一次新增多筆帳號:echo “account1\naccount2” | xargs -i  useradd -d /home/{} –s /usr/bin/bash -m {}; passwd {} )
        • 可直接編輯 /etc/passwd 以修改現有帳號的 default shell
      • 通行碼管理
        • 帳戶密碼最大使用期限不可超過90天、最小使用期限不可超過60天、密碼最小長度12、密碼到期30天前提醒:
          vi /etc/login.defs #設定完畢後,新增帳號會自用套用相關規則
          PASS_MAX_DAYS 90
          PASS_MIN_DAYS 60
          PASS_MIN_LEN 12
          PASS_WARN_AGE 30
        • 帳號使用之密碼滿90天需強迫變更,到期前30天提醒:
          chage -M 90 -W 30 account
          (一次設定多筆帳號:echo “account1\naccount2” | xargs -i chage -M 90 -W 30 {})

          設定完成後,再將各帳號的最後變更密碼日期改成今天:
          chage -d yyyy-mm-dd account
          (一次設定多筆帳號:echo “account1\naccount2” | xargs -i chage -d yyyy-mm-dd {})
        • 密碼重設不可使用3代以內的密碼、密碼長度至少為12碼、需符合密碼複雜度:
    /etc/pam.d/system-auth
    password requisite pam_cracklib.so try_first_pass retry=3 dcredit=1 ucredit=1 ocredit=1 lcredit=1 minlen=12
    password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authok remember=3
    password required pam_deny.so
        • 密碼輸入錯誤三次鎖定 for RHEL 4.x (不支援自動解鎖)
    vi /etc/pam.d/system-auth
    auth    required    /lib/security/$ISA/pam_env.so
    auth    required    /lib/security/$ISA/pam_tally.so no_magic_root    # add this line here

    account    required    /lib/security/$ISA/pam_permit.so
    account    required    /lib/security/$ISA/pam_tally.so deny=3 no_magic_root    # add this line here

    check fail count of particular account:
    faillog -u [account]

    unlock account:
    faillog -u [account] -r
        • 密碼輸入錯誤三次鎖定 for RHEL 5.x (不可設定自動解鎖: unlock_time)
    vi /etc/pam.d/system-auth
    auth    required    pam_env.so
    auth    required    pam_tally.so onerr=fail deny=3 # add this line here

    check fail count of particular account:
    faillog -u [account]

    unlock account:
    faillog -u [account] -r
        • 密碼輸入錯誤三次鎖定 for RHEL 6.x (不可設定自動解鎖: unlock_time)
    vi /etc/pam.d/sshd
    auth    required    pam_sepermit.so
    auth    required    pam_tally2 onerr=fail deny=3    # add this line here

    account    required    pam_nologin.so
    account    required    pam_tally2.so per_user    # add this line here

    check fail count of particular account:
    pam_tally2 -u [account]

    unlock account:
    pam_tally2 -u [account] -r

      • 密碼不得與帳號相同:
        此為OS本來就有的限制,不需要調整設定
    • NTP設定
      • 設定root排程定期執行ntpdate指令
    • SNMP設定
      • 編輯 /etc/snmp/snmpd.conf,將「community」設定為「XXX
      • 重起 SNMP Servicechkconfig snmpd on; service snmpd start;
      • For Cacti monitoring: 編輯 /etc/snmp/snmpd.conf,在「Make at least  snmpwalk -v 1 localhost -c public system fast again.」下有兩行「view    systemview    included .1.3.6…」,保留第二行,把第一行改為「view    systemview    included   .1.3.6」。

    Google Spreadsheet 裡用規則運算式

    最近因為工作關係,遇到要用 Google Form 及 Google Sheet 所以研究了 Google Sheet 裡的一些 function 怎麼用 首先,分享一下如何在 Google Sheet 裡用規則運算 :D