Edit on GitHub

Intercept Requests

A powerful feature of mitmproxy is the interception of requests. An intercepted request is paused so that the user can modify (or discard) the request before sending it to the server. mitmproxy’s set intercept command configures interceptions. The command is bound to shortcut i by default.

Intercepting all requests is usually not desired as it constantly interrupts your browsing. Thus, mitmproxy expects a flow filter expression as the first argument to set intercept to selectively intercept requests. In the tutorial below we use the flow filter ~u <regex> that filters flows by matching the regular expressing on the URL of the request.

Video Content

  1. Welcome to the mitmproxy tutorial. In this lesson we cover the interception of requests.
00:00
  1. We first need to configure mitmproxy to intercept requests.
00:16
  1. Press i to prepopulate mitmproxy’s command prompt with set intercept ''.
00:21
  1. We use the flow filter expression ~u <regex> to only intercept specific URLs.
00:30
  1. Additionally, we use the filter ~q to only intercept requests, but not responses.
00:37
  1. We combine both flow filters using &.
00:44
  1. Enter ~u /Dunedin & ~q between the quotes of the set intercept command and press ENTER.
00:47
  1. The bottom bar shows that the interception has been configured.
01:02
  1. Let’s generate a request using curl in a separate terminal.
01:08
  1. You see a new line in in the list of flows.
01:36
  1. The new flow is displayed in red to indicate that it has been intercepted.
01:40
  1. Put the focus (>>) on the intercepted flow. This is already the case in our example.
01:46
  1. Press a to resume this flow without making any changes.
01:53
  1. Submit another request and focus its flow.
02:01
  1. Press X to kill this flow, i.e., discard it without forwarding it to its final destination wttr.in.
02:08
  1. In the next lesson you will learn to modify intercepted flows.
02:21

In the next lesson, you will learn to modify intercepted flows before sending them to the server.