Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

SQL Injection Attack
All,
I am trying to test an attack against a web page. The VBScript runs 2
queries against the database; the first must succeed before the second
runs. Here is the code:

1st-
select * from users where (userid=' + @string + ') and password=' +
@pwdstring + '

2nd-
select * from permissions where userid=' + @string + '

When attempting the attack the problem lies in the "(" & ")"
surrounding the first userid string in the 1st query. if I attempt to
put a ")" in the original @string function to cancel out the first "("
it then causes problems for the second string. Also, the @pwdstring
gets encrypted before it is sent to the SQL Server, so attempting the
attack from that field is useless.

For instance:
@string = ' or 1=1)--
@pwdstring = blank (becomes @pwdstring = 55-12-567-3244-123 due to
encryption)

select * from users where (userid='' or 1=1)--') and
password='55-12-567-3244-123' WORKS OK
select * from permissions where userid='' or 1=1)--' DOES NOT WORK

Is this an instance where the original developers made a happy coding
error (I asked and preventing injection attacks wasn't intended) or is
there something I can do to circumvent this?

Thanks,
josh


Report this thread to moderator Post Follow-up to this message
Old Post
joshsackett
05-24-05 01:24 AM


Re: SQL Injection Attack
joshsackett (joshsackett@gmail.com)  writes:
> For instance:
> @string = ' or 1=1)--
> @pwdstring = blank (becomes @pwdstring = 55-12-567-3244-123 due to
> encryption)
>
> select * from users where (userid='' or 1=1)--') and
> password='55-12-567-3244-123' WORKS OK
> select * from permissions where userid='' or 1=1)--' DOES NOT WORK
>
> Is this an instance where the original developers made a happy coding
> error (I asked and preventing injection attacks wasn't intended) or is
> there something I can do to circumvent this?

I am afraid that I don't understand. There may or may not be a string
that can be used for both queries, but both of them are open to SQL
injection, and that's bad enough. You make it like SQL injection is a
desired feature, but find it difficult to understand such requirements.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
05-24-05 01:24 AM


Re: SQL Injection Attack
I don't understand either - why don't you just use a stored procedure
i.e. the recommended approach?

This is cleaner, simpler and does not offer any possibility for a SQL
injection attack.

Malc
www.dbghost.com


Report this thread to moderator Post Follow-up to this message
Old Post
Malcolm
05-24-05 12:23 PM


Re: SQL Injection Attack
Malcolm  wrote:
> I don't understand either - why don't you just use a stored procedure
> i.e. the recommended approach?
>
> This is cleaner, simpler and does not offer any possibility for a SQL
> injection attack.
>
> Malc
> www.dbghost.com

Using prepared statments seems to be another approach that does not suffer
this risk.

robert


Report this thread to moderator Post Follow-up to this message
Old Post
Robert Klemme
05-24-05 04:23 PM


Re: SQL Injection Attack
I suppose I didn't make myself entirely clear.. I have been contracted
to find vulnerabilities in a customer's web page. I examined their code
and found this login page to be an excellent candidate to display to
them what a SQL injection attack is. Once I prove to them that it is
simple to hack directly into their database using an attack I am going
to suggest changing the code to a stored procedure (as well as checking
the text fields for invalid characters).

I just cannot thing of a @string that satisfies both queries.


Report this thread to moderator Post Follow-up to this message
Old Post
joshsackett
05-24-05 06:23 PM


Re: SQL Injection Attack
On 24 May 2005 10:29:50 -0700, joshsackett wrote:

>I suppose I didn't make myself entirely clear.. I have been contracted
>to find vulnerabilities in a customer's web page. I examined their code
>and found this login page to be an excellent candidate to display to
>them what a SQL injection attack is. Once I prove to them that it is
>simple to hack directly into their database using an attack I am going
>to suggest changing the code to a stored procedure (as well as checking
>the text fields for invalid characters).
>
>I just cannot thing of a @string that satisfies both queries.

Hi Josh,

If you need to demonstrate the harm that can be done, try

set @string = ''') drop table permissions --'

Or

set @string = ''') shutdown with nowait --'



Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Report this thread to moderator Post Follow-up to this message
Old Post
Hugo Kornelis
05-25-05 01:23 AM


Re: SQL Injection Attack
Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo)  writes:
> set @string = ''') shutdown with nowait --'

That one is good! Then Josh does not need to worry about the syntax
error in the second statement, because there will be no server that
can detect it!

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
05-25-05 01:24 AM


Re: SQL Injection Attack
Hugo - Thank you!
I can't believe I totally overlooked the obvious. I appreciate the help!


Report this thread to moderator Post Follow-up to this message
Old Post
joshsackett
05-25-05 02:23 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 11:42 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006