FlareSolverr/FlareSolverr:绕过 Cloudflare 保护的代理服务器 --- FlareSolverr/FlareSolverr: Proxy server to bypass Cloudflare protection
2025-2-1 11:53:7 Author: github.com(查看原文) 阅读量:6 收藏

Latest release Docker Pulls GitHub issues GitHub pull requests Donate PayPal Donate Bitcoin Donate Ethereum

FlareSolverr is a proxy server to bypass Cloudflare and DDoS-GUARD protection.
FlareSolverr 是一个代理服务器,用于绕过 Cloudflare 和 DDoS-GUARD 保护。

How it works  运作方式

FlareSolverr starts a proxy server, and it waits for user requests in an idle state using few resources. When some request arrives, it uses Selenium with the undetected-chromedriver to create a web browser (Chrome). It opens the URL with user parameters and waits until the Cloudflare challenge is solved (or timeout). The HTML code and the cookies are sent back to the user, and those cookies can be used to bypass Cloudflare using other HTTP clients.
FlareSolverr 启动代理服务器,并使用少量资源等待处于空闲状态的用户请求。当某个请求到达时,它使用 Selenium未检测到的 chromedriver 以创建 Web 浏览器 (Chrome)。它打开包含用户参数的 URL,并等待 Cloudflare 质询 已解决(或超时)。HTML 代码和 Cookie 将发送回用户,这些 Cookie 可用于 使用其他 HTTP 客户端绕过 Cloudflare。

NOTE: Web browsers consume a lot of memory. If you are running FlareSolverr on a machine with few RAM, do not make many requests at once. With each request a new browser is launched.
注意:Web 浏览器会消耗大量内存。如果您在 RAM 较少的计算机上运行 FlareSolverr,请不要一次发出多个请求。每次请求时,都会启动一个新的浏览器。

It is also possible to use a permanent session. However, if you use sessions, you should make sure to close them as soon as you are done using them.
也可以使用永久会话。但是,如果您使用会话,则应确保在使用完会话后立即关闭它们。

Installation  安装

Docker

It is recommended to install using a Docker container because the project depends on an external browser that is already included within the image.
建议使用 Docker 容器进行安装,因为该项目依赖于映像中已包含的外部浏览器。

Docker images are available in:
Docker 镜像可用于:

Supported architectures are:
支持的架构包括:

Architecture  建筑 Tag  标记
x86 linux/386  Linux的/386
x86-64  x86-64 元 linux/amd64  Linux/AMD64作系统
ARM32 linux/arm/v7  Linux/ARM/v7 版本
ARM64 linux/arm64  Linux/ARM64 的

We provide a docker-compose.yml configuration file. Clone this repository and execute docker-compose up -d (Compose V1) or docker compose up -d (Compose V2) to start the container.
我们提供了一个 docker-compose.yml 配置文件。克隆此存储库并执行 docker-compose up -d(Compose V1)docker compose up -d(Compose V2) 来启动容器。

If you prefer the docker cli execute the following command.
如果您更喜欢 docker cli,请执行以下命令。

docker run -d \
  --name=flaresolverr \
  -p 8191:8191 \
  -e LOG_LEVEL=info \
  --restart unless-stopped \
  ghcr.io/flaresolverr/flaresolverr:latest

If your host OS is Debian, make sure libseccomp2 version is 2.5.x. You can check the version with sudo apt-cache policy libseccomp2 and update the package with sudo apt install libseccomp2=2.5.1-1~bpo10+1 or sudo apt install libseccomp2=2.5.1-1+deb11u1. Remember to restart the Docker daemon and the container after the update.
如果您的主机作系统是 Debian,请确保 libseccomp2 版本为 2.5.x。您可以使用 sudo apt-cache policy libseccomp2 并使用 sudo apt install libseccomp2=2.5.1-1~bpo10+1sudo apt install libseccomp2=2.5.1-1+deb11u1 更新包。请记住在更新后重新启动 Docker 守护程序和容器。

Precompiled binaries

Warning Precompiled binaries are only available for x64 architecture. For other architectures see Docker images.
警告 预编译的二进制文件仅适用于 x64 体系结构。有关其他体系结构,请参阅 Docker 映像。

This is the recommended way for Windows users.
这是 Windows 用户的推荐方法。

  • Download the FlareSolverr executable from the release's page. It is available for Windows x64 and Linux x64.
    从版本页面下载 FlareSolverr 可执行文件。它适用于 Windows x64 和 Linux x64。
  • Execute FlareSolverr binary. In the environment variables section you can find how to change the configuration.
    执行 FlareSolverr 二进制文件。在 environment variables 部分中,您可以找到如何更改配置。

From source code

Warning Installing from source code only works for x64 architecture. For other architectures see Docker images.
警告 从源代码安装仅适用于 x64 体系结构。有关其他体系结构,请参阅 Docker 映像。

  • Install Python 3.11.
    安装 Python 3.11
  • Install Chrome (all OS) or Chromium (just Linux, it doesn't work in Windows) web browser.
    安装 Chrome(所有作系统)或 Chromium(仅限 Linux,在 Windows 中不起作用)网络浏览器。
  • (Only in Linux) Install Xvfb package.
    (仅在 Linux 中)安装 Xvfb 软件包。
  • (Only in macOS) Install XQuartz package.
    (仅在 macOS 中)安装 XQuartz 软件包。
  • Clone this repository and open a shell in that path.
    克隆此存储库并在该路径中打开一个 shell。
  • Run pip install -r requirements.txt command to install FlareSolverr dependencies.
    运行 pip install -r requirements.txt 命令以安装 FlareSolverr 依赖项。
  • Run python src/flaresolverr.py command to start FlareSolverr.
    运行 python src/flaresolverr.py 命令以启动 FlareSolverr。

From source code (FreeBSD/TrueNAS CORE)

  • Run pkg install chromium python311 py311-pip xorg-vfbserver command to install the required dependencies.
    执行 pkg install chromium python311 py311-pip xorg-vfbserver 命令以安装所需的依赖项。
  • Clone this repository and open a shell in that path.
    克隆此存储库并在该路径中打开一个 shell。
  • Run python3.11 -m pip install -r requirements.txt command to install FlareSolverr dependencies.
    运行 python3.11 -m pip install -r requirements.txt 命令以安装 FlareSolverr 依赖项。
  • Run python3.11 src/flaresolverr.py command to start FlareSolverr.
    运行 python3.11 src/flaresolverr.py 命令以启动 FlareSolverr。

Systemd service

We provide an example Systemd unit file flaresolverr.service as reference. You have to modify the file to suit your needs: paths, user and environment variables.
我们提供了一个示例 Systemd 单元文件 flaresolverr.service 作为参考。您必须修改文件以满足您的需要:路径、用户和环境变量。

Usage  用法

Example Bash request:  Bash 请求示例:

curl -L -X POST 'http://localhost:8191/v1' \
-H 'Content-Type: application/json' \
--data-raw '{
  "cmd": "request.get",
  "url": "http://www.google.com/",
  "maxTimeout": 60000
}'

Example Python request:  Python 请求示例:

import requests

url = "http://localhost:8191/v1"
headers = {"Content-Type": "application/json"}
data = {
    "cmd": "request.get",
    "url": "http://www.google.com/",
    "maxTimeout": 60000
}
response = requests.post(url, headers=headers, json=data)
print(response.text)

Example PowerShell request:
PowerShell 请求示例:

$body = @{
    cmd = "request.get"
    url = "http://www.google.com/"
    maxTimeout = 60000
} | ConvertTo-Json

irm -UseBasicParsing 'http://localhost:8191/v1' -Headers @{"Content-Type"="application/json"} -Method Post -Body $body

Commands

+ sessions.create
+ 会话.create

This will launch a new browser instance which will retain cookies until you destroy it with sessions.destroy. This comes in handy, so you don't have to keep solving challenges over and over and you won't need to keep sending cookies for the browser to use.
这将启动一个新的浏览器实例,该实例将保留 Cookie,直到您使用 sessions.destroy 销毁它。这很方便,因此您不必一遍又一遍地解决挑战,也不需要不断发送 cookie 供浏览器使用。

This also speeds up the requests since it won't have to launch a new browser instance for every request.
这还可以加快请求速度,因为它不必为每个请求启动新的浏览器实例。

Parameter  参数 Notes  笔记
session  会期 Optional. The session ID that you want to be assigned to the instance. If isn't set a random UUID will be assigned.
自选。要分配给实例的会话 ID。如果未设置,将分配一个随机的 UUID。
proxy  代理 Optional, default disabled. Eg: "proxy": {"url": "http://127.0.0.1:8888"}. You must include the proxy schema in the URL: http://, socks4:// or socks5://. Authorization (username/password) is supported. Eg: "proxy": {"url": "http://127.0.0.1:8888", "username": "testuser", "password": "testpass"}
可选,默认禁用。例如: "proxy": {"url": "http://127.0.0.1:8888"} .您必须在 URL 中包含代理架构:http://socks4://socks5://。支持授权 (用户名/密码)。例如: "proxy": {"url": "http://127.0.0.1:8888", "username": "testuser", "password": "testpass"}

+ sessions.list  + 会话列表

Returns a list of all the active sessions. More for debugging if you are curious to see how many sessions are running. You should always make sure to properly close each session when you are done using them as too many may slow your computer down.
返回所有活动会话的列表。如果您想查看正在运行的会话数,则更多用于调试。使用完每个会话后,您应该始终确保正确关闭每个会话,因为太多可能会降低您的计算机速度。

Example response:  响应示例:

{
  "sessions": [
    "session_id_1",
    "session_id_2",
    "session_id_3..."
  ]
}

+ sessions.destroy
+ 会话.destroy

This will properly shutdown a browser instance and remove all files associated with it to free up resources for a new session. When you no longer need to use a session you should make sure to close it.
这将正确关闭浏览器实例并删除与其关联的所有文件,以便为新会话释放资源。当您不再需要使用某个会话时,应确保将其关闭。

Parameter  参数 Notes  笔记
session  会期 The session ID that you want to be destroyed.
要销毁的会话 ID。

+ request.get  + 请求.get

Parameter  参数 Notes  笔记
url  网址 Mandatory  命令的
session  会期 Optional. Will send the request from and existing browser instance. If one is not sent it will create a temporary instance that will be destroyed immediately after the request is completed.
自选。将从现有浏览器实例发送请求。如果未发送一个,它将创建一个临时实例,该实例将在请求完成后立即销毁。
session_ttl_minutes Optional. FlareSolverr will automatically rotate expired sessions based on the TTL provided in minutes.
maxTimeout Optional, default value 60000. Max timeout to solve the challenge in milliseconds.
cookies Optional. Will be used by the headless browser. Eg: "cookies": [{"name": "cookie1", "value": "value1"}, {"name": "cookie2", "value": "value2"}].
returnOnlyCookies Optional, default false. Only returns the cookies. Response data, headers and other parts of the response are removed.
proxy Optional, default disabled. Eg: "proxy": {"url": "http://127.0.0.1:8888"}. You must include the proxy schema in the URL: http://, socks4:// or socks5://. Authorization (username/password) is not supported. (When the session parameter is set, the proxy is ignored; a session specific proxy can be set in sessions.create.)

Warning If you want to use Cloudflare clearance cookie in your scripts, make sure you use the FlareSolverr User-Agent too. If they don't match you will see the challenge.

Example response from running the curl above:

{
    "solution": {
        "url": "https://www.google.com/?gws_rd=ssl",
        "status": 200,
        "headers": {
            "status": "200",
            "date": "Thu, 16 Jul 2020 04:15:49 GMT",
            "expires": "-1",
            "cache-control": "private, max-age=0",
            "content-type": "text/html; charset=UTF-8",
            "strict-transport-security": "max-age=31536000",
            "p3p": "CP=\"This is not a P3P policy! See g.co/p3phelp for more info.\"",
            "content-encoding": "br",
            "server": "gws",
            "content-length": "61587",
            "x-xss-protection": "0",
            "x-frame-options": "SAMEORIGIN",
            "set-cookie": "1P_JAR=2020-07-16-04; expires=Sat..."
        },
        "response":"<!DOCTYPE html>...",
        "cookies": [
            {
                "name": "NID",
                "value": "204=QE3Ocq15XalczqjuDy52HeseG3zAZuJzID3R57...",
                "domain": ".google.com",
                "path": "/",
                "expires": 1610684149.307722,
                "size": 178,
                "httpOnly": true,
                "secure": true,
                "session": false,
                "sameSite": "None"
            },
            {
                "name": "1P_JAR",
                "value": "2020-07-16-04",
                "domain": ".google.com",
                "path": "/",
                "expires": 1597464949.307626,
                "size": 19,
                "httpOnly": false,
                "secure": true,
                "session": false,
                "sameSite": "None"
            }
        ],
        "userAgent": "Windows NT 10.0; Win64; x64) AppleWebKit/5..."
    },
    "status": "ok",
    "message": "",
    "startTimestamp": 1594872947467,
    "endTimestamp": 1594872949617,
    "version": "1.0.0"
}

+ request.post

This is the same as request.get but it takes one more param:

Parameter Notes
postData Must be a string with application/x-www-form-urlencoded. Eg: a=b&c=d

Environment variables

Name Default Notes
LOG_LEVEL info Verbosity of the logging. Use LOG_LEVEL=debug for more information.
LOG_HTML false Only for debugging. If true all HTML that passes through the proxy will be logged to the console in debug level.
CAPTCHA_SOLVER none Captcha solving method. It is used when a captcha is encountered. See the Captcha Solvers section.
TZ UTC Timezone used in the logs and the web browser. Example: TZ=Europe/London.
LANG none Language used in the web browser. Example: LANG=en_GB.
HEADLESS true Only for debugging. To run the web browser in headless mode or visible.
BROWSER_TIMEOUT 40000 If you are experiencing errors/timeouts because your system is slow, you can try to increase this value. Remember to increase the maxTimeout parameter too.
TEST_URL https://www.google.com FlareSolverr makes a request on start to make sure the web browser is working. You can change that URL if it is blocked in your country.
PORT 8191 Listening port. You don't need to change this if you are running on Docker.
HOST 0.0.0.0 Listening interface. You don't need to change this if you are running on Docker.
PROMETHEUS_ENABLED false Enable Prometheus exporter. See the Prometheus section below.
PROMETHEUS_PORT 8192 Listening port for Prometheus exporter. See the Prometheus section below.

Environment variables are set differently depending on the operating system. Some examples:

  • Docker: Take a look at the Docker section in this document. Environment variables can be set in the docker-compose.yml file or in the Docker CLI command.
  • Linux: Run export LOG_LEVEL=debug and then run flaresolverr in the same shell.
  • Windows: Open cmd.exe, run set LOG_LEVEL=debug and then run flaresolverr.exe in the same shell.

Prometheus exporter

The Prometheus exporter for FlareSolverr is disabled by default. It can be enabled with the environment variable PROMETHEUS_ENABLED. If you are using Docker make sure you expose the PROMETHEUS_PORT.

Example metrics:

# HELP flaresolverr_request_total Total requests with result
# TYPE flaresolverr_request_total counter
flaresolverr_request_total{domain="nowsecure.nl",result="solved"} 1.0
# HELP flaresolverr_request_created Total requests with result
# TYPE flaresolverr_request_created gauge
flaresolverr_request_created{domain="nowsecure.nl",result="solved"} 1.690141657157109e+09
# HELP flaresolverr_request_duration Request duration in seconds
# TYPE flaresolverr_request_duration histogram
flaresolverr_request_duration_bucket{domain="nowsecure.nl",le="0.0"} 0.0
flaresolverr_request_duration_bucket{domain="nowsecure.nl",le="10.0"} 1.0
flaresolverr_request_duration_bucket{domain="nowsecure.nl",le="25.0"} 1.0
flaresolverr_request_duration_bucket{domain="nowsecure.nl",le="50.0"} 1.0
flaresolverr_request_duration_bucket{domain="nowsecure.nl",le="+Inf"} 1.0
flaresolverr_request_duration_count{domain="nowsecure.nl"} 1.0
flaresolverr_request_duration_sum{domain="nowsecure.nl"} 5.858
# HELP flaresolverr_request_duration_created Request duration in seconds
# TYPE flaresolverr_request_duration_created gauge
flaresolverr_request_duration_created{domain="nowsecure.nl"} 1.6901416571570296e+09

Captcha Solvers

Warning At this time none of the captcha solvers work. You can check the status in the open issues. Any help is welcome.

Sometimes CloudFlare not only gives mathematical computations and browser tests, sometimes they also require the user to solve a captcha. If this is the case, FlareSolverr will return the error Captcha detected but no automatic solver is configured.

FlareSolverr can be customized to solve the CAPTCHA automatically by setting the environment variable CAPTCHA_SOLVER to the file name of one of the adapters inside the /captcha directory.

Related projects


文章来源: https://github.com/FlareSolverr/FlareSolverr
如有侵权请联系:admin#unsafe.sh