标签 Gmail 下的文章

Blog站点被黑以及问题解决过程

记得前些日子,我在Blog评论里发现有人说我的Blog站点被黑:

"YOUR SITE HAS BEEN HACKED – THERE ARE PARASITE PAGES IN http://tonybai.com/dl SECURE YOUR SITE!!!"

粗浅检查了一番,没有发现什么异常,也就没把这事当回事儿。

昨天上Gmail(由于需要搭梯子,不经常登录),发现一位网友发来mail说我的站点被入侵了,还附上了google search结果的截图:

接着我也发现了google webmaster发来的mail,同样是警告我的博客站点被黑,并给出了两个可疑URL:

http://tonybai.com/dl

http://tonybai.com/dl/call-of-duty-4-modern-warfare-crack-download-tpb.html

我自己访问了一下上述URL,我靠!果然被黑了。

以前blog站点无论是搭建在dreamhost上还是朋友的主机上时都未出现过被黑的情况,这次在DO上居然被黑,之前没有解决类似问题的经验,这次只能从头摸索。

看了几篇解决wordpress被黑问题的文章,都推荐先安装几个安全插件对site进行扫描,于是我就试了两个:iThemes Security和Wordfence Security。前者似乎有问题,安装后,dashboard页一片空白。Wordfence Security还好,只是每次scan都无法finish,也就无法得到到底哪些wordpress文件被感染的结果。

插件不可靠,只能自己“手工”解决了。

首先到server上利用find , ls等命令对比时间,发现是否有哪些文件的最近访问时间戳与其他文件有差异。不过search了半天,也没发现半点痕迹。

网上还推荐用文件比对工具,比对现在的wordpress文件与backup的文件异同。多亏有backup插件的备份包,于是下载了20150326和20150409的backup zip,使用beyond compare进行目录比对。不比不知道,一比吓一跳啊:index.php文件时间戳相同,但内容居然不同

0409中的index.php的头部居然多了一段代码:

<?php $V3a3xH8="JQAgHfEmQKV+JuR5Y38ZdWofSxp4PSPn00uzTC

….

….

($CdFxbnu0g($nGXNegRe($dvXZv9($cDjofDA))));?>

显然这就是入侵代码了。删除这段代码,重启apache2,试试再访问以下上述那两个URL。结果是令人悲伤的,页面居然还能正常打开和显示。我第一时间想到的是浏览器和apache2的缓存。

强制刷新brower,无用。

查找apache2关于Cache的配置,发现一个:/etc/apache2/mods-available/cache_disk.conf

其内容:
<IfModule mod_cache_disk.c>

        # cache cleaning is done by htcacheclean, which can be configured in
        # /etc/default/apache2
        #
        # For further information, see the comments in that file,
        # /usr/share/doc/apache2/README.Debian, and the htcacheclean(8)
        # man page.

        # This path must be the same as the one in /etc/default/apache2
        CacheRoot /var/cache/apache2/mod_cache_disk

        # This will also cache local documents. It usually makes more sense to
        # put this into the configuration for just one virtual host.
        #CacheEnable disk /

    # The result of CacheDirLevels * CacheDirLength must not be higher than
    # 20. Moreover, pay attention on file system limits. Some file systems
    # do not support more than a certain number of inodes and
    # subdirectories (e.g. 32000 for ext3)
    CacheDirLevels 2
    CacheDirLength 1

</IfModule>

查看CacheRoot,发现/var/cache/apache2/mod_cache_disk下是空的。显然并未缓存。

难道还有其他位置为hacked了?难道0326的backup也是被hack过的?

于是我翻箱倒柜,在电脑里发现了20150101的backup,用这个Backup和0409又对比了一次,这回发现了另外一个被hack的文件:.htaccess。

.htaccess中多了这么一行代码:
RewriteRule ^dl/(.*)$ wp-add.php [L]

原来入侵的人或程序总共在我的主机上做了多处修改,这里总结一下:

1、.htaccess中增加一行规则
2、添加wp-add.php
3、修改了index.php
4、修改了wp-includes/theme-compat/header.php
5、修改了wp-content/themes/xx/header.php和footer.php

我ls了一下0409下的文件:

-rw-r–r–    1 tony  staff      4343 11 28 04:01 wp-activate.php
-rw-r–r–    1 tony  staff      1991 11 28 04:01 wp-add.php
drwxr-xr-x   89 tony  staff      3026  4  9 11:00 wp-admin/
-rw-r–r–    1 tony  staff     40243 11 28 04:01 wp-app.php

可以看出入侵代码在添加文件之后,对文件时间做了调整,让简单的时间戳对比无法揪出这个罪魁。

去除以上入侵代码后,上述可以网址就无法访问了。

在google webmaster提交request,期望google 早日将搜索结果中的"此网站可能遭到黑客入侵"标签去掉。

之后将密码修改了一遍,希望后续能免疫。

后记:
根据朋友建议,将blog的文件用git管理起来,并push到bitbucket的private repository中,这样一旦再被hack,恢复起来也较为方便。
步骤如下:
1、在/var/www目录下git init
2、git add ./
3、git commit -m”initial import” ./
4、git remote add origin https://user@bitbucket.org/user/blog.git
5、git push origin master

读《How Google Tests Software》

一直对Google这个牛X公司的内部开发过程很是感兴趣,毕竟像Google Search EngineGoogle云计算平台这些伟大产品都是在这个开发过程下缔造出来的。但也许是Google保密工作做的很好,或许人家不是刻意保密,只是 因为工作太忙或人员太低调,没空派人出来宣讲罢了。外界对Google内部的开发流程知之甚少;知道一些,诸如20%项目,也只是皮毛。

终于有一天,Google的三位工程师冒了出来,为我们带来的了一本名为《How Google Tests Software》的小书。我断断续续用了不到一周时间粗略地浏览了一遍这本书,算是对神秘的Google内部开发过程有了初步的了解了。其中有一些思路 还真是值得我后续深入思考,这里仅列出一些让我心有所触的"点",与大家共享。

书是从Test角度展开的,但Google的Test与我们所熟知的Test还有不同,包括这个过程的角色设置与职责等。下面是从书中摘录的一些语句(有些地方是我总结后的)和观点,再加上我的一些体会。

1、在Google,Software Testing被称作"Engineering Productivity(工程效率)",既负责开发和测试工具的开发、发布工程,还负责从单元测试(unit level)到探索性测试(exploratory testing)的全过程。
     
      — 在国内,多数公司的Testers只负责测试过程,而且多从功能测试开始,Unit test是开发人员的责任。大部分公司的开发与测试工具都是开发人员设计和实现的,但也有少部分先进的公司有专职的测试工具开发岗。总体来 说,Google内部的"测试人员"角色是与众不同的。

2、"Quality is a development issue, not a testing issue"、
     "At Google, this is exactly our goal: to merge development and testing so that you cannot do one without the other. Build a little and then test it. Build some more and test some more. "  、
     "The reason Google can get by with so few dedicated testers is because developers own quality.If a product breaks in the field, the first point of escalation is the developer who created the problem, not the tester who didn't catch it."
     "Testing must be an unavoidable aspect of development, and the marriage of development and testing is where quality is achieved."

     — 可以看出Google信奉:"Developer是质量的owner,是第一责任人;质量应该由开发人员把关;测试是开发过程必不可少的一方面;将开发与 测试融合在一起以获取更高的质量;开发一些,测试一些(迭代的思想)"。而国内多数组织依旧信奉着测试是软件质量的最后保证这一信条,将开发和测试隔离的 很开。
 
3、Google内部开发测试过程的三个角色:software engineer (SWE) 、software engineer in test (SET)和 test engineer (TE),Google SWEs are feature developers. Google SETs are test developers. Google TEs are user developers.

    — 在Google,似乎没有纯粹的传统意义上的Testers,按照书中所讲,SWE肯定是开发工程师,负责实现产品功能(feature),而SET,其 实也是开发工程师,用于编写产品的测试Feature,关于测试Feature这个概念很独特,Google认为,产品应该有两种Feature属性,一 种是function feature,一种则是产品的test feature,而SWE和SET则分别focus这两点。SWE和SET共享同一代码库,是开发过程中的Partner。与SWE关注功能 feature不同,SET更加关注产品的可测试性、如何通过测试提升产品质量以及提升测试覆盖率以及产品性能。他们为产品的feature编写测试代 码,从单元测试到后续的各种测试,编写各种工具,并尽量的将测试自动化,提升测试效率。

       而TE这个角色则有些类似传统的Testers,但在Google也有不同。在Google,TE更多是从user角度去探索产品,有的TE会编写大量脚 本代码,模拟user使用产品的各种场景;按照书中的说法:"TEs are product experts, quality advisers, and analyzers of risk"。

4、One of the key ways Google achieves good results with fewer testers than many companies is that we rarely attempt to ship a large set of features at once.

    — 显然Google也倾向于增量的迭代开发,这种模式符合Google内部的role设置,同时,这种role设置也更好地促进了增量迭代开发的顺利高效开展。

5、Build the core of a product and release it the moment it is useful to as large a crowd as feasible, and then get their feedback and iterate. This is what we did with Gmail, a product that kept its beta tag for four years.

     Google often builds the minimum useful product as an initial version and then quickly iterates successive versions allowing for internal and user feedback and careful consideration of quality with every small step. Products proceed through canary, development, testing, beta, and release channels before making it to users.

   — 这似乎就是Google著名的"Beta"模式,目前很多互联网企业(特别是startup)均效仿之。

6、Instead of distinguishing between code, integration, and system testing, Google uses the language of small, medium, and large tests, emphasizing scope over form.

    Small tests cover a single unit of code in a completely faked environment. Medium tests cover multiple and interacting units of code in a faked or real environment. Large tests cover any number of units of code in the actual production environment with real and not faked resources.

    The general rule of thumb is to start with a rule of 70/20/10: 70 percent of tests should be small, 20 percent medium,
and 10 percent large.

   — Google内部的测试不是按照代码单元测试、集成测试以及系统测试这些典型的阶段划分的,而是用"small、medium、large、 enormous"这些词汇来描述测试的各个环节,这些词汇也是Google内部的"共同语言"。如何界定这些测试的scope呢?Google内部有一 套共享的测试执行系统,它通过test size来界定不同的test类型。比如:对small tests的要求是每方法(method)的测试执行时间不能超过100ms,如果1分钟仍然执行不完,则将被kill掉。

7、Keeping it simple and uniform is a specific goal of the Google platform: a common Linux distribution for engineering workstations and production deployment machines; a centrally managed set of common, core libraries; a common source,
build, and test infrastructure; a single compiler for each core programming language; language independent, common build specification; and a culture that respects and rewards the maintenance of these shared resources.

   — 在Google内部一切都是"整齐划一"的,大大降低了各种人员在熟悉、学习和使用过程中的工作量。可以看出,Google为了提升内部开发效率,真是无 所不用其极啊。另外Google内部这套完整的强大的基础设施工具、库、语言以及流程支撑想必也让大家垂涎三尺吧。

8、There is no set rule at Google for when SETs engage in a project, as there are no set rules for establishing when projects become “real.” A common scenario for new project creation is that some informal 20 percent effort takes a life of its own as an actual Google-branded product. Gmail and Chrome OS are both projects that started out as ideas that were not formally sanctioned by Google but overtime grew into shipping products with teams of developers and testers working on them.

No project gets testing resources as some right of its existence. The onus is on the development teams to solicit help from testers and convince them that their project is exciting and full of potential.

  — 这两段话既描述了SETs进入项目的时机,同时也从侧面反映出了Google内部产品的初期形成机制。在这种机制下,一些著名产品诸如Gmail、 Chrome等诞生了。个人很是认同这种自底向上的产品"产生机制",有利于员工创造力的充分展现。其实退一步来说,我们不一定非要公司明确规定设置 20%个人时间,只是我们在平时工作中主动去发现、去分析、思考和总结,我们一样可以"创造"出一些用于改善我们工作和生活的工具或产品,这些"成果"在 我们的日常工作中使用,逐渐被大家所接受,甚至于发展演化成熟,形成一个可盈利的产品或是贡献给开源社区,不是一样很好么。感觉国内的很多互联网公司里面 的一些同行正在做这些事情。

9、This is the convention at Google: Make the common case fast.

  — 这显然已经上升到了哲学的层次,不仅对开发测试过程的效率改进有着指导意义,对软件自身的调优也是一样富有价值。甚至于对我们的日常生活也是有帮助的。

10、Designs that seek to automate everything end-to-end all in one master test suite are generally a mistake. The larger an automation effort is, the harder it is to maintain and the more brittle it becomes as the system evolves. It’s the smaller, more special purpose automation that creates useful infrastructure and that attracts the most SWEs to write tests.

        Overinvesting in end-to-end automation often ties you to a product’s specific design.

  –  这又是Google内部对自动化测试的一种中肯的实用的理解。我们要自动化,但要掌握方法,不要大而全,要小且精,吸引SWE自己去写测试代码。过分追求全闭环的自动化测试会将你与一个产品的细节间建立依赖。

11、Google centers its development process around code reviews. There is far more fanfare about reviewing code than there is about writing it.
      
       These pre-submit rules cover simple things such as adherence to the Google coding style guide and more involved things such as ensuring that every existing test associated with the CL has been executed (the rule is that all tests must pass).

  — Google打造了一个以代码评审为中心的开发过程,建立了一套完整的日常开发流程以及评审流程。并通过一套完整的工具平台在代码提交评审前对代码进行各种自动化检查,让评审过程更加focus关键业务逻辑,而不是语法之类的细节。

12、Test Runtime Requirements
   – Each test must be independent from other tests so that tests can be executed in any order.
   – Tests must not have any persistent side effects. They must leave their environment exactly in the state when it started.

  — 这里点明测试执行的原则:测试case间无依赖,可任意顺序执行;测试执行应遵循"童子军"纪律:测试执行结束后,将环境恢复到测试起始状态。

13、带认证的测试(Test Certified)

  — Google内部建立了类似竞赛似的规则,对每个项目的测试水平进行认证,分为几个级别:从TC level1到TC level5。对于每个级别都有明确的指标,甚至是明确的达标数字,比如总测试覆盖率,各种类型(比如small)测试的覆盖率等。在每个项目的首页都会 看到该项目的认证级别。这种规则将促使项目SWE和SET不断地改善测试,来提升测试认证水平,间接地提升了产品的质量。

如发现本站页面被黑,比如:挂载广告、挖矿等恶意代码,请朋友们及时联系我。十分感谢! Go语言第一课 Go语言精进之路1 Go语言精进之路2 商务合作请联系bigwhite.cn AT aliyun.com

欢迎使用邮件订阅我的博客

输入邮箱订阅本站,只要有新文章发布,就会第一时间发送邮件通知你哦!

这里是 Tony Bai的个人Blog,欢迎访问、订阅和留言! 订阅Feed请点击上面图片

如果您觉得这里的文章对您有帮助,请扫描上方二维码进行捐赠 ,加油后的Tony Bai将会为您呈现更多精彩的文章,谢谢!

如果您希望通过微信捐赠,请用微信客户端扫描下方赞赏码:

如果您希望通过比特币或以太币捐赠,可以扫描下方二维码:

比特币:

以太币:

如果您喜欢通过微信浏览本站内容,可以扫描下方二维码,订阅本站官方微信订阅号“iamtonybai”;点击二维码,可直达本人官方微博主页^_^:
本站Powered by Digital Ocean VPS。
选择Digital Ocean VPS主机,即可获得10美元现金充值,可 免费使用两个月哟! 著名主机提供商Linode 10$优惠码:linode10,在 这里注册即可免费获 得。阿里云推荐码: 1WFZ0V立享9折!


View Tony Bai's profile on LinkedIn
DigitalOcean Referral Badge

文章

评论

  • 正在加载...

分类

标签

归档



View My Stats