learn wireshark

Zero to Hero with Wireshark Display Filter Macros


Check out these great references as well: 

 Our custom profiles repository for Wireshark
 Our Udemy course on Wireshark 
 Our Udemy course on Wireless Packet capture

If you are a Wireshark power user, you know the importance of complex display filters to narrow searches for very particular items.  The challenge can be to recall these filters, end edit them in different analysis cases.  Also, if you want to be able to replace addresses, the possibility of typos and time being lost becomes evident, if not frustrating.

Luckily Wireshark has a very little known capability called display filter macros.  In the entire Wireshark web site, there may be 10 total sentences dedicated to the capability.  Ok it might be 12 sentences.

Here is how it works.  You have to define the macro first, using variables, that when you execute the macro, the variables are then inserted.  Let’s start with a really simple one that you probably would never actually define because, like most of us, you know the filter by heart:  the ip.addr == a.b.c.d filter.

 

Creating Your First Simple Display FIlter Macro

Before we get started: Display filter macros are stored by profile, so we are going to create one in our Default Profile.

To define the macro select Analyze> Display Filter Macros and you will get the following pop-up:

You can see we do not have any!

As with any of the Wireshark lists, click the “+” sign to add a macro.

Enter the name of the macro (no spaces allowed):  I used IPA

Then enter the macro syntax: ip.addr == $1

The $1 is essentially a variable, and you can have multiple variables in complex macros.

Click OK.

Now in a capture, type the following into the display filter: ${IPA:192.168.1.1} and apply the filter (replace the 192.168.1.1 address with anything you want):

I am using the our Comprehensive Pcap file – if you want it you can grab it here.

OK perfect, – now we know now this works, let’s take it a step further (and more useful).

Taking it to the Next Level

Let’s say we wanted to find a particular IP address pair.  One option would be the Conversation Filter.  Or we could create a macro based on a more complex filter syntax.  We will have two variables: $1 and $2 for the two addresses.

The normal display filter would look like this: ip.addr==17.248.185.174 && ip.addr==192.168.1.114

So let’s create a macro we will call IPAP (for IP Address Pair) and use the syntax replacing the addresses with $1 and $2:

Now if I want to find a set of packets between an IP address pair, I simply type ${IPAP:194.247.5.7;85.25.246.38} in the display filter:

The key here is that a semicolon separates the variables.

Remember – different Profiles can have different profile specific macros.

Using Macros inside Display Filter Expressions

You can also use Display Filter Macros inside expressions.

For example if you defined a macro to be called ‘priv24’ and then defined the macro syntax to be ‘192.168.1.0/24’, you could in a display filter enter something like:

ip.addr == ${priv24}

The result would be the same as typing ‘ip.addr == 192.168.1.0/24’

If you are a network admistrator, you can imagine how using this could save a lot of time typing addresses.

Interesting Macro Syntax Variations

Another thing you can do is use the Wireshark Display Macro syntax to perform quick filters on your trace.  For example:

  • ip.addr == ${ip.src} will find all packets that have the same source IP address as the selected packet
  • tcp.stream == ${tcp.stream} will find all packets in the current selected packet tcp stream (assumes you have a valid tcp packet selected)

These are not technically macros, so you would not save them as such, instead you would simply save these as Display filters in your pick list/bookmark list.

Useful Macros 

So let’s create a cheat sheet of macros you may find useful and you can add them to your favorite profiles:

Macro NamePurposeMacro Filter SyntaxDisplay Filter Syntax to call the Macro
n/aFind all IP addresses that match the Source IP of current selected packetip.addr == ${ip.src}n/a
n/aFind all IP addresses that match the Destination IP of current selected packetip.addr == ${ip.dst}n/a
n/aFind all packets in the TCP stream of the current selected packettcp.stream == ${tcp.stream}n/a
n/aFind all DNS packets belonging to the selected packet (usually query response pairs)dns.id == ${dsn.id}n/a
TCPConvFilter a particular TCP conversation knowing Source, destination, and TCP Port((ip.src == $1 and ip.dst == $2 and tcp.srcport == $3 and tcp.dstport == $4) or (ip.src == $2 and ip.dst == $1 and tcp.srcport == $4 and tcp.dstport == $3))${TCPConv:192.168.1.10;192.168.1.13;8080}
ARPrqFind all ARP Requestsarp.opcode == 0x0001${ARPrq}
ARPrpFind all ARP Responsesarp.opcode == 0x0002$(ARPrp}
DNSrqFind all DNS Requestsdns.flags.response == 0${DNSrq}
DNSrpFind all DNS Responsesdns.flags.response == 1${DNSrp}
DNSerFind all DNS Errorsdns.flags.rcode != 0${DNSer}
ICMPrqFind all ICMPv4 Requestsicmp.type == 8${ICMPrq}
ICMPrpFind all ICMPv4 Responsesicmp.type == 0${ICMPrp}
ICMPredFind all ICMPv4 redirects except IP Address w.x.y.zicmp.type == 5 and ip.src != $1${ICMPred:w.x.y.z}
SSLhsFind all SSL Handshake packetsssl.record.content_type==22${SSLhs}
NoBeaconsWireless: remove all Beacon Frameswlan.fc.subtype != 8${NoBeacons}
JustBeaconsWireless: show only Beacon Frameswlan.fc.subtype == 8${JustBeacons}
SSIDnWireless: show only management frames with SSID x where x is the SSID termwlan_mgt.ssid == \x22$1\x22${SSIDn:x}
ProbesWireless: show only the probe frameswlan.fc.subtype==4 or wlan.fc.subtype==5${Probes}
plcmallIP Telephony – find all PLCM packetseth.addr[0:3] == 00-04-f2 || bootp.hw.mac_addr[0:3] == 00-04-f2${plcmall}
plcmIP Telephony – find PLCM for a particular MAC 12-34-56eth.addr == 00-04-f2-$1 || bootp.hw.mac_addr == 00-04-f2-$1${plcm:12-34-56}
issallIP Telephony – find all ISS packetseth.addr[0:3] == 00-26-fd || bootp.hw.mac_addr[0:3] == 00-26-fd${issall}
issIP Telephony – find ISS packets for a particular MAC 12-34-56eth.addr == 0026-fdf0-$1 || bootp.hw.mac_addr == 0026-fdf0-$1${iss:1234}

 

Be sure to check back here often as we will keep adding to the list.  Any you would add?


Comments are welcomed below from registered users.  You can also leave comments at our Discord server

If you would like to see more content and articles like this, please support us by clicking the patron link where you will receive free bonus access to courses and more, or simply buying us a cup of coffee!

Leave a Comment

Scroll to Top