> For the complete documentation index, see [llms.txt](https://ninjia.gitbook.io/secskill/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ninjia.gitbook.io/secskill/web/quan.md).

# 1.31 越权漏洞

## 简介

越权漏洞是Web应用程序中一种常见的安全漏洞。它的威胁在于一个账户即可控制全站用户数据，这些数据仅限于存在漏洞功能对应的数据。

## 原理

越权漏洞的成因主要是因为开发人员在对数据进行增、删、改、查询时对客户端请求的数据过分相信，在验证用户权限时存在缺陷，遗漏或未正确进行权限判定，从而导致了越权漏洞的出现

假设存在一个购物类网站，其中有修改收货地址的操作，正确逻辑为 A 用户仅能修改 A 用户自己的地址， B 用户仅能修改 B 用户自己的地址

此时修改地址的sql语句如

update order set address='xxx' where id = 1 这里的 id 为 order 表中的主键，id 为 1 对应 A 用户地址， id 为 2 对应 B 用户地址。 更新 url 为

/?action=update\&address=xxx\&id=1 此时用户将 url 中的 1 修改为 2，而程序却未对做出更新请求的用户做权限判定，那么 B 用户的收货地址将会被修改

## 平行越权

### 原理

基于数据的控制访问，平行越权就是同等角色下的用户，不但能够访问自己私有的数据，还能访问其他人私有的数据。

### 漏洞复现

随便注册两个账号 13888888888 和 12888888888，登入并填写收货地址

在前台登录了 13888888888 账号，此时查看自己账号下的收货地址仅有一条记录

![](http://ww1.sinaimg.cn/large/007F8GgBly1g2xnfq7biuj30k107x3zt.jpg)

点击记录查看详细信息时发现请求了一个地址为

> <http://127.0.0.1:8333/index.php?mod=mobile&op=detail&name=shopwap&do=address&id=1>

返回了详细地址信息

```javascript
{
    "id": "1",
    "realname": "11",
    "mobile": "13888888888",
    "province": "河北省",
    "area": "复兴区",
    "city": "邯郸市",
    "address": "1111"
}
```

而将id修改为2时，返回了 12888888888 用户的收货地址信息

```javascript
{
    "id": "2",
    "realname": "tttttt",
    "mobile": "12888888888",
    "province": "北京市",
    "city": "北京辖区",
    "area": "东城区",
    "address": "1"
}
```

造成了平行越权

实验环境为百家CMS

## 垂直越权

### 原理

基于角色的控制访问，垂直越权即低权限的角色通过一些途径，获得高权限

最常见的一种垂直越权便是后台信息的越权查看

使用\[IP:Port]访问靶机，url加上/admin访问后台，使用admin/admin弱口令登录后台

网站后台一般会做成在 index.php 中包含其余文件来显示内容。若被包含的文件未做权限验证，可导致任意用户都可通过直接访问该页面查看信息

### 漏洞复现

登录后台成功后，可看到服务器信息

![](http://ww1.sinaimg.cn/large/007F8GgBly1g2xnsb78pfj30ue0cu0t2.jpg)

此时服务器信息是包含了后台的 info.php 文件来显示的，在未登录的情况下直接访问该文件，造成越权，若该页面含有数据操作功能切未做权限验证将造成更大危害

![](http://ww1.sinaimg.cn/large/007F8GgBly1g2xntxhtkij30jk08pdg2.jpg)

## 交叉越权

### 原理

垂直越权和水平越权的交集。

如注册用户时，后台可能未验证传入得参数，将其全都代入sql语句中。这时如果用户传入类似 type=admin 的参数，可直接注册成为管理员，完成权限的提升。

### 漏洞复现

正常注册一个账号密码为 123/123 的账户并登录

![](http://ww1.sinaimg.cn/large/007F8GgBly1g2xo455v3ij30ip09et9f.jpg)

返回注册页面，注册一个 user/123 的用户，在提交时，多添加一个参数为 type=admin

登录后发现该用户为管理员

![](http://ww1.sinaimg.cn/large/007F8GgBly1g2xo4j4q4gj30ig092q3q.jpg)

## 防御

对于涉及用户唯一信息的请求，每次都要验证和检查所有权

敏感信息页面加随机数的参数，防止浏览器缓存内容。

将权限与功能对应，使用最小权限原则，普通用户授予能正常使用基本功能的最小权限

不使用暴露给用户的参数来做权限与身份得区分标识


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://ninjia.gitbook.io/secskill/web/quan.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.
