|
| 1 | +<p align="center"> |
| 2 | + <a href="https://avwo.github.io/whistle/"> |
| 3 | + <img alt="whistle logo" src="https://user-images.githubusercontent.com/11450939/168828068-99e38862-d5fc-42bc-b5ab-6262b2ca27d6.png"> |
| 4 | + </a> |
| 5 | +</p> |
| 6 | + |
| 7 | +# whistle |
| 8 | +[](https://npmjs.org/package/whistle) |
| 9 | +[](http://nodejs.org/download/) |
| 10 | +[](https://codecov.io/gh/avwo/whistle) |
| 11 | +[](https://npmjs.org/package/whistle) |
| 12 | +[](https://www.npmjs.com/package/whistle) |
| 13 | +[](https://www.npmjs.com/package/whistle) |
| 14 | + |
| 15 | +[中文](./README-zh_CN.md) · English |
| 16 | + |
| 17 | +Whistle is a simple and powerful cross-platform packet capture and debugging tool based on Node.JS. It can be used as **HTTP proxy (default)**, **HTTPS proxy**, **Socks proxy**, **reverse proxy**, etc., for **packet capture analysis** or **modification through configuration rules** of HTTP, HTTPS, HTTP/2, WebSocket, TCP requests. It also has built-in **Weinre**, **Log**, **Composer** and other tools to view the DOM structure of remote pages, view console output content, replay and edit construction requests, etc. It also supports **plug-in extension functions** or **referenced by projects as NPM packages**. |
| 18 | + |
| 19 | +# Installation |
| 20 | + |
| 21 | +**Windows PC or Mac PC recommended client: [https://github.com/avwo/whistle-client](https://github.com/avwo/whistle-client).** |
| 22 | + |
| 23 | +> If you use Whistle client, you can skip this installation step |
| 24 | +
|
| 25 | +Linux PC, server and other systems can use the command line version, which needs to be installed strictly according to the following 4 steps: |
| 26 | + |
| 27 | +1. Install Whistle |
| 28 | +2. Start Whistle |
| 29 | +3. Install root certificate |
| 30 | +4. Set up proxy |
| 31 | + |
| 32 | +### Install Whistle |
| 33 | + |
| 34 | +Choose one of the following installation methods according to the actual situation: |
| 35 | + |
| 36 | +1. Install through npm (need to install Node.JS first: https://nodejs.org/ ): |
| 37 | + |
| 38 | +``` sh |
| 39 | +npm i -g whistle |
| 40 | +``` |
| 41 | + |
| 42 | +2. Install through brew (need to install brew first: https://brew.sh/ ): |
| 43 | + |
| 44 | +``` sh |
| 45 | +brew install whistle |
| 46 | +``` |
| 47 | + |
| 48 | +### Start Whistle |
| 49 | + |
| 50 | +``` sh |
| 51 | +w2 start |
| 52 | +``` |
| 53 | + |
| 54 | +> Whistle starts HTTP proxy by default (IP: `127.0.0.1`, port: `8899`), which can be started through `w2 start -p 8888` Modify the port. If it has been started, restart it with `w2 restart -p 8888` to modify the port. |
| 55 | +
|
| 56 | +For complete command line functions, please refer to the full document: https://wproxy.org/whistle/options.html |
| 57 | + |
| 58 | +### Install the root certificate |
| 59 | + |
| 60 | +After starting Whistle, you can install the root certificate with the following command: |
| 61 | + |
| 62 | +``` sh |
| 63 | +w2 ca --enable-https |
| 64 | +``` |
| 65 | + |
| 66 | +<details> |
| 67 | +<summary>Windows needs to click "Yes (Y)" to confirm</summary> |
| 68 | +<img alt="Click Yes (Y)" width="420" src="https://user-images.githubusercontent.com/11450939/168846905-384e0540-e02f-46de-81d7-e395a496f032.jpeg"> |
| 69 | +</details> |
| 70 | + |
| 71 | +<details> |
| 72 | +<summary>Mac You need to enter the power-on password or fingerprint verification</summary> |
| 73 | +<img alt="Enter the power-on password" width="330" src="https://user-images.githubusercontent.com/11450939/176977027-4a7b06a0-64f6-4580-b983-312515e9cd4e.png"> |
| 74 | +<img alt="Enter fingerprint" width="330" src="https://user-images.githubusercontent.com/11450939/168847123-e66845d0-6002-4f24-874f-b6943f7f376b.png"> |
| 75 | +</details> |
| 76 | + |
| 77 | +For how to install the root certificate on other terminals such as mobile phones, please refer to the complete document: https://wproxy.org/whistle/webui/https.html |
| 78 | + |
| 79 | +### Setting up a proxy |
| 80 | + |
| 81 | +**There are four ways to use Windows PC or Mac PC. You can choose one of them according to your actual situation:** |
| 82 | + |
| 83 | +1. **[Recommended]** Set up a proxy by installing the Chrome plug-in SwitchyOmega: https://chromewebstore.google.com/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif |
| 84 | + |
| 85 | +> Chrome App Store requires a VPN. If you cannot access it, please install it manually: https://proxy-switchyomega.com/download/ |
| 86 | +
|
| 87 | +<details> |
| 88 | +<summary>SwitchyOmega setting method example diagram</summary> |
| 89 | +<img width="620" alt="image" src="https://github.com/user-attachments/assets/24016b7c-8f2a-45a3-9dc8-5ef3ddf46233" /><img width="180" alt="image" src="https://github.com/user-attachments/assets/43afd3cd-5c17-4d6a-82d0-20a7ef2e0d99" /> |
| 90 | +</details> |
| 91 | + |
| 92 | +2. Set the system proxy through the command line: |
| 93 | + |
| 94 | +```. sh |
| 95 | +w2 proxy |
| 96 | +``` |
| 97 | + |
| 98 | +> You can also specify the IP (default `127.0.0.1`) and port: `w2 proxy "10.x.x.x:8888"`, and use `w2 proxy 0` to turn off the system proxy setting |
| 99 | +
|
| 100 | +3. Set the proxy directly on the client, such as FireFox, WeChat developer tools, etc., which have built-in proxy setting functions |
| 101 | +<details> |
| 102 | +<summary>FireFox proxy setting example image</summary> |
| 103 | +<img width="1100" alt="image" src="https://github.com/user-attachments/assets/98c1ec5d-4955-4e23-a49a-c1015b128d9d" /> |
| 104 | +</details> |
| 105 | +4. Set up a proxy through Proxifier (for clients that cannot set up a proxy and do not use a system proxy): https://www.proxifier.com/docs/win-v4/http-proxy.html |
| 106 | + |
| 107 | +**Linux setting path: Settings > Network > VPN > Network Proxy > Manual** |
| 108 | +<details> |
| 109 | +<summary>Linux proxy setting example image</summary> |
| 110 | +<img width="1000" alt="image" src="https://github.com/user-attachments/assets/e9441d32-c818-4446-8be6-0fa3df3aed86" /> |
| 111 | +</details> |
| 112 | + |
| 113 | +**Mobile devices such as mobile phones need to configure the current `Wi-Fi` proxy, taking iOS as an example:** |
| 114 | +<details> |
| 115 | +<summary>iOS proxy settings example image</summary> |
| 116 | +<img width="1000" alt="image" src="https://github.com/user-attachments/assets/e97dc311-2ace-4287-b6b0-0247b13974a9" /> |
| 117 | +</details> |
| 118 | + |
| 119 | +# Use |
| 120 | + |
| 121 | +After installing Whistle according to the above steps, open the link http://local.whistlejs.com on the Chrome browser, and you can see the following operation interface: |
| 122 | + |
| 123 | +<img width="1200" alt="network" src="https://github.com/user-attachments/assets/3186e76a-486a-4e61-98a1-2d4b4f91fad0" /> |
| 124 | + |
| 125 | +<img width="1200" alt="rules" src="https://github.com/user-attachments/assets/2e336403-4810-48e5-91c1-6f22dcda7388" /> |
| 126 | + |
| 127 | +Among them, Network is the interface for viewing packet capture, Rules is the configuration rule, Values is the configuration data interface (used with Rules), and Plugins is the list of installed plugins. |
| 128 | + |
| 129 | +### Interface functions |
| 130 | + |
| 131 | +<details> |
| 132 | +<summary>Replay request</summary> |
| 133 | +<img width="800" alt="image" src="https://github.com/user-attachments/assets/9f8276ac-e089-427b-97f4-becac250ae5e" /> |
| 134 | +</details> |
| 135 | + |
| 136 | +<details> |
| 137 | +<summary>Edit or construct request</summary> |
| 138 | +<img width="1200" alt="image" src="https://github.com/user-attachments/assets/f2a5b088-72b6-4098-8ba6-3e42f15f3ad8" /> |
| 139 | +</details> |
| 140 | + |
| 141 | +For other interface functions, see the full document: https://wproxy.org/whistle/webui/ |
| 142 | + |
| 143 | +### Rule functions |
| 144 | + |
| 145 | +Whistle rules can be seen as an extension of the following system hosts rules: |
| 146 | + |
| 147 | +``` txt |
| 148 | +# One domain name corresponds to one IP |
| 149 | +127.0.0.1 localhost |
| 150 | +::1 localhost |
| 151 | +# Multiple domain names correspond to one IP |
| 152 | +10.2.55.3 www.test.com www.example.com |
| 153 | +``` |
| 154 | + |
| 155 | +The system hosts rules have a single function, only supporting DNS modification and domain name matching, and there are DNS cache problems, which cannot meet daily work needs. Whistle rules extend the functions of system hosts rules. In terms of matching methods, they not only support domain name matching, path matching, wildcard matching, regular matching, etc., but also support further filtering by request method, response status code, request (response) header, request content, etc.; in terms of functions, they not only support DNS modification, but also support port modification, CNAME, proxy setting, request URL modification, request method, response status code, request header, response header, request content, response content, etc. In theory, everything in HTTP request can be modified. The format of Whistle rules is: |
| 156 | + |
| 157 | +1. Default format |
| 158 | + |
| 159 | +``` txt |
| 160 | +pattern operation |
| 161 | +``` |
| 162 | + |
| 163 | +2. Support matching multiple operations |
| 164 | + |
| 165 | +``` txt |
| 166 | +pattern operation1 operation2 ... |
| 167 | +``` |
| 168 | + |
| 169 | +3. Support filters |
| 170 | + |
| 171 | +``` txt |
| 172 | +pattern operation1 operation2 ... includeFilter://filterPattern1 ... excludeFilter://filterPatternN ... |
| 173 | +``` |
| 174 | + |
| 175 | +> Multiple filters are in an or relationship, that is, one of the conditions must be met |
| 176 | +
|
| 177 | +4. Support position swap (prerequisite: operation and pattern are not URLs or domain names at the same time) |
| 178 | + |
| 179 | +``` txt |
| 180 | +operation pattern [filters ...] |
| 181 | +operation pattern1 pattern2 ... [filters ...] |
| 182 | +``` |
| 183 | + |
| 184 | +5. Support line breaks |
| 185 | + |
| 186 | +``` txt |
| 187 | +line` |
| 188 | +operation |
| 189 | +pattern1 |
| 190 | +pattern2 ... |
| 191 | +[filters ...] |
| 192 | +` |
| 193 | +``` |
| 194 | + |
| 195 | +Specific examples are as follows: |
| 196 | + |
| 197 | +##### Modify DNS (set Hosts) |
| 198 | + |
| 199 | +1. Domain name matching |
| 200 | + |
| 201 | +``` txt |
| 202 | +www.test.com 127.0.0.1 |
| 203 | +# Support port |
| 204 | +www.test.com 127.0.0.1:8080 |
| 205 | +# CNAME function (port optional) |
| 206 | +www.test.com host://www.example.com:8181 |
| 207 | +``` |
| 208 | + |
| 209 | +> Unlike the system hosts rule, the Whistle rule adopts **left-to-right mapping** and **top-to-bottom priority** by default, but the operation and pattern can be swapped when they are different URLs or domain names, so it is also compatible with the system hosts rule, that is: `127.0.0.1:8080 www.test.com` |
| 210 | +
|
| 211 | +2. Path matching |
| 212 | + |
| 213 | +``` txt |
| 214 | +www.test.com/path/to 127.0.0.1:8080 |
| 215 | +# Support with protocol |
| 216 | +https://www.test.com/path/to 127.0.0.1:8080 |
| 217 | +``` |
| 218 | + |
| 219 | +3. Wildcard matching |
| 220 | + |
| 221 | +``` txt |
| 222 | +# Domain name wildcard, matching test.com All descendant domain names of |
| 223 | +**.test.com 127.0.0.1:8080 |
| 224 | +# Support wildcards for domain names with protocols |
| 225 | +https://**.test.com 127.0.0.1:8080 |
| 226 | +# Path wildcards (* is a legal character for paths, so add ^ in front to tell Whistle that it is a wildcard) |
| 227 | +^**.test.com/*/path/to 127.0.0.1:8080 |
| 228 | +# Support wildcards for paths with protocols |
| 229 | +^https://**.test.com/*/path/to 127.0.0.1:8080 |
| 230 | +``` |
| 231 | + |
| 232 | +> `*`, `**`, `***` have different matching ranges, for details, see the full document: https://wproxy.org/whistle/pattern.html |
| 233 | +
|
| 234 | +4. Regular matching |
| 235 | + |
| 236 | +``` txt |
| 237 | +# The internal `/` can be escaped, which is equivalent to `new RegExp('^https?://\w+\.test\.com')` |
| 238 | +/^https?://\w+\.test\.com/ 127.0.0.1:8080 |
| 239 | +``` |
| 240 | + |
| 241 | +5. Filter matching |
| 242 | + |
| 243 | +``` txt |
| 244 | +# `pattern` is the same as the domain name, path, and regular expression above, indicating that in addition to matching `pattern`, the request header `cookie` must also contain `env=test` |
| 245 | +pattern 127.0.0.1:8080 includeFilter://reqH.cookie=/env=test/ |
| 246 | +``` |
| 247 | + |
| 248 | +##### Modify form data |
| 249 | + |
| 250 | +``` txt |
| 251 | +# Modify the value of the `test` field in the form |
| 252 | +pattern reqMerge://test=123 |
| 253 | +
|
| 254 | +# Delete the `abc` field in the form |
| 255 | +pattern delete://reqBody.abc |
| 256 | +``` |
| 257 | + |
| 258 | +##### Set the cross-domain response header |
| 259 | + |
| 260 | +``` txt |
| 261 | +# Taking path matching as an example, set the cross-domain response header Access-Control-Allow-Origin: * and exclude OPTION requests |
| 262 | +pattern resCors://* excludeFilter://m:option |
| 263 | +``` |
| 264 | + |
| 265 | +For all rules, see the full document: https://wproxy.org/whistle/rules/ |
| 266 | + |
| 267 | +### Install the plugin |
| 268 | + |
| 269 | +The plugin needs to be installed through the command line: |
| 270 | + |
| 271 | +``` sh |
| 272 | +w2 i whistle.inspect whistle.vase |
| 273 | +``` |
| 274 | + |
| 275 | +> The above plug-in function introduction and source code: [https://github.com/whistle-plugins](https://github.com/whistle-plugins), the client can be installed through the interface: [https://github.com/avwo/whistle-client](https://github.com/avwo/whistle-client) |
| 276 | +
|
| 277 | +After installation, you can see these two plug-ins in the Plugins of the management interface: |
| 278 | + |
| 279 | +<details> |
| 280 | +<summary>Plugin list example image</summary> |
| 281 | +<img width="1000" alt="image" src="https://github.com/user-attachments/assets/ec018691-c7a9-415e-9809-bf079694c024" /> |
| 282 | +</details> |
| 283 | + |
| 284 | +Each plug-in can add two rule protocols by default: |
| 285 | + |
| 286 | +``` txt |
| 287 | +whistle.inspect://xxx |
| 288 | +inspect://xxx |
| 289 | +``` |
| 290 | + |
| 291 | +> By configuring the custom rules of the plug-in, the matching request can be forwarded to the plug-in specified hook implements custom functions. If not needed, you can also set `"hideLongProtocol": true` or `"hideShortProtocol": true` in `whistleConfig` of `package.json` of the plugin to hide the corresponding rule protocol |
| 292 | +
|
| 293 | +In addition to extending rules, the plugin also supports extending the Whistle interface, as well as providing operation interfaces, built-in rules and other functions. For installation, use and development of the plugin, please refer to the complete document: https://wproxy.org/whistle/plugins.html |
| 294 | + |
| 295 | +# License |
| 296 | + |
| 297 | +[MIT](./LICENSE) |
0 commit comments