deleting DB & tables via webforms

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default deleting DB & tables via webforms

    Hi all

    I heard that my DB tables can be truncated, deleted & dropped via uses
    using my forms on my site

    when a form asks for something like "name & passoword" IE a login form
    this is where users/hackers can do nasty things.

    instead of typing in the username they type something like:

    ' ; DROP DB

    I'm not sure what they can type or how as you need things like DB &
    table names.

    My question is basically - how do you people stop people doing things
    like this???

    I'm using W2k Pro IIS5, ASP 3.0, and SQL Server. I'm going to have
    quite a lot of forms when the projects completed and would like to
    solve this issue asap.

    thanks for any help.

    Al

    Harag Guest

  2. Similar Questions and Discussions

    1. CDONTS - WebForms - Pls Help
      I am hoping that someone can help me Here is what I want to do; I need to have a htm page that has text boxes that website visitors fill out...
    2. Deleting row generated from multiple tables
      I am having a hell of a time removing a row from my datagrid that was generated from 2 different tables. I get the following error... Dynamic...
    3. [PHP] deleting one cookie is deleting both..why? (tiny scripts)
      --- Ryan A <ryan@jumac.com> wrote: If you are setting the cookie from bestwebhosters.com, the best way (my opinion) is to not specify the domain,...
    4. deleting one cookie is deleting both..why? (tiny scripts)
      Hi again, I am setting 2 cookies like so:(setCookie.php) <?php setcookie("name1","1","0","",".bestwebhosters.com");...
    5. HELP - WebForms as HttpResponseHandlers
      Hello All, I'm using the <httpHandlers> section of the web.config file to specify a webform class (WebForm1) that is the base class for...
  3. #2

    Default Re: deleting DB & tables via webforms

    See the SQL Injection FAQ at [url]www.sqlsecurity.com[/url].

    Basically, you can stop all of this by using stored procedures instedad of
    dynamic SQL.

    Bob Barrows

    Harag wrote:
    > Hi all
    >
    > I heard that my DB tables can be truncated, deleted & dropped via uses
    > using my forms on my site
    >
    > when a form asks for something like "name & passoword" IE a login form
    > this is where users/hackers can do nasty things.
    >
    > instead of typing in the username they type something like:
    >
    > ' ; DROP DB
    >
    > I'm not sure what they can type or how as you need things like DB &
    > table names.
    >
    > My question is basically - how do you people stop people doing things
    > like this???
    >
    > I'm using W2k Pro IIS5, ASP 3.0, and SQL Server. I'm going to have
    > quite a lot of forms when the projects completed and would like to
    > solve this issue asap.
    >
    > thanks for any help.
    >
    > Al


    Bob Barrows Guest

  4. #3

    Default Re: deleting DB & tables via webforms

    Nicely done, except for this:

    Daniel Bush wrote:
    > On Sun, 27 Jul 2003 19:04:01 +0100, Harag <harag@softhome.net> wrote:
    >
    > It should be something like this
    > set cmd=server.createobject("adodb.command")
    > with cmd
    > .activeconnection=conn
    > .cmdtype=adCmdText
    > .commandtext="insert into tablea(a,b,c) values (?,?,?)"
    > end with
    > set rs=server.createobject("adodb.recordset")
    > set rs=cmd.execute(lngRecs, _
    >
    > array(request.form("varA"),request.form("varB"),re quest.form("varC"))
    >
    > (or alternatively, you can create and populate the parameters in the
    > with cmd block above and use the syntax
    >
    > rs.open cmd,,adOpenStatic,adLockOptimistic
    > )
    >
    Why in the world would you advocate using a recordset object to run an
    action query? A recordset is (should be) used for receiving results from a
    records-returning query or procedure. It is a waste of resources and time to
    create and open a recordset when you don't expect results from your query.
    Much better would be:
    cmd.execute lngRecs, _
    array(request.form("varA"),request.form("varB"),re quest.form("varC"), _
    adCmdText + adExecuteNoRecords

    or, if you manually create the parameters collection:
    cmd.execute lngRecs, , adCmdText + adExecuteNoRecords

    Bob Barrows




    The key is using the adExecuteNoRecords constant to tell the Command not to
    bother creating a recordset object


    Bob Barrows Guest

  5. #4

    Default Re: deleting DB & tables via webforms

    Please allow me to modify these rules - Bob caught me with an
    embarrasing error:
    >
    >Dan's Rules for Web Based ASP Database Programming
    >
    >1. Use Stored Procedures where possible. You can require this - go
    >ahead and do so if you can.
    >
    >2. Do NOT allow the use of the "sa" username to access the database
    >via your web site - create a web user account for each web site to
    >access their database(s). When creating the UserName, give only the
    >rights necessary (in SQL Server, datareader and if necessary,
    >datawriter) to the databases required. So, even if a spurious "db
    >drop" or other input is used, the UserId won't have permissions to do
    >it anyway.
    >
    >3. REQUIRE - that the programmers use a DSNless connection to the
    >database. I require that they put the ADO ConnectionString, UserId,
    >and Password into Application variables in the global.asa. That way
    >moving a web site to another box is easy and the administrators of the
    >box don't have to worry about managing DSN's (which is an outdated way
    >of connecting to databases anyway, if a programmer insists on this
    >method, you have probably got an ignorant, inexperienced or lazy one
    >anyway) (or all three).
    >
    >4. If the programmer needs to use Dynamic SQL instead of stored
    >procedures, make sure that they use the ? placeholder in their SQL
    >calls and use the ADO Command object ALWAYS when they use Dynamic SQL
    >(you avoid the user being able to put in additional SQL into the SQL
    >call). Require them to use Command Objects even for Recordset calls.
    >If you see a programmer using a recordset object to do an UPDATE or
    >INSERT statement, fire them and get someone who knows what they are
    >doing. If you see code like this, hurl the programmer immediately out
    >the nearest window:
    >
    >set rs=server.createobject("adodb.recordset")
    >rs.open "insert into tablea (a,b,c) values('" & request.form("varA") &
    >"', '" & request.form("varB") & "', '" & request.form("varC") & "')",
    >conn,1,1
    >
    >It should be something like this
    >set cmd=server.createobject("adodb.command")
    >with cmd
    > .activeconnection=conn
    > .cmdtype=adCmdText
    > .commandtext="insert into tablea(a,b,c) values (?,?,?)"
    >end with
    WRONG - this is what I should have written:
    cmd.execute lngRecs, _
    array(request.form("varA"),request.form("varB"),re quest.form("varC")

    If you need to execute SQL to retrieve information back from the SQL
    Server, again, use a command object but use a recordset to hold your
    output
    set cmd=server.createobject("adodb.command")
    set rs=server.createobject("adodb.recordset")
    with cmd
    .activeconnection=conn
    .cmdtype=adcmdtext
    .commandtext="select from tableA where a=? or b=? or c=?"
    end with
    set rs=cmd.execute(lngRecs, _
    array(request.form("varA"),request.form("varB"),re quest.form("varC"))
    >
    >(or alternatively, you can create and populate the parameters in the
    >with cmd block above and use the syntax
    >
    >rs.open cmd,,adOpenStatic,adLockOptimistic
    >)
    >
    Sorry for the confusion. Later in the post I was trying (badly as it
    turns out) to point out this exact point - DO NOT use a recordset
    object unless you have output comming back from the database.

    Thanks Bob for pointing out my error(s),

    Dan Bush
    [email]me@R3M0V3.danbush.com[/email]
    Daniel Bush Guest

  6. #5

    Default Re: deleting DB & tables via webforms

    On Mon, 28 Jul 2003 08:08:50 -0400, "Bob Barrows"
    <reb_01501@yahoo.com> wrote:
    >Nicely done, except for this:
    >
    >Daniel Bush wrote:
    >> On Sun, 27 Jul 2003 19:04:01 +0100, Harag <harag@softhome.net> wrote:
    >>
    >> It should be something like this
    >> set cmd=server.createobject("adodb.command")
    >> with cmd
    >> .activeconnection=conn
    >> .cmdtype=adCmdText
    >> .commandtext="insert into tablea(a,b,c) values (?,?,?)"
    >> end with
    >> set rs=server.createobject("adodb.recordset")
    >> set rs=cmd.execute(lngRecs, _
    >>
    >> array(request.form("varA"),request.form("varB"),re quest.form("varC"))
    >>
    >> (or alternatively, you can create and populate the parameters in the
    >> with cmd block above and use the syntax
    >>
    >> rs.open cmd,,adOpenStatic,adLockOptimistic
    >> )
    >>
    >Why in the world would you advocate using a recordset object to run an
    >action query? A recordset is (should be) used for receiving results from a
    >records-returning query or procedure. It is a waste of resources and time to
    >create and open a recordset when you don't expect results from your query.
    >Much better would be:
    >cmd.execute lngRecs, _
    >array(request.form("varA"),request.form("varB"),r equest.form("varC"), _
    >adCmdText + adExecuteNoRecords
    >
    >or, if you manually create the parameters collection:
    >cmd.execute lngRecs, , adCmdText + adExecuteNoRecords
    >
    >Bob Barrows
    >
    >
    >
    >
    >The key is using the adExecuteNoRecords constant to tell the Command not to
    >bother creating a recordset object
    >
    ARRGGGG!

    Thanks for pointing out my mistake - I am definately NOT advocating
    using a recordset object for an action query. I was trying to say the
    exact opposite (and I tried to say so again in the last paragraph),
    but instead of putting the SQL I meant to put in the command object, I
    put in the "insert" statement. The SQL statement should have been
    something like this:
    >> .commandtext="insert into tablea(a,b,c) values (?,?,?)"
    ..commandtext="select a,b,c from tableA where a=? or b=? or c=?"

    Anyway, I deserve this for being so sure of myself. One always gets
    humbled when you try to put out "Dan's Rules for ..." anything <red
    faced grin>.

    My point in the last couple of threads was to try and show people that
    this SQL Injection problem (and many others) can be eliminated just by
    using the COMMAND object with placeholders. When this is used, it is
    impossible for the input to be regarded as anything other than data -
    and cannot be mistaken for CommandText.

    I do agree that Stored Procedures are the best way to go, but
    sometimes due to lack of DBA resources or other reasons, we, as
    programmers, must use dynamic SQL - and if you do, you can avoid many
    of the pitfalls if you just use the command object for all dynamic
    SQL.

    Dan Bush
    [email]me@R3M0V3.danbush.com[/email]
    Daniel Bush Guest

  7. #6

    Default Re: deleting DB & tables via webforms

    Thanks for the help & tips guys.

    Al.

    On Sun, 27 Jul 2003 19:04:01 +0100, Harag <harag@softhome.net> wrote:
    >Hi all
    >
    >I heard that my DB tables can be truncated, deleted & dropped via uses
    >using my forms on my site
    >
    >when a form asks for something like "name & passoword" IE a login form
    >this is where users/hackers can do nasty things.
    >
    >instead of typing in the username they type something like:
    >
    >' ; DROP DB
    >
    >I'm not sure what they can type or how as you need things like DB &
    >table names.
    >
    >My question is basically - how do you people stop people doing things
    >like this???
    >
    >I'm using W2k Pro IIS5, ASP 3.0, and SQL Server. I'm going to have
    >quite a lot of forms when the projects completed and would like to
    >solve this issue asap.
    >
    >thanks for any help.
    >
    >Al
    Harag Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139