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 475065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:21:04+00:00 2026-05-13T00:21:04+00:00

Background I’ve been contracted to analyze an existing Data Provider and I know the

  • 0

Background

I’ve been contracted to analyze an existing Data Provider and I know the following code is faulty; but in order to point out how bad it is, I need to prove that it’s susceptible to SQL injection.

Question

What "Key" parameter could break the PrepareString function and allow me to execute a DROP statement?

Code Snippet

Public Shared Function GetRecord(ByVal Key As String) As Record
    Dim Sql As New StringBuilder()

    With Sql
        .Append("SELECT * FROM TableName")
        If String.IsNullOrEmpty(Agency) Then
            .Append(" ORDER BY DateAdded")
        Else
            .Append(" WHERE Key = '")
            .Append(PrepareString(Key))
            .Append("'")
        End If
    End With

    Return ExecuteQuery(Sql.ToString())
End Function

Public Shared Function PrepareString(ByVal Value As String) As String
    Return Value.Replace("''", "'") _
                .Replace("'", "''") _
                .Replace("`", "''") _
                .Replace("´", "''") _
                .Replace("--", "")
End Function
  • 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-13T00:21:04+00:00Added an answer on May 13, 2026 at 12:21 am

    In answer to your direct question: Does this code prevent SQL injection: No

    Here’s the proof – push this string through the PrepareString method:

    Dim input = "'" & Chr(8) & "; Drop Table TableName; - " & Chr(8) & "-"
    Dim output = PrepareString(input)
    
    Console.WriteLine(input)
    Console.WriteLine(output)
    

    I modified the GetRecord method you posted to return the fully prepared SQL string rather than get the record from the database:

    Console.WriteLine(GetRecord(output))
    

    And this is the output

    Input  = ; Drop Table TableName; --
    Output = '; Drop Table TableName; --
    Query  = SELECT * FROM TableName WHERE Key = ''; Drop Table TableName; --'
    

    Add 1 extra line of code:

    My.Computer.Clipboard.SetText(input)
    

    And you’ve got the string you need copied right to your clipboard to paste into your input field on the website to complete your SQL injection:

    '; Drop Table TableName; - -
    

    [Noting that the control characters have been omitted from the post output by StackOverflow, so you’ll have to follow the code example to create your output]

    After the PrepareString method is run, it will have the exact same output – the Chr(8) ASCII code is the backspace which will remove the extra “‘” that you’re appending to mine which will close your string and then I’m free to add whatever I want on the end. Your PrepareString doesn’t see my — because I’m actually using – – with a backspace character to remove the space.

    The resulting SQL code that you’re building will then execute my Drop Table statement unhindered and promptly ignore the rest of your query.

    The fun thing about this is that you can use non-printable characters to basically bypass any character check you can invent. So it’s safest to use parameterized queries (which isn’t what you asked, but is the best path to avoid this).

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

Sidebar

Related Questions

Background: I am attempting to do a couple of unit tests on AJAX requests
Background: I'm writing an installation for a SharePoint component. In addition to getting the
Background We have a Windows .NET application used by our field employees who travel
Background: I'm working on a system where the developers seem to be using a
Background : I currently have a Web Forms, ASP.NET 3.5/C# application which I'm interested
Background: writing an automated release script to export changed files between versions from SVN
Background I'm trying to get obtain a unique identifier out of a computer and
Background: I'm using Google's protobuf , and I would like to read/write several gigabytes
Background I have a web app that will create an image from user input.
Background: Our companies internal user's run our .Net programs on 10-20 windows terminal servers.

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.