brook

brook

多功能跨平台网络工具Brook提供灵活控制

Brook是一款跨平台网络工具,支持iOS、Android、Mac、Windows、Linux和OpenWrt等多种操作系统。它提供Fake DNS功能和可编程脚本接口,使用户能够精细控制网络请求和管理。Brook适用于各种网络环境,可用于优化网络性能和管理复杂的网络需求。

Brook网络工具代理VPN跨平台Github开源项目

Brook

<!--SIDEBAR--> <!--G-R3M673HK5V-->

A cross-platform programmable network tool.

Sponsor

❤️ Shiliew - A network app designed for those who value their time

Getting Started

Server

bash <(curl https://bash.ooo/nami.sh)
nami install brook
brook server -l :9999 -p hello

Client

iOSAndroidMacWindowsLinuxOpenWrt
WindowsOpenWrt
//App ModeHowHowHow

You may want to use brook link to customize some parameters

Client

Brook GUI will pass different global variables to the script at different times, and the script only needs to assign the processing result to the global variable out

CLI

Before discussing the GUI client, let's first talk about the command line client brook. As we know, after you have deployed the server, you can use the command line client brook to create a local socks5 proxy or http proxy on your machine, and then configure it in your system proxy settings or in your browser to use this proxy. However:

  1. Not all apps will use this proxy, whether they use it is up to the app itself.
  2. Generally, all UDP protocols will not go through this proxy, such as http3.

For the specifics of socks5 and http proxy, you can read this article.

GUI

The GUI client does not use socks5 and http proxy mode, so there is no issue with some software not using the system proxy. Instead, it uses a virtual network card to take over the entire system's network, including UDP-based http3. Moreover, Brook allows us to control network requests programmatically, so it is necessary to have basic knowledge of network requests.

Without Brook: Basic Knowledge of Network Requests

Note: When we talk about addresses, we mean addresses that include the port number, such as a domain address: google.com:443, or an IP address: 8.8.8.8:53

  1. When an app requests a domain address, such as google.com:443
  2. It will first perform a DNS resolution, which means that the app will send a network request to the system-configured DNS, such as 8.8.8.8:53, to inquire about the IP of google.com
    1. The system DNS will return the IP of google.com, such as 1.2.3.4, to the app
  3. The app will combine the IP and port into an IP address, such as: 1.2.3.4:443
  4. The app makes a network request to this IP address 1.2.3.4:443
  5. The app receives the response data

In the above process, the app actually makes two network requests: one to the IP address 8.8.8.8:53 and another to the IP address 1.2.3.4:443. In other words, the domain name is essentially an alias for the IP, and must obtain the domain's IP to establish a connection.

With Brook: Fake DNS On

Brook has a Fake DNS feature, which can parse the domain name out of the query requests that an app sends to the system DNS and decide how to respond to the app.

  1. When an app requests a domain name address, such as google.com:443
  2. A DNS resolution will be performed first. That is, the app will send a network request to the system-configured DNS, such as 8.8.8.8:53, to inquire about the IP of google.com
  3. The Brook client detects that an app is sending a network request to 8.8.8.8:53. <mark>This will trigger the in_dnsquery variable, carrying information such as domain</mark>
    1. The Brook client returns a fake IP to the app, such as 240.0.0.1
  4. The app combines the IP and port into an IP address, such as: 240.0.0.1:443
  5. The app makes a network request to the IP address 240.0.0.1:443
  6. The Brook client detects that an app is sending a network request to 240.0.0.1:443, discovers that this is a fake IP, and will convert the fake IP address back to the domain address google.com:443. <mark>This will trigger the in_address variable, carrying information such as domainaddress</mark>
    1. The Brook client sends google.com:443 to the Brook Server
    2. The Brook Server first requests its own DNS to resolve the domain name to find out the IP of google.com, such as receiving 1.2.3.4
    3. The Brook Server combines the IP and port into an IP address, such as: 1.2.3.4:443
    4. The Brook Server sends a network request to 1.2.3.4:443 and returns the data to the Brook client
    5. The Brook client then returns the data to the app
  7. The app receives the response data

However, if the following situations occur, the domain name will not/cannot be parsed, meaning that the Brook client will not/cannot know what the domain name is and will treat it as a normal request sent to an IP address:

  • Fake DNS not enabled: in this case, the Brook client will not attempt to parse the domain name from the request sent to the system DNS and will treat it as a normal request sent to an IP address.
  • Even with Fake DNS enabled, but the app uses the system's secure DNS or the app's own secure DNS: in this case, the Brook client cannot parse the domain name from the request sent to the secure DNS and will treat it as a normal request sent to an IP address.

To avoid the ineffectiveness of Fake DNS, please refer to this article.

With Brook: Fake DNS Off

  1. When an app requests a domain address, such as google.com:443
  2. A DNS resolution will be performed first. That is, the app will send a network request to the system-configured DNS, such as 8.8.8.8:53, to inquire about the IP of google.com
  3. The Brook client detects that an app is sending a network request to 8.8.8.8:53. <mark>This will trigger the in_address variable, carrying information such as ipaddress</mark>
    1. The Brook client sends 8.8.8.8:53 to the Brook Server
    2. The Brook Server sends a network request to 8.8.8.8:53 and returns the result, such as 1.2.3.4, to the Brook client
    3. The Brook client then returns the result to the app
  4. The app combines the IP and port into an IP address, such as: 1.2.3.4:443
  5. The app makes a network request to the IP address 1.2.3.4:443
  6. The Brook client detects that an app is sending a network request to 1.2.3.4:443. <mark>This will trigger the in_address variable, carrying information such as ipaddress</mark>
    1. The Brook client sends 1.2.3.4:443 to the Brook Server
    2. The Brook Server sends a network request to 1.2.3.4:443 and returns the data to the Brook client
    3. The Brook client then returns the data to the app
  7. The app receives the response data

With Brook: Fake DNS On, But the App Uses the System's Secure DNS or Its Own Secure DNS

  1. When an app requests a domain name address, such as google.com:443
  2. A DNS resolution will be performed first. That is, the app will send a network request to the secure DNS, such as 8.8.8.8:443, to inquire about the IP of google.com
  3. The Brook client detects that an app is sending a network request to 8.8.8.8:443. <mark>This will trigger the in_address variable, carrying information such as ipaddress</mark>
    1. The Brook client sends 8.8.8.8:443 to the Brook Server
    2. The Brook Server sends a network request to 8.8.8.8:443, and returns the result, such as 1.2.3.4, to the Brook client
    3. The Brook client then returns the result to the app
  4. The app combines the IP and port into an IP address, such as: 1.2.3.4:443
  5. The app makes a network request to the IP address 1.2.3.4:443
  6. The Brook client detects that an app is sending a network request to 1.2.3.4:443. <mark>This will trigger the in_address variable, carrying information such as ipaddress</mark>
    1. The Brook client sends 1.2.3.4:443 to the Brook Server
    2. The Brook Server sends a network request to 1.2.3.4:443 and returns the data to the Brook client
    3. The Brook client then returns the data to the app
  7. The app receives the response data

To avoid the ineffectiveness of Fake DNS, please refer to this article.

Handle Variable Trigger

  • When the in_brooklinks variable is triggered:
    • This is currently the only variable that gets triggered before the Brook client starts.
    • We know that Brook starts with your choice of a Brook Server, and this variable lets you specify multiple Brook Servers.
    • Then during runtime, you can use one of these Brook Servers as needed.
  • When the in_dnsquery variable is triggered, you can process as needed, such as:
    • Blocking, such as to prevent ad domain names.
    • Directly specifying the response IP.
    • Letting the system DNS resolve this domain.
    • Letting Bypass DNS resolve this domain.
    • And so on.
  • When the in_address variable is triggered, you can process as needed, such as:
    • Block this connection.
    • Rewrite the destination.
    • If it's a domain address, you can specify that Bypass DNS is responsible for resolving the IP of this domain.
    • Allow it to connect directly without going through a proxy.
    • If it's HTTP/HTTPS, you can start MITM (Man-In-The-Middle), which will subsequently trigger in_httprequest and in_httpresponse.
    • And so on.
  • When the in_httprequest variable is triggered, you can process as needed, such as:
    • Modifying the HTTP request.
    • Returning a custom HTTP response directly.
  • When the in_httpresponse variable is triggered, you can process as needed, such as:
    • Modifying the HTTP response.

For detailed information on the properties and responses of variables, please refer to the following content.

Variables

variabletypeconditiontimingdescriptionout type
in_brooklinksmap/Before connectingPredefine multiple brook links, and then programmatically specify which one to connect tomap
in_dnsquerymapFakeDNS: OnWhen a DNS query occursScript can decide how to handle this requestmap
in_addressmap/When connecting to an addressscript can decide how to connectmap
in_httprequestmap/When an HTTP(S) request comes inthe script can decide how to handle this requestmap
in_httprequest,in_httpresponsemap/when an HTTP(S) response comes inthe script can decide how to handle this responsemap

in_brooklinks

KeyTypeDescriptionExample
_boolmeaninglesstrue

out, ignored if not of type map

KeyTypeDescriptionExample
............
custom namestringbrook linkbrook://...
............

in_dnsquery

KeyTypeDescriptionExample
domainstringdomain namegoogle.com
typestringquery typeA
appidstringApp ID or pathcom.google.Chrome.helper
interfacestringnetwork interface. Mac onlyen0

out, if it is error type will be recorded in the log. Ignored if not of type map

KeyTypeDescriptionExample
blockboolWhether Block, default falsefalse
ipstringSpecify IP directly, only valid when type is A/AAAA1.2.3.4
systemboolResolve by System DNS, default falsefalse
bypassboolResolve by Bypass DNS, default falsefalse
brooklinkkeystringWhen need to connect the Server,instead, connect to the Server specified by the key in_brooklinkscustom name

in_address

KeyTypeDescriptionExample
networkstringNetwork type, the value tcp/udptcp
ipaddressstringIP type address. There is only of ipaddress and domainaddress. Note that there is no relationship between these two1.2.3.4:443
domainaddressstringDomain type address, because of FakeDNS we can get the domain name address heregoogle.com:443
appidstringApp ID or pathcom.google.Chrome.helper
interfacestringnetwork interface. Mac onlyen0

out, if it is error type will be recorded in the log. Ignored if not of type map

KeyTypeDescriptionExample
blockboolWhether Block, default falsefalse
ipaddressstringIP type address, rewrite destination1.2.3.4:443
ipaddressfrombypassdnsstringUse Bypass DNS to obtain A or AAAA IP and rewrite the destination, only valid when domainaddress exists, the value A/AAAAA
bypassboolBypass, default false. If true and domainaddress, then ipaddress or ipaddressfrombypassdns must be specifiedfalse
mitmboolWhether to perform MITM, default false. Only valid when network is tcp. Need to install CA, see belowfalse
mitmprotocolstringMITM protocol needs to be specified explicitly, the value is http/httpshttps
mitmcertdomainstringThe MITM certificate domain name, which is taken from domainaddress by default. If ipaddress and mitm is true and mitmprotocol is https then must be must be specified explicitlyexample.com
mitmwithbodyboolWhether to manipulate the http body, default false. will read the body of the request and response into the memory and interact with the script. iOS 50M total memory limit may kill processfalse
mitmautohandlecompressboolWhether to automatically decompress the http body when interacting with the script, default falsefalse
mitmclienttimeoutintTimeout for MITM talk to server,

编辑推荐精选

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

Hunyuan3D-2

Hunyuan3D-2

高分辨率纹理 3D 资产生成

Hunyuan3D-2 是腾讯开发的用于 3D 资产生成的强大工具,支持从文本描述、单张图片或多视角图片生成 3D 模型,具备快速形状生成能力,可生成带纹理的高质量 3D 模型,适用于多个领域,为 3D 创作提供了高效解决方案。

3FS

3FS

一个具备存储、管理和客户端操作等多种功能的分布式文件系统相关项目。

3FS 是一个功能强大的分布式文件系统项目,涵盖了存储引擎、元数据管理、客户端工具等多个模块。它支持多种文件操作,如创建文件和目录、设置布局等,同时具备高效的事件循环、节点选择和协程池管理等特性。适用于需要大规模数据存储和管理的场景,能够提高系统的性能和可靠性,是分布式存储领域的优质解决方案。

下拉加载更多