脚本环境:RHEL6.*

脚本说明:该脚本作用为纯执行检测不涉及更改配置等操作,与直接上来就改安全配置等基线脚本相比相对安全一些。虽然如此,在你执行该脚本之前仍然建议你备份或快照一下目标系统。

代码部分:

#! /bin/bash
cat <<EOF
*************************************************************************
linux安全配置扫描脚本:
. 输出结果也可以在当前目录的out.txt中查看
. 检查范围:
-》账号策略检查
-》账号注销检查
-》GRUB密码检查
-》LILO密码检查
-》非root账号但UID为0的用户检查
-》/etc/profile中umask默认值检查
-》/etc/csh.cshrc中umask默认值检查
-》/etc/bashrc中umask默认值检查
-》重要文件权限检查
-》内核文件dump配置检查 *************************************************************************
EOF
rm -rf ./out.txt
echo -e "\n"
echo "[1] 账号策略检查中..."
passmax=`cat /etc/login.defs | grep PASS_MAX_DAYS | grep -v ^# | awk '{print $2}'`
passmin=`cat /etc/login.defs | grep PASS_MIN_DAYS | grep -v ^# | awk '{print $2}'`
passlen=`cat /etc/login.defs | grep PASS_MIN_LEN | grep -v ^# | awk '{print $2}'`
passage=`cat /etc/login.defs | grep PASS_WARN_AGE | grep -v ^# | awk '{print $2}'`
if [ $passmax -le -a $passmax -gt ];then
echo " [OK]口令生存周期为${passmax}天,符合要求" >> out.txt
else
echo " [ X ] 口令生存周期为${passmax}天,不符合要求,建议设置不大于90天" >> out.txt
fi
if [ $passmin -ge ];then
echo " [OK]口令更改最小时间间隔为${passmin}天,符合要求" >> out.txt
else
echo " [ X ] 口令更改最小时间间隔为${passmin}天,不符合要求,建议设置大于等于6天" >> out.txt
fi
if [ $passlen -ge ];then
echo " [OK]口令最小长度为${passlen},符合要求" >> out.txt
else
echo " [ X ] 口令最小长度为${passlen},不符合要求,建议设置最小长度大于等于8" >> out.txt
fi
if [ $passage -ge -a $passage -lt $passmax ];then
echo " [OK]口令过期警告时间天数为${passage},符合要求" >> out.txt
else
echo " [ X ] 口令过期警告时间天数为${passage},不符合要求,建议设置大于等于30并小于口令生存周期" >> out.txt
fi
echo "..."
echo 'check over'
echo -e "\n"
echo "[2] 账号注销检查中..."
TMOUT=`cat /etc/profile | grep TMOUT | awk -F[=] '{print $2}'`
if [ ! $TMOUT ];then
echo " [ X ] 账号超时不存在自动注销,不符合要求,建议设置小于600秒" >> out.txt
else
if [ $TMOUT -le -a $TMOUT -ge ] ; then
echo " [ √ ] 账号超时时间${TMOUT}秒,符合要求" >> out.txt
else
echo " [ X ] 账号超时时间$TMOUT秒,不符合要求,建议设置小于600秒" >> out.txt
fi
fi
echo "..."
echo 'check over'
echo -e "\n"
echo "[3] GRUB密码检查中..."
grup_pwd=`cat /etc/grub.conf | grep -v ^# | grep password > /dev/null`
if [ $? -eq ];then
echo " [ √ ] 已设置grub密码,符合要求" >> out.txt
else
echo " [ X ] 没有设置grub密码,不符合要求,建议设置grub密码" >> out.txt
fi
echo "..."
echo "check over"
echo -e "\n"
echo "[4] LILO密码检查中..."
if [ ! -f /etc/lilo.conf ] ; then
echo " [ √ ] lilo.conf配置文件不存在,系统可能不是通过LILO引导" >> out.txt
else
lilo_pwd=`cat /etc/lilo.conf | grep -v ^# | grep password &> /dev/null`
if [ $? -eq ];then
echo " [ √ ] 已设置lilo密码,符合要求" >> out.txt
else
echo " [ X ] 没有设置lilo密码,不符合要求,建议设置lilo密码(操作有风险,需慎重!)" >> out.txt
fi
fi
echo "..."
echo "check over"
echo -e "\n" echo "[5] 非root账号但UID为0的用户检查中..."
UIDS=`awk -F[:] 'NR!=1{print $3}' /etc/passwd`
flag=
for i in $UIDS
do
if [ $i = ];then
flag=
fi
done
if [ $flag != ];then
echo " [ √ ] 不存在root账号外的UID为0的异常用户" >> out.txt
else
echo " [ X ] 存在非root但UID为0的异常用户,请立刻进行排查" >> out.txt
fi
echo "..."
echo "check over"
echo -e "\n" echo "[6] /etc/profile中umask默认值检查中..."
umask1=`cat /etc/profile | grep umask | grep -v '^#' | awk '{print $2}'`
flags= for i in $umask1
do
if [ $i = "" ];then
flags=
fi
done
if [ $flags = ];then
echo " [ √ ] /etc/profile文件中所设置的umask为${i},符合要求" >> out.txt
else
echo " [ X ] /etc/profile文件中所设置的umask为${i},不符合要求" >> out.txt
echo " 【理论上建议设置值为027,但因系统重要程度不同请根据具体情况慎重操作,如不确定请暂忽略此项】" >> out.txt
fi
echo "..."
echo "check over"
echo -e "\n" echo "[7] /etc/csh.cshrc中umask默认值检查中..."
umask2=`cat /etc/csh.cshrc | grep umask | grep -v '^#' | awk '{print $2}'`
flags= for i in $umask2
do
if [ $i = "" ];then
flags=
fi
done
if [ $flags = ];then
echo " [ √ ] /etc/csh.cshrc文件中所设置的umask为${i},符合要求" >> out.txt
else
echo " [ X ] /etc/csh.cshrc文件中所设置的umask为${i},不符合要求" >> out.txt
echo " 【理论上建议设置值为027,但因系统重要程度不同请根据具体情况慎重操作,如不确定请暂忽略此项】" >> out.txt
fi
echo "..."
echo "check over"
echo -e "\n" echo "[8] /etc/bashrc中umask默认值检查中..."
umask3=`cat /etc/bashrc | grep umask | grep -v '^ #' | awk '{print $2}'`
flags= for i in $umask3
do
if [ $i = "" ];then
flags=
fi
done
if [ $flags = ];then
echo " [ √ ] /etc/bashrc文件中所设置的umask为${i},符合要求" >> out.txt
else
echo " [ X ] /etc/bashrc文件中所设置的umask为${i},不符合要求" >> out.txt
echo " 【理论上建议设置值为027,但因系统重要程度不同请根据具体情况慎重操作,如不确定请暂忽略此项】" >> out.txt
fi
echo "..."
echo "check over"
echo -e "\n" echo "[9] 重要文件权限检查中..."
file1=`ls -l /etc/passwd | awk '{print $1}'`
if [ $file1 = "-rw-r--r--." ];then
echo " [ √ ] /etc/passwd文件权限为644,符合要求" >> out.txt
else
echo " [ X ] /etc/passwd文件权限为[$file1.],不符合要求" >> out.txt
fi file2=`ls -l /etc/shadow | awk '{print $1}'`
if [ $file2 = "-rw-r--r--." ] || [ $file2 = "----------." ];then
echo " [ √ ] /etc/shadow文件权限为400或000,符合要求" >> out.txt
else
echo " [ X ] /etc/shadow文件权限为${file2},不符合要求" >> out.txt
fi file3=`ls -l /etc/group | awk '{print $1}'`
if [ $file3 = "-rw-r--r--." ];then
echo " [ √ ] /etc/group文件权限为644,符合要求" >> out.txt
else
echo " [ X ] /etc/group文件权限为$file3,不符合要求" >> out.txt
fi file4=`ls -l /etc/securetty | awk '{print $1}'`
if [ $file4 = "-rw-------." ];then
echo " [ √ ] /etc/security文件权限为600,符合要求" >> out.txt
else
echo " [ X ] /etc/security文件权限不为600,不符合要求,建议设置权限为600" >> out.txt
fi file5=`ls -l /etc/services | awk '{print $1}'`
if [ $file5 = "-rw-r--r--." ];then
echo " [ √ ] /etc/services文件权限为644,符合要求" >> out.txt
else
echo " [ X ] /etc/services文件权限不为644,不符合要求,建议设置权限为644" >> out.txt
fi file6=`ls -l /etc/xinetd.conf | awk '{print $1}'`
if [ !-f $file6 ];then
echo " [ √ ] /etc/xinetd.conf文件不存在,暂略此项" >> out.txt
else
if [ $file6 = "-rw-------." ];then
echo " [ √ ] /etc/xinetd.conf文件权限为600,符合要求" >> out.txt
else
echo " [ X ] /etc/xinetd.conf文件权限不为600,不符合要求,建议设置权限为600" >> out.txt
fi
fi file7=`ls -l /etc/grub.conf | awk '{print $1}'`
if [ $file7 = "-rw-------." ];then
echo " [ √ ] /etc/grub.conf文件权限为600,符合要求" >> out.txt
else
echo " [ X ] /etc/grub.conf文件权限为$file7,不符合要求,建议设置权限为600" >> out.txt
fi file8=`ls -l /etc/lilo.conf | awk '{print $1}'`
if [ -f /etc/lilo.conf ];then
if [ $file8 = "-rw-------" ];then
echo " [ √ ] /etc/lilo.conf文件权限为600,符合要求" >> out.txt
else
echo " [ X ] /etc/lilo.conf文件权限不为600,不符合要求,建议设置权限为600" >> out.txt
fi
else
echo " [ √ ] /etc/lilo.conf文件不存在,暂略此项" >> out.txt
fi
echo "..."
echo "check over"
echo -e "\n" echo "[10] 内核文件dump配置检查中..."
cat /etc/security/limits.conf | grep -v ^# | grep core
if [ $? = ];then
#soft=`cat /etc/security/limits.conf| grep -V ^# | grep core | awk {print $}`
soft=`cat /etc/security/limits.conf| grep -v '^#' | awk '{print $2}'` &> /dev/null
for i in $soft
do
if [ $i = "soft" ];then
echo -e " [ √ ] 内核文件dump配置检查[*\tsoft\tcore\t0]已经设置" >> out.txt
fi
if [ $i = "hard" ];then
echo -e " [ √ ] 内核文件dump配置检查[*\thard\tcore\t0]已经设置" >> out.txt
fi
done
else
echo -e " [ X ] 没有设置core,建议在/etc/security/limits.conf中添加[*\tsoft\tcore\t0]和[*\thard\tcore\t0]" >> out.txt
fi
echo "..."
echo "check over"
echo -e "\n" echo "--------------------------------------------------------------------------"
echo ""
echo "扫描结果:"
echo ""
cat ./out.txt
echo ""
echo "--------------------------------------------------------------------------"
echo ""

执行结果:

[root@localhost ~]# ./linuxCheck.sh
*************************************************************************
linux安全配置扫描脚本:
. 输出结果也可以在当前目录的out.txt中查看
. 检查范围:
-》账号策略检查
-》账号注销检查
-》GRUB密码检查
-》LILO密码检查
-》非root账号但UID为0的用户检查
-》/etc/profile中umask默认值检查
-》/etc/csh.cshrc中umask默认值检查
-》/etc/bashrc中umask默认值检查
-》重要文件权限检查
-》内核文件dump配置检查 ************************************************************************* [] 账号策略检查中...
...
check over [] 账号注销检查中...
...
check over [] GRUB密码检查中...
...
check over [] LILO密码检查中...
...
check over [] 非root账号但UID为0的用户检查中...
...
check over [] /etc/profile中umask默认值检查中...
...
check over [] /etc/csh.cshrc中umask默认值检查中...
...
check over [] /etc/bashrc中umask默认值检查中...
...
check over [] 重要文件权限检查中...
ls: cannot access /etc/xinetd.conf: No such file or directory
ls: cannot access /etc/lilo.conf: No such file or directory
...
check over [] 内核文件dump配置检查中...
* soft core
...
check over -------------------------------------------------------------------------- 扫描结果: [ X ] 口令生存周期为99999天,不符合要求,建议设置不大于90天
[ X ] 口令更改最小时间间隔为0天,不符合要求,建议设置大于等于6天
[ X ] 口令最小长度为5,不符合要求,建议设置最小长度大于等于8
[ X ] 口令过期警告时间天数为7,不符合要求,建议设置大于等于30并小于口令生存周期
[ X ] 账号超时不存在自动注销,不符合要求,建议设置小于600秒
[ √ ] 已设置grub密码,符合要求
[ √ ] lilo.conf配置文件不存在,系统可能不是通过LILO引导
[ √ ] 不存在root账号外的UID为0的异常用户
[ X ] /etc/profile文件中所设置的umask为022,不符合要求
【理论上建议设置值为027,但因系统重要程度不同请根据具体情况慎重操作,如不确定请暂忽略此项】
[ X ] /etc/csh.cshrc文件中所设置的umask为022,不符合要求
【理论上建议设置值为027,但因系统重要程度不同请根据具体情况慎重操作,如不确定请暂忽略此项】
[ X ] /etc/bashrc文件中所设置的umask为022,不符合要求
【理论上建议设置值为027,但因系统重要程度不同请根据具体情况慎重操作,如不确定请暂忽略此项】
[ √ ] /etc/passwd文件权限为644,符合要求
[ √ ] /etc/shadow文件权限为400或000,符合要求
[ √ ] /etc/group文件权限为644,符合要求
[ √ ] /etc/security文件权限为600,符合要求
[ √ ] /etc/services文件权限为644,符合要求
[ √ ] /etc/xinetd.conf文件不存在,暂略此项
[ X ] /etc/grub.conf文件权限为lrwxrwxrwx.,不符合要求,建议设置权限为600
[ √ ] /etc/lilo.conf文件不存在,暂略此项
[ √ ] 内核文件dump配置检查[* soft core ]已经设置
[ √ ] 内核文件dump配置检查[* hard core ]已经设置 --------------------------------------------------------------------------

linux安全配置检查脚本_v0.8的更多相关文章

  1. linux安全配置检查脚本_v0.5

    看到网上有人分享了一些linux系统的基线检查脚本,但有些检查项未必适合自己或者说检查的不够完善, 计划按着自己的需求重新写一份出来,其中脚本的检查范围在不断更新中. 脚本内容: [root@loca ...

  2. Linux安全基线检查脚本

    基线检查内容: 一:共享账号检查 配置名称:用户账号分配检查,避免共享账号存在配置要求:1.系统需按照实际用户分配账号; 2.避免不同用户间共享账号,避免用户账号和服务器间通信使用的账号共享.操作指南 ...

  3. 服务端测试环境hosts配置检查脚本

    [本文出自天外归云的博客园] 问题 由于A测试环境和B测试环境相互耦合,B测试环境切换导致我方测试环境需要更改后台服务器的响应配置.若多台服务器中有一台服务器没有更改配置,则在测试过程中将会出现问题. ...

  4. linux系统健康检查脚本

    #!/bin/bash echo "You are logged in as `whoami`"; if [ `whoami` != root ]; then echo " ...

  5. linux 安装配置kafka脚本

    安装脚本 #!/bin/bash # auto install kafka echo "========= Start to install kafka ==============&quo ...

  6. Linux CPU 核数检查脚本

    #!/bin/bash physicalNumber=0 coreNumber=0 logicalNumber=0 HTNumber=0 logicalNumber=$(grep "proc ...

  7. linux 安装配置zookeeper脚本

    #!/bin/bash # automatic install zookeeper echo "========= Start to install zookeeper ========== ...

  8. linux安装配置JDK脚本

    #!/bin/bash # install jdk and configuring environment variables function installjdk(){ tar -zxf jdk- ...

  9. linux各版本基线检查脚本(centos6、centos7、ubuntu系列)

    以下是centos7基线检查脚本: #!/bin/bash #version v1. by pensar #操作系统linux 配置规范--centos7 cat <<EOF ****** ...

随机推荐

  1. C#-常用知识点

    1.日期相关 获取英文月份名称 : DateTime.Now.ToString("MMMM") 1.1 各个字母所代表的意思 1.MM:月份 2.mm:分钟 3. MMMM:文字形 ...

  2. SpringBoot2使用WebFlux函数式编程

    本文只是简单使用SpringBoot2使用WebFlux的函数式编程简单使用,后续会继续写关于Webflux相关的文章. 最近一直在研究WebFlux,后续会陆续出一些相关的文章. 首先看一下Srpi ...

  3. 241. String to Integer

    描述 Given a string, convert it to an integer. * You may assume the string is a valid integer number t ...

  4. 编辑datagridview单元格

    以这3种为例,最简单的是第三种,直接让单元格处于可编辑状态,当完成编辑后触发CellEndEdit事件,最后对输入的数据进行处理. private DateTimePicker dtp = new D ...

  5. Codeforces.487C.Prefix Product Sequence(构造)

    题目链接 \(Description\) 对于一个序列\(a_i\),定义其前缀积序列为\(a_1\ \mathbb{mod}\ n,\ (a_1a_2)\ \mathbb{mod}\ n,...,( ...

  6. 2955 ACM 杭电 抢银行 01背包 乘法

    题意: 强盗抢银行,在不被抓住的情况下,想尽量多的偷点钱.已知各个银行的金钱和被抓的概率,以及强盗能容忍的最大不被抓的概率(小于等于该概率才能不被抓),求最多能抢到钱? 并不是简单的01背包问题? 1 ...

  7. python字符串与列表的相互转换

    学习内容: 1.字符串转列表 2.列表转字符串 1. 字符串转列表 s ='hello python !'li = s.split(' ') #注意:引号内有空格print (li)输出:['hell ...

  8. Wooden Sticks [POJ1065] [DP]

    Description 有N根木棍等待处理.机器在处理第一根木棍时需要准备1分钟,此后遇到长宽都不大于前一根木棍的木棍就不需要时间准备,反之则需要1分钟重新准备.比如木棍按照(3,3).(1,3).( ...

  9. TFS2017新特性(一)

    自 Team Foundation Server 2015 中引入了基于集成式 Web 的 Release Management 以来,我们在此版本中进行了几处功能增强. 克隆.导出和导入发布定义 我 ...

  10. 向json对象中添加数组

    // JSONArray jsonArray = new JSONArray();// for (int i = 0; i < list.size(); i++) {// JSONObject ...