开发者社区> 问答> 正文

今天收到有奖,安全整改?

已解决

今天收到邮件,安全整改?让我们Linux系统整改加固。请问如何处理哦

展开
收起
1780169608831412 2021-07-27 09:16:29 833 0
1 条回答
写回答
取消 提交回答
  • 网络规划设计师、敏捷专家、CISP、ITSS服务经理、ACA全科目、ACP4项、ACE、CBP、CDSP、CZTP等。拥有 PRINCE2 Foundation/Practitioner、CCSK、ITIL、ISO27001、PMP等多项国际认证。 专利5+、期刊10+、知识产权师。核心期刊审稿人。
    采纳回答

    您好,您需要根据您实际的业务情况来对Linux进行加固,如下给你提供了5个方面您可以参考,谢谢。安全配置前,请注意做好数据备份工作。

    
    
    01 账号安全加固
    
    部分详细配置:
    修改口令生存期如下配置即可:
    [root@localhost ~]# vim /etc/login.defs
     
    # Password aging controls:
    #
    #       PASS_MAX_DAYS   Maximum number of days a password may be used.
    #     PASS_MIN_DAYS   Minimum number of days allowed between password changes.
    #       PASS_MIN_LEN    Minimum acceptable password length.
    #     PASS_WARN_AGE   Number of days warning given before a password expires.
    #
    PASS_MAX_DAYS   90      # 新建用户密码最长使用天数
    PASS_MIN_DAYS   0       # 新建用户密码最短使用天数
    PASS_MIN_LEN    7       # 新建用户密码到期提示天数
    PASS_WARN_AGE   10      # 最小密码长度
    
    设置口令复杂度:
    [root@localhost ~]# vim /etc/pam.d/system-auth
    
    #%PAM-1.0
    # This file is auto-generated.
    # User changes will be destroyed the next time authconfig is run.
     
    password    required pam_cracklib.so try_first_pass retry=3 dcredit=-1 lcredit=-1 ucredit=-1 ocredit=-1 minlen=10
    
    在上方文件中添加如下一行配置,其含义是至少包含一个数字、一个小写字母、一个大写字母、一个特殊字符、且密码长度>=10
    
    限制登录超时:
    [root@localhost ~]# vim /etc/profile
     
    TMOUT=300
    export TMOUT
    
    限制TTY尝试次数:
    [root@localhost ~]# vim /etc/pam.d/login
     
    #%PAM-1.0
    auth required  pam_tally2.so deny=3 lock_time=300 even_deny_root root_unlock_time=10
     
    [root@localhost ~]# pam_tally2 --user lyshark    查询远程登录次数
    
    修改SSH远程端口:
    [root@localhost ~]# vim /etc/ssh/sshd_config
     
    # If you want to change the port on a SELinux system, you have to tell
    # SELinux about this change.
    # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
    #
    Port 65534               # 登录端口改为65534
    MaxAuthTries=3           # 密码最大尝试次数3
     
    [root@localhost ~]# systemctl restart sshd
    [C:\Users]$ ssh root@192.168.1.30 6553
    
    禁止Root用户登录:创建一个普通用户以lyshark用户为例
    # -----------------------------------------------------------
    # 创建普通用户 lyshark
    [root@localhost ~]# useradd lyshark
    [root@localhost ~]# passwd lyshark
     
    # -----------------------------------------------------------
    # 给普通用户添加Sudo授权
    [root@localhost ~]# vim /etc/sudoers
     
    ## The COMMANDS section may have other options added to it.
    ##
    ## Allow root to run any commands anywhere
    root    ALL=(ALL)       ALL
    lyshark ALL=(ALL)       ALL
    # -----------------------------------------------------------
    # 修改ROOT用户禁止登录系统
    [root@localhost ~]# vim /etc/ssh/sshd_config
    PermitRootLogin no
     
    [root@localhost ~]# systemctl restart sshd
    
    除此之外,你可以通过指定那些被允许用来使用SSH的用户名,从而使得SSH服务更为安全。
    [root@localhost ~]# vim /etc/ssh/sshd_config
    
    AllowUsers lyshark admin          # 指定允许登录的用户
    AllowGroup lyshark admin         # 指定允许登录的用户组
    
    小提示:不要小看任何攻击者的社工和爆破能力!
    
    
    02 文件权限加固
    
    部分详细配置:
    限制GCC编译器:
    首先,你需要检查单数据包以确定其包含有哪些二进制文件。然后将这些文件全部设置为000无权限。
    [root@localhost ~]# rpm -q --filesbypkg gcc | grep "bin"
     
    [root@localhost ~]# chmod 000 /usr/bin/c89
    [root@localhost ~]# chmod 000 /usr/bin/c99
    [root@localhost ~]# chmod 000 /usr/bin/cc
    [root@localhost ~]# chmod 000 /usr/bin/gcc
    [root@localhost ~]# chmod 000 /usr/bin/gcc-*
    [root@localhost ~]# chmod 000 /usr/bin/gcc-*
    然后,单独创建一个可以访问二进制文件的编译器的组,赋予他这个组相应的权限。
    [root@localhost ~]# groupadd compilerGroup
    [root@localhost ~]# chown root:compilerGroup /usr/bin/gcc
    [root@localhost ~]# chmod 0750 /usr/bin/gcc
    至此,任何试图使用gcc的用户将会看到权限被拒绝的信息。
    
    
    03  iptables与SELinux
    
    部分详细配置:
    最小化防火墙规则:
    [root@localhost ~]# iptables -F
    [root@localhost ~]# iptables -p INPUT DROP
    
    [root@localhost ~]# iptables -I INPUT -p tcp --dport 6553 -j ACCEPT
    [root@localhost ~]# iptables -I OUTPUT -p tcp --dport 6553 -j ACCEPT
    [root@localhost ~]# iptables -A INPUT -p tcp --doprt 80 -j ACCEPT
    [root@localhost ~]# iptables -A INPUT -p tcp --dport 443 -j ACCEPT
    [root@localhost ~]# iptables-save
    
    开启SELinux:
    [root@localhost ~]# vim /etc/selinux/config
     
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=enforcing
     
    [root@localhost ~]# setenforce 1
    
    SELinux放行SSH端口:
    [root@localhost ~]# yum install -y policycoreutils-python-2.5-29.el7.x86_64
     
    [root@localhost ~]# semanage port -l | grep ssh
    ssh_port_t                     tcp      22
     
    [root@localhost ~]# semanage port -a -t ssh_port_t -p tcp 6553
     
    [root@localhost ~]# semanage port -l | grep ssh
    ssh_port_t                     tcp      6553, 22
    
    设置Web目录权限:
    [root@localhost html]# semanage fcontext -a -t httpd_sys_content_t /var/www/html/index.html
     
    [root@localhost html]# ls -Z
    -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
    
    
    04  Dokcer容器隔离
    以上的安全配置仅限于在真实机中配置,同样我们可以把Web应用放入Docker容器中,这样可以把权限牢牢地锁在笼子里,即使被非法入侵,除非有沙盒逃逸漏洞,否则的话很难逃离Docker沙盒。
    
    1.配置好阿里的Yum源,然后直接一条命令即可完成安装,安装成功后直接运行Docker。
    [root@localhost ~]# yum install -y epel-release docker
    [root@localhost ~]# systemctl restart docker
    [root@localhost ~]# systemctl enable docker
    2.在根目录创建一个/data/的文件夹,并赋予最小的权限。
    [root@localhost ~]# mkdir /data
    [root@localhost /]# chmod 444 -R /data/
    [root@localhost /]# chown -R dockerroot.dockerroot /data/
    [root@localhost ~]# echo "hello docker" > /data/index.html
    3.安装Apache服务,然后将本机的 /data/目录挂载到容器内部。
    [root@localhost ~]# docker search httpd
    [root@localhost ~]# docker pull docker.io/httpd
    [root@localhost ~]# docker run -itd -p 80:80 -v /data:/usr/local/apache2/htdocs httpd:latest
    
    小提示:还可以用docker部署一些蜜罐哦!
    
    
    05 网站安全狗配置
    安全狗可有效抵御部分SQL注入,文件上传等。
    1.首先安装依赖包。
    [root@localhost ~]#  yum install -y mlocate lsof pciutils dmidecode wget psmisc
     
    Package mlocate-0.26-8.el7.x86_64 already installed and latest version
    Package lsof-4.87-6.el7.x86_64 already installed and latest version
    Package pciutils-3.5.1-3.el7.x86_64 already installed and latest version
    Package 1:dmidecode-3.1-2.el7.x86_64 already installed and latest version
    Package wget-1.14-18.el7_6.1.x86_64 already installed and latest version
    Nothing to do
    2.下载并安装网站安全狗,这里安全狗和SELinux有些冲突,需要暂时关闭SeLinux。
    [root@localhost ~]# wget http://download.safedog.cn/safedog_linux64.tar.gz
    [root@localhost ~]# tar -xzvf safedog_linux64.tar.gz
    [root@localhost ~]# cd safedog_an_linux64_2.8.21207/
    [root@localhost safedog_an_linux64_2.8.21207]# chmod +x install.py
    [root@localhost safedog_an_linux64_2.8.21207]# ./nstall.py
    3.登录并启动安全狗。
    [root@localhost ~]# sdcloud -u 注册用户名 -p 密码
    [root@localhost ~]# sdui
    [root@localhost ~]# sdstart
    
    2021-07-27 09:51:08
    赞同 2 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
钉钉教育,停课不停学 立即下载
直达客户 贴身服务——通信在快递场景中的应用 立即下载
从此爱上开会 云投屏和视频会议系统提升会议体验和效率 立即下载