Can someone explain this SQL injection attack to me?

后端 未结 5 408
甜味超标
甜味超标 2020-12-08 02:04

I wanted to post this here as it is very much coding related and was something I had to clean up this week on one of my company\'s old ASP (classic) sites.

We got hi

5条回答
  •  情深已故
    2020-12-08 02:52

    Look at changing your queries like this;

    Dim oConn, oRS, SQL
    'Query open to attack
    SQL = "SELECT * FROM [Table] WHERE [id] = " & Request.QueryString("id")
    
    Set oConn = Server.CreateObject("ADODB.Connection")
    Call oConn.Open(conn_string_from_inc)
    
    Set oRS = oConn.Execute(SQL)    
    
    Call oConn.Close()
    Set oConn = Nothing
    

    To something like this;

    Dim oCmd, oRS, SQL
    SQL = "SELECT * FROM [Table] WHERE [id] = ?"
    
    Set oCmd = Server.CreateObject("ADODB.Command")
    With oCmd
      .ActiveConnection = conn_string_from_inc
      .CommandType = adCmdText
      .CommandText = SQL
      Call .Parameters.Append(.CreateParameter("@id", adInteger, adParamInput, 4))
      .Parameters("@id").Value = Request.QueryString("id")
      Set oRS = .Execute()
    End With
    Set oCmd = Nothing
    

    This is just a crude example of combating SQL Injection without resorting to sanitizing input. I would still approach this differently.

提交回复
热议问题