SlideShare a Scribd company logo
1 of 34
A Case Study of
              Django
Web Applications that are Secure by Default


         Mohammed ALDOUB

               @Voulnet
Web Security Essentials
• The essentials of web application security are still not
  well understood.

• Most developers have little to no idea about web
  security fundamentals.

• Higher adoption to new web technologies, but no
  accompanying security awareness.
Web Security Essentials
• The basic idea of web security: Never trust users,
  and never trust their data. No exceptions.

• Many layers exist in web technologies, and therefore
  many attack vectors and possibilities.

• Web developers must understand risks and
  mitigations for all web layers.
Problems in Applying Web Security
• Web security cannot be achieved if developers are
  not well trained in security. Education is key.

• Deadlines will almost always result in security
  vulnerabilities. Developers who are too busy and
  under pressure will not focus on security.

• Security is not integrated early in the development
  process, so it gets delayed/forgotten.
Bad Practices in Web Security
• Developers don’t validate user input.

• Even if they validate it, they do it poorly or out of
  context.

• Developers make wrong assumptions about security:
   – “It’s ok, we use SSL!”
   – “The Firewall will protect us”
   – “Who will think of attacking this function?”

• Most developers copy/paste code from the internet.
  Admit it.
Bad Practices in Web Security
• Session/password management is done poorly:
   – Sessions are easy to forge by attackers.
   – Passwords are stored as plaintext.


• Server & Database configuration/security are not
  understood by web developers.

• Developers don’t realize the threats on end users:
   – Cross Site Scripting (XSS)
   – Cross Site Request Forgery (CSRF)
• Django is a Web Application Framework, written in
  Python

• Allows rapid, secure and agile web development.

• Write better web applications in less time & effort.
• Django is loaded with security features that are used
  by default.

• Security by default provides great protection to
  developers with no security experience

• Django makes it more difficult to write insecure
  code.
• Django is used by many popular websites/services:
Security Features of Django
• Django provides many default protections against
  web threats, mainly against problems of:
   –   User Management
   –   Authorization
   –   Cookies
   –   SQL Injection
   –   Cross Site Scripting (XSS)
   –   Cross Site Request Forgery (CSRF)
   –   Clickjacking
   –   Files
   –   E-mail Header Injection
   –   Cryptography
   –   Directory Traversal
User Management
• Developers make many mistakes in user
  management.

• Passwords are stored/transferred as plaintext.

• Users are exposed if databases get leaked.

• Weak authentication methods are used by
  inexperienced developers.
User Management
• Django provides a default User model that can be used in
  any website. It comes equipped with correct session
  management, permissions, registration and login.

• Developers don’t need to re-invent the wheel and re-
  introduce user management risks.

• Django provides strong password hashing methods
  (bcrypt, PBKDF2, SHA1), with increasing work factors.
•
• Django makes passwords very hard to crack.
User Management
• Django provides easy methods for user management
  such as is_authenticated(), permission_required(),
  requires_login(), and more, offsetting difficult session
  and permission code away from the developer.

• Django provides secure default password reset and login
  redirection functionality. Developers don’t need to create
  password reset forms and introduce risks.

• By using Django’s user management module, developers
  will not make mistakes such as ‘admin=true’ in cookies!
Clickjacking
• Clickjacking is an attack where an attackers loads an
  invisible page over a visible one. The user thinks he is
  clicking on the visible page, but he’s actually clicking on
  invisible buttons and links.

• Can be used to trick users into buying items, deleting
  content or adding fake friends online.

• Django provides direct protection against Clickjacking
  attacks using the X-Frame-Options header. Only one line
  of code!
Clickjacking Example




Image taken from ‘Busting Frame Busting’ research paper (found in references)
Cross Site Scripting (XSS)
• XSS is one of the most dangerous and popular
  attacks, where users instead of servers are targeted.

• In an XSS attack, an attacker runs evil scripts on the
  user’s browser, through a vulnerable website.

• It can be used to steal cookies, accounts, install
  malware, deface websites and many more uses.
Cross Site Scripting (XSS)
• XSS is very easy to introduce by ignorant developers,
  example:
  <?php
  echo "Results for: " . $_GET["query"];
  ?>

• It’s okay if the search query was Car, but what if the
  attacker entered…
  <script>alert(document.cookie)</script>
Cross Site Scripting (XSS)
• Evidently XSS is a critical attack, so Django provides great
  default protections against it.

• HTML output is always escaped by Django to ensure that user
  input cannot execute code.

• Django’s templating engine provides autoescaping.

• HTML Attributes must always be quoted so that Django’s
  protections can be activated.

• For extra XSS protections, use ESAPI, lxml, html5lib, Bleach or
  Markdown
SQL Injection (SQLi)
• SQL Injection is a dangerous attack in which evil data is sent to
  the database to be executed as destructive commands.

• Developers write SQL queries in a wrong way, allowing
  attackers to inject SQL commands into the query, to be
  executed as SQL code. Example:
string sql = “SELECT * FROM USERS WHERE name=‘” +
Request[‘username’] + “’”;

• Looks innocent, but what if the user entered ‘; DROP
  TABLE USERS;-- ?
SQL Injection (SQLi)
• SQL injection attacks are used to read and corrupt databases,
  take complete control over servers as well as modify web
  pages (and therefore steal user sessions or install malware)

• The good news is that Django provides excellent defense
  against SQL Injection!

• Django uses ORM and query sets to make sure all input is
  escaped & validated.
• Developers do not need to write any SQL. Just write Python
  classes and Django will convert them to SQL securely!
SQL Injection (SQLi)
• No matter where input comes from (GET,POST,COOKIES),
  Django will escape all input that goes to the database.

• Even if developers needed to write raw SQL, they can use
  placeholders like "Select * from users where id = %s ” which
  will safely validate input.
Cookies
• Django sets cookies to HttpOnly by default, to prevent
  sessions from getting stolen in most browsers.

• Session ID are never used in URLs even if cookies are disabled.

• Django will always give a new session ID if a user tried a non-
  existent one, to protect against session fixation.


• Cookies can be digitally signed and time-stamped, to
  protect against tampering of data.
Files
• Django provides excellent protection to files.

• No webroot concept in Django. Only the directories and files
  you allow are requested. Even if attackers upload a file, it is
  only downloaded if you allow it in URLConf.

• Django executes Python code from the outside of the web
  root, so attackers cannot retrieve any files not explicitly
  allowed from the web root.
Cross Site Request Forgery (CSRF)
• CSRF is an attack where an attacker can force users of a
  website to perform actions without their permission.

• If a user is logged into website A, an attacker can let a user
  visit website B, which will perform actions on website A on
  behalf of the user.

• This happens because the forms in website A are not
  protected against CSRF.

• Basically CSRF means evil websites can let users of other
  websites perform actions without user permission.
Cross Site Request Forgery (CSRF)
• Example: A form in website A allows a logged in user to delete
  his account. If there is no CSRF protection, website B can force
  visitors to delete their account on website A.

• Example: Suppose website B has this HTML form in its code.
  What happens if a user of website A visits B?

  <form
  action="http://websiteA.com/deleteMyAccount.php”
  method=”post” >
  </form>
Cross Site Request Forgery (CSRF)
• The effects of CSRF is that attackers can make users perform
  ANY action on the vulnerable website.
• Django provides CSRF protections for all POST,PUT,DELETE
  requests (according to RFC2616).
• If website A used Django CSRF protection, the form would be:

   <form action=”/deleteMyAccount.php” method=”post”
   >
   <input type='hidden' name='csrfmiddlewaretoken'
   value='Aes4YiAfBQwCS8d4T1ngDAa6jJQiYDFs' />
   </form>
E-mail Header Injection
• E-mail Header injection is a less popular attack that targets
  weak email-sending forms in websites.
• By crafting a special string, attackers can use your email form
  to spend spam through your mail server, resulting in your
  domains/IPs getting blocked and possible worse effects.

• Example email form:

   To: mycustomer@example.com
   Subject: Customer feedback
   <email content here>
E-mail Header Injection
• What if the attacker supplies the following data as the email
  content? They will be able to use your website as a spam
  base.
• “ncc: spamVictim@example.comn<spam content>”
• It would be:
To: mycustomer@example.com
Subject: Customer feedback
cc: spamVictim@example.com
<spam message content, buy drugs, lose weight or something>

• Django provides default protection by using the built-in email
  form.
Final Remarks
• It must be understood that nothing can protect developers if
  they refuse to learn about web security and vulnerabilities.

• The point of Django’s default security features is to make it
  very easy to add security, and very difficult to remove
  security.

• However, developers still need to learn the basics of security
  and risk assessment.

• Knowledge is the best defense against web attacks.
References
• http://davidbliss.com/sites-built-using-django

• https://docs.djangoproject.com/en/1.4/topics/security/

• http://www.djangobook.com/en/2.0/chapter20/

• http://seclab.stanford.edu/websec/framebusting/framebust.p
  df
Questions?


• Do not hesitate to ask any question!




• Do not hesitate to let your developers try Django in the
  workplace! It could be your road to increased productivity and
  security!

More Related Content

What's hot

Web Security: A Primer for Developers
Web Security: A Primer for DevelopersWeb Security: A Primer for Developers
Web Security: A Primer for DevelopersMike North
 
Evolution Of Web Security
Evolution Of Web SecurityEvolution Of Web Security
Evolution Of Web SecurityChris Shiflett
 
Become a Security Ninja
Become a Security NinjaBecome a Security Ninja
Become a Security NinjaPaul Gilzow
 
Web security-–-everything-we-know-is-wrong-eoin-keary
Web security-–-everything-we-know-is-wrong-eoin-kearyWeb security-–-everything-we-know-is-wrong-eoin-keary
Web security-–-everything-we-know-is-wrong-eoin-kearydrewz lin
 
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)Brian Huff
 
Web security presentation
Web security presentationWeb security presentation
Web security presentationJohn Staveley
 
Owasp advanced mobile-application-code-review-techniques-v0.2
Owasp advanced mobile-application-code-review-techniques-v0.2Owasp advanced mobile-application-code-review-techniques-v0.2
Owasp advanced mobile-application-code-review-techniques-v0.2drewz lin
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encodingEoin Keary
 
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka IrongeekMutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka IrongeekMagno Logan
 
Owasp2013 johannesullrich
Owasp2013 johannesullrichOwasp2013 johannesullrich
Owasp2013 johannesullrichdrewz lin
 
OWASP Top 10 vs Drupal - OWASP Benelux 2012
OWASP Top 10 vs Drupal - OWASP Benelux 2012OWASP Top 10 vs Drupal - OWASP Benelux 2012
OWASP Top 10 vs Drupal - OWASP Benelux 2012ZIONSECURITY
 
ECrime presentation - A few bits about malware
ECrime presentation - A few bits about malwareECrime presentation - A few bits about malware
ECrime presentation - A few bits about malwareMichael Hendrickx
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesCarol McDonald
 
Web application attack Presentation
Web application attack PresentationWeb application attack Presentation
Web application attack PresentationKhoa Nguyen
 
Csrf not-all-defenses-are-created-equal
Csrf not-all-defenses-are-created-equalCsrf not-all-defenses-are-created-equal
Csrf not-all-defenses-are-created-equaldrewz lin
 
The Hidden XSS - Attacking the Desktop & Mobile Platforms
The Hidden XSS - Attacking the Desktop & Mobile PlatformsThe Hidden XSS - Attacking the Desktop & Mobile Platforms
The Hidden XSS - Attacking the Desktop & Mobile Platformskosborn
 

What's hot (20)

Web Security: A Primer for Developers
Web Security: A Primer for DevelopersWeb Security: A Primer for Developers
Web Security: A Primer for Developers
 
Evolution Of Web Security
Evolution Of Web SecurityEvolution Of Web Security
Evolution Of Web Security
 
Become a Security Ninja
Become a Security NinjaBecome a Security Ninja
Become a Security Ninja
 
Web security-–-everything-we-know-is-wrong-eoin-keary
Web security-–-everything-we-know-is-wrong-eoin-kearyWeb security-–-everything-we-know-is-wrong-eoin-keary
Web security-–-everything-we-know-is-wrong-eoin-keary
 
Web Hacking
Web HackingWeb Hacking
Web Hacking
 
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)
 
Web security presentation
Web security presentationWeb security presentation
Web security presentation
 
Owasp advanced mobile-application-code-review-techniques-v0.2
Owasp advanced mobile-application-code-review-techniques-v0.2Owasp advanced mobile-application-code-review-techniques-v0.2
Owasp advanced mobile-application-code-review-techniques-v0.2
 
Make profit with UI-Redressing attacks.
Make profit with UI-Redressing attacks.Make profit with UI-Redressing attacks.
Make profit with UI-Redressing attacks.
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka IrongeekMutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
 
Phishing with Super Bait
Phishing with Super BaitPhishing with Super Bait
Phishing with Super Bait
 
Owasp2013 johannesullrich
Owasp2013 johannesullrichOwasp2013 johannesullrich
Owasp2013 johannesullrich
 
OWASP Top 10 vs Drupal - OWASP Benelux 2012
OWASP Top 10 vs Drupal - OWASP Benelux 2012OWASP Top 10 vs Drupal - OWASP Benelux 2012
OWASP Top 10 vs Drupal - OWASP Benelux 2012
 
Starwest 2008
Starwest 2008Starwest 2008
Starwest 2008
 
ECrime presentation - A few bits about malware
ECrime presentation - A few bits about malwareECrime presentation - A few bits about malware
ECrime presentation - A few bits about malware
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security Vulnerabilities
 
Web application attack Presentation
Web application attack PresentationWeb application attack Presentation
Web application attack Presentation
 
Csrf not-all-defenses-are-created-equal
Csrf not-all-defenses-are-created-equalCsrf not-all-defenses-are-created-equal
Csrf not-all-defenses-are-created-equal
 
The Hidden XSS - Attacking the Desktop & Mobile Platforms
The Hidden XSS - Attacking the Desktop & Mobile PlatformsThe Hidden XSS - Attacking the Desktop & Mobile Platforms
The Hidden XSS - Attacking the Desktop & Mobile Platforms
 

Viewers also liked

Mr. Khalid Shaikh - emerging trends in managing it security
Mr. Khalid Shaikh  - emerging trends in managing it securityMr. Khalid Shaikh  - emerging trends in managing it security
Mr. Khalid Shaikh - emerging trends in managing it securitynooralmousa
 
Mr. Andrey Belenko - secure password managers and military-grade encryption o...
Mr. Andrey Belenko - secure password managers and military-grade encryption o...Mr. Andrey Belenko - secure password managers and military-grade encryption o...
Mr. Andrey Belenko - secure password managers and military-grade encryption o...nooralmousa
 
Mr. Burhan Khalid - secure dev.
Mr. Burhan Khalid - secure dev.Mr. Burhan Khalid - secure dev.
Mr. Burhan Khalid - secure dev.nooralmousa
 
Meraj Ahmad - Information security in a borderless world
Meraj Ahmad - Information security in a borderless worldMeraj Ahmad - Information security in a borderless world
Meraj Ahmad - Information security in a borderless worldnooralmousa
 
Mr. Bulent Teksoz - Security trends and innovations
Mr. Bulent Teksoz  - Security trends and innovationsMr. Bulent Teksoz  - Security trends and innovations
Mr. Bulent Teksoz - Security trends and innovationsnooralmousa
 
Mr. Vivek Ramachandran - Advanced Wi-­Fi Security Penetration Testing
Mr. Vivek Ramachandran - Advanced Wi-­Fi Security Penetration TestingMr. Vivek Ramachandran - Advanced Wi-­Fi Security Penetration Testing
Mr. Vivek Ramachandran - Advanced Wi-­Fi Security Penetration Testingnooralmousa
 
Renaud Bido & Mohammad Shams - Hijacking web servers & clients
Renaud Bido & Mohammad Shams - Hijacking web servers & clientsRenaud Bido & Mohammad Shams - Hijacking web servers & clients
Renaud Bido & Mohammad Shams - Hijacking web servers & clientsnooralmousa
 

Viewers also liked (7)

Mr. Khalid Shaikh - emerging trends in managing it security
Mr. Khalid Shaikh  - emerging trends in managing it securityMr. Khalid Shaikh  - emerging trends in managing it security
Mr. Khalid Shaikh - emerging trends in managing it security
 
Mr. Andrey Belenko - secure password managers and military-grade encryption o...
Mr. Andrey Belenko - secure password managers and military-grade encryption o...Mr. Andrey Belenko - secure password managers and military-grade encryption o...
Mr. Andrey Belenko - secure password managers and military-grade encryption o...
 
Mr. Burhan Khalid - secure dev.
Mr. Burhan Khalid - secure dev.Mr. Burhan Khalid - secure dev.
Mr. Burhan Khalid - secure dev.
 
Meraj Ahmad - Information security in a borderless world
Meraj Ahmad - Information security in a borderless worldMeraj Ahmad - Information security in a borderless world
Meraj Ahmad - Information security in a borderless world
 
Mr. Bulent Teksoz - Security trends and innovations
Mr. Bulent Teksoz  - Security trends and innovationsMr. Bulent Teksoz  - Security trends and innovations
Mr. Bulent Teksoz - Security trends and innovations
 
Mr. Vivek Ramachandran - Advanced Wi-­Fi Security Penetration Testing
Mr. Vivek Ramachandran - Advanced Wi-­Fi Security Penetration TestingMr. Vivek Ramachandran - Advanced Wi-­Fi Security Penetration Testing
Mr. Vivek Ramachandran - Advanced Wi-­Fi Security Penetration Testing
 
Renaud Bido & Mohammad Shams - Hijacking web servers & clients
Renaud Bido & Mohammad Shams - Hijacking web servers & clientsRenaud Bido & Mohammad Shams - Hijacking web servers & clients
Renaud Bido & Mohammad Shams - Hijacking web servers & clients
 

Similar to Mr. Mohammed Aldoub - A case study of django web applications that are secure by default - copy

2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10bilcorry
 
Secure coding guidelines
Secure coding guidelinesSecure coding guidelines
Secure coding guidelinesZakaria SMAHI
 
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...IBM Security
 
How to Test for The OWASP Top Ten
 How to Test for The OWASP Top Ten How to Test for The OWASP Top Ten
How to Test for The OWASP Top TenSecurity Innovation
 
How to Destroy a Database
How to Destroy a DatabaseHow to Destroy a Database
How to Destroy a DatabaseJohn Ashmead
 
Web Hacking Series Part 4
Web Hacking Series Part 4Web Hacking Series Part 4
Web Hacking Series Part 4Aditya Kamat
 
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Michael Pirnat
 
OWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADF
OWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADFOWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADF
OWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADFBrian Huff
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingSam Bowne
 
Ch 12 Attacking Users - XSS
Ch 12 Attacking Users - XSSCh 12 Attacking Users - XSS
Ch 12 Attacking Users - XSSSam Bowne
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingSam Bowne
 
Vulnerabilities in modern web applications
Vulnerabilities in modern web applicationsVulnerabilities in modern web applications
Vulnerabilities in modern web applicationsNiyas Nazar
 
OWASP top 10-2013
OWASP top 10-2013OWASP top 10-2013
OWASP top 10-2013tmd800
 

Similar to Mr. Mohammed Aldoub - A case study of django web applications that are secure by default - copy (20)

Security testing
Security testingSecurity testing
Security testing
 
Owasp top 10 2013
Owasp top 10 2013Owasp top 10 2013
Owasp top 10 2013
 
2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10
 
Secure coding guidelines
Secure coding guidelinesSecure coding guidelines
Secure coding guidelines
 
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
 
Owasp top 10 2017
Owasp top 10 2017Owasp top 10 2017
Owasp top 10 2017
 
Joomla web application development vulnerabilities
Joomla web application development vulnerabilitiesJoomla web application development vulnerabilities
Joomla web application development vulnerabilities
 
How to Test for The OWASP Top Ten
 How to Test for The OWASP Top Ten How to Test for The OWASP Top Ten
How to Test for The OWASP Top Ten
 
How to Destroy a Database
How to Destroy a DatabaseHow to Destroy a Database
How to Destroy a Database
 
Web Hacking Series Part 4
Web Hacking Series Part 4Web Hacking Series Part 4
Web Hacking Series Part 4
 
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
 
OWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADF
OWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADFOWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADF
OWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADF
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
 
Ch 12 Attacking Users - XSS
Ch 12 Attacking Users - XSSCh 12 Attacking Users - XSS
Ch 12 Attacking Users - XSS
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
 
Vulnerabilities in Web Applications
Vulnerabilities in Web ApplicationsVulnerabilities in Web Applications
Vulnerabilities in Web Applications
 
Xss talk, attack and defense
Xss talk, attack and defenseXss talk, attack and defense
Xss talk, attack and defense
 
Vulnerabilities in modern web applications
Vulnerabilities in modern web applicationsVulnerabilities in modern web applications
Vulnerabilities in modern web applications
 
OWASP top 10-2013
OWASP top 10-2013OWASP top 10-2013
OWASP top 10-2013
 

More from nooralmousa

Sudarsan Jayaraman - Open information security management maturity model
Sudarsan Jayaraman  - Open information security management maturity modelSudarsan Jayaraman  - Open information security management maturity model
Sudarsan Jayaraman - Open information security management maturity modelnooralmousa
 
Ahmed Al Barrak - Staff information security practices - a latent threat
Ahmed Al Barrak - Staff information security practices - a latent threatAhmed Al Barrak - Staff information security practices - a latent threat
Ahmed Al Barrak - Staff information security practices - a latent threatnooralmousa
 
Fadi Mutlak - Information security governance
Fadi Mutlak - Information security governanceFadi Mutlak - Information security governance
Fadi Mutlak - Information security governancenooralmousa
 
Mohammed Al Mulla - Best practices to secure working environments
Mohammed Al Mulla - Best practices to secure working environmentsMohammed Al Mulla - Best practices to secure working environments
Mohammed Al Mulla - Best practices to secure working environmentsnooralmousa
 
Pradeep menon how to influence people and win top management buy0in for ciso
Pradeep menon   how to influence people and win top management buy0in for cisoPradeep menon   how to influence people and win top management buy0in for ciso
Pradeep menon how to influence people and win top management buy0in for cisonooralmousa
 
Nabil Malik - Security performance metrics
Nabil Malik - Security performance metricsNabil Malik - Security performance metrics
Nabil Malik - Security performance metricsnooralmousa
 
Khaled al amri using fingerprints as private and public keys
Khaled al amri   using fingerprints as private and public keysKhaled al amri   using fingerprints as private and public keys
Khaled al amri using fingerprints as private and public keysnooralmousa
 
Hisham Dalle - Zero client computing - taking the desktop into the cloud
Hisham Dalle - Zero client computing - taking the desktop into the cloudHisham Dalle - Zero client computing - taking the desktop into the cloud
Hisham Dalle - Zero client computing - taking the desktop into the cloudnooralmousa
 
Ghassan farra it security a cio perspective
Ghassan farra   it security a cio perspectiveGhassan farra   it security a cio perspective
Ghassan farra it security a cio perspectivenooralmousa
 
Taiye Lambo - Auditing the cloud
Taiye Lambo - Auditing the cloudTaiye Lambo - Auditing the cloud
Taiye Lambo - Auditing the cloudnooralmousa
 

More from nooralmousa (10)

Sudarsan Jayaraman - Open information security management maturity model
Sudarsan Jayaraman  - Open information security management maturity modelSudarsan Jayaraman  - Open information security management maturity model
Sudarsan Jayaraman - Open information security management maturity model
 
Ahmed Al Barrak - Staff information security practices - a latent threat
Ahmed Al Barrak - Staff information security practices - a latent threatAhmed Al Barrak - Staff information security practices - a latent threat
Ahmed Al Barrak - Staff information security practices - a latent threat
 
Fadi Mutlak - Information security governance
Fadi Mutlak - Information security governanceFadi Mutlak - Information security governance
Fadi Mutlak - Information security governance
 
Mohammed Al Mulla - Best practices to secure working environments
Mohammed Al Mulla - Best practices to secure working environmentsMohammed Al Mulla - Best practices to secure working environments
Mohammed Al Mulla - Best practices to secure working environments
 
Pradeep menon how to influence people and win top management buy0in for ciso
Pradeep menon   how to influence people and win top management buy0in for cisoPradeep menon   how to influence people and win top management buy0in for ciso
Pradeep menon how to influence people and win top management buy0in for ciso
 
Nabil Malik - Security performance metrics
Nabil Malik - Security performance metricsNabil Malik - Security performance metrics
Nabil Malik - Security performance metrics
 
Khaled al amri using fingerprints as private and public keys
Khaled al amri   using fingerprints as private and public keysKhaled al amri   using fingerprints as private and public keys
Khaled al amri using fingerprints as private and public keys
 
Hisham Dalle - Zero client computing - taking the desktop into the cloud
Hisham Dalle - Zero client computing - taking the desktop into the cloudHisham Dalle - Zero client computing - taking the desktop into the cloud
Hisham Dalle - Zero client computing - taking the desktop into the cloud
 
Ghassan farra it security a cio perspective
Ghassan farra   it security a cio perspectiveGhassan farra   it security a cio perspective
Ghassan farra it security a cio perspective
 
Taiye Lambo - Auditing the cloud
Taiye Lambo - Auditing the cloudTaiye Lambo - Auditing the cloud
Taiye Lambo - Auditing the cloud
 

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Mr. Mohammed Aldoub - A case study of django web applications that are secure by default - copy

  • 1. A Case Study of Django Web Applications that are Secure by Default Mohammed ALDOUB @Voulnet
  • 2. Web Security Essentials • The essentials of web application security are still not well understood. • Most developers have little to no idea about web security fundamentals. • Higher adoption to new web technologies, but no accompanying security awareness.
  • 3. Web Security Essentials • The basic idea of web security: Never trust users, and never trust their data. No exceptions. • Many layers exist in web technologies, and therefore many attack vectors and possibilities. • Web developers must understand risks and mitigations for all web layers.
  • 4. Problems in Applying Web Security • Web security cannot be achieved if developers are not well trained in security. Education is key. • Deadlines will almost always result in security vulnerabilities. Developers who are too busy and under pressure will not focus on security. • Security is not integrated early in the development process, so it gets delayed/forgotten.
  • 5. Bad Practices in Web Security • Developers don’t validate user input. • Even if they validate it, they do it poorly or out of context. • Developers make wrong assumptions about security: – “It’s ok, we use SSL!” – “The Firewall will protect us” – “Who will think of attacking this function?” • Most developers copy/paste code from the internet. Admit it.
  • 6. Bad Practices in Web Security • Session/password management is done poorly: – Sessions are easy to forge by attackers. – Passwords are stored as plaintext. • Server & Database configuration/security are not understood by web developers. • Developers don’t realize the threats on end users: – Cross Site Scripting (XSS) – Cross Site Request Forgery (CSRF)
  • 7. • Django is a Web Application Framework, written in Python • Allows rapid, secure and agile web development. • Write better web applications in less time & effort.
  • 8. • Django is loaded with security features that are used by default. • Security by default provides great protection to developers with no security experience • Django makes it more difficult to write insecure code.
  • 9. • Django is used by many popular websites/services:
  • 10. Security Features of Django • Django provides many default protections against web threats, mainly against problems of: – User Management – Authorization – Cookies – SQL Injection – Cross Site Scripting (XSS) – Cross Site Request Forgery (CSRF) – Clickjacking – Files – E-mail Header Injection – Cryptography – Directory Traversal
  • 11. User Management • Developers make many mistakes in user management. • Passwords are stored/transferred as plaintext. • Users are exposed if databases get leaked. • Weak authentication methods are used by inexperienced developers.
  • 12. User Management • Django provides a default User model that can be used in any website. It comes equipped with correct session management, permissions, registration and login. • Developers don’t need to re-invent the wheel and re- introduce user management risks. • Django provides strong password hashing methods (bcrypt, PBKDF2, SHA1), with increasing work factors. • • Django makes passwords very hard to crack.
  • 13. User Management • Django provides easy methods for user management such as is_authenticated(), permission_required(), requires_login(), and more, offsetting difficult session and permission code away from the developer. • Django provides secure default password reset and login redirection functionality. Developers don’t need to create password reset forms and introduce risks. • By using Django’s user management module, developers will not make mistakes such as ‘admin=true’ in cookies!
  • 14. Clickjacking • Clickjacking is an attack where an attackers loads an invisible page over a visible one. The user thinks he is clicking on the visible page, but he’s actually clicking on invisible buttons and links. • Can be used to trick users into buying items, deleting content or adding fake friends online. • Django provides direct protection against Clickjacking attacks using the X-Frame-Options header. Only one line of code!
  • 15. Clickjacking Example Image taken from ‘Busting Frame Busting’ research paper (found in references)
  • 16. Cross Site Scripting (XSS) • XSS is one of the most dangerous and popular attacks, where users instead of servers are targeted. • In an XSS attack, an attacker runs evil scripts on the user’s browser, through a vulnerable website. • It can be used to steal cookies, accounts, install malware, deface websites and many more uses.
  • 17. Cross Site Scripting (XSS) • XSS is very easy to introduce by ignorant developers, example: <?php echo "Results for: " . $_GET["query"]; ?> • It’s okay if the search query was Car, but what if the attacker entered… <script>alert(document.cookie)</script>
  • 18.
  • 19. Cross Site Scripting (XSS) • Evidently XSS is a critical attack, so Django provides great default protections against it. • HTML output is always escaped by Django to ensure that user input cannot execute code. • Django’s templating engine provides autoescaping. • HTML Attributes must always be quoted so that Django’s protections can be activated. • For extra XSS protections, use ESAPI, lxml, html5lib, Bleach or Markdown
  • 20. SQL Injection (SQLi) • SQL Injection is a dangerous attack in which evil data is sent to the database to be executed as destructive commands. • Developers write SQL queries in a wrong way, allowing attackers to inject SQL commands into the query, to be executed as SQL code. Example: string sql = “SELECT * FROM USERS WHERE name=‘” + Request[‘username’] + “’”; • Looks innocent, but what if the user entered ‘; DROP TABLE USERS;-- ?
  • 21.
  • 22. SQL Injection (SQLi) • SQL injection attacks are used to read and corrupt databases, take complete control over servers as well as modify web pages (and therefore steal user sessions or install malware) • The good news is that Django provides excellent defense against SQL Injection! • Django uses ORM and query sets to make sure all input is escaped & validated. • Developers do not need to write any SQL. Just write Python classes and Django will convert them to SQL securely!
  • 23. SQL Injection (SQLi) • No matter where input comes from (GET,POST,COOKIES), Django will escape all input that goes to the database. • Even if developers needed to write raw SQL, they can use placeholders like "Select * from users where id = %s ” which will safely validate input.
  • 24. Cookies • Django sets cookies to HttpOnly by default, to prevent sessions from getting stolen in most browsers. • Session ID are never used in URLs even if cookies are disabled. • Django will always give a new session ID if a user tried a non- existent one, to protect against session fixation. • Cookies can be digitally signed and time-stamped, to protect against tampering of data.
  • 25. Files • Django provides excellent protection to files. • No webroot concept in Django. Only the directories and files you allow are requested. Even if attackers upload a file, it is only downloaded if you allow it in URLConf. • Django executes Python code from the outside of the web root, so attackers cannot retrieve any files not explicitly allowed from the web root.
  • 26. Cross Site Request Forgery (CSRF) • CSRF is an attack where an attacker can force users of a website to perform actions without their permission. • If a user is logged into website A, an attacker can let a user visit website B, which will perform actions on website A on behalf of the user. • This happens because the forms in website A are not protected against CSRF. • Basically CSRF means evil websites can let users of other websites perform actions without user permission.
  • 27. Cross Site Request Forgery (CSRF) • Example: A form in website A allows a logged in user to delete his account. If there is no CSRF protection, website B can force visitors to delete their account on website A. • Example: Suppose website B has this HTML form in its code. What happens if a user of website A visits B? <form action="http://websiteA.com/deleteMyAccount.php” method=”post” > </form>
  • 28.
  • 29. Cross Site Request Forgery (CSRF) • The effects of CSRF is that attackers can make users perform ANY action on the vulnerable website. • Django provides CSRF protections for all POST,PUT,DELETE requests (according to RFC2616). • If website A used Django CSRF protection, the form would be: <form action=”/deleteMyAccount.php” method=”post” > <input type='hidden' name='csrfmiddlewaretoken' value='Aes4YiAfBQwCS8d4T1ngDAa6jJQiYDFs' /> </form>
  • 30. E-mail Header Injection • E-mail Header injection is a less popular attack that targets weak email-sending forms in websites. • By crafting a special string, attackers can use your email form to spend spam through your mail server, resulting in your domains/IPs getting blocked and possible worse effects. • Example email form: To: mycustomer@example.com Subject: Customer feedback <email content here>
  • 31. E-mail Header Injection • What if the attacker supplies the following data as the email content? They will be able to use your website as a spam base. • “ncc: spamVictim@example.comn<spam content>” • It would be: To: mycustomer@example.com Subject: Customer feedback cc: spamVictim@example.com <spam message content, buy drugs, lose weight or something> • Django provides default protection by using the built-in email form.
  • 32. Final Remarks • It must be understood that nothing can protect developers if they refuse to learn about web security and vulnerabilities. • The point of Django’s default security features is to make it very easy to add security, and very difficult to remove security. • However, developers still need to learn the basics of security and risk assessment. • Knowledge is the best defense against web attacks.
  • 33. References • http://davidbliss.com/sites-built-using-django • https://docs.djangoproject.com/en/1.4/topics/security/ • http://www.djangobook.com/en/2.0/chapter20/ • http://seclab.stanford.edu/websec/framebusting/framebust.p df
  • 34. Questions? • Do not hesitate to ask any question! • Do not hesitate to let your developers try Django in the workplace! It could be your road to increased productivity and security!