Skip to Main Content
Linux Server Security, Second Edition
book

Linux Server Security, Second Edition

by Michael D. Bauer
January 2005
Intermediate to advanced content levelIntermediate to advanced
544 pages
23h 44m
English
O'Reilly Media, Inc.
Content preview from Linux Server Security, Second Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Database Operation
|
249
SQL Injection
Some queries are actual attempts to attack the server. Since SQL is a language, it’s
susceptible to lexical, grammatical, and logical errors. Exploiting SQL to crack a sys-
tem is also called SQL injection.
Let’s say you have a web site where people register to access your content. Some-
where you’ll have a table defining your users: ID, password, and so on. You have a
script (Perl, PHP, or whatever) that collects the ID and password from a form and
checks the database to see if that user exists. In PHP, you might code:
$query = "SELECT * FROM USERS WHERE ID = '$id' and password = '$password'";
where $id and $password are the values from the form. (In Chapter 10, I point out
that we would actually take a few steps before this to ensure that $id and $password
actually came from the form.) If $id were shrek and $password were donkey, the query
would be:
SELECT * FROM USERS WHERE ID = 'shrek' and PASSWORD = 'donkey'
A cunning SQL injector could use these values instead:
This results in:
SELECT * FROM USERS WHERE ID = '' OR ''='' and PASSWORD = '' OR ''=''
This will select every row. If we had used SELECT COUNT(*) instead, we would get
a count of all the rows.
Chapter 10 includes more information on how to guard against SQL injection in
your Perl or PHP scripts. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux: Powerful Server Administration

Linux: Powerful Server Administration

Uday Sawant, Oliver Pelz, Jonathan Hobson, William Leemans
Linux Server Hacks

Linux Server Hacks

Rob Flickenger
Linux Server Hacks, Volume Two

Linux Server Hacks, Volume Two

William von Hagen, Brian K. Jones

Publisher Resources

ISBN: 0596006705Supplemental ContentCatalog PageErrata