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

  • 相关阅读:
    php 字符串
    iOS copy&mutableCopy理解
    Swift学习(二)
    Swift 学习一函数&函数属性&懒加载
    LICEcap GIF 屏幕录制工具
    UIApplication介绍
    进度条渐变色
    -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    DedeCms 5.7友情链接模块注入漏洞
    phpcms v9会员中心文件上传漏洞
  • 原文地址:https://www.cnblogs.com/simengphp/p/7846604.html
Copyright © 2011-2022 走看看