TIPs:

世界上有一撮人专门研究主机安全加固基线,有兴趣的读者可以到 http://benchmarks.cisecurity.org/ 获取更加详细专业的主机安全基线配置文档。或者到 https://www.open-scap.org/security-policies/choosing-policy/获取scap格式的加固模板。

CentOS 7 主机加固手册-上

CentOS 7 主机加固手册-中

CentOS 7 主机加固手册-下

0x01 Kickstart自动化安装

通过kickstart脚本安装操作系统,最小化安装,预分区并设置严格的挂载权限。

#version=RHEL7

install

# System authorization information

auth --enableshadow --passalgo=sha512

# Use CDROM installation media

cdrom

# Accept EULA

eula --agreed

services --enabled=NetworkManager,sshd

reboot

# Run the Setup Agent on first boot

#firstboot --enable

ignoredisk --only-use=sda

# Keyboard layouts

keyboard --vckeymap=us --xlayouts='us'

# System language

lang en_US.UTF-8

# SELinux

selinux --enforcing

# Network information

network  --bootproto=dhcp --device=eno16777736 --onboot=on --ipv6=off

network  --hostname=default-vm

# Root password

rootpw --iscrypted HASHGOESHERE

# System timezone

timezone Europe/London --isUtc --ntpservers=prime.transformers

# System bootloader configuration

bootloader --location=mbr --boot-drive=sda

# Partition clearing information

clearpart --all --drives=sda

ignoredisk --only-use=sda

# LVM

# Disk partitioning information

part pv.18 --fstype="lvmpv" --ondisk=sda --size=8004

part pv.11 --fstype="lvmpv" --ondisk=sda --size=8004

part /boot --fstype="ext4" --ondisk=sda --size=1000

volgroup lg_data --pesize=4096 pv.18

volgroup lg_os --pesize=4096 pv.11

logvol /  --fstype="xfs" --size=4000 --name=lv_root --vgname=lg_os

logvol /home  --fstype="xfs" --size=2000 --name=lv_home --vgname=lg_data

logvol /tmp  --fstype="xfs" --size=1000 --name=lv_tmp --vgname=lg_os

logvol /var  --fstype="xfs" --size=2000 --name=lv_var --vgname=lg_os

logvol /var/tmp  --fstype="xfs" --size=1000 --name=lv_var_tmp --vgname=lg_os

logvol /var/www  --fstype="xfs" --size=5000 --name=lv_var_www --vgname=lg_data

logvol /var/log  --fstype="xfs" --size=1500 --name=lv_var_log --vgname=lg_os

logvol /var/log/audit  --fstype="xfs" --size=500 --name=lv_var_log_audit --vgname=lg_os

logvol swap  --fstype="swap" --size=1000 --name=lv_swap --vgname=lg_data

%packages

@core

 %end

%post

%end

0x02 安全地挂载分区

如果网站是动态网站,那么网站所在的盘不可以使用noexec挂载选项。像/tmp和/var/tmp应该使用noexec挂载选项,因为黑客通常在这两个目录里面上传并执行提权程序。

一个安全地/etc/fstab 文件配置举例:

#

# /etc/fstab

# Created by anaconda on Sat Oct 11 14:28:47 2014

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/lg_os-lv_root /                       xfs     defaults        1 1

UUID=d73c5d22-75ed-416e-aad2-8c1bb1dfc713 /boot                   ext4    defaults,nosuid,noexec,nodev        1 2

/dev/mapper/lg_data-lv_home /home                   xfs     defaults        1 2

/dev/mapper/lg_os-lv_tmp /tmp                    xfs     defaults,nosuid,noexec,nodev        1 2

/dev/mapper/lg_os-lv_var /var                    xfs     defaults,nosuid        1 2

/dev/mapper/lg_os-lv_var_tmp /var/tmp                xfs     defaults,nosuid,noexec,nodev        1 2

/dev/mapper/lg_os-lv_var_tmp /var/log                xfs     defaults,nosuid,noexec,nodev        1 2

/dev/mapper/lg_os-lv_var_tmp /var/log/audit                xfs     defaults,nosuid,noexec,nodev        1 2

/dev/mapper/lg_data-lv_var_www /var/www                xfs     defaults,nosuid,noexec,nodev        1 2

/dev/mapper/lg_data-lv_swap swap                    swap    defaults        0 0

0x03  安装NTP服务

在进行一些合规性审计的时候NTP是必要的,同步时间有利于审计日志。

yum install ntp ntpdate

chkconfig ntpd on

ntpdate pool.ntp.org

/etc/init.d/ntpd start 

0x04 配置完整性检查工具AIDE

Pre-linking binaries功能缩短了运行时间,然而这种方式会导致AIDE出现故障,所以配置AIDE之前需要禁止此项。打开/etc/sysconfig/prelink确保PRELINKING=no ,或者直接使用下面的脚本:

# Disable prelinking altogether

#

if grep -q ^PRELINKING /etc/sysconfig/prelink

then

  sed -i 's/PRELINKING.*/PRELINKING=no/g' /etc/sysconfig/prelink

else

  echo -e "\n# Set PRELINKING=no per security requirements" >> /etc/sysconfig/prelink

  echo "PRELINKING=no" >> /etc/sysconfig/prelink

fi

Disable previous prelink changes to binaries:

Disable previous prelink changes to binaries

root:~# /usr/sbin/prelink -ua

安装AIDE

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

Configure periodic execution of AIDE, runs every morning at 04:30

echo "05 4 * * * root /usr/sbin/aide --check" >> /etc/crontab

  

0x05 阻止用户挂载USB

echo "install usb-storage /bin/false" > /etc/modprobe.d/usb-storage.conf

0x06 启用高强度的密码策略

下面这条命令将启用SHA512替代MD5

authconfig --passalgo=sha512 —update

0x07 配置密码策略pwquality.conf

vi /etc/security/pwquality.conf

# Configuration for systemwide password quality limits

# Defaults:

#

# Number of characters in the new password that must not be present in the

# old password.

difok = 5

#

# Minimum acceptable size for the new password (plus one if

# credits are not disabled which is the default). (See pam_cracklib manual.)

# Cannot be set to lower value than 6.

minlen = 14

#

# The maximum credit for having digits in the new password. If less than 0

# it is the minimum number of digits in the new password.

dcredit = 1

#

# The maximum credit for having uppercase characters in the new password.

# If less than 0 it is the minimum number of uppercase characters in the new

# password.

ucredit = 1

#

# The maximum credit for having lowercase characters in the new password.

# If less than 0 it is the minimum number of lowercase characters in the new

# password.

lcredit = 1

#

# The maximum credit for having other characters in the new password.

# If less than 0 it is the minimum number of other characters in the new

# password.

ocredit = 1

#

# The minimum number of required classes of characters for the new

# password (digits, uppercase, lowercase, others).

minclass = 4

#

# The maximum number of allowed consecutive same characters in the new password.

# The check is disabled if the value is 0.

maxrepeat = 3

#

# The maximum number of allowed consecutive characters of the same class in the

# new password.

# The check is disabled if the value is 0.

maxclassrepeat = 3

#

# Whether to check for the words from the passwd entry GECOS string of the user.

# The check is enabled if the value is not 0.

gecoscheck = 1

#

# Path to the cracklib dictionaries. Default is to use the cracklib default.

# dictpath =

设置密码策略

Add the following to /etc/login.defs

PASS_MIN_LEN 14

PASS_MIN_DAYS 1

PASS_MAX_DAYS 60

0x08 设置提示上次登录信息

vim /etc/pam.d/system-auth 

session required pam_lastlog.so showfailed

0x09 设置每个会话最大密码尝试次数

Set the amount of password reprompts per session, by editing the pam_pwquality.so statement in

vim  /etc/pam.d/system-auth 

auth pam_pwquality.so  retry=3  

0x0a 阻止错误密码尝试

编辑 /etc/pam.d/system-auth 和 /etc/pam.d/password-auth两个PAM配置文件

auth [default=die] pam_faillock.so authfail deny=3 unlock_time=604800 fail_interval=900

auth required pam_faillock.so authsucc deny=3 unlock_time=604800 fail_interval=900

0x0b 限制密码重用

使用PAM模块配置,在 /etc/pam.d/system-auth这个PAM配置文件里面,在pam_unix.so所在的行添加 remember=24 。这样服务器就会记录历史上的前24个旧密码,为啥为24?因为这是美国国防部的标准。

password sufficient pam_unix.so existing_options remember=24 

CentOS 7 主机加固手册-上的更多相关文章

  1. CentOS 7 主机加固手册-下

      CentOS 7 主机加固手册-上 CentOS 7 主机加固手册-中 CentOS 7 主机加固手册-下 0x1f 删除禁用非必要的服务 删除非必要的服务 # Remove yum remove ...

  2. CentOS 7 主机加固手册-中

      CentOS 7 主机加固手册-上 CentOS 7 主机加固手册-中 CentOS 7 主机加固手册-下 0x0c 设置/boot/grub2/grub.cfg权限 Set grub.conf ...

  3. 在阿里云 CentOS 服务器(ECS)上搭建 nginx + mysql + php-fpm 环境

    阿里云的云服务器(ECS)可以选择多种操作系统,打算用它运行 Drupal或者 WordPress ,你最好选择 Linux 系统,这篇文章的演示是基于阿里云的 CentOS 操作系统的服务器.我们在 ...

  4. (转)在阿里云 CentOS 服务器(ECS)上搭建 nginx + mysql + php-fpm 环境

    阿里云的云服务器(ECS)可以选择多种操作系统,打算用它运行 Drupal或者 WordPress ,你最好选择 Linux 系统,这篇文章的演示是基于阿里云的 CentOS 操作系统的服务器.我们在 ...

  5. CentOS 7主机名的弯弯绕绕

    在CentOS 6中,修改主机名方式很简单,临时修改主机名使用hostname命令,永久修改主机名直接写进文件/etc/sysconfig/network中即可. 但在CentOS 7中,主机名就没那 ...

  6. 主机加固之windows2003

    这篇与上一篇的win7主机加固内容大体类似,部分有些不同.这篇也可以用来尝试加固windows XP. 1. 配置管理 1.1用户策略 注意:在对Windows系统加固之前先新建一个临时的系统管理员账 ...

  7. 主机加固之win7

    这套主机加固方案很简单,一步一步按着顺序来弄就可以,部分步骤还配有相关图片.可以先用虚拟机来做一次加固,以防弄错后不好恢复.记得弄个快照,以防万一.下次有空写个win7暴力破解~ 1. 配置管理 1. ...

  8. centos修改主机名命令

    centos修改主机名命令   需要修改两处:一处是/etc/sysconfig/network,另一处是/etc/hosts,只修改任一处会导致系统启动异常.首先切换到root用户.    vi / ...

  9. Centos 修改主机名称

    Centos 配置主机名称: 1.首先查询一下当前的主机名称 [root@localhost~]# hostnamectl status Static hostname: ****** //永久主机名 ...

随机推荐

  1. mybatis if标签比较字符串

    项目中需要在mybatis后台比较字符串 因为mybatis映射文件使用的是ognl表达式,所以不能使用 <if test="type == '0'"> 解决: < ...

  2. Java 集合学习--集合概述

    一.集合框架 集合,通常也叫容器,java中有多种方式保存对象,集合是java保存对象(对象的引用)的方式之一,之前学习的数组是保存对象的最有效的方式,但是数组却存在一个缺陷,数组的大小是固定的,但是 ...

  3. 初学者学习python2还是python3?

    如果你是一个初学者,或者你以前接触过其他的编程语言,你可能不知道,在开始学习python的时候都会遇到一个比较让人很头疼的问题:版本问题!!是学习python2 还是学习 python3 ?这是非常让 ...

  4. [剑指Offer] 42.和为S的两个数字

    题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小的先输出. [思 ...

  5. SQL 取数值小数后两位,但不四舍五入

    select round('1.67789',2,1) /* 1.67*/

  6. BZOJ4444 SCOI2015国旗计划(贪心+倍增)

    链上问题是一个经典的贪心.于是考虑破环成链,将链倍长.求出每个线段右边能作为后继的最远线段,然后倍增即可. #include<iostream> #include<cstdio> ...

  7. [CF15C]Industrial Nim

    题目大意:有$n$个采石场,每行一个$m_i$一个$x_i$,表示第$i$个采石场有$m_i$辆车,这个采石场中车中的石子为从$x_i$开始的自然数.Nim游戏若先手赢输出"tolik&qu ...

  8. nowcoder 提高组模拟赛 最长路 解题报告

    最长路 链接: https://www.nowcoder.com/acm/contest/178/A 来源:牛客网 题目描述 有一张 \(n\) 个点 \(m\) 条边的有向图,每条边上都带有一个字符 ...

  9. 使用es6一行搞定文字溢出省略号

    使用的是es6中扩展字符串方法参考地址 padStart(),padEnd() 使用padStart() 两个参数padStart(字符串最小长度,用来补全的字符串): 例如 let str = '1 ...

  10. git使用笔记(一)入门

    By francis_hao    Nov 17,2016 本来是想把git的使用笔记写在一个文件里,但是越写越长,最后也不得不分开了.这样也好,每一篇一个侧重,可以写的详细一点.   初学乍练 在l ...