Delphi considers SQL injection QUOTEDSTR

Source: Internet
Author: User

Previously only in the BS architecture of the project to consider the SQL injection problem, but rarely consider the use of the Delphi project for many years should also consider the issue of SQL injection, today did an experiment, successfully completed the injection, the table data are all deleted, and then do Delphi Project also really consider this issue.

Generally speaking, generally know there are two ways to avoid the Delphi SQL injection: 1, the use of quotedstr instead of "" string splicing, 2, the use of parameters to interact with the database, this way to carefully experience the day.

Here is a small test, a simple INSERT statement, if the Edit1 content is
ABC ') delete from tb1 insert into TB1 (Id, Name) VALUES (123, ' xxxx
After running, the data in the TB1 table will all be cleared, leaving only the insert into TB1 (Id, Name) VALUES (123, ' xxxx
Add a piece of

[Delphi]View Plaincopy
  1. Procedure TForm1.  Button1Click (Sender:tobject);
  2. Var
  3. sqlstr:string;
  4. Begin
  5. SQLSTR: = ' INSERT into TB1 (Id, Name) VALUES (1, ' "+ edit1.  Text + ') ';
  6. Self. ADOQuery1. SQL.  Text: = Sqlstr;
  7. Self. ADOQuery1.  Execsql;
  8. ShowMessage (' successfully completed SQL injection ');
  9. End

Change to Sqlstr: = ' insert into TB1 (Id, Name) VALUES (1, ' + quotedstr (edit1. Text) + ') ';

can be avoided.

Quotedstr refer to the following statement:

adoquery1.sql.text:=
' Select character number from yourtable where character type number = ' abc ' and integer number = 123 ';
Equivalent to
adoquery1.sql.text:=
' Select ' +afieldname+ ' from ' +atablename+ ' where ' +afieldname
+ ' = ' ' +astr+ ' and integer number = ' +anintstr;
is also equivalent to
adoquery1.sql.text:=
' Select ' +afieldname+ ' from ' +atablename+ ' where ' +afieldname
+ ' = ' +quotedstr (AStr) + ' and integer number = ' +inttostr (anint);
Upload to Database server:
Select character number from yourtable where character type number = ' abc ' and integer number =123

Delphi considers SQL injection QUOTEDSTR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.