从一个另类的hook解密方法学习javascript hijacking

2008-04-25 00:08:02 0 2738
晚上习惯性的去126邮箱看Ph4nt0m的讨论贴,突然看到一位同学发帖求一段javascript的加密代码的解密版本,于是另外一个大牛回答他并给出了解密方法:

我的解密方法,hook:
document.write = window.alert;
eval = window.alert;
把这两行加在加密代码前面,然后执行,弹出message后ctrl+c。

我回来试了下,解密代码确实被alert出来了,但我没明白这两句话的意思(事后看看,一目了然的两句话却被我折腾N久),我去bingo群咨询,他们说这代码太垃圾了,强行赋值原有的属性,简直太无聊了,可是却没有指出我理解错误的所在,不过得到了一段代码点醒了我:
SB = document.write;
SB('hello');
代码只是解释了赋值的意思,却把本来我要得到的东西扯远了。于是我继续百度,终于我发现了一篇也是来自于Ph4nt0m的文章,专门讲javascript函数劫持的,于是我第一次接触到javascript hijacking,看完之后我的问题也迎刃而解了,自己写了下:
eval= document.write=function(s){
window.alert(s);
}
等同于邮件里那段:
document.write = window.alert;
eval = window.alert;
终于我知道我犯了两个错误:

第一、加密的js脚本里不止有eval,也有document.write,而且我把哪个赋值给哪个看错了,以致到群里问惹笑话;

第二、我一心想把解密后的代码document.write出来,因为我觉得window.alert不好拷贝。

javascript函数劫持那篇文章里,我看到里一个好玩的想法,那就是:

设置陷阱实时捕捉跨站测试者,搞跨站的人总习惯用alert来确认是否存在跨站,如果你要监控是否有人在测试你的网站xss的话,可以在你要监控的页面里hook alert函数,记录alert调用情况。


感觉创意无处不在啊,曾几何时,我也是喜欢去含有留言板的网站去留个<script>alert(/xss/)</script>,通过这个劫持,可以joking那些所谓的hacker了...

网上找了下JavaScript Hijacking的资料:JavaScript Hijacking

A few readers have asked for my opinion regarding the recent fuss over a "new kind of web-based attack" that's being called JavaScript hijacking:

Security researchers have found what they say is an entirely new kind of web-based attack, and it only targets the Ajax applications so beloved of the Web 2.0 movement.

Although the attack is not at all new, it is worth reading about if you're using Ajax and don't know what CSRF is. Jeremiah's Gmail exploit from early last year is a good example that uses CSRF for information disclosure, which is all this really is.

Being in the web application security profession myself, I appreciate the strong desire among my peers to increase awareness, but I'm not fond of the tendency to deliberately misinform people and incite fear based upon false pretenses. We should strive to offer clarity, not confusion. In this particular case, there are also some strong technical concerns to consider.

In some of the comments I've read in various places, people new to CSRF recommend checking the Referer header as a safeguard. This does not offer sufficient protection against CSRF, because an attacker can forge HTTP headers with Flash.


简单翻译了一下:

一些读者问我对近来出现的一种被称为JavaScript hijacking的新web攻击技术的看法:

安全研究者发现他们所说的是一个完全崭新的web攻击技术,它的目标是基于ajax的web2.0应用程序。

虽然这个攻击不是那么新,但如果你在使用ajax却不知道什么是CSRF,这个还是值得一看的。早期Jeremiah的Gmail溢出漏洞就是一个很好的CSRF使用的例子。

作为一个web应用程序安全专家,我有很强的增长意识的求知欲,但我不喜欢故意用错误信息误导大家,我们应该提供清晰不易混淆的观点。在此特定情况下,也有一些很强技术关注值得考虑。

在不同的地方我阅读了很多评论,现在最新认识CSRF的人们通过检查头部中的Referer作为一个安全防卫。这并不能完全防护csrf ,因为攻击者可以通过建立HTTP头部。


看完这段文献,我又有点感觉了,去年那个通过构造flash头部实在XSS的原来也是JavaScript hijacking,今天看到对于构造头部,还可以通过firefox的插件...学无止境啊...

关于作者

oldjun132篇文章575篇回复

评论0次

要评论?请先  登录  或  注册