Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Injection attack prevention: where do I start

I'm looking to make my site secure against SQL injection attacks. Does anyone have any good links to make the site secure against these types of attacks in an ASP.NET site (c#, web forms)?

EDIT:

I should point out at I am using the Entity Framework

like image 428
Funky Avatar asked Feb 06 '12 15:02

Funky


People also ask

How can SQL injection attacks be prevented?

The only sure way to prevent SQL Injection attacks is input validation and parametrized queries including prepared statements. The application code should never use the input directly. The developer must sanitize all input, not only web form inputs such as login forms.

What is the first steps that need to be carried out in an SQL injection attack?

1Locate the Vulnerable Code The first step in recovering from a SQL injection attack is to identify where the vulnerability is located. You can manually launch an attack or run an automated SQL injection attack tool like Havij, SQLmap, or jSQL to identify vulnerable code.

Where do you do SQL injection?

The most common other locations where SQL injection arises are: In UPDATE statements, within the updated values or the WHERE clause. In INSERT statements, within the inserted values. In SELECT statements, within the table or column name.


2 Answers

The first and best line of defense is to not use dynamic SQL.

Always use parameterized queries.

Take a look at the OWASP page about SQL Injection.

like image 67
Oded Avatar answered Sep 30 '22 14:09

Oded


See these resources:

  • How To: Protect From SQL Injection in ASP.NET (MSDN)

  • Data Security: Stop SQL Injection Attacks Before They Stop You

  • SQL Injection Attacks and Some Tips on How to Prevent Them

  • Preventing SQL Injection in ASP.NET

Basically, as Oded already pointed out, it boils down to stop concatenating together your SQL statements - especially if that involves data entered by user's into textboxes - and use parametrized queries in ADO.NET.

like image 25
marc_s Avatar answered Sep 30 '22 13:09

marc_s