Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

Can SQL server escape single quotes while producing a sql injection on sql server? And how do SQL server escape single quote?

Asked by Anna Ball Apr 23, 2021 2.5K views 1 answer
Share

About this question

I found a simple breakout in a where clause in one of our projects where the code is so old that they claim they can't use parameters to communicate with ms SQL server. It's written in C++, I can't read this language and I'm not able to access the code in any way. To illustrate the issue I added an example of a non harmful statement, the bold part is what the user can directly input SELECT '1 ' SELECT 2--';

The single quote after 1 is causing the breakout in this scenario. This is what I've shown to the team. They then did a detection in code that searches for single quotes and add three other single quotes after each single quote they find. Thus the example would become this SELECT '1'''' SELECT 2--'; I don't like this solution at all, but I can't find a way to breakout any more. The fields inside the database are stored treated as nvarchar characters. Is there still a possibility to bypass this practice in any kind? How do SQL server escape single quote?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.