项目安全等保测评加固手册_服务器未设置暗码复杂度战略,未定期更换口令

[复制链接]
发表于 2026-2-5 20:40:08 | 显示全部楼层 |阅读模式

文章目次



  • 前言
  • 一、服务器侧等保测评项目及加固


    • 1、服务器未启用暗码长度以及口令复杂度、且未定期更新口令
    • 2、服务器未限定非法登录次数,未设置登录毗连超时主动退出
    • 3、服务器只采取暗码技能对用户的身份举行辨别,未采取双因子认证;服务器未限定管理终端登录
    • 4、Rc3.d文件权限过大755
    • 5、未有第三方审计体系,未对审计记载举行定期备份
    • 6、服务器未安装杀毒

  • 二、MySql数据库等保加固


    • 1、采取用户名+口令举行身份辨别,未启用口令复杂度战略,未定期更换口令
    • 2、未启用登录失败处置处罚功能,未有登录毗连超时退出战略
    • 3、采取用户名+口令验证码举行身份辨别,未实现使用两种或两种以上组合辨别技能举行身份辨别,未实现双因子登录;未对接入方式或网络地点范围举行限定且网络不可控
    • 4、未实现管理用户的最小权限分离
    • 5、未有加密技能包管数据在传输过程中的完备性;
    • 6、未定期举行数据备份规复测试功能

  • 三、中央件版本过低产生的各种毛病


    • 1、nginx毛病示例及修复

  • 四、Harbor 访问控制错误毛病
  • 五、Swagger API 未授权访问毛病
  • 六、服务器常见安全加固脚天职享
  • 总结

前言

安全品级测评的目标是通过对目标体系在安全技能及管理方面的测评,对目标体系的安全技能状态及安全管理状态做出开端判断,给出目标体系在安全技能及安全管理方面与其相应安全品级掩护要求之间的差距。测评结论作为委托方进一步美满体系安全战略及安全技能防护步伐依据

一、服务器侧等保测评项目及加固

1、服务器未启用暗码长度以及口令复杂度、且未定期更新口令

  1.         整改建议:
  2.                 建议修改密码长度、口令复杂度以及定期90天更换口令。
  3.                
  4.         整改方法:
  5.                 logindefs(){
  6.                   echo "---口令生存期---"
  7.                   cp -p /etc/login.defs /etc/login.defs_bak
  8.                   sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/g' /etc/login.defs
  9.                   sed -i 's/^PASS_MIN_DAYS.*/PASS_MIN_DAYS 10/g' /etc/login.defs
  10.                   sed -i 's/^PASS_WARN_AGE.*/PASS_WARN_AGE 7/g' /etc/login.defs
  11.                 }
  12.                 system_auth_crack(){
  13.                   echo "---口令复杂度及密码长度---"
  14.                   # 判断 system-auth 配置文件中是否包含 password requisite pam_cracklib.so 的配置
  15.                   if grep -q 'password requisite pam_cracklib.so' /etc/pam.d/system-auth; then
  16.                   # 如果有,则使用 sed 命令替换原有的行
  17.                         sed -i 's/^password.*requisite.*pam_cracklib.so$/& try_first_pass retry=3 dcredit=-1 lcredit=-1 ucredit=-1 ocredit=-1 minlen=8/g' /etc/pam.d/system-auth
  18.                   else
  19.                     # 如果没有,则添加新的一行
  20.                        echo "password requisite  pam_cracklib.so try_first_pass retry=3 dcredit=-1 lcredit=-1 ucredit=-1 ocredit=-1 minlen=8" >> /etc/pam.d/system-auth
  21.                   fi
  22.                 }
复制代码
2、服务器未限定非法登录次数,未设置登录毗连超时主动退出

  1.         整改建议:
  2.                 建议限制非法登录次数;设置登录连接超时自动退出,如:连续登录3次锁定10分钟,并无操作10分钟自动退出。
  3.        
  4.         整改方法:
  5.                 login_timeout(){
  6.                           # 检查 /etc/profile 文件是否存在
  7.                         if [ ! -f /etc/profile ]; then
  8.                           echo "/etc/profile 文件不存在"
  9.                           exit 1
  10.                         fi
  11.                        
  12.                         # 使用 sed 命令检查文件末尾是否已经存在所需的两行内容,不存在则添加
  13.                         if ! grep -q '^TMOUT=' /etc/profile; then
  14.                           echo 'TMOUT=300' >> /etc/profile
  15.                         else
  16.                           sed -i 's/^TMOUT=.*/TMOUT=300/' /etc/profile
  17.                         fi
  18.                        
  19.                         if ! grep -q '^export TMOUT' /etc/profile; then
  20.                           echo 'export TMOUT' >> /etc/profile
  21.                         fi
  22.         }
复制代码
3、服务器只采取暗码技能对用户的身份举行辨别,未采取双因子认证;服务器未限定管理终端登录

  1.         整改建议:
  2.                 服务器只采用密码技术对用户的身份进行鉴别,未采用双因子认证。
  3.                 因为维护的项目都是通过vpn(短信验证)-->堡垒机堡垒机(短信验证)-->登录服务器,最后沟通这项可以按如下修复。即服务器配置ssh白名单,只允许堡垒机堡垒机登录
  4.        
  5.         整改方法:
  6.                 vim /etc/hosts.deny #添加以下配置
  7.                 sshd:all:deny
  8.                 vim /etc/hosts.allow #添加以下配置
  9.                 sshd:堡垒机堡垒机IP:allow
复制代码
4、Rc3.d文件权限过大755

  1.         整改建议:
  2.                 建议修改rc3.d的读写权限为755以下
  3.        
  4.         整改方法:
  5.                 chmod 644  -R /etc/rc.d/rc3.d
复制代码
5、未有第三方审计体系,未对审计记载举行定期备份

  1.         整改建议:
  2.                 未有第三方审计系统,未对审计记录进行定期备份;
  3.         整改方法:
  4.                 1、服务器开启audit服务
  5.                 2、使用aidutctl -l命令查看审计策略
  6.                 3、使用auditctl -w 路径/文件 -p 权限 命令对文件或目录配置审计策略
  7.                    补充: 使用auditctl -W 路径/文件 -p 权限 命令是取消审计策略
  8.                 4、使用ausearch -f 配置的路径/文件  查看对应的审计日志日志
  9.                 5、使用AuditLogSync.py脚本+ip_address.txt文件实现将全部服务器的audit.log日志日志备份并同步到日志日志归档服务器。脚本如下所示
  10.                 6、在日志归档服务器配置定时同步,即可
  11.                         [root@LogArchive]# crontab -e
  12.                                 * */23 * * *  /usr/bin/python3 -W ignore /path/AuditLogSync.py
复制代码
  1.     #!/usr/bin/env python3
  2.         #Date: 202403212005
  3.         import os
  4.         import time
  5.         import paramiko
  6.         import logging
  7.         from datetime import datetime
  8.         import threading
  9.         import inspect
  10.        
  11.        
  12.         class AuditLogSync:
  13.             def __init__(self, ip_file,audit_path,username,password,port):
  14.                 """
  15.                 初始化AuditLogSync类
  16.        
  17.                 Parameters:
  18.                 ip_file (str): 包含IP地址列表的文件路径
  19.                 audit_path (str): 审计日志路径
  20.                 username (str): 用户名
  21.                 password (str): 密码
  22.                 port    (int):  端口
  23.                 """
  24.                 self.ip_file = ip_file
  25.                 self.audit_path=audit_path
  26.                 self.username = username
  27.                 self.password = password
  28.                 self.port = port
  29.                 #生成日期
  30.                 self.current_time = datetime.now().strftime("%Y%m%d")
  31.                 #生成审计日志归档目录
  32.                 self.export_dir = f"/export/AuditLogSync/{self.current_time}"
  33.                 #生成执行日志
  34.                 self.info_log_file = "/export/AuditLogSync/sync_info.log"
  35.                 self.error_log_file = "/export/AuditLogSync/sync_error.log"
  36.                  # 设置 info 日志记录器
  37.                 self.info_logger = logging.getLogger('info_logger')
  38.                 info_handler = logging.FileHandler(self.info_log_file)
  39.                 info_handler.setLevel(logging.INFO)
  40.                 info_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
  41.                 info_handler.setFormatter(info_formatter)
  42.                 self.info_logger.addHandler(info_handler)
  43.                 self.info_logger.setLevel(logging.INFO)
  44.                 # 设置 error 日志记录器
  45.                 self.error_logger = logging.getLogger('error_logger')
  46.                 error_handler = logging.FileHandler(self.error_log_file)
  47.                 error_handler.setLevel(logging.ERROR)
  48.                 error_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
  49.                 error_handler.setFormatter(error_formatter)
  50.                 self.error_logger.addHandler(error_handler)
  51.                 #判断审计日志归档目录是否存在
  52.                 if not os.path.exists(self.export_dir):
  53.                     os.makedirs(self.export_dir)
  54.             
  55.             def run_operations(self):
  56.                 """
  57.                 运行一系列操作:连接到服务器,打包日志文件,执行rsync同步
  58.                 """
  59.                 # 从文件中读取IP地址列表
  60.                 with open(self.ip_file, 'r') as file:
  61.                     ip_addresses = file.readlines()
  62.                 threads= []
  63.                 # 拿到ip地址调用连接服务器方法
  64.                 for ip_address in ip_addresses:
  65.                     ip_address = ip_address.strip()
  66.                     # 创建线程并启动,不采用多线程容易卡死
  67.                     thread = threading.Thread(target=self.process_server, args=(ip_address,))
  68.                     threads.append(thread)
  69.                     thread.start()
  70.                     #ssh_client = self.connect_to_server(ip_address)
  71.                     #判断服务器连接是否成功,如果成功调用打包审计日志方法、执行rsync同步方法,最后关闭连接
  72.                     #if ssh_client is not None:
  73.                     #    self.package_logs(ssh_client, ip_address)
  74.                     #    self.execute_rsync(ssh_client, ip_address)
  75.                     #    ssh_client.close()
  76.                 # 等待所有线程完成
  77.                 for thread in threads:
  78.                     thread.join()
  79.             def process_server(self, ip_address):
  80.                 """
  81.                 处理单个服务器的操作
  82.                 """
  83.                 ssh_client = self.connect_to_server(ip_address)
  84.                 #判断服务器连接是否成功,如果成功调用打包审计日志方法、执行rsync同步方法,最后关闭连接
  85.                 if ssh_client is not None:
  86.                     self.package_logs(ssh_client, ip_address)
  87.                     self.execute_rsync(ssh_client, ip_address)
  88.                     ssh_client.close()
  89.             def connect_to_server(self, ip_address):
  90.                 """
  91.                 建立SSH连接到远程服务器
  92.        
  93.                 Parameters:
  94.                 ip_address (str): 目标服务器的IP地址
  95.        
  96.                 Returns:
  97.                 paramiko.SSHClient: SSH客户端对象
  98.                 """
  99.                 ssh_client = paramiko.SSHClient()
  100.                 ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  101.        
  102.                 try:
  103.                     ssh_client.connect(ip_address, username=self.username, password=self.password, port=self.port,timeout=20)
  104.                     self.info_logger.info(f"成功连接到服务器 {ip_address} - {inspect.currentframe().f_code.co_name}")
  105.                 except paramiko.ssh_exception.AuthenticationException:
  106.                     self.error_logger.error(f"连接服务器失败 {ip_address}. 请检查服务器信息是否正确 - {inspect.currentframe().f_code.co_name}")
  107.                     return None
  108.        
  109.                 return ssh_client
  110.        
  111.             def package_logs(self, ssh_client, ip_address):
  112.                 """
  113.                 打包远程服务器上的日志文件
  114.        
  115.                 Parameters:
  116.                 ssh_client (paramiko.SSHClient): SSH客户端对象
  117.                 ip_address (str): 目标服务器的IP地址
  118.                 """
  119.                 check_dir_cmd = f"""
  120.                 if [ -d {self.audit_path} ]; then
  121.                     echo 'Directory exists'
  122.                 else
  123.                    echo 'Directory does not exist'
  124.                 fi
  125.               """
  126.                 stdin, stdout, stderr = ssh_client.exec_command(check_dir_cmd)
  127.                 dir_check_output = stdout.read().decode('utf-8')
  128.                 if "Directory exists" in dir_check_output:
  129.                    self.info_logger.info(f"{ip_address}: 审计日志目录 {self.audit_path} 存在 - {inspect.currentframe().f_code.co_name}")
  130.                    tar_cmd = f"cd {self.audit_path} && tar -zcf /tmp/{ip_address}_{self.current_time}_audit.tar.gz ."
  131.                    stdin, stdout, stderr = ssh_client.exec_command(tar_cmd)
  132.                    exit_status = stdout.channel.recv_exit_status()
  133.                 
  134.                    # 判断打包是否成功
  135.                    if exit_status == 0:
  136.                       self.info_logger.info(f"{ip_address}: 审计日志打包成功 - {inspect.currentframe().f_code.co_name}")
  137.                    else:
  138.                       self.error_logger.error(f"{ip_address}: 审计日志打包失败 - {stderr.read().decode('utf-8')} - {inspect.currentframe().f_code.co_name}")
  139.                 else:
  140.                    self.error_logger.error(f"{ip_address}: 审计日志目录 {self.audit_path} 不存在 - {inspect.currentframe().f_code.co_name}")
  141.             def execute_rsync(self, ssh_client, ip_address):
  142.                 """
  143.                 执行rsync同步操作
  144.        
  145.                 Parameters:
  146.                 ssh_client (paramiko.SSHClient): SSH客户端对象
  147.                 ip_address (str): 目标服务器的IP地址
  148.                 """
  149.                 rsync_check_cmd = "which rsync"
  150.                 stdin, stdout, stderr = ssh_client.exec_command(rsync_check_cmd)
  151.                 #调试
  152.                 #print(f"execute_rsync_stdout: {stdout.read().decode('utf-8')}")
  153.                 if "rsync" not in stdout.read().decode('utf-8'):
  154.                     install_rsync_cmd = "yum -y install rsync"
  155.                     ssh_client.exec_command(install_rsync_cmd)
  156.                     #安装rsync命令可能需要20s左右
  157.                     self.info_logger.info(f"{ip_address}: 安装rsync中,请等待... - {inspect.currentframe().f_code.co_name}")
  158.                     time.sleep(20)
  159.                     # 再次检查rsync命令是否安装成功
  160.                     stdin, stdout, stderr = ssh_client.exec_command(rsync_check_cmd)
  161.                     if "rsync" not in stdout.read().decode('utf-8'):
  162.                         self.error_logger.error(f"{ip_address} 安装rsync失败 - {inspect.currentframe().f_code.co_name}")
  163.                         return
  164.                 # 已经安装rsync,执行目标服务器的操作
  165.                 rsync_cmd = f"rsync -az -e 'ssh -p {self.port}' {self.username}@{ip_address}:/tmp/{ip_address}_{self.current_time}_audit.tar.gz {self.export_dir}"
  166.                 os.system(rsync_cmd)
  167.                 self.info_logger.info(f"{ip_address}: 审计日志压缩包同步成功 - {inspect.currentframe().f_code.co_name}")
  168.                 # 删除远程服务器上的tar包
  169.                 delete_tar_cmd = f"rm /tmp/{ip_address}_{self.current_time}_audit.tar.gz"
  170.                 ssh_client.exec_command(delete_tar_cmd)
  171.                 self.info_logger.info(f"{ip_address}: 成功删除远程服务器上的tar包 - {inspect.currentframe().f_code.co_name}")
  172.          
  173.             def delete_old_archive_logs(self, ssh_client):
  174.                 # 删除旧归档日志目录方法
  175.                 check_archive_cmd = f"find /export/AuditLogSync/ -mindepth 1 -maxdepth 1  -type d -mtime +7"
  176.                 stdin, stdout, stderr = ssh_client.exec_command(check_archive_cmd)
  177.                 old_archive_dirs = stdout.read().decode('utf-8').splitlines()
  178.                 
  179.                 for old_dir in old_archive_dirs:
  180.                     delete_cmd = f"rm -rf {old_dir}"
  181.                     _, stderr, _ = ssh_client.exec_command(delete_cmd)
  182.                     error = stderr.read().decode('utf-8')
  183.                     if error:
  184.                        self.error_logger.error(f"xx.xx.xx.xx 删除旧归档日志目录失败: {error} - {inspect.currentframe().f_code.co_name}")
  185.                     else:
  186.                        self.info_logger.info("xx.xx.xx.xx 没有7天前旧归档日志目录")
  187.         # 使用AuditLogSync类来运行操作,程序执行入口
  188.         if __name__ == '__main__':
  189.             auditLogSync = AuditLogSync("/export/AuditLogSync/ip_addresses.txt","/var/log/audit",'root','Dcn763#+',822)
  190.             auditLogSync.run_operations()
  191.             ssh_client = auditLogSync.connect_to_server("xx.xx.xx.xx")
  192.             if ssh_client is not None:
  193.                 auditLogSync.info_logger.info(f"成功连接服务器 xx.xx.xx.xx")
  194.                 auditLogSync.delete_old_archive_logs(ssh_client)
  195.                 ssh_client.close()
复制代码
6、服务器未安装杀毒

  1.         整改建议:
  2.                 建议服务器安装杀毒程序,并提供最新病毒库版本
  3.        
  4.         整改方法:
  5.                 找服务器厂商协助安装杀毒软件(商业版),一般是深信服EDR防护
复制代码
二、MySql数据库等保加固

此处mysql版本是5.7.32,别的版本请DBA判断是否能用以下设置;而且设置后不要立刻重启数据库,发起跟项目侧和客户约定业务低峰期举行重启操纵,肯定要得到客户侧的同意再实验重启操纵
1、采取用户名+口令举行身份辨别,未启用口令复杂度战略,未定期更换口令

  1.         整改建议:
  2.                 建议配置数据库口令复杂度策略,如口令长度至少8位以上且包含大写字母、小写字母、数字三种字符类型中至少两种组成
  3.        
  4.         整改方法:
  5.                 1、检查mysql是否已安装validate_password插件
  6.                         登录mysql,执行以下命令:
  7.                                 mysql> show plugins;
  8.                 2、如果未安装该插件,执行以下命令进行安装:
  9.                         mysql>INSTALL PLUGIN validate_password SONAME 'validate_password.so';
  10.                 3、my.cnf添加以下配置
  11.                     plugin-load-add=validate_password.so
  12.                         validate_password_check_user_name     =  ON
  13.                         validate_password_length              =  8
  14.                         validate_password_mixed_case_count     = 1
  15.                         validate_password_number_count         = 1
  16.                         validate_password_policy               = medium
  17.                         validate_password_special_char_count   = 1
复制代码
2、未启用登录失败处置处罚功能,未有登录毗连超时退出战略

  1.         整改建议:
  2.                 建议配置登录失败处理及登录连接超时退出策略;(如登录失败5次锁定账户20分钟,登录连接超时30分钟自动退出)
  3.        
  4.         整改方法:
  5.                 my.cnf添加以下配置
  6.                 #登录失败次数限制
  7.                 max_connect_errors = 5
  8.                 #登录连接超时退出策略
  9.                 interactive_timeout = 1800  # 将交互式客户端的超时时间设置为 1800 秒(30 分钟)
  10.                 wait_timeout = 1800  # 将非交互式客户端的超时时间设置为 1800 秒(30 分钟)
复制代码
3、采取用户名+口令验证码举行身份辨别,未实现使用两种或两种以上组合辨别技能举行身份辨别,未实现双因子登录;未对接入方式或网络地点范围举行限定且网络不可控

  1.         整改建议:
  2.                 服务器只采用密码技术对用户的身份进行鉴别,未采用双因子认证。
  3.                 因为维护的项目都是通过vpn(短信验证)-->堡垒机(短信验证)-->登录服务器,最后沟通这项可以按如下修复。即服务器配置ssh白名单,只允许堡垒机登录
  4.        
  5.         整改方法:
  6.                 vim /etc/hosts.deny #添加以下配置
  7.                 sshd:all:deny
  8.                 vim /etc/hosts.allow #添加以下配置
  9.                 sshd:堡垒机IP:allow
复制代码
4、未实现管理用户的最小权限分离

  1.         整改建议:
  2.                 建议创建系统管理员、审计管理员、安全管理员并划分各管理员所需管理的最小权限,实现管理用户的三权分离
  3.        
  4.         整改方法:
  5.                 创建系统管理员(root) 审计管理员(audit) 安全管理员(secure)并分配对应权限
复制代码
5、未有加密技能包管数据在传输过程中的完备性;

  1.         整改建议:
  2.                 建议采用加密技术或密码技术保证重要数据在传输过程中的完整性
  3.        
  4.         整改方法:
  5.                 my.cnf添加以下配置
  6.             require_secure_transport=ON
复制代码
6、未定期举行数据备份规复测试功能

  1.         整改建议:
  2.                 建议重要数据进行本地数据备份与恢复功能
  3.                
  4.         整改方法:
  5.                 添加mysql_backup_3306.py全量备份脚本,定时备份,并进行恢复测试
  6.                 crontab -e
  7.                 * */23 * * * /usr/bin/python /path/mysql_backup_3306.py  IP  PORT
复制代码
三、中央件版本过低产生的各种毛病

此处就不挨个展示中央件干系的毛病了,就拿nginx的毛病作为示例,别的中央件的修复方法都与此处划一
1、nginx毛病示例及修复

  1.         漏洞示例:
  2.                 nginx 安全漏洞(CVE-2021-23017)
  3.                 nginx 缓冲区错误漏洞(CVE-2022-41741)
  4.                 nginx 越界写入漏洞(CVE-2022-41742)
  5.                 Nginx 信任管理问题漏洞(CVE-2021-3618)
  6.                 NGINX 环境问题漏洞(CVE-2019-20372)
  7.                
  8.         漏洞修复方法:
  9.                 采用iptables规则或firewalld规则进行修复。我比较熟练iptables规则,因此采用iptables
  10.                
  11.                 只允许指定的源IP地址、源网段地址、127.0.0.1访问nginx暴露出来的端口,拒绝其余网段/ip地址的访问
  12.                 iptables -A INPUT -s 10.x.xx.0/24  -p tcp -m multiport --dports 80,8999 -j ACCEPT
  13.                 iptables -A INPUT -s 172.xx.xx.0/24  -p tcp -m multiport --dports 80,8999 -j ACCEPT
  14.                 iptables -A INPUT -s 127.0.0.1 -p tcp -m multiport --dports 80,8999 -j ACCEPT
  15.                 iptables -A INPUT -p tcp  -m multiport --dports 80,8999 -j DROP
  16.        
  17.         注意事项:
  18.                 1、为什么中间件漏洞通过IPtables规则进行修复?
  19.                         因为随着项目再交付期的稳定运行,客户侧已开始学习使用系统,如果升级中间件版本,后端微服务代码可能也涉及到需要更改,更改后也并不一定能保证系统平稳运行,耗时巨大,成功率不敢保证100%。一般情况下客户侧也是不同意升级版本的。如果客户侧强烈要求升级版本,那只能自求多福写升级方案并演练,演练通过后再上生产。
  20.                 2、其余中间件的修复方法亦是如此,只需要确定好哪些IP地址方法该中间件端口,然后添加规则就行。
复制代码
四、Harbor 访问控制错误毛病

  1.         整改建议:
  2.                 1、升级harbor版本
  3.                 2、将harbor中公开的仓库全部设置为私有仓库,给pod的yaml文件中配置镜像拉取策略即可 #推荐方法2
复制代码

五、Swagger API 未授权访问毛病

  1.         整改建议:
  2.                 结合SpringSecurity/shiro进行认证授权,将Swagger-UI的URLs加入到各自的认证和授权过滤链中,当用户访问Swagger对应的资源时,只有通过认证授权的用户才能进行访问
  3.        
  4.         整改方法:
  5.                 拉通研发,进行处理即可
复制代码
六、服务器常见安全加固脚天职享

一个简单的shell脚本,包罗了服务器暗码、毗连超时、文件权限、服务器汗青下令等方面的加固
  1. #!/bin/bash
  2. #linux脆弱性加固脚本
  3. system_auth(){
  4.   echo "---口令锁定策略---"
  5.   cp -p /etc/pam.d/system-auth /etc/pam.d/system-auth_bak
  6.   if grep -q 'auth required pam_tally2.so' /etc/pam.d/system-auth;then
  7.      sed -i 's/^auth.*required.*pam_tally2.so$/&\nauth required pam_tally2.so deny=3 unlock_time=600 even_deny_root root_unlock_time=10/g' /etc/pam.d/system-auth
  8.   else
  9.      echo "auth required pam_tally2.so deny=3 unlock_time=600 even_deny_root root_unlock_time=10" >> /etc/pam.d/system-auth
  10.   fi  
  11.   
  12.   if grep -q 'account required pam_tally2.so' /etc/pam.d/system-auth;then
  13.      sed -i 's/^account.*required.*pam_tally2.so$/&\n/g' /etc/pam.d/system-auth
  14.   else
  15.      echo "account required pam_tally2.so" >> /etc/pam.d/system-auth
  16. fi
  17. }
  18. logindefs(){
  19.   echo "---口令生存期---"
  20.   cp -p /etc/login.defs /etc/login.defs_bak
  21.   sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/g' /etc/login.defs
  22.   sed -i 's/^PASS_MIN_DAYS.*/PASS_MIN_DAYS 10/g' /etc/login.defs
  23.   sed -i 's/^PASS_WARN_AGE.*/PASS_WARN_AGE 7/g' /etc/login.defs
  24. }
  25. system_auth_crack(){
  26.   echo "---口令复杂度---"
  27.   # 判断 system-auth 配置文件中是否包含 password requisite pam_cracklib.so 的配置
  28.   if grep -q 'password requisite pam_cracklib.so' /etc/pam.d/system-auth; then
  29.   # 如果有,则使用 sed 命令替换原有的行
  30.         sed -i 's/^password.*requisite.*pam_cracklib.so$/& try_first_pass retry=3 dcredit=-1 lcredit=-1 ucredit=-1 ocredit=-1 minlen=8/g' /etc/pam.d/system-auth
  31.   else
  32.     # 如果没有,则添加新的一行
  33.        echo "password requisite  pam_cracklib.so try_first_pass retry=3 dcredit=-1 lcredit=-1 ucredit=-1 ocredit=-1 minlen=8" >> /etc/pam.d/system-auth
  34.   fi
  35. }
  36. file_contro(){
  37.   echo "文件与目录缺省权限控制"
  38.   cp  -p /etc/profile /etc/profile.bak
  39.   if grep -q 'umask 027' /etc/profile;then
  40.     echo "已存在umask 027"
  41.   else
  42.     echo "umask 027" >>/etc/profile
  43.   source /etc/profile
  44. }
  45. user_control(){
  46.     chmod 644 /etc/passwd
  47.     chmod 400 /etc/shadow
  48.     chmod 644 /etc/group
  49.     chmod 644 /etc/services
  50.     chmod 600 /etc/xinetd.conf
  51.     chmod 600 /etc/security
  52.     chattr +a /var/log/messages  
  53. }
  54. security_log(){
  55.   filename="/var/adm/messages"
  56.   if [ -e "${filename}" ]; then
  57.     chmod 666 /var/adm/messages
  58.     /etc/init.d/rsyslog restart
  59. else
  60.    touch ${filename}
  61.    chmod 666 /var/adm/messages
  62.    echo " *.err;kern.debug;daemon.notice /var/adm/messages" >> /etc/rsyslog.conf
  63.    /etc/init.d/rsyslog restart
  64. fi
  65. }
  66. login_timeout(){
  67.   # 检查 /etc/profile 文件是否存在
  68. if [ ! -f /etc/profile ]; then
  69.   echo "/etc/profile 文件不存在"
  70.   exit 1
  71. fi
  72. # 使用 sed 命令检查文件末尾是否已经存在所需的两行内容,不存在则添加
  73. if ! grep -q '^TMOUT=' /etc/profile; then
  74.   echo 'TMOUT=300' >> /etc/profile
  75. else
  76.   sed -i 's/^TMOUT=.*/TMOUT=300/' /etc/profile
  77. fi
  78. if ! grep -q '^export TMOUT' /etc/profile; then
  79.   echo 'export TMOUT' >> /etc/profile
  80. fi
  81. }
  82. history_set(){
  83. # 检查 /etc/profile 文件是否存在
  84. if [ ! -f /etc/profile ]; then
  85.   echo "/etc/profile 文件不存在"
  86.   exit 1
  87. fi
  88. # 使用 sed 命令检查文件中是否已经存在所需的两行内容,不存在则添加上去
  89. if ! grep -q '^HISTFILESIZE=' /etc/profile; then
  90.   echo 'HISTFILESIZE=5' >> /etc/profile
  91. else
  92.   sed -i 's/^HISTFILESIZE=.*/HISTFILESIZE=5/' /etc/profile
  93. fi
  94. if ! grep -q '^HISTSIZE=' /etc/profile; then
  95.   echo 'HISTSIZE=5' >> /etc/profile
  96. else
  97.   sed -i 's/^HISTSIZE=.*/HISTSIZE=5/' /etc/profile
  98. fi
  99. # 让配置生效
  100. source /etc/profile
  101. }
  102. core_dump(){
  103. # 检查 /etc/security/limits.conf 文件是否存在
  104. if [ ! -f /etc/security/limits.conf ]; then
  105.   echo "/etc/security/limits.conf 文件不存在"
  106.   exit 1
  107. fi
  108. # 使用 sed 命令检查文件末尾是否已经存在所需的两行内容
  109. if ! grep -q '^\*\s\+soft\s\+core\s\+0$' /etc/security/limits.conf; then
  110.   echo '* soft core 0' >> /etc/security/limits.conf
  111. else
  112.   sed -i 's/^\(\*\s\+soft\s\+core\s\+\).*/\10/' /etc/security/limits.conf
  113. fi
  114. if ! grep -q '^\*\s\+hard\s\+core\s\+0$' /etc/security/limits.conf; then
  115.   echo '* hard core 0' >> /etc/security/limits.conf
  116. else
  117.   sed -i 's/^\(\*\s\+hard\s\+core\s\+\).*/\10/' /etc/security/limits.conf
  118. fi
  119. # 检查 /etc/profile 文件是否存在
  120. if [ ! -f /etc/profile ]; then
  121.   echo "/etc/profile 文件不存在"
  122.   exit 1
  123. fi
  124. # 使用 grep 命令检查文件中是否存在指定内容,同时注释掉对应的行
  125. if grep -q 'ulimit\s\+-S\s\+-c\s\+0\s\+>\s\+\/dev\/null\s\+2>&1' /etc/profile; then
  126.   sed -i 's/^ulimit\s\+-S\s\+-c\s\+0\s\+>\s\+\/dev\/null\s\+2>&1/#&/' /etc/profile
  127. fi
  128. }
  129. system_auth
  130. logindefs
  131. system_auth_crack
  132. file_contro
  133. user_control
  134. security_log
  135. login_timeout
  136. history_set
  137. core_dump
复制代码

总结

以上就是关于常见的等保测评项及加固方法,后期碰到新的测评项及加固方法会随时更新,渴望能对各人起到资助作用,也渴望各人能给文章点点赞!!!
学习网络安全技能的方法无非三种:
第一种是报网络安全专业,现在叫网络空间安全专业,紧张专业课程:步伐计划、盘算机构成原理原理、数据布局、操纵体系原理、数据库体系、 盘算机网络、人工智能、自然语言处置处罚、社会盘算、网络安全法律法规、网络安全、内容安全、数字取证、呆板学习,多媒体技能,信息检索、舆情分析等。
第二种是自学,就是在网上找资源、找教程,大概是想办法熟悉一-些大佬,抱紧大腿,不外这种方法很耗时间,而且学习没有规划,大概很长一段时间感觉本身没有进步,容易劝退。
第三种就是去找培训。

接下来,我会教你零底子入门快速入门上手网络安全。
网络安全入门到底是先学编程还是先学盘算机底子?这是一个争议比力大的题目,有的人会发起先学编程,而有的人会发起先学盘算机底子,实在这都是要学的。而且这些对学习网络安全来说非常紧张。但是对于完全零底子的人来说又大概急于转行的人来说,学习编程大概盘算机底子对他们来说都有肯定的难度,而且耗费时间太长。
第一阶段:底子预备 4周~6周

这个阶段是全部预备进入安全行业必学的部门,俗话说:底子不劳,地震山摇

第二阶段:web渗出

学习底子 时间:1周 ~ 2周:
① 相识根本概念:(SQL注入、XSS、上传、CSRF、一句话木马、等)为之后的WEB渗出测试打下底子。
② 检察一些论坛的一些Web渗出,学一学案例的思绪,每一个站点都不一样,以是思绪是紧张的。
③ 学会提问的艺术,如果碰到不懂得要善于提问。

设置渗出环境 时间:3周 ~ 4周:
① 相识渗出测试常用的工具,比方(AWVS、SQLMAP、NMAP、BURP、中国菜刀等)。
② 下载这些工具无后门版本而且安装到盘算机上。
③ 相识这些工具的使用场景,懂得根本的使用,保举在Google上查找。
渗出实战操纵 时间:约6周:

① 在网上搜刮渗出实战案例,深入相识SQL注入、文件上传、剖析毛病等在实战中的使用。
② 本身搭建毛病环境测试,保举DWVA,SQLi-labs,Upload-labs,bWAPP。
③ 懂得渗出测试的阶段,每一个阶段须要做那些动作:比方PTES渗出测试实验标准。
④ 深入研究手工SQL注入,探求绕过waf的方法,制作本身的脚本。
⑤ 研究文件上传的原理,怎样举行截断、双重后缀诱骗(IIS、PHP)、剖析毛病使用(IIS、Nignix、Apache)等,参照:上传攻击框架。
⑥ 相识XSS形成原理和种类,在DWVA中举行实践,使用一个含有XSS毛病的cms,安装安全狗等举行测试。
⑦ 相识一句话木马,并实验编写过狗一句话。
⑧ 研究在Windows和Linux下的提升权限,Google关键词:提权

以上就是入门阶段
第三阶段:进阶

已经入门而且找到工作之后又该怎么进阶?详情看下图

给新手小白的入门发起:
新手入门学习最好还是从视频入手举行学习,视频的浅近易懂相比起晦涩的笔墨而言更容易汲取,这里我给各人预备了一套网络安全从入门到醒目标视频学习资料包免费领取哦!

本文转自 https://blog.csdn.net/weixin_50902636/article/details/137755977?spm=1001.2100.3001.7377&utm_medium=distribute.pc_feed_blog_category.none-task-blog-classify_tag-18-137755977-null-null.nonecase&depth_1-utm_source=distribute.pc_feed_blog_category.none-task-blog-classify_tag-18-137755977-null-null.nonecase,如有侵权,请接洽删除。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表