# Write a signature to match a single bit (drop for TCP SYN)

**URL:** <https://forum.suricata.io/t/write-a-signature-to-match-a-single-bit-drop-for-tcp-syn/2035>\
**Category:** Rules\
**Created:** [December 20, 2021, 8:54am UTC](https://forum.suricata.io/t/write-a-signature-to-match-a-single-bit-drop-for-tcp-syn/2035 "2021-12-20T08:54:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Graham\_Bartlett](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.suricata.io/graham_bartlett/32/1117_2.png) [@Graham\_Bartlett](https://forum.suricata.io/u/Graham_Bartlett)\
**Post date:** [December 20, 2021, 8:54am UTC](https://forum.suricata.io/t/write-a-signature-to-match-a-single-bit-drop-for-tcp-syn/2035/1 "2021-12-20T08:54:13Z")

</div>

Hi

I’m trying to write a signature that will check for any TCP SYN. So I have checked the contents of 0x02, which will then match any SYNs, but I have found that some stacks will include ECN or URGENT flags, in which case I would need to match on 0x02 or 0xc2 or 0x22. What’s the best way to write this ? I did look at bitwise, but that didn’t seem to meet my needs.

many thanks

(TCP flags below)

Flags: 0x002 (SYN)  
000. … … = Reserved: Not set  
…0 … … = Nonce: Not set  
… 0… … = Congestion Window Reduced (CWR): Not set  
… .0… … = ECN-Echo: Not set  
… …0. … = Urgent: Not set  
… …0 … = Acknowledgment: Not set  
… … 0… = Push: Not set  
… … .0… = Reset: Not set  
… … …1. = Syn: Set  
… … …0 = Fin: Not set  
[TCP Flags: ··········S·]

---

<div class="post-metadata">

**Author:** ![syoc](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@syoc](https://forum.suricata.io/u/syoc)\
**Post date:** [December 21, 2021, 1:09pm UTC](https://forum.suricata.io/t/write-a-signature-to-match-a-single-bit-drop-for-tcp-syn/2035/2 "2021-12-21T13:09:12Z")

</div>

Hi.

A combination of bitwise and with byte\_test and the tcp.hdr buffer [6.7. Payload Keywords — Suricata 7.0.0-dev documentation](https://suricata.readthedocs.io/en/latest/rules/payload-keywords.html#byte-test) and [6.3. IP Keywords — Suricata 7.0.0-dev documentation](https://suricata.readthedocs.io/en/latest/rules/header-keywords.html#tcp-hdr) sounds like it could do the trick.

---

<div class="post-metadata">

**Author:** ![vjulien](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.suricata.io/vjulien/32/4_2.png) [@vjulien](https://forum.suricata.io/u/vjulien)\
**Post date:** [December 21, 2021, 1:28pm UTC](https://forum.suricata.io/t/write-a-signature-to-match-a-single-bit-drop-for-tcp-syn/2035/3 "2021-12-21T13:28:46Z")

</div>

I think the `flags` keyword can do what you wanted. Example from ET open:  
`flags: S,12;` which is equal to `flags: S,EC;`. This should match if only the SYN set, or SYN+ECN or SYN+CWR or SYN+both.

```auto
alert tcp $HOME_NET any -> $EXTERNAL_NET 3389 (msg:"ET SCAN Behavioral Unusually fast Terminal Server Traffic Potential Scan or Infection (Outbound)"; flow:to_server; flags: S,12; threshold: type both, track by_src, count 20, seconds 360; reference:url,threatpost.com/en_us/blogs/new-worm-morto-using-rdp-infect-windows-pcs-082811; classtype:misc-activity; sid:2013479; rev:5; metadata:created_at 2011_08_29, former_category SCAN, updated_at 2017_05_11;)

```

Looks like docs are missing.

---

<div class="post-metadata">

**Author:** ![syoc](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@syoc](https://forum.suricata.io/u/syoc)\
**Post date:** [December 21, 2021, 1:29pm UTC](https://forum.suricata.io/t/write-a-signature-to-match-a-single-bit-drop-for-tcp-syn/2035/4 "2021-12-21T13:29:12Z")

</div>

Arrggh! I was seconds away 😛

---

<div class="post-metadata">

**Author:** ![vjulien](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.suricata.io/vjulien/32/4_2.png) [@vjulien](https://forum.suricata.io/u/vjulien)\
**Post date:** [December 21, 2021, 1:30pm UTC](https://forum.suricata.io/t/write-a-signature-to-match-a-single-bit-drop-for-tcp-syn/2035/5 "2021-12-21T13:30:01Z")

</div>

Ticket for the missing keyword [Documentation #3748: Add documentation for flags keyword - Suricata - Open Information Security Foundation](https://redmine.openinfosecfoundation.org/issues/3748)

---

<div class="post-metadata">

**Author:** ![Graham\_Bartlett](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.suricata.io/graham_bartlett/32/1117_2.png) [@Graham\_Bartlett](https://forum.suricata.io/u/Graham_Bartlett)\
**Post date:** [December 23, 2021, 9:51pm UTC](https://forum.suricata.io/t/write-a-signature-to-match-a-single-bit-drop-for-tcp-syn/2035/6 "2021-12-23T21:51:20Z")

</div>

Hi

Thank you - I really appreciate the help. Merry xmas.

I was confused as to what the ‘12’ was…

After reading the following I now know.

[https://paginas.fe.up.pt/~mgi98020/pgr/writing\_snort\_rules.htm#flags](https://paginas.fe.up.pt/~mgi98020/pgr/writing_snort_rules.htm#flags)

For other looking at this, the S is mandatory and whatever after the ‘,’ is optional.

cheers
