"Geoff Berrow" wrote...
: As I said, without the proper grounding it can't be done...
: ...
: Of course, you may pick it up more quickly, but it's still beyond
: the scope of this group.
Nothing is beyond the scope of any newsgroup. That's just making up
a quick excuse and it probably was stated too quickly.
So to prove that this is NOT beyond the scope of any news group we
need to start by breaking things up into different topics and then
we can go from there. This information should help everyone here,
but please take not, I am NOT a PHP professional, I make no such
claim and the information that I'm about to post I need to learn
and relearn myself and it's to be of benefit to you, to me and to
anyone else that is willing to participate and help out.
In the rhythms of some not so old but popular British singers...
All you need is love,
Everybody,
All you need is love,
Love PHP...
Yeah, yeah, yeah...
Paricipate, anticipate and try
Participate, anticipate, apply
....
Ok, so much for my musical talent. <g>
We need to define things first.
What is "SQL Injection"?
It's an SQL string or some other sort of string which compromises
access to data files. It can be javascript or some other client
side scripting which calls or runs a server-side SQL query. It can
be server-side scripting which does the same but delivers to some-
one that's not supposed to get it. It can be the actual SQL query
itself which either does improper updates, deletions, et al.
So, given those facts, you need to find ways to limit these types
of attacks. I believe the best ways to limit these attacks, involves
making sure the queries you run are the queries you set up and
configured to run and no other type of query.
Most SQL queries end up as dynamic queries, meaning most of the
SQL string is a static string, but there may be a WHERE clause or
a FROM clause that varies depending upon the table and the data
needed.
Try something along the lines of:
1) Identify ALL the query strings you will run. Create a valid list.
Put this list of information into an array of strings to check.
$sSQLStrings = array(
array(0, 'SELECT * FROM MyTable;'),
array(1, 'SELECT PLAYER, TEAM, HOMERS FROM NATIONAL WHERE HOMERS >= '),
array(2, ' GROUP BY TEAM;'),
array(3, 'SELECT PLAYER, TEAM, HOMERS FROM AMERICAN WHERE HOMERS >= '),
array(4, ' GROUP BY TEAM, PLAYER, HOMERS;')
);
Now someone else can help out by providing string comparisons. I'm
weak in my string comparison help, so that will benefit myself.
2) Validate each query you plan to run to make sure it...
a) Comes only from your server,
b) Is a valid query for the server by comparing the SQL string
to predefined lists of strings.
You can use the PHP strstr() function to help you out, and if a
mismatch is found, use the header() function to redirect to some
other site or to a predefined page.
1) Your normal valid regular customers WILL NEVER try such things.
IF they do, perhaps log the details and send it to proper auth-
orities.
2) The people that try such things you don't want at your website,
so redirect them to another website, possibly the FBI or a local
police agency. If you know the local police folks you might be able
to work something out them to see if anything can be enforced.
3) There may be some agencies that identify unscrupulous IP addresses
so this may help, but be careful when using such lists, as you do
not want to make "your real customers" angry, meaning you do not
want to blacklist a real customer.
Something that may make processing faster, includes knowing the maximum
string length of any SQL query and then using that as the first test for
validation, as comparing numbers works a lot faster than comparing char-
for-char sequences. Use PHP's strlen() function to get the length of the
SQL statements.
It requires knowing your SQL queries, knowing about the various cross-site
scripting attacks, and knowing your PHP code.
The PHP documentation seems to discourage regular expressions. So if
anyone can supply "regular expression" string comparisons to run through
such an array as above, or provide some recommended string comparisons
using strcmp or whatnot, and perhaps a comment on if they tested the
results, how they tested the results, this should get this topic started
and be of benefit to everyone here. We can all work through this by
going through each step listed above. I'll be happy to put the details
onto a webpage if no one else wants to do such.
The information here is placed into the public domain.
--
Jim Carlock
You Have More Than Five Senses
http://www.associatedcontent.com/art...ve_senses.html