|
HTML injection的背景:
1 现在的XSS就是跨站脚本攻击一般都是在有服务器交互的情况下在客户端产生的一些问题,那么在没有服务器交互的情况下呢? 2 另外就是很多人都认为html文件是绝对安全的,那么真的是这样么?
什么是HTML injection:
有交互才会产生漏洞,无论交互是怎么进行的,HTML文件并不是像大家想的那样没有任何交互,在HTML文件里还是会用到一些javascript来完成自己需要的一些动态效果,这样其实交互的地方还是有的,譬如地址栏的参数也就是location,用户所做的点击触发的事件,以及一些动态的DOM交互都会影响到javascript的执行导致漏洞的产生。
为什么要做HTML injection:
在Windows本地存在大量的HTML文件,如果这些HTML文件可以被injection的话,那么就可以利用本地的HTML文件在本地域内执行javascript,权限是非常高的。
如何寻找HTML injection:
寻找交互的地方:交互的地方就是上面说的地址栏等可能可以交互的地方,最常用的就是地址栏了,也就是javascript里的location,所以在HTML文件里寻找location.可能找到你需要的东西。 寻找危险的操作:HTML里危险的操作包括document.write,eval,对innerHTML这些属性的操作等等都可能会造成jnjection,当然也包括一些其他的可能导致执行脚本的操作。
实际的一个例子:
如果你安装了iis,那么很容易在c:\windows\Help\iisHelp\common\下面找到类似于下面的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html dir=ltr>
<head> <style> a:link {font:9pt/11pt 宋体; color:FF0000} a:visited {font:9pt/11pt 宋体; color:#4e4e4e} </style>
<META NAME="ROBOTS" CONTENT="NOINDEX">
<title>无法显示网页</title>
<META HTTP-EQUIV="Content-Type" Content="text-html; charset=gb2312"> </head>
<script> function Homepage(){ <!-- // in real bits, urls get returned to our script like this: // res://shdocvw.dll/http_404.htm#http://www.DocURL.com/bar.htm
//For testing use DocURL = "res://shdocvw.dll/http_404.htm#https://www.microsoft.com/bar.htm" DocURL=document.URL;
//this is where the http or https will be, as found by searching for :// but skipping the res:// protocolIndex=DocURL.indexOf("://",4);
//this finds the ending slash for the domain server serverIndex=DocURL.indexOf("/",protocolIndex + 3);
//for the href, we need a valid URL to the domain. We search for the # symbol to find the begining //of the true URL, and add 1 to skip it - this is the BeginURL value. We use serverIndex as the end marker. //urlresult=DocURL.substring(protocolIndex - 4,serverIndex); BeginURL=DocURL.indexOf("#",1) + 1; urlresult=DocURL.substring(BeginURL,serverIndex);
//for display, we need to skip after http://, and go to the next slash displayresult=DocURL.substring(protocolIndex + 3 ,serverIndex); insertElementAnchor(urlresult, displayresult); }
function HtmlEncode(text) { return text.replace(/&/g, ’&’).replace(/’/g, ’"’).replace(/</g, ’<’).replace(/>/g, ’>’); }
function TagAttrib(name, value) { return ’ ’+name+’="’+HtmlEncode(value)+’"’; }
function PrintTag(tagName, needCloseTag, attrib, inner){ document.write( ’<’ + tagName + attrib + ’>’ + HtmlEncode(inner) ); if (needCloseTag) document.write( ’</’ + tagName +’>’ ); }
function URI(href) { IEVer = window.navigator.appVersion; IEVer = IEVer.substr( IEVer.indexOf(’MSIE’) + 5, 3 );
return (IEVer.charAt(1)==’.’ && IEVer >= ’5.5’) ? encodeURI(href) : escape(href).replace(/%3A/g, ’:’).replace(/%3B/g, ’;’); }
function insertElementAnchor(href, text) { PrintTag(’A’, true, TagAttrib(’HREF’, URI(href)), text); }
[1] [2] 下一页 |