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语句

  • 相关阅读:
    iOS开发——iOS10升级极光推送SDK、友盟分享SDK
    iOS动画——弹窗动画(pop动画)
    iOS动画——文字晃动
    iOS安全——代码混淆&反编译
    iOS学习——iOS视频和推荐网站
    iOS开发——消息推送跳转
    iOS开发——时间格式类
    iOS开发——锁屏监听
    iOS开发——毛玻璃透明
    iMAC——全新重装Mac系统
  • 原文地址:https://www.cnblogs.com/simengphp/p/7846604.html
Copyright © 2011-2022 走看看