duanbo7517 2017-01-16 09:46
浏览 17

这个mysql查询是如何工作的?

My php code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Less-1 SqL Injection master Course by Hitesh Choudhary</title>
        <link rel="stylesheet" href="../index.html_files/freemind2html.css" type="text/css"/>
    </head>
    <body>
        <div style=" margin-top:70px;color:#FFF; font-size:23px; text-align:center">
            <h1><span class="style1">Welcome </span><font color="#FF0000">to SQL injection Master Course </font></h1>
            <h1><span class="style2">Lesson-1</span></h1>
            <h1><span class="style4">Hint : Error based string</span> <br>
                <font size="3" color="#666666">
                <?php
                    //including the Mysql connect parameters.
                    include("../sql-connections/sql-connect.php");

                    // take the variables
                    if(isset($_GET['id']))
                    {
                        $id=$_GET['id'];
                        //logging the connection parameters to a file for analysis.
                        //$fp=fopen('result.txt','a');
                        //fwrite($fp,'ID:'.$id."
");
                        //fclose($fp);

                        // connectivity

                        $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
                        $result=mysql_query($sql);
                        $row = mysql_fetch_array($result);

                            if($row)
                            {
                                echo '<font color= "#0000ff">';
                                echo 'Your Login name:'. $row['username'];
                                echo "<br>";
                                echo 'Your Password:' .$row['password'];
                                echo "</font>";
                            }
                            else
                            {
                                echo '<font color= "#900">';
                                print_r(mysql_error());
                                echo "</font>";
                            }
                        }
                        else { echo "Please input the ID as parameter with numeric value";}

                ?>
                </font>
            </h1>
        </div>
        <img border="0" src="img1.gif" alt="funny" width="200" height="200">
        <div class="botton_fix">For more please visit : <a href="http://www.hiteshchoudhary.com" target="_blank">www.hiteshchoudhary.com</a></div>
        </br></br></br>
        <center>
        </center>
    </body>
</html>

I am trying to SQL inject this page using the following query

localhost/example/Less-1/index.php?id=1 order by 100

result is username:some and password:some

localhost/example/Less-1/index.php?id=1

result is username:some and password:some

I also checked with $id=2,3,... so on, and it works normally why does it work like that? I should get an error right?

  • 写回答

2条回答 默认 最新

  • donglie1898 2017-01-16 10:59
    关注

    I don't know, How you will be connect your db and use connection.. so i have wrote db connection in code .. Please try with it and let me know, if you get any issue. :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Less-1 SqL Injection master Course by Hitesh Choudhary</title>
            <link rel="stylesheet" href="../index.html_files/freemind2html.css" type="text/css"/>
        </head>
        <body>
            <div style=" margin-top:70px;color:#FFF; font-size:23px; text-align:center">
                <h1><span class="style1">Welcome </span><font color="#FF0000">to SQL injection Master Course </font></h1>
                <h1><span class="style2">Lesson-1</span></h1>
                <h1><span class="style4">Hint : Error based string</span> <br>
                    <font size="3" color="#666666">
    
    
                    <?php
    
    
                     //   include("../sql-connections/sql-connect.php");
    
    
                    if (!$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
                            echo 'Could not connect to mysql';
                            exit;
                        }
    
                        if (!mysql_select_db('mysql_dbname', $link)) {
                            echo 'Could not select database';
                            exit;
                        }
    
                        $sql = "SELECT * FROM users WHERE id='".$id."' LIMIT 0,1";
                        $result = mysql_query($sql, $link);
    
                        if (!$result) {
                            echo "DB Error, could not query the database
    ";
                            echo 'MySQL Error: ' . mysql_error();
                            exit;
                        }
    
                        while ($row = mysql_fetch_assoc($result)) {
                            echo '<font color= "#0000ff">';
                                    echo 'Your Login name:'. $row['username'];
                                    echo "<br>";
                                    echo 'Your Password:' .$row['password'];
                                    echo "</font>"
                        }
    
                        mysql_free_result($result);
    
    
    
    
                    ?>
                    </font>
                </h1>
            </div>
            <img border="0" src="img1.gif" alt="funny" width="200" height="200">
            <div class="botton_fix">For more please visit : <a href="http://www.hiteshchoudhary.com" target="_blank">www.hiteshchoudhary.com</a></div>
            </br></br></br>
            <center>
            </center>
        </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀