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