LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-06-2011, 10:05 AM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
Preventing MySQL Injections


I have a database server in my office and it's also exposed to the outside world via web servers that run PHP. I was wondering how can I make sure my server is protected from SQL injections or other commonly SQL level attacks? I want to make sure my data on the server remains secure. I'm not exactly sure what happens when someone does a SQL injection but it sounds like a bad thing.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 06-06-2011, 10:15 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Plenty of information about what it is, and what to do about it if you look - http://www.tizag.com/mysqlTutorial/m...-injection.php for example.

Basically, write good code, and don't believe anything a user tells you.
 
2 members found this post helpful.
Old 06-06-2011, 10:20 AM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Every SQL statement that takes a parameter should be a prepared statement with bound parameters. You never build SQL queries with string concatenation.

Quote:
Originally Posted by carlosinfl View Post
I'm not exactly sure what happens when someone does a SQL injection but it sounds like a bad thing.
Here's one recent testimonal:

http://programmers.stackexchange.com...ite-what-to-do

Last edited by dugan; 06-06-2011 at 10:27 AM.
 
Old 06-06-2011, 11:31 AM   #4
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
I know this is a comic, but it is one of the best "explanations" of SQL injections I've seen.
 
1 members found this post helpful.
Old 06-06-2011, 03:20 PM   #5
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
In addition to the prepared statements, I like to sanitize all input received from the user before before using it any fashion. For example, if you are expecting numerical input, make sure that you only receive a number AND that it is within the expected range. If you are expecting a date or date-time make sure that it is in the proper format AND that it is a valid date. Do not pass anything received from a user directly to your database.
 
Old 06-06-2011, 03:31 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
...and in addition to that GreenSQL doesn't prevent injections but at least its an IDS approach to getting malicious activity early warnings.
 
Old 06-07-2011, 09:12 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
The "Bobby Tables problem," referred to (and originally inspired by) that comic strip, has another aspect, too: "don't give your web applications any more database privileges than they actually require to do a particular thing." If you are querying records, you shouldn't be using a database-handle that is connected using privileges that allow writing to anything ... nor read-access to anything that does not need to be queried at this time.

Basically, it comes down to being dis-trustful, and programming your applications to do the same thing.
 
Old 06-13-2011, 02:53 PM   #8
softwarelabus
LQ Newbie
 
Registered: Jun 2011
Posts: 27

Rep: Reputation: Disabled
Like others said here, use prepared statement. I've never heard of any security hole with prepared statements.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] mysql injections. markraves Programming 2 10-30-2010 11:31 AM
LXer: Preventing MySQL Injection Attacks With GreenSQL On Debian Etch LXer Syndicated Linux News 0 10-28-2008 05:40 PM
Help. i use php/mysql, and someone is using mysql injections to hack my site Malcome_thompson Programming 3 08-16-2008 07:43 PM
Sendmail Injections wuhaa Linux - Security 1 10-30-2006 09:11 AM
something or someone is preventing mysql to run mariogarcia Linux - Server 1 08-29-2006 10:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 04:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration