# Captive Portal简介

Captive portal（捕获物门户网站）是一个面向网络新连接用户在授权访问网络资源前展示的页面。Captive portal通常用于展示一个登陆页面，要求授权，付费或者接受终端用户授权书确认。通常在移动网络、酒店、机场服务，也用于企业提供客户临时使用网络。

Captive portal主要用于开放无线网络，用户连接到无线网络时，通常会被重定向所有WEB流量到一个WEB服务器，也就是captive portal。

## 实现

### HTTP重定向

现代的移动设备连接到网络时，会发送一个HTTP请求并期望获得一个`204`的HTTP状态码。如果设备收到一个HTTP 204状态码，设备就会假设自己具有无限制的internet访问。Captive portal则提供一个HTTP 302（重定向）返回码，这样就会重定向到captive portal。

### ICMP重定向

在IP层（layer 3 level）使用ICMP redirect重定向客户端流量。

### DNS重定向

当客户端请求web网站，浏览器会发出DNS请求。在captive portal，防火墙会确保只有网络DHCP提供的DNS服务器给非授权的客户端（或者，防火墙会把所有非授权客户端的DNS请求转发给指定DNS服务器）。此时，这个指定DNS服务器会把解析到IP地址指向captive portal页面。

为了使得captive portal的DNS能够实现重定向，会使用一种称为[DNS劫持](https://en.wikipedia.org/wiki/DNS_hijacking)（DNS hijacking）的技术，类似[中间人攻击](https://en.wikipedia.org/wiki/Man-in-the-middle_attack)。为了限制DNS中毒的影响，通常会将TTL设置成`0`。

## captive portal的环境

Captive portals有一些已知的不完善的防火墙规则集。一些部署环境，规则集会路由DNS请求从客户端到internet，或者提供DNS服务器以完全提交的DNS请求。这样就会允许客户端绕过captive portal，并通过在DNS数据包的隧道流量访问开放的Internet。（安全漏洞）

一些captive portal会配置成允许特定设备的用户代理检测到captive portal并实现自动认证。例如Apple的Captive Portal Assistant可以透明绕过captive portal内容。

captive portal使用MAC地址来跟踪连接的设备，优势能够避免连接路由器以允许设置路由器MAC地址。路由器firmware通常称其为MAC克隆。一旦主机或移动设备允许连接网络（通过captive portal授权），则这个MAC地址就会进入路由器，这也就允许设备能够访问internet。

## 缺陷

通过数据包嗅探能否发现连接到网路的允许访问internet的IP和MAC地址，这样就非常容易使用MAC地址欺骗来实现未经授权的访问。

> [渗透测试思路 | Linux下自动化搭建FakeAP，劫持用户在Portal认证下的所有流量](https://www.freebuf.com/articles/wireless/151734.html) 这篇文档的思路可以借鉴

此外，HTTPS连接是不能重定向的，因为浏览器只会访问安全web网站，而captive protal则看不到这个请求。

## 参考

* [第11期——WLAN接入认证-Portal](https://blog.csdn.net/czq1024/article/details/80623257)有一篇详细介绍Portal认证的流程介绍，非常详细


---

# 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://huataihuang.gitbook.io/cloud-atlas-draft/security/wifi/captive_portal/introduce_captive_portal.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.
