Project Icon

brook

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

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

Brook

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. This will trigger the in_dnsquery variable, carrying information such as domain
    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. This will trigger the in_address variable, carrying information such as domainaddress
    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. This will trigger the in_address variable, carrying information such as ipaddress
    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. This will trigger the in_address variable, carrying information such as ipaddress
    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. This will trigger the in_address variable, carrying information such as ipaddress
    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. This will trigger the in_address variable, carrying information such as ipaddress
    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,
项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号