Union losses from the micro blood deleted 150 million library events, chat a few server security

REVIEW naked eye care products in the world: Micro League delete library event of blood loss 150 million, bloody lessons ah, as there is another version, the micro-union executives operation and maintenance staff to make students interested in private indecent things can search, authenticity has yet to discuss ; here we talk about a few safety issues, in several stages on the nature of security issues: 1: prevention mechanism on the front line 2: run online data backup alarm mechanism 3: accident and recovery log traceability system appear                                                                           
more premium content, please No micro-channel public attention "to the naked eye care products in the world" (ID: find_world_fine)

Read the text takes about 10 minutes.

Early looked at micro League, and have somewhat similar praise do have to say that the rise of micro-channel led a group of man-made rich, a number of new industries emerge, seems to be synonymous with ecological micro-channel on some incomplete sense of the mobile Internet .

As for micro-AU data is deleted, there is no fresher data backup and monitoring mechanisms at least the next day, somewhat puzzled.

March 1 evening, Micro One announced that as of March 1 evening at 8:00, in the assistance team Tencent cloud, the data has been fully recovered.

Micro One said that due to the very large amount of data, in order to ensure data consistency and online experience, will be held at 2:00 on March 2 line drills carried out on the system, will resume formally launched at 9:00 on March 3 data .

For the impact of the accident caused to businesses, micro League said that the management is deeply self-blame and guilt, prepared a 150 million yuan payment of provision, which undertook 100 million yuan, 50 million yuan of management commitment.

Do not know what has happened, the junior partner, you can stamp the following figure:

What has happened, the micro-union official public source Figure No.

From after the accident can be seen from February 23 to delete the library interrupt event data to March 1st fully recovered, and then data March 3 to restore the entire incident lasted more than a week's time.

This massing of such micro electricity supplier Union is undoubtedly a huge loss of stock market capitalization of evaporation is one thing. More importantly, the technology company is operating data of company from nature, and data loss event and the theft of a bank vault event is of the same nature to some extent, it will cause great impact on the party's reputation.

做为一名多年战斗IT行业老兵,笔者就以这个事件为切入点,聊聊如今的互联网公司特别是中小型创业企业如何做数据安全,服务器安全,保障自己的业务低成本安全有效的跑得飞快

1

linux服务器安全

一:基础安全

1:修改ssh端口,ssh禁止root登陆

vi /etc/ssh/sshd_config
Port 3310  #修改端口
PermitRootLogin no   #禁止root登陆
vi /etc/passwd
root:x:0:0:root:/root:/bin/bash修改为:
root:x:0:0:root:/root:/sbin/nologin

2:配置允许的ip:

vi /etc/hosts.allow
sshd:108.11.12.13:allow # 如果只允许一个ip那么就可以作为跳板机使用
vi /etc/hosts.deny 
sshd:ALL #禁止所有,只有allow中的才可以访问 ,也可以在sshd_config中配置

3:防火墙,centos7中已经是firewall-cmd,把自己需要的端口打开并限定ip访问

firewall-cmd --state
firewall-cmd --list-ports # 查看所有端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

其他更多的firewall操作同学们自行搜索一下

4:关闭scp、sftp权限:

# 1.先禁止scp
rpm -qa|grep openssh-*
yum remove openssh-clients -y
# 删除了openssh-clients后,再执行scp,就会报下面的错误:
-bash: scp: command not found
# 2.禁止sftp
vi /etc/ssh/sshd_config
Subsystem sftp /usr/libexec/openssh/sftp-server
# 把这行注释了,如下:
#Subsystem sftp /usr/libexec/openssh/sftp-server
# 退出保存后,重启sshd:
service sshd restart

5:启动应用程序不要用root权限相关用户,比如你亲爱的tomcat,go,python

6:对/etc/passwd文件跟踪起来,谁改了,哪个进程改的都得知道,俗称监控起来

auditctl -w /etc/passwd -p war -k passwd
ausearch -i -k passwd

每个日志可以同步到eleasticsearch,不怕暗算的删除,日志早同步了

7:每个用户的操作命令跟踪起来

history
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
        USER_IP=`hostname`
fi


if [ ! -d /tmp/operation ]
then
        mkdir /tmp/operation
        chmod 777 /tmp/operation
fi


if [ ! -d /tmp/operation/${LOGNAME} ]
then
        mkdir /tmp/operation/${LOGNAME}
        chmod 700 /tmp/operation/${LOGNAME}
fi


export HISTSIZE=4096


DT=`date +%Y%m%d`


# file=`find /tmp/operation/${LOGNAME}/ |awk '/'$DT'$/'`
file=/tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT
if [ -e "$file" ]
then
        export HISTFILE="/tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT.tmp"
        tmpfile=/tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT.tmp
        if [ -e "$tmpfile" ]
        then
                cat /tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT.tmp >> $file
        fi
else
        export HISTFILE="/tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT"
fi
 rm -f /tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT.tmp
chmod 600 /tmp/operation/${LOGNAME}/*susworld* 2>/dev/null
### end add by jim

还可以指定用户搜索:opsearch -u xxx

vi /usr/bin/opsearch

脚本内容:

#!/bin/sh -
# filename getrecord


user=
time=
while [ $# -gt 0 ]
do
    case $1 in
    -u|--user) user=$2
    shift 2
    ;;
    -t|--time) time=$2
    shift 2
    ;;
    -*)        echo "$0:$1 Wrong Options!" >&2
    shift
    exit 0
    ;;
    --)        break
     ;;
      *)         break
    ;;
        esac
done
if [ -z "$user" ]
then
        user=${LOGNAME}
fi
if [ -z "$time" ]
then
        time=`date +%Y%m%d`
fi
file=`find /tmp/operation/$user/ |awk '/'$time'$/'`
cat $file

一样的每个日志可以同步到eleasticsearch,还来个报警,暗算的可以让他变透明了

说了这么多,是不是操作起来很费劲?好了,这些都有一个新的运维管理软件帮你做权限管理,审计管理了,那就是jumpserver,这个东西把你脚本要操作的都可以很好的管理起来;但是我们熟悉相关基础脚本操作很重要,任何基于此建立的软件都能知道他的来龙去脉

2

代码安全

需要注意几个点:

1:通过jenkins等发布工具发布代码,服务器上发布的尽量是已经变过过后的代码

2:webshell,有一个工具findWebShell ,很多公司都有自己开发的工具

3:一些危险函数的执行权限可以服务器配置去掉如php的system相关函数

4:sql注入:扫描神器可以尝试一下:SQLMAP SQL,有时间人肉复查也是必须的

5:所有输入的参数过滤,安全检查,避免xss攻击等

6:支付安全,这个相当重要,如果是自己公司做的支付接口,你得在参数中多加一个timestamp的时间戳参数,签名根据时间戳签名一种加密算法,其次看看discuz的formhash函数,提交前存储一个随机串,提交时需要对此进行对比验证的

还有很多代码安全审计的工具,不同的语言可以都能搜索到一些工具,人肉代码review还是必不可少

3

数据安全

1:数据库用户限定ip访问,数据库按时间段备份,密码尽量复杂,不使用root用户

2: 关键数据都加密存储,密码更不用说了,需要反向解密的地方用c给打包成一个.so文件给java,python等语言调用,关键key资源不在源码中暴露

3:两地三中心:同城同步复制,异地异步复制 ,解决方案有商用的也有开源的,商用的华为SAN 3DC方案的不错,mysql开源的可以尝试一下阿里的canal:跨地域 MySQL binlog 增量订阅&消费组件

一般来说目前比较流行的灾备体系是至少建设三个数据中心,其中:

  • 主中心:正常情况下全面提供业务服务。

  • 同城中心:一般使用同步复制的方式来向同城灾备中心传输数据,保证同城中心数据复本为最新,随时可以接管业务,以保证RTO的指标。但是同城中心无法应对此类删库事件。

  • 异地中心:一般使用延时异步复制(延时时间一般为30分钟左右)的方式向异地灾备中心传输数据,其中同步复制的好处是一旦主中心被人工破坏,那么不会立刻涉及异地中心以保证RPO的指标。

一句话总结灾备体系的最佳实践就是两地三中心;同城保证业务连续性,优先负责用户体验;异地保证数据连续性,确保企业生存底线。而针对行为及日志等重要性等级不高的数据,一般采用异地磁带备份的方式。具体方式如下:

不过从目前情况看不少企业尤其是创业型企业,都没有百年老店的观念,因此在异地中心的建设上投入还不够,不过这样的模式缺点也很明显,一旦发生这种删库事件就影响就是致命的。

4:任何数据操作必须报备,所有审核无误后,一人执行,一人check;操作数据库之前备份最新数据

4

结论思考

上面说那么多,是不是觉得很烦(也有同学把上面的脚本给收藏了,总结得比较全的文章还是比较少),得请多少运维,出错的几率还大大增加,还有更多细节去做

没错,云来了,阿里云,华为云,腾讯云

任何时候的数据库备份都给你恢复,你爽不爽

看看阿里云RDS的介绍(不是广告):

阿里云关系型数据库(Relational Database Service,简称RDS)是一种稳定可靠、可弹性伸缩的在线数据库服务。基于阿里云分布式文件系统和SSD盘高性能存储,RDS支持MySQL、SQL Server、PostgreSQL、PPAS(Postgre Plus Advanced Server,高度兼容Oracle数据库)和MariaDB TX引擎,并且提供了容灾、备份、恢复、监控、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。

阿里云RDS具备以下产品优势:

便宜易用:具有灵活计费、按需变配、即开即用等优点。

高性能提供高性能实例,包括参数优化、SQL优化建议等优点。

灾备设计提供数据备份与恢复、同城容灾、异地容灾等多种灾备方案,确保您的数据不会丢失。

高安全性:提供放DDoS共计、检测SQL注入威胁、访问控制策略等多种安全措施,保证您的数据安全。

你所想要的数据安全都给你做了,还等什么呢,上云是对中小企业最好的保障,也是未来趋势;所谓给小钱,节约大钱!

原创不易,记得转发,点赞

发布了25 篇原创文章 · 获赞 1 · 访问量 9696

Guess you like

Origin blog.csdn.net/weixin_45727359/article/details/104687908