![]()
|
You are here: Home > Articles > SQL Injection SQL InjectionSQL Injection is a widespread but little known problem amongst software developers and web masters. If you use an SQL based database such as MySQL, Oracle or Microsoft SQL Server you may be at rist of an SQL Injection attack from any of your web-based applications that use a database. What is SQL InjectionAny user-supplied or hidden form field in a web application, or any user supplied field in any application that connects to a database is at risk. Users can enter data that the SQL processor believes are commands. Why is SQL Injection a Problem?By default, fields a user enters are not validity checked for this type of exploit, the programmer must specifically ensure that special characters are handled properly. This is where programmer-error may leave some more all user-entered, hidden fields, or tracking cookies at risk from a malicious user. What could a malicious user do?From mybassing authentication, or collecting information about other users in your database, a malicious user could even insert a "drop table" command and delete all of data and cripple your applications. For database user accounts that have administrator priveledges, a malicious user could create accounts, change or collect passwords or even execute shell commands to compromise your server. But I do input validation in Javascript!Even if you check for user input issues with Javascript, you must always double check the fields and hidden values or cookie values before using them in an SQL statement. A malicious user could just save your form on their local computer and edit the HTML (or create their own) to craft an SQL Injection attack against your web application. How can I tell is my application is at risk of SQL Injection?The table below contains some of the most common SQL Injection attacks.
How does the attack work?
Here's a typical SQL command: SELECT * from users where username='$username';SELECT * from users where username='' or 1=1 or username = '';SELECT * from users where username=''; drop table users; select * from billing where account <> '';
Preventing SQL Injection AttacksEscape all variables before adding them to an SQL statement. PERL has an included function called DBI::quote which can be used:
my $dbh = DBI->connect("dbi:$db_type:$db_schema:$db_host", "$db_user", "$db_password") or die "DB Error!\n";
This does get a bit complicated for handling very complicated inserts etc, this function will handle most SQL Injection attacks as long as you put all your data in 'quotes':
sub mysql_escape {
Additionally, it's a good idea to limit the scope of the user that you use in your web application to limit damage to your database. It's also a good idea to have all fields within quotes 'value', with all the various character sets emerging, it's much easier to exploit a field not within quotes. Free Security Evaluation of Your Web AppsContact us today for a free no obligation review of your web application. While Stellar will not conduct penetration testing or an active evaluation of any website or application, we can review the concept or source code to provide an evaluation of problem areas. Stellar's web application subject matter experts can help plan and implement changes to prevent misuse and hacking of your web application. | ||||||||||||||||||||||||
|
| |||||||||||||||||||||||||