• zabbix密码复杂度有效期安全增强,符合三级等保要求。


    一、关于三级等保要求

    1.zabbix没有设置密码复杂度功能,密码有效期功能。

    2.zabbix没有失败处理功能。

    3.zabbix具备超时退出功能。

    二、整改

    1.zabbix 系统不具备登录失败处理功能,运维终端未设置超时退出功能。

     添加失败处理功能,失败3次锁定30分钟,修改include/defines.inc.php

    define('ZBX_LOGIN_ATTEMPTS',    3);
    define('ZBX_LOGIN_BLOCK',               1800); // sec

    截图如下:

    使用zhangyifan帐号测试输入5次密码,可以看到状态已锁定,截图如下:

    添加自动超时退出功能,截图如下:

    2.zabbix 系统和应用系统未实现密码定期更换

    整改证据:zabbix数据库users表添加10位时间戳过期字段,截图如下:

    程序添加90天过期字段,此处有两个文件需要修改。include/classes/api/services/CUser.php和include/schema.inc.php。

    其中CUser.php创建用户时候新增代码$ins_users[0]['passwd_expired'] = time() + 7776000; 代表90天后过期:

        public function create(array $users) {
            $this->validateCreate($users);
    
            $ins_users = [];
    
            foreach ($users as $user) {
                unset($user['usrgrps'], $user['user_medias']);
                $ins_users[] = $user;
            }
            //创建用户时候添加过期时间
            $ins_users[0]['passwd_expired'] = time() + 7776000;
            $userids = DB::insert('users', $ins_users);

    其中CUser.php创建更新用户设置时候新增代码$upd_user['passwd_expired'] = time() + 7776000;代表90天后过期:

    public function update(array $users) {
            $this->validateUpdate($users, $db_users);
    
            $upd_users = [];
    
            foreach ($users as $user) {
                $db_user = $db_users[$user['userid']];
    
                $upd_user = [];
    
    
                // strings
                $field_names = ['alias', 'name', 'surname', 'autologout', 'passwd', 'refresh', 'url', 'lang', 'theme'];
    
                foreach ($field_names as $field_name) {
                    if (array_key_exists($field_name, $user) && $user[$field_name] !== $db_user[$field_name]) {
                        $upd_user[$field_name] = $user[$field_name];
                    }
                }
    
                // integers
                foreach (['autologin', 'type', 'rows_per_page'] as $field_name) {
                    if (array_key_exists($field_name, $user) && $user[$field_name] != $db_user[$field_name]) {
                        $upd_user[$field_name] = $user[$field_name];
                    }
                }
    
                if ($upd_user) {
                    //添加过期时间
                    $upd_user['passwd_expired'] = time() + 7776000;
                    $upd_users[] = [
                        'values' => $upd_user,
                        'where' => ['userid' => $user['userid']]
                    ];
                }
            }

    在schema.inc.php中'users'段,最后加入数据库的过期字段。

        'users' => [
            'key' => 'userid',
            'fields' => [
                'userid' => [
                    'null' => false,
                    'type' => DB::FIELD_TYPE_ID,
                    'length' => 20
                ],
                            ...省略一大坨...
                'rows_per_page' => [
                    'null' => false,
                    'type' => DB::FIELD_TYPE_INT,
                    'length' => 10,
                    'default' => 50
                ],
                'passwd_expired' => [
                    'null' => false,
                    'type' => DB::FIELD_TYPE_INT,
                    'length' => 10
                ]
            ]
        ],    

    完成以上内容,只是在创建用户和修改用户设置的时候,触发更新数据库中密码过期时间字段修改。

     接下来写一个巡检代码,定期巡检数据库表中zabbix过期的用户。加到crontab里

    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    # @Time    : 2022/2/22 14:34
    # @Author  : GuoYabin
    # @Email   : hbbdgyb@163.com
    # @File    : mysql.py
    # @Software: PyCharm
    
    import pymysql
    import time
    
    class Localmysqlopt(object):
        def __init__(self):
            self.db = pymysql.connect(host="localhost",
                                      user="zabbix",
                                      password="zap2dfal43",
                                      port=3306,
                                      database="zabbix",
                                      charset="utf8")
            self.cursor = self.db.cursor()
    
        def dml_execute(self, sql=None):
            try:
                with self.cursor as cursor:
                    cursor.execute(sql)
                    self.db.commit()
            except Exception as e:
                self.db.rollback()
                print(e)
    
    
    
        def chaxun(self):
            sql = "select userid,passwd_expired from users where passwd_expired < {0} and attempt_failed < 3 ".format(int(time.time()))
            self.cursor.execute(sql)
            results = self.cursor.fetchall()
            if results:
                for value in results:
                    attempt_failed,userid = 5,value[0]  #修改登录失败次数,实现锁定账户
                    sql = "update users set attempt_failed = '{0}' where userid = '{1}'".format(attempt_failed,userid)
                    self.dml_execute(sql)
    
    if __name__=='__main__':
        db = Localmysqlopt()
        db.chaxun()

    ps等保整改截图时候偷个懒,只截一个update方法中的内容。截图如下:

     真是难为我了,做为一个运维又改php代码,又写Python的。

     

    3.zabbix 系统远程管理使用 http 协议进行连接。

    这段不用写了吧?NGINX配置一个https证书,自己发挥吧。

    4.zabbix 系统未采用密码技术保证重要数据在存储过程中的完整性。

    整改证据:添加密码复杂度相关代码,修改文件./app/controllers/CControllerUserUpdateGeneral.php结尾部分

            if ($password1 !== null && $password2 !== null) {
                if ($password1 !== $password2) {
                    error(_('Both passwords must be equal.'));
                    return false;
                }
    
                if ($password1 === '' && !$this->allow_empty_password) {
                    error(_s('Incorrect value for field "%1$s": %2$s.', _('Password'), _('cannot be empty')));
                    return false;
                }
                /**
                * 检查密码复杂度
                */
                if (strlen($password1) <= 8) {    //必须大于8个字符
                    error(_('密码必须大于8字符'));
                    return false;
                }
    
                if (preg_match("/^[0-9]+$/", $password1)) { //必须含有特殊字符
                    error(_('密码不能全是数字,请包含数字,字母大小写或者特殊字符'));
                    return false;
                }
    
                if (preg_match("/^[a-zA-Z]+$/", $password1)) {
                    error(_('密码不能全是字母,请包含数字,字母大小写或者特殊字符'));
                    return false;
                }
    
                if (preg_match("/^[0-9A-Z]+$/", $password1)) {
                    error(_('请包含数字,字母大小写或者特殊字符'));
                    return false;
                }
    
                if (preg_match("/^[0-9a-z]+$/", $password1)) {
                    error(_('请包含数字,字母大小写或者特殊字符'));
                    return false;
                }
            }
            return true;
        }
    }

    截图如下:

     测试修改zhangyifan密码为纯数字,提示密码复杂度不符合要求。截图如下:

     测试修改zhangyifan帐号为3个字符,提示密码长度不符合要求。截图如下:

     

  • 相关阅读:
    CSS优先级及继承
    group by 与 order by
    软件开发升级指南(转)
    安装DELL服务器,安装Windows 2003 sp2 问题
    SQL SERVER 2005数据库总结
    C#操作INI文件(调用WindowsAPI函数:WritePrivateProfileString,GetPrivateProfileString)
    对RBS理解与使用
    WSS和MOSS的区别
    关于.net winform ComboBox数据绑定显示问题
    OpenNETCF.Desktop.Communication.DLL程序集的使用
  • 原文地址:https://www.cnblogs.com/guoyabin/p/15930436.html
Copyright © 2020-2023  润新知