亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3098 | 回復(fù): 3
打印 上一主題 下一主題

[系統(tǒng)安全] 根據(jù)網(wǎng)上資料整理的linux安全加固的腳本,求助一個(gè)問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2016-01-25 20:33 |只看該作者 |倒序?yàn)g覽
本帖最后由 yaoyansi 于 2016-01-25 20:39 編輯

hi~大家好,
我根據(jù)網(wǎng)上的資料整理了2個(gè)centos7的系統(tǒng)加固的shell腳本。代碼和附件見下面。
我先執(zhí)行centos7_hardening1.sh,重啟機(jī)器,沒有問題。
然后執(zhí)行centos7_hardening2.sh,再重啟機(jī)器,無法顯示圖形登陸界面,顯示錯(cuò)誤。
請(qǐng)問,centos7_hardening2.sh哪里出問題了?
謝謝

centos7_hardening1.sh
centos7_hardening1.sh.word (7.32 KB, 下載次數(shù): 11)
  1. # centos7_hardening1.sh
  2. #

  3. timestamp="`date +%Y-%m-%d_%H-%M-%S`"

  4. # backup this script
  5. cp -p /home/user0/Documents/centos7_hardening1.sh /run/media/user0/HDDREG/tools/centos7_hardening1.sh

  6. gLogFilePath="./centos7_hardening1.log"
  7. echo "Begin" > $gLogFilePath

  8. backupFile()
  9. {
  10.         originalFilePath="$1";

  11.         if [ -f "$originalFilePath" ]
  12.         then
  13.                 dir=`dirname $originalFilePath`;
  14.                 base=`basename $originalFilePath`;
  15.                 # cp command can't copy the file to the source directory,
  16.                 # so I copy the source file to /tmp and then move it back with timestamp in
  17.                 # file name  to source directory.
  18.                 # copy the file to /tmp
  19.                 cp -p $originalFilePath /tmp;

  20.                 # move the /tmp/$file back to src dir
  21.                 mv -f "/tmp/$base" "$originalFilePath-$timestamp";       
  22.         else
  23.                 echo "$originalFilePath not found."
  24.         fi
  25. }

  26. Setup_accunts()
  27. {
  28.         echo "| Setup_accunts"
  29.         #account setup
  30.         passwd -l xfs
  31.         passwd -l news
  32.         passwd -l nscd
  33.         passwd -l dbus
  34.         passwd -l vcsa
  35.         passwd -l games
  36.         passwd -l nobody
  37.         passwd -l avahi
  38.         passwd -l haldaemon
  39.         passwd -l gopher
  40.         passwd -l ftp
  41.         passwd -l mailnull
  42.         passwd -l pcap
  43.         passwd -l mail
  44.         passwd -l shutdown
  45.         passwd -l halt
  46.         passwd -l uucp
  47.         passwd -l operator
  48.         passwd -l sync
  49.         passwd -l adm
  50.         passwd -l lp
  51. }

  52. Remove_App()
  53. {
  54.         echo "| Remove_App"
  55.         /etc/rc.d/init.d/apmd stop
  56.         /etc/rc.d/init.d/sendmail stop
  57.         /etc/rc.d/init.d/kudzu stop

  58.         rpm  -e  pump
  59.         rpm  -e  apmd
  60.         rpm  -e  lsapnptools
  61.         rpm  -e  redhat-logos
  62.         rpm  -e  mt-st
  63.         rpm  -e  kernel-pcmcia-cs
  64.         rpm  -e  setserial
  65.         rpm  -e  redhat-relese
  66.         rpm  -e  eject
  67.         rpm  -e  linuxconf
  68.         rpm  -e  kudzu
  69.         rpm  -e  gd
  70.         rpm  -e  bc
  71.         rpm  -e  getty_ps
  72.         rpm  -e  raidtools
  73.         rpm  -e  pciutils
  74.         rpm  -e  mailcap
  75.         rpm  -e  setconsole
  76.         rpm  -e  gnupg

  77.        
  78.         chkconfig postfix off # echo "close Mail   Server "
  79.         chkconfig --level 35 apmd off
  80.         chkconfig --level 35 netfs off
  81.         chkconfig --level 35 yppasswdd off
  82.         chkconfig --level 35 ypserv off
  83.         chkconfig --level 35 dhcpd off?
  84.         chkconfig --level 35 portmap off
  85.         chkconfig --level 35 lpd off
  86.         chkconfig --level 35 nfs off
  87.         chkconfig --level 35 sendmail off
  88.         chkconfig --level 35 snmpd off
  89.         chkconfig --level 35 rstatd off
  90.         chkconfig --level 35 atd off
  91. }
  92. Remove_User()
  93. {
  94.         echo "| Remove_User"

  95.         userdel adm
  96.         userdel lp
  97.         userdel sync
  98.         userdel shutdown
  99.         userdel halt
  100.         userdel news
  101.         userdel uucp
  102.         userdel operator
  103.         userdel games
  104.         userdel gopher
  105.         userdel ftp

  106.         groupdel adm
  107.         groupdel lp
  108.         groupdel news
  109.         groupdel uucp
  110.         groupdel games
  111.         groupdel dip

  112.         chmod 0755 /etc/passwd
  113.         chmod 0755 /etc/shadow
  114.         chmod 0755 /etc/group
  115.         chmod 0755 /etc/gshadow
  116.         chattr +i /etc/passwd
  117.         chattr +i /etc/shadow
  118.         chattr +i /etc/group
  119.         chattr +i /etc/gshadow

  120.         chmod 600  /etc/services
  121.         chown root /etc/services
  122.         chattr +i  /etc/services

  123.         # /etc, /usr/etc, /bin, /usr/bin, /sbin, /usr/sbin, /tmp and/var/tmp的屬主是root,并且設(shè)置粘滯
  124.         chown root /etc
  125.         chown root /usr/etc
  126.         chown root /bin
  127.         chown root /usr/bin
  128.         chown root /sbin
  129.         chown root /usr/sbin
  130.         chown root /tmp and/var/tmp
  131.         chmod +t /etc
  132.         chmod +t /usr/etc
  133.         chmod +t /bin
  134.         chmod +t /usr/bin
  135.         chmod +t /sbin
  136.         chmod +t /usr/sbin
  137.         chmod +t /tmp and/var/tmp



  138.         # 只有根用戶允許在該目錄下使用 Read、Write,和 Execute 腳本文件
  139.         chmod -R 700 /etc/rc.d/init.d/*
  140.         chmod -R 700 /etc/init.d/*

  141.         # limit chmod important commands
  142.         chmod 700 /bin/ping
  143.         chmod 700 /usr/bin/finger
  144.         chmod 700 /usr/bin/who
  145.         chmod 700 /usr/bin/w
  146.         chmod 700 /usr/bin/locate
  147.         chmod 700 /usr/bin/whereis
  148.         chmod 700 /sbin/ifconfig
  149.         chmod 700 /usr/bin/pico
  150.         chmod 700 /bin/vi
  151.         chmod 700 /usr/bin/which
  152.         #chmod 700 /usr/bin/gcc
  153.         #chmod 700 /usr/bin/make
  154.         chmod 700 /bin/rpm

  155.         # Narrow Down Permissions
  156.         chmod 700 /root
  157.         chmod 700 /var/log/audit
  158.         chmod 740 /etc/rc.d/init.d/iptables
  159.         chmod 740 /sbin/iptables
  160.         chmod -R 700 /etc/skel
  161.         chmod 600 /etc/rsyslog.conf
  162.         chmod 640 /etc/security/access.conf
  163.         chmod 600 /etc/sysctl.conf


  164.         # history security
  165.         chattr +a /root/.bash_history
  166.         chattr +i /root/.bash_history

  167.         chmod 600 /etc/grub.conf
  168.         chattr +i /etc/grub.conf
  169. }

  170. Disable_Ping_Response()
  171. {
  172.         echo "| Disable_Ping_Response"

  173.         echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
  174.        
  175.         #將上述命令加到/etc/rc.d/rc.local中去,每次重啟動(dòng)將自動(dòng)執(zhí)行
  176.         filepath="/etc/rc.d/rc.local"
  177.         if [ -f "$filepath" ]
  178.         then
  179.                 echo "$filepath found."
  180.         else
  181.                 echo "$filepath not found."
  182.                 touch $filepath
  183.         fi
  184.         echo "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all" >> $filepath
  185. }

  186. Disable_IP_Source_Routing()
  187. {
  188.         echo "| Disable_IP_Source_Routing"

  189.         for f in /proc/sys/net/ipv4/conf/*/accept_source_route; do
  190.         #echo $f
  191.         #cat $f
  192.         echo 0 > $f
  193.         done

  194.         #將上述命令加到/etc/rc.d/rc.local中去,每次重啟動(dòng)將自動(dòng)執(zhí)行
  195.         filepath="/etc/rc.d/rc.local"
  196.         if [ -f "$filepath" ]
  197.         then
  198.                 echo "$filepath found."
  199.         else
  200.                 echo "$filepath not found."
  201.                 touch $filepath
  202.         fi
  203.         echo "for f in /proc/sys/net/ipv4/conf/*/accept_source_route; do" >> $filepath
  204.         echo "echo 0 > $f" >> $filepath
  205.         echo "done"        >> $filepath
  206. }
  207. Res_limits()
  208. {
  209.         echo "prevent Dos attack"
  210.         # in On_core_dumps() in centos7_hardening2.sh
  211.         # 禁止創(chuàng)建core文件
  212.         #echo "* hard core 0"   >> /etc/security/limits.conf
  213.         # 除root外,其他用戶最多使用5M內(nèi)存
  214.         #echo "* hard rss 5000" >> /etc/security/limits.conf
  215.         # 最多進(jìn)程數(shù)限制為20
  216.         #echo "* hard nproc 20" >> /etc/security/limits.conf

  217.         echo "session required /lib/security/pam_limits.so" >> /etc/pam.d/login
  218. }
  219. File_Rights()
  220. {

  221.         echo "查找任何人可寫的文件和目錄" >> $gLogFilePath
  222.         echo "find / -type f \( -perm -2 -o -perm -20 \) -exec ls -lg {} \;" >> $gLogFilePath
  223.               find / -type f \( -perm -2 -o -perm -20 \) -exec ls -lg {} \;  >> $gLogFilePath
  224.         echo "find / -type d \( -perm -2 -o -perm -20 \) -exec ls -ldg {} \;">> $gLogFilePath
  225.               find / -type d \( -perm -2 -o -perm -20 \) -exec ls -ldg {} \; >> $gLogFilePath
  226.        
  227.         echo "查找異常文件, 如..文件,...文件等"            >> $gLogFilePath
  228.         echo "find / -name ".." -print -xdev"          >> $gLogFilePath
  229.               find / -name ".." -print -xdev               >> $gLogFilePath
  230.         echo "find / -name ".*" -print -xdev | cat -v" >> $gLogFilePath
  231.               find / -name ".*" -print -xdev | cat -v  >> $gLogFilePath

  232.         echo "檢查沒有屬主的文件"            >> $gLogFilePath
  233.         echo "find / -nouser -o -nogroup" >> $gLogFilePath
  234.               find / -nouser -o -nogroup  >> $gLogFilePath

  235.         echo "檢查在/dev目錄以外還有沒有特殊的塊文件"                          >> $gLogFilePath
  236.         echo "find / \( -type b -o -type c \) -print | grep -v '^/dev/'" >> $gLogFilePath
  237.               find / \( -type b -o -type c \) -print | grep -v '^/dev/'  >> $gLogFilePath



  238. }

  239. remove_logon_msg()
  240. {
  241.         echo "remove_logon_msg"
  242.         rm -f /etc/issue
  243.         rm -f /etc/issue.net
  244.         touch /etc/issue
  245.         touch /etc/issue.net
  246. }

  247. prevent_IP_cheat()
  248. {
  249.         echo "prevent_IP_cheat"

  250.         backupFile /etc/host.conf

  251.         echo "order bind,hosts"        >  /etc/host.conf
  252.         echo "multi off"                 >> /etc/host.conf
  253.         echo "nospoof on"                >> /etc/host.conf
  254. }
  255. ##########################################################################
  256. echo '';echo '';echo ''
  257. echo '-------------------------------------------'
  258. echo 'Security Harden CentOS 7    1'
  259. echo '-------------------------------------------'

  260. echo '';echo '';echo ''
  261. Setup_accunts;
  262. echo '';echo '';echo ''
  263. Remove_App;
  264. echo '';echo '';echo ''
  265. Remove_User;
  266. echo '';echo '';echo ''
  267. Disable_Ping_Response;
  268. echo '';echo '';echo ''
  269. Disable_IP_Source_Routing;
  270. echo '';echo '';echo ''
  271. Res_limits;
  272. echo '';echo '';echo ''
  273. File_Rights;
  274. echo '';echo '';echo ''
  275. remove_logon_msg;
  276. echo '';echo '';echo ''
  277. prevent_IP_cheat;
復(fù)制代碼
------------------------------------------------------------------------------------------------
centos7_hardening2.sh
centos7_hardening2.sh.word (28.71 KB, 下載次數(shù): 8)
  1. # centos7_hardening2.sh
  2. #
  3. # This CentOS7 hardening script is implemented with this guide:
  4. # 由于我沒有權(quán)限發(fā)鏈接,訪問下面網(wǎng)址時(shí)請(qǐng)把前綴的空格去掉。
  5. # h t t p s://highon.coffee/blog/security-harden-centos-7/
  6. #

  7. timestamp="`date +%Y-%m-%d_%H-%M-%S`"

  8. # backup this script
  9. cp -p /home/user0/Documents/centos7_hardening2.sh /run/media/user0/HDDREG/tools/centos7_hardening2.sh

  10. backupFile()
  11. {
  12.         originalFilePath="$1";

  13.         if [ -f "$originalFilePath" ]
  14.         then
  15.                 dir=`dirname $originalFilePath`;
  16.                 base=`basename $originalFilePath`;
  17.                 # cp command can't copy the file to the source directory,
  18.                 # so I copy the source file to /tmp and then move it back with timestamp in
  19.                 # file name  to source directory.
  20.                 # copy the file to /tmp
  21.                 cp -p $originalFilePath /tmp;

  22.                 # move the /tmp/$file back to src dir
  23.                 mv -f "/tmp/$base" "$originalFilePath-$timestamp";       
  24.         else
  25.                 echo "$originalFilePath not found."
  26.         fi
  27. }

  28. On_NTP()
  29. {
  30.         echo '|Install NTP'
  31.         yum install ntp ntpdate
  32.         chkconfig ntpd on
  33.         ntpdate pool.ntp.org
  34.         /etc/init.d/ntpd start

  35.         backupFile /etc/ntp.conf;
  36.         echo "server ntpserver" >> /etc/ntp.conf
  37. }

  38. Configure_System_for_AIDE()
  39. {
  40.         echo '|Configure System for AIDE'
  41.         # Disable prelinking altogether
  42.         #
  43.         backupFile /etc/sysconfig/prelink
  44.         if grep -q ^PRELINKING /etc/sysconfig/prelink
  45.         then
  46.           sed -i 's/PRELINKING.*/PRELINKING=no/g' /etc/sysconfig/prelink
  47.         else
  48.           echo -e "\n# Set PRELINKING=no per security requirements" >> /etc/sysconfig/prelink
  49.           echo "PRELINKING=no" >> /etc/sysconfig/prelink
  50.         fi
  51.         # Disable previous prelink changes to binaries
  52.         /usr/sbin/prelink -ua
  53.        
  54.         #
  55.         echo ''
  56.         echo ''
  57.         echo ''
  58.         echo '|Install AIDE'
  59.         yum install aide -y && /usr/sbin/aide --init && cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz && /usr/sbin/aide --check
  60.         echo '|Configure periodic execution of AIDE, runs every morning at 20:30'
  61.         echo "30 20 * * * /usr/sbin/aide --check" >> /etc/crontab
  62. }

  63. Enable_Secure_high_quality_Password_Policy()
  64. {
  65.         echo '|Enable Secure (high quality) Password Policy'
  66.         authconfig --passalgo=sha512 --update
  67. }

  68. Verify_grub_Permissions()
  69. {
  70.         echo '|Verify /boot/grub2/grub.cfg Permissions'
  71.         backupFile /boot/grub2/grub.cfg
  72.         chmod 600 /boot/grub2/grub.cfg
  73. }

  74. Require_Authentication_for_Single_User_Mode()
  75. {
  76.         echo '|Require Authentication for Single User Mode'
  77.         backupFile /etc/sysconfig/init
  78.         echo "SINGLE=/sbin/sulogin" >> /etc/sysconfig/init
  79. }

  80. Disable_Zeroconf_Networking()
  81. {
  82.         echo '|Disable Zeroconf Networking'
  83.         backupFile /etc/sysconfig/network
  84.         echo "NOZEROCONF=yes" >> /etc/sysconfig/network
  85. }

  86. Securing_root_Logins()
  87. {
  88.         echo '|Securing root Logins'
  89.         backupFile /etc/securetty
  90.         echo "tty1" > /etc/securetty
  91.         #echo "console" > /etc/securetty
  92.         chmod 700 /root
  93. }

  94. Enable_UMASK_077()
  95. {
  96.         echo '|Enable UMASK 077'
  97.         perl -npe 's/umask\s+0\d2/umask 077/g' -i /etc/bashrc
  98.         perl -npe 's/umask\s+0\d2/umask 077/g' -i /etc/csh.cshrc
  99. }

  100. Prune_Idle_Users()
  101. {
  102.         echo '|Prune Idle Users'
  103.         echo "Idle users will be removed after 15 minutes"
  104.         backupFile /etc/profile.d/os-security.sh
  105.         echo "readonly TMOUT=900" >> /etc/profile.d/os-security.sh
  106.         echo "readonly HISTFILE" >> /etc/profile.d/os-security.sh
  107.         chmod +x /etc/profile.d/os-security.sh
  108. }

  109. Securing_Cron()
  110. {
  111.         echo '|Securing Cron'
  112.         echo "Locking down Cron"
  113.         touch /etc/cron.allow
  114.         chmod 600 /etc/cron.allow
  115.         awk -F: '{print $1}' /etc/passwd | grep -v root > /etc/cron.deny
  116.         echo "Locking down AT"
  117.         touch /etc/at.allow
  118.         chmod 600 /etc/at.allow
  119.         awk -F: '{print $1}' /etc/passwd | grep -v root > /etc/at.deny
  120. }

  121. Sysctl_Security()
  122. {
  123.         backupFile /etc/sysctl.conf

  124.         echo '|Sysctl Security'
  125.         echo "# my data"                                         >> /etc/sysctl.conf
  126.         echo "net.ipv4.ip_forward = 0"                                 >> /etc/sysctl.conf
  127.         echo "net.ipv4.conf.all.send_redirects = 0"                 >> /etc/sysctl.conf
  128.         echo "net.ipv4.conf.default.send_redirects = 0"         >> /etc/sysctl.conf
  129.         echo "net.ipv4.tcp_max_syn_backlog = 1280"                 >> /etc/sysctl.conf
  130.         echo "net.ipv4.conf.all.accept_source_route = 0"         >> /etc/sysctl.conf
  131.         echo "net.ipv4.conf.all.accept_redirects = 0"                 >> /etc/sysctl.conf
  132.         echo "net.ipv4.conf.all.secure_redirects = 0"                 >> /etc/sysctl.conf
  133.         echo "net.ipv4.conf.all.log_martians = 1"                 >> /etc/sysctl.conf
  134.         echo "net.ipv4.conf.default.accept_source_route = 0"         >> /etc/sysctl.conf
  135.         echo "net.ipv4.conf.default.accept_redirects = 0"         >> /etc/sysctl.conf
  136.         echo "net.ipv4.conf.default.secure_redirects = 0"         >> /etc/sysctl.conf
  137.         echo "net.ipv4.icmp_echo_ignore_broadcasts = 1"         >> /etc/sysctl.conf
  138.         echo "net.ipv4.icmp_ignore_bogus_error_responses = 1"         >> /etc/sysctl.conf
  139.         echo "net.ipv4.tcp_syncookies = 1"                         >> /etc/sysctl.conf
  140.         echo "net.ipv4.conf.all.rp_filter = 1"                         >> /etc/sysctl.conf
  141.         echo "net.ipv4.conf.default.rp_filter = 1"                 >> /etc/sysctl.conf
  142.         echo "net.ipv4.tcp_timestamps = 0"                         >> /etc/sysctl.conf

  143.         # lynis warnings
  144.         echo "kernel.kptr_restrict = 1"                         >> /etc/sysctl.conf
  145.         echo "kernel.sysrq = 0"                                 >> /etc/sysctl.conf
  146.         echo "net.ipv4.conf.all.forwarding = 0"                 >> /etc/sysctl.conf
  147.         echo "net.ipv4.conf.default.log_martians = 1"                 >> /etc/sysctl.conf
  148.         echo "net.ipv6.conf.all.accept_redirects = 0"                 >> /etc/sysctl.conf
  149.         echo "net.ipv6.conf.default.accept_redirects = 0"         >> /etc/sysctl.conf

  150.         echo 'Disable ping response'
  151.         echo "net.ipv4.conf.icmp_echo_ignore_all = 1"                 >> /etc/sysctl.conf



  152.         # On_core_dumps
  153.         #
  154.         # If fs.suid_dumpable present in /etc/sysctl.conf, change value to "0"
  155.         #     else, add "fs.suid_dumpable = 0" to /etc/sysctl.conf
  156.         #
  157.         backupFile /etc/sysctl.conf
  158.         if grep --silent ^fs.suid_dumpable /etc/sysctl.conf ; then
  159.              sed -i 's/^fs.suid_dumpable.*/fs.suid_dumpable = 0/g' /etc/sysctl.conf
  160.         else
  161.              echo "" >> /etc/sysctl.conf
  162.              echo "# Set fs.suid_dumpable to 0 per security requirements" >> /etc/sysctl.conf
  163.              echo "fs.suid_dumpable = 0" >> /etc/sysctl.conf
  164.         fi


  165.         # Buffer_Overflow_Protection
  166.         echo "Enable ExecShield. Helps prevent stack smashing / BOF"
  167.         sysctl -w kernel.exec-shield=1
  168.         echo "kernel.exec-shield = 1" >> /etc/sysctl.conf

  169.         echo "Check / Enable ASLR"
  170.         sysctl -q -n -w kernel.randomize_va_space=2
  171.         echo "kernel.randomize_va_space = 2" >> /etc/sysctl.conf
  172.        
  173.         echo "---------------------------------------------------------"
  174.         echo "Check BIOS>Power and ensure XD(Intel)/NX(AMD) is enabled."
  175.         echo "---------------------------------------------------------"
  176. }

  177. Deny_All_TCP_Wrappers()
  178. {
  179.         echo "|Deny All TCP Wrappers"
  180.         backupFile  /etc/hosts.deny
  181.         backupFile  /etc/hosts.allow
  182.         echo "ALL:ALL"  >> /etc/hosts.deny
  183.         echo "sshd:ALL" >> /etc/hosts.allow
  184. }

  185. Verify_iptables_Enabled()
  186. {
  187.         echo "|Verify iptables Enabled"
  188.         systemctl enable iptables
  189.         systemctl start iptables.service
  190. }

  191. Disable_Uncommon_Protocols()
  192. {
  193.         echo "|Disable Uncommon Protocols"
  194.         backupFile /etc/modprobe.d/dccp.conf
  195.         backupFile /etc/modprobe.d/sctp.conf
  196.         backupFile /etc/modprobe.d/rds.conf
  197.         backupFile /etc/modprobe.d/tipc.conf
  198.         echo "install dccp /bin/false" > /etc/modprobe.d/dccp.conf
  199.         echo "install sctp /bin/false" > /etc/modprobe.d/sctp.conf
  200.         echo "install rds /bin/false"  > /etc/modprobe.d/rds.conf
  201.         echo "install tipc /bin/false" > /etc/modprobe.d/tipc.conf
  202. }

  203. Enable_Rsyslog()
  204. {
  205.         echo "|Ensure Rsyslog is installed"
  206.         yum -y install rsyslog
  207.         echo "|Enable Rsyslog"
  208.         systemctl enable rsyslog.service
  209.         systemctl start rsyslog.service
  210. }

  211. On_Auditd()
  212. {
  213.         echo '|Enable auditd Service'
  214.         systemctl enable auditd.service
  215.         systemctl start auditd.service

  216.         # But /etc/grub.conf doesn't exist on my centos7
  217.         #echo "kernel /vmlinuz-version ro vga=ext root=/dev/VolGroup00/LogVol00 rhgb quiet audit=1" >> /etc/grub.conf
  218.        
  219.         backupFile /etc/audit/auditd.conf
  220.         echo "modify /etc/audit/auditd.conf"
  221.         echo "num_logs = 5"
  222.         echo "max_log_file = 30MB"            # default 6
  223.         echo "max_log_file_action = rotate"
  224.         echo "space_left_action = email"      # default SYSLOG
  225.         echo "admin_space_left_action = halt" # default SUSPEND
  226.         echo "action_mail_acct = root"        # add this line
  227.         gedit /etc/audit/auditd.conf

  228.         backupFile /etc/audisp/plugins.d/syslog.conf
  229.         echo ""
  230.         echo ""
  231.         echo ""
  232.         echo "| active = yes" # default no
  233.         gedit /etc/audisp/plugins.d/syslog.conf
  234.         service auditd restart

  235.         backupFile /etc/audit/audit.rules
  236.         echo "" >> /etc/audit/audit.rules
  237.         echo "# audit_time_rules - Record attempts to alter time through adjtime" >> /etc/audit/audit.rules
  238.         echo "-a always,exit -F arch=b64 -S adjtimex -k audit_time_rules" >> /etc/audit/audit.rules

  239.         echo "# audit_time_rules - Record attempts to alter time through settimeofday" >> /etc/audit/audit.rules
  240.         echo "-a always,exit -F arch=b64 -S settimeofday -k audit_time_rules" >> /etc/audit/audit.rules

  241.         echo "# audit_time_rules - Record Attempts to Alter Time Through stime" >> /etc/audit/audit.rules
  242.         echo "-a always,exit -F arch=b64 -S adjtimex -S settimeofday -S clock_settime" >> /etc/audit/audit.rules
  243.         echo "-k audit_time_rules" >> /etc/audit/audit.rules

  244.         echo "# audit_time_rules - Record Attempts to Alter Time Through clock_settime" >> /etc/audit/audit.rules
  245.         echo "-a always,exit -F arch=b64 -S clock_settime -k audit_time_rules" >> /etc/audit/audit.rules

  246.         echo "# Record Attempts to Alter the localtime File" >> /etc/audit/audit.rules
  247.         echo "-w /etc/localtime -p wa -k audit_time_rules" >> /etc/audit/audit.rules

  248.         echo "# Record Events that Modify User/Group Information" >> /etc/audit/audit.rules
  249.         echo "# audit_account_changes" >> /etc/audit/audit.rules
  250.         echo "-w /etc/group -p wa -k audit_account_changes" >> /etc/audit/audit.rules
  251.         echo "-w /etc/passwd -p wa -k audit_account_changes" >> /etc/audit/audit.rules
  252.         echo "-w /etc/gshadow -p wa -k audit_account_changes" >> /etc/audit/audit.rules
  253.         echo "-w /etc/shadow -p wa -k audit_account_changes" >> /etc/audit/audit.rules
  254.         echo "-w /etc/security/opasswd -p wa -k audit_account_changes" >> /etc/audit/audit.rules

  255.         echo "# Record Events that Modify the System's Network Environment" >> /etc/audit/audit.rules
  256.         echo "# audit_network_modifications" >> /etc/audit/audit.rules
  257.         echo "-a always,exit -F arch=ARCH -S sethostname -S setdomainname -k audit_network_modifications" >> /etc/audit/audit.rules
  258.         echo "-w /etc/issue -p wa -k audit_network_modifications" >> /etc/audit/audit.rules
  259.         echo "-w /etc/issue.net -p wa -k audit_network_modifications" >> /etc/audit/audit.rules
  260.         echo "-w /etc/hosts -p wa -k audit_network_modifications" >> /etc/audit/audit.rules
  261.         echo "-w /etc/sysconfig/network -p wa -k audit_network_modifications" >> /etc/audit/audit.rules

  262.         echo "#Record Events that Modify the System's Mandatory Access Controls" >> /etc/audit/audit.rules
  263.         echo "-w /etc/selinux/ -p wa -k MAC-policy" >> /etc/audit/audit.rules

  264.         echo "#Record Events that Modify the System's Discretionary Access Controls - chmod" >> /etc/audit/audit.rules
  265.         echo "-a always,exit -F arch=b32 -S chmod -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  266.         echo "-a always,exit -F arch=b64 -S chmod  -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  267.         echo "#Record Events that Modify the System's Discretionary Access Controls - chown" >> /etc/audit/audit.rules
  268.         echo "-a always,exit -F arch=b32 -S chown -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  269.         echo "-a always,exit -F arch=b64 -S chown -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  270.         echo "#Record Events that Modify the System's Discretionary Access Controls - fchmod" >> /etc/audit/audit.rules
  271.         echo "-a always,exit -F arch=b32 -S fchmod -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  272.         echo "-a always,exit -F arch=b64 -S fchmod -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  273.         echo "#Record Events that Modify the System's Discretionary Access Controls - fchmodat" >> /etc/audit/audit.rules
  274.         echo "-a always,exit -F arch=b32 -S fchmodat -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  275.         echo "-a always,exit -F arch=b64 -S fchmodat -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  276.         echo "#Record Events that Modify the System's Discretionary Access Controls - fchown" >> /etc/audit/audit.rules
  277.         echo "-a always,exit -F arch=b32 -S fchown -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  278.         echo "-a always,exit -F arch=b64 -S fchown -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  279.         echo "#Record Events that Modify the System's Discretionary Access Controls - fchownat" >> /etc/audit/audit.rules
  280.         echo "-a always,exit -F arch=b32 -S fchownat -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  281.         echo "-a always,exit -F arch=b64 -S fchownat -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  282.         echo "#Record Events that Modify the System's Discretionary Access Controls - fremovexattr" >> /etc/audit/audit.rules
  283.         echo "-a always,exit -F arch=b32 -S fremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  284.         echo "-a always,exit -F arch=b64 -S fremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  285.         echo "#Record Events that Modify the System's Discretionary Access Controls - fsetxattr" >> /etc/audit/audit.rules
  286.         echo "-a always,exit -F arch=b32 -S fsetxattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  287.         echo "-a always,exit -F arch=b64 -S fsetxattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  288.         echo "#Record Events that Modify the System's Discretionary Access Controls - lchown" >> /etc/audit/audit.rules
  289.         echo "-a always,exit -F arch=b32 -S lchown -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  290.         echo "-a always,exit -F arch=b64 -S lchown -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  291.         echo "#Record Events that Modify the System's Discretionary Access Controls - lremovexattr" >> /etc/audit/audit.rules
  292.         echo "-a always,exit -F arch=b32 -S lremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  293.         echo "-a always,exit -F arch=b64 -S lremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  294.         echo "#Record Events that Modify the System's Discretionary Access Controls - lsetxattr" >> /etc/audit/audit.rules
  295.         echo "-a always,exit -F arch=b32 -S lsetxattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  296.         echo "-a always,exit -F arch=b64 -S lsetxattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  297.         echo "#Record Events that Modify the System's Discretionary Access Controls - removexattr" >> /etc/audit/audit.rules
  298.         echo "-a always,exit -F arch=b32 -S removexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  299.         echo "-a always,exit -F arch=b64 -S removexattr -F auid>=500 -F auid!=4294967295 -k perm_mod-a always,exit -F arch=b32 -S fchmodat -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  300.         echo "-a always,exit -F arch=b64 -S fchmodat -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  301.         echo "#Record Events that Modify the System's Discretionary Access Controls - fchown" >> /etc/audit/audit.rules
  302.         echo "-a always,exit -F arch=b32 -S fchown -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  303.         echo "-a always,exit -F arch=b64 -S fchown -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  304.         echo "#Record Events that Modify the System's Discretionary Access Controls - fchownat" >> /etc/audit/audit.rules
  305.         echo "-a always,exit -F arch=b32 -S fchownat -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  306.         echo "-a always,exit -F arch=b64 -S fchownat -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  307.         echo "#Record Events that Modify the System's Discretionary Access Controls - fremovexattr" >> /etc/audit/audit.rules
  308.         echo "-a always,exit -F arch=b32 -S fremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  309.         echo "-a always,exit -F arch=b64 -S fremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  310.         echo "#Record Events that Modify the System's Discretionary Access Controls - fsetxattr" >> /etc/audit/audit.rules
  311.         echo "-a always,exit -F arch=b32 -S lsetxattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  312.         echo "-a always,exit -F arch=b64 -S lsetxattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  313.         echo "#Record Events that Modify the System's Discretionary Access Controls - removexattr" >> /etc/audit/audit.rules
  314.         echo "-a always,exit -F arch=b32 -S removexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  315.         echo "-a always,exit -F arch=b64 -S removexattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  316.         echo "#Record Events that Modify the System's Discretionary Access Controls - setxattr" >> /etc/audit/audit.rules
  317.         echo "-a always,exit -F arch=b32 -S setxattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules
  318.         echo "-a always,exit -F arch=b64 -S setxattr -F auid>=500 -F auid!=4294967295 -k perm_mod" >> /etc/audit/audit.rules

  319.         echo "#Record Attempts to Alter Logon and Logout Events" >> /etc/audit/audit.rules
  320.         echo "-w /var/log/faillog -p wa -k logins" >> /etc/audit/audit.rules
  321.         echo "-w /var/log/lastlog -p wa -k logins" >> /etc/audit/audit.rules

  322.         echo "#Record Attempts to Alter Process and Session Initiation Information" >> /etc/audit/audit.rules
  323.         echo "-w /var/run/utmp -p wa -k session" >> /etc/audit/audit.rules
  324.         echo "-w /var/log/btmp -p wa -k session" >> /etc/audit/audit.rules
  325.         echo "-w /var/log/wtmp -p wa -k session" >> /etc/audit/audit.rules

  326.         echo "#Ensure auditd Collects Unauthorized Access Attempts to Files (unsuccessful)" >> /etc/audit/audit.rules
  327.         echo "-a always,exit -F arch=b32 -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EACCES -F auid>=500 -F auid!=4294967295 -k access" >> /etc/audit/audit.rules
  328.         echo "-a always,exit -F arch=b32 -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EPERM -F auid>=500 -F auid!=4294967295 -k access" >> /etc/audit/audit.rules
  329.         echo "-a always,exit -F arch=b64 -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EACCES -F auid>=500 -F auid!=4294967295 -k access" >> /etc/audit/audit.rules
  330.         echo "-a always,exit -F arch=b64 -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EPERM -F auid>=500 -F auid!=4294967295 -k access" >> /etc/audit/audit.rules

  331.         echo "#Ensure auditd Collects Information on the Use of Privileged Commands" >> /etc/audit/audit.rules
  332.         echo "#" >> /etc/audit/audit.rules
  333.         echo "#  Find setuid / setgid programs then modify and uncomment the line below." >> /etc/audit/audit.rules
  334.         echo "#" >> /etc/audit/audit.rules
  335.         echo "##  sudo find / -xdev -type f -perm -4000 -o -perm -2000 2>/dev/null" >> /etc/audit/audit.rules
  336.         echo "#" >> /etc/audit/audit.rules
  337.         echo "# -a always,exit -F path=SETUID_PROG_PATH -F perm=x -F auid>=500 -F auid!=4294967295 -k privileged" >> /etc/audit/audit.rules

  338.         echo "#Ensure auditd Collects Information on Exporting to Media (successful)" >> /etc/audit/audit.rules
  339.         echo "-a always,exit -F arch=ARCH -S mount -F auid>=500 -F auid!=4294967295 -k export" >> /etc/audit/audit.rules

  340.         echo "#Ensure auditd Collects File Deletion Events by User" >> /etc/audit/audit.rules
  341.         echo "-a always,exit -F arch=ARCH -S rmdir -S unlink -S unlinkat -S rename -S renameat -F auid>=500 -F auid!=4294967295 -k delete" >> /etc/audit/audit.rules

  342.         echo "#Ensure auditd Collects System Administrator Actions" >> /etc/audit/audit.rules
  343.         echo "-w /etc/sudoers -p wa -k actions" >> /etc/audit/audit.rules

  344.         echo "#Ensure auditd Collects Information on Kernel Module Loading and Unloading" >> /etc/audit/audit.rules
  345.         echo "-w /sbin/insmod -p x -k modules" >> /etc/audit/audit.rules
  346.         echo "-w /sbin/rmmod -p x -k modules" >> /etc/audit/audit.rules
  347.         echo "-w /sbin/modprobe -p x -k modules" >> /etc/audit/audit.rules
  348.         echo "-a always,exit -F arch=b64 -S init_module -S delete_module -k modules" >> /etc/audit/audit.rules

  349.         echo "#Make the auditd Configuration Immutable" >> /etc/audit/audit.rules
  350.         echo "-e 2" >> /etc/audit/audit.rules
  351. }

  352. Remove_Services()
  353. {
  354.         echo "| Bulk Remove of Services"
  355.         # Remove
  356.         yum remove xinetd
  357.         yum remove telnet-server
  358.         yum remove rsh-server
  359.         yum remove telnet
  360.         yum remove rsh-server
  361.         yum remove rsh
  362.         yum remove ypbind
  363.         yum remove ypserv
  364.         yum remove tftp-server
  365.         yum remove cronie-anacron
  366.         yum remove bind
  367.         yum remove vsftpd
  368.         yum remove httpd
  369.         yum remove dovecot
  370.         yum remove squid
  371.         yum remove net-snmpd
  372.        
  373.         echo "| Bulk Enable / Disable Services"
  374.         #Disable / Enable
  375.         systemctl disable xinetd #Failed to execute operation: Access denied
  376.         systemctl disable rexec  #Failed to execute operation: Access denied
  377.         systemctl disable rsh    #Failed to execute operation: Access denied
  378.         systemctl disable rlogin #Failed to execute operation: Access denied
  379.         systemctl disable ypbind #Failed to execute operation: Access denied
  380.         systemctl disable tftp   #Failed to execute operation: Access denied
  381.         systemctl disable certmonger
  382.         systemctl disable cgconfig
  383.         systemctl disable cgred
  384.         systemctl disable cpuspeed #Failed to execute operation: Access denied
  385.         systemctl enable irqbalance
  386.         systemctl disable kdump
  387.         systemctl disable mdmonitor
  388.         systemctl disable messagebus
  389.         systemctl disable netconsole #netconsole.service is not a native service, redirecting to /sbin/chkconfig.Executing /sbin/chkconfig netconsole off
  390.         systemctl disable ntpdate
  391.         systemctl disable oddjobd
  392.         systemctl disable portreserve #Failed to execute operation: Access denied
  393.         systemctl enable psacct
  394.         systemctl disable qpidd #Failed to execute operation: Access denied
  395.         systemctl disable quota_nld #Failed to execute operation: Access denied
  396.         systemctl disable rdisc
  397.         systemctl disable rhnsd #Failed to execute operation: Access denied
  398.         systemctl disable rhsmcertd #Failed to execute operation: Access denied
  399.         systemctl disable saslauthd
  400.         systemctl disable smartd
  401.         systemctl disable sysstat #Failed to execute operation: Access denied
  402.         systemctl enable crond
  403.         systemctl disable atd
  404.         systemctl disable nfslock
  405.         systemctl disable named #Failed to execute operation: Access denied
  406.         systemctl disable httpd #Failed to execute operation: Access denied
  407.         systemctl disable dovecot #Failed to execute operation: Access denied
  408.         systemctl disable squid #Failed to execute operation: Access denied
  409.         systemctl disable snmpd #Failed to execute operation: Access denied

  410.         echo "| Disable Secure RPC Client Service"
  411.         systemctl disable rpcgssd

  412.         echo "| Disable Secure RPC Server Service"
  413.         systemctl disable rpcsvcgssd

  414.         echo "| Disable RPC ID Mapping Service"
  415.         systemctl disable rpcidmapd
  416.         systemctl disable netfs #Failed to execute operation: Access denied

  417.         echo "| Disable Network File System (nfs)"
  418.         systemctl disable nfs


  419.         echo "| Remove Rsh Trust Files"
  420.         backupFile /etc/hosts.equiv
  421.         backupFile ~/.rhosts
  422.         rm /etc/hosts.equiv
  423.         rm ~/.rhosts

  424.         echo "| Disable Avahi Server Software"
  425.         systemctl disable avahi-daemon

  426.         echo "| Disable the CUPS Service"
  427.         systemctl disable cups

  428.         echo "| Disable xinetd Service"
  429.         systemctl disable xinetd #Failed to execute operation: Access denied

  430. }

  431. On_DHCP()
  432. {
  433.         echo "| Disable DHCP Service"
  434.         systemctl disable dhcpd

  435.         echo "| Uninstall DHCP Server Package"
  436.         yum erase dhcp

  437.         echo "| Disable DHCP Client"

  438. echo "Open /etc/sysconfig/network-scripts/ifcfg-eth0 (if you have more interfaces, do this for each one) and make sure the address is statically assigned with the BOOTPROTO=none

  439. Example:
  440. BOOTPROTO=none
  441. NETMASK=255.255.255.0
  442. IPADDR=192.168.1.2
  443. GATEWAY=192.168.1.1"

  444. }

  445. On_Postfix()
  446. {

  447.         systemctl enable postfix
  448.         yum remove sendmail

  449.         #Postfix Disable Network Listening
  450.         backupFile /etc/postfix/main.cf
  451.         echo "|/etc/postfix/main.cf. ensure the following inet_interfaces line appears:inet_interfaces = localhost"
  452.         gedit  /etc/postfix/main.cf
  453. }

  454. Disable_autofs()
  455. {
  456.         echo "| Disable autofs"
  457.         chkconfig --level 0123456 autofs off
  458.         service autofs stop
  459. }

  460. Disable_uncommon_filesystems()
  461. {
  462.         echo "| Disable uncommon filesystems"
  463.         backupFile /etc/modprobe.d/cramfs.conf
  464.         backupFile /etc/modprobe.d/freevxfs.conf
  465.         backupFile /etc/modprobe.d/jffs2.conf
  466.         backupFile /etc/modprobe.d/hfs.conf
  467.         backupFile /etc/modprobe.d/hfsplus.conf
  468.         backupFile /etc/modprobe.d/squashfs.conf
  469.         backupFile /etc/modprobe.d/udf.conf
  470.         echo "install cramfs /bin/false"   > /etc/modprobe.d/cramfs.conf
  471.         echo "install freevxfs /bin/false" > /etc/modprobe.d/freevxfs.conf
  472.         echo "install jffs2 /bin/false"    > /etc/modprobe.d/jffs2.conf
  473.         echo "install hfs /bin/false"      > /etc/modprobe.d/hfs.conf
  474.         echo "install hfsplus /bin/false"  > /etc/modprobe.d/hfsplus.conf
  475.         echo "install squashfs /bin/false" > /etc/modprobe.d/squashfs.conf
  476.         echo "install udf /bin/false"      > /etc/modprobe.d/udf.conf
  477. }

  478. On_core_dumps()
  479. {
  480.         echo "| Disable core dumps for all users"
  481.         backupFile /etc/security/limits.conf
  482.         # 禁止創(chuàng)建core文件
  483.         echo "* hard core 0"   >> /etc/security/limits.conf
  484.         # 除root外,其他用戶最多使用5M內(nèi)存
  485.         echo "* hard rss 5000" >> /etc/security/limits.conf
  486.         # 最多進(jìn)程數(shù)限制為20
  487.         echo "* hard nproc 20" >> /etc/security/limits.conf

  488.         echo "| Disable core dumps for SUID programs"
  489.         # Set runtime for fs.suid_dumpable
  490.         #
  491.         sysctl -q -n -w fs.suid_dumpable=0
  492. }


  493. On_SELinux()
  494. {
  495.         backupFile /etc/grub.conf
  496.         echo "| Confirm SELinux is not disabled"
  497.         sed -i "s/selinux=0//gI"   /etc/grub.conf
  498.         sed -i "s/enforcing=0//gI" /etc/grub.conf


  499.         backupFile /etc/selinux/config
  500.         echo "| Open /etc/selinux/config and check for SELINUXTYPE=targeted or SELINUXTYPE=enforcing, depending on your requirements."
  501.         gedit /etc/selinux/config


  502.         echo "| Enable the SELinux restorecond Service"
  503.         echo "| Enable restorecond for all run levels:"
  504.         chkconfig --level 0123456 restorecond on
  505.         echo "| Start restorecond if not currently running:"
  506.         service restorecond start


  507.         echo "| Check no daemons are unconfined by SELinux"
  508.         sudo ps -eZ | egrep "initrc" | egrep -vw "tr|ps|egrep|bash|awk" | tr ':' ' ' | awk '{ print $NF }'
  509.         echo "| This should return no output."
  510. }

  511. Prevent_Log_Into_Accounts_With_Empty_Password()
  512. {
  513.         backupFile /etc/pam.d/system-auth
  514.         sed -i 's/\<nullok\>//g' /etc/pam.d/system-auth
  515. }
  516. On_SSH()
  517. {
  518.         echo "| Allow Only SSH Protocol 2"
  519.         echo "| Open /etc/ssh/sshd_config and ensure the following line exists:Protocol 2"
  520.         echo "| PermitRootLogin no"
  521.         echo "| HostbasedAuthentication no"
  522.         echo "| IgnoreRhosts yes"
  523.         echo "| PermitEmptyPasswords no"
  524.         echo "| PermitUserEnvironment no"
  525.         echo "| ClientAliveInterval 300  #Set SSH Idle Timeout Interval(seconds)"
  526.         echo "| ClientAliveCountMax 0         #指如果發(fā)現(xiàn)客戶端沒有相應(yīng),則判斷一次超時(shí),這個(gè)參數(shù)設(shè)置允許超時(shí)的次數(shù)"
  527.         echo "| Banner /etc/issue"
  528.         echo "| DenyUsers USER1 USER2         #Limit Users’ SSH Access"
  529.        
  530.         backupFile /etc/ssh/sshd_config
  531.         gedit /etc/ssh/sshd_config

  532.         echo "restart ssh"
  533.         systemctl restart sshd.service
  534. }
  535. On_Update()
  536. {
  537.         echo "| Prompt OS update installation"
  538.         yum -y install yum-cron
  539.         chkconfig yum-cron on
  540. }

  541. Passwd_For_SingleUserMode()
  542. {
  543.         echo "| Passwd_For_SingleUserMode"

  544.         backupFile /etc/inittab
  545.         echo "# Require the root pw when booting into single user mode" >> /etc/inittab
  546.         echo "~~:S:wait:/sbin/sulogin" >> /etc/inittab
  547.         echo "Don't allow any nut to kill the server"
  548.         perl -npe 's/ca::ctrlaltdel:\/sbin\/shutdown/#ca::ctrlaltdel:\/sbin\/shutdown/' -i /etc/inittab
  549. }

  550. Install_Packages()
  551. {
  552.         echo "| Install clamav"
  553.         yum install clamav clamav-daemon clamav-freshclam clamav-unofficial-sigs
  554.         freshclam
  555.         service clamav-daemon start


  556.         echo "| Install lynis"
  557.         yum install lynis


  558.         lynis audit system

  559.         rpm -Uvh lux-release-7-1.noarch.rpm
  560.         yum install maldetect



  561. }


  562. echo '';echo '';echo ''
  563. echo '-------------------------------------------'
  564. echo 'Security Harden CentOS 7'
  565. echo '-------------------------------------------'

  566. echo '';echo '';echo ''
  567. On_NTP;
  568. #
  569. echo '';echo '';echo ''
  570. Configure_System_for_AIDE;
  571. #
  572. echo '';echo '';echo ''
  573. Enable_Secure_high_quality_Password_Policy;
  574. #
  575. echo '';echo '';echo ''
  576. Verify_grub_Permissions;
  577. #
  578. echo '';echo '';echo ''
  579. Require_Authentication_for_Single_User_Mode;
  580. #
  581. echo '';echo '';echo ''
  582. Disable_Zeroconf_Networking;
  583. #
  584. echo '';echo '';echo ''
  585. Securing_root_Logins;
  586. #
  587. echo '';echo '';echo ''
  588. Enable_UMASK_077;
  589. #
  590. echo '';echo '';echo ''
  591. Prune_Idle_Users;
  592. #
  593. echo '';echo '';echo ''
  594. Securing_Cron;
  595. #
  596. echo '';echo '';echo ''
  597. Sysctl_Security;
  598. #
  599. echo '';echo '';echo ''
  600. Deny_All_TCP_Wrappers;
  601. #
  602. echo '';echo '';echo ''
  603. Verify_iptables_Enabled;
  604. #
  605. echo '';echo '';echo ''
  606. Disable_Uncommon_Protocols;
  607. #
  608. echo '';echo '';echo ''
  609. Enable_Rsyslog;
  610. #
  611. echo '';echo '';echo ''
  612. On_Auditd;
  613. #
  614. echo '';echo '';echo ''
  615. Remove_Services;
  616. #
  617. echo '';echo '';echo ''
  618. On_DHCP;
  619. #
  620. echo '';echo '';echo ''
  621. On_Postfix;
  622. #
  623. echo '';echo '';echo ''
  624. Disable_autofs;
  625. #
  626. echo '';echo '';echo ''
  627. Disable_uncommon_filesystems;
  628. #
  629. echo '';echo '';echo ''
  630. On_core_dumps;
  631. #
  632. echo '';echo '';echo ''
  633. On_SELinux;
  634. #
  635. echo '';echo '';echo ''
  636. Prevent_Log_Into_Accounts_With_Empty_Password;
  637. #
  638. echo '';echo '';echo ''
  639. On_SSH;
  640. #
  641. echo '';echo '';echo ''
  642. On_Update;
  643. #
  644. echo '';echo '';echo ''
  645. Passwd_For_SingleUserMode;
  646. #
  647. echo '';echo '';echo ''
  648. Install_Packages;


  649. echo '-------------------------------------------'
  650. echo ' '
  651. echo '-------------------------------------------'
  652. echo ''
  653. echo ''
  654. echo ''
  655. echo 'Disable ping response'
  656. echo '/etc/sysctl.conf        set net.ipv4.conf.icmp_echo_ignore_all = 1'
  657. #gedit /etc/sysctl.conf
復(fù)制代碼

centos7_hardening1.sh.word

7.32 KB, 下載次數(shù): 3

centos7_hardening2.sh.word

28.71 KB, 下載次數(shù): 4

論壇徽章:
224
2022北京冬奧會(huì)紀(jì)念版徽章
日期:2015-08-10 16:30:32操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-02-18 06:20:00操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-03-01 06:20:00操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-03-02 06:20:0015-16賽季CBA聯(lián)賽之上海
日期:2019-09-20 12:29:3219周年集字徽章-周
日期:2019-10-01 20:47:4815-16賽季CBA聯(lián)賽之八一
日期:2020-10-23 18:30:5320周年集字徽章-20	
日期:2020-10-28 14:14:2615-16賽季CBA聯(lián)賽之廣夏
日期:2023-02-25 16:26:26CU十四周年紀(jì)念徽章
日期:2023-04-13 12:23:1015-16賽季CBA聯(lián)賽之四川
日期:2023-07-25 16:53:45操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-05-10 19:22:58
2 [報(bào)告]
發(fā)表于 2016-01-27 17:53 來自手機(jī) |只看該作者
多打補(bǔ)丁就好了,沒必要搞這些。。。

論壇徽章:
5
金牛座
日期:2015-07-03 13:32:00卯兔
日期:2015-07-03 13:32:17程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-11-29 06:20:0015-16賽季CBA聯(lián)賽之同曦
日期:2015-12-15 09:36:06CU十四周年紀(jì)念徽章
日期:2016-07-06 17:18:48
3 [報(bào)告]
發(fā)表于 2016-01-28 15:24 |只看該作者
2.sh里面
echo "tty1" > /etc/securetty
#echo "console" > /etc/securetty

console就是監(jiān)視器,控制臺(tái)
不要使用自己都不清楚含義的腳本,安全加固是針對(duì)性的。不是隨便下一個(gè)腳本用的。

論壇徽章:
41
操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-08-21 06:20:00每日論壇發(fā)貼之星
日期:2016-05-05 06:20:00操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-05-05 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-05 06:20:0015-16賽季CBA聯(lián)賽之山西
日期:2016-04-27 08:49:00操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-04-25 06:20:00操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-04-17 06:23:2815-16賽季CBA聯(lián)賽之吉林
日期:2016-03-25 15:46:3415-16賽季CBA聯(lián)賽之四川
日期:2016-03-25 14:26:19操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-05-27 06:20:00操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-05-28 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-08-18 06:20:00
4 [報(bào)告]
發(fā)表于 2016-01-29 09:39 |只看該作者
這么多功能賬號(hào)和應(yīng)用都被移除了,樓主確定大丈夫?

如果是你自己寫的腳本,那么的說,如果只是隨便下載的一個(gè)腳本,你確定知道它會(huì)有哪些影響嗎?
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP