1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

SQL injection attacks

Discussion in 'Databases' started by Triexa, Dec 4, 2006.

  1. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #21
    I'm only saying that CAPTCHA's in itself have nothing to do with SQL Injections. And they can't prevent GET manipulation anyway. So that's why I dismissed the idea. Not just "all other people's ideas".

    So in reply to Dan Thorpe, no it's not just to do with forms albeit a major part of it indeed because of bad tutorials out there.

    Go to any website where you find parameters in the URL like id=35 or sort=a and stick an apostrophe in there. Bad sites will instantly choke and throw up errors.
     
    T0PS3O, Dec 7, 2006 IP
  2. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #22
    oh mine doesnt do that, if the page doesnt exist special page is shown and all characters work in the url
     
    Silver89, Dec 7, 2006 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #23
    Sounds like you have it all covered.

    BTW Example, note the ':

    http://www.dripirrigation.com/index.php?cPath=36&page=1&sort='3a

    It's not a full blown injection risk but it illustrates the point.
     
    T0PS3O, Dec 7, 2006 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #24
    Your site can be perfectly safe with forms, you just have to spend a little longer with the coding to make it so, slapping code you find in tutorials and php.net on your site just won't do, you gotta know what you're doing....
     
    krakjoe, Dec 7, 2006 IP
  5. Futures_Equity

    Futures_Equity Well-Known Member

    Messages:
    454
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #25
    haha what if someone put a typo in that box tops30 was talking about, an honest mistake but they'd get screwed
     
    Futures_Equity, Dec 7, 2006 IP
  6. danielbruzual

    danielbruzual Active Member

    Messages:
    906
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    70
    #26
    You have to remove any special characters and validate user-submited information, always.

    You do not need to be a hacker to perform a SQL injection, you only need to understand SQL sintax. I have found some BIG sites with validation issues that I have been able to gain access to (with my scarce hacking knowledge).

    Here are some guides you might find useful to test your site for validation flaws:
    http://www.hackthissite.org/articles/read/535
    http://www.hackthissite.org/articles/read/336
     
    danielbruzual, Dec 7, 2006 IP
  7. Pierre Monteux

    Pierre Monteux Peon

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #27
    always use str_replace("'", "''", $variable_name) when passing user suplied data to sql. This replaces ' wiht '' the sql escape code for '. This prevents an injection attack of the user modifying the sql query because he cannot break out using a '.
     
    Pierre Monteux, Dec 7, 2006 IP
  8. MrMean

    MrMean Guest

    Messages:
    98
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #28
    Good suggestion - I would think its also worth trying out this kinda thing:
    http://bcable.net/project.php?sqlier

    Hope this helps ;)
     
    MrMean, Dec 8, 2006 IP
  9. Nick_Mayhem

    Nick_Mayhem Notable Member

    Messages:
    3,486
    Likes Received:
    338
    Best Answers:
    0
    Trophy Points:
    290
    #29
    I don't directly send the input to be executed. Trim it.
     
    Nick_Mayhem, Dec 8, 2006 IP
    Mong likes this.
  10. gree124

    gree124 Well-Known Member

    Messages:
    720
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #30
    gree124, Sep 7, 2007 IP
  11. tarponkeith

    tarponkeith Well-Known Member

    Messages:
    4,758
    Likes Received:
    279
    Best Answers:
    0
    Trophy Points:
    180
    #31
    I use ASP...

    Use things like:
    
    dim tmpInt
    tmpInt = instr(1, strUserInput, "<")
    if tmpInt <> 0 then response.write("There is an HTML tag!")
    
    Code (markup):
    or
    
    strUserInput = replace(strUserInput, "<", "(") ' Now their < has turned into a (
    strUserInput = replace(strUserInput, """", "") ' Now we got rid of any quotes
    
    Code (markup):
     
    tarponkeith, Sep 7, 2007 IP
  12. gree124

    gree124 Well-Known Member

    Messages:
    720
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #32
    i am using VBulletin
     
    gree124, Sep 7, 2007 IP
  13. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #33
    When keeping the place locked down isn't enough...

    There will come a day when every security specialist has their own botnet, just in case the boogie man comes. Isn't that like the right to bear arms?
     
    ErectADirectory, Sep 12, 2007 IP
  14. Trusttec

    Trusttec Peon

    Messages:
    147
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #34
    did you update your vbuliten to the lastest version?
     
    Trusttec, Sep 12, 2007 IP
  15. mustii

    mustii Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #35
    Yes !

    did you update your vbuliten to the lastest version?
     
    mustii, Sep 12, 2007 IP
  16. gree124

    gree124 Well-Known Member

    Messages:
    720
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #36
    i did with 3.6.8 but they hacked again but now my 1 good friend upload my backup old so now again i have 3.6.7 and i don;t thing VB latest is more secure becouse there is alots of website who is still using Old vb version their site not hack now however my site is back
     
    gree124, Sep 12, 2007 IP
  17. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #37
    we should make a list of the top 10 tips here
     
    mnymkr, Sep 14, 2007 IP
  18. scriptman

    scriptman Peon

    Messages:
    175
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #38
    I just wrote a simple in / out preparation function for use in PHP:

    function prepare_input($var)
    {
    $var = (get_magic_quotes_gpc())? stripslashes($var) : $var;
    return mysql_real_escape_string(htmlspecialchars(trim($var)));
    }
    
    function prepare_output($var)
    {
    return stripslashes($var);
    }
    Code (markup):
    So when you're taking user input, first run it through prepare_input. If you're going to display anything based on user input, run it through prepare_output first. I'm using it in something I'm developing and so far it seems effective. It defeats SQL injection and cross-site scripting assuming you remember to validate ALL input ;) You cannot trust a single thing - HTTP_HOST, cookies, useragent, anything.

    (Edit: Added in that line to strip slashes if magic quotes is on, for those who have it enabled in php.ini)
     
    scriptman, Sep 14, 2007 IP
  19. guruhowto

    guruhowto Guest

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #39
    Use mysql_real_escape_string if you have encoded strings but if you have just simple english alphabet strings use only mysql_escape_string

    The difference is the active connection being passed or used in mysql_real_escape_string while mysql_escape_string doesn't need any connection.
     
    guruhowto, Sep 16, 2007 IP
  20. Aron Schatz

    Aron Schatz Peon

    Messages:
    201
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #40
    Type cast things you can like numbers and such from forms and ALWAYS escape input elements.
     
    Aron Schatz, Sep 17, 2007 IP