Results 1 to 13 of 13

Thread: Help with Anti-SQL

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    208

    Help with Anti-SQL

    well as you can see im trying to test my anti-sql injector

    Code:
    <FORM METHOD=POST ACTION="Inject.php">
    <CENTER><INPUT NAME="IJz" TYPE="text"></CENTER>
    <CENTER><INPUT VALUE="Anti-Inject" TYPE="submit"></CENTER>
    </FORM>
    
    <?php
    if ($_GET['$submit']){
    $Test = AntiInject($_POST['IJz']);
    echo '$test';
    }
    
    //Anti-Injection
    function AntiInject($sql){
    $sql = str_replace("SELECT", "", $sql);
    return $sql;
    }
    ?>
    everything seems to go wrong... I type SQL Injection text into the box, press Submit and i want it to echo the results after going through AntiInject(); im just using the word SELECT to see if it works.

    any help?

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Help with Anti-SQL

    well what echos out? Try putting some other text in it.
    My usual boring signature: Something

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    208

    Re: Help with Anti-SQL

    what do you mean? can you show me on my code? I only started PHP a few days ago... im more of a... C++ guy..

    i dont even think it runs this...

    Code:
    if ($_GET['$submit']){
    $Test = AntiInject($_POST['IJz']);
    echo '$test';
    }
    what could i put as the if?

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Help with Anti-SQL

    here, i tested this on my server. There was a couple of problems:
    • You used $_GET instead of $_POST
    • You had a variable in single quotes
    • variable capitalization problem (Test vs. test)
    • You had $_GET[$submit']


    PHP Code:
    <FORM METHOD=POST ACTION="test1.php">
    <CENTER><INPUT NAME="IJz" TYPE="text"></CENTER>
    <CENTER><INPUT VALUE="Anti-Inject" name="submit" TYPE="submit"></CENTER>
    </FORM>

    <?php
    if ($_POST['submit']){
        
    $test AntiInject($_POST['IJz']);
        echo 
    $test;
    }

    //Anti-Injection
    function AntiInject($sql){
        
    $sql str_ireplace("select"""$sql);
        return 
    $sql;
    }
    ?>
    My usual boring signature: Something

  5. #5
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: Help with Anti-SQL

    Quote Originally Posted by Gunner54
    what do you mean? can you show me on my code? I only started PHP a few days ago... im more of a... C++ guy..

    i dont even think it runs this...

    Code:
    if ($_GET['$submit']){
    $Test = AntiInject($_POST['IJz']);
    echo '$test';
    }
    what could i put as the if?
    Code:
    echo '$test';
    is similar to:

    Code:
    string strVar = "test";
    
    cout << "strVar" << endl; //will print "strVar"
    cout << strVar << endl; //will print "test"

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help with Anti-SQL

    This is a needlessly complex way of trying to prevent SQL injection. You should ideally use a data access library, such as PDO or mysqli, which supports parameterised statements. These avoid any chance of injection when used properly.

  7. #7
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Help with Anti-SQL

    nice touch at the end "when used properly"

    I want to continue with my site properly, can you show my mysqli or pdo?
    My usual boring signature: Something

  8. #8
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Help with Anti-SQL

    I looked on php.net, and mysqli looks exactly like mysql syntax, just with the "i" appended to the end. if most of all the syntax is the same, then i can just go through and add the i to the end.

    is this true pena?
    My usual boring signature: Something

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help with Anti-SQL

    No, you should use prepared statements.

    http://php.net/manual/en/function.mysqli-stmt-prepare

    Also, the object-oriented syntax is preferable, although not necessary.

  10. #10
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Help with Anti-SQL

    that looks alot harder then it should be. Do you personally use that? I am not sure if i want to convert every thing to prepared statements
    My usual boring signature: Something

  11. #11
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Help with Anti-SQL

    Don't forget to
    PHP Code:
    mysql_real_escape_string() 
    too, just an extra security layer.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help with Anti-SQL

    But don't do that if using parameters.

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Help with Anti-SQL

    Quote Originally Posted by dclamp
    that looks alot harder then it should be. Do you personally use that? I am not sure if i want to convert every thing to prepared statements
    It's actually a lot easier.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width