Free Download: SQL Anywhere Developer Edition

WebProWorld Dev Forum

need help with smarterscript
I'd like to add some coding to the smartersearch. Just not sure how to add the coding or what to code. Not looking for major changes, just small changes to how the affiliate is setup.

PHP problem - need help
My page has suddenly started presenting PHP errors - I am only doing some content rework for this client, but this page has started playing up with the only changes being made to the prices of the products. I have tried copying back the original file to no avail...

some simple MOD rewrite help - like its ever simple
I have a site which uses this very simple MOD to change php to html is some cases, and pass a variable in some cases as you see. I would like to adapt this to catch incoming subdomain requests. would like to pass incoming requests that fit this bill (SUBDOMAINNAME).mysite.com/one-two-three.html


Free Software Archive:
Enterprise and Home Networking Downloads

Recent Articles

Oracle To Let Loose "Fusion Middleware" Brand
Oracle is placing its "Oracle Fusion Middleware" brand on 32 middleware and development products. The "Oracle Fusion Middleware" products will be formally announced

Microsoft Releases Newest Visual Studio and SQL Server
Microsoft announced availability of Visual Studio 2005 Beta 2, Microsoft .NET Framework 2.0 Beta 2 and the SQL Server 2005 April Community Technology Preview (CTP).

MySQL Users Conference Coming Up
The 2005 MySQL Users Conference isn't far off. It runs from April 18th - 21st at the Santa Clara Convention Center.

Microsoft Great Plains SQL Reporting and Data Fixing
This is beginner level SQL scripting article for a DB Administrator, Programmer, or IT Specialist.

Dell's Database Double-Edge
Dell recently unveiled 2 new database servers, systems management software and data center assessment services.

Oracle Integration with Microsoft CRM
Oracle has a huge number of installations worldwide and Microsoft Business Solutions CRM is gaining its market share on the CRM market mostly for mid-size and small companies.


05.10.05


SQL Injections

By Douglas Brunner

Since learning how to manipulate a database is usually the first thing programmers learn it makes sense that learning about SQL injections should also be one of the first things they learn.

SQL Injections happen when a malicious user extends your SQL query by writing a bit of code into the input box. By running an unchecked query you could leave yourself open to attacks that could cripple your database.

To know how to prevent an SQL injection you need to know how programs talk to a MySQL server, it's done with the Structured Query Language.

For the purpose of this article, there isn't much need to dive deeply into how to use SQL, but you do need to be familiar with it.

Below is a query that will tell the server to change someone's name to Don.

update Members set Name='Don' where ID='1'

Doesn't look to complex does it. To get the server to update a record (A record in one row of information in the database) you simple start the query by saying "update".

rom there, you need to tell the server what table (Since there can be many in one database) in the database you'll be updating, in this example it's the table called "Members".

Free Download: SQL Anywhere Developer Edition

Since each table can have one or more columns (Columns are used to store information specific to a table) you need to tell the server which column you want to alter, and what you want new information you want to enter.

This is done by telling the server to set the column Name with new information (Don), but only where the unique id (The unique ID is a column created to give each record it's own number to help identify rows easier) is equal to 1.

This query will only enter the name Don, which doesn't make the application very dynamic. To allow people to enter a varied array of different information we use variables (A variable can contain any combination of characters).

update Members set Name='$Name' where ID='1'

This is what our SQL query looks like when we use a variable to input the new name. The variable would come from a form (It could realistically come from other sources, but most commonly it would come from a form) that someone submitted from the site.

Now if someone submitted the name Don from the form the SQL query would look identical to the first one posted. However, they could submit the name Mike, Fred or Wallace.

This is where the SQL injection comes into play. What if the user didn't enter their name, what if they entered a little bit of code to adjust their Member privileges?


You probably noticed the single quotes (') around the variable and the number one. These tell the server where the information to enter into the column is, anything between the quotations, or in the case of the id, which record to update.

update Members set Name='Don' ,Userlevel='Administrator' where ID='1'

This SQL query will update the table named Members, and set the members name to Don, and their Userlevel to Administrator. This can be done with an SQL injection, as illustrated below.

Don' ,Userlevel='Administrator

Fairly easy to do isn't it? Remember that to update the name the server is only looking for information between the two single quotations. By entering their name as Don' ,Userlevel='Administrator, the malicious user set their name to Don, but also extended the query by adding more code giving themselves administrator privileges.

Scripting languages like PHP will automatically place a backslash in front of single quotes entered by users. This lets the SQL server know that this is only part of the information to be added, and doesn't allow an SQL injection. If for any reason you need to strip the slashed from user input, remember to add them again before running your query, or you may find yourself a vicitim of an SQL injection.


About the Author:
Douglas Brunner is the administrative director for Norics. Norics provides resources for the off-line world to get on-line, and be successful.

About SQLproNews
SQLproNews is a collection of up to date tutorials and insightful articles designed to help SQL users of any skill level implement successful SQL systems and practices. SQL Strategies and Tactics for Business

SQLproNews is brought to you by:

SecurityConfig.comNetworkingFiles.com
NetworkNewz.comWebProASP.com
DatabaseProNews.comSQLProNews.com
ITcertificationNews.comSysAdminNews.com
SQLproNews.comWirelessProNews.com
CProgrammingTrends.comSysAdminNews.com



-- SQLProNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2005 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

advertising info | news headlines | free newsletters | comments/feedback | submit article

SQL Strategies and Tactics for Business SQLproNews News Archives About Us Feedback SQLproNews Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact