Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Injection

SQL Injection

Scheduled Pinned Locked Moved Database
databasetutorialquestion
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ritesh1234
    wrote on last edited by
    #1

    Is SQL Injection is possible even after replacing all single quote i.e ' from the user input with two single quote i.e '' ? .If so can you give me any example.

    M D 2 Replies Last reply
    0
    • R Ritesh1234

      Is SQL Injection is possible even after replacing all single quote i.e ' from the user input with two single quote i.e '' ? .If so can you give me any example.

      M Offline
      M Offline
      Mark Churchill
      wrote on last edited by
      #2

      Using parameterized queries is better practice anyway.

      Mark Churchill Director Dunn & Churchill Diamond Binding: Zero to Data Layer in 3 mins

      R 1 Reply Last reply
      0
      • M Mark Churchill

        Using parameterized queries is better practice anyway.

        Mark Churchill Director Dunn & Churchill Diamond Binding: Zero to Data Layer in 3 mins

        R Offline
        R Offline
        Ritesh1234
        wrote on last edited by
        #3

        there there is no way to inject after replacing ' with '' :^)

        C 1 Reply Last reply
        0
        • R Ritesh1234

          Is SQL Injection is possible even after replacing all single quote i.e ' from the user input with two single quote i.e '' ? .If so can you give me any example.

          D Offline
          D Offline
          Dave B
          wrote on last edited by
          #4

          This Page http://www.sommarskog.se/dynamic_sql.html[^] Contains a lot of info about sql injection

          R 1 Reply Last reply
          0
          • D Dave B

            This Page http://www.sommarskog.se/dynamic_sql.html[^] Contains a lot of info about sql injection

            R Offline
            R Offline
            Ritesh1234
            wrote on last edited by
            #5

            thankx for link.I went through this but still could not got my answer. Can u pls help me out to find in what way this query can venerable to SQL injection strQuery = "select * from Table where Name ='" & strName.Replace("'","''") & "'"

            P D 2 Replies Last reply
            0
            • R Ritesh1234

              thankx for link.I went through this but still could not got my answer. Can u pls help me out to find in what way this query can venerable to SQL injection strQuery = "select * from Table where Name ='" & strName.Replace("'","''") & "'"

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Why are you looking to do this? It's much better to use parameters which take care of these things for you and are a much better way of preventing SQL Injection attacks. Please read this[^] article and do yourself a favour.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              1 Reply Last reply
              0
              • R Ritesh1234

                thankx for link.I went through this but still could not got my answer. Can u pls help me out to find in what way this query can venerable to SQL injection strQuery = "select * from Table where Name ='" & strName.Replace("'","''") & "'"

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Ritesh1234 wrote:

                Can u pls help me out to find in what way this query can venerable to SQL injection

                Yes, it's STILL an injection attack, and a rather successful one if the code that depends on this query doesn't expect to find 0 results comming back. The replacement of ' with '' is NOT a guarantee against injection attacks, and neither is using parameterized queries, though using parameters and the SqlParameter objects does look for other possible problems that you don't normally think of, such as DateTime representation in the SQL statement. Simply put, there is no reason NOT to use parameterized queries and stored procedures. It makes you code much more robust, easier to debug, and easier to support when it breaks, not if. It's also no excuse for not thoroughly checking user input before you pass it to SQL, which is what you're code snippet is suggesting you're not doing. Consider ALL user input as evil. It MUST go through validation testing before you try to use it. What if the user typed in 1000+ characters into that textbox?? What happens when you pass that to your SQL, which is only expecting, maybe, 14 characters?? What you have is a lazy way of attempting to secure your SQL code without understanding what an SQL Injection attack really is. Make no mistake, your "solution" is not secure, not in the least. Read this[^] or Colin will make you read it.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007

                R 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Ritesh1234 wrote:

                  Can u pls help me out to find in what way this query can venerable to SQL injection

                  Yes, it's STILL an injection attack, and a rather successful one if the code that depends on this query doesn't expect to find 0 results comming back. The replacement of ' with '' is NOT a guarantee against injection attacks, and neither is using parameterized queries, though using parameters and the SqlParameter objects does look for other possible problems that you don't normally think of, such as DateTime representation in the SQL statement. Simply put, there is no reason NOT to use parameterized queries and stored procedures. It makes you code much more robust, easier to debug, and easier to support when it breaks, not if. It's also no excuse for not thoroughly checking user input before you pass it to SQL, which is what you're code snippet is suggesting you're not doing. Consider ALL user input as evil. It MUST go through validation testing before you try to use it. What if the user typed in 1000+ characters into that textbox?? What happens when you pass that to your SQL, which is only expecting, maybe, 14 characters?? What you have is a lazy way of attempting to secure your SQL code without understanding what an SQL Injection attack really is. Make no mistake, your "solution" is not secure, not in the least. Read this[^] or Colin will make you read it.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007

                  R Offline
                  R Offline
                  Ritesh1234
                  wrote on last edited by
                  #8

                  thanks buddy for u r valuable input well first of all this is NOT my way coding and i raised this question just to find out any good EXAMPLE how attacker can take advantage of this poorly fabricated query.Though we all advocating parameterized queries and stored procedures including ME and even this query seems easily attackable but still could not figured out HOW neither got any single example from anyone :^) btw that was the first article which make me aware of the SQL injection long ago :-O

                  D 1 Reply Last reply
                  0
                  • R Ritesh1234

                    thanks buddy for u r valuable input well first of all this is NOT my way coding and i raised this question just to find out any good EXAMPLE how attacker can take advantage of this poorly fabricated query.Though we all advocating parameterized queries and stored procedures including ME and even this query seems easily attackable but still could not figured out HOW neither got any single example from anyone :^) btw that was the first article which make me aware of the SQL injection long ago :-O

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    "The Six Dumbest Ideas in Computer Security[^]" is one of the best essays I've seen on security. Make sure you pay attention to point #2. How many different ways are there to hack a database?? There are dozens and dozens of them. Now add the poor security in your code and you've opened up dozens more. Are you going to address each one of these vulnerabilities on an individual basis, such as that one Replace statement?? How about the other 9,999 vulnerabilities?? Starting to see the point behind "Enumerating Badness"?? If you read the entire article, it explains perfectly why the mere existance of virus scanning software is a stupid idea. And it's one which I happen to subscribe to.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    1 Reply Last reply
                    0
                    • R Ritesh1234

                      there there is no way to inject after replacing ' with '' :^)

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #10

                      What about injecting into values that don't need quotes around them?

                      Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Follow up on hiring a software developer * The Value of Smaller Methods My website | blog

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups