1 / 27

Cookies poisoning

Cookies poisoning. Prof. Stefano Bistarelli. C Consiglio Nazionale delle Ricerche Iit Istituto di Informatica e Telematica - Pisa. Università “G. d’Annunzio” Dipartimento di Scienze, Pescara. Cookies poisoning cookies gessable broken authentication session hijacking.

ayla
Download Presentation

Cookies poisoning

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cookies poisoning Prof. Stefano Bistarelli CConsiglio Nazionale delle Ricerche IitIstituto di Informatica e Telematica - Pisa Università “G. d’Annunzio”Dipartimento di Scienze, Pescara

  2. Cookies poisoningcookies gessablebroken authenticationsession hijacking Prof. Stefano Bistarelli CConsiglio Nazionale delle Ricerche IitIstituto di Informatica e Telematica - Pisa Università “G. d’Annunzio”Dipartimento di Scienze, Pescara

  3. A3. Broken Authentication e Session Management • Processo di autenticazione • Meccanismo di autenticazione implementato non adeguato • Gestione delle sessioni web • HTTP protocollo stateless: è necessario implementare una corretta gestione delle sessioni S. Bistarelli - Metodologie di Secure Programming

  4. A3. Broken Authentication Meccanismi di autenticazione non adeguati S. Bistarelli - Metodologie di Secure Programming

  5. A3. Broken Authentication (2) S. Bistarelli - Metodologie di Secure Programming

  6. Carta di identità Mario Rossi Buongiorno Mario Rossi Ticket #33 Ticket #33: mi dia 1000 euro dal mio conto Tenga 1000 euro Sig. Rossi A.3: Concetto di “gestione della sessione” nel mondo reale Dipendente Banca A. Ferrari Mario Rossi Verifica identità in base alla carta di identità Num. 33 Firma: A.Ferrari Verifica identità in base al ticket Meccanismo di autenticazione? Meccanismo di gestione della sessione? Livello di sicurezza del sistema? S. Bistarelli - Metodologie di Secure Programming

  7. Verifica credenziali: se ok  client autenticato  Generazione del cookie [4] Welcome page personale e Set Cookie=TWFyaW8123 Cookie=TWFyaW8123 Cookie=TWFyaW8123 Token di autenticazione Verifica del cookie:  Identifica il mittente Invio del contenuto al DEST [5] Richiesta dell’estratto CC (https://www. mia-banca.it/cont.jsp) [6] Invio del contenuto A.3: Gestione della sessione web --Procedura di autenticazione-- Web Server Mario Rosssi [1] https://www.mia-banca.it [2] Invio form di autenticazione via HTTPS [3] inserisce username/password via HTTPS Username/password --Richieste seguenti-- S. Bistarelli - Metodologie di Secure Programming

  8. Cookie=TWFyaW8122 • Verifica del cookie: • TWFyaW8122 • Identifica il mittente Paolo Verdi • Invio del contenuto di Paolo Verdi al destinatario Mario Rossi [5a]Richiesta dell’estratto CC (https://www. mia-banca.it/cont.jsp) [6a] Invio del contenuto di Paolo Verdi A.3: Furto di identità Mario Rossi Per implementare una corretta gestione delle sessioni è necessario proteggere sia le credenziali di autenticazione di un utente che i token di sessione generati dal server ed assegnati all’utente Se altero la GET HTTP, “forgiando” il cookie sono in grado di accedere al contenuto di un’altra persona I dati relativi all’utenza di Verdi non sono stati adeguatamente protetti S. Bistarelli - Metodologie di Secure Programming

  9. Cookie poisoning Alterando campi forniti al client tramite un cookie (stato), un attaccante puo’ impersonare un utente per accedere a servizi web. Cookie: lang=en-us; ADMIN=no; y=1 ; time=10:30GMT ; Cookie: lang=en-us; ADMIN=yes; y=1 ; time=12:30GMT ; Cookie guessable Cookie:aefdsg6757nb90 ;  M.Rossi Cookie:aefdsg6757nb92 ;  G.Verdi Cookie:aefdsg6757nb9? ;  V.Bianchi A.3: Errata gestione della sessione - Furto di identità S. Bistarelli - Metodologie di Secure Programming

  10. Review your account • Find where the confidential data is S. Bistarelli - Metodologie di Secure Programming

  11. So Many Cookies • TestSess • ‘Site cookie’ • Seg • TestPerm • ProfileAddressVerified • ProfileID • MEMUSER • USERID • SESSIONUSERID • PROFILE S. Bistarelli - Metodologie di Secure Programming

  12. Eliminate each one until the ones that matter are left • In this case ‘SESSIONUSERID=505741’ • Is the number incremental? • Keep everything the same except decrement the number – ‘SESSIONUSERID=505740’ S. Bistarelli - Metodologie di Secure Programming

  13. Victoria’s Secret Victoria’s Secret • Victoria’s Secret, November 27, 2002 • Order ID parameter in the order status page • Order status page bound to your session, but not the parameters • $50,000 fine and publicity in 2003 S. Bistarelli - Metodologie di Secure Programming

  14. Quale e’ la soluzione al problema? • Suggerimenti .. S. Bistarelli - Metodologie di Secure Programming

  15. Usare hashing, encryption, nonces, timestamp S. Bistarelli - Metodologie di Secure Programming

  16. Lab: • In this scenario, you have a public-facing web application accepts anonymous requests from the Internet. Cookies are used to store state on the client machines, but the cookies are being tampered with by malicious users, leading to possible cross-site scripting attacks and general data tampering mischief. S. Bistarelli - Metodologie di Secure Programming

  17. Controllando codice: • Page_load chiama display_cookie string cookieValue = readCookie(); if (null == cookieValue) { lblCookieInfo.Text = "No cookie was found."; } else { // Note that there is an XSS vulnerability here. // The user can change the contents of any cookie! lblCookieInfo.Text = "Cookie found: " + cookieValue; } • Su tag: • <asp:Label ID="lblCookieInfo" runat="server"></asp:Label><br /> • Possiamo usare cookie come input e fare un XSS attack come prima!!! • (provare a settare come cookie <script>alert(‘ciao’)</script>  S. Bistarelli - Metodologie di Secure Programming

  18. Modifichiamo cookie in black • Per IE andare sotto • C:\Documents and Settings\Stefano Bistarelli\Cookies • Per firefox • C:\Documents and Settings\Stefano Bistarelli\Dati applicazioni\Mozilla\Firefox\Profiles • Nota: • <pages validateRequest="false"/> • E se lo modifichiamo con lo <script> …. ?? • Funziona!!!  • Ma su IE no  S. Bistarelli - Metodologie di Secure Programming

  19. Perche? • IE ha un controllo sulla lunghezza dei cookies • Ma ora lo bypassiamo • Usiamo tool per editare cookies • iecv.zip • Altro problema i caratteri  • Bypassiamo • Usiamo X al posto dei caratteri vietati e popi editiamo a mano il file!! • FUNZIONA!!! S. Bistarelli - Metodologie di Secure Programming

  20. Difesa: • Controllare i cookies come se fossero un input!! • Al solito <pages validateRequest=“true"/> • A tamper detector: • Add new item, new class TamperDetector using System; using System.Text; using System.Security.Cryptography; using System.Configuration; public class TamperDetector { public static string AddTamperDetection(string s) { return s; } public static string CheckAndRemoveTamperDetection(string s) { return s; } public static string GenerateRandomKey() { return string.Empty; } } public class DataTamperingException : Exception { public DataTamperingException(string msg) : base(msg) {} } S. Bistarelli - Metodologie di Secure Programming

  21. AddTamperDetection • public static string AddTamperDetection(string s) { byte[] data = Encoding.UTF8.GetBytes(s); byte[] hash = getKeyedHash().ComputeHash(data); return Convert.ToBase64String(hash) + '|' + s; } • static HMACSHA1 getKeyedHash() { string skey = ConfigurationManager.AppSettings["validationKey"]; byte[] key = Convert.FromBase64String(skey); return new HMACSHA1(key); } S. Bistarelli - Metodologie di Secure Programming

  22. CheckAndRemoveTamperDetection • public static string CheckAndRemoveTamperDetection(string s) { int i = s.IndexOf('|'); if (-1 == i) throw new DataTamperingException("Unexpected format."); string prefix = s.Substring(0, i); string suffix = s.Substring(i + 1); byte[] hash = Convert.FromBase64String(prefix); byte[] data = Encoding.UTF8.GetBytes(suffix); byte[] computedHash = getKeyedHash().ComputeHash(data); if (!isEqual(hash, computedHash)) throw new DataTamperingException("String has been modified!"); return suffix; } • static bool isEqual(byte[] a, byte[] b) { if (a.Length != b.Length) return false; for (int i = 0; i < a.Length; ++i) if (a[i] != b[i]) return false; return true; } S. Bistarelli - Metodologie di Secure Programming

  23. GenerateRandomKey • Usata per salvare su web.config la chiave per fare hash • public static string GenerateRandomKey() { byte[] rnd = new byte[16]; // 128 bits new RNGCryptoServiceProvider().GetBytes(rnd); return Convert.ToBase64String(rnd); } S. Bistarelli - Metodologie di Secure Programming

  24. Change to write and read cookie • cookie.Value = TamperDetector.AddTamperDetection(value); • return TamperDetector.CheckAndRemoveTamperDetection(cookie.Value); S. Bistarelli - Metodologie di Secure Programming

  25. Gestione ecc su displaycookie • Cambia displaycookie per gestire eccezione void displayCookie() { try { string cookieValue = readCookie(); if (null == cookieValue) { lblCookieInfo.Text = "No cookie was found."; } else { // Note that there is an XSS vulnerability here. // The user can change the contents of any cookie! lblCookieInfo.Text = "Cookie found: " + cookieValue; } } catch (DataTamperingException) { lblCookieInfo.Text = "Cookie has been tampered with or corrupted!"; } } S. Bistarelli - Metodologie di Secure Programming

  26. Aggiunta chiave a web.config • Aggiungi a Page_Load in Default.aspx • lblRandomKey.Text = TamperDetector.GenerateRandomKey(); • Run: • Copia su web.config la stringa <appSettings> <add key="validationKey" value=""/> </appSettings> S. Bistarelli - Metodologie di Secure Programming

  27. Se ora modifico i cookie • Errore!!!  S. Bistarelli - Metodologie di Secure Programming

More Related