BSI-Maßnahmenkatalog und Best Practices • OWASP Best Practices: Projektierung der Sicherheitsprüfung von Webanwendungen • OWASP Best Practices: Einsatz von Web Application Firewalls • WASC Web Application Firewall Evaluation Criteria • WASC-TC The WASC Threat Classification • HTTP State Management Mechanism (Cookie) – RFC 6265 → sic[!]sec GmbH www.sicsec.de
im Cookie ohne „secure“-Flag, ohne ausreichendes „path“-Attribut – Auslesen mitttels XSS in der Anwendung – Auslesen in anderen Anwendungen • Session-ID in der URL – Problem nur bei XSS oder Referer-Leakage • Session-ID im HTTP-Authentication-Header – nur MiTM wenn kein HTTPS • Session-ID im Refer(r)er Angriffspunkt: Session-Diebstahl
im Cookie je nach „secure“-Flag, bzw. „path“-Attribut – alle Anwendungen in der selben Domain: *.me.tld – RFC 6265: → 8. Security Considerations • Session-ID in der URL – nur Anwendung selbst, Benutzer wegen C&P • Session-ID im HTTP-Authentication-Header – nur Anwendung selbst (aber sehr schwierig) Angriffspunkt: Session-Diebstahl - Angriffsoberfläche
• Session-ID im Cookie oder der URL – XSS irgendwo in Anwendungen auf *.victim.tld – <img src=http://victim.tld/vuln.do;jsessionid=bindrinn /> • Ursachen – Session-ID wird vor Login vergeben – Session-ID wird nach Login nicht erneuert – Session-ID wird wieder verwendet (selten) – Anwendung erlaubt Cookie und URL-Rewriting
im Cookie unabhängig von „secure“-Flag, bzw. „path“-Attribut! – alle Anwendungen in der selben Domain: *.me.tld – RFC 6265: → 8. Security Considerations • Session-ID in der URL – Webseite irgendwo • Session-ID im HTTP-Authorization-Header – Anwendung, Web-, Application-Server (schwierig) Angriffspunkt: Session-Fixation – Angriffsoberfläche
• Session (in Anwendung) wird beim Logout nicht zerstört • Ursachen: – nur Session-ID wird „gelöscht“ – kein Timeout (absolut und „idle“) – multiple, concurrent Sessions nicht richtig verwaltet
• ist i.W. eine Folge der Session-Logout-Problematik • aber auch „Remember me“ und SSO • Logout erzwingen, serverseitigesTimeout • Session-Objekt in der Anwendung zerstören • kein SSO und „Remember me“ Maßnahmen
– Angriffsoberfläche • Angreifer ist Benutzer selbst – kann GET oder POST benutzen (auch AJAX usw.) • Angreifer nutzt CSRF (Benutzer ist Opfer) – nur mit Cookie oder HTTP-Authentication-Header • zusätzliche Token für jede Aktion verwenden siehe Anti-CSRF-Token http://victim.tld/safe.do?aktion&token=random-unique Maßnahmen
Request Forgery • URL löst Aktion aus • URL kann an beliebiger Stelle stehen, z.B. attacker.tld • URL ist (meist) unsichtbar, z.B. in <img src=...> Tag • betrifft: Cookie, HTTP-Authentication, SmartCard
Request Forgery – Angriffsoberfläche • Session-ID im Cookie, HTTP-Authentication-Header – schadhafter Link kann irgendwo stehen • Session-ID in der URL – CSRF nicht möglich • zusätzliches Anti-CSRF-Token für jede Aktion notwendig • muss eindeutig, nicht-eratbar, zufällig sein http://victim.tld/safe.do?aktion&token=random-unique Maßnahmen
Passwort als Hash in URL • Passwort-Reset-Funktion liefert URL zur Bestätigung http://victim.tld/recover.do/1cbb2ba737624db6c6d5cca6 c18e3c36/uid=0815 • altes Passwort soll noch nicht geändert werden • Benutzer soll Änderung bestätigen • keine Speicherung serverseitig („tote“ Daten vermeiden) Motivation der Entwickler
Passwort als Hash in URL – Angriffsoberfläche • Passwort-Preisgabe • DoS auf Benutzerkonto http://victim.tld/recover.do/deadbeaf/uid=0815 • DoS auf alle Benutzer • keine Passwörter in der URL, Hash immer salzen • Informationen (uid=0815) verschlüsseln • ORM, Datenbank Maßnahmen
Business-Logik und ORM-Injection • Anwendung liefert bei Fehleingaben Fehlermeldung • Anwendung liefert bei „Manipulation“ eine neue Seite • (blind) Hibernate-Injection • Passwort-Hash
ORM-Injection – Angriffsoberfläche • HQL unterstützt UNION-Operator nicht • jedes Teil-Statement, dass mit UNION eingeleitet wird, wird verworfen → fehlerhafte Statements werden ausgeführt • Anwendung liefert „user friendly“ Fehlermeldung • Passwort als MD5-Hash, ungesalzen!
Hibernate • Hibernate bildet Java-Objekte auf die Strukturen einer relationalen Datenbank ab • Hibernate unterstützt: – Hibernate Query Language (HQL) – natives SQL – Criteria – Syntax analog zu der von SQL – Referenziert werden nicht Tabellen und Spalten, sondern Objekte und Attribute
Business-Logik – „Feature“ • Benutzer kann seinen Login-Namen ändern • vor Änderung des Login-Namens prüft das System, ob es den neuen Namen bereits gibt (uniqueness) • falls der neue Name bereits existiert, erfolgt keine Änderung und es erscheint eine Fehlermeldung:
HQL – Implementierung • HQL Statement, analog zu select count(*) from ... • sUserLoginName kommt (ungeprüft) vom Client • Login-Name existiert falls lCount größer als Null ist → Fehlermeldung wird ausgegeben
HQL – Injection SELECT COUNT(u) FROM User u WHERE u.userLoginName = 'admin' and u.userPassword like '%' union' SELECT COUNT(u) FROM User u WHERE u.userLoginName = 'admin' and u.userPassword like '%' union' • union wirkt dabei wie ein Kommentar bis Zeilenende
BigDecimal() Translates the string representation of a BigDecimal into a BigDecimal. The string representation consists of an optional sign, '+' ( '\u002B') or '-' ('\u002D'), followed by a sequence of zero or more decimal digits ("the integer"), optionally followed by a fraction, Translates the string representation of a BigDecimal into a BigDecimal. The string representation consists of an optional sign, '+' ( '\u002B') or '-' ('\u002D'), followed by a sequence of zero or more decimal digits ("the integer"), optionally followed by a fraction, http://docs.oracle.com/javase/6/docs/api/java/math/BigDecimal.html optionally followed by an exponent. optionally followed by an exponent.
BigDecimal() Translates the string representation of a BigDecimal into a BigDecimal. The string representation consists of an optional sign, '+' ( '\u002B') or '-' ('\u002D'), followed by a sequence of zero or more decimal digits ("the integer"), optionally followed by a fraction, optionally followed by an exponent. The fraction consists of a decimal point followed by zero or more decimal digits. The string must contain at least one digit in either the integer or the fraction. The number formed by the sign, the integer and the fraction is referred to as the significand. The exponent consists of the character 'e' ('\u0065') or 'E' ('\u0045') followed by one or more decimal digits. The value of the exponent must lie between -Integer.MAX_VALUE (Integer.MIN_VALUE+1) and Integer.MAX_VALUE, inclusive. • Translates the string representation of a BigDecimal into a BigDecimal. The string representation consists of an optional sign, '+' ( '\u002B') or '-' ('\u002D'), followed by a sequence of zero or more decimal digits ("the integer"), optionally followed by a fraction, optionally followed by an exponent. The fraction consists of a decimal point followed by zero or more decimal digits. The string must contain at least one digit in either the integer or the fraction. The number formed by the sign, the integer and the fraction is referred to as the significand. The exponent consists of the character 'e' ('\u0065') or 'E' ('\u0045') followed by one or more decimal digits. The value of the exponent must lie between -Integer.MAX_VALUE (Integer.MIN_VALUE+1) and Integer.MAX_VALUE, inclusive. • http://docs.oracle.com/javase/6/docs/api/java/math/BigDecimal.html