Forum Moderators: phranque
Is there any way to find out the page through which the values were inserted into the database
Any page that does this:
<input type="text" name="test">
....
echo "$_POST['test']"; // or $_GET, or $_REQUEST, whatever
Means your data is passing through unfiltered and vulnerable.
Another, substitute "test" for any valid form field in your scripts, and "scriptname" for any script.
http://www.example.com/scriptname.php?test=%22%3E%3Cscript%3Ealert%28123%29%3C%2Fscript%3E%22
If you get an alert "123" your scripts are also vulnerable to cross site scripting. Either can be a cause.
Anything that accepts input . . . needs to be examined.
Every user input is a potential hack. - Selena Sol
Private Function RemChr(byVal string, byVal remove)
Dim i, j, tmp, strOutput
strOutput = ""
for j = 1 to len(string)
tmp = Mid(string, j, 1)
for i = 1 to len(remove)
tmp = replace( tmp, Mid(remove, i, 1), "")
if len(tmp) = 0 then exit for
next
strOutput = strOutput & tmp
next
RemChr = strOutput
End Function
[edited by: dukelips at 10:06 am (utc) on Jan. 1, 2010]
The best approach is to always use parameterised queries instead of dynamic SQL strings.
You should also validate all user input e.g. if your code requires an integer as input, check an integer is passed not a string; if it's not what you expect display error and abort or set to a default value.
ASP Example: SQL Stored Procedure with an Integer parameter:
Set cmd = Server.CreateObject("ADODB.Command")
With cmd
.ActiveConnection = cnn
.CommandText = "MyStoredProcedure"
.CommandType = adCmdStoredProc
.Parameters.Append cmd.CreateParameter("MyID", adInteger, adParamInput, 0, MyID)
End With
Set rs = cmd.Execute()
ASP Example: Parameterised SQL String with a varchar(50) parameter (question marks are used as placeholders for parameters):
sql = "SELECT * FROM MyTable WHERE MyField = ?;"
Set cmd = Server.CreateObject("ADODB.Command")
With cmd
.ActiveConnection = cnn
.CommandText = sql
.CommandType = adCmdText
.Parameters.Append cmd.CreateParameter("MyValue", adVarChar, adParamInput, 50, MyValue)
End With
Set rs = cmd.Execute()
More info: [owasp.org...]