• Linux 系统安全规范


    转载自:http://zoukejian.blog.51cto.com/131276/56631

    基本原则: a. 及时更新所有的服务,以防止最新的威胁
    b. 尽可能使用安全的协议
    c. 尽可能让每台机只提供一种服务
    d. 严格监控所有机器以及时发现恶意行为
    e. 订阅系统相关的安全邮件列表
    一.帐户和口令
    (). 帐户
    1.为每个系统维护人员建立一个独立的普通权限帐号,为监控机建立监控
    帐号,分别用于日常系统维护和系统监控;
    2FTP 服务器配置虚拟帐号;
    3.禁止除root 帐号系统维护人员帐号和监控机帐号之外所有帐号使用
    SHELL的权限;
    4.锁定所有在安装系统时自动建立的帐号;
    a. 查找出未锁定的系统帐号:egrep -v ‘.*:\*|:\!’ /etc/shadow | awk -F: ‘{print $1}’
    b. 锁定:usermod –L <username>
    (). 口令
    1.强度:a. 10位以上;包含了字母(大写字母和小写字母),数字和特殊符号;不允许包含英文单词;
    b. 配置:在文件/etc/pam.d/system-auth中配置;
    password requisite /lib/security/$ISA/pam_cracklib.so retry=3 minlen=10 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1
    2.更改频率:a. 120天;
    b. 配置新建帐户的默认更改频率:在文件/etc/login.defs中设置 pass_max_days=120
    c. 修改当前用户的更改频率: chage –M 120 <username>
    3.历史:a. 10
    b. 配置:在文件/etc/pam.d/system-auth中配置
    password requisite /lib/security/$ISA/pam_cracklib.so retry=3 minlen=10 lcredit=-1 ucredit=-1dcredit=-1 ocredit=-1 difok=3
    password sufficient /lib/security/$ISA/pam_unix.so nullok use_authtokmd5 shadow remember=10
    4.推荐的选择口令的方法:想出一个句子,用其中每个单词的首字母及其包含的符合,并将字母替换为跟其相似的数字或符号来生成口令;
    5.好的口令举例:Zhongguoliantong10010!))!), Beijingquhao010)!)
    二.远程登录
    (). SSH
    1.只支持SSH v.2
    2.禁止直接使用root帐号登录,只允许使用普通权限帐号直接登录;
    3.更改默认端口(改为22222);
    (). 登录banner
    1. /etc/issue文件里加入登录警告
    #cat > /etc/issue << EOF
    =======================================
    Warning: The system is owned by xxxxxx,
    Unauthorized access to this system is prohibited!!!
    =======================================
    2. /etc/motd文件里加入对登录成功者的警告
    #cat > /etc/motd << EOF
    =======================================
    Warning: The system is owned by xxxxxx,
    What you do will be monitored and logged!!!
    =======================================
    三.内核参数
    1.调整如下内核参数,以提高系统防止IP欺骗及DOS攻击的能力:
    net.ipv4.ip_forward = 0 对于LVS,网关或VPN服务器,要设置为1
    net.ipv4.tcp_syncookies = 1
    net.ipv4.conf.all.accept_source_route = 0
    net.ipv4.conf.all.accept_redirects = 0
    net.ipv4.conf.all.rp_filter = 1 对于LVS 后端服务器
    要设置为0
    net.ipv4.icmp_echo_ignore_broadcasts = 1
    net.ipv4.icmp_ignore_bogus_error_responses = 1
    net.ipv4.conf.all.log_martians = 1
    kernel.sysrq = 0
    kernel.core_uses_pid = 1
    四.文件系统
    1mount 选项:/ ro 先将 /root 目录移到/home/root
    /boot ro
    /usr ro
    /var noexec, nosuid
    /tmp noexec, nosuid
    2SUID,SGID文件:每天运行一个cron任务,看是否有新的SUID/SGID文件出现,
    如果有,则发e-mail 给维护人员;
    3.所有人都可以写的目录:每天运行一个cron任务,看是否有新的所有人都可以
    写的目录出现,如果有,则发e-mail 给维护人员;
    4ACL:在为多个用户分配某个文件或目录的权限时,禁止使用修改用户所属组
    实现,使用ACL实现;
    5. umask:配置为0022 0055(在/etc/bashrc中配置);
    五.日志
    1.日志集中存放到日志主机上本地保存4周的日志备份;
    2.日志客户机配置:参考<<linux 系统规范>> 8. 配置系统日志;
    3.日志主机配置:参考<<linux 日志主机配置指南>>
    六.应用程序
    (). MySQL
    1.以mysql用户运行MySQL
    2.给管理员帐户root改名(ht-mysql-admin)
    3.给管理员帐户设置强键的口令;
    4.删除数据库test
    5.删除MySQL安装过程中自动创建的不需要的帐户,
    禁止创建非绝对必需的帐户;
    6.禁止存放任何纯文本口令在数据库中;
    7.禁止从字典里选择口令;
    8.严格控制用户权限:仅给予用户完成其工作所需的最小的权限;
    禁止授予PROCESS, SUPER, FILE 权限给非管理帐户;
    9.禁止将MySQL数据目录的读写权限授予给mysql用户外的其它OS 用户;
    10.订阅邮件列表:MySQL Announcements
    (). Resin
    1.以用户resin运行resin
    2.跟APACHE集成使用,禁止运行在standalone 模式直接提供WEB服务 
    (). Apache
    1.只编译必须使用的模块;
    2.以daemon组的daemon用户运行APACHE
    3.关闭所有的诊断页面和自动目录索引服务;
    4.删除cgi-bin目录和manul目录;
    5.尽可能不要暴露自己的真实身份;
    6.使用chrooting 限制apache对文件系统的访问(在使用了集中存储的情况下
    比较难以实现);
    7.安装modsecurity模块;
    8.运用基于主机的身份验证控制对管理页面的访问;
    9.日志集中存放和分析;
    10.订阅邮件列表:Apache HTTP Server Announcements List 
    七.防火墙
    一).软件:iptables
    (). 规则
    1.加载重要的iptables 模块:ip_tables, iptable_filter, ip_conntrack,
    ip_conntrack_ftp
    2.按网卡接口(eth0, eth1,…)和数据包类型(TCP,UDP,ICMP
    自定义规则集;
    3.配置每个规则集的 policy ACCEPT,但一定要在每个规则集的末尾显式DROP任何匹配该规则集但不允许的数据包(iptables –A <rule-set name> -j DROP);
    4DROP 无效数据包,IP spoof 数据包;
    5.只开放能满足业务需求的最少的端口;
    (). 配置
    参考<< linux 系统规范 >> 10. 配置安全 3)防火墙;
    八.入侵检测和防护
    1.工具:OSSEC
    2.策略:在某台服务器上安装OSSEC HIDS 服务器,在需要作主机入侵检查和防护及文件完整性检测的服务器上安装OSSEC HIDS 代理,代理将相关信息发送到HIDS服务器,由服务器统一分析处理;
    3.配置:参考<< HIDS OSSEC安装指南>>
    九.安全审计
    —————————————————————
    审计对象 工具 频率
    ———————————————————–
    Linux 系统 nmap 1个月
    Nessus 3个月
    自动日志分析 实时
    人工日志分析 必要时
    口令文件 John the ripper 3个月
    APACHE nikto 6个月
    Appscan 6个月
    ————————————————————
    注:新安装的服务器必须经过安全审计才允许投入产品环境;
    新发布了应用后,必须立即进行安全审计;
    .安全邮件列表和网站
    1.订阅邮件列表:[url]www.securityfocus.com[/url] Bugtraq, Focus-Linux, Web
    Application Security
    [url]http://www.cert.org[/url][url]http://www.us-cert.gov[/url]

    #/bin/bash
    #
    export 

    # ---------------------------------------------------------------------------------------------------------#
    # define vars
    script_base_dir=/root/system_check

    today=$(date +'%Y-%m-%d')
    today_perm_777=$script_base_dir/"$today"_perm_777.txt
    today_sugid=$script_base_dir/"$today"_perm_sugid.txt
    today_owner_none=$script_base_dir/"$today"_owner_none.txt
    today_files_jsp=$script_base_dir/"$today"_files_jsp.txt
    today_result=$script_base_dir/"$today"_result.txt

    yesterday=$(date +'%Y-%m-%d' --date '1 days ago')
    yesterday_perm_777=$script_base_dir/"$yesterday"_perm_777.txt
    yesterday_sugid=$script_base_dir/"$yesterday"_perm_sugid.txt
    yesterday_owner_none=$script_base_dir/"$yesterday"_owner_none.txt
    yesterday_files_jsp=$script_base_dir/"$yesterday"_files_jsp.txt

    ip=`ip addr l dev eth0 | grep 'inet ' | awk '{ print $2 }' | awk -F/ '{ print $1 }' | awk -F. '{ print $4 }'`

    mail_subject="Check report from $ip on $today"
    mail_recept="mgroup@xx-xxx.com"

    # ---------------------------------------------------------------------------------------------------------#
    # search for abnormal dirs and files

    echo begin to find world-writable directories, please wait... > $today_perm_777
    find / \( -path /usr/local/v2.marry5.com/files -o -path /proc \) -prune -o \
    -type d \( -perm 777 \) -exec ls -lda {} \; >> $today_perm_777
    echo finished finding world-writable directories >> $today_perm_777

    echo begin to find suid/sgid files, please wait... > $today_sugid
    find / \( -path /usr/local/v2.marry5.com/files -o -path /proc \) -prune -o \
    -type f \( -perm -2000 -o -perm -4000 \) -exec ls -la {} \;  >> $today_sugid
    echo finished finding suid/sgid files  >> $today_sugid

    echo begin to find files without owner, please wait... > $today_owner_none
    find / \( -path /usr/local/v2.marry5.com/files -o -path /proc \) -prune -o \
    -nouser -o -nogroup -exec -ls -lda {} \; >> $today_owner_none
    echo finished finding files without owner >> $today_owner_none

    # this line is for 81 only
    echo begin to find jsp files in directory /usr/local/v2.marry5.com, please wait... > $today_files_jsp
    if [ "$ip""A" == "81A" ] ; then
    find /usr/local/v2.marry5.com/files -type f -name *.jsp -exec ls -la {} \; >> $today_files_jsp
    fi
    echo finished finding jsp files  >> $today_files_jsp

    # ---------------------------------------------------------------------------------------------------------#
    # compare the search result of today to yesterday's result

    echo "Date: " $(date +'%Y-%m-%d')  > $today_result
    echo "IP: " $ip >> $today_result
    echo "Findings:"  >> $today_result
    echo >> $today_result
    if [ ! -f $yesterday_perm_777 ] ; then
    echo "The file $yesterday_perm_777 has lost! " >> $today_result
    else
    echo "World-writable directories:"  >> $today_result
    diff $yesterday_perm_777 $today_perm_777 >> $today_result
    fi
    echo >> $today_result
    if [ ! -f $yesterday_sugid ] ; then
    echo "The file $yesterday_sugid has lost! " >> $today_result
    else
    echo "SUID/SGID files:"  >> $today_result
    diff $yesterday_sugid $today_sugid  >> $today_result
    fi
    echo >> $today_result
    if [ ! -f $yesterday_owner_none ] ; then
    echo "The file $yesterday_owner_none has lost!" >> $today_result
    else
    echo "Files without owner:"  >> $today_result
    diff $yesterday_owner_none $today_owner_none >> $today_result
    fi
    echo >> $today_result
    if [ "$ip""A" == "81A" ] ; then
    if [ ! -f $yesterday_files_jsp ] ; then
    echo "The file $yesterday_files_jsp has lost!" >>$today_result
    else
    echo "Files without owner:"  >> $today_result
    diff $yesterday_files_jsp $today_files_jsp >> $today_result
    fi
    fi

    # ---------------------------------------------------------------------------------------------------------#
    # mail the finding to monitor group and remove old files
    mail -s "$mail_subject" "$mail_recept" < $today_result

    rm $(date +'%Y-%m-%d' --date '1 days ago')*.txt
    # ---------------------------------------------------------------------------------------------------------#

    exit 0

  • 相关阅读:
    SQL Server 限制IP登陆
    提高MSSQL数据库读取速度,降低CPU损耗
    Windows Azure 平台开发基础系列视频
    AutoFac使用方法总结:Part III
    Python学习笔记 01 快速入门
    黑苹果~~
    Python学习笔记 02 Python基础
    Python学习笔记 04 数字
    Python学习笔记 03 Python对象
    Gridview导出excel范例
  • 原文地址:https://www.cnblogs.com/jydeng/p/4418489.html
Copyright © 2020-2023  润新知