Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


sql injections

Posted on 2011-03-05
Medium Priority
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

Cornelia Yoder earned 500 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 500 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?
Introducing the WatchGuard 420 Access Point

WatchGuard's newest access point includes an 802.11ac Wave 2 chipset, providing the fastest speeds for VoIP, video and music streaming, and large data file transfers. Additionally, enjoy the benefits of strong security as the 3rd radio delivers dedicated WIPS protection!

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 30

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 500 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 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

670 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