Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 533705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:32:10+00:00 2026-05-13T09:32:10+00:00

The problem We need to defend against a ‘WAITFOR DELAY’ sql injection attack in

  • 0

The problem

We need to defend against a ‘WAITFOR DELAY’ sql injection attack in our java application.

Background

[This is long. Skip to ‘Solution?’ section below if you’re in a rush ]

Our application mostly uses prepared statements and callable statements (stored procedures) in accessing the database.

In a few places we dynamically build-and-execute queries for selection. In this paradigm we use a criteria object to build the query depending on the user-input criteria. For example, if the user specified values for first_name and last_name, the result querying always looks something like this:

SELECT first_name,last_name FROM MEMBER WHERE first_name ='joe' AND last_name='frazier'

(In this example the user would have specified “joe” and “frazier” as his/her input values. If the user had more or less critieria we would have longer or shorter queries. We have found that this approach is easier than using prepared statements and quicker/more performant than stored procedures).

The attack

A vulnerability audit reported an sql injection failure. The attacker injected the value ‘frazier WAITFOR DELAY ’00:00:20’ for the ‘last_name’ parameter, resulting in this sql:

   SELECT first_name,last_name FROM MEMBER WHERE first_name ='joe' AND last_name='frazier' WAITFOR DELAY '00:00:20'

The result: the query executes successfully, but takes 20 seconds to execute. An attacker could tie up all your database connections in the db pool and effectively shut down your site.

Some observations about this ‘WAITFOR DELAY’ attack

  • I had thought that because we used Statement executeQuery(String) we would be safe from sql injection. executeQuery(String) will not execute DML or DDL (deletes or drops). And executeQuery(String) chokes on semi-colons, thus the ‘Bobby Tables’ paradigm will fail (i.e. user enters ‘frazier; DROP TABLE member’ for a parameter. See. http://xkcd.com/327/)

  • The ‘WAITFOR’ attack differs in one important respect: WAITFOR modifies the existing ‘SELECT’ command, and is not a separate command.

  • The attack only works on the ‘last parameter’ in the resulting query. i.e. ‘WAITFOR’ must occur at the very end of the sql statement

Solution, Cheap Hack, or Both?

The most obvious solution entails simply tacking “AND 1=1” onto the where clause.

The resulting sql fails immediately and foils the attacker:

   SELECT first_name,last_name FROM MEMBER WHERE first_name ='joe' AND last_name='frazier' WAITFOR DELAY '00:00:20' AND 1=1

The Questions

  • Is this a viable solution for the WAITFOR attack?
  • Does it defend against other similar vulnerabilities?
  • I think the best option would entail using prepared statements. More work, but less vulnerable.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:32:10+00:00Added an answer on May 13, 2026 at 9:32 am

    The correct way to handle SQL injection is to use parameterized queries. Everything else is just pissing in the wind. It might work one time, even twice, but eventually you’ll get hit by that warm feeling that says “you screwed up, badly!”

    Whatever you do, except parameterized queries, is going to be sub-optimal, and it will be up to you to ensure your solution doesn’t have other holes that you need to patch.

    Parameterized queries, on the other hand, works out of the box, and prevents all of these attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java background so I’m used to having Maven handle all problem
Goal: Gain datatype date with year and month Problem: Need to help to convert
Problem: I need to write/read objects from a file.This because I need to write/read
The problem: I need to ensure that a particular directory hierarchy exists in the
My problem : I need to create draggable widgets (here it's a jslider for
To solve some problem I need to compute a variant of the pascal's triangle
I faced a problem - I need to use a macro value both as
I have problem i need to convert from my Array structure to std::vector<int> ...
i got some problem and need help .. my plan : 1. get ip
I have the following problem: I need to use XSLFO to generate a 2-column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.