Hi,
I am looking for some advice on how to calculate a variable offset for a suricata rule. The target protocol is BACnet/IP. I have included a chart that shows the UDP payload of a BACnet/IP message.
My offset calculation needs to solve for the start of the ADPU, which is highlighted in yellow.
The issue is that there are two variable items in the payload prior to the ADPU start (destination and source specifiers (highlighted in red and blue). Thankfully these items have a deterministic size.
There are 2 bits in the Control octet that flag whether the destination (b’00100000) and source (b’00001000) fields are present at all. The first step would be to check those bits. If the control bit is 0, the fields are left out entirely. If the bit is 1 for either dest or src, then we know the following lengths:
The blue items (dest) would be 4 + DLEN value = total length
The red items (src) would be 3 + SLEN value = total length
The minimum offset is 5 bytes if both src and dest identifiers are absent (Version=1, Control=1,Type=1,Vendor=2)
Following the logic above, my pseudo code for my calculation would be:
offset = 5
destflag = controlbyte (bitwise &) b’00001000
srcflag = controlbyte (bitwise &) b’00100000
if destflag:
offset += 4 + DLEN
if srcflag:
offset += 3 + SLEN
I need help converting this pseudocode into a rule with the byte* keywords.
Reference Image
