zoukankan      html  css  js  c++  java
  • 常见sql注入原理详解!

    1、首先我们创建一个mysqli的链接

    /**数据库配置*/

    $config = ['hostname'=>"localhost", 'port'=>"3306", 'username'=>"root",'password'=>'','db'=>'sql'];

    /**接收参数*/

    $id = $_GET['id']?$_GET['id']:"";

    if(empty($id)){

    echo "article is not def"

    }

    /**链接数据库*/

    $mysqli = new mysqli($config['hostname'],$config['username'],$config['password'],$config['db']);

    /**设置编码*/

    $mysqli->set_charset("utf8");

    url数字注入结果测试

    我们访问url:http://localhost/mysql/index.php?id=1

    结果展示:

    array (size=2)  'article_id' => string '1' (length=1)  'title' => string '思梦php编写:PHP操作Redis详解案例' (length=44)

    (1)/当我们在在url上稍作修改时:

    http://localhost/mysql/index.php?id=1‘   //加一个单引号

    这样你的sql语句就会报错

    (2)我们再次修改url的时候

    http://localhost/mysql/index.php?id=-1 or 1=1  //后面参数修改成这样

    结果展示了所有的文章列表

    D:wampwwwmysqlindex.php:11:array (size=2)  'article_id' => string '1' (length=1)  'title' =>string '思梦php编写:PHP操作Redis详解案例' (length=44)

    D:wampwwwmysqlindex.php:11:array (size=2)  'article_id' => string '2' (length=1)  'title' =>string 'Mysql存储过程从0开始(上)' (length=36)

    D:wampwwwmysqlindex.php:11:array (size=2)  'article_id' => string '3' (length=1)  'title' =>string '思梦php编写:PHP排序的几种方法' (length=42).............

    2、表单注入,主要利用sql语句的注释

    $username = $_POST['username']?$_POST['username']:"";

    $password = $_POST['password']?$_POST['password']:"";

    $sql = "select * from tb_member where account='$username'AND password='$pass'";

    $res = $mysqli->query($sql);

    $row = $res->fetch_assoc();

    if($row){

    echo "登录成功!";

    }else{

    echo "账号密码错误!";

    }

    正常输入

    打印:登录成功!

    我们简单修改一下

    打印:登录成功!

    原理:首先使用单引号结束sql语句,然后加#注释后面的sql语句

    同理另一种方式为

    打印:登录成功!

    原理:首先使用单引号结束sql语句,然后加(-- )注释后面的sql语句

  • 相关阅读:
    Sql Server数据库汉字按字母、笔划、拼音首字母、排序
    产生一个int数组,长度为100,并向其中随机插入1100,并且不能重复
    使用DropDownExtender
    一些关于中文乱码问题的一些解决方案和经验和大家分享!
    (译)Silverlight教程第一部分: 使用Silverlight 2 和 VS 2008创建“Hello World”程序
    使用CalendarExtender
    .NET实现中英文验证码
    使用Accordion
    使用AlwaysVisibleControlExtender
    Javascript经典窍门
  • 原文地址:https://www.cnblogs.com/simengphp/p/7846604.html
Copyright © 2011-2022 走看看