From a5a2cf8c838d1c9c4d47a7fa66488d63fab036d3 Mon Sep 17 00:00:00 2001 From: "a869920004@163.com" Date: Wed, 16 Sep 2020 16:19:30 +0800 Subject: [PATCH] init --- LICENSE | 127 ++++ README.en.md | 36 - README.md | 37 - openEuler-security.service | 30 + security | 17 + security-tool-2.0/csh.precmd | 24 + security-tool-2.0/password-auth-crond | 45 ++ security-tool-2.0/su-local | 29 + security-tool.sh | 1004 +++++++++++++++++++++++++ security-tool.spec | 163 ++++ security.conf | 218 ++++++ usr-security.conf | 14 + 12 files changed, 1671 insertions(+), 73 deletions(-) create mode 100644 LICENSE delete mode 100644 README.en.md delete mode 100644 README.md create mode 100644 openEuler-security.service create mode 100644 security create mode 100644 security-tool-2.0/csh.precmd create mode 100644 security-tool-2.0/password-auth-crond create mode 100644 security-tool-2.0/su-local create mode 100644 security-tool.sh create mode 100644 security-tool.spec create mode 100644 security.conf create mode 100644 usr-security.conf diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9e32cde --- /dev/null +++ b/LICENSE @@ -0,0 +1,127 @@ + 木兰宽松许可证, 第2版 + + 木兰宽松许可证, 第2版 + 2020年1月 http://license.coscl.org.cn/MulanPSL2 + + + 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: + + 0. 定义 + + “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 + + “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 + + “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 + + “法人实体”是指提交贡献的机构及其“关联实体”。 + + “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 + + 1. 授予版权许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 + + 2. 授予专利许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 + + 3. 无商标许可 + + “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 + + 4. 分发限制 + + 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 + + 5. 免责声明与责任限制 + + “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + + 6. 语言 + “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 + + 条款结束 + + 如何将木兰宽松许可证,第2版,应用到您的软件 + + 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: + + 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; + + 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; + + 3, 请将如下声明文本放入每个源文件的头部注释中。 + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. + + + Mulan Permissive Software License,Version 2 + + Mulan Permissive Software License,Version 2 (Mulan PSL v2) + January 2020 http://license.coscl.org.cn/MulanPSL2 + + Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + + 0. Definition + + Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + + Contribution means the copyrightable work licensed by a particular Contributor under this License. + + Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + + Legal Entity means the entity making a Contribution and all its Affiliates. + + Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + + 1. Grant of Copyright License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + + 2. Grant of Patent License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + + 3. No Trademark License + + No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. + + 4. Distribution Restriction + + You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + + 5. Disclaimer of Warranty and Limitation of Liability + + THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + 6. Language + + THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + + END OF THE TERMS AND CONDITIONS + + How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + + To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + + i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; + + ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; + + iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. + + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 2402464..0000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# security-tool - -#### Description -A tool with scripts for reinforcing operating system security - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md deleted file mode 100644 index 9720664..0000000 --- a/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# security-tool - -#### 介绍 -A tool with scripts for reinforcing operating system security - -#### 软件架构 -软件架构说明 - - -#### 安装教程 - -1. xxxx -2. xxxx -3. xxxx - -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 码云特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 -5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/openEuler-security.service b/openEuler-security.service new file mode 100644 index 0000000..ab60920 --- /dev/null +++ b/openEuler-security.service @@ -0,0 +1,30 @@ +####################################################################################### +# +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# security-tool licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Description: Security Tool Activation Service +# +####################################################################################### + +[Unit] +Description=OpenEuler Security Tool +After=network.target sshd.service auditd.service crond.service tuned.service NetworkManager.service +Wants=sshd.service auditd.service rsyslog.service tuned.service NetworkManager.service +ConditionFileIsExecutable=/usr/sbin/security-tool.sh + +[Service] +Type=oneshot +RemainAfterExit=yes +EnvironmentFile=/etc/openEuler_security/security +ExecStart=/usr/sbin/security-tool.sh -d / -c /etc/openEuler_security/security.conf -u /etc/openEuler_security/usr-security.conf -l /var/log/openEuler-security.log -s +TimeoutSec=0 + +[Install] +WantedBy=multi-user.target diff --git a/security b/security new file mode 100644 index 0000000..a3d87ac --- /dev/null +++ b/security @@ -0,0 +1,17 @@ +####################################################################################### +# +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# security-tool licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Description: Configuration file for the openEuler-security service. +# +####################################################################################### + +OPENEULER_SECURITY=0 + diff --git a/security-tool-2.0/csh.precmd b/security-tool-2.0/csh.precmd new file mode 100644 index 0000000..ee59457 --- /dev/null +++ b/security-tool-2.0/csh.precmd @@ -0,0 +1,24 @@ +####################################################################################### +# +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# security-tool licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Description: Append the history list to the history file. +# +####################################################################################### + +set el_precmd_msg = `history 1|cut -f3-|sed -e "s|{||g" | sed -e "s|}||g"` +set el_precmd_user = `whoami` +set el_precmd_loginuser = `who -m | awk '{print $2" "$NF}'` +set el_precmd_num = `history 1| awk -F" " '{print $1}'` + +if ((${el_precmd_num} != ${LastComandNum_for_history}) && (${LastComandNum_for_history} != "" || ${el_precmd_num} == 1)) then + logger -t "[/bin/csh]" "[${el_precmd_msg}]" "by [${el_precmd_user}] from [${el_precmd_loginuser}]" > /dev/null +endif +set LastComandNum_for_history = ${el_precmd_num} diff --git a/security-tool-2.0/password-auth-crond b/security-tool-2.0/password-auth-crond new file mode 100644 index 0000000..11ddabf --- /dev/null +++ b/security-tool-2.0/password-auth-crond @@ -0,0 +1,45 @@ +####################################################################################### +# +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# security-tool licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Description: Configuration File for PAMified Services +# +####################################################################################### + +#%PAM-1.0 +# User changes will be destroyed the next time authconfig is run. +auth required pam_env.so +auth required pam_faillock.so preauth audit deny=3 even_deny_root unlock_time=60 +-auth sufficient pam_fprintd.so +auth sufficient pam_unix.so nullok try_first_pass +-auth sufficient pam_sss.so use_first_pass +auth [default=die] pam_faillock.so authfail audit deny=3 even_deny_root unlock_time=60 +auth sufficient pam_faillock.so authsucc audit deny=3 even_deny_root unlock_time=60 +auth requisite pam_succeed_if.so uid >= 1000 quiet_success +auth required pam_deny.so + +account required pam_unix.so +#account required pam_faillock.so +account sufficient pam_localuser.so +account sufficient pam_succeed_if.so uid < 1000 quiet +-account [default=bad success=ok user_unknown=ignore] pam_sss.so +account required pam_permit.so + +password requisite pam_pwquality.so try_first_pass local_users_only +password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok +-password sufficient pam_sss.so use_authtok +password required pam_deny.so + +session optional pam_keyinit.so revoke +session required pam_limits.so +-session optional pam_systemd.so +session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid +session required pam_unix.so +-session optional pam_sss.so diff --git a/security-tool-2.0/su-local b/security-tool-2.0/su-local new file mode 100644 index 0000000..9913ebd --- /dev/null +++ b/security-tool-2.0/su-local @@ -0,0 +1,29 @@ +####################################################################################### +# +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# security-tool licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Description: Configuration File for PAMified Services +# +####################################################################################### + +#%PAM-1.0 +auth sufficient pam_rootok.so +# Uncomment the following line to implicitly trust users in the "wheel" group. +#auth sufficient pam_wheel.so trust use_uid +# Uncomment the following line to require a user to be in the "wheel" group. +auth required pam_wheel.so use_uid +auth substack system-auth +auth include postlogin +account sufficient pam_succeed_if.so uid = 0 use_uid quiet +account include system-auth +password include system-auth +session include system-auth +session include postlogin +session optional pam_xauth.so diff --git a/security-tool.sh b/security-tool.sh new file mode 100644 index 0000000..c6bc4e7 --- /dev/null +++ b/security-tool.sh @@ -0,0 +1,1004 @@ +#!/bin/sh +####################################################################################### +# +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# security-tool licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# http://license.coscl.org.cn/MulanPSL +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v1 for more details. +# Description: openEuler Security Tool +# +####################################################################################### +# name of this script +readonly NAME=`basename $0` +# working directory +readonly WORKD=`pwd`/ +# the separator of fields of security configration file +readonly FIELD_SEP='@' + +# distinction +DST="" +# security configuration file +SCONF="" +# USER security configuration file +USR_SCONF="" +# File where to write log +LOGFILE="" +# flag +SILENT=0 +# execute configure item's id +EXECID=0 +# temporary target of decompress and compress +TMPTARGET="openEuler" + +# distinction type(rootfs, ar, cpio.gz) +DST_TYPE="rootfs" +# directory of decompressed rootfs +ROOTFS="" +# distinction name when it's not rootfs +AR_F="" +GZ_F="" + +############################################################################## + +#============================================================================= +# Function Name: pushd/popd +# Description : the same to standard pushd/popd except that no info printed +# Returns : 0 on success, otherwise on fail +#============================================================================= +function pushd() +{ + builtin pushd "$@" > /dev/null + return $? +} +function popd() +{ + builtin popd "$@" > /dev/null + return $? +} + +#============================================================================= +# Function Name: fn_test_params_num +# Description : test if the num of params is the right num(do not support flexible parameters), quit otherwise +# Parameter : params_num +# Returns : none +#============================================================================= +function _fn_test_params_num() +{ + if [ $# -lt 3 ] || [ $2 -ne $3 ]; then + echo "Line $1: num of params $2 not equals to $3" + exit 1 + fi +} +alias fn_test_params_num='_fn_test_params_num $LINENO $#' + +#============================================================================= +# Function Name: fn_test_type +# Description : test if the specific file type by a keyword +# Parameter : file, keyword(directory, cpio archive, gzip compressed, ar archive, ...) +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_test_type() +{ + fn_test_params_num 2 + + file "$1"| awk -F: '{print $2}' |grep "$2" >/dev/null + return $? +} + +#============================================================================= +# Function Name: fn_get_fullpath +# Description : get absolute path name of file +# Parameter : file +# Returns : fullpath +#============================================================================= +function fn_get_fullpath() +{ + fn_test_params_num 1 + + local p=$1 + local out + + if [ "${p:0:1}" = "/" ]; then + echo $p + return + fi + + pushd `dirname $p` + out=`pwd` + popd + echo $out"/"`basename $p` +} + +#============================================================================= +# Function Name: fn_escape_string +# Description : set special character(/) in the string to be escaped +# Parameter : string +# Returns : escaped string +#============================================================================= +function fn_escape_string() +{ + fn_test_params_num 1 + + echo "$1"| sed 's/\//\\\//g'| sed 's/\./\\\./g'| sed 's/\[/\\[/g'| sed 's/\]/\\]/g' | sed 's/\$/\\\$/g' | sed 's/\*/\\\*/g' +} + +#============================================================================= +# Function Name: fn_log +# Description : write a message to log file or console +# Parameter : lineno level(error, warn, info) message +# Returns : none +#============================================================================= +function fn_log() +{ + fn_test_params_num 3 + + local lno=$1 + local level=$2 + shift 2 + + if [ $SILENT -eq 0 ] || [ "$level" = "error" ]; then + output=$@ + opt=`echo $output | grep -e "success$"` + if [ $? -eq 0 ];then + output=`echo $opt | sed -r 's/success$/\\\033\\[32;1msuccess\\\033\\[0m/g'` + fi + opt=`echo $output | grep -e "fail$"` + if [ $? -eq 0 ];then + output=`echo $opt | sed -r 's/fail$/\\\033\\[31;1mfail\\\033\\[0m/g'` + fi + echo -e "[$NAME:$lno] [$level] $output" + fi + + echo "`date +%Y-%m-%d\ %H:%M:%S` [$NAME:$lno] [$level] $@" >> $LOGFILE +} +alias fn_error='fn_log $LINENO error' +alias fn_warn='fn_log $LINENO warn' +alias fn_info='fn_log $LINENO info' + +#============================================================================= +# Function Name: fn_exit +# Description : to be excuted when exit with return value(0 ok, 1 params error, 2 hardening error) +# Parameter : status(0 ok, otherwise error), [message] +# Returns : none +#============================================================================= +function fn_exit() +{ + fn_test_params_num 1 + local s=$1 + # cleanup when destination is cpio.gz + if [ "$DST_TYPE" = "tar.gz" ]; then + if [ $s -eq 0 ]; then + local new_initrd=$WORKD`basename $GZ_F`".secure" + pushd $ROOTFS + tar -cf -- "$ROOTFS/$TMPTARGET" * + gzip <"$ROOTFS/$TMPTARGET" > $new_initrd + fn_info "hardened initrd is $new_initrd" + popd + fi + + # cleanup rootfs + rm -rf $ROOTFS + fi + + # cleanup when destination is cpio.gz + if [ "$DST_TYPE" = "cpio.gz" ]; then + if [ $s -eq 0 ]; then + local new_initrd=$WORKD`basename $GZ_F`".secure" + pushd $ROOTFS + find . |cpio --quiet -co |gzip > $new_initrd + fn_info "hardened initrd is $new_initrd" + popd + fi + + # cleanup rootfs + rm -rf $ROOTFS + fi + + # cleanup when destination is ar target + if [ "$DST_TYPE" = "ar" ]; then + if [ $s -eq 0 ]; then + local new_ar=$WORKD`basename $AR_F`".secure" + cp $AR_F $new_ar + + pushd $ROOTFS + find . |cpio --quiet -co|gzip > $GZ_F + popd + ar -r $new_ar $GZ_F + if [ $? -eq 0 ]; then + fn_info "initrd.cpio.gz updated" + else + fn_error "fail to replace initrd.cpio.gz in $AR_F by $GZ_F" + fn_exit 1 + fi + + # update checksum in new ar target + rm -f checksum + ar -x $new_ar checksum + if [ -f checksum ]; then + local sum=`cksum $GZ_F | awk '{print $1}'` + sed -i "s/^initrd\.cpio\.gz.*/initrd\.cpio\.gz $sum/" checksum + ar -r $new_ar checksum + rm checksum + fn_info "checksum updated" + fi + + fn_info "finish updating, new target is $new_ar" + fi + + # cleanup initrd and rootfs + fn_info "cleanup GZ [$GZ_F] and ROOTFS [$ROOTFS]" + rm -f $GZ_F + rm -rf $ROOTFS + fi + + # log + fn_info "========exit, status is [$s]========" + exit $s +} + +#============================================================================= +# Function Name: fn_usage +# Description : print help messages to console +# Parameter : none +# Returns : none +#============================================================================= +function fn_usage() +{ + cat < "$ROOTFS/$TMPTARGET" + if [ $? -ne 0 ]; then + fn_error "fail to extract [$GZ_F] to $ROOTFS/$TMPTARGET" + fn_exit 2 + fi + + fn_test_type "$ROOTFS/$TMPTARGET" "cpio archive" + if [ $? -eq 0 ]; then + cpio --quiet -id <"$ROOTFS/$TMPTARGET" >/dev/null + if [ $? -ne 0 ]; then + fn_error "fail to extract [$GZ_F] to $ROOTFS" + fn_exit 2 + fi + if [ "$DST_TYPE" != "ar" ];then + DST_TYPE="cpio.gz" + fi + else + tar -xvf "$ROOTFS/$TMPTARGET" >/dev/null + if [ $? -ne 0 ]; then + fn_error "fail to extract [$GZ_F] to $ROOTFS" + fn_exit 2 + fi + DST_TYPE="tar.gz" + fi + rm -f "$ROOTFS/$TMPTARGET" + popd + + fn_info "pre_hardening done" +} + +#============================================================================= +# Function Name: fn_check_rootfs +# Description : examine if rootfs is a standard hiberarchy +# Parameter : none +# Returns : none +#============================================================================= +function fn_check_rootfs() +{ + for i in bin usr/bin sbin usr/sbin etc boot lib home root opt var tmp proc sys mnt + do + if [ ! -d "$ROOTFS/$i" ]; then + if [ $i == "boot" ];then + continue + fi + fn_error "[$ROOTFS] is not a standard openEuler rootfs" + fn_exit 2 + fi + done + if [ ! -d "$ROOTFS"/boot ]; then + fn_info "[$ROOTFS] is a openEuler iSula rootfs" + fi +} + +#============================================================================= +# Function Name: fn_handle_key +# Description : deal with configurations referred to key and value +# Parameter : operator, file, key, f4, f5 +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_handle_key() +{ + fn_test_params_num 5 + + local op file + op=$1 + file=$2 + + file=$ROOTFS$file + if [ ! -w "$file" ]; then + fn_warn "file [$file] not existed or writable" + return 1 + fi + + # key and value with string escaped + local key f4 f5 + key=`fn_escape_string "$3"` + f4=`fn_escape_string "$4"` + f5=`fn_escape_string "$5"` + + # to ingore the differences of key caused by blank characters + echo "$key" | egrep "^-e.*" + if [[ $? == 0 ]] + then + local grepkey="[[:blank:]]*"`echo "$key" | sed -r 's/[[:blank:]]+/[[:blank:]]\+/g'` + else + local grepkey="[[:blank:]]*"`echo $key | sed -r 's/[[:blank:]]+/[[:blank:]]\+/g'` + fi + + case "$op" in + # d@file@key + d) + grep -E "$grepkey" $file >/dev/null + if [ $? -eq 0 ]; then + # comment a line + sed -ri "s/^[^#]*$grepkey/#&/" $file + return $? + else + return 0 + fi + ;; + # m@file@key[@value] + m) + grep -E "^$grepkey" $file >/dev/null + if [ $? -eq 0 ]; then + sed -ri "s/^$grepkey.*/$key$f4/g" $file + else + # add a blank line to file because sed cannot deal with empty file by 'a' + if [ ! -s $file ]; then + echo >> $file + fi + + sed -i "\$a $key$f4" $file + fi + + return $? + ;; + # sm@file@key[@value] similar to m: strict modify on the origin position + sm) + grep -E "^$grepkey" $file >/dev/null + if [ $? -eq 0 ]; then + sed -ri "s/$key.*/$key$f4/g" $file + else + # add a blank line to file because sed cannot deal with empty file by 'a' + if [ ! -s $file ]; then + echo >> $file + fi + sed -i "\$a $key$f4" $file + fi + + return $? + ;; + # M@file@key@key2[@value2] + M) + grep -E "^$grepkey" $file >/dev/null + if [ $? -eq 0 ]; then + grep "^$grepkey.*$f4" $file >/dev/null + if [ $? -eq 0 ]; then + sed -ri "/^$grepkey/ s/$f4[^[:space:]]*/$f4$f5/g" $file + else + sed -ri "s/^$grepkey.*/&$f4$f5/g" $file + fi + + return $? + else + fn_warn "key [$key] not found in [$file]" + return 1 + fi + ;; + *) + fn_error "bad operator [$op]" + return 1 + ;; + esac +} + +#============================================================================= +# Function Name: fn_handle_command +# Description : deal with configurations referred to operations to files +# Parameter : command[option], files +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_handle_command() +{ + fn_test_params_num 2 + + local op=$1 + local files=$2 + local status=0 + + # add ROOTFS path for every file + for file in `echo "$files" | awk -v rf="$ROOTFS" '{ + for(i=1; i<=NF; i++) { + printf "%s%s\n",rf,$i + } + }'`; do + ${op} ${file} >/dev/null 2>&1 + if [ $? -ne 0 ]; then + status=1 + fi + done + unset f + + return $status +} + +#============================================================================= +# Function Name: fn_handle_cp +# Description : deal with configurations referred to operations to files +# Parameter : src_file dst_file +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_handle_cp() +{ + fn_test_params_num 2 + + src_file=$1 + dst_file=$2 + + cp -p $src_file $ROOTFS/$dst_file + if [ $? -ne 0 ]; then + return 1 + else + return 0 + fi +} + +#============================================================================= +# Function Name: fn_handle_systemctl +# Description : start or stop services +# Parameter : service_name service_status +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_handle_systemctl() +{ + fn_test_params_num 2 + + syetem_service_name=$1 + syetem_service_status=$2 + + systemctl ${syetem_service_status} ${syetem_service_name} + + return $? +} + +#============================================================================= +# Function Name: fn_handle_umask +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_handle_umask() +{ + fn_test_params_num 2 + + local target=$1 + local value=$2 + local ret=0 + + if [ "$target" == "user" ] + then + echo "umask $value" >> "$ROOTFS/etc/bashrc" + echo "umask $value" >> "$ROOTFS/etc/csh.cshrc" + for file in $(find "$ROOTFS/etc/profile.d/" -type f) + do + echo '' >> $file # 防止配置文件末尾没有换行符的情况 + echo "umask $value" >> $file + done + elif [ "$target" == "deamon" ] + then + echo "umask $value" >> "$ROOTFS/etc/sysconfig/init" + else + ret=1 + fi + + return $ret +} + +#============================================================================= +# Function Name: fn_handle_ln +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_handle_ln() +{ + fn_test_params_num 3 + + local arg=$1 + local target=$2 + local link_file=$3 + chroot $ROOTFS ln "$arg" "$target" "$link_file" + return $? +} + + +#============================================================================= +# Function Name: fn_harden_rootfs +# Description : harden the rootfs, according to configuration file +# Parameter : none +# Returns : none +#============================================================================= +function fn_harden_rootfs() +{ + fn_check_rootfs + + fn_info "---begin hardening rootfs by [$SCONF]---" + local status + local f1 f2 f3 f4 f5 f6 + + # do configuration traversal, with comments and lines starting with blankspace ignored + grep -v '^#' $SCONF| grep -v '^$'| grep -Ev '^[[:space:]]+'| while read line + do + f1=`echo "$line" | awk -F$FIELD_SEP '{print $1}'` + if [ $EXECID -ne 0 ] && [ "$EXECID" -ne "$f1" ];then + continue + fi + + if [[ $line =~ "@@" ]] + then + PRE_IFS=$IFS + IFS='@' + arr=($line) + IFS=$PRE_IFS + pos=1 + for ((i=2;i<${#arr[*]};i++)) + do + if [[ x${arr[$i]} = x ]] + then + tem="${arr[$((i-1))]}@${arr[$((i+1))]}" + i=$((i+1)) + arr[$pos]=$tem + arr[$i]=$tem + else + pos=$((pos+1)) + arr[$pos]=${arr[$i]} + fi + done + + pos=$((pos+1)) + for ((j=$pos;j<${#arr[*]};j++)) + do + arr[$j]= + done + + f2=${arr[1]} + f3=${arr[2]} + f4=${arr[3]} + f5=${arr[4]} + f6=${arr[5]} + else + f2=`echo "$line" | awk -F$FIELD_SEP '{print $2}'` + f3=`echo "$line" | awk -F$FIELD_SEP '{print $3}'` + f4=`echo "$line" | awk -F$FIELD_SEP '{print $4}'` + f5=`echo "$line" | awk -F$FIELD_SEP '{print $5}'` + f6=`echo "$line" | awk -F$FIELD_SEP '{print $6}'` + fi + + case "$f2" in + d|m|sm|M) + fn_handle_key "$f2" "$f3" "$f4" "$f5" "$f6" + status=$? + ;; + cp) + fn_handle_cp "$f3" "$f4" + status=$? + ;; + systemctl) + fn_handle_systemctl "$f3" "$f4" + status=$? + ;; + umask) + fn_handle_umask "$f3" "$f4" + status=$? + ;; + ln) + fn_handle_ln "$f3" "$f4" "$f5" + status=$? + ;; + *) + fn_handle_command "$f2" "$f3" + status=$? + ;; + esac + + if [ $status -eq 0 ]; then + fn_info "-harden [$line]: success" + else + fn_warn "-harden [$line]: fail" + fi + done + unset line + fn_info "---end hardening rootfs---" + + fn_check_rootfs +} + +#============================================================================= +# Function Name: fn_harden_usr_conf +# Description : harden the user conf, according to configuration file usr_security.conf +# Parameter : none +# Returns : none +#============================================================================= +function fn_harden_usr_conf() +{ + fn_check_rootfs + + fn_info "---begin hardening SUER CONF by [$USR_SCONF]---" + local status + local f1 f2 f3 f4 f5 f6 + + # do configuration traversal, with comments and lines starting with blankspace ignored + grep -v '^#' $USR_SCONF| grep -v '^$'| grep -Ev '^[[:space:]]+'| while read line + do + f1=`echo "$line" | awk -F$FIELD_SEP '{print $1}'` + if [ $EXECID -ne 0 ] && [ "$EXECID" -ne "$f1" ];then + continue + fi + + if [[ $line =~ "@@" ]] + then + #eval $(echo $line | awk '{split($0, filearray, "@");for(i in filearray)print "arr["i"]="filearray[i]}') +PRE_IFS=$IFS +IFS='@' + arr=($line) +IFS=$PRE_IFS + pos=1 + for ((i=2;i<${#arr[*]};i++)) + do + if [[ x${arr[$i]} = x ]] + then + tem="${arr[$((i-1))]}@${arr[$((i+1))]}" + i=$((i+1)) + arr[$pos]=$tem + arr[$i]=$tem + else + pos=$((pos+1)) + arr[$pos]=${arr[$i]} + fi + done + + pos=$((pos+1)) + for ((j=$pos;j<${#arr[*]};j++)) + do + arr[$j]= + done + + f2=${arr[1]} + f3=${arr[2]} + f4=${arr[3]} + f5=${arr[4]} + f6=${arr[5]} + else + f2=`echo "$line" | awk -F$FIELD_SEP '{print $2}'` + f3=`echo "$line" | awk -F$FIELD_SEP '{print $3}'` + f4=`echo "$line" | awk -F$FIELD_SEP '{print $4}'` + f5=`echo "$line" | awk -F$FIELD_SEP '{print $5}'` + f6=`echo "$line" | awk -F$FIELD_SEP '{print $6}'` + fi + + case "$f2" in + d|m|sm|M) + fn_handle_key "$f2" "$f3" "$f4" "$f5" "$f6" + status=$? + ;; + cp) + fn_handle_cp "$f3" "$f4" + status=$? + ;; + systemctl) + fn_handle_systemctl "$f3" "$f4" + status=$? + ;; + umask) + fn_handle_umask "$f3" "$f4" + status=$? + ;; + ln) + fn_handle_ln "$f3" "$f4" "$f5" + status=$? + ;; + *) + fn_handle_command "$f2" "$f3" + status=$? + ;; + esac + + if [ $status -eq 0 ]; then + fn_info "-harden [$line]: success" + else + fn_warn "-harden [$line]: fail" + fi + done + unset line + fn_info "---end hardening USER CONF---" + + fn_check_rootfs +} + +#============================================================================= +# Function Name: fn_harden_nouser_nogroup +# Description : Remove nouser and nogroup files +# Parameter : none +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_harden_nouser_nogroup() +{ + local option="" + local command="chown -R root.root" + local dir="" + local file="" + local dirs=`mount | awk '{ if($5!="proc" && $1!="/proc")print $3}'` + + for option in -nouser -nogroup; do + for dir in ${dirs}; do + for file in `find $dir -xdev $option`; do + fn_handle_command "$command" "$file" + done + done + done +} + +#============================================================================= +# Function Name: fn_harden_grub2 +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_harden_grub2() +{ + echo -e "cat <> /etc/grub.d/00_header + if [ -d /boot/efi/EFI/openEuler -a -d /sys/firmware/efi ]; then + grub2-mkconfig -o /boot/efi/EFI/openEuler/grub.cfg + fi +} +# Function Name: fn_harden_sysctl +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_harden_sysctl() +{ + /sbin/sysctl -p /etc/sysctl.conf +} + +#============================================================================ +# Function Name: fn_baseStripInvalidLink +# Description : removing invalidlink +#============================================================================ +function fn_baseStripInvalidLink() +{ + echo ' +#!/bin/bash + +for path in /etc /lib /lib64 /usr /var +do + find $path -type l -follow -exec ls {} \; | while read link_file + do + if [ ! -z "$(ls -l $link_file | grep -v '/boot/')" ];then + stat -L $link_file 1>/dev/null 2>&1 + [ "$?" != 0 ] && rm -f $link_file && echo "Removing invalidlink:$link_file" + fi + done +done ' > $ROOTFS/baseStripInvalidLink.sh + echo $ROOTFS + chroot $ROOTFS chmod u+x baseStripInvalidLink.sh + chroot $ROOTFS sh baseStripInvalidLink.sh + chroot $ROOTFS rm -rf baseStripInvalidLink.sh +} + +#============================================================================= +# Function Name: fn_main +# Description : main function +# Parameter : command line params +# Returns : 0 on success, otherwise on fail +#============================================================================= +function fn_main() +{ + # operator must be root + if [ `id -u` -ne 0 ]; then + echo "You must be logged in as root." + exit 1 + fi + + # parse user params + fn_parse_params "$@" + + # pre-process + fn_pre_hardening + + if [ "x${OPENEULER_SECURITY}" = "x0" ] + then + # harden rootfs + fn_harden_rootfs + + # harden grub2 + fn_harden_grub2 + + fn_harden_sysctl + + sed -i "s/^OPENEULER_SECURITY=.*$/OPENEULER_SECURITY=1/g" /etc/openEuler_security/security + elif [ "x${OPENEULER_SECURITY}" = "x1" ] + then + fn_harden_sysctl + else + echo "the value of OPENEULER_SECURITY is unexpected! please check it." + fi + + # harden user conf + fn_harden_usr_conf + + # disable the service in system start + systemctl disable openEuler-security.service + + # do cleanup and exit + fn_exit 0 +} + +# check cancel action and do cleanup +trap "echo 'canceled by user...'; fn_exit 1" INT TERM +# main entrance + +fn_main "$@" + +exit 0 + diff --git a/security-tool.spec b/security-tool.spec new file mode 100644 index 0000000..ca31514 --- /dev/null +++ b/security-tool.spec @@ -0,0 +1,163 @@ +Summary: openEuler Security Tool +Name : security-tool +Version: 2.0 +Release: 1.48 +Source0: %{name}-%{version}.tar.bz2 +Source1: security +Source2: security.conf +Source3: security-tool.sh +Source4: openEuler-security.service +Source5: usr-security.conf +License: Mulan PSL v2 +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +Requires: bash setup pam util-linux binutils sudo crontabs cronie +Requires: shadow initscripts ca-certificates openssh rsyslog dbus-daemon +Requires(post): systemd-units +Requires(preun): systemd-units +Requires(postun): systemd-units +BuildRequires: xauth + +%description +openEuler Security Tool + +%global debug_package %{nil} + +%prep +%setup -q + +%build + +%check + +%install +rm -rf $RPM_BUILD_ROOT +install -d -m0700 $RPM_BUILD_ROOT%{_sysconfdir}/openEuler_security +install -m0600 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/openEuler_security/security +install -m0400 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/openEuler_security/security.conf +install -m0600 %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/openEuler_security/usr-security.conf +install -d -m0755 $RPM_BUILD_ROOT/%{_unitdir} +install -m0644 %{SOURCE4} $RPM_BUILD_ROOT/%{_unitdir}/openEuler-security.service +install -d -m0755 $RPM_BUILD_ROOT/%{_sbindir} +install -m0500 %{SOURCE3} $RPM_BUILD_ROOT/%{_sbindir}/security-tool.sh +install -m0644 csh.precmd $RPM_BUILD_ROOT%{_sysconfdir}/csh.precmd +install -d -m0755 $RPM_BUILD_ROOT/%{_sysconfdir}/profile.d +install -d -m0755 $RPM_BUILD_ROOT/%{_sysconfdir}/pam.d +install -m0644 password-auth-crond $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/password-auth-crond +install -m0644 su-local $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/su-local + +%clean +rm -rf $RPM_BUILD_ROOT + +%pre + +%post +sed -i 's/password-auth$/password-auth-crond/g' /etc/pam.d/crond + +if [ $1 -ge 2 ] +then + sed -i 's/readonly HISTSIZE$//g' /etc/profile + sed -i 's/readonly TMOUT$//g' /etc/profile +fi + +if [ -h /etc/pam.d/su ] +then + rm -f /etc/pam.d/su +else + mv -f /etc/pam.d/su /etc/pam.d/su-bak +fi +ln -s /etc/pam.d/su-local /etc/pam.d/su + +%systemd_post openEuler-security.service +systemctl enable openEuler-security.service + +%preun +%systemd_preun openEuler-security.service +if [ $1 -eq 0 ] +then + sed -i 's/password-auth-crond$/password-auth/g' /etc/pam.d/crond +fi + +%postun +%systemd_postun_with_restart openEuler-security.service + +if [ $1 -eq 0 ] +then + + if [ -f /etc/pam.d/su-bak ] + then + mv -f /etc/pam.d/su-bak /etc/pam.d/su + fi + + if [ -f /etc/pam.d/password-auth-ac ] + then + rm -f /etc/pam.d/password-auth + ln -s /etc/pam.d/password-auth-ac /etc/pam.d/password-auth + elif [ -f /etc/pam.d/password-auth-bak ] + then + mv -f /etc/pam.d/password-auth-bak /etc/pam.d/password-auth + fi + + if [ -f /etc/pam.d/system-auth-ac ] + then + rm -f /etc/pam.d/system-auth + ln -s /etc/pam.d/system-auth-ac /etc/pam.d/system-auth + elif [ -f /etc/pam.d/system-auth-bak ] + then + mv -f /etc/pam.d/system-auth-bak /etc/pam.d/system-auth + fi +fi + +%files +%defattr(-,root,root) +%attr(0700,root,root) %dir %{_sysconfdir}/openEuler_security +%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/openEuler_security/security +%attr(0400,root,root) %config %{_sysconfdir}/openEuler_security/security.conf +%attr(0600,root,root) %config %{_sysconfdir}/openEuler_security/usr-security.conf +%attr(0644,root,root) %{_sysconfdir}/csh.precmd +%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/pam.d/password-auth-crond +%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/pam.d/su-local +%attr(0644,root,root) %{_unitdir}/openEuler-security.service +%attr(0500,root,root) %{_sbindir}/security-tool.sh + +%changelog +* Fri Jul 3 2020 openEuler Buildteam - 2.0-1.48 +- rm zzz_openEuler_history.sh + +* Fri May 29 2020 openEuler Buildteam - 2.0-1.47 +- Move -- befora path + +* Fri May 29 2020 openEuler Buildteam - 2.0-1.46 +- Do not set umask to 077 any more + +* Thu May 7 2020 openEuler Buildteam - 2.0-1.45 +- Update LICENSE of files + +* Wed Apr 29 2020 openEuler Buildteam - 2.0-1.44 +- Update LICENSE to Mulan PSL v2.0 + +* Fri Feb 21 2020 openEuler Buildteam - 2.0-1.43 +- Allow wheel group to use sudo by default + +* Wed Jan 22 2020 openEuler Buildteam - 2.0-1.42 +- Fix problems of script caused by "*" and multiple spaces + +* Wed Jan 22 2020 openEuler Buildteam - 2.0-1.41 +- Fix the problem of dbus-daemon-launch-helper's group + +* Sun Jan 12 2020 openEuler Buildteam - 2.0-1.40 +- Delete password-auth-local and system-auth-local + +* Sun Dec 29 2019 openEuler Buildteam - 2.0-1.39 +- Add copyright for su-local + +* Thu Dec 19 2019 openEuler Buildteam - 2.0-1.38 +- Delete unused infomation + +* Mon Nov 11 2019 openEuler Buildteam - 2.0-1.37 +- Modify License + +* Mon Sep 25 2019 openEuler Buildteam - 2.0-1.36 +- Add requires + +* Mon Sep 16 2019 openEuler Buildteam - 2.0-1.35 +- Package init for openEuler diff --git a/security.conf b/security.conf new file mode 100644 index 0000000..e5d39e2 --- /dev/null +++ b/security.conf @@ -0,0 +1,218 @@ +####################################################################################### +# +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# security-tool licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Description: Configuration file for the security-tool. +# +####################################################################################### + +######################################################################## +# +# HowTo: +# # delete key, and difference caused by blankspace/tab on key is ignored +# id@d@file@key +# +# # modify option: find line started with key, and get the value changed +# id@m@file@key[@value] +# +# # modify sub-option: find line started with key, and then change the value of key2 to value2(prepostive seperator should not be blank characters) in the line +# id@M@file@key@key2[@value2] +# +# # check existence of commands +# id@which@command1 [command2 ...] +# +# # execute command on the files found +# id@find@dir@condition@command +# +# # any command(with or without parameter), such as 'rm -f','chmod 700','which','touch', used to extend functions, return 0 is ok +# id@command@file1 [file2 ...] +# +# Notes: +# 1. The comment line should start with '#' +# 2. "value" related with "key" should contain prepositive separator("="," " and so on), if there is any. +# 3. When item starts with "d", "m" or "M", "file" should be a single normal file, otherwise multi-objects(separated by blankspace) are allowed. +# +######################################################################## + +######################################################################## +# SSH server settting +######################################################################## +# Set sshd Protocol version +101@m@/etc/ssh/sshd_config@Protocol @2 + +102@m@/etc/ssh/sshd_config@SyslogFacility @AUTH +102@m@/etc/ssh/sshd_config@LogLevel @VERBOSE + +103@m@/etc/ssh/sshd_config@X11Forwarding @no + +105@m@/etc/ssh/sshd_config@PubkeyAuthentication @yes +105@m@/etc/ssh/sshd_config@RSAAuthentication @yes +# Don't read the user's ~/.rhosts and ~/.shosts files +105@m@/etc/ssh/sshd_config@IgnoreRhosts @yes +105@m@/etc/ssh/sshd_config@RhostsRSAAuthentication @no + +# To disable host authentication +106@m@/etc/ssh/sshd_config@HostbasedAuthentication @no + +108@m@/etc/ssh/sshd_config@PermitEmptyPasswords @no + +109@m@/etc/ssh/sshd_config@PermitUserEnvironment @no + +# Set sshd password algorithm +110@m@/etc/ssh/sshd_config@Ciphers @aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@@openssh.com,aes256-gcm@@openssh.com,chacha20-poly1305@@openssh.com + +111@m@/etc/ssh/sshd_config@ClientAliveCountMax @0 + +# Make sshd print warning banner +112@m@/etc/ssh/sshd_config@Banner @/etc/issue.net + +# Set sshd message authentication code algorithm +113@m@/etc/ssh/sshd_config@MACs @hmac-sha2-512,hmac-sha2-512-etm@@openssh.com,hmac-sha2-256,hmac-sha2-256-etm@@openssh.com,hmac-sha1,hmac-sha1-etm@@openssh.com + +# Make sshd check file modes and ownership of the user's files and home directory before accepting login +114@m@/etc/ssh/sshd_config@StrictModes @yes + +# Set this to 'yes' to enable PAM authentication, account processing, and session processing. +115@m@/etc/ssh/sshd_config@UsePAM @yes + +# Set this to 'no', do not allowed TCP forwarding. +116@m@/etc/ssh/sshd_config@AllowTcpForwarding @no + +# Log on sftp. +117@m@/etc/ssh/sshd_config@Subsystem sftp @/usr/libexec/openssh/sftp-server -l INFO -f AUTH + +118@m@/etc/ssh/sshd_config@AllowAgentForwarding @no + +119@m@/etc/ssh/sshd_config@GatewayPorts @no + +120@m@/etc/ssh/sshd_config@PermitTunnel @no + +#CVE-2015-4000 +121@m@/etc/ssh/sshd_config@KexAlgorithms@ curve25519-sha256,curve25519-sha256@@libssh.org,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256 + +130@systemctl@sshd.service@restart + +######################################################################## +# System access and authorization +######################################################################## + +# close the kernel request debugging functionality +204@m@/etc/sysctl.conf@kernel.sysrq@=0 + +206@rm -f @/etc/motd +206@touch @/etc/motd +206@chown root:root @/etc/motd +206@chmod 644 @/etc/motd +206@m@/etc/motd@Authorized users only. All activities may be monitored and reported. +206@rm -f @/etc/issue +206@touch @/etc/issue +206@chown root:root @/etc/issue +206@chmod 644 @/etc/issue +206@m@/etc/issue@Authorized users only. All activities may be monitored and reported. +206@rm -f @/etc/issue.net +206@touch @/etc/issue.net +206@chown root:root @/etc/issue.net +206@chmod 644 @/etc/issue.net +206@m@/etc/issue.net@Authorized users only. All activities may be monitored and reported. + +208@chown root:root @/etc/crontab +208@chmod og-rwx @/etc/crontab + +209@chown root:root @/etc/cron.d +209@chmod og-rwx @/etc/cron.d + +210@chown root:root @/etc/cron.hourly +210@chmod og-rwx @/etc/cron.hourly + +211@chown root:root @/etc/cron.daily +211@chmod og-rwx @/etc/cron.daily + +212@chown root:root @/etc/cron.weekly +212@chmod og-rwx @/etc/cron.weekly + +213@chown root:root @/etc/cron.monthly +213@chmod og-rwx @/etc/cron.monthly + +214@rm -f @/etc/at.deny +214@touch @/etc/at.allow +214@chown root:root @/etc/at.allow +214@chmod og-rwx @/etc/at.allow + +215@rm -f @/etc/cron.deny +215@touch @/etc/cron.allow +215@chown root:root @/etc/cron.allow +215@chmod og-rwx @/etc/cron.allow + +#rpm initscripts drop /etc/sysconfig/init defaultly +216@touch @/etc/sysconfig/init +217@m@/etc/sysconfig/init@PROMPT=@no + +######################################################################## +# Kernel parameters +######################################################################## +# Disable IP forwarding +301@m@/etc/sysctl.conf@net.ipv4.ip_forward=@0 + +# Disable sending ICMP redirects +302@m@/etc/sysctl.conf@net.ipv4.conf.all.send_redirects=@0 +302@m@/etc/sysctl.conf@net.ipv4.conf.default.send_redirects=@0 + +# Disable IP source routing +303@m@/etc/sysctl.conf@net.ipv4.conf.all.accept_source_route=@0 +303@m@/etc/sysctl.conf@net.ipv4.conf.default.accept_source_route=@0 + +# Disable ICMP redirects acceptance +304@m@/etc/sysctl.conf@net.ipv4.conf.all.accept_redirects=@0 +304@m@/etc/sysctl.conf@net.ipv4.conf.default.accept_redirects=@0 + +# Disable ICMP redirect messages only for gateways +305@m@/etc/sysctl.conf@net.ipv4.conf.all.secure_redirects=@0 +305@m@/etc/sysctl.conf@net.ipv4.conf.default.secure_redirects=@0 + +# Disable response to broadcasts. +306@m@/etc/sysctl.conf@net.ipv4.icmp_echo_ignore_broadcasts=@1 + +# Enable ignoring bogus error responses +307@m@/etc/sysctl.conf@net.ipv4.icmp_ignore_bogus_error_responses=@1 + +# Enable route verification on all interfaces +308@m@/etc/sysctl.conf@net.ipv4.conf.all.rp_filter=@1 +308@m@/etc/sysctl.conf@net.ipv4.conf.default.rp_filter=@1 + +# Enable TCP-SYN cookie protection +309@m@/etc/sysctl.conf@net.ipv4.tcp_syncookies=@1 + +# Enable preventing normal users from getting dmesg output +310@m@/etc/sysctl.conf@kernel.dmesg_restrict=@1 + +######################################################################## +# Only Wants NetworkManager +######################################################################## +401@m@/usr/lib/systemd/system/openEuler-security.service@Wants=@NetworkManager.service + +#del SHA1 pem +402@rm -f @/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem + +#limit user environment variables when used su +403@m@/etc/login.defs@ALWAYS_SET_PATH=@yes + +#add umask 077 to /etc/csh.login +404@m@/etc/csh.login@umask@ 077 + +#disable ICMP redirects acceptance +407@m@/etc/sysctl.conf@net.ipv6.conf.all.accept_redirects=@0 +407@m@/etc/sysctl.conf@net.ipv6.conf.default.accept_redirects=@0 + +#set LOG_UNKFAIL_ENAB to no +622@m@/etc/login.defs@LOG_UNKFAIL_ENAB @no + +#fix the problem of +700@chown root:dbus @/usr/libexec/dbus-1/dbus-daemon-launch-helper +700@chmod 4750 @/usr/libexec/dbus-1/dbus-daemon-launch-helper diff --git a/usr-security.conf b/usr-security.conf new file mode 100644 index 0000000..2f5bf38 --- /dev/null +++ b/usr-security.conf @@ -0,0 +1,14 @@ +####################################################################################### +# +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# security-tool licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# http://license.coscl.org.cn/MulanPSL +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v1 for more details. +# Description: Configuration file for the usr hardening. +# +####################################################################################### -- Gitee