SniffMaster Interceptor User Guide
SniffMaster allows you to intercept and modify network requests and responses, including their full content, such as request URL, headers, and body. By writing JavaScript, you can make modifications, replacements, and set rules for requests.
Open Interceptor Log
On the right side of the proxy packet capture interface, there is an interceptor icon resembling a plug. Double-click the interceptor icon to open the interceptor log interface, where you can view the status and, if the interceptor is enabled, see the interception logs.
Open Interceptor Editor
In the interceptor log interface, click Edit Interceptor to access the interceptor editing functionality.
Edit Interceptor Code
The interceptor includes a default code example demonstrating the basic framework. You need to modify this according to your specific needs. The interceptor code is written in JavaScript, and the names of the three functions and their parameters cannot be changed; only the internal logic of the functions can be modified.
handleRequest
- Request interception, where the logic for modifying the request is written.handleResponse
- Response interception, where the logic for modifying the response data is written.filterUrl
- Intercept URL rules, listing the URLs to be intercepted (supports wildcards).
The interceptor must at least contain the following code, which is an empty interceptor that does nothing.
1function handleRequest(request) {
2 return request;
3}
4
5function handleResponse(response) {
6 return response;
7}
8
9function filterUrl() {
10 return [];
11}
A simple interceptor example is shown below. This interceptor intercepts Google requests and logs messages when sending or receiving data.
function handleRequest(request) {
console.log("Preparing to send request to " + request.URL);
return request;
}
function handleResponse(response) {
console.log("Received response from " + response.URL);
return response;
}
function filterUrl() {
return ["https://www.google.com/*"];
}
Interceptor - request
Object
The request
object contains all the data of the request about to be sent to the server. You can modify this data to alter what is sent to the server. The request
object includes the following properties:
URL
- The request URL. If you want to redirect to another address, simply modify this value.Header
- The request headers, represented as a key-value object.Body
- The request body data to be sent to the server.IsBase64Body
- Indicates whether the body is base64-encoded before being sent to the interceptor. If the data is binary, SniffMaster encodes it as a base64 string and assigns it to theBody
.IsBase64Body
is set totrue
. If the body is plain text,Body
contains the original string andIsBase64Body
is set tofalse
. To modify the base64-encoded body, ensure the body data andIsBase64Body
are correctly matched.
Interceptor - response
Object
The response
object contains all the information returned by the server. You can modify this to alter the data sent to the final target program. The response
object has similar properties to the request
object, with the addition of the StatusCode
field:
StatusCode
- The response status code.URL
- The response URL. If you want to redirect to another address, modify this value.Header
- The response headers, represented as a key-value object.Body
- The data returned by the server, which will be sent to the software.IsBase64Body
- Indicates whether the body is base64-encoded before being sent to the interceptor. If the returned data is binary, SniffMaster encodes it as a base64 string and assigns it to theBody
.IsBase64Body
is set totrue
. If the response is plain text, theBody
contains the original string andIsBase64Body
is set tofalse
. Ensure that the body data andIsBase64Body
are properly matched when modifying a base64-encoded body.