Questions tagged [sql-injection]

For questions about SQL injection vulnerabilities.

Filter by
Sorted by
Tagged with
0 votes
2 answers
56 views

I'm trying to make an SQL injection in my own function in PostgreSQL 13

Just for learning purposes, I'm trying to create a function using PLPGSQL and make an SQL injection on it. I recently learned about format, USING and quote_literal and quote_indent, so I'm good about ...
user avatar
0 votes
1 answer
41 views

Allow create table (dynamic name) and insert but nothing else

I'm trying to find a way to allow an application to create tables and insert data into them on a SQL Server 2019 while protecting from injection attacks in case the app credentials would leak. My ...
user avatar
0 votes
1 answer
17 views

Second Subquery Inside INSERT Into saves int 0

Read it carefully, we have this query which is inserting values in the table called users. For the value member_id we are running a subquery to select from the table admin_users the id of the member. ...
user avatar
7 votes
2 answers
945 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, @...
user avatar
0 votes
1 answer
1k 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=&...
user avatar
-1 votes
1 answer
45 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?
user avatar
0 votes
2 answers
91 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 ...
user avatar
  • 1
1 vote
2 answers
34 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 ...
user avatar
  • 15
-1 votes
2 answers
108 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 ...
user avatar
0 votes
1 answer
70 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” ...
user avatar
  • 11
2 votes
2 answers
332 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 ...
user avatar
0 votes
1 answer
111 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, ...
user avatar
  • 1,302
0 votes
0 answers
72 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 ...
user avatar
1 vote
1 answer
128 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 ...
user avatar
  • 145
0 votes
1 answer
398 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', '...
user avatar
3 votes
1 answer
56 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 ...
user avatar
3 votes
2 answers
666 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) ...
user avatar
1 vote
1 answer
328 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 ...
user avatar
2 votes
1 answer
393 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 ...
user avatar
2 votes
0 answers
55 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 ...
user avatar
0 votes
0 answers
31 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<...
user avatar
1 vote
1 answer
578 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 ...
user avatar
  • 137
2 votes
2 answers
232 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 ...
user avatar
2 votes
0 answers
261 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 ...
user avatar
2 votes
1 answer
459 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 ...
user avatar
2 votes
2 answers
562 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'); ^ ...
user avatar
  • 56.2k
3 votes
1 answer
120 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 ...
user avatar
  • 4,722
2 votes
1 answer
618 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 ...
user avatar
  • 2,824
3 votes
1 answer
101 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 ...
user avatar
  • 145
11 votes
1 answer
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 ...
user avatar
  • 56.2k
5 votes
1 answer
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 ...
user avatar
  • 471
1 vote
3 answers
856 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 ...
user avatar
  • 11
4 votes
2 answers
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 ...
user avatar
  • 891
-1 votes
1 answer
116 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 ...
user avatar
2 votes
0 answers
107 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 ...
user avatar
  • 121
9 votes
1 answer
4k 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 ...
user avatar
5 votes
1 answer
11k 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 ...
user avatar
  • 675
7 votes
3 answers
149 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 ...
user avatar
18 votes
2 answers
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 '%' ...
user avatar
  • 657
1 vote
1 answer
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 ...
user avatar
1 vote
0 answers
285 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 ...
user avatar
  • 33
0 votes
0 answers
336 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&...
user avatar
0 votes
1 answer
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 ...
user avatar
  • 77
2 votes
1 answer
726 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 ...
user avatar
  • 77
1 vote
1 answer
559 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 ...
user avatar
2 votes
3 answers
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 ...
user avatar
  • 165
1 vote
1 answer
72 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]....
user avatar
  • 147
0 votes
2 answers
115 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 ...
user avatar
4 votes
3 answers
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 ...
user avatar
  • 1,610
1 vote
1 answer
528 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 ...
user avatar
  • 11