Chen Yangjian's Blog

Carpe diem - Seize the day

Designing for Evil

| Comments

最近在 Coding Horror 上看到的这篇文章,Designing for Evil

When you design your software, work under the assumption that some of your users will be evil: out to game the system, to defeat it at every turn, to cause interruption and denial of service, to attack and humiliate other users, to fill your site with the vilest, nastiest spam you can possibly imagine.

该文提到 Craigslist 与所谓黑客之间的无休止的争斗, 并引出上述的结论。这让我想到我前一阵做给同事们用的一个工作日志程序,姑且叫 Worklog 好了。

开发的原因很简单,组内每周需要向老大汇报一周工作进展及计划,原本的方式是 email,很是麻烦。 于是做了这个 Worklog,因为都是同事们使用,安全机制几乎没有,用户不需要登陆, 根据 IP 判断谁是谁(公司局域网固定 IP,并且有个机器编号),初次访问的时候设定名字, 之后就可以一直记录工作日志。

试运行第一天,全是叫 qwerty、asdf、1234 的,工作日志有 ................................''''''''''''\\\\\\\\\\\\\\\\---------.,,,,,,,,.||||||&&&&&&$$$$!!!@@@###^^^***、有 a'; DROP TABLE users;,有特长的有空的等等。

全组总共也就10来号人,大家都是同事,同样都有如此问题。

无怪乎时代杂志的所谓百大最具影响力人物网络调查背后的形同虚设的安全工作要 被别人耻笑了。

In early stages of the poll, Time.com didn’t have any authentication or validation – the door was wide open to any client that wanted to stuff the ballot box.

开始的时候,time.com 没有任何授权或者验证机制 —— 开门揖盗

Soon afterward, it was discovered that the Time.com Poll didn’t even range check its parameters to ensure that the ratings fell within the 1 to 100 range

不久后,还被发现 time.com 连投票范围都没有检查,用户提交的评分并没有被限制在 UI 显示的 1-100 的范围之内。

Shortly afterward, Time.com changed the protocol to attempt to authenticate votes by requiring a key be appended to the poll submission URL. The key consisted of an MD5 hash of the URL + a secret word (aka ‘the salt’). [hackers eventually] discovered that the salt [..] was poorly hidden in Time.com’s voting flash application. With the salt extracted, the autovoters were back online, rocking the vote.

再不久后,time.com 改了协议,试着去使用密钥。密钥是 URL 与一个密文的 MD5 算值。 结果,所谓黑客们发现该密文只不过藏在该投票 swf 程序里头。然后,自动投票机又复活了~

还有些后来的并没有考虑透彻的 13秒 限制之类,这里就不细说了。

总之,随时想着你的网站是给撒旦用的,就行了。

题外话,关于代码也有个金科玉律。“随时想着你的代码将给一个拿着沙鹰的暴徒维护,而且他还知道你的住址。”

Comments