SQL injection could be prevented by inserting only base64_encoded data into the data base. Before searching the data base for a certain value or string base64_encode the search string and then start the query.
Securitatea Bazelor de Date
Cuprins
In zilele noastre, bazele de date sunt componente esentiale ale aplicatiilor web, dand posibilitatea acestora de a servi continut dinamic. Datorita faptului ca informatii secrete sau cu caracter confidential se stocheaza adesea intr-o baza de date, va trebui sa luati in considerare protejarea bazelor de date.
Pentru a primi sau trimite orice informatie, trebuie sa te conectezi la baza de date, sa trimiti un query valid, sa iei rezultatele, si sa inchizi conexiunea. Recent, cel mai folosit limbaj query pentru asemenea tip de interactiune este Nowadays, the commonly used query language in this interaction is the Structured Query Language (SQL). Vezi cum un atacator poate sa manipuleze un query SQL.
Dupa cum probabil ati presupus, PHP nu va poate proteja bazele de date in sine. Urmatoarele sectiuni tind sa fie o introducere in notiunile de baza ale accesarii si manipularii bazelor de date, cu scripturi PHP.
Pastrati in minte urmatoarea regula: securitate maxima. Cu cat cresteti masurile de protectie asupra bazelor de date, cu atat mai putina este probabilitatea ca un atacator sa reuseasca sa sustraga date importante sau sa abuzeze de ele. Incercati ca structura si designul bazei de date sa fie cat mai eficient, dupa care va puteti pune problemele legate de securitate.
Designul bazelor de date
Primul pas este intotdeauna crearea bazei de date, numai in cazul in care nu doriti sa folositi alta de pe alt server. Cand o baza de date este creata, ea este desemnata unui anume utilizator, care a executat comanda de creare. In general numai proprietarul (sau superuserul) pot face orice cu obiectele din acea baza de date, iar pentru a lasa si alti utilizatori sa o foloseasca, ei trebuie sa aiba privilegii.
Aplicatiile pe care le construiti nu ar trebui sa se conecteze niciodata la o baza de date cu privilegii de administrator sau superuser, pentru ca acesti utilizatori pot executa orice fel de query, de exemplu, modificarea schemei (stergerea tabelelor) sau stergerea intregului continut.
Poti crea diferiti useri de baze de date pentru fiecare aspect al aplicatiei, cu drepturi limitate, in functie de task-urile pe care le indeplinesc. Se pot da numai privilegiile strict necesare, si evitati ca acelasi user sa interactioneze cu mai multe baze de date. Aceasta inseamna ca daca un intrus va avea privilegii la baza de date, acesta va avea privilegii limitate si nu va putea sa faca decat schimbari cu impact asupra aplicatie dumneavoastra.
Este bine sa nu implementati toate solutiile prin prisma scriptului web, in schimb incercati sa creati o schema de baza de date cat mai competitiva, din care sa extrageti simplu informatia. Daca sistemul evolueaza, noi porturi vor fi folosite pentru a manipula bazele de date, si va trebui sa reimplementati scripturile pentru fiecare baza de date in parte.
Securitatea Bazelor de Date
17-Jan-2008 07:37
16-Aug-2007 12:15
The posting below is at the very best extremely POV.
There is no more reason to assume you would want to change database vendor than there is to assume you might want to port your php code to Java for example. In either case, its going to be a matter of luck where your business rules sit.
Even if your business rules sit in your application, SQL is NOT portable. Oracle outer joins and pivot queries for example, can look completely different to those in other vendors software (particularly from 8i or lower). This fact alone means that changing your DB vendor requires work on your business rules either in the database or in the application.
Having your rules in the database and keeping the sql in application simple, will at least keep the work in the database if you need to change DB vendor. If you have the rules in the PHP, you'll have to change both.
14-Aug-2007 09:48
About offloading business logic to views and queries facilitated by the database engine, I seek to avoid this as much as possible, and only do so when such would drastically improve efficiency and user response time.
For instance, where I am there is database staff and application staff. Trying to do analysis on existent applications can easily become a snipe hunt.
The database should be kept discreet as much as possible from the application, such that any database or database provider can easily be substituted with a minimum of cognitive effort on the part of the one setting up a new database. If functionality has been offloaded to the database, additional testing is required to make sure triggers and views were done correctly, again, and that they work right.
Also, keeping all business logic with the application allows all functionality and documentation to be readable in one place, which is invaluable when doing subsequent analysis on an existing application. The worst thing is to have functionality scattered here and there.
Keeping everything with the application means one group of people is responsible, as in my case, application staff. Fewer requests go back and forth. Remember, anytime someone else is brought into the picture, such as asking a DBA to create a view or trigger for you, that DBA must take responsibility over his or her work, with whatever requirements, causing more bureaucracy and administrative complexity.
28-Jun-2007 12:23
<?php
$getal1 = 5.5;
$getal2 = 2.0;
function printDeling() {
$resultaat = global $getal1 / global $getal2;
return $resultaat;
}
function printVermenigvuldiging() {
$resultaat = global $getal1 * global $getal2;
return $resultaat;
}
function printSom() {
$resultaat = global $getal1 + global $getal2;
return $resultaat;
}
function printAftrekking() {
$resultaat = global $getal1 - global $getal2;
return $resultaat;
}
(printDeling()>=7) ? print "<font color=\"green\"> printDeling()</font>" : print "<font color=\"red\"> printDeling()</font>" ;
?>
10-May-2006 09:03
Encrypting user input doesn't do much to guard against SQL injection attacks. Naturally, you want to encrypt sensitive information across the wire, but if a user puts in malicious data into an input field, any encryption scheme will just dutifully unpack it at the other and and still run the SQL injection hack if you haven't guarded against it.
Encryption is not magic pixie dust to sprinkle on things to make them more secure.
you can also chamge CHMOD for some file containing "user names" or "passwords"
12-Mar-2005 02:08
On a database design point of view, you should make sure that you design databases in a manor that any query run from them need minimal input from the user and if it requires user input, that you encrypt where possible.
20-Jun-2003 10:17
I would say one of the best ways to guard against SQL injection is to use the excellent PEAR DB package. If you prepare() and execute() your queries, PEAR will automagically addslashes and handle the query depending on your RDBMS. And of course, for repeatable queries prepare and execute will give you a bit of a readability and speed increase.
