Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default SQL Injection

    Hi,

    I have to check all textboxes in my web application for SQL injection.
    Is there any ready product that detect SQL inhection patterns?
    A regular expression also would be helpfull.

    Any help would be apprecited,
    Ali


    A.M Guest

  2. Similar Questions and Discussions

    1. Aspx's Html Injection
      Hi, I'm try to find an easy efficient way to generate my web pages dynamically from an xml/text file. What exactly I want? I want that...
    2. What is CF injection?
      Hello people We are doing a security revision of our application, with the help of some consultants. They alerted us to the risc of ColdFusion...
    3. SQL Injection Vulnerabilities
      In the May 29th, 2005 listserv message from cflib.org, they mention this function, sqlSafe(): http://www.cflib.org/udf.cfm?id=1219 The function...
    4. Has ColdFusion MX taken care of SQL injection ?
      Has ColdFusion MX taken care of SQL injection ? The reason is that when I tried to test my own application without using <cfqueryparam ...> it...
    5. how to protect web server against SQL Injection ?
      i didnt find any information where to start . please write something
  3. #2

    Default Re: SQL Injection

    It seems to me you would want to do two things here as there are two
    different problems:

    Check all of your SQL code to ensure that you are using parameterized
    queries
    Verify that your input contains only valid input based on what is being
    requested

    Parameterized queries in ADO.NET will prevent SQL injection attacks. If you
    are building queries by creating SQL strings on the fly, then you should
    concentrate on fixing that first. You can still use parameterized queries
    without stored procedures if you don't want to or can't use them.

    The next thing you want to do is ensure that your input conforms to what it
    should be. This will help prevent all sorts of other attacks besides SQL
    injection such as Cross Site Scripting.

    Validating input should be done based on what is allowed, not based on what
    is not allowed, so trying to look for signs of SQL injection in your inputs
    is the wrong way to go.

    Regular expressions are excellent tools for validating input, but they are
    "domain dependent", meaning that no one regular expression can validate any
    random text. It depends on what is required.

    [url]http://www.regexlib.com/[/url] is an excellent source of regular expressions,
    especially for .NET.

    The bottom line is that you need to carefully validate input AND make sure
    your database code is not suceptible to SQL injection. You shouldn't just
    do one or the other. Read "Writing Secure Code" and/or the "Code Secure"
    column on MSDN for more info.

    HTH,

    Joe K.

    "A.M" <IHateSpam@sapm123.com> wrote in message
    news:OfAcxND4DHA.1428@TK2MSFTNGP12.phx.gbl...
    > Hi,
    >
    > I have to check all textboxes in my web application for SQL injection.
    > Is there any ready product that detect SQL inhection patterns?
    > A regular expression also would be helpfull.
    >
    > Any help would be apprecited,
    > Ali
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default sql injection

    I am looking at writing a routine which will validate input to be used in database queries so as to protect against sql injection attacks. Obviosly I can look at removing items like single quotes however I have read that there are means of circumventing this such as by using hexadecimal or the char function to encode the query. Is there any function/technique I can use to process the query string first before I run the routines to remove single apostrophes etc. which will ensure that the validation will work ok.

    scottrm Guest

  5. #4

    Default Re: sql injection

    scottrm wrote:
    > I am looking at writing a routine which will validate input to be
    > used in database queries so as to protect against sql injection
    > attacks. Obviosly I can look at removing items like single quotes
    > however I have read that there are means of circumventing this such
    > as by using hexadecimal or the char function to encode the query. Is
    > there any function/technique I can use to process the query
    > first before I run the routines to remove single apostrophes etc.
    > which will ensure that the validation will work ok.
    You shouldn't be removing the apstrophes: you should be escaping them by
    replacing them with two apostrophes, using the Replace function.

    Better yet, you should be using stored procedures, or parameterize your
    dynamic sql if you must use it.

    Here are some links:
    see the SQL Injection FAQ at [url]www.sqlsecurity.com[/url]

    SQL Injection Attacks - Are You Safe? by Mitchell Harper - 6/17/2002
    [url]http://www.webmasterbase.com/article/794[/url]
    Interesting but mostly covers things that can happen with SQL Server but not
    with Access as the database.

    Data Sanitization - Reducing Security Holes in an ASP Web Site by Craig
    Atkins
    - 11/27/2002
    [url]http://www.4guysfromrolla.com/webtech/112702-1.shtml[/url]
    How do we Protect Against SQL Injection?
    What are Regular Expressions?

    There was a great white paper somebody posted a few weeks ago. I don't have
    time to find it right now, perhaps if you do a Google search ...

    Bob Barrows


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  6. #5

    Default Re: sql injection

    Hello,

    Thank you for using the community. Regarding the issue, I agree with Bob
    that we should replace apstrophes to protect SQL injection attacks, not hex
    encode. And I think the link he provide was very helpful on this issue, you
    may browse following link:

    [url]http://www.sitepoint.com/article/sql-injection-attacks-safe/5[/url]

    They are general ways we can use to protect the SQL injection attacks.

    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    [MSFT] Guest

  7. #6

    Default Re: sql injection

    Thanks for the response but maybe I have not made myself clear. My thinking is that it may be possible for an attacker to hex encode (or similar means) single apostrophes or other bad characters to avoid any validation routines such as the one described in the article and it is this I want to find a way to avoid.
    scottrm Guest

  8. #7

    Default Re: sql injection

    If an attack hex encode the bad characters in SQL query expression, sql
    server may not recognize the expression, and report syntax error. I can't
    figure out a sample with hex encode and possible injection attack. If you
    have such one on hand, please let me know. We may discuss them to see how
    to protect.

    Thanks,

    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    [MSFT] Guest

  9. #8

    Default Re: sql injection

    There are are couple of examples of how to avoid validatio
    from the papers [url]http://www.nextgenss.com/papers/advanced_sql_injection.pdf[/url] (Page 18 using char function) and

    [url]http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf[/url] (page 12 using the hex encoding method


    scottrm Guest

  10. #9

    Default Re: sql injection

    scottrm wrote:
    > There are are couple of examples of how to avoid validation
    > from the papers
    > [url]http://www.nextgenss.com/papers/advanced_sql_injection.pdf[/url] (Page 18
    > using char function) and
    >
    > [url]http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf[/url] (page
    > 12 using the hex encoding method)
    I see nothing in this article that invalidates the principle that passing
    parameters to a stored procedure using a Command object is safe (unless the
    procedure is executed with a dynamic sql statement, or unless the procedure
    builds its own dynamic sql statement). Sure, there's the statement that new
    attacks are " ... being discovered all the time." But that statement also
    applies to any defenses you can come up with for this hex attack you are
    worried about. In my mind, this is much more possible than circumventing the
    stored procedure parameter defense. ALL sql injection attacks depend on the
    use of dynamic sql. If you do not use dynamic sql you are safe. If a way is
    found to inject sql into a parameter value passed by a Parameter object,
    then we may as well shut everything down.

    I realize that you have a bunch of legacy code that would need to be
    rewritten. However, wouldn't much of that code need to be revised anyways to
    implement any defenses you come up with?

    BTW, you do not have to use an explicit Command object and its Parameters
    collection to be safe. You can also pass parameter values via the
    "procedure-as-connection-method" technique:

    'no resultset returned (INSERT, DELETE, UPDATE,etc.):
    conn.procedurename parmval1,...,parmvalN

    'resultset returned:
    set rs=createobject("adodb.recordset")
    conn.procedurename parmval1,...,parmvalN, rs

    This techniques causes ADO to create a command object behind the scenes and
    populate its Parameters collection. (Note: this technique is not usable in
    ADO.Net)

    This may reduce the pain you foresee in rewriting your legacy code.

    Bob Barrows


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  11. #10

    Default Re: sql injection

    Try this...

    [url]http://www.sitepoint.com/article/794[/url]

    In addition to the technique mentioned, I also test wether or not the
    value of a query parameter is all numeric if the query parameter in
    question requires a numeric value.

    scottrm wrote:
    > I am looking at writing a routine which will validate input to be used in database queries so as to protect against sql injection attacks. Obviosly I can look at removing items like single quotes however I have read that there are means of circumventing this such as by using hexadecimal or the char function to encode the query. Is there any function/technique I can use to process the query string first before I run the routines to remove single apostrophes etc. which will ensure that the validation will work ok.
    >
    David C. Holley Guest

  12. #11

    Default SQL Injection

    Hello, Does ColdFusion automatically invalidate any attempts to inject SQL statements (eg., 1=1) when doing a query, or is this something we need to code for?

    Steve
    mockworld Guest

  13. #12

    Default Re: SQL Injection


    I would recommend taking a look at the CFQUERYPARAM tag, used inside CFQUERY. This can be used to prevent injection and also do field data type checking.

    Bryan
    blewis Guest

  14. #13

    Default Re: SQL Injection

    ok, thanks Bryan.
    mockworld Guest

  15. #14

    Default SQL injection

    simple question. is it possible to do sql injections to CF pages? i tried it a little bit but seems not to work in coldfusion. just want to be sure since i'm not a pro in sql and sql commands
    Kiriran Guest

  16. #15

    Default Re: SQL injection

    On 2005-05-03 07:09:01 -0500, "Kiriran" <webforumsuser@macromedia.com> said:
    > simple question. is it possible to do sql injections to CF pages? i
    > tried it a little bit but seems not to work in coldfusion. just want to
    > be sure since i'm not a pro in sql and sql commands
    If you mean SQL injection as in the nasty kind where people try to tack
    on malicious SQL commands to what the application is supposed to be
    doing, then yes this is possible. The best way to protect yourself
    against this is to use cfqueryparam for all your variables that are
    going to interact with your database, as well as validate the heck out
    of everything both client and server-side.

    Matt
    --
    Matt Woodward
    [email]mpwoodward@gmail.com[/email]
    Team Macromedia - ColdFusion

    mpwoodward *TMM* Guest

  17. #16

    Default Re: SQL injection

    ah thanks :) well i encrypt it most times and yes use cfqueryparam so i think i'm on the save side. or at least i hope so ;)
    Kiriran Guest

  18. #17

    Default Re: SQL injection

    may i ask another question. what does <cfqueryparam> exactly? beside validating the datatyp, is it to make sure nothing executes (no sql commands?)
    Kiriran Guest

  19. #18

    Default Re: SQL injection

    Kiriran wrote:
    > may i ask another question. what does <cfqueryparam> exactly?
    It separates the query string from the variables and sends them
    to the database separately. The words to Google for are "bind
    variables" and "prepared statement".

    > beside validating the datatyp, is it to make sure nothing executes (no sql commands?)
    Correct.

    Jochem

    --
    Jochem van Dieten
    Team Macromedia Volunteer for ColdFusion, beer and fun.
    Jochem van Dieten - TMM Guest

  20. #19

    Default Re: SQL injection

    Can someone give me an example of how sql injection is done in CFMX?

    I read that single quotes are automatically escaped/doubled.

    let's say that the code is
    select * from mytable where firstName = '#form.firstName#'

    I tried to enter
    aaa' ; drop table test; select 'blah
    which should end up being
    select * from mytable where firstName = 'aaa' ; drop table test; select
    'blah'
    Looks like perfect syntax.

    but it automatically gets turned into:
    select * from mytable where firstName = 'aaa'' ; drop table test; select
    ''blah'

    What gives? How does a hacker get around that?



    urfriendx Guest

  21. #20

    Default Re: SQL injection

    If passed variables of varchar type are not protected by cfqueryparam a hacker
    can use for example UNION statement adding it as a part of variable that could
    be interpreted as valid part of a query and select data from any uprotected by
    granted permissions tables.

    CF_Oracle 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