# 不安全的直接对象引用（IDOR）

在本节中，我们将讲解什么是不安全的直接对象引用（IDOR），并描述一些常见的漏洞。

## 什么是不安全的直接对象引用（IDOR）？

不安全的直接对象引用（IDOR）是一种访问控制类型的漏洞，当应用程序使用用户提供的输入直接访问对象时，就会出现这种漏洞。IDOR这个术语是由于其在OWASP 2007十大安全漏洞中的出现而广为人知。然而，它只是众多可能导致访问控制被绕过的实现错误之一。IDOR漏洞常常与水平权限提升相关，但也可能与垂直权限提升有关。

## IDOR示例

存在众多访问控制漏洞的例子，其中用户可控的参数值被用于直接访问资源或功能。

### 直接引用数据库对象的IDOR漏洞

考虑一个网站，它使用以下URL通过从后端数据库检索信息来访问客户账户页面：

```
https://insecure-website.com/customer_account?customer_number=132355
```

在这里，客户编号被直接用作后端数据库查询中的记录索引。如果没有其他控制措施，攻击者可以简单地修改`customer_number`值，绕过访问控制查看其他客户的记录。这是一个导致水平权限提升的IDOR漏洞的例子。

攻击者可以绕过访问控制，将用户改为具有额外权限的用户，从而实现水平和垂直权限升级。其他可能性包括利用密码泄露或在攻击者登陆到用户的账户页面后修改参数。

### 直接引用静态文件的IDOR漏洞

当敏感资源位于服务器端文件系统上的静态文件中时，往往会出现IDOR漏洞。例如，一个网站可能会使用递增的文件名将聊天消息记录保存到磁盘，并允许用户通过访问如下URL来检索这些记录：

```
https://insecure-website.com/static/12144.txt
```

在这种情况下，攻击者可以简单地修改文件名，以检索由另一个用户创建的记录，并可能获取用户凭证和其他敏感数据。

> **LAB**
>
> [不安全的直接对象引用](https://portswigger.net/web-security/access-control/lab-insecure-direct-object-references)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://web-sec.gitbook.io/wsa/server-side/access-control/idor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
