sql injections

Posted on 2011-03-05
Last Modified: 2012-05-11
Hey guys m new to developing can i know how can i find sql injection errors from the script and fix them?

like i have source codes of many websites which include normal blogs to commerce sites i want to know how can i find where possible sql injection error could be by opening the php files in notepad or any other editor????

database can be any mysql mssql
Question by:martin2311
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 27

Accepted Solution

yodercm earned 125 total points
ID: 35043859
EVERY SINGLE INPUT that comes into your scripts that gets anywhere near a database is potential injection.   That even includes such things as hidden inputs from a form.

Pass EVERY input through a safety filter such as htmlentities(), mysql_real_escape_string(), or when values are known, use a white list.

If any input could ever be used in a database query, stored in the database, used in a WHERE clause, or any other use in any query, you must safety filter it.  No exceptions.
LVL 11

Assisted Solution

lenordiste earned 125 total points
ID: 35043930
here is a nice PHP blog on sql injections:
look at the bottom comments since some of them provide very interesting ressources.

Also, to build on yodercm's comment your best bet is to use a database framework of some sort so that all your database code can be changed at a single location: if you have to check every single inputs on every page you create you will probably make mistakes at some point. If all your database logic is encapsulated in a few well designed classes however you will be able to have more control on security matters.

Author Comment

ID: 35043999
well there are hell of files how to check in each and every file? any easy way around?
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

LVL 11

Expert Comment

ID: 35044328
not really... if you want to rely on magic quotes you can turn them on while you work your way through each files (it's not a 100% foul's proof though but it is "automatic"). In the long run however I advise you to encapsulate your DB logic in a few classes and do the necessary security checks there:

if you want something 100% secure you will have to edit most of your pages anyway, especially if security was not taken into account during the development process. You might also want to look at PHP frameworks that comes with secure database classes
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 125 total points
ID: 35046007
If you want to examine source coe of blogs or other CMS systems, then it would perhaps be better to ask to corresponding programmers an community of the product. As you are novice programmer, do you really think you would find insecure code an experienced programmer has overlooked?

There are security fixes to most any software having some success and being used, no question, there never is 100% security anyway.

As yodercm initially said what is important is the flow of input into sql queries. Using filters as mentioned is one way, using parameterization is another one and you can of course also do both. Quotes are just one simple problem.

So what you'd need is a parser finding all code lines processing input. That's not easily automated. But code grows slowly, you only start with "a hell of files", if you base your code on an existing CMS or other system. If you start from scratch you can oversee where vulnaribilies are. And yes, you can oversee something, even in a team of developers. Security checks are typically done in unit tests with random input, also wrong input and of cause known injection attacks. So vulnerabilities are not only found by code analysis, but also by testing.

Open source has the advantage not only the bad but also the good hackers are analyzing code and reporting errors and security issues. It also initially asks more precaution by the developer, as the code is open source and can be analyzed of course. It's not a matter of how much code this is, on the other side there are also masses of people searching for vulnerabilities, so there is no security due to an error being buried in lots of code.

Last not least, there are good architecture patterns, liek MVC (model view controller), where a controller is taking in input, seeing what the request means, calling the model to retrieve data, providing that to a view needed to show the next page. In short. In this design pattern all input goes through one object and the coe to prevent injections is centralized and not scattered.

Bye, Olaf.
LVL 25

Assisted Solution

madunix earned 125 total points
ID: 35047155
sql injection is top rated web Application attack these days. There are many insecure code over the net and also there are several ways to protect ASP.NET application from sql injection attacks. sql injection can occur when an application uses input to construct dynamic sql statements or when it uses stored procedures to connect to the database. Methods of sql injection exploitation are classified according to the DBMS type and exploitation conditions  Vulnerable request can implement Insert, update, delete. It is possible to inject sql code into any part of sql request Blind sql injection Features of sql implementations used in various dbms. Successful sql injection attacks enable attackers to execute commands in an application's database and also take over the server.
my recommendation:
- Basically, make sure your web server is up-to-date with latest security fixes/patches.
- Make sure you have filter every user input and output as proper encoding like UTF-8.
Read the full testing guide:
- try tom imlement web application scanner , check this link
- i use ex. watchfile now IBM aapscan tools  to scan all my web application

check google more how to protect against sql injection
regarding Microsoft issue check
search  "sql injection"

Here's a data cheat sheet with several  tricks for sql injection  exploitation:

Author Comment

ID: 35056678
well i said me new i meant new in finding errors i know php and web development but m not good in finding errors are there any good tools to find web app errors free one ? like i make a local server and test them that way
LVL 27

Expert Comment

ID: 36283842
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSIS GUID Variable 2 32
Regarding Disk IO 3 43
Dynamic Table mySQL stored procedure 5 33
SQL 2012 Instance Problem 3 54
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question