02.06.2013 Views

analisi e gestione della sicurezza di una complessa applicazione ...

analisi e gestione della sicurezza di una complessa applicazione ...

analisi e gestione della sicurezza di una complessa applicazione ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CAPITOLO VI - Gli attacchi e il progetto OWASP<br />

"select * from users where name like ‘‘ or ‘a’ like ‘a%’ "<br />

In sostanza la clausola “where” è sempre vera causando quin<strong>di</strong> la restituzione del contenuto<br />

completo <strong>della</strong> tabella users.<br />

Questo esempio non è che la punta dell’iceberg ed è solo il primo assaggio. Il peggio deve<br />

ancora arrivare, ma questo può far riflettere gli sviluppatori poco accorti in quanto, essere<br />

vulnerabili a questo tipo <strong>di</strong> attacco, è palesemente contrario alla normativa vigente in materia <strong>di</strong><br />

privacy con tutto ciò che ne consegue per legge.<br />

Un altro punto interessante è che questo tipo <strong>di</strong> attacco non è <strong>di</strong>rettamente <strong>di</strong>pendente dalla<br />

tecnologia utilizzata o per <strong>di</strong>rlo in altri termini è un attacco cross-platform, funziona per<br />

esempio su SQL Server, MySQL, Access, Oracle o FireBird, solo per citarne alcuni.<br />

Naturalmente l’hacker in alcuni casi dovrà iniettare co<strong>di</strong>ce <strong>di</strong>fferente in base al database usato,<br />

ma nessuno è immune a priori. La vulnerabilità è figlia <strong>della</strong> stessa natura del linguaggio SQL<br />

che è espresso per mezzo <strong>di</strong> stringhe <strong>di</strong> testo; le soluzioni definitive esistono, ma purtroppo<br />

sono snobbate da molti sviluppatori che sottovalutano la portata <strong>di</strong> questa vulnerabilità.<br />

Fino a che punto <strong>una</strong> SQL Injection è pericolosa? Niente <strong>di</strong> meglio che un altro esempio per<br />

rispondere a questa domanda, partendo dalla stessa query iniziale:<br />

"select * from users where name like ‘ " + TextBox1.Text + "%’ "<br />

l’hacker potrebbe scrivere nella TextBox (cioè iniettare) questo co<strong>di</strong>ce:<br />

che risulterebbe in questa stringa:<br />

"‘ ; select * from sys.tables -- "<br />

"select * from users where name like ‘‘ ;<br />

select * from sys.tables -- ‘ "<br />

Questo statement ha tre punti fondamentali. Il primo è il ";" che permette la <strong>di</strong>chiarazione <strong>di</strong><br />

due <strong>di</strong>stinte query all’interno <strong>di</strong> <strong>una</strong> stessa stringa; il secondo è l’uso <strong>di</strong> "--" per commentare<br />

ciò che resta nella stringa. Non tutti i database permettono l’uso <strong>di</strong> ";" e/o <strong>di</strong> "--" ma questo non<br />

è altro che uno degli esempi possibili. Il terzo punto è l’uso <strong>della</strong> view sys.tables <strong>di</strong> SQL2005.<br />

In SQL2000 esiste la tabella sysobjects mentre nel MySQL esiste la tabella<br />

INFORMATION_SCHEMA.TABLES, supportata anche da SQL2005. Ancora <strong>una</strong> volta<br />

queste <strong>di</strong>fferenze non costituiscono alcun ostacolo per l’attuazione dell’injection.<br />

117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!