Brook Client Basic Knowledge

Updated at: 2024-07-25

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 Client

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 Client

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:

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

Handle Variable Trigger

For detailed information on the properties and responses of variables, please refer to the Brook documentation: https://brook.app