Transcript
Page 1: Sichere Web-Applikationen am Beispiel von Django

Sichere Web-Applikationen am Beispiel von Django

Markus Zapke-Gründemann LinuxTag 2014

Page 2: Sichere Web-Applikationen am Beispiel von Django

Markus Zapke-Gründemann

Softwareentwickler seit 2001

Python, Django und Mercurial

Inhaber von transcode

Vorstand des Deutschen Django-Vereins

keimlink.de // @keimlink

Page 3: Sichere Web-Applikationen am Beispiel von Django

Einführung

Page 4: Sichere Web-Applikationen am Beispiel von Django

DjangoPython Web-Application Framework

Open Source (BSD-Lizenz)

Rapid Development

Model Template View (MTV)

Object Relational Mapper (ORM)

www.djangoproject.com

Page 5: Sichere Web-Applikationen am Beispiel von Django

OWASP

Open Web Application Security Project

Non-Profit-Organisation

Alle Materialien unter freier Lizenz

www.owasp.org

Page 6: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 10

https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project

Page 7: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 10

Page 8: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

Page 9: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

Page 10: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

3. Cross-Site Scripting (XSS)

Page 11: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

3. Cross-Site Scripting (XSS)

4. Insecure Direct Object References

Page 12: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

3. Cross-Site Scripting (XSS)

4. Insecure Direct Object References

5. Security Misconfiguration

Page 13: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

3. Cross-Site Scripting (XSS)

4. Insecure Direct Object References

5. Security Misconfiguration

6. Sensitive Data Exposure

Page 14: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

3. Cross-Site Scripting (XSS)

4. Insecure Direct Object References

5. Security Misconfiguration

6. Sensitive Data Exposure

7. Missing Function Level Access Control

Page 15: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

3. Cross-Site Scripting (XSS)

4. Insecure Direct Object References

5. Security Misconfiguration

6. Sensitive Data Exposure

7. Missing Function Level Access Control

8. Cross-Site Request Forgery (CSRF)

Page 16: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

3. Cross-Site Scripting (XSS)

4. Insecure Direct Object References

5. Security Misconfiguration

6. Sensitive Data Exposure

7. Missing Function Level Access Control

8. Cross-Site Request Forgery (CSRF)

9. Using Components with Known Vulnerabilities

Page 17: Sichere Web-Applikationen am Beispiel von Django

OWASP Top 101. Injection

2. Broken Authentication and Session Management

3. Cross-Site Scripting (XSS)

4. Insecure Direct Object References

5. Security Misconfiguration

6. Sensitive Data Exposure

7. Missing Function Level Access Control

8. Cross-Site Request Forgery (CSRF)

9. Using Components with Known Vulnerabilities

10.Unvalidated Redirects and Forwards

Page 18: Sichere Web-Applikationen am Beispiel von Django

SQL Injection

>>> cmd = "UPDATE animals SET name='%s' WHERE id='%s'" % (name, id)

>>> cursor.execute(cmd)

Page 19: Sichere Web-Applikationen am Beispiel von Django

SQL Injection

Exploits of a Mom by Randall Munroe (cc-by-nc)

Page 20: Sichere Web-Applikationen am Beispiel von Django

SQL Injection

Exploits of a Mom by Randall Munroe (cc-by-nc)

Datenbank-Eingaben bereinigen!

Page 21: Sichere Web-Applikationen am Beispiel von Django

SQL Injection

>>> from animals.models import Animal

>>> Animal.objects.filter(id=id).update(name=name)

Page 22: Sichere Web-Applikationen am Beispiel von Django

Broken Authentication and Session Management

http://example.com/sale/saleitems;sessionid= 2P0OC2JSNDLPSKHCJUN2JV?dest=Hawaii

Page 23: Sichere Web-Applikationen am Beispiel von Django

Cross-Site Scripting (XSS)

<h3>Preparation</h3>

{{ recipe.preparation }}

!

<script>alert('The best recipe in the world!')</script>

Heat the water in the pot to 100 °C.

!

<p>&lt;script&gt;alert(&#39;The best recipe in the <world!&#39;)&lt;/script&gt;</p>

<p>Heat the water in the pot to 100 °C.</p>

Page 24: Sichere Web-Applikationen am Beispiel von Django

Cross-Site Scripting (XSS)

<h3>Preparation</h3>

{{ recipe.preparation|safe }}

!

<script>alert('The best recipe in the world!')</script>

Heat the water in the pot to 100 °C.

!

<p><script>alert('The best recipe in the world!')</script></p>

<p>Heat the water in the pot to 100 °C.</p>

Page 25: Sichere Web-Applikationen am Beispiel von Django

Security Misconfiguration

DEBUG = True

Page 26: Sichere Web-Applikationen am Beispiel von Django

Sensitive Data Exposure

>>> from django.contrib.auth.models import User

>>> User.objects.get(pk=1).password

u'pbkdf2_sha256$10000$sDN75YuuoUWi$Ua/H364jPAPTPBiAyJ1fc0uB4ClzQD5yGFisYrxCo40='

Page 27: Sichere Web-Applikationen am Beispiel von Django

Cross-Site Request Forgery (CSRF)

http://example.com/app/transferFunds?amount=1500 &destinationAccount=4673243243

Page 28: Sichere Web-Applikationen am Beispiel von Django

Cross-Site Request Forgery (CSRF)

<form method="post" accept-charset="utf-8">

{{ form.as_p }}

{% csrf_token %}

<input type="submit" value="Submit"/>

</form>

Page 29: Sichere Web-Applikationen am Beispiel von Django

Cross-Site Request Forgery (CSRF)

<form method="post" accept-charset="utf-8">

...

<input type='hidden' name='csrfmiddlewaretoken' value='gB3bL3MU2fr8BCQXXrNV6pfS7GJYBdU0' />

<p><input type="submit" value="Submit" /></p>

</form>

Page 30: Sichere Web-Applikationen am Beispiel von Django

Clickjacking

X-Frame-Options Header aktivieren: MIDDLEWARE_CLASSES = (

...

'django.middleware.clickjacking.XFrameOptionsMiddleware',

...

)

Page 31: Sichere Web-Applikationen am Beispiel von Django

Information Leakage

Page 34: Sichere Web-Applikationen am Beispiel von Django

Code sicher(er) machen

Code Review

Security Scanner

Security Audit

Page 35: Sichere Web-Applikationen am Beispiel von Django

Danke! !

www.transcode.de

@keimlink


Recommended