Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 38 ยท Setup and Proxy

Proxy Match and Replace Rules

Use Burp's match and replace rules to edit requests and responses automatically, for example swapping a user agent or a header, and learn the risks of regex rules.

Editing one message by hand in the intercept panel is fine for a single experiment. When you need the same change on every message, such as sending a different User-Agent, adding a test header, or neutralising a client-side check, you can let Burp do it with match and replace rules.

A rule says: "in this part of the message, find this text (or regular expression) and replace it with that text". Rules run automatically as traffic passes through the proxy, both ways, without stopping anything.

Where rules live

Settings > Tools > Proxy > Match and replace rules (older versions: Proxy > Options). Each rule has:

Field Meaning
Type Which part of the message to look at (see below)
Match Text or regular expression to find
Replace Text that takes its place
Comment Your note on why the rule exists
Regex match Treat Match as a regular expression
Enabled On/off switch (turn off rules you are not using!)

Types you will use

  • Request header: matches against the headers of requests.
  • Request body: matches the body of requests.
  • Response header and Response body: the same for responses.
  • Request param name / value: edit a named parameter.
  • Request first line: the method, path and version.

An empty Match with type "Request header" adds a new header on every request; an empty Replace deletes the matched text.

Practical examples

These are typical, safe examples for your own lab.

1. Mark your test traffic. Add a header so the lab's server logs identify your requests:

  • Type: Request header; Match: (empty); Replace: X-Tester: lab-session-1.

This is courteous (and in a real engagement often required): it lets the client's team tell your traffic from an attack.

2. Simulate a different browser. Replace the user agent when testing how a site treats mobile clients:

  • Type: Request header; Match: ^User-Agent.*$ with Regex on; Replace: User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X).

3. Make a hidden element visible. Many pages hide fields with the hidden attribute or by disabling controls. A response rule can reveal them so you can see what the page really sends:

  • Type: Response body; Match: type="hidden"; Replace: type="text".

4. Disable a client-side check. Replace a form's disabled attribute or a script's validation function name in a response, to test whether the server enforces the same limit:

  • Type: Response body; Match: maxlength="5"; Replace: (empty).

5. Downgrade a header for testing. Remove If-None-Match so you always get fresh responses, not 304 Not Modified:

  • Type: Request header; Match: ^If-None-Match.*$; Regex on; Replace: (empty).

Regular expression basics

Match and replace regexes use Java syntax, close to what you know from most languages.

Pattern Meaning
. any one character
.* any run of characters
^ / $ start / end of line
\d+ one or more digits
`(a b)`
[A-Za-z0-9]+ letters and digits
(...) and $1 capture a group and reuse it in the replacement

Example: to bump every qty=1 to qty=2 in request bodies, Match qty=1\b, Replace qty=2.

Risks and good habits

  • Broad rules change things you did not intend. 1 replaced by 2 rewrites every digit one. Make matches specific and anchored.
  • Rules apply to everything through the proxy, including out-of-scope sites. Keep the rule narrow, or turn it off when browsing elsewhere.
  • Forgotten rules cause mystery bugs. A rule disabling maxlength will confuse you weeks later. Always write a comment and disable rules after use.
  • Rules change the response your browser sees, not what the server did. Do not report "the field was editable" as a flaw if only your rule made it so.
  • Do not use rules to bypass protections on systems you are not authorised to test.

Try it: a match and replace engine

A stand-in rule engine: a list of rules with a type, a regex and a replacement, applied to a request and a response. This is the exact logic Burp performs, in small.

Python Stand-in: a match and replace engine

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Try it: dry-run a rule before enabling it

A stand-in that previews how many matches a rule would change, which is a sensible check before turning on a broad regex.

Python Stand-in: preview a rule's impact

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The broad rule rewrote qty=10 into qty=20 and page=11 into page=22. The specific rule only touched the value you meant. This is the whole lesson of rule writing: narrow, anchored, previewed.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is match and replace best for?

    Rules edit requests or responses as they pass through the proxy, saving you from repeating a manual change.
  2. 2. A rule replaces the text 1 with 2 in request bodies. What goes wrong?

    Broad matches modify unrelated text. Anchor and narrow patterns, and test them before enabling.
  3. 3. Why add an X-Tester header to your lab traffic?

    Identifying your traffic is courteous and, in real engagements, often part of the rules of engagement.
  4. 4. You use a response rule to remove a maxlength limit. What can you conclude if the form now accepts long text?

    The rule altered what your browser enforces. A server-side finding requires submitting the value and observing the server's reaction.

Summary

  • Match and replace rules edit requests and responses automatically as they pass through the proxy.
  • Each rule has a type (header, body, parameter, first line), a match, a replacement, and a comment.
  • Good uses: mark traffic, change the user agent, reveal hidden fields, drop caching headers.
  • Keep rules specific, anchored and commented; disable them when finished.
  • A rule changes what your browser sees, not what the server does; confirm real flaws by sending the request.

Next: Target scope