title: Snort Config: PCRE Matching across TCP Packets
body: <p>I am working with my Security Onion and at the moment all the longer PCRE is not working, because the rules and the regex is not applied to the TCP stream but only to single packets. </p>
  
  <p>My Snort.conf should have everything enabled:</p>
  
  <pre><code>    # Target-based IP defragmentation.  For more inforation, see README.frag3
  preprocessor frag3_global: max_frags 65536
  preprocessor frag3_engine: policy windows detect_anomalies overlap_limit 10 min_fragment_length 100 timeout 180
  
  # Target-Based stateful inspection/stream reassembly.  For more inforation, see README.stream5
  preprocessor stream5_global: track_tcp yes, \
     track_udp yes, \
     track_icmp no, \
     max_tcp 262144, \
     max_udp 131072, \
     max_active_responses 2, \
     min_response_seconds 5
  preprocessor stream5_tcp: log_asymmetric_traffic no, policy windows, \
     detect_anomalies, require_3whs 180, \
     overlap_limit 10, small_segments 3 bytes 150, timeout 180, \
      ports client 21 22 23 25 42 53 79 109 110 111 113 119 135 136 137 139 143 \
          161 445 513 514 587 593 691 1433 1521 1741 2100 3306 6070 6665 6666 6667 6668 6669 \
          7000 8181 32770 32771 32772 32773 32774 32775 32776 32777 32778 32779, \
      ports both 80 81 311 383 443 465 563 591 593 636 901 989 992 993 994 995 1220 1414 1830 2301 2381 2809 3037 3128 3702 4343 4848 5250 6988 7907 7000 7001 7144 7145 7510 7802 7777 7779 \
          7801 7900 7901 7902 7903 7904 7905 7906 7908 7909 7910 7911 7912 7913 7914 7915 7916 \
          7917 7918 7919 7920 8000 8008 8014 8028 8080 8085 8088 8090 8118 8123 8180 8243 8280 8300 8800 8888 8899 9000 9060 9080 9090 9091 9443 9999 11371 34443 34444 41080 50002 55555
  preprocessor stream5_udp: timeout 180
  </code></pre>
  
  <p>Now I got a node.js server up with a simple XML file (I made it a little bit shorter): </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;saml2p:Response Destination="http://localhost:8080/sp/saml/index.html"
    ID="_28940080d39ea1191d9910414147f372"
    InResponseTo="_15b217492a05e534df8539c7a84014cd"
    IssueInstant="2018-07-24T16:04:13.830Z" Version="2.0"
    xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:SAML:2.0:protocol"&gt;
    &lt;saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"&gt;eLearning SAML SSO IdP&lt;/saml2:Issuer&gt;
    &lt;saml2p:Status&gt;
      &lt;saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/&gt;
    &lt;/saml2p:Status&gt;
    &lt;saml2:Assertion ID="_evil_assertion_ID"
      IssueInstant="2018-07-24T16:04:13.831Z" Version="2.0"
      xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:SAML:2.0:protocol"&gt;
      &lt;saml2:Issuer&gt;eLearning SAML SSO IdP&lt;/saml2:Issuer&gt;
      &lt;saml2:Subject&gt;
        &lt;saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"&gt;xmluser&lt;/saml2:NameID&gt;
      [..........................]
        &lt;/saml2:AuthnContext&gt;
      &lt;/saml2:AuthnStatement&gt;
    &lt;/saml2:Assertion&gt;
  &lt;/saml2p:Response&gt;
  </code></pre>
  
  <p>A rule matching only the content:"saml2p:response" or a small regex like pcre:"/saml2p:Response/smi" is working without problem, but a rule with a longer regex is not matching the pattern.</p>
  
  <p>I made my rule as generic as possible:</p>
  
  <p>alert tcp any any -> any any (msg:"ET WEB_SERVER SAML XSW3 Attack, Possible Signature Wrapping Attack v15"; pcre:"/saml2p:Response.*?/saml2p:Response/smi"; reference:url,<a href="https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf" rel="nofollow noreferrer">https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf</a>;  classtype:web-application-attack; sid:200000120; rev:1;)</p>
  
  <p>edit: I have also tried this rule with all versions of flow:from_server,established; (to_server, from_client, to_client). None of them is working for me. But when I cut down the xml to a size which fits in one packet, all rules are firing!</p>
  
  <p>The Regex pcre:"/saml2p:Response.*?/saml2p:Response/smi" should match everything from the first response tag to the closing response tag, but whenever it is splitted into different TCP Packets the regex is not matching. </p>
  
  <p>Do i miss anything?</p>
  
  <p>Thanks for your help! </p>