AnyProxy Documentation
repository·master·Indexed 26 days ago
https://github.com/alibaba/anyproxyA fully configurable HTTP/HTTPS proxy server implemented in Node.js (version 4.1.3). AnyProxy features a plugin architecture for traffic interception, modification, and analysis. It provides a CLI for server management, a web GUI for request viewing, and an npm module for integration into Node.js applications. Key capabilities include HTTPS decryption via Root CA management, WebSocket interception, traffic throttling, and a rule-based processing flow for modifying requests and responses.
What's inside anyproxy
- AnyProxy is a fully configurable HTTP/HTTPS proxy server built on NodeJS. It is designed to be extensible via a plugin system, allowing developers to intercept and modify network traffic.
Getting Started with AnyProxy
masterTo start using AnyProxy, you can follow these primary workflows:
- Install: Install the package via npm.
- Launch: Run the AnyProxy CLI to start the proxy server.
- Configure Options: Use command-line options to customize the proxy behavior.
- Use as a Node Module: Import AnyProxy into your own Node.js application for programmatic control.
Start AnyProxy via CLI
masterYou can start the AnyProxy server from the terminal. By default, it runs on port 8001.
- Run the command:
anyproxy - Configure your terminal's HTTP proxy to
127.0.0.1:8001. - Access the Web GUI at
http://127.0.0.1:8002to view request information.
To start on a specific port (e.g., 1080):
anyproxy --port 1080anyproxy- Run the command:
Install and run AnyProxy as a global module
masterTo use AnyProxy as a standalone CLI tool, install it globally via npm. For Debian or Ubuntu users, ensure
nodejs-legacyis installed first.Installation:
sudo apt-get install nodejs-legacy npm install -g anyproxyRunning:
- Start the proxy on the default port (8001):
anyproxy - Start on a specific port:
anyproxy --port 1080
Accessing the Web Interface: Once running, visit
http://127.0.0.1:8002in your browser to view request information.# Installation sudo apt-get install nodejs-legacy npm install -g anyproxy # Start anyproxy # Other commands anyproxy --port 1080- Start the proxy on the default port (8001):
Install AnyProxy via npm
masterTo install AnyProxy globally, use npm. Note that Debian and Ubuntu users may need to install
nodejs-legacyfirst.sudo apt-get install nodejs-legacy npm install -g anyproxynpm install -g anyproxyConfigure Root CA for HTTPS interception
masterTo intercept HTTPS traffic, you must trust the AnyProxy Root CA on your device.
macOS
- Double-click
rootCA.crt. - Add the certificate to your Keychain (Login or System).
- Find the AnyProxy certificate and set it to Always Trust.
Windows
Install the certificate via the Windows Certificate Manager.
iOS
- Click Root CA in the AnyProxy web UI to install.
- Crucial for iOS 10.3+: Go to
Settings > General > About > Certificate Trust Settingsand manually enable full trust for the AnyProxy certificate.
Android
- Download the CA via the AnyProxy web UI (scan the QR code).
- Install via
Settings > Security > Install from storage(or similar path depending on your Android version). - Note: If
.crtis not supported, you can choose a different certificate type in AnyProxy before installing.
- Double-click
Handle HTTPS requests in Rule modules
masterIf your Rule module cannot intercept HTTPS requests, you must enable HTTPS interception using one of the following methods:
- Via CLI: Use the
--interceptflag when launching AnyProxy. - Via npm module: Set
forceProxyHttps: truein your configuration options. - Via Rule module: Implement a
beforeDealHttpsRequestfunction within your rule file to manually determine which requests to intercept.
- Via CLI: Use the
Proxy HTTPS and WebSocket traffic
masterAnyProxy supports intercepting and proxying both HTTPS and WebSocket traffic. Detailed guides are available for configuring these specific protocols.Trust the AnyProxy CA certificate on various platforms
masterTo intercept HTTPS traffic, you must trust the AnyProxy Root CA certificate on your device.
iOS
- Click Root CA in the AnyProxy Web UI and scan the QR code to install.
- For iOS >= 10.3: Go to Settings -> General -> About This Device -> Certificate Trust Settings and enable the switch for the AnyProxy certificate.
Android
- Scan the QR code from the Web UI to download the certificate.
- Installation varies by device:
- Direct install: Tap the downloaded file.
- Manual: Settings -> Security -> Encryption & Credentials -> Install from storage (or similar path depending on Android version).
- Note: Some devices (like OPPO) may require
.cerfiles; AnyProxy provides multiple formats.
macOS
- Double-click
rootCA.crt. - Add it to the login or system keychain.
- Find the certificate in Keychain Access and set it to Always Trust.
Windows
Follow the system prompts to install the certificate into the Trusted Root Certification Authorities store.
Ignore HTTPS certificate errors (Global)
masterIf you encounter 'The connection is not private' errors due to self-signed certificates, you can ignore SSL certificate authentication errors globally using one of these methods. Warning: This applies to all websites visited while AnyProxy is active.
Via CLI: Use the
--ignore-unauthorized-sslflag.Via Node.js code: Pass
dangerouslyIgnoreUnauthorized: truein the options object when initializingAnyProxy.ProxyCore.// Via Node.js code const options = { // ... other options dangerouslyIgnoreUnauthorized: true }; const anyproxyIns = new AnyProxy.ProxyCore(options); anyproxyIns.start();Create a custom Rule module
masterYou can extend AnyProxy by writing a JavaScript rule module to intercept and modify requests or responses.
Rule Lifecycle and Flow
beforeSendRequest(requestDetail): Called when a request is sent. You can modify headers, body, or the target URL. If you return a response object here, the request is short-circuited and the actual server is never contacted.beforeDealHttpsRequest(requestDetail): For HTTPS requests. If this returnstrue, the request is decrypted and processed like a standard HTTP request.beforeSendResponse(requestDetail, responseDetail): Called after receiving a response from the server. You can modify the status code, headers, or the response body.
Example: Modify a response and add delay
Create a file named
sample.js:module.exports = { summary: 'a rule to hack response', *beforeSendResponse(requestDetail, responseDetail) { if (requestDetail.url === 'http://httpbin.org/user-agent') { const newResponse = responseDetail.response; newResponse.body += '- AnyProxy Hacked!'; return new Promise((resolve, reject) => { setTimeout(() => { // delay resolve({ response: newResponse }); }, 5000); }); } }, };How to run the rule
Run AnyProxy pointing to your rule file:
anyproxy --rule sample.jsYou can also reference rules via:
- Local path:
anyproxy --rule ./rule.js - Online URL:
anyproxy --rule https://sample.com/rule.js - NPM package:
anyproxy --rule myRulePkg(if installed globally) oranyproxy --rule ./path/to/pkg/
// file: sample.js module.exports = { summary: 'a rule to hack response', *beforeSendResponse(requestDetail, responseDetail) { if (requestDetail.url === 'http://httpbin.org/user-agent') { const newResponse = responseDetail.response; newResponse.body += '- AnyProxy Hacked!'; return new Promise((resolve, reject) => { setTimeout(() => { // delay resolve({ response: newResponse }); }, 5000); }); } }, };Launch AnyProxy via CLI
masterYou can start AnyProxy from the command line. By default, it runs on port 8001, and the web interface is available at port 8002.
To specify a custom port, use the
--portflag.To intercept all HTTPS traffic, use the
--interceptflag (requires CA certificate setup).To intercept WebSocket traffic, use the
--ws-interceptflag.anyproxy anyproxy --port 1080 anyproxy --intercept anyproxy --ws-intercept