Proving SQL Injection

后端 未结 5 1077
旧巷少年郎
旧巷少年郎 2021-01-01 01:24

I\'m trying to simply prove here that this simple function isn\'t good enough to prevent every sql injection in the world:

Function CleanForSQL(ByVal input A         


        
5条回答
  •  心在旅途
    2021-01-01 01:56

    Scott Ivey has the classic case that can break it, the lack of quotes protecting a numeric input. (+1'ed that)

    Depending on the language and where the string is being 'cleansed' and the database being used your immediate risk is that they language permits the string to be escaped. At that point the single quote you are trying to avoid getting thru goes wrong

    \'; DROP yourTable;-- => \''; DROP yourTable;--

    That goes into your sql string as

    UPDATE tblFilledForms SET Text1 = '" + \''; DROP yourTable;-- + ' etc.
    

    Which is then:

    UPDATE tblFilledForms SET Text1 = '\''; DROP yourTable;-- ' etc.
    

    '\'' is taken as the literal string of a single quote, if your database supports escaped characters - bingo your compromised.

    Equally the protection has to be remembered to be effective, even the example update statement provided failed to protect the parameter in the where clause, was it because DGVNotes.SelectedRows(0).Cells("FilledFormID").Value.ToString) could never be entered by a user? will that hold true for the entire lifetime of the app etc?

提交回复
热议问题