J
joesin
I recently found a vulnerability on my website that allowed sql
injection. I have been trying to write some code that would clean user
data but have been running into problems. The validation still works,
however so does the injection methods I have used....
These are the examples of code I have tried to use to fix the problem.
1. FrmUserName=replace (FrmUserName, " ' ", "")
2. function stripQuotes(FrmUserName)
stripQuotes = replace(FrmUserName, "'", "''")
end function
3. Function InputFilter(userInput)
Dim newString, regEx
Set regEx = New RegExp
regEx.Pattern = " ' "
regEx.IgnoreCase = True
regEx.Global = True
newString = regEx.Replace(userInput, "")
Set regEx = nothing
InputFilter = newString
End Function
here is the validation I am currently using...
++++++++++++++++++++++++++++++++++++++++++++++
DIM oDBConn, oDBRS, oDBCommand
DIM oDBString, oDBSQL
DIM frmUserName,frmPassword
Set oDBConn = Server.CreateObject("ADODB.Connection")
Set oDBRS = Server.CreateObject("ADODB.Recordset")
Set oSYSDB = Server.CreateObject("ADODB.REcordset")
Set oDBCommand = Server.CreateObject("ADODB.Command")
' On Error Resume Next
oDBString = Application("Database1_ConnectionString")
oDBConn.Open oDBString
If Session("validated") = 0 OR IsNull(Session("validated"))=True Then
frmUserName = Request.Form("UserName")
frmPassword = Request.Form("Password")
oDBSQL = "SELECT * FROM WEBUSERS WHERE UPPER(USERNAME)='"&
UCase(frmUserName) &"' AND PWD='"& frmPassword &"'"
oDBRS.Open oDBSQL,oDBConn,adOpenDynamic
If oDBRS.EOF = False Then
If oDBRS("STATUS") = 1 Then
Session("UserClass") = oDBRS("CLASS")
Session("UserID") = oDBRS("SYSID")
Session("UserName") = oDBRS("FIRSTNAME")&" "& oDBRS("LASTNAME")
Session("Validated") = 1
Session("Marketer") = oDBRS("MARKETER")
If IsNull(oDBRS("TELEPHONE1"))=True or
IsNull(oDBRS("MARKETER"))=True Then
Session("UpdateProfile") = 1
Else
Session("UpdateProfile") = 2
End If
Else
AccessDenied
End If
Else
displaybadlogin
End If
End If
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
any suggestions would be greatly appreciated.
Thanks Very Much
Joe Sin
injection. I have been trying to write some code that would clean user
data but have been running into problems. The validation still works,
however so does the injection methods I have used....
These are the examples of code I have tried to use to fix the problem.
1. FrmUserName=replace (FrmUserName, " ' ", "")
2. function stripQuotes(FrmUserName)
stripQuotes = replace(FrmUserName, "'", "''")
end function
3. Function InputFilter(userInput)
Dim newString, regEx
Set regEx = New RegExp
regEx.Pattern = " ' "
regEx.IgnoreCase = True
regEx.Global = True
newString = regEx.Replace(userInput, "")
Set regEx = nothing
InputFilter = newString
End Function
here is the validation I am currently using...
++++++++++++++++++++++++++++++++++++++++++++++
DIM oDBConn, oDBRS, oDBCommand
DIM oDBString, oDBSQL
DIM frmUserName,frmPassword
Set oDBConn = Server.CreateObject("ADODB.Connection")
Set oDBRS = Server.CreateObject("ADODB.Recordset")
Set oSYSDB = Server.CreateObject("ADODB.REcordset")
Set oDBCommand = Server.CreateObject("ADODB.Command")
' On Error Resume Next
oDBString = Application("Database1_ConnectionString")
oDBConn.Open oDBString
If Session("validated") = 0 OR IsNull(Session("validated"))=True Then
frmUserName = Request.Form("UserName")
frmPassword = Request.Form("Password")
oDBSQL = "SELECT * FROM WEBUSERS WHERE UPPER(USERNAME)='"&
UCase(frmUserName) &"' AND PWD='"& frmPassword &"'"
oDBRS.Open oDBSQL,oDBConn,adOpenDynamic
If oDBRS.EOF = False Then
If oDBRS("STATUS") = 1 Then
Session("UserClass") = oDBRS("CLASS")
Session("UserID") = oDBRS("SYSID")
Session("UserName") = oDBRS("FIRSTNAME")&" "& oDBRS("LASTNAME")
Session("Validated") = 1
Session("Marketer") = oDBRS("MARKETER")
If IsNull(oDBRS("TELEPHONE1"))=True or
IsNull(oDBRS("MARKETER"))=True Then
Session("UpdateProfile") = 1
Else
Session("UpdateProfile") = 2
End If
Else
AccessDenied
End If
Else
displaybadlogin
End If
End If
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
any suggestions would be greatly appreciated.
Thanks Very Much
Joe Sin