Questions tagged [sql-injection]

For questions about SQL injection vulnerabilities.

Filter by
Sorted by
Tagged with
6
votes
2answers
816 views

How does use of sp_executesql with parameters protect against SQL injection?

The following is a dynamic filtering solution that uses sp_executesql IF OBJECT_ID(N'dbo.GetOrders', N'P') IS NOT NULL DROP PROC dbo.GetOrders; GO CREATE PROC dbo.GetOrders @orderid AS INT = NULL, @...
0
votes
1answer
113 views

How to pass parameters to sql script via psql \i command

The psql \i command is able to execute a given SQL script but I need a way to pass parameters to the script. Example: say you have this simple script select * from :table LIMIT 1; I've tried my_db=&...
-1
votes
1answer
41 views

Is there any builtin mechanism to stop sql injections in mariadb?

Actually this question is a assignment given to me and I was not able to find any answer by googling. Is there any builtin mechanism in mariadb to stop sql injections?
0
votes
2answers
54 views

Passing parameters in MySql procedure with prepare execute

I am trying to write a procedure that has a location parameter, this parameter is later used in the queries inside the procedure. Also, I want to be able to limit the query results dynamically. I have ...
1
vote
2answers
29 views

Inject aggregation function inside a procedure

Is it possible to inject the name of a function (AVG, MAX...) as a procedure parameter? CREATE PROCEDURE test(func TEXT) LANGUAGE PLPGSQL AS $$ BEGIN DROP TABLE IF EXISTS foo; CREATE TEMPORARY TABLE ...
-1
votes
2answers
83 views

TSQL - Sql Injection

DECLARE @TSQL NVARCHAR(MAX) = N'SELECT 1, ''One'''; CREATE TABLE #ThisIsATable (Id INT, VAL NVARCHAR(10)); INSERT INTO #ThisIsATable EXEC [dbo].[sp_executesql] @TSQL ; Is it safe to have input ...
0
votes
1answer
68 views

Is this SP safe to SQL Injection?

CREATE PROCEDURE [sp_Test] ( @param nvarchar(Max) ) AS BEGIN DECLARE @Output nvarchar(Max) = N’Select ‘ + @param Select @output Return Intended Use exec sp_test ‘5’ Returns “select 5” ...
2
votes
2answers
261 views

Divide by zero in ORDER BY CLAUSE

I just got a PEN-Test result from a web application. The tester stated they were able to use the ORDER BY clause of a dynamic SQL statement to retrieve information. The name of the column that should ...
0
votes
1answer
89 views

How to prevent a highly dynamic PL-SQL query from injection using bind variables

I have a procedure as you can see below: create or replace procedure Injection_test(qry1 varchar2, qry2 varchar2, ...
0
votes
0answers
67 views

If there is no end-user input, is it safe to un-parameterize a parameterized query to avoid parameter sniffing?

AFAIK, a parameterized query is commonly used to prevent SQL injection attacks. What if there is no end-user input that can cause SQL injection? In this case, is it safe to un-parameterize a ...
1
vote
1answer
116 views

SQL Injection penn testing from the queries only

Is there an established method or tool available to perform pen testing on an application by only testing queries it sends to the database? For example, if I have a bunch of SQL Servers hosting ...
0
votes
1answer
326 views

PostgreSQL : Prevent SQL Injection in pl/pgsql function [closed]

I am trying to handle sql injection related to startdate and enddate in the below pl/pgsql function. Let's say If I provide startdate as '2019-10-02' and end date as the following : 2019-10-16', '...
3
votes
1answer
51 views

Closing bracket ']' in LIKE wildcard

I have a query that looks a bit like this: SELECT * FROM Stuff WHERE name LIKE '[a\]]%' My goal is to match all names starting with a or ] (closed bracket). However, this seems to match everything ...
3
votes
2answers
623 views

Dynamic SQL query - how do I add an int to the code?

Consider: Declare @stringsvar varchar(1000) Declare @Emp_id int DECLARE @strvar SYSNAME = 'Employee_test' SET @stringsvar = ('select * from' + ' ' + @strvar + ' where emp_id' + ' =' + @Emp_id) ...
1
vote
1answer
303 views

Security Risks with having Test Stored Procedures that have SQL Injection Vulnerability

I noticed that some of the stored procedures used in our integration tests for data generation have SQL injection vulnerabilities. These procedures are taking into string parameters to build a SQL ...
2
votes
1answer
345 views

Dangerous MySQL functions

It is well-known that the SQL function SLEEP() can be used to attack web applications, e.g. as described here. The sleep function cannot be disabled since it is compiled into the MySQL code and does ...
2
votes
0answers
54 views

Is SQL Injection possible after filtering " and /?

I'm aiming at building dynamic SQL queries that modify columns. The DBMS doesn't allow parameters to be there, so I can't escape identifier using more robust methods. To be clearer, using ? or $1 is ...
0
votes
0answers
29 views

I have created a website using SQL. I want to know whether my website is safe from the SQL injections or not?

The basic code which I used for the admin login and admin password is: </style> <div id="login-form"> <div> </div> <div > <h2 class="text-center">Login<...
1
vote
1answer
542 views

Why most of Sql Injection need url like this "index.asp?id=123"

I am trying to learn "SQL Injection" concepts and also trying to practice some Kali tools to learn, but there is a question that I do not understand and my question is why do most tools need URL's ...
2
votes
2answers
206 views

PostgreSQL. Is using random tag in dollar quoting without escaping input safe?

Is that safe to run such query without escaping input? Assume noone can guess the random string I generate. SELECT * FROM foo WHERE bar = $long random tag$ THIS NOT ESCAPED $long random tag$ What ...
2
votes
0answers
238 views

Is using dollar quoting $$ and removing $ from input enough to avoid SQL injection in PostgreSQL?

I'm coding some logic in embeded Freeswitch LUA and built in database handling does not allow parametric input for SQL, so I need to escape the input. I'm sure my username should not have $ symbols ...
2
votes
1answer
382 views

Invoke-SqlCmd - does casting as integer prevent injection

I am lazy and would rather parameterize once (to get an object_id for a name) and use Invoke-SqlCmd for the rest of the work. Given a series of functions meant to work with an arbitrary server ...
2
votes
2answers
538 views

Safely quoting type names to protect against SQL-injection

How would I quote the type name to protect against SQL Injection. For example, take this SELECT FORMAT('SELECT CAST(%L AS %s);', '5.42', 'int'); ^ ...
3
votes
1answer
118 views

Does concating a string like this open me up to SQL injection?

I recently answered a question with the following code sample: Create Table #Testing ( emaildomain varchar(100) -- Still bigger than functionally needed but better than MAX ); INSERT INTO #Testing ...
2
votes
1answer
525 views

How to make PostreSQL functions private (inaccessible to end users)?

When writing a set of PostgreSQL functions with procedural languages, is it possible to make some of the supporting functions private and not accessible by end users? I wanted to refactor some common ...
3
votes
1answer
96 views

Is it efficient to use plpgsql functions only to validate identifiers and values?

Will my queries be safe from SQL injections if I use plpgsql functions only to validate identifiers and values, instead of executing queries. Here are the example functions: CREATE OR REPLACE ...
11
votes
1answer
1k views

What function quotes an identifier in dynamic-sql with SQL Server?

What is the SQL Server method of safe-quoting identifiers for dynamic sql generation. MySQL has quote_identifier PostgreSQL has quote_ident How do I ensure given a dynamically generated column name ...
5
votes
1answer
2k views

Microsoft SQL Server SQL Injection Through .NET Even With Quote Escaping [closed]

I've been reading up on SQL Injection as part of a security audit for a fairly large web service. I've been googling and read all the posts I could find here and on SO and have a fairly solid ...
1
vote
3answers
821 views

Is there a way to see if database has been accessed through SQL Injection attack?

I recently discovered that my website had a page with a SQL Injection vulnerability. Upon testing, it was easily exploitable with a pentesting tool like sqlmap. How do I figure out if the site ...
4
votes
2answers
3k views

Safe alternative to exec(sql)

I've found some exec(sql) statements buried in the code. They're there for good reason, because these statements couldn't be written directly, however they are an obvious attack vector. Is there a ...
-1
votes
1answer
111 views

Stop a person from entering my database and make changes [closed]

This one is probably very easy for most of you to answer and resolve, but not me... I could use some help and guidance. Someone had got access to my site, and now he keeps deleting tables from the ...
2
votes
0answers
106 views

JDBC Statement vs. Prepared Statement SQL Injection

as far as I understand a "normal" JDBC Statement which is created via conn.createStatement() is prone to SQL-Injection. A prepared statement protects from such attacks. So why/when should I use a ...
9
votes
1answer
3k views

Should we still be using QUOTENAME to protect from injection attacks?

I was looking at an old stored procedure today and noticed it was using quotename on the input parameters. After doing some digging to figure out what that does exactly I came across this site. I now ...
5
votes
1answer
10k views

Wildcard search using parameters in function with dynamic SQL

What is the proper way to implement a wildcard search in PostgreSQL when using a parameter in a function that uses dynamic SQL? As a starting point, here is an example from Erwin Brandstetter ...
7
votes
3answers
147 views

Find the source of a recurrent mass SQL edit on a server

I'll try to explain my problem as clear as possible. The server of a company I support runs many websites. This server runs Windows Server 2012 with Microsoft SQL Server 2014. Almost all of the ...
18
votes
2answers
4k views

Why does SQL Injection not happen on this query inside a stored procedure?

I made the following stored procedure: ALTER PROCEDURE usp_actorBirthdays (@nameString nvarchar(100), @actorgender nvarchar(100)) AS SELECT ActorDOB, ActorName FROM tblActor WHERE ActorName LIKE '%' ...
1
vote
1answer
2k views

Bringing SQL Server filegroups online

We've experienced an sql injection attack which corrupted our main db. The main db had two partitioned tables into filegroups. The corrupt database entered into Suspect mode, and it's been ...
1
vote
0answers
281 views

PostgreSQL DML statements

I am trying to trick an application into executing a DML statement AFTER starting a SELECT statement without using stacked queries so I cannot use the ; character anywhere in my query. I have resorted ...
0
votes
0answers
334 views

SQL Server DB in suspect mode after installing SQL Server 2008 R2 SP3

One of our production DBs is stuck in Suspect mode since we installed SQL Server 2008 R2 SP3. Earlier today we found that most text fields (nvarchar) had the following data appended to it </title&...
0
votes
1answer
1k views

Explain how this real injection attempt works [closed]

We use stored procedures and so far we haven't detected any injections that have been successful, but we see attempts all of the time. I started logging some of the data hoping to gain insight on ...
2
votes
1answer
713 views

Best Practice for Passing and Working With Parameters Security/Performance

Our senior programmer has been having me write stored procedures in the following format to protect against injection attacks. He says that the best practice is to take the parameter in, then declare ...
1
vote
1answer
548 views

Can we use TDE as an anti-injection technique

TDE prevent unauthorized access to the data by restoring the files to another server, because it requires the original encryption certificate and master key. If i applied a table level encryption ...
2
votes
3answers
3k views

Benefits of using prepared statements in stored procedures?

Except from helping avoid SQL injection, what are the benefits - if any - of using prepared statements inside a stored procedure (assume query is only executed once in the procedure)? Does the engine ...
1
vote
1answer
66 views

Could this ActiveRecord/SQL statement in my code base be susceptible to SQL injection?

I was reading up on SQL injection attacks from the Rails Guides and was wondering if the below line could be susceptible to a SQL Injection attack: accounts.where("lower(name) LIKE '%#{params[:query]....
0
votes
2answers
110 views

Searching a database safely using SELECT

I have a site that allows users to search the database for several items. However I am not that good with SQL and I have read that allowing user to type in boxes that then use "SELECT-statements" is ...
4
votes
3answers
2k views

SET ROLE via parameterized query

In the very helpful response I received to a previous question, I am trying to write some JDBC code that first sets the role to a specific user before executing subsequent queries. On the safe side I ...
1
vote
1answer
500 views

How to get more information from dm_exec_query_stats

I am running SQL server 2012 on windows azure VM (windows server 2012) I suspected that some of my web appliactions are attacked via SQL injection, So far i could not trace the relevant text with my ...
3
votes
3answers
537 views

Preventing SQL Injection

I know that this is very dangerous: EXEC sp_executesql 'SELECT * FROM ' + @Table But, is this safe from SQL injection? IF EXISTS(SELECT * FROM information_schema.tables WHERE TABLE_NAME = @Table) ...
0
votes
2answers
657 views

Are these linked server queries susceptible to SQL injection?

I'm using a stored procedure to generate a create table script on the fly based on parameters passed into it. I am validating that the server exists, and then validating if the table exists in the ...
1
vote
1answer
79 views

Am I using the ORDER BY clause incorrectly

I am trying to enumerate a database, created specifically for the purpose of learning SQL injections. I am trying to discover the number of columns a particular select statement might be using. I do ...