Anatomy of a SQL injection attack

This vendor-written tech primer has been edited to eliminate product promotion, but readers should note it will likely favor the submitter's approach.

While there are a number of security risks in the world of electronic commerce, SQL injection is one of the most common Web site attack techniques used to steal customer data such as credit card numbers, hold customer data hostage by encrypting it or destroy data outright.

Where a Web server only understands and speaks the HTTP protocol, a database's native tongue is Structured Query Language (SQL), which is essentially a set of command statements that instruct a database to execute specific actions. Every database server has a similar series of commands to query its tables, narrow down results to a few specific entries, and combine information from one table to another.

Here is an example SQL query:

SELECT -- FROM users WHERE Email = '" + Email + "' AND Password = '" + Password + "';

The WHERE specifies a condition, that an e-mail address and password combination match data present in the "users" table. When this command is given to the database server, it returns true if a match is found and a false if there is no match.

When clients send data on the Web, they use URLs and forms to assemble the database query statements. The following URL represents an example login page for a Web application:

GET /shopping_cart/login.asp?Email=jdoe@example.com&Password=$ecret123 HTTP/1.1

This URL shows that the destination application is a Microsoft ASP page and it is accepting two parameters, one called "Email" and the other called "Password." If the user credentials are correct then the result of this query will provide response data that represents a successful authentication and will be used to allow the client to proceed to the corresponding Web page.

Developers of traditional application code generally trust user input. They believe that database queries are coming from a trusted source, namely the database server itself, rather than from an untrusted user's Web browser. SQL injection is an attack technique where an untrusted user inserts SQL query data into input fields sent to back-end databases in an attempt to trick the database into executing the commands.

The Web application firewall in the example was configured in a "detection only" mode where it was logging alerts and events but not blocking any inbound attacks or outbound data leakages. Due to this configuration, the inbound SQL injection attack from the previous section was allowed to continue on to the vulnerable Web application when it would have been blocked.

The Web page returned indicates that the SQL injection reconnaissance probe was successful, giving the hacker valuable information, including the exact version of the database and the database user. Armed with this information, the attacker can fine tune the attack and execute further reconnaissance probes to enumerate more information about the database itself, such as the table and column names. After a number of intermediary reconnaissance probes, the attacker has the information needed to send a complex SQL injection attack, attempting to extract customer record details. By targeting specific customer data such as credit card name, expiration data and security code, the attacker can extract a vast amount of sensitive customer data.

Join the PC World newsletter!

Error: Please check your email address.

Tags SQL

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Ryan Barnett

Network World
Show Comments

Most Popular Reviews

Latest News Articles

Resources

PCW Evaluation Team

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Aysha Strobbe

Windows 10 / HP Spectre x360

Ultimately, I think the Windows 10 environment is excellent for me as it caters for so many different uses. The inclusion of the Xbox app is also great for when you need some downtime too!

Mark Escubio

Windows 10 / Lenovo Yoga 910

For me, the Xbox Play Anywhere is a great new feature as it allows you to play your current Xbox games with higher resolutions and better graphics without forking out extra cash for another copy. Although available titles are still scarce, but I’m sure it will grow in time.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?