Mysql被黑客入侵及安全措施总结
2018-03-06 09:43
579 查看
情况概述
今天登陆在腾讯云服务器上搭建的Mysql数据库,发现数据库被黑了,黑客提示十分明显。Mysql中只剩下两个数据库,一个是information_schema,另一个是黑客创建的
PLEASE_READ,其中有一张
info表,内容如下:
Info: Your DB is Backed up at our servers, to restore send 0.2 BTC to the Bitcoin Address then send an email with your server ip
Bitcoin_Address: 1F33LEJjdphD6YpaonNCHejwLcgkgDGQW9
显然,我这是遇到比特币敲诈了。我的数据在别人的服务器里安然的躺着,需要向黑客支付0.2比特币才有可能恢复。按照当前的汇率,0.2比特币大约为1400人民币,这是我第一次遇到网络敲诈,金额还不小。所幸数据库里并没有值钱的数据,就当是送给黑客了,不过 数据库安全问题 引起了我的注意。
安全措施
由于缺乏必要的安全措施和备份机制,数据库中原有的数据均已丢失。为了恢复到Mysql初始的状态,重新安装了Mysql数据库,并且重新创建原先存在的数据库,同时,为了防止再次被黑客入侵,对Mysql进行了一些安全配置。禁用或限制远程访问。若允许远程访问,需要确保特定主机才拥有访问权。对用户进行合理授权,应用程序中最好不要直接使用
root用户。
限制打开网络socket,此时仍可以建立与Mysql服务器的本地连接。
[mysqld] skip-networking强迫Mysql仅监听本机。
[mysqld] bind-address=127.0.0.1更改
root用户的登录名称和密码。
移除测试数据库和匿名账户及废弃的账户。
禁用
LOCAL INFILE。
[mysqld] set-variable=local-infile=0删除历史命令记录。
cat /dev/null > ~/.bash_history cat /dev/null > ~/.mysql_history及时安装Mysql安全补丁。
使用
chroot限制Mysql运行环境。
自动定期备份数据库。
用防火墙实现mysql绑定多个ipmy.cnf中有选项bind-address=127.0.0.1,是说mysql server监听的是本地发来的请求,如果是任意主机都可以请求,则写为0.0.0.0,但是这样又不太安全。监听某ip,指定此ip地址即可,但是要保证mysql的user中有允许此ip访问,否则不能对数据库操作。那么是否可以在配置里只规定几个ip呢?简单直接回答:不可能请参考:http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_bind-addressThe MySQL server listens on a single network socket for TCP/IP connections. This socket is bound to a single address, but it is possible for an address to map onto multiple network interfaces. The default address is 0.0.0.0. To specify an address explicitly, use the –bind-address=addr option at server startup, where addr is an IPv4 address or a host name. If addr is a host name, the server resolves the name to an IPv4 address and binds to that address. The server treats different types of addresses as follows:If the address is 0.0.0.0, the server accepts TCP/IP connections on all server host IPv4 interfaces.
If the address is a “regular” IPv4 address (such as 127.0.0.1), the server accepts TCP/IP connections only for that particular IPv4 address.但是有此需求,就会到访问控制,那么使用防火墙iptables可实现此效果mysql-server为192.168.1.3,只允许192.168.1.4, 192.168.1.5, 192.168.1.6来访问3306端口在my.cnf中bind-address = 0.0.0.0在访问3306端口的主机中,只允许192.168.1.4-6,其他ip一律DROP掉/sbin/iptables -A INPUT -p tcp -s 192.168.1.4 --dport 3306 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -s 192.168.1.5 --dport 3306 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -s 192.168.1.6 --dport 3306 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 3306 -j DROP或/sbin/iptables -A INPUT -p tcp --dport 3306 ! -s 192.168.1.4 -j DROP
/sbin/iptables -A INPUT -p tcp --dport 3306 ! -s 192.168.1.5 -j DROP
/sbin/iptables -A INPUT -p tcp --dport 3306 ! -s 192.168.1.6 -j DROP保存防火墙规则service iptables save查看INPUT链包含3306的规则echo -e "target prot opt source destination\n$(iptables -L INPUT -n | grep 3306)"这样就实现了mysql只允许指定ip访问。参考:http://www.cyberciti.biz/faq/unix-linux-mysqld-server-bind-to-more-than-one-ip-address/
yum 和 rpm安装mysql彻底删除
1、yum方式安装的MySQL $ yum remove mysql mysql-server mysql-libs compat-mysql51$ rm -rf /var/lib/mysq$ rm /etc/my.cnf查看是否还有mysql软件:$ rpm -qa|grep mysql如果存在的话,继续删除即可,删除方式:yum remove + 【名字】。 2、rpm方式安装的mysql a)查看系统中是否以rpm包安装的mysql: [root@localhost opt]# rpm -qa | grep -i mysqlMySQL-server-5.6.17-1.el6.i686
MySQL-client-5.6.17-1.el6.i686 b)卸载mysql[root@localhost local]# rpm -e MySQL-server-5.6.17-1.el6.i686
[root@localhost local]# rpm -e MySQL-client-5.6.17-1.el6.i686c)删除mysql服务[root@localhost local]# chkconfig --list | grep -i mysql
[root@localhost local]# chkconfig --del mysqld)删除分散mysql文件夹[root@localhost local]# whereis mysql 或者 find / -name mysql mysql: /usr/lib/mysql /usr/share/mysql清空相关mysql的所有目录以及文件
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysqlrm -rf /usr/my.cnf 通过以上几步,mysql应该已经完全卸载干净了。
相关文章推荐
- Mysql被黑客入侵及安全措施总结
- Linux安全问题之防黑客入侵
- 世界第一黑客改过自新 总结电脑安全十大建议
- 经验总结 黑客入侵网络的20种方法
- PHP网站常见安全漏洞,及相应防范措施总结
- Windows下MySQL配置及安全加固总结
- 总结揭露黑客入侵网站的手法
- MySQL基本安全总结
- 网站安全之常见入侵总结
- 黑客入侵精彩总结
- 世界第一黑客总结电脑安全十大建议 ZT
- 四步提高网络安全 阻止黑客入侵(转载)
- Mysql安全措施
- 挑战黑客入侵 安全虚拟主机配置
- 世界第一黑客总结电脑安全十大建议
- 世界第一黑客总结电脑安全十大建议
- 求师傅教我黑客攻防!安全维护!入侵安检
- PHP网站常见安全漏洞 及相应防范措施总结
- 工信部:黑客入侵等是网络安全防护工作的重点
- 系统安全:Linux主机服务器被入侵后需采取的措施