Java Web SQL injection Test (2)---instance test

Source: Internet
Author: User
Tags java web

In the following space, a simple example is used to illustrate how to test.

Function: Delete user according to user name, adopt the way of SQL stitching, the core code part is as follows:

Public Static void deletebyname (String name)throws exception{

Session session = Seesionfactory. opensession ();

Org.hibernate.Transaction tx = Session.begintransaction ();

Try

{

String hql= "Delete from Department where name= '" + name + "'";

Query query = session.createquery (HQL);

int res = query.executeupdate ();

Tx.commit ();

System. out. println (res);

}

Catch (Hibernateexception e)

{

System. out. println ("Deletebyname have Exception!");

E.printstacktrace ();

if (null ! = TX)

{

Tx.rollback ();

}

}

The corresponding tables in the database contain the following records:

Test code:

String name= "1";

Deletebyname (name);

A record of the database is not deleted after execution.

Instead, execute the following test code:

String name= "1 ' or ' 1 ' = ' 1";

Deletebyname (name);

All two records of the database were emptied after execution.

Clearly the database is no name=1 records exist, but incredibly all deleted, the reason is the existence of malicious SQL, the system is not properly processed, resulting in the Where condition is always true, delete all the data in the table.

Java Web SQL injection Test (2)---instance test

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.