1% $Id$ 2% 3% BUILDING HTML VERSION: 4% latex2html -info 0 -local_icons -show_section_numbers -link +2 -split +2 -noaddress snort_manual.tex 5% 6% BUILDING PDF VERSION: 7% pdflatex snort_manual.tex 8 9\documentclass[english]{report} 10%\usepackage[T1]{fontenc} 11\usepackage[latin1]{inputenc} 12\usepackage{geometry} 13\usepackage{longtable} 14\geometry{verbose,letterpaper,tmargin=1in,bmargin=.5in,lmargin=1in,rmargin=1in} 15\usepackage{url} 16%\IfFileExists{url.sty}{\usepackage{url}} 17% {\newcommand{\url}{\texttt}} 18 19\usepackage{html} 20 21% \makeatletter 22 23\newcounter{slistnum} 24\newcounter{subslistnum} 25\newcounter{subsublistnum} 26 27\newenvironment{slist} 28{ \begin{list}{ {\bf \arabic{slistnum}.} }{\usecounter{slistnum} } } 29{ \end{list} } 30 31\newenvironment{subslist} 32{ \begin{list} { {\bf \arabic{slistnum}-\Alph{subslistnum}. } } 33 {\usecounter{subslistnum} } } 34{ \end{list} } 35 36\newenvironment{subsubslist} { 37 \begin{list}{ 38 {\bf \arabic{slistnum}-\arabic{subslistnum}-\arabic{subsublistnum}. } 39 }{ 40 \usecounter{subsubslistnum} 41 } 42}{ 43 \end{list} 44} 45 46%\begin{latexonly} 47\newsavebox{\savepar} 48\newenvironment{note}{ 49\samepage 50 \vspace{10pt}{\textsf{ 51 {\hspace{7pt}\Huge{$\triangle$\hspace{-12.5pt}{\Large{$^!$}}}}\hspace{5pt} 52 {\Large{NOTE}} 53 } 54 } 55 \begin{center} 56 \par\vspace{-17pt} 57 58 \begin{lrbox}{\savepar} 59 \begin{minipage}[r]{6in} 60} 61{ 62 \end{minipage} 63 \end{lrbox} 64 \fbox{ 65 \usebox{ 66 \savepar 67 } 68 } 69 \par\vskip10pt 70 \end{center} 71} 72%\end{latexonly} 73 74\begin{htmlonly} 75\newenvironment{note}{ 76 \begin{rawhtml} 77 <p><table border="1"><tr><td><b> 78 Note: </b> 79 \end{rawhtml} 80}{ 81 \begin{rawhtml} 82 </b></td></tr></table></p> 83 \end{rawhtml} 84} 85\end{htmlonly} 86 87\usepackage{babel} 88 89% \makeatother 90 91\addtolength{\parindent}{-5mm} 92\addtolength{\parskip}{2mm} 93 94%\renewcommand\floatpagefraction{.9} 95%\renewcommand\topfraction{.9} 96%\renewcommand\bottomfraction{.9} 97%\renewcommand\textfraction{.1} 98%\setcounter{totalnumber}{50} 99%\setcounter{topnumber}{50} 100%\setcounter{bottomnumber}{50} 101 102\begin{document} 103 104\title{SNORT\textsuperscript{\textregistered} Users Manual\\2.9.18} 105 106\author{The Snort Project} 107 108\maketitle 109 110\newpage 111 112Copyright \copyright 1998-2003 Martin Roesch 113 114Copyright \copyright 2001-2003 Chris Green 115 116Copyright \copyright 2003-2013 Sourcefire, Inc. 117 118Copyright \copyright 2014-2021 Cisco and/or its affiliates. All rights reserved. 119 120\tableofcontents{} 121 122\chapter{Snort Overview} 123 124This manual is based on \emph{Writing Snort Rules} by Martin Roesch and further 125work from Chris Green $<$cmg@snort.org$>$. It was then maintained by Brian 126Caswell $<$bmc@snort.org$>$ and now is maintained by the Snort Team. If you 127have a better way to say something or find that something in the documentation 128is outdated, drop us a line and we will update it. If you would like to submit 129patches for this document, you can find the latest version of the documentation 130in \LaTeX\ format in the most recent source tarball under 131\verb!/doc/snort_manual.tex!. Small documentation updates are the easiest way 132to help out the Snort Project. 133 134\section{Getting Started} 135 136Snort really isn't very hard to use, but there are a lot of command line 137options to play with, and it's not always obvious which ones go together well. 138This file aims to make using Snort easier for new users. 139 140Before we proceed, there are a few basic concepts you should understand about 141Snort. Snort can be configured to run in three modes: 142 143\begin{itemize} 144 145\item {\em Sniffer mode,} which simply reads the packets off of the network and 146displays them for you in a continuous stream on the console (screen). 147 148\item {\em Packet Logger mode,} which logs the packets to disk. 149 150\item {\em Network Intrusion Detection System (NIDS) mode,} which performs 151detection and analysis on network traffic. This is the most complex and 152configurable mode. 153 154\end{itemize} 155 156\section{Sniffer Mode} 157 158First, let's start with the basics. If you just want to print out the TCP/IP 159packet headers to the screen (i.e. sniffer mode), try this: 160 161\begin{verbatim} 162 ./snort -v 163\end{verbatim} 164 165This command will run Snort and just show the IP and TCP/UDP/ICMP headers, 166nothing else. If you want to see the application data in transit, try the 167following: 168 169\begin{verbatim} 170 ./snort -vd 171\end{verbatim} 172 173This instructs Snort to display the packet data as well as the headers. If you 174want an even more descriptive display, showing the data link layer headers, do 175this: 176 177\begin{verbatim} 178 ./snort -vde 179\end{verbatim} 180 181As an aside, notice that the command line switches can be listed separately or 182in a combined form. The last command could also be typed out as: 183 184\begin{verbatim} 185 ./snort -d -v -e 186\end{verbatim} 187 188to produce the same result. 189 190\section{Packet Logger Mode} 191 192OK, all of these commands are pretty cool, but if you want to record the 193packets to the disk, you need to specify a logging directory and Snort will 194automatically know to go into packet logger mode: 195 196\begin{verbatim} 197 ./snort -dev -l ./log 198\end{verbatim} 199 200Of course, this assumes you have a directory named \verb!log! in the current 201directory. If you don't, Snort will exit with an error message. When Snort runs 202in this mode, it collects every packet it sees and places it in a directory 203hierarchy based upon the IP address of one of the hosts in the datagram. 204 205If you just specify a plain -l switch, you may notice that Snort sometimes uses 206the address of the remote computer as the directory in which it places packets 207and sometimes it uses the local host address. In order to log relative to the 208home network, you need to tell Snort which network is the home network: 209 210\begin{verbatim} 211 ./snort -dev -l ./log -h 192.168.1.0/24 212\end{verbatim} 213 214This rule tells Snort that you want to print out the data link and TCP/IP 215headers as well as application data into the directory \verb!./log!, and you 216want to log the packets relative to the 192.168.1.0 class C network. All 217incoming packets will be recorded into subdirectories of the log directory, 218with the directory names being based on the address of the remote 219(non-192.168.1) host. 220 221\begin{note} 222 223Note that if both the source and destination hosts are on the home network, 224they are logged to a directory with a name based on the higher of the two port 225numbers or, in the case of a tie, the source address. 226 227\end{note} 228 229If you're on a high speed network or you want to log the packets into a more 230compact form for later analysis, you should consider logging in binary mode. 231Binary mode logs the packets in tcpdump format to a single binary file in the 232logging directory: 233 234\begin{verbatim} 235 ./snort -l ./log -b 236\end{verbatim} 237 238Note the command line changes here. We don't need to specify a home network any 239longer because binary mode logs everything into a single file, which eliminates 240the need to tell it how to format the output directory structure. Additionally, 241you don't need to run in verbose mode or specify the -d or -e switches because 242in binary mode the entire packet is logged, not just sections of it. All you 243really need to do to place Snort into logger mode is to specify a logging 244directory at the command line using the -l switch---the -b binary logging 245switch merely provides a modifier that tells Snort to log the packets in 246something other than the default output format of plain ASCII text. 247 248Once the packets have been logged to the binary file, you can read the packets 249back out of the file with any sniffer that supports the tcpdump binary format 250(such as tcpdump or Ethereal). Snort can also read the packets back by using 251the -r switch, which puts it into playback mode. Packets from any tcpdump 252formatted file can be processed through Snort in any of its run modes. For 253example, if you wanted to run a binary log file through Snort in sniffer mode 254to dump the packets to the screen, you can try something like this: 255 256\begin{verbatim} 257 ./snort -dv -r packet.log 258\end{verbatim} 259 260You can manipulate the data in the file in a number of ways through Snort's 261packet logging and intrusion detection modes, as well as with the BPF interface 262that's available from the command line. For example, if you only wanted to see 263the ICMP packets from the log file, simply specify a BPF filter at the command 264line and Snort will only see the ICMP packets in the file: 265 266\begin{verbatim} 267 ./snort -dvr packet.log icmp 268\end{verbatim} 269 270For more info on how to use the BPF interface, read the Snort and tcpdump man 271pages. 272 273\section{Network Intrusion Detection System Mode} 274 275To enable Network Intrusion Detection System (NIDS) mode so that you don't 276record every single packet sent down the wire, try this: 277 278\begin{verbatim} 279 ./snort -dev -l ./log -h 192.168.1.0/24 -c snort.conf 280\end{verbatim} 281 282where \texttt{snort.conf} is the name of your snort configuration file. This will 283apply the rules configured in the \verb!snort.conf! file to each packet to decide 284if an action based upon the rule type in the file should be taken. If you don't 285specify an output directory for the program, it will default to 286\verb!/var/log/snort!. 287 288One thing to note about the last command line is that if Snort is going to be 289used in a long term way as an IDS, the -v switch should be left off the command 290line for the sake of speed. The screen is a slow place to write data to, and 291packets can be dropped while writing to the display. 292 293It's also not necessary to record the data link headers for most applications, 294so you can usually omit the -e switch, too. 295 296\begin{verbatim} 297 ./snort -d -h 192.168.1.0/24 -l ./log -c snort.conf 298\end{verbatim} 299 300This will configure Snort to run in its most basic NIDS form, logging packets 301that trigger rules specified in the \texttt{snort.conf} in plain ASCII to disk 302using a hierarchical directory structure (just like packet logger mode). 303 304 305\subsection{NIDS Mode Output Options} 306 307There are a number of ways to configure the output of Snort in NIDS mode. The 308default logging and alerting mechanisms are to log in decoded ASCII format and 309use full alerts. The full alert mechanism prints out the alert message in 310addition to the full packet headers. There are several other alert output modes 311available at the command line, as well as two logging facilities. 312 313Alert modes are somewhat more complex. There are seven alert modes available at 314the command line: full, fast, socket, syslog, console, cmg, and none. Six of 315these modes are accessed with the -A command line switch. These options are: 316 317\begin{center} 318\begin{tabular}{| l | p{5.4in} |} 319 320\hline 321{\bf Option} & {\bf Description}\\ 322\hline 323 324\hline 325{\tt -A fast} & 326 327Fast alert mode. Writes the alert in a simple format with a timestamp, alert 328message, source and destination IPs/ports.\\ 329 330\hline 331{\tt -A full} & 332 333Full alert mode. This is the default alert mode and will be used automatically 334if you do not specify a mode.\\ 335 336\hline 337{\tt -A unsock} & 338 339Sends alerts to a UNIX socket that another program can listen on.\\ 340 341\hline 342{\tt -A none} & 343 344Turns off alerting.\\ 345 346\hline 347{\tt -A console} & 348 349Sends ``fast-style'' alerts to the console (screen).\\ 350 351\hline 352{\tt -A cmg} & 353 354Generates ``cmg style'' alerts.\\ 355 356\hline 357\end{tabular} 358\end{center} 359 360Packets can be logged to their default decoded ASCII format or to a binary log 361file via the -b command line switch. To disable packet logging altogether, use 362the -N command line switch. 363 364For output modes available through the configuration file, see Section 365\ref{output config}. 366 367\begin{note} 368 369Command line logging options override any output options specified in the 370configuration file. This allows debugging of configuration issues quickly via 371the command line. 372 373\end{note} 374 375To send alerts to syslog, use the -s switch. The default facilities for the 376syslog alerting mechanism are LOG\_AUTHPRIV and LOG\_ALERT. If you want to 377configure other facilities for syslog output, use the output plugin directives 378in snort.conf. See Section \ref{alert syslog label} for more details on 379configuring syslog output. 380 381For example, use the following command line to log to default (decoded ASCII) 382facility and send alerts to syslog: 383 384\begin{verbatim} 385 ./snort -c snort.conf -l ./log -h 192.168.1.0/24 -s 386\end{verbatim} 387 388As another example, use the following command line to log to the default 389facility in /var/log/snort and send alerts to a fast alert file: 390 391\begin{verbatim} 392 ./snort -c snort.conf -A fast -h 192.168.1.0/24 393\end{verbatim} 394 395\subsection{Understanding Standard Alert Output} 396 397When Snort generates an alert message, it will usually look like the following: 398 399\begin{verbatim} 400 [**] [116:56:1] (snort_decoder): T/TCP Detected [**] 401\end{verbatim} 402 403The first number is the Generator ID, this tells the user what component of 404Snort generated this alert. For a list of GIDs, please read etc/generators in 405the Snort source. In this case, we know that this event came from the 406``decode'' (116) component of Snort. 407 408The second number is the Snort ID (sometimes referred to as Signature ID). 409For a list of preprocessor SIDs, please see etc/gen-msg.map. Rule-based SIDs 410are written directly into the rules with the \emph{sid} option. In this case, 411\emph{56} represents a T/TCP event. 412 413The third number is the revision ID. This number is primarily used when 414writing signatures, as each rendition of the rule should increment this number 415with the \emph{rev} option. 416 417\subsection{High Performance Configuration} 418 419If you want Snort to go \emph{fast} (like keep up with a 1000 Mbps connection), 420you need to use unified2 logging and a unified2 log reader such as 421\emph{barnyard2}. This allows Snort to log alerts in a binary form as fast as 422possible while another program performs the slow actions, such as writing to a 423database. 424 425If you want a text file that's easily parsed, but still somewhat fast, try 426using binary logging with the ``fast'' output mechanism. 427 428This will log packets in tcpdump format and produce minimal alerts. For 429example: 430 431\begin{verbatim} 432 ./snort -b -A fast -c snort.conf 433\end{verbatim} 434 435\subsection{Changing Alert Order} 436 437The default way in which Snort applies its rules to packets may not be 438appropriate for all installations. The Pass rules are applied first, then the 439Drop rules, then the Alert rules and finally, Log rules are applied. 440 441\begin{note} 442Sometimes an errant pass rule could cause alerts to not show up, in 443which case you can change the default ordering to allow Alert rules 444to be applied before Pass rules. For more information, please refer 445to the \texttt{--alert-before-pass} option. 446\end{note} 447 448Several command line options are available to change the order in 449which rule actions are taken. 450 451\begin{itemize} 452 453\item \texttt{--alert-before-pass} option forces alert rules to take 454affect in favor of a pass rule. 455 456\item \texttt{--treat-drop-as-alert} causes drop and reject rules and 457any associated alerts to be logged as alerts, rather then the normal 458action. This allows use of an inline policy with passive/IDS mode. 459The sdrop rules are not loaded. 460 461\item \texttt{--process-all-events} option causes Snort to process 462every event associated with a packet, while taking the actions based 463on the rules ordering. Without this option (default case), only the 464events for the first action based on rules ordering are processed. 465 466\end{itemize} 467 468\begin{note} 469 470Pass rules are special cases here, in that the event processing is terminated 471when a pass rule is encountered, regardless of the use of 472\texttt{--process-all-events}. 473 474\end{note} 475 476\section{Packet Acquisition} 477 478Snort 2.9 introduces the DAQ, or Data Acquisition library, for packet I/O. The 479DAQ replaces direct calls to libpcap functions with an abstraction layer that 480facilitates operation on a variety of hardware and software interfaces without 481requiring changes to Snort. It is possible to select the DAQ type and mode 482when invoking Snort to perform pcap readback or inline operation, etc. 483 484\begin{note} 485 486Some network cards have features which can affect Snort. Two of these features 487are named "Large Receive Offload" (lro) and "Generic Receive Offload" (gro). 488With these features enabled, the network card performs packet reassembly 489before they're processed by the kernel. 490 491By default, Snort will truncate packets larger than the default snaplen of 1518 492bytes. In addition, LRO and GRO may cause issues with Stream target-based 493reassembly. We recommend that you turn off LRO and GRO. On linux systems, you can run: 494 495\begin{verbatim} 496 $ ethtool -K eth1 gro off 497 $ ethtool -K eth1 lro off 498\end{verbatim} 499 500\end{note} 501 502\subsection{Configuration} 503 504Assuming that you did not disable static modules or change the default DAQ 505type, you can run Snort just as you always did for file readback or sniffing an 506interface. However, you can select and configure the DAQ when Snort is invoked 507as follows: 508 509\begin{verbatim} 510 ./snort \ 511 [--daq <type>] \ 512 [--daq-mode <mode>] \ 513 [--daq-dir <dir>] \ 514 [--daq-var <var>] 515 516 config daq: <type> 517 config daq_dir: <dir> 518 config daq_var: <var> 519 config daq_mode: <mode> 520 521 <type> ::= pcap | afpacket | dump | nfq | ipq | ipfw 522 <mode> ::= read-file | passive | inline 523 <var> ::= arbitrary <name>=<value> passed to DAQ 524 <dir> ::= path where to look for DAQ module so's 525\end{verbatim} 526 527The DAQ type, mode, variable, and directory may be specified either via the 528command line or in the conf file. You may include as many variables and 529directories as needed by repeating the arg / config. DAQ type may be specified 530at most once in the conf and once on the command line; if configured in both 531places, the command line overrides the conf. 532 533 534If the mode is not set explicitly, -Q will force it to inline, and if that 535hasn't been set, -r will force it to read-file, and if that hasn't been set, 536the mode defaults to passive. Also, -Q and --daq-mode inline are allowed, 537since there is no conflict, but -Q and any other DAQ mode will cause a fatal 538error at start-up. 539 540Note that if Snort finds multiple versions of a given library, the most recent 541version is selected. This applies to static and dynamic versions of the same 542library. 543 544\begin{verbatim} 545 ./snort --daq-list[=<dir>] 546 ./snort --daq-dir=<dir> --daq-list 547\end{verbatim} 548 549The above commands search the specified directories for DAQ modules and print 550type, version, and attributes of each. This feature is not available in the 551conf. Snort stops processing after parsing --daq-list so if you want to add 552one or more directories add --daq-dir options before --daq-list on the command 553line. (Since the directory is optional to --daq-list, you must use an = 554without spaces for this option.) 555 556\subsection{pcap} 557 558pcap is the default DAQ. if snort is run w/o any DAQ arguments, it will 559operate as it always did using this module. These are equivalent: 560 561\begin{verbatim} 562 ./snort -i <device> 563 ./snort -r <file> 564 565 ./snort --daq pcap --daq-mode passive -i <device> 566 ./snort --daq pcap --daq-mode read-file -r <file> 567\end{verbatim} 568 569You can specify the buffer size pcap uses with: 570 571\begin{verbatim} 572 ./snort --daq pcap --daq-var buffer_size=<#bytes> 573\end{verbatim} 574 575Note that the pcap DAQ does not count filtered packets. 576 577\subsection{AFPACKET} 578 579afpacket functions similar to the memory mapped pcap DAQ but no external 580library is required: 581 582\begin{verbatim} 583 ./snort --daq afpacket -i <device> 584 [--daq-var buffer_size_mb=<#MB>] 585 [--daq-var debug] 586\end{verbatim} 587 588If you want to run afpacket in inline mode, you must set device to one or more 589interface pairs, where each member of a pair is separated by a single colon and 590each pair is separated by a double colon like this: 591 592\begin{verbatim} 593 eth0:eth1 594\end{verbatim} 595 596or this: 597 598\begin{verbatim} 599 eth0:eth1::eth2:eth3 600\end{verbatim} 601 602By default, the afpacket DAQ allocates 128MB for packet memory. You can change 603this with: 604 605\begin{verbatim} 606 --daq-var buffer_size_mb=<#MB> 607\end{verbatim} 608 609Note that the total allocated is actually higher, here's why. Assuming the 610default packet memory with a snaplen of 1518, the numbers break down like this: 611 612\begin{slist} 613\item 614The frame size is 1518 (snaplen) + the size of the AFPacket header (66 615bytes) = 1584 bytes. 616 617\item 618The number of frames is 128 MB / 1518 = 84733. 619 620\item 621The smallest block size that can fit at least one frame is 4 KB = 4096 bytes 622 @ 2 frames per block. 623 624\item 625As a result, we need 84733 / 2 = 42366 blocks. 626 627\item 628Actual memory allocated is 42366 * 4 KB = 165.5 MB. 629\end{slist} 630 631\subsection{NFQ} 632 633NFQ is the new and improved way to process iptables packets: 634 635\begin{verbatim} 636 ./snort --daq nfq \ 637 [--daq-var device=<dev>] \ 638 [--daq-var proto=<proto>] \ 639 [--daq-var queue=<qid>] \ 640 [--daq-var queue_len=<qlen>] 641 642 <dev> ::= ip | eth0, etc; default is IP injection 643 <proto> ::= ip4 | ip6 | ip*; default is ip4 644 <qid> ::= 0..65535; default is 0 645 <qlen> ::= 0..65535; default is 0 646\end{verbatim} 647 648Notes on iptables can be found in the DAQ distro README. 649 650\subsection{IPQ} 651 652IPQ is the old way to process iptables packets. It replaces the inline version 653available in pre-2.9 versions built with this: 654 655\begin{verbatim} 656 ./configure --enable-inline / -DGIDS 657\end{verbatim} 658 659Start the IPQ DAQ as follows: 660 661\begin{verbatim} 662 ./snort --daq ipq \ 663 [--daq-var device=<dev>] \ 664 [--daq-var proto=<proto>] \ 665 666 <dev> ::= ip | eth0, etc; default is IP injection 667 <proto> ::= ip4 | ip6; default is ip4 668\end{verbatim} 669 670\subsection{IPFW} 671 672IPFW is available for BSD systems. It replaces the inline version available in 673pre-2.9 versions built with this: 674 675\begin{verbatim} 676 ./configure --enable-ipfw / -DGIDS -DIPFW 677\end{verbatim} 678 679This command line argument is no longer supported: 680 681\begin{verbatim} 682 ./snort -J <port#> 683\end{verbatim} 684 685Instead, start Snort like this: 686 687\begin{verbatim} 688 ./snort --daq ipfw [--daq-var port=<port>] 689 690 <port> ::= 1..65535; default is 8000 691\end{verbatim} 692 693* IPFW only supports ip4 traffic. 694 695\subsection{Dump} 696 697The dump DAQ allows you to test the various inline mode features available in 6982.9 Snort like injection and normalization. 699 700\begin{verbatim} 701 ./snort -i <device> --daq dump 702 ./snort -r <pcap> --daq dump 703\end{verbatim} 704 705By default a file named inline-out.pcap will be created containing all packets 706that passed through or were generated by snort. You can optionally specify a 707different name. 708 709\begin{verbatim} 710 ./snort --daq dump --daq-var file=<name> 711\end{verbatim} 712 713dump uses the pcap daq for packet acquisition. It therefore does not count 714filtered packets. 715 716Note that the dump DAQ inline mode is not an actual inline mode. Furthermore, 717you will probably want to have the pcap DAQ acquire in another mode like this: 718 719\begin{verbatim} 720 ./snort -r <pcap> -Q --daq dump --daq-var load-mode=read-file 721 ./snort -i <device> -Q --daq dump --daq-var load-mode=passive 722\end{verbatim} 723 724\subsection{Statistics Changes} 725 726The Packet Wire Totals and Action Stats sections of Snort's output include 727additional fields: 728 729\begin{itemize} 730\item \texttt{Filtered} 731count of packets filtered out and not handed to Snort for analysis. 732 733\item \texttt{Injected} 734packets Snort generated and sent, e.g. TCP resets. 735 736\item \texttt{Allow} 737packets Snort analyzed and did not take action on. 738 739\item \texttt{Block} 740packets Snort did not forward, e.g. due to a block rule. 741 742\item \texttt{Replace} 743packets Snort modified. 744 745\item \texttt{Whitelist} 746packets that caused Snort to allow a flow to pass w/o inspection by any 747analysis program. 748 749\item \texttt{Blacklist} 750packets that caused Snort to block a flow from passing. 751 752\item \texttt{Ignore} 753packets that caused Snort to allow a flow to pass w/o inspection by this 754instance of Snort. 755\end{itemize} 756 757The action stats show "blocked" packets instead of "dropped" packets to avoid 758confusion between dropped packets (those Snort didn't actually see) and blocked 759packets (those Snort did not allow to pass). 760 761\section{Reading pcap files} 762 763Instead of having Snort listen on an interface, you can give it a packet 764capture to read. Snort will read and analyze the packets as if they came off 765the wire. This can be useful for testing and debugging Snort. 766 767\subsection{Command line arguments} 768 769Any of the below can be specified multiple times on the command line 770(\texttt{-r} included) and in addition to other Snort command line options. 771Note, however, that specifying \texttt{--pcap-reset} and \texttt{--pcap-show} 772multiple times has the same effect as specifying them once. 773 774\begin{center} 775\begin{tabular}{| l | p{4.5in} |} 776 777\hline 778\textbf{Option} & \textbf{Description}\\ 779\hline 780 781\hline 782\texttt{-r <file>} & 783 784Read a single pcap. \\ 785 786\hline 787\texttt{--pcap-single=<file>} & 788 789Same as -r. Added for completeness. \\ 790 791\hline 792\texttt{--pcap-file=<file>} & 793 794File that contains a list of pcap files to read. Can specify path to each 795pcap or directory to recurse to get pcaps. \\ 796 797\hline 798\texttt{--pcap-list="<list>"} & 799 800A space separated list of pcaps to read. \\ 801 802\hline 803\texttt{--pcap-dir=<dir>} & 804 805A directory to recurse to look for pcaps. Sorted in ASCII order. \\ 806 807\hline 808\texttt{--pcap-filter=<filter>} & 809 810Shell style filter to apply when getting pcaps from file or directory. This 811filter will apply to any \texttt{--pcap-file} or \texttt{--pcap-dir} arguments 812following. Use \texttt{--pcap-no-filter} to delete filter for following 813\texttt{--pcap-file} or \texttt{--pcap-dir} arguments or specify 814\texttt{--pcap-filter} again to forget previous filter and to apply to 815following \texttt{--pcap-file} or \texttt{--pcap-dir} arguments. \\ 816 817\hline 818\texttt{--pcap-no-filter} & 819 820Reset to use no filter when getting pcaps from file or directory. \\ 821 822\hline 823\texttt{--pcap-reset} & 824 825If reading multiple pcaps, reset snort to post-configuration state before 826reading next pcap. The default, i.e. without this option, is not to reset 827state. \\ 828 829\hline 830\texttt{--pcap-show} & 831 832Print a line saying what pcap is currently being read. \\ 833 834\hline 835\end{tabular} 836\end{center} 837 838\subsection{Examples} 839 840\subsubsection{Read a single pcap} 841 842\begin{verbatim} 843 $ snort -r foo.pcap 844 $ snort --pcap-single=foo.pcap 845\end{verbatim} 846 847\subsubsection{Read pcaps from a file} 848 849\begin{verbatim} 850 $ cat foo.txt 851 foo1.pcap 852 foo2.pcap 853 /home/foo/pcaps 854\end{verbatim} 855 856\begin{verbatim} 857 $ snort --pcap-file=foo.txt 858\end{verbatim} 859 860This will read foo1.pcap, foo2.pcap and all files under /home/foo/pcaps. Note 861that Snort will not try to determine whether the files under that directory are 862really pcap files or not. 863 864\subsubsection{Read pcaps from a command line list} 865 866\begin{verbatim} 867 $ snort --pcap-list="foo1.pcap foo2.pcap foo3.pcap" 868\end{verbatim} 869 870This will read foo1.pcap, foo2.pcap and foo3.pcap. 871 872\subsubsection{Read pcaps under a directory} 873 874\begin{verbatim} 875 $ snort --pcap-dir="/home/foo/pcaps" 876\end{verbatim} 877 878This will include all of the files under /home/foo/pcaps. 879 880\subsubsection{Using filters} 881 882\begin{verbatim} 883 $ cat foo.txt 884 foo1.pcap 885 foo2.pcap 886 /home/foo/pcaps 887\end{verbatim} 888 889\begin{verbatim} 890 $ snort --pcap-filter="*.pcap" --pcap-file=foo.txt 891 $ snort --pcap-filter="*.pcap" --pcap-dir=/home/foo/pcaps 892\end{verbatim} 893 894The above will only include files that match the shell pattern "*.pcap", in 895other words, any file ending in ".pcap". 896 897\begin{verbatim} 898 $ snort --pcap-filter="*.pcap --pcap-file=foo.txt \ 899 > --pcap-filter="*.cap" --pcap-dir=/home/foo/pcaps 900\end{verbatim} 901 902In the above, the first filter "*.pcap" will only be applied to the pcaps in 903the file "foo.txt" (and any directories that are recursed in that file). The 904addition of the second filter "*.cap" will cause the first filter to be 905forgotten and then applied to the directory /home/foo/pcaps, so only files 906ending in ".cap" will be included from that directory. 907 908\begin{verbatim} 909 $ snort --pcap-filter="*.pcap --pcap-file=foo.txt \ 910 > --pcap-no-filter --pcap-dir=/home/foo/pcaps 911\end{verbatim} 912 913In this example, the first filter will be applied to foo.txt, then no filter 914will be applied to the files found under /home/foo/pcaps, so all files found 915under /home/foo/pcaps will be included. 916 917\begin{verbatim} 918 $ snort --pcap-filter="*.pcap --pcap-file=foo.txt \ 919 > --pcap-no-filter --pcap-dir=/home/foo/pcaps \ 920 > --pcap-filter="*.cap" --pcap-dir=/home/foo/pcaps2 921\end{verbatim} 922 923In this example, the first filter will be applied to foo.txt, then no filter 924will be applied to the files found under /home/foo/pcaps, so all files found 925under /home/foo/pcaps will be included, then the filter "*.cap" will be applied 926to files found under /home/foo/pcaps2. 927 928\subsubsection{Resetting state} 929 930\begin{verbatim} 931 $ snort --pcap-dir=/home/foo/pcaps --pcap-reset 932\end{verbatim} 933 934The above example will read all of the files under /home/foo/pcaps, but after 935each pcap is read, Snort will be reset to a post-configuration state, meaning 936all buffers will be flushed, statistics reset, etc. For each pcap, it will be 937like Snort is seeing traffic for the first time. 938 939\subsubsection{Printing the pcap} 940 941\begin{verbatim} 942 $ snort --pcap-dir=/home/foo/pcaps --pcap-show 943\end{verbatim} 944 945The above example will read all of the files under /home/foo/pcaps and will 946print a line indicating which pcap is currently being read. 947 948\section{Basic Output} 949 950Snort does a lot of work and outputs some useful statistics when it is done. 951Many of these are self-explanatory. The others are summarized below. This 952does not include all possible output data, just the basics. 953 954\subsection{Timing Statistics} 955 956This section provides basic timing statistics. It includes total seconds and 957packets as well as packet processing rates. The rates are based on whole 958seconds, minutes, etc. and only shown when non-zero. 959 960Example: 961 962\begin{verbatim} 963=============================================================================== 964Run time for packet processing was 175.856509 seconds 965Snort processed 3716022 packets. 966Snort ran for 0 days 0 hours 2 minutes 55 seconds 967 Pkts/min: 1858011 968 Pkts/sec: 21234 969=============================================================================== 970\end{verbatim} 971 972\subsection{Packet I/O Totals} 973 974This section shows basic packet acquisition and injection peg counts obtained 975from the DAQ. If you are reading pcaps, the totals are for all pcaps combined, 976unless you use --pcap-reset, in which case it is shown per pcap. 977 978\begin{itemize} 979\item Outstanding indicates how many packets are buffered awaiting processing. 980The way this is counted varies per DAQ so the DAQ documentation should be 981consulted for more info. 982 983\item Filtered packets are not shown for pcap DAQs. 984 985\item Injected packets are the result of active response which can be 986configured for inline or passive modes. 987\end{itemize} 988 989Example: 990 991\begin{verbatim} 992=============================================================================== 993Packet I/O Totals: 994 Received: 3716022 995 Analyzed: 3716022 (100.000%) 996 Dropped: 0 ( 0.000%) 997 Filtered: 0 ( 0.000%) 998Outstanding: 0 ( 0.000%) 999 Injected: 0 1000=============================================================================== 1001\end{verbatim} 1002 1003 1004\subsection{Protocol Statistics} 1005 1006Traffic for all the protocols decoded by Snort is summarized in the breakdown 1007section. This traffic includes internal "pseudo-packets" if preprocessors such 1008as frag3 and stream5 are enabled so the total may be greater than the number of 1009analyzed packets in the packet I/O section. 1010 1011\begin{itemize} 1012\item Disc counts are discards due to basic encoding integrity flaws that 1013prevents Snort from decoding the packet. 1014 1015\item Other includes packets that contained an encapsulation that Snort doesn't 1016decode. 1017 1018\item S5 G 1/2 is the number of client/server sessions stream5 flushed due to 1019cache limit, session timeout, session reset. 1020\end{itemize} 1021 1022Example: 1023 1024\begin{verbatim} 1025=============================================================================== 1026Breakdown by protocol (includes rebuilt packets): 1027 Eth: 3722347 (100.000%) 1028 VLAN: 0 ( 0.000%) 1029 IP4: 1782394 ( 47.884%) 1030 Frag: 3839 ( 0.103%) 1031 ICMP: 38860 ( 1.044%) 1032 UDP: 137162 ( 3.685%) 1033 TCP: 1619621 ( 43.511%) 1034 IP6: 1781159 ( 47.850%) 1035 IP6 Ext: 1787327 ( 48.016%) 1036 IP6 Opts: 6168 ( 0.166%) 1037 Frag6: 3839 ( 0.103%) 1038 ICMP6: 1650 ( 0.044%) 1039 UDP6: 140446 ( 3.773%) 1040 TCP6: 1619633 ( 43.511%) 1041 Teredo: 18 ( 0.000%) 1042 ICMP-IP: 0 ( 0.000%) 1043 EAPOL: 0 ( 0.000%) 1044 IP4/IP4: 0 ( 0.000%) 1045 IP4/IP6: 0 ( 0.000%) 1046 IP6/IP4: 0 ( 0.000%) 1047 IP6/IP6: 0 ( 0.000%) 1048 GRE: 202 ( 0.005%) 1049 GRE Eth: 0 ( 0.000%) 1050 GRE VLAN: 0 ( 0.000%) 1051 GRE IP4: 0 ( 0.000%) 1052 GRE IP6: 0 ( 0.000%) 1053GRE IP6 Ext: 0 ( 0.000%) 1054 GRE PPTP: 202 ( 0.005%) 1055 GRE ARP: 0 ( 0.000%) 1056 GRE IPX: 0 ( 0.000%) 1057 GRE Loop: 0 ( 0.000%) 1058 MPLS: 0 ( 0.000%) 1059 ARP: 104840 ( 2.817%) 1060 IPX: 60 ( 0.002%) 1061 Eth Loop: 0 ( 0.000%) 1062 Eth Disc: 0 ( 0.000%) 1063 IP4 Disc: 0 ( 0.000%) 1064 IP6 Disc: 0 ( 0.000%) 1065 TCP Disc: 0 ( 0.000%) 1066 UDP Disc: 1385 ( 0.037%) 1067 ICMP Disc: 0 ( 0.000%) 1068All Discard: 1385 ( 0.037%) 1069 Other: 57876 ( 1.555%) 1070Bad Chk Sum: 32135 ( 0.863%) 1071 Bad TTL: 0 ( 0.000%) 1072 S5 G 1: 1494 ( 0.040%) 1073 S5 G 2: 1654 ( 0.044%) 1074 Total: 3722347 1075=============================================================================== 1076\end{verbatim} 1077 1078\subsection{Snort Memory Statistics} 1079On systems with mallinfo (3), you will see additional statistics. Check the man 1080page of mallinfo for details 1081 1082Example: 1083\begin{verbatim} 1084=============================================================================== 1085Memory usage summary: 1086 Total non-mmapped bytes (arena): 415481856 1087 Bytes in mapped regions (hblkhd): 409612288 1088 Total allocated space (uordblks): 92130384 1089 Total free space (fordblks): 323351472 1090 Topmost releasable block (keepcost): 3200 1091=============================================================================== 1092\end{verbatim} 1093 1094\subsection{Actions, Limits, and Verdicts} 1095 1096Action and verdict counts show what Snort did with the packets it analyzed. 1097This information is only output in IDS mode (when snort is run with the 1098\texttt{-c <conf>} option). 1099 1100\begin{itemize} 1101\item Alerts is the number of alert, and block actions processed as 1102determined by the rule actions. Here block includes block, drop, and reject 1103actions. 1104\end{itemize} 1105 1106Limits arise due to real world constraints on processing time and available 1107memory. These indicate potential actions that did not happen: 1108 1109\begin{itemize} 1110\item Match Limit counts rule matches were not processed due to the 1111\texttt{config detection: max\_queue\_events} setting. The default is 5. 1112 1113\item Queue Limit counts events couldn't be stored in the event queue 1114due to the \texttt{config event\_queue: max\_queue} setting. The default is 8. 1115 1116\item Log Limit counts events were not alerted due to the 1117\texttt{config event\_queue: log} setting. The default is 3. 1118 1119\item Event Limit counts events not alerted due to 1120\texttt{event\_filter} limits. 1121 1122\item Alert Limit counts events were not alerted because they already 1123were triggered on the session. 1124\end{itemize} 1125 1126Verdicts are rendered by Snort on each packet: 1127 1128\begin{itemize} 1129\item Allow = packets Snort analyzed and did not take action on. 1130 1131\item Block = packets Snort did not forward, e.g. due to a block rule. "Block" 1132is used instead of "Drop" to avoid confusion between dropped packets (those 1133Snort didn't actually see) and blocked packets (those Snort did not allow to 1134pass). 1135 1136\item Replace = packets Snort modified, for example, due to normalization or 1137replace rules. This can only happen in inline mode with a compatible DAQ. 1138 1139\item Whitelist = packets that caused Snort to allow a flow to pass w/o 1140inspection by any analysis program. Like blacklist, this is done by the DAQ or 1141by Snort on subsequent packets. 1142 1143\item Blacklist = packets that caused Snort to block a flow from passing. This 1144is the case when a block TCP rule fires. If the DAQ supports this in hardware, 1145no further packets will be seen by Snort for that session. If not, snort will 1146block each packet and this count will be higher. 1147 1148\item Ignore = packets that caused Snort to allow a flow to pass w/o inspection 1149by this instance of Snort. Like blacklist, this is done by the DAQ or by Snort 1150on subsequent packets. 1151 1152\item Int Blklst = packets that are GTP, Teredo, 6in4 or 4in6 encapsulated that are 1153being blocked. These packets could get the Blacklist verdict if \texttt{config 1154tunnel\_verdicts} was set for the given protocol. Note that these counts are 1155output only if non-zero. Also, this count is incremented on the first packet 1156in the flow that alerts. The alerting packet and all following packets on the 1157flow will be counted under Block. 1158 1159\item Int Whtlst = packets that are GTP, Teredo, 6in4 or 4in6 encapsulated that are 1160being allowed. These packets could get the Whitelist verdict if \texttt{config 1161tunnel\_verdicts} was set for the given protocol. Note that these counts are 1162output only if non-zero. Also, this count is incremented for all packets on 1163the flow starting with the alerting packet. 1164\end{itemize} 1165 1166Example: 1167 1168\begin{verbatim} 1169=============================================================================== 1170Action Stats: 1171 Alerts: 0 ( 0.000%) 1172 Logged: 0 ( 0.000%) 1173 Passed: 0 ( 0.000%) 1174Limits: 1175 Match: 0 1176 Queue: 0 1177 Log: 0 1178 Event: 0 1179 Alert: 0 1180Verdicts: 1181 Allow: 3716022 (100.000%) 1182 Block: 0 ( 0.000%) 1183 Replace: 0 ( 0.000%) 1184 Whitelist: 0 ( 0.000%) 1185 Blacklist: 0 ( 0.000%) 1186 Ignore: 0 ( 0.000%) 1187=============================================================================== 1188\end{verbatim} 1189 1190\section{Tunneling Protocol Support} 1191 1192Snort supports decoding of many tunneling protocols, including GRE, PPTP over GRE, 1193MPLS, IP in IP, and ERSPAN, all of which are enabled by default. 1194 1195To disable support for any GRE related encapsulation, PPTP over GRE, IPv4/IPv6 over 1196GRE, and ERSPAN, an extra configuration option is necessary: 1197 1198\begin{verbatim} 1199 $ ./configure --disable-gre 1200\end{verbatim} 1201 1202To disable support for MPLS, an separate extra configuration option is necessary: 1203 1204\begin{verbatim} 1205 $ ./configure --disable-mpls 1206\end{verbatim} 1207 1208\subsection{Multiple Encapsulations} 1209 1210Snort will not decode more than one encapsulation. Scenarios such as 1211 1212\begin{verbatim} 1213 Eth IPv4 GRE IPv4 GRE IPv4 TCP Payload 1214\end{verbatim} 1215 1216or 1217 1218\begin{verbatim} 1219 Eth IPv4 IPv6 IPv4 TCP Payload 1220\end{verbatim} 1221 1222will not be handled and will generate a decoder alert. 1223 1224\subsection{Logging} 1225 1226Currently, only the encapsulated part of the packet is logged, e.g. 1227 1228\begin{verbatim} 1229 Eth IP1 GRE IP2 TCP Payload 1230\end{verbatim} 1231 1232gets logged as 1233 1234\begin{verbatim} 1235 Eth IP2 TCP Payload 1236\end{verbatim} 1237 1238and 1239 1240\begin{verbatim} 1241 Eth IP1 IP2 TCP Payload 1242\end{verbatim} 1243 1244gets logged as 1245 1246\begin{verbatim} 1247 Eth IP2 TCP Payload 1248\end{verbatim} 1249 1250\begin{note} 1251 1252Decoding of PPTP, which utilizes GRE and PPP, is not currently supported on 1253architectures that require word alignment such as SPARC. 1254 1255\end{note} 1256 1257\section{Miscellaneous} 1258 1259\subsection{Running Snort as a Daemon} 1260 1261If you want to run Snort as a daemon, you can the add -D switch to any 1262combination described in the previous sections. Please notice that if you want 1263to be able to restart Snort by sending a SIGHUP signal to the daemon, you {\em 1264must} specify the full path to the Snort binary when you start it, for example: 1265 1266\begin{verbatim} 1267 /usr/local/bin/snort -d -h 192.168.1.0/24 \ 1268 -l /var/log/snortlogs -c /usr/local/etc/snort.conf -s -D 1269\end{verbatim} 1270 1271Relative paths are not supported due to security concerns. 1272 1273\subsubsection{Snort PID File} 1274 1275When Snort is run as a daemon , the daemon creates a PID file in the log 1276directory. In Snort 2.6, the \texttt{--pid-path} command line switch causes 1277Snort to write the PID file in the directory specified. 1278 1279Additionally, the \texttt{--create-pidfile} switch can be used to force 1280creation of a PID file even when not running in daemon mode. 1281 1282The PID file will be locked so that other snort processes cannot start. Use 1283the \texttt{--nolock-pidfile} switch to not lock the PID file. 1284 1285If you do not wish to include the name of the interface in the PID file, use 1286the \texttt{--no-interface-pidfile} switch. 1287 1288\subsection{Running in Rule Stub Creation Mode} 1289 1290If you need to dump the shared object rules stub to a directory, you must use the --dump-dynamic-rules command line option. These rule stub files are used in conjunction with the shared object rules. The path can be relative or absolute. 1291 1292\begin{verbatim} 1293 /usr/local/bin/snort -c /usr/local/etc/snort.conf \ 1294 --dump-dynamic-rules=/tmp 1295\end{verbatim} 1296 1297This path can also be configured in the snort.conf using the config option dump-dynamic-rules-path as follows: 1298 1299\begin{verbatim} 1300 config dump-dynamic-rules-path: /tmp/sorules 1301\end{verbatim} 1302 1303The path configured by command line has precedence over the one configured using dump-dynamic-rules-path. 1304 1305\begin{verbatim} 1306 /usr/local/bin/snort -c /usr/local/etc/snort.conf \ 1307 --dump-dynamic-rules 1308 1309 snort.conf: 1310 config dump-dynamic-rules-path: /tmp/sorules 1311\end{verbatim} 1312 1313In the above mentioned scenario the dump path is set to /tmp/sorules. 1314 1315\subsection{Obfuscating IP Address Printouts} 1316 1317If you need to post packet logs to public mailing lists, you might want to use 1318the -O switch. This switch obfuscates your IP addresses in packet printouts. 1319This is handy if you don't want people on the mailing list to know the IP 1320addresses involved. You can also combine the -O switch with the -h switch to 1321only obfuscate the IP addresses of hosts on the home network. This is useful 1322if you don't care who sees the address of the attacking host. For example, you 1323could use the following command to read the packets from a log file and dump 1324them to the screen, obfuscating only the addresses from the 192.168.1.0/24 1325class C network: 1326 1327\begin{verbatim} 1328 ./snort -d -v -r snort.log -O -h 192.168.1.0/24 1329\end{verbatim} 1330 1331\subsection{Specifying Multiple-Instance Identifiers} 1332 1333In Snort v2.4, the \texttt{-G} command line option was added that specifies an 1334instance identifier for the event logs. This option can be used when running 1335multiple instances of snort, either on different CPUs, or on the same CPU but a 1336different interface. Each Snort instance will use the value specified to 1337generate unique event IDs. Users can specify either a decimal value 1338(\texttt{-G 1}) or hex value preceded by 0x (\texttt{-G 0x11}). This is also 1339supported via a long option \texttt{--logid}. 1340 1341\subsection{Snort Modes} 1342 1343Snort can operate in three different modes namely tap (passive), inline, and inline-test. 1344Snort policies can be configured in these three modes too. 1345 1346\subsubsection{Explanation of Modes} 1347 1348\begin{itemize} 1349 1350\item \texttt{Inline} 1351 1352When Snort is in Inline mode, it acts as an IPS allowing drop rules to trigger. Snort can be 1353configured to run in inline mode using the command line argument -Q and snort config option 1354\texttt{policy\_mode} as follows: 1355 1356\begin{verbatim} 1357 snort -Q 1358 config policy_mode:inline 1359\end{verbatim} 1360 1361\item \texttt{Passive} 1362 1363When Snort is in Passive mode, it acts as a IDS. Drop rules are not loaded (without --treat-drop-as-alert). 1364Snort can be configured to passive mode using the snort config option \texttt{policy\_mode} as follows: 1365 1366\begin{verbatim} 1367 config policy_mode:tap 1368\end{verbatim} 1369 1370 1371\item \texttt{Inline-Test} 1372 1373Inline-Test mode simulates the inline mode of snort, allowing evaluation of inline behavior without affecting 1374traffic. The drop rules will be loaded and will be triggered as a Wdrop (Would Drop) alert. Snort can be 1375configured to run in inline-test mode using the command line option (--enable-inline-test) or using the 1376snort config option \texttt{policy\_mode} as follows: 1377 1378\begin{verbatim} 1379 snort --enable-inline-test 1380 config policy_mode:inline_test 1381\end{verbatim} 1382 1383\begin{note} 1384 1385Please note --enable-inline-test cannot be used in conjunction with -Q. 1386 1387\end{note} 1388 1389\end{itemize} 1390 1391\texttt{Behavior of different modes with rule options} 1392 1393 1394\begin{tabular}{|l|c|c|p{6cm}|} 1395\hline 1396Rule Option & Inline Mode & Passive Mode & Inline-Test Mode\\ 1397\hline 1398\hline 1399\texttt{reject} & Drop + Response & Alert + Response & Wdrop + Response\\ 1400\hline 1401\texttt{react} & Blocks and send notice & Blocks and send notice & Blocks and send notice\\ 1402\hline 1403\texttt{normalize} & Normalizes packet & Doesn't normalize & Doesn't normalize\\ 1404\hline 1405\texttt{replace} & replace content & Doesn't replace & Doesn't replace\\ 1406\hline 1407\texttt{respond} & close session & close session & close session\\ 1408\hline 1409\end{tabular} 1410 1411 1412\texttt{Behavior of different modes with rules actions} 1413 1414 1415\begin{tabular}{|l|c|c|c|} 1416\hline 1417Adapter Mode & Snort args & config policy\_mode & Drop Rule Handling\\ 1418\hline 1419\hline 1420Passive & \texttt{ --treat-drop-as-alert} & tap & Alert\\ 1421\hline 1422Passive & \texttt{ no args} & tap & Not Loaded\\ 1423\hline 1424Passive & \texttt{ --treat-drop-as-alert} & inline\_test & Alert\\ 1425\hline 1426Passive & \texttt{ no args} & inline\_test & Would Drop\\ 1427\hline 1428Passive & \texttt{ --treat-drop-as-alert} & inline & Alert\\ 1429\hline 1430Passive & \texttt{no args} & inline & Not loaded + warning\\ 1431\hline 1432Inline Test & \texttt{ --enable-inline-test --treat-drop-as-alert} & tap & Alert\\ 1433\hline 1434Inline Test & \texttt{ --enable-inline-test} & tap & Would Drop\\ 1435\hline 1436Inline Test & \texttt{ --enable-inline-test --treat-drop-as-alert} & inline\_test & Alert\\ 1437\hline 1438Inline Test & \texttt{ --enable-inline-test} & inline\_test & Would Drop\\ 1439\hline 1440Inline Test & \texttt{ --enable-inline-test --treat-drop-as-alert} & inline & Alert\\ 1441\hline 1442Inline Test & \texttt{ --enable-inline-test} & inline & Would Drop\\ 1443\hline 1444Inline & \texttt{ -Q --treat-drop-as-alert} & tap & Alert\\ 1445\hline 1446Inline & \texttt{ -Q} & tap & Alert\\ 1447\hline 1448Inline & \texttt{ -Q --treat-drop-as-alert} & inline\_test & Alert\\ 1449\hline 1450Inline & \texttt{ -Q} & inline\_test & Would Drop\\ 1451\hline 1452Inline & \texttt{ -Q --treat-drop-as-alert} & inline & Alert\\ 1453\hline 1454Inline & \texttt{ -Q} & inline & Drop\\ 1455\hline 1456\end{tabular} 1457 1458\section{Control socket} 1459\label{control_socket} 1460Snort can be configured to provide a Unix socket that can be used to issue commands 1461to the running process. You must build snort with the 1462\texttt{--enable-control-socket} option. The control socket 1463functionality is supported on Linux only.\\ 1464 1465Snort can be configured to use control socket using the command line argument \texttt{--cs-dir <path>} 1466 and snort config option \texttt{cs\_dir} as follows: 1467 1468\begin{verbatim} 1469 snort --cs-dir <path> 1470 config cs_dir:<path> 1471\end{verbatim} 1472 1473\texttt{<path>} specifies the directory for snort to create the socket. If relative path is used, 1474the path is relative to pid path specified. If there is no pid path specified, it is relative to 1475current working directory. 1476 1477A command \texttt{snort\_control} is made and installed along with snort in the same 1478bin directory when configured with the \texttt{--enable-control-socket} option. 1479 1480\section{Configure signal value} 1481\label{configure_signal} 1482On some systems, signal used by snort might be used by other functions. To avoid conflicts, 1483users can change the default signal value through \texttt{./configure} options for non-Windows system. 1484 1485These signals can be changed: 1486\begin{itemize} 1487\item \texttt{SIGNAL\_SNORT\_RELOAD} 1488\item \texttt{SIGNAL\_SNORT\_DUMP\_STATS} 1489\item \texttt{SIGNAL\_SNORT\_ROTATE\_STATS} 1490\item \texttt{SIGNAL\_SNORT\_READ\_ATTR\_TBL} 1491\end{itemize} 1492 1493Syntax: 1494 1495\begin{verbatim} 1496 ./configure SIGNAL_SNORT_RELOAD=<value/name> SIGNAL_SNORT_DUMP_STATS=<value/name>\ 1497 SIGNAL_SNORT_READ_ATTR_TBL=<value/name> SIGNAL_SNORT_ROTATE_STATS=<value/name> 1498\end{verbatim} 1499 1500You can set those signals to user defined values or known signal names in the system. 1501The following example changes the rotate stats signal to 31 and reload attribute table to 1502signal SIGUSR2 : 1503 1504\begin{verbatim} 1505 ./configure SIGNAL_SNORT_ROTATE_STATS=31 SIGNAL_SNORT_READ_ATTR_TBL=SIGUSR2 1506\end{verbatim} 1507 1508If the same signal is assigned more than once a warning will be logged 1509during snort initialization. If a signal handler cannot be installed a warning 1510will be logged and that has to be fixed, otherwise the functionality will be lost. 1511 1512\texttt{Signals used in snort} 1513\label{signalactions} 1514\begin{tabular}{|l|l|l|} 1515\hline 1516Signal name & Default value & Action \\ 1517\hline 1518\hline 1519SIGTERM & SIGTERM & exit \\ 1520\hline 1521SIGINT & SIGINT & exit \\ 1522\hline 1523SIGQUIT & SIGQUIT & exit \\ 1524\hline 1525SIGPIPE & SIGPIPE & ignore \\ 1526\hline 1527SIGNAL\_SNORT\_RELOAD & SIGHUP & reload snort \\ 1528\hline 1529SIGNAL\_SNORT\_DUMP\_STATS & SIGUSR1 & dump stats \\ 1530\hline 1531SIGNAL\_SNORT\_ROTATE\_STATS & SIGUSR2 & rotate stats \\ 1532\hline 1533SIGNAL\_SNORT\_READ\_ATTR\_TBL & SIGURG & reload attribute table \\ 1534\hline 1535SIGNAL\_SNORT\_CHILD\_READY & SIGCHLD & internal use in daemon mode \\ 1536\hline 1537\end{tabular} 1538 1539\section{More Information} 1540 1541Chapter \ref{Configuring Snort} contains much information about many 1542configuration options available in the configuration file. The Snort manual 1543page and the output of \texttt{snort -?} or \texttt{snort --help} contain 1544information that can help you get Snort running in several different modes. 1545 1546\begin{note} 1547 1548In many shells, a backslash (\textbackslash{}) is needed to escape the ?, so 1549you may have to type \texttt{snort -\textbackslash{}?} instead of \texttt{snort 1550-?} for a list of Snort command line options. 1551 1552\end{note} 1553 1554The Snort web page (\url{http://www.snort.org}) and the Snort Users mailing 1555list: 1556 1557\url{http://marc.theaimsgroup.com/?l=snort-users} 1558 1559at \verb?snort-users@lists.snort.org? provide informative announcements 1560as well as a venue for community discussion and support. There's a lot to 1561Snort, so sit back with a beverage of your choosing and read the documentation 1562and mailing list archives. 1563 1564\chapter{Configuring Snort} 1565\label{Configuring Snort} 1566 1567\section{Includes} 1568 1569The {\tt include} keyword allows other snort config files to be included within the 1570snort.conf indicated on the Snort command line. It works much like an \#include 1571from the C programming language, reading the contents of the named file and 1572adding the contents in the place where the include statement appears in the 1573file. 1574 1575\subsection{Format} 1576\begin{verbatim} 1577 include <include file path/name> 1578\end{verbatim} 1579 1580\begin{note} 1581 1582Note that there is no semicolon at the end of this line. 1583 1584\end{note} 1585 1586Included files will substitute any predefined variable values into their own 1587variable references. See Section \ref{variables} for more information on 1588defining and using variables in Snort config files. 1589 1590\subsection{Variables} 1591\label{variables} 1592 1593Three types of variables may be defined in Snort: 1594 1595\begin{itemize} 1596\item var 1597\item portvar 1598\item ipvar 1599\end{itemize} 1600 1601These are simple substitution variables set with the {\tt var}, {\tt ipvar}, or 1602{\tt portvar} keywords as follows: 1603 1604\begin{verbatim} 1605 var RULES_PATH rules/ 1606 portvar MY_PORTS [22,80,1024:1050] 1607 ipvar MY_NET [192.168.1.0/24,10.1.1.0/24] 1608 alert tcp any any -> $MY_NET $MY_PORTS (flags:S; msg:"SYN packet";) 1609 include $RULE_PATH/example.rule 1610\end{verbatim} 1611 1612\subsubsection{IP Variables and IP Lists} 1613 1614IPs may be specified individually, in a list, as a CIDR block, or any 1615combination of the three. IP variables should be specified using 'ipvar' 1616instead of 'var'. Using 'var' for an IP variable is still allowed for backward 1617compatibility, but it will be deprecated in a future release. 1618 1619IP variable name can begin with an alphanumeric character [A-Za-z0-9] or '\_' 1620and should be followed by characters and numbers. Only numbers are not 1621accepted as variable names. 1622 1623IPs, IP lists, and CIDR blocks may be negated with '!'. Negation is handled 1624differently compared with Snort versions 2.7.x and earlier. Previously, each 1625element in a list was logically OR'ed together. IP lists now OR non-negated 1626elements and AND the result with the OR'ed negated elements. 1627 1628The following example list will match the IP 1.1.1.1 and IP from 2.2.2.0 to 16292.2.2.255, with the exception of IPs 2.2.2.2 and 2.2.2.3. 1630 1631\begin{verbatim} 1632 [1.1.1.1,2.2.2.0/24,![2.2.2.2,2.2.2.3]] 1633\end{verbatim} 1634 1635The order of the elements in the list does not matter. The element 'any' can 1636be used to match all IPs, although '!any' is not allowed. Also, negated IP 1637ranges that are more general than non-negated IP ranges are not allowed. 1638 1639See below for some valid examples if IP variables and IP lists. 1640 1641\begin{verbatim} 1642 ipvar EXAMPLE [1.1.1.1,2.2.2.0/24,![2.2.2.2,2.2.2.3]] 1643 1644 alert tcp $EXAMPLE any -> any any (msg:"Example"; sid:1;) 1645 1646 alert tcp [1.0.0.0/8,!1.1.1.0/24] any -> any any (msg:"Example";sid:2;) 1647\end{verbatim} 1648 1649The following examples demonstrate some invalid uses of IP variables and IP 1650lists. 1651 1652Use of !any: 1653 1654\begin{verbatim} 1655 ipvar EXAMPLE any 1656 alert tcp !$EXAMPLE any -> any any (msg:"Example";sid:3;) 1657\end{verbatim} 1658 1659Different use of !any: 1660 1661\begin{verbatim} 1662 ipvar EXAMPLE !any 1663 alert tcp $EXAMPLE any -> any any (msg:"Example";sid:3;) 1664\end{verbatim} 1665 1666Logical contradictions: 1667 1668\begin{verbatim} 1669 ipvar EXAMPLE [1.1.1.1,!1.1.1.1] 1670\end{verbatim} 1671 1672Nonsensical negations: 1673 1674\begin{verbatim} 1675 ipvar EXAMPLE [1.1.1.0/24,!1.1.0.0/16] 1676\end{verbatim} 1677 1678 1679\subsubsection{Port Variables and Port Lists} 1680 1681Portlists supports the declaration and lookup of ports and the representation 1682of lists and ranges of ports. Variables, ranges, or lists may all be negated 1683with '!'. Also, 'any' will specify any ports, but '!any' is not allowed. 1684Valid port ranges are from 0 to 65535. 1685 1686Lists of ports must be enclosed in brackets and port ranges may be specified 1687with a ':', such as in: 1688 1689\begin{verbatim} 1690 [10:50,888:900] 1691\end{verbatim} 1692 1693Port variables should be specified using 'portvar'. The use of 'var' to 1694declare a port variable will be deprecated in a future release. For backwards 1695compatibility, a 'var' can still be used to declare a port variable, provided 1696the variable name either ends with '\_PORT' or begins with 'PORT\_'. 1697 1698The following examples demonstrate several valid usages of both port variables 1699and port lists. 1700 1701\begin{verbatim} 1702 portvar EXAMPLE1 80 1703 1704 var EXAMPLE2_PORT [80:90] 1705 1706 var PORT_EXAMPLE2 [1] 1707 1708 portvar EXAMPLE3 any 1709 1710 portvar EXAMPLE4 [!70:90] 1711 1712 portvar EXAMPLE5 [80,91:95,100:200] 1713 1714 alert tcp any $EXAMPLE1 -> any $EXAMPLE2_PORT (msg:"Example"; sid:1;) 1715 1716 alert tcp any $PORT_EXAMPLE2 -> any any (msg:"Example"; sid:2;) 1717 1718 alert tcp any 90 -> any [100:1000,9999:20000] (msg:"Example"; sid:3;) 1719\end{verbatim} 1720 1721Several invalid examples of port variables and port lists are demonstrated 1722below: 1723 1724Use of !any: 1725 1726\begin{verbatim} 1727 portvar EXAMPLE5 !any 1728 var EXAMPLE5 !any 1729\end{verbatim} 1730 1731Logical contradictions: 1732 1733\begin{verbatim} 1734 portvar EXAMPLE6 [80,!80] 1735\end{verbatim} 1736 1737Ports out of range: 1738 1739\begin{verbatim} 1740 portvar EXAMPLE7 [65536] 1741\end{verbatim} 1742 1743Incorrect declaration and use of a port variable: 1744 1745\begin{verbatim} 1746 var EXAMPLE8 80 1747 alert tcp any $EXAMPLE8 -> any any (msg:"Example"; sid:4;) 1748\end{verbatim} 1749 1750Port variable used as an IP: 1751 1752\begin{verbatim} 1753 alert tcp $EXAMPLE1 any -> any any (msg:"Example"; sid:5;) 1754\end{verbatim} 1755 1756\subsubsection{Variable Modifiers} 1757 1758Rule variable names can be modified in several ways. You can define 1759meta-variables using the \$ operator. These can be used with the variable 1760modifier operators {\tt ?} and {\tt -}, as described in the following table: 1761 1762\begin{center} 1763\begin{tabular}{| l | p{4.5in} |} 1764 1765\hline 1766\textbf{Variable Syntax} & \textbf{Description}\\ 1767\hline 1768 1769\hline 1770\texttt{var} & 1771 1772Defines a meta-variable.\\ 1773 1774\hline 1775\texttt{\$(var) or \$var} & 1776 1777Replaces with the contents of variable \texttt{var}.\\ 1778 1779\hline 1780\texttt{\$(var:-default)} & 1781 1782Replaces the contents of the variable \texttt{var} with ``default'' if 1783\texttt{var} is undefined.\\ 1784 1785\hline 1786\texttt{\$(var:?message)} & 1787 1788Replaces with the contents of variable \texttt{var} or prints out the error 1789message and exits.\\ 1790 1791\hline 1792\end{tabular} 1793\end{center} 1794 1795Here is an example of advanced variable usage in action: 1796 1797\begin{verbatim} 1798 ipvar MY_NET 192.168.1.0/24 1799 log tcp any any -> $(MY_NET:?MY_NET is undefined!) 23 1800\end{verbatim} 1801 1802\subsubsection{Limitations} 1803 1804When embedding variables, types can not be mixed. For instance, port variables 1805can be defined in terms of other port variables, but old-style variables (with 1806the 'var' keyword) can not be embedded inside a 'portvar'. 1807 1808Valid embedded variable: 1809 1810\begin{verbatim} 1811 portvar pvar1 80 1812 portvar pvar2 [$pvar1,90] 1813\end{verbatim} 1814 1815Invalid embedded variable: 1816 1817\begin{verbatim} 1818 var pvar1 80 1819 portvar pvar2 [$pvar1,90] 1820\end{verbatim} 1821 1822Likewise, variables can not be redefined if they were previously defined as a 1823different type. They should be renamed instead: 1824 1825Invalid redefinition: 1826 1827\begin{verbatim} 1828 var pvar 80 1829 portvar pvar 90 1830\end{verbatim} 1831 1832\subsection{Config} 1833\label{Config} 1834 1835Many configuration and command line options of Snort can be specified in the 1836configuration file. 1837 1838\subsubsection{Format} 1839 1840\begin{verbatim} 1841 config <directive> [: <value>] 1842\end{verbatim} 1843 1844\newpage 1845\begin{center} 1846\begin{longtable}[t]{| p{2.5in} | p{3.5in} |} 1847 1848\hline 1849{\bf Config Directive} & {\bf Description}\\ 1850\hline 1851 1852% KEEP THESE IN ALPHABETICAL ORDER 1853\hline 1854\texttt{config alert\_with\_interface\_name} & Appends interface name to alert 1855(\texttt{snort -I}). \\ 1856 1857\hline 1858\texttt{config alertfile: <filename>} & Sets the alerts output file. \\ 1859 1860\hline 1861\texttt{config asn1: <max-nodes>} & Specifies the maximum number of nodes to track when 1862doing ASN1 decoding. See Section \ref{asn1} for more information and 1863examples.\\ 1864 1865\hline 1866\texttt{config autogenerate\_preprocessor\newline \_decoder\_rules} & If Snort was 1867configured to enable decoder and preprocessor rules, this option will cause 1868Snort to revert back to its original behavior of alerting if the decoder or 1869preprocessor generates an event. \\ 1870 1871\hline 1872\texttt{config bpf\_file: <filename>} & Specifies BPF filters (\texttt{snort 1873-F}). \\ 1874 1875\hline 1876\texttt{config checksum\_drop: <types>} & Types of packets to drop if invalid 1877checksums. Values: \texttt{none}, \texttt{noip}, \texttt{notcp}, 1878\texttt{noicmp}, \texttt{noudp}, \texttt{ip}, \texttt{tcp}, \texttt{udp}, 1879\texttt{icmp} or \texttt{all} (only applicable in inline mode and for packets 1880checked per \texttt{checksum\_mode} config option). \\ 1881 1882\hline 1883\texttt{config checksum\_mode: <types>} & Types of packets to calculate checksums. 1884Values: \texttt{none}, \texttt{noip}, \texttt{notcp}, \texttt{noicmp}, 1885\texttt{noudp}, \texttt{ip}, \texttt{tcp}, \texttt{udp}, \texttt{icmp} or 1886\texttt{all}. \\ 1887 1888\hline 1889\texttt{config chroot: <dir>} & Chroots to specified dir (\texttt{snort 1890-t}). \\ 1891 1892\hline 1893\texttt{config classification: <class>} & See Table 1894\ref{Snort Default Classifications} for a list of classifications.\\ 1895 1896\hline 1897\texttt{config cs\_dir: <path>} & configure snort to provide a Unix socket in the path 1898that can be used to issue commands to the running process. See Section 1899\ref{control_socket} for more details.\\ 1900 1901\hline 1902\texttt{config daemon} & Forks as a daemon (\texttt{snort -D}). \\ 1903 1904\hline 1905\texttt{config decode\_data\_link} & Decodes Layer2 headers (\texttt{snort 1906-e}). \\ 1907 1908\hline 1909\texttt{config default\_rule\_state: <state>} & Global configuration directive 1910to enable or disable the loading of rules into the detection engine. Default 1911(with or without directive) is enabled. Specify \texttt{disabled} to disable 1912loading rules. \\ 1913 1914\hline 1915\texttt{config daq: <type>} & Selects the type of DAQ to instantiate. The 1916DAQ with the highest version of the given type is selected if there are 1917multiple of the same type (this includes any built-in DAQs).\\ 1918 1919\hline 1920\texttt{config daq\_mode: <mode>} & Select the DAQ mode: passive, inline, or 1921read-file. Not all DAQs support modes. See the DAQ distro README for 1922possible DAQ modes or list DAQ capabilities for a brief summary. \\ 1923 1924\hline 1925\texttt{config daq\_var: <name=value>} & Set a DAQ specific variable. Snort 1926just passes this information down to the DAQ. See the DAQ distro README for 1927possible DAQ variables. \\ 1928 1929\hline 1930\texttt{config daq\_dir: <dir>} & Tell Snort where to look for available 1931dynamic DAQ modules. This can be repeated. The selected DAQ will be the 1932one with the latest version. \\ 1933 1934\hline \texttt{config daq\_list: [<dir>]} & Tell Snort to dump basic DAQ 1935capabilities and exit. You can optionally specify a directory to include any 1936dynamic DAQs from that directory. You can also precede this option with extra 1937DAQ directory options to look in multiple directories. \\ 1938 1939\hline 1940\texttt{config decode\_esp: [enable | disable]} & Enable or disable the decoding of 1941Encapsulated Security Protocol (ESP). This is disabled by default. 1942Some networks use ESP for authentication without encryption, allowing their 1943content to be inspected. Encrypted ESP may cause some false positives if this 1944option is enabled.\\ 1945 1946\hline 1947\texttt{config detection: [search-method <method>]} & Select type of fast pattern 1948matcher algorithm to use. 1949\begin{itemize} 1950\item \texttt{search-method <method>} 1951\begin{itemize} 1952\item Queued match search methods - Matches are queued until the fast pattern 1953matcher is finished with the payload, then evaluated. This was found to generally 1954increase performance through fewer cache misses (evaluating each rule would 1955generally blow away the fast pattern matcher 1956state in the cache). 1957\begin{itemize} 1958\item \texttt{ac} and \texttt{ac-q} - Aho-Corasick Full (high memory, best performance). 1959\item \texttt{ac-bnfa} and \texttt{ac-bnfa-q} - Aho-Corasick Binary NFA (low memory, high performance) 1960\item \texttt{lowmem} and \texttt{lowmem-q} - Low Memory Keyword Trie (low memory, moderate performance) 1961\item \texttt{ac-split} - Aho-Corasick Full with ANY-ANY port group evaluated separately (low memory, high performance). Note this is shorthand for \texttt{search-method ac, split-any-any} 1962\item \texttt{intel-cpm} - Intel CPM library (must have compiled Snort with location of libraries to enable this) 1963\end{itemize} 1964\end{itemize} 1965\begin{itemize} 1966\item No queue search methods - The "nq" option specifies that matches should not 1967be queued and evaluated as they are found. 1968\begin{itemize} 1969\item \texttt{ac-nq} - Aho-Corasick Full (high memory, best performance). 1970\item \texttt{ac-bnfa-nq} - Aho-Corasick Binary NFA (low memory, high performance). 1971This is the default search method if none is specified. 1972\item \texttt{lowmem-nq} - Low Memory Keyword Trie (low memory, moderate performance) 1973\end{itemize} 1974\end{itemize} 1975\begin{itemize} 1976\item Other search methods (the above are considered superior to these) 1977\begin{itemize} 1978\item \texttt{ac-std} - Aho-Corasick Standard (high memory, high performance) 1979\item \texttt{acs} - Aho-Corasick Sparse (high memory, moderate performance) 1980\item \texttt{ac-banded} - Aho-Corasick Banded (high memory, moderate performance) 1981\item \texttt{ac-sparsebands} - Aho-Corasick Sparse-Banded (high memory, moderate performance) 1982\end{itemize} 1983\end{itemize} 1984\end{itemize} \\ 1985 1986\hline 1987\texttt{config detection: [split-any-any] [search-optimize] [max-pattern-len <int>]} & Other options 1988that affect fast pattern matching. 1989\begin{itemize} 1990\item \texttt{split-any-any} 1991\begin{itemize} 1992\item A memory/performance tradeoff. By default, ANY-ANY port rules are added to 1993every non ANY-ANY port group so that only one port group rule evaluation needs to 1994be done per packet. Not putting the ANY-ANY port rule group into every other 1995port group can significantly reduce the memory footprint of the fast pattern 1996matchers if there are many ANY-ANY port rules. But doing so may require two 1997port group evaluations per packet - one for the specific port group and one for 1998the ANY-ANY port group, thus potentially reducing performance. This option is 1999generic and can be used with any \texttt{search-method} but was specifically 2000intended for use with the \texttt{ac} \texttt{search-method} where the memory 2001footprint is significantly reduced though overall fast pattern performance is 2002better than \texttt{ac-bnfa}. Of note is that the lower memory footprint can 2003also increase performance through fewer cache misses. Default is not to split 2004the ANY-ANY port group. 2005\end{itemize} 2006\item \texttt{search-optimize} 2007\begin{itemize} 2008\item Optimizes fast pattern memory when used with \texttt{search-method} 2009\texttt{ac} or \texttt{ac-split} by dynamically determining the size of a 2010state based on the total number of states. When used with \texttt{ac-bnfa}, some 2011fail-state resolution will be attempted, potentially increasing performance. 2012Default is not to optimize. 2013\end{itemize} 2014\item \texttt{max-pattern-len <integer>} 2015\begin{itemize} 2016\item This is a memory optimization that specifies the maximum length of a pattern 2017that will be put in the fast pattern matcher. Patterns longer than this length 2018will be truncated to this length before inserting into the pattern matcher. Useful 2019when there are very long contents being used and truncating the pattern won't diminish 2020the uniqueness of the patterns. Note that this may cause more false positive rule 2021evaluations, i.e. rules that will be evaluated because a fast pattern was matched, 2022but eventually fail, however CPU cache can play a part in performance so a smaller memory 2023footprint of the fast pattern matcher can potentially increase performance. Default 2024is to not set a maximum pattern length. 2025\end{itemize} 2026\end{itemize} \\ 2027 2028\hline 2029\texttt{config detection: [no\_stream\_inserts] [max\_queue\_events <int>] [enable-single-rule-group] [bleedover-port-limit]} & Other detection engine options. 2030\begin{itemize} 2031\item \texttt{no\_stream\_inserts} 2032\begin{itemize} 2033\item Specifies that stream inserted packets should not be evaluated against the detection engine. 2034This is a potential performance improvement with the idea that the stream rebuilt packet will 2035contain the payload in the inserted one so the stream inserted packet doesn't need to be 2036evaluated. Default is to inspect stream inserts. 2037\end{itemize} 2038\item \texttt{max\_queue\_events <integer>} 2039\begin{itemize} 2040\item Specifies the maximum number of matching fast-pattern states to queue per packet. 2041Default is 5 events. 2042\end{itemize} 2043\item \texttt{enable-single-rule-group} 2044\begin{itemize} 2045\item Put all rules into one port group. Not recommended. Default is not to 2046do this. 2047\end{itemize} 2048\item \texttt{bleedover-port-limit} 2049\begin{itemize} 2050\item The maximum number of source or destination ports designated in a rule 2051before the rule is considered an ANY-ANY port group rule. Default is 1024. 2052\end{itemize} 2053\end{itemize} \\ 2054 2055\hline 2056\texttt{config detection: [debug] [debug-print-nocontent-rule-tests] [debug-print-rule-group-build-details] [debug-print-rule-groups-uncompiled] [debug-print-rule-groups-compiled] [debug-print-fast-pattern] [bleedover-warnings-enabled]} & Options for detection engine debugging. 2057\begin{itemize} 2058\item \texttt{debug} 2059\begin{itemize} 2060\item Prints fast pattern information for a particular port group. 2061\end{itemize} 2062\item \texttt{debug-print-nocontent-rule-tests} 2063\begin{itemize} 2064\item Prints port group information during packet evaluation. 2065\end{itemize} 2066\item \texttt{debug-print-rule-group-build-details} 2067\begin{itemize} 2068\item Prints port group information during port group compilation. 2069\end{itemize} 2070\item \texttt{debug-print-rule-groups-uncompiled} 2071\begin{itemize} 2072\item Prints uncompiled port group information. 2073\end{itemize} 2074\item \texttt{debug-print-rule-groups-compiled} 2075\begin{itemize} 2076\item Prints compiled port group information. 2077\end{itemize} 2078\item \texttt{debug-print-fast-pattern} 2079\begin{itemize} 2080\item For each rule with fast pattern content, prints information about the content 2081being used for the fast pattern matcher. 2082\end{itemize} 2083\item \texttt{bleedover-warnings-enabled} 2084\begin{itemize} 2085\item Prints a warning if the number of source or destination ports used in a 2086rule exceed the \texttt{bleedover-port-limit} forcing the rule to be moved into 2087the ANY-ANY port group. 2088\end{itemize} 2089\end{itemize} \\ 2090 2091\hline 2092\texttt{config disable\_decode\_alerts} & Turns off the alerts generated by the 2093decode phase of Snort. \\ 2094 2095\hline 2096\texttt{config disable\_inline\_init\_failopen} & Disables failopen thread that 2097allows inline traffic to pass while Snort is starting up. Only useful if Snort 2098was configured with --enable-inline-init-failopen. (\texttt{snort 2099--disable-inline-init-failopen}) \\ 2100 2101\hline 2102\texttt{config disable\_ipopt\_alerts} & Disables IP option length validation 2103alerts. \\ 2104 2105\hline 2106\texttt{config disable\_tcpopt\_alerts} & Disables option length validation 2107alerts. \\ 2108 2109\hline 2110\texttt{config\newline disable\_tcpopt\_experimental\_alerts} & Turns off 2111alerts generated by experimental TCP options. \\ 2112 2113\hline 2114\texttt{config disable\_tcpopt\_obsolete\_alerts} & Turns off alerts 2115generated by obsolete TCP options. \\ 2116 2117\hline 2118\texttt{config disable\_tcpopt\_ttcp\_alerts} & Turns off alerts generated by 2119T/TCP options. \\ 2120 2121\hline 2122\texttt{config disable\_ttcp\_alerts} & Turns off alerts generated by T/TCP 2123options. \\ 2124 2125\hline 2126\texttt{config dump\_chars\_only} & Turns on character dumps (\texttt{snort 2127-C}). \\ 2128 2129\hline 2130\texttt{config dump\_payload} & Dumps application layer (\texttt{snort -d}). \\ 2131 2132\hline 2133\texttt{config dump\_payload\_verbose} & Dumps raw packet starting at link 2134layer (\texttt{snort -X}). \\ 2135 2136\hline 2137\texttt{config enable\_decode\_drops} & Enables the dropping of bad packets 2138identified by decoder (only applicable in inline mode).\\ 2139 2140\hline 2141\texttt{config enable\_decode\_oversized\_alerts} & Enable alerting 2142on packets that have headers containing length fields for which the value is 2143greater than the length of the packet. \\ 2144 2145\hline 2146\texttt{config enable\_decode\_oversized\_drops} & Enable dropping 2147packets that have headers containing length fields for which the value is 2148greater than the length of the packet. 2149\texttt{enable\_decode\_oversized\_alerts} must also be enabled for this to be 2150effective (only applicable in inline mode). \\ 2151 2152\hline 2153\texttt{config enable\_deep\_teredo\_inspection} & Snort's packet decoder only 2154decodes Teredo (IPv6 over UDP over IPv4) traffic on UDP port 3544. This option 2155makes Snort decode Teredo traffic on all UDP ports. \\ 2156 2157\hline 2158\texttt{config enable\_ipopt\_drops} & Enables the dropping of bad packets with 2159bad/truncated IP options (only applicable in inline mode).\\ 2160 2161\hline 2162\texttt{config enable\_mpls\_multicast} & Enables support for MPLS multicast. 2163This option is needed when the network allows MPLS multicast traffic. When this 2164option is off and MPLS multicast traffic is detected, Snort will generate an 2165alert. By default, it is off.\\ 2166 2167\hline 2168\texttt{config enable\_mpls\_overlapping\_ip} & Enables support for overlapping 2169IP addresses in an MPLS network. In a normal situation, where there are no 2170overlapping IP addresses, this configuration option should not be turned on. 2171However, there could be situations where two private networks share the same IP 2172space and different MPLS labels are used to differentiate traffic from the two 2173VPNs. In such a situation, this configuration option should be turned on. By 2174default, it is off. \\ 2175 2176\hline 2177\texttt{config enable\_tcpopt\_drops} & Enables the dropping of bad packets 2178with bad/truncated TCP option (only applicable in inline mode).\\ 2179 2180\hline 2181\texttt{config\newline enable\_tcpopt\_experimental\_drops} & Enables the 2182dropping of bad packets with experimental TCP option. (only applicable in 2183inline mode).\\ 2184 2185\hline 2186\texttt{config enable\_tcpopt\_obsolete\_drops} & Enables the 2187dropping of bad packets with obsolete TCP option. (only applicable in inline 2188mode).\\ 2189 2190\hline 2191\texttt{config enable\_tcpopt\_ttcp\_drops} & Enables the dropping of bad packets with 2192T/TCP option. (only applicable in inline mode).\\ 2193 2194\hline 2195\texttt{config enable\_ttcp\_drops} & Enables the dropping of bad packets with T/TCP 2196option. (only applicable in inline mode).\\ 2197 2198\hline 2199\texttt{config event\_filter: memcap <bytes>} & Set global memcap in bytes for 2200thresholding. Default is 1048576 bytes (1 megabyte). \\ 2201 2202\hline 2203\texttt{config event\_queue: [max\_queue <num>] [log <num>] [order\_events 2204<order>]} & Specifies conditions about Snort's event queue. You can use the 2205following options: 2206 2207\begin{itemize} 2208\item \texttt{max\_queue $<$integer$>$} (max events supported) 2209\item \texttt{log $<$integer$>$} (number of events to log) 2210\item \texttt{order\_events [priority$|$content\_length]} (how to order events within the queue) 2211\end{itemize} 2212 2213See Section \ref{eventqueue} for more information and examples.\\ 2214 2215\hline 2216\texttt{config flowbits\_size: <num-bits>} & Specifies the maximum number of 2217flowbit tags that can be used within a rule set. The default is 1024 bits 2218and maximum is 2048. \\ 2219 2220\hline 2221\texttt{config ignore\_ports: <proto> <port-list>} & Specifies ports to ignore 2222(useful for ignoring noisy NFS traffic). Specify the protocol (TCP, UDP, IP, or 2223ICMP), followed by a list of ports. Port ranges are supported.\\ 2224 2225\hline 2226\texttt{config interface: <iface>} & Sets the network interface (\texttt{snort 2227-i}). \\ 2228 2229\hline 2230\texttt{config ipv6\_frag: [bsd\_icmp\_frag\_alert on|off] [, 2231bad\_ipv6\_frag\_alert on|off] [, frag\_timeout <secs>] [, max\_frag\_sessions 2232<max-track>]} & The following options can be used: 2233 2234\begin{itemize} 2235 2236\item \texttt{bsd\_icmp\_frag\_alert on|off} (Specify whether or not to alert. 2237Default is on) 2238 2239\item \texttt{bad\_ipv6\_frag\_alert on|off} (Specify whether or not to alert. 2240Default is on) 2241 2242\item \texttt{frag\_timeout $<$integer$>$} (Specify amount of time in seconds 2243to timeout first frag in hash table) 2244 2245\item \texttt{max\_frag\_sessions $<$integer$>$} (Specify the number of 2246fragments to track in the hash table) 2247 2248\end{itemize} \\ 2249 2250\hline 2251\texttt{config logdir: <dir>} & Sets the logdir (\texttt{snort -l}). 2252\\ 2253 2254\hline 2255\texttt{config log\_ipv6\_extra\_data} & Set Snort to log IPv6 source and destination 2256addresses as unified2 extra data events. \\ 2257 2258\hline 2259\texttt{config max\_attribute\_hosts: <hosts>} & Sets a limit on the maximum 2260number of hosts to read from the attribute table. Minimum value is 32 and the 2261maximum is 524288 (512k). The default is 10000. If the number of hosts in the 2262attribute table exceeds this value, an error is logged and the remainder of the 2263hosts are ignored. This option is only supported with a Host Attribute Table 2264(see section \ref{targetbased}). \\ 2265 2266\hline 2267\texttt{config max\_attribute\_services\_per\_host: <hosts>} & Sets a per host 2268limit on the maximum number of services to read from the attribute table. 2269Minimum value is 1 and the maximum is 65535. The default is 100. For a given 2270host, if the number of services in the attribute table exceeds this value, an 2271error is logged and the remainder of the services for that host are ignored. 2272This option is only supported with a Host Attribute Table (see section 2273\ref{targetbased}). \\ 2274 2275\hline 2276\texttt{config max\_mpls\_labelchain\_len: <num-hdrs>} & Sets a Snort-wide 2277limit on the number of MPLS headers a packet can have. Its default value is -1, 2278which means that there is no limit on label chain length.\\ 2279 2280\hline 2281\texttt{config max\_ip6\_extensions: <num-extensions>} & Sets the maximum number 2282of IPv6 extension headers that Snort will decode. Default is 8. \\ 2283 2284\hline 2285\texttt{config min\_ttl: <ttl>} & Sets a Snort-wide minimum ttl to ignore all 2286traffic. \\ 2287 2288\hline 2289\texttt{config mpls\_payload\_type: ipv4|ipv6|ethernet} & Sets a Snort-wide 2290MPLS payload type. In addition to ipv4, ipv6 and ethernet are also valid 2291options. The default MPLS payload type is ipv4\\ 2292 2293\hline 2294\texttt{config no\_promisc} & Disables promiscuous mode (\texttt{snort -p}). \\ 2295 2296\hline 2297\texttt{config nolog} & Disables logging. Note: Alerts will still occur. 2298(\texttt{snort -N}). \\ 2299 2300\hline 2301\texttt{config nopcre} & Disables pcre pattern matching. \\ 2302 2303\hline 2304\texttt{config obfuscate} & Obfuscates IP Addresses (\texttt{snort -O}). \\ 2305 2306\hline 2307\texttt{config order: <order>} & Changes the order that rules 2308are evaluated, e.g.: pass alert log activation. \\ 2309 2310\hline 2311\texttt{config pcre\_match\_limit: $<$integer$>$} & Restricts the amount of 2312backtracking a given PCRE option. For example, it will limit the number of 2313nested repeats within a pattern. A value of -1 allows for unlimited PCRE, up 2314to the PCRE library compiled limit (around 10 million). A value of 0 results 2315in no PCRE evaluation. The snort default value is 1500. \\ 2316 2317\hline 2318\texttt{config pcre\_match\_limit\_recursion: $<$integer$>$} & Restricts the 2319amount of stack used by a given PCRE option. A value of -1 allows for 2320unlimited PCRE, up to the PCRE library compiled limit (around 10 million). A 2321value of 0 results in no PCRE evaluation. The snort default value is 1500. 2322This option is only useful if the value is less than the 2323\texttt{pcre\_match\_limit} \\ 2324 2325\hline 2326\texttt{config pkt\_count: <N>} & Exits after N packets (\texttt{snort -n}). \\ 2327 2328\hline 2329\texttt{config policy\_version: $<$base-version-string$>$ [$<$binding-version-string$>$]} & 2330Supply versioning information to configuration files. Base version should be 2331a string in all configuration files including included ones. In addition, 2332binding version must be in any file configured with \texttt{config binding}. 2333This option is used to avoid race conditions when modifying and loading a 2334configuration within a short time span - before Snort has had a chance to 2335load a previous configuration. \\ 2336 2337\hline 2338\texttt{config profile\_preprocs} & Print statistics on preprocessor 2339performance. See Section \ref{preproc profiling} for more details. \\ 2340 2341 2342\hline 2343\texttt{config profile\_rules} & Print statistics on rule performance. See 2344Section \ref{rule profiling} for more details. \\ 2345 2346\hline 2347\texttt{config protected\_content: 2348md5|sha256|sha512} & Specifies a default algorithm to use for protected\_content rules. \\ 2349 2350\hline 2351\texttt{config quiet}& Disables banner and status reports (\texttt{snort -q}). 2352NOTE: The command line switch \texttt{-q} takes effect immediately after 2353processing the command line parameters, whereas using \texttt{config quiet} 2354in snort.conf takes effect when the configuration line in snort.conf is parsed. 2355That may occur after other configuration settings that result in output to 2356console or syslog. 2357\\ 2358 2359\hline 2360\texttt{config reference: <ref>} & Adds a new reference system to Snort, e.g.: 2361myref http://myurl.com/?id=\\ 2362 2363\hline 2364\texttt{config reference\_net <cidr>} & For IP obfuscation, the obfuscated net 2365will be used if the packet contains an IP address in the reference net. Also 2366used to determine how to set up the logging directory structure for the 2367\texttt{session} post detection rule option and ASCII output plugin - an 2368attempt is made to name the log directories after the IP address that is not in 2369the reference net. \\ 2370 2371\hline \texttt{config response: [attempts <count>] [, device <dev>]} & Set the 2372number of strafing attempts per injected response and/or the device, such as 2373eth0, from which to send responses. These options may appear in any order but 2374must be comma separated. The are intended for passive mode. \\ 2375 2376\hline 2377\texttt{config set\_gid: <gid>} & Changes GID to specified GID (\texttt{snort 2378-g}). \\ 2379 2380\hline 2381\texttt{config set\_uid: <uid>} & Sets UID to $<$id$>$ (\texttt{snort -u}). \\ 2382 2383\hline 2384\texttt{config show\_year} & Shows year in timestamps (\texttt{snort -y}). \\ 2385 2386\hline 2387\texttt{config snaplen: <bytes>} & Set the snaplength of packet, same effect as 2388\texttt{-P $<$snaplen$>$} or \texttt{--snaplen $<$snaplen$>$} options.\\ 2389 2390\hline 2391\texttt{config so\_rule\_memcap: <bytes>} & Set global memcap in bytes for 2392so rules that dynamically allocate memory for storing session data in the 2393stream preprocessor. A value of 0 disables the memcap. Default is 0. 2394Maximum value is the maximum value an unsigned 32 bit integer can hold 2395which is 4294967295 or 4GB.\\ 2396 2397\hline 2398\texttt{config stateful} & Sets assurance mode for stream (stream is 2399established). \\ 2400 2401\hline 2402\texttt{config tagged\_packet\_limit: <max-tag>} & When a metric other than 2403\texttt{packets} is used in a tag option in a rule, this option sets the 2404maximum number of packets to be tagged regardless of the amount defined by the 2405other metric. See Section \ref{tag section} on using the tag option when 2406writing rules for more details. The default value when this option is not 2407configured is 256 packets. Setting this option to a value of 0 will disable 2408the packet limit. \\ 2409 2410\hline 2411\texttt{config threshold: memcap <bytes>} & Set global memcap in bytes for 2412thresholding. Default is 1048576 bytes (1 megabyte). (This is deprecated. 2413Use config event\_filter instead.)\\ 2414 2415\hline 2416\texttt{config umask: <umask>} & Sets umask when running (\texttt{snort -m}). \\ 2417 2418\hline 2419\texttt{config utc} & Uses UTC instead of local time for timestamps 2420(\texttt{snort -U}). \\ 2421 2422\hline 2423\texttt{config verbose} & Uses verbose logging to STDOUT (\texttt{snort -v}). 2424\\ 2425 2426\hline 2427\texttt{config vlan\_agnostic} & Causes Snort to ignore vlan headers for 2428the purposes of connection and frag tracking. This option is only valid in the 2429base configuration when using multiple configurations, and the default is off. 2430\\ 2431 2432\hline 2433\texttt{config address\_space\_agnostic} & Causes Snort to ignore DAQ 2434address space ID for the purposes of connection and frag tracking. This option 2435is only valid in the base configuration when using multiple configurations, and 2436the default is off. \\ 2437 2438\hline 2439\texttt{config policy\_mode: tap|inline|inline\_test} & Sets the policy 2440mode to either \texttt{passive}, \texttt{inline} or \texttt{inline\_test}. \\ 2441 2442\hline 2443\texttt{config disable\_replace} & Disables content replace option. Default 2444behaviour is to replace content. \\ 2445 2446\hline \texttt{config tunnel\_verdicts: gtp|teredo|6in4|4in6} & By default, whitelist 2447and blacklist verdicts are handled internally by Snort for GTP, Teredo, 6in4 and 4in6 2448encapsulated traffic. This means Snort actually gives the DAQ a pass or block 2449verdict instead. This is to workaround cases where the DAQ would apply 2450the verdict to the whole tunnel instead of the individual session within the 2451tunnel. If your DAQ decodes GTP, Teredo, 6in4 or 4in6 correctly, setting this config 2452will allow the whitelist or blacklist verdict to go to the DAQ. There is a 2453modest performance boost by doing this where possible since Snort won't see the 2454remaining packets on the session. \\ 2455 2456\hline 2457\end{longtable} 2458\end{center} 2459 2460\section{Preprocessors} 2461 2462Preprocessors were introduced in version 1.5 of Snort. They allow the 2463functionality of Snort to be extended by allowing users and programmers to drop 2464modular plugins into Snort fairly easily. Preprocessor code is run before the 2465detection engine is called, but after the packet has been decoded. The packet 2466can be modified or analyzed in an out-of-band manner using this mechanism. 2467 2468Preprocessors are loaded and configured using the {\tt preprocessor} keyword. 2469The format of the preprocessor directive in the Snort config file is: 2470 2471\begin{verbatim} 2472 preprocessor <name>: <options> 2473\end{verbatim} 2474 2475\subsection{Frag3} 2476\label{frag3 section} 2477 2478The frag3 preprocessor is a target-based IP defragmentation module for Snort. 2479Frag3 is designed with the following goals: 2480 2481\begin{slist} 2482\item Fast execution with less complex data management. 2483\item Target-based host modeling anti-evasion techniques. 2484\end{slist} 2485 2486Frag3 uses the sfxhash data structure and linked lists for data handling 2487internally which allows it to have much more predictable and deterministic 2488performance in any environment which should aid us in managing heavily 2489fragmented environments. 2490 2491Target-based analysis is a relatively new concept in network-based intrusion 2492detection. The idea of a target-based system is to model the actual targets on 2493the network instead of merely modeling the protocols and looking for attacks 2494within them. When IP stacks are written for different operating systems, they 2495are usually implemented by people who read the RFCs and then write their 2496interpretation of what the RFC outlines into code. Unfortunately, there are 2497ambiguities in the way that the RFCs define some of the edge conditions that 2498may occur and when this happens different people implement certain aspects of 2499their IP stacks differently. For an IDS this is a big problem. 2500 2501In an environment where the attacker can determine what style of IP 2502defragmentation is being used on a particular target, the attacker can try to 2503fragment packets such that the target will put them back together in a specific 2504manner while any passive systems trying to model the host traffic have to guess 2505which way the target OS is going to handle the overlaps and retransmits. As I 2506like to say, if the attacker has more information about the targets on a 2507network than the IDS does, it is possible to evade the IDS. This is where the 2508idea for ``target-based IDS'' came from. For more detail on this issue and how 2509it affects IDS, check out the famous Ptacek \& Newsham paper at 2510\url{http://www.snort.org/docs/idspaper/}. 2511 2512The basic idea behind target-based IDS is that we tell the IDS information 2513about hosts on the network so that it can avoid Ptacek \& Newsham style evasion 2514attacks based on information about how an individual target IP stack operates. 2515Vern Paxson and Umesh Shankar did a great paper on this very topic in 2003 that 2516detailed mapping the hosts on a network and determining how their various IP 2517stack implementations handled the types of problems seen in IP defragmentation 2518and TCP stream reassembly. Check it out at 2519\url{http://www.icir.org/vern/papers/activemap-oak03.pdf}. 2520 2521We can also present the IDS with topology information to avoid TTL-based 2522evasions and a variety of other issues, but that's a topic for another day. 2523Once we have this information we can start to really change the game for these 2524complex modeling problems. 2525 2526Frag3 was implemented to showcase and prototype a target-based module within 2527Snort to test this idea. 2528 2529\subsubsection{Frag 3 Configuration} 2530 2531There are at least two preprocessor directives required to activate frag3, 2532a global configuration directive and an engine instantiation. There can 2533be an arbitrary number of engines defined at startup with their own 2534configuration, but only one global configuration. 2535 2536\textbf{Global Configuration} 2537 2538\begin{itemize} 2539 2540\item Preprocessor name: \texttt{frag3\_global} 2541 2542\item Available options: NOTE: Global configuration options are comma 2543separated. 2544 2545\begin{itemize} 2546 2547\item \texttt{max\_frags $<$number$>$} - Maximum simultaneous fragments to 2548track. Default is 8192. 2549 2550\item \texttt{memcap $<$bytes$>$} - Memory cap for self preservation. Default 2551is 4MB. 2552 2553\item \texttt{prealloc\_memcap $<$bytes$>$} - alternate memory management mode, 2554use preallocated fragment nodes based on a memory cap (faster in some 2555situations). 2556 2557\item \texttt{prealloc\_frags $<$number$>$} - Alternate memory management mode, 2558use preallocated fragment nodes (faster in some situations). 2559 2560\item \texttt{disabled} - This optional keyword is allowed with any 2561policy to avoid packet processing. This option disables the preprocessor 2562for this config, but not for other instances of multiple configurations. 2563Use the disable keyword in the base configuration to specify values for the 2564options \texttt{memcap}, \texttt{prealloc\_memcap}, and \texttt{prealloc\_frags} 2565without having the preprocessor inspect traffic for traffic applying to the base 2566configuration. The other options are parsed but not used. Any valid 2567configuration may have "disabled" added to it. 2568 2569\end{itemize} 2570\end{itemize} 2571 2572\textbf{Engine Configuration} 2573 2574\begin{itemize} 2575 2576\item Preprocessor name: \texttt{frag3\_engine} 2577 2578\item Available options: 2579 NOTE: Engine configuration options are space separated. 2580 2581\begin{itemize} 2582 2583\item \texttt{timeout $<$seconds$>$} - Timeout for fragments. Fragments in the 2584engine for longer than this period will be automatically dropped. Default is 258560 seconds. 2586 2587\item \texttt{min\_ttl $<$value$>$} - Minimum acceptable TTL value for a 2588fragment packet. Default is 1. The accepted range for this option is 1 - 255. 2589 2590\item \texttt{detect\_anomalies} - Detect fragment anomalies. 2591 2592\item \texttt{bind\_to $<$ip\_list$>$} - IP List to bind this engine to. This 2593engine will only run for packets with destination addresses contained within 2594the IP List. Default value is \texttt{all}. 2595 2596\item \texttt{overlap\_limit <number>} - Limits the number of overlapping 2597fragments per packet. The default is "0" (unlimited). This config option takes 2598values equal to or greater than zero. This is an optional parameter. 2599detect\_anomalies option must be configured for this option to take effect. 2600 2601\item \texttt{min\_fragment\_length <number>} - Defines smallest fragment size 2602(payload size) that should be considered valid. Fragments smaller than or 2603equal to this limit are considered malicious and an event is raised, if 2604detect\_anomalies is also configured. The default is "0" (unlimited), the 2605minimum is "0". This is an optional parameter. detect\_anomalies option 2606must be configured for this option to take effect. 2607 2608\item \texttt{policy $<$type$>$} - Select a target-based defragmentation mode. 2609Available types are first, last, bsd, bsd-right, linux, windows and solaris. 2610Default type is bsd. 2611 2612The Paxson Active Mapping paper introduced the terminology frag3 is using to 2613describe policy types. The known mappings are as follows. Anyone who develops 2614more mappings and would like to add to this list please feel free to send us an 2615email! 2616 2617\begin{tabular}{| l | l |} 2618\hline 2619\textbf{Platform} & \textbf{Type}\\ 2620\hline 2621\hline 2622 AIX 2 & BSD \\ 2623 \hline 2624 AIX 4.3 8.9.3 & BSD \\ 2625 \hline 2626 Cisco IOS & Last \\ 2627 \hline 2628 FreeBSD & BSD\\ 2629 \hline 2630 HP JetDirect (printer) & BSD-right \\ 2631 \hline 2632 HP-UX B.10.20 & BSD \\ 2633 \hline 2634 HP-UX 11.00 & First \\ 2635 \hline 2636 IRIX 4.0.5F & BSD \\ 2637 \hline 2638 IRIX 6.2 & BSD \\ 2639 \hline 2640 IRIX 6.3 & BSD \\ 2641 \hline 2642 IRIX64 6.4 & BSD \\ 2643 \hline 2644 Linux 2.2.10 & linux \\ 2645 \hline 2646 Linux 2.2.14-5.0 & linux \\ 2647 \hline 2648 Linux 2.2.16-3 & linux \\ 2649 \hline 2650 Linux 2.2.19-6.2.10smp & linux \\ 2651 \hline 2652 Linux 2.4.7-10 & linux \\ 2653 \hline 2654 Linux 2.4.9-31SGI 1.0.2smp & linux \\ 2655 \hline 2656 Linux 2.4 (RedHat 7.1-7.3) & linux \\ 2657 \hline 2658 MacOS (version unknown) & First \\ 2659 \hline 2660 NCD Thin Clients & BSD \\ 2661 \hline 2662 OpenBSD (version unknown) & linux \\ 2663 \hline 2664 OpenBSD (version unknown) & linux \\ 2665 \hline 2666 OpenVMS 7.1 & BSD \\ 2667 \hline 2668 OS/2 (version unknown) & BSD \\ 2669 \hline 2670 OSF1 V3.0 & BSD \\ 2671 \hline 2672 OSF1 V3.2 & BSD \\ 2673 \hline 2674 OSF1 V4.0,5.0,5.1 & BSD \\ 2675 \hline 2676 SunOS 4.1.4 & BSD \\ 2677 \hline 2678 SunOS 5.5.1,5.6,5.7,5.8 & First \\ 2679 \hline 2680 Tru64 Unix V5.0A,V5.1 & BSD \\ 2681 \hline 2682 Vax/VMS & BSD \\ 2683 \hline 2684 Windows (95/98/NT4/W2K/XP) & Windows\\ 2685\hline 2686\end{tabular} 2687 2688\end{itemize} 2689\end{itemize} 2690 2691\subsubsection{Format} 2692 2693Note in the advanced configuration below that there are three engines specified 2694running with \emph{Linux}, \texttt{first} and \texttt{last} policies assigned. 2695The first two engines are bound to specific IP address ranges and the last one 2696applies to all other traffic. Packets that don't fall within the address 2697requirements of the first two engines automatically fall through to the third 2698one. 2699 2700\paragraph{Basic Configuration} 2701\begin{verbatim} 2702 preprocessor frag3_global 2703 preprocessor frag3_engine 2704\end{verbatim} 2705 2706\paragraph{Advanced Configuration} 2707\begin{verbatim} 2708 preprocessor frag3_global: prealloc_nodes 8192 2709 preprocessor frag3_engine: policy linux bind_to 192.168.1.0/24 2710 preprocessor frag3_engine: policy first bind_to [10.1.47.0/24,172.16.8.0/24] 2711 preprocessor frag3_engine: policy last detect_anomalies 2712\end{verbatim} 2713 2714\subsubsection{Frag 3 Alert Output} 2715\label{frag3 alert output} 2716 2717Frag3 is capable of detecting eight different types of anomalies. Its event 2718output is packet-based so it will work with all output modes of Snort. Read 2719the documentation in the \texttt{doc/signatures} directory with filenames that 2720begin with ``123-'' for information on the different event types. 2721 2722%%Need to doc these eight types of anomalies and truncate beginning of section. 2723 2724\subsection{Session} 2725\label{session section} 2726 2727The Session preprocessor is a global stream session management module 2728for Snort. It is derived from the session management functions that 2729were part of the Stream5 preprocessor. 2730 2731Since Session implements part of the functionality and API that was 2732previously in Stream5 it cannot be used with Stream5 but must be 2733used in conjunction with the new Stream preprocessor. Similarly, 2734due to the API changes, the other preprocessors in Snort 2.9.7 work 2735only with the new Session and Stream preprocessers. 2736 2737\subsubsection{Session API} 2738 2739Session provides an API to enable the creation and management of 2740the session control block for a flow and the management of data 2741and state that may be associated with that flow by service and 2742application preprocessors (most of these functions were previously 2743supported by the Stream5 API). These methods are called to identify 2744sessions that may be ignored (large data transfers, etc), and 2745update the identifying information about the session (application 2746protocol, direction, etc) that can later be used by rules. 2747API methods to enable preprocessors to register for dispatch for 2748ports and services for which they should be called to process 2749the packet have been added to the Session API. Session is required 2750for the use of the 'flow' and 'flowbits' keywords. 2751 2752\subsubsection{Session Global Configuration} 2753 2754Global settings for the Session preprocessor. 2755 2756\begin{verbatim} 2757 preprocessor stream5_global: \ 2758 [track_tcp <yes|no>], [max_tcp <number>], \ 2759 [memcap <number bytes>], \ 2760 [track_udp <yes|no>], [max_udp <number>], \ 2761 [track_icmp <yes|no>], [max_icmp <number>], \ 2762 [track_ip <yes|no>], [max_ip <number>], \ 2763 [flush_on_alert], [show_rebuilt_packets], \ 2764 [prune_log_max <number bytes>], [disabled], \ 2765 [enable_ha] 2766\end{verbatim} 2767 2768\begin{center} 2769\begin{tabular}{| l | p{4.5in} |} 2770 2771\hline 2772\textbf{Option} & \textbf{Description}\\ 2773\hline 2774 2775\hline 2776\texttt{track\_tcp <yes|no>} & 2777 2778Track sessions for TCP. The default is "yes".\\ 2779 2780\hline 2781\texttt{max\_tcp <num sessions>} & 2782 2783Maximum simultaneous TCP sessions tracked. The default is "262144", maximum is 2784"1048576", minimum is "2".\\ 2785 2786\hline 2787\texttt{memcap <num bytes>} & 2788 2789Memcap for TCP packet storage. The default is "8388608" (8MB), maximum is 2790"1073741824" (1GB), minimum is "32768" (32KB).\\ 2791 2792\hline 2793\texttt{track\_udp <yes|no>} & 2794 2795Track sessions for UDP. The default is "yes".\\ 2796 2797\hline 2798\texttt{max\_udp <num sessions>} & 2799 2800Maximum simultaneous UDP sessions tracked. The default is "131072", maximum is 2801"1048576", minimum is "1".\\ 2802 2803\hline 2804\texttt{track\_icmp <yes|no>} & 2805 2806Track sessions for ICMP. The default is "no".\\ 2807 2808\hline 2809\texttt{max\_icmp <num sessions>} & 2810 2811Maximum simultaneous ICMP sessions tracked. The default is "65536", maximum is 2812"1048576", minimum is "1".\\ 2813 2814\hline 2815\texttt{track\_ip <yes|no>} & 2816 2817Track sessions for IP. The default is "no". Note that "IP" includes all 2818non-TCP/UDP traffic over IP including ICMP if ICMP not otherwise configured.\\ 2819 2820\hline 2821\texttt{max\_ip <num sessions>} & 2822 2823Maximum simultaneous IP sessions tracked. The default is "16384", maximum is 2824"1048576", minimum is "1".\\ 2825 2826\hline 2827\texttt{disabled} & 2828 2829Option to disable the stream5 tracking. By default this option is turned off. 2830When the preprocessor is disabled only the options memcap, max\_tcp, max\_udp 2831and max\_icmp are applied when specified with the configuration.\\ 2832 2833\hline 2834\texttt{flush\_on\_alert} & 2835 2836Backwards compatibility. Flush a TCP stream when an alert is generated on that 2837stream. The default is set to off.\\ 2838 2839\hline 2840\texttt{show\_rebuilt\_packets} & 2841 2842Print/display packet after rebuilt (for debugging). The default is set to 2843off.\\ 2844 2845\hline 2846\texttt{prune\_log\_max <num bytes>} & 2847 2848Print a message when a session terminates that was consuming more than the 2849specified number of bytes. The default is "1048576" (1MB), minimum can be either "0" 2850(disabled) or if not disabled the minimum is "1024" and maximum is "1073741824".\\ 2851 2852\hline 2853\texttt{enable\_ha} & 2854 2855 2856Enable High Availability state sharing. The default is set to off.\\ 2857 2858\hline 2859\end{tabular} 2860\end{center} 2861 2862\subsubsection{Session HA Configuration} 2863 2864Configuration for HA session state sharing. 2865 2866\begin{verbatim} 2867 preprocessor stream5_ha: [min_session_lifetime <num millisecs>], \ 2868 [min_sync_interval <num millisecs>], [startup_input_file <filename>], \ 2869 [runtime_output_file <filename>], [use_side_channel] 2870\end{verbatim} 2871 2872\begin{center} 2873\begin{tabular}{| l | p{4.5in} |} 2874 2875\hline 2876\textbf{Option} & \textbf{Description}\\ 2877\hline 2878 2879\hline 2880\texttt{min\_session\_lifetime <num millisecs>} & 2881 2882Minimum session liftime in milliseconds. HA update messages will only be generated once a session has existed for 2883at least this long. The default is 0, the minimum is 0, and the maximum is 65535.\\ 2884 2885\hline 2886\texttt{min\_sync\_interval <num millisecs>} & 2887 2888Minimum synchronization interval in milliseconds. HA update messages will not be generated more often than 2889once per interval on a given session. The default is 0, the minimum is 0, and the maximum is 65535.\\ 2890 2891\hline 2892\texttt{startup\_input\_file <filename>} & 2893 2894The name of a file for snort to read HA messages from at startup.\\ 2895 2896\hline 2897\texttt{runtime\_output\_file <filename>} & 2898 2899The name of a file to which Snort will write all HA messages that are generated while it is running.\\ 2900 2901\hline 2902\texttt{use\_side\_channel} & 2903 2904Indicates that all HA messages should also be sent to the side channel for processing.\\ 2905 2906\hline 2907\end{tabular} 2908\end{center} 2909 2910\subsubsection{Example Configurations} 2911 2912\begin{enumerate} 2913 2914\item{} 2915 2916This example configuration sets a maximum number of TCP session control blocks to 8192, 2917enables tracking of TCP and UPD sessions, and disables tracking of ICMP sessions. The 2918number of UDP session control blocks will be set to the compiled default. 2919 2920\begin{verbatim} 2921 preprocessor stream5_global: \ 2922 max_tcp 8192, track_tcp yes, track_udp yes, track_icmp no 2923 2924 preprocessor stream5_tcp: \ 2925 policy first, use_static_footprint_sizes 2926 2927 preprocessor stream5_udp: \ 2928 ignore_any_rules 2929\end{verbatim} 2930 2931\end{enumerate} 2932 2933 2934 2935\subsection{Stream} 2936\label{stream5 section} 2937 2938The Stream preprocessor is a target-based TCP reassembly module for Snort. It 2939is capable of tracking sessions for both TCP and UDP. 2940 2941\subsubsection{Transport Protocols} 2942 2943TCP sessions are identified via the classic TCP "connection". UDP sessions are 2944established as the result of a series of UDP packets from two end points via 2945the same set of ports. ICMP messages are tracked for the purposes of checking 2946for unreachable and service unavailable messages, which effectively terminate a 2947TCP or UDP session. 2948 2949\subsubsection{Target-Based} 2950 2951Stream, like Frag3, introduces target-based actions for handling of 2952overlapping data and other TCP anomalies. The methods for handling overlapping 2953data, TCP Timestamps, Data on SYN, FIN and Reset sequence numbers, etc. and the 2954policies supported by Stream are the results of extensive research with many 2955target operating systems. 2956 2957\subsubsection{Stream API} 2958 2959Stream supports the modified Stream API that is now focused on 2960functions specific to reassembly and protocol aware flushing 2961operations. Session management functions have been moved to the 2962Session API. The remaining API functions enable other protocol 2963normalizers/preprocessors to dynamically configure reassembly 2964behavior as required by the application layer protocol. 2965 2966\subsubsection{Anomaly Detection} 2967 2968TCP protocol anomalies, such as data on SYN packets, data received outside the 2969TCP window, etc are configured via the \texttt{detect\_anomalies} option to the 2970TCP configuration. Some of these anomalies are detected on a per-target basis. 2971For example, a few operating systems allow data in TCP SYN packets, while 2972others do not. 2973 2974\subsubsection{Protocol Aware Flushing} 2975 2976Protocol aware flushing of HTTP, SMB and DCE/RPC can be enabled with this option: 2977 2978\begin{verbatim} 2979config paf_max: <max-pdu> 2980\end{verbatim} 2981 2982where \texttt{<max-pdu>} is between zero (off) and 63780. This allows Snort to 2983statefully scan a stream and reassemble a complete PDU regardless of 2984segmentation. For example, multiple PDUs within a single TCP segment, as well 2985as one PDU spanning multiple TCP segments will be reassembled into one PDU per 2986packet for each PDU. PDUs larger than the configured maximum will be split 2987into multiple packets. 2988 2989\subsubsection{Stream TCP Configuration} 2990 2991Provides a means on a per IP address target to configure TCP policy. This can 2992have multiple occurrences, per policy that is bound to an IP address or network. 2993One default policy must be specified, and that policy is not bound to an IP 2994address or network. 2995 2996\begin{verbatim} 2997 preprocessor stream5_tcp: \ 2998 [log_asymmetric_traffic <yes|no>], \ 2999 [bind_to <ip_addr>], \ 3000 [timeout <number secs>], [policy <policy_id>], \ 3001 [overlap_limit <number>], [max_window <number>], \ 3002 [require_3whs [<number secs>]], [detect_anomalies], \ 3003 [check_session_hijacking], [use_static_footprint_sizes], \ 3004 [dont_store_large_packets], [dont_reassemble_async], \ 3005 [max_queued_bytes <bytes>], [max_queued_segs <number segs>], \ 3006 [small_segments <number> bytes <number> [ignore_ports number [number]*]], \ 3007 [ports <client|server|both> <all|number|!number [number]* [!number]*>], \ 3008 [protocol <client|server|both> <all|service name [service name]*>], \ 3009 [ignore_any_rules], [flush_factor <number segs>] 3010\end{verbatim} 3011 3012\begin{longtable}[h]{| p{2in} | p{4in} |} 3013 3014\hline 3015\textbf{Option} & \textbf{Description}\\ 3016\hline 3017 3018\hline 3019\texttt{bind\_to <ip\_addr>} & 3020 3021IP address or network for this policy. The default is set to any.\\ 3022 3023\hline 3024\texttt{timeout <num seconds>} & 3025 3026Session timeout. The default is "30", the minimum is "1", and the maximum is 3027"86400" (approximately 1 day).\\ 3028 3029\hline 3030\texttt{policy <policy\_id>} & 3031 3032The Operating System policy for the target OS. The policy\_id can be one of 3033the following: 3034 3035\begin{tabular}{| l | p{2.5in} |} 3036\hline 3037Policy Name & Operating Systems.\\ 3038\hline 3039 3040\hline 3041\texttt{first} & 3042 3043Favor first overlapped segment.\\ 3044 3045\hline 3046\texttt{last} & Favor last overlapped segment.\\ 3047 3048\hline 3049\texttt{bsd} & FresBSD 4.x and newer, NetBSD 2.x and newer, OpenBSD 3.x and newer\\ 3050 3051\hline 3052\texttt{linux} & Linux 2.4 and newer\\ 3053 3054\hline 3055\texttt{old-linux} & Linux 2.2 and earlier\\ 3056 3057\hline 3058\texttt{windows} & Windows 2000, Windows XP, Windows 95/98/ME\\ 3059 3060\hline 3061\texttt{win2003} & Windows 2003 Server\\ 3062 3063\hline 3064\texttt{vista} & Windows Vista\\ 3065 3066\hline 3067\texttt{solaris} & Solaris 9.x and newer\\ 3068 3069\hline 3070\texttt{hpux} & HPUX 11 and newer\\ 3071 3072\hline 3073\texttt{hpux10} & HPUX 10\\ 3074 3075\hline 3076\texttt{irix} & IRIX 6 and newer\\ 3077 3078\hline 3079\texttt{macos} & MacOS 10.3 and newer\\ 3080 3081\hline 3082\end{tabular}\\ 3083 3084\hline 3085\texttt{overlap\_limit <number>} & 3086 3087Limits the number of overlapping packets per session. The default is "0" 3088(unlimited), the minimum is "0", and the maximum is "255".\\ 3089 3090\hline 3091\texttt{max\_window <number>} & 3092 3093Maximum TCP window allowed. The default is "0" (unlimited), the minimum is 3094"0", and the maximum is "1073725440" (65535 left shift 14). That is the 3095highest possible TCP window per RFCs. This option is intended to prevent a DoS 3096against Stream by an attacker using an abnormally large window, so using a 3097value near the maximum is discouraged.\\ 3098 3099\hline 3100\texttt{require\_3whs [<number seconds>]} & 3101 3102Establish sessions only on completion of a SYN/SYN-ACK/ACK handshake. The 3103default is set to off. The optional number of seconds specifies a startup 3104timeout. This allows a grace period for existing sessions to be considered 3105established during that interval immediately after Snort is started. The 3106default is "0" (don't consider existing sessions established), the minimum is 3107"0", and the maximum is "86400" (approximately 1 day).\\ 3108 3109\hline 3110\texttt{detect\_anomalies} & 3111 3112Detect and alert on TCP protocol anomalies. The default is set to off.\\ 3113 3114\hline 3115\texttt{check\_session\_hijacking} & 3116 3117Check for TCP session hijacking. This check validates the hardware (MAC) 3118address from both sides of the connect -- as established on the 3-way handshake 3119against subsequent packets received on the session. If an ethernet layer is 3120not part of the protocol stack received by Snort, there are no checks 3121performed. Alerts are generated (per '\texttt{detect\_anomalies}' option) for 3122either the client or server when the MAC address for one side or the other does 3123not match. The default is set to off.\\ 3124 3125\hline 3126\texttt{use\_static\_footprint\_sizes} & 3127 3128Use static values for determining when to build a reassembled packet to 3129allow for repeatable tests. This option should not be used production 3130environments. The default is set to off.\\ 3131 3132\hline 3133\texttt{dont\_store\_large\_packets} & 3134 3135Performance improvement to not queue large packets in reassembly buffer. The 3136default is set to off. Using this option may result in missed attacks.\\ 3137 3138\hline 3139\texttt{dont\_reassemble\_async} & 3140 3141Don't queue packets for reassembly if traffic has not been seen in both 3142directions. The default is set to queue packets.\\ 3143 3144\hline 3145\texttt{max\_queued\_bytes <bytes>} & 3146 3147Limit the number of bytes queued for reassembly on a given TCP session to 3148bytes. Default is "1048576" (1MB). A value of "0" means unlimited, with a 3149non-zero minimum of "1024", and a maximum of "1073741824" (1GB). A message is 3150written to console/syslog when this limit is enforced.\\ 3151 3152\hline 3153\texttt{max\_queued\_segs <num>} & 3154 3155Limit the number of segments queued for reassembly on a given TCP session. The 3156default is "2621", derived based on an average size of 400 bytes. A value of 3157"0" means unlimited, with a non-zero minimum of "2", and a maximum of 3158"1073741824" (1GB). A message is written to console/syslog when this limit is 3159enforced.\\ 3160 3161\hline 3162\texttt{small\_segments <number> bytes <number> [ignore\_ports <number(s)> ]} & 3163 3164Configure the maximum small segments queued. This feature requires that 3165detect\_anomalies be enabled. The first number is the number of consecutive segments 3166that will trigger the detection rule. The default value is "0" (disabled), with a 3167maximum of "2048". The second number is the minimum bytes for a segment to be 3168considered "small". The default value is "0" (disabled), with a maximum of "2048". 3169ignore\_ports is optional, defines the list of ports in which will be ignored for 3170this rule. The number of ports can be up to "65535". A message is written to 3171console/syslog when this limit is enforced.\\ 3172 3173\hline 3174\texttt{ports <client|server|both> <all|number(s)|!number(s)>} & 3175 3176 3177Specify the client, server, or both and list of ports in which to perform 3178reassembly. This can appear more than once in a given config. The default 3179settings are \texttt{ports client 21 23 25 42 53 80 110 111 135 136 137 139 143 3180445 513 514 1433 1521 2401 3306}. The minimum port allowed is "1" and the 3181maximum allowed is "65535". To disable reassembly for a port specifiy the port 3182number preceeded by an '!', e.g. !8080 !25\\ 3183 3184\hline 3185\texttt{protocol <client|server|both> <all|service name(s)>} & 3186 3187 3188Specify the client, server, or both and list of services in which to perform 3189reassembly. This can appear more than once in a given config. The default 3190settings are \texttt{ports client ftp telnet smtp nameserver dns http pop3 3191sunrpc dcerpc netbios-ssn imap login shell mssql oracle cvs mysql}. The 3192service names can be any of those used in the host attribute table (see 3193\ref{targetbased}), including any of the internal defaults (see 3194\ref{attribute:service names}) or others specific to the network.\\ 3195 3196\hline 3197\texttt{ignore\_any\_rules} & 3198 3199Don't process any \texttt{->} any (ports) rules for TCP that attempt to match 3200payload if there are no port specific rules for the src or destination port. 3201Rules that have flow or flowbits will never be ignored. This is a performance 3202improvement and may result in missed attacks. Using this does not affect rules 3203that look at protocol headers, only those with content, PCRE, or byte test 3204options. The default is "off". This option can be used only in default 3205policy.\\ 3206 3207\hline 3208\texttt{flush\_factor} & 3209 3210Useful in ips mode to flush upon seeing a drop in segment size after N 3211segments of non-decreasing size. The drop in size often indicates an 3212end of request or response.\\ 3213 3214\hline 3215\end{longtable} 3216 3217\begin{note} 3218 3219If no options are specified for a given TCP policy, that is the default TCP 3220policy. If only a bind\_to option is used with no other options that TCP 3221policy uses all of the default values. 3222 3223\end{note} 3224 3225\subsubsection{Stream UDP Configuration} 3226 3227Configuration for UDP session tracking. Since there is no target based 3228binding, there should be only one occurrence of the UDP configuration. 3229 3230\begin{verbatim} 3231 preprocessor stream5_udp: [timeout <number secs>], [ignore_any_rules] 3232\end{verbatim} 3233 3234\begin{center} 3235\begin{tabular}{| l | p{4.5in} |} 3236 3237\hline 3238\textbf{Option} & \textbf{Description}\\ 3239\hline 3240 3241\hline 3242\texttt{timeout <num seconds>} & 3243 3244Session timeout. The default is "30", the minimum is "1", and the maximum is 3245"86400" (approximately 1 day).\\ 3246 3247\hline 3248\texttt{ignore\_any\_rules} & 3249 3250Don't process any \texttt{->} any (ports) rules for UDP that attempt to match 3251payload if there are no port specific rules for the src or destination port. 3252Rules that have flow or flowbits will never be ignored. This is a performance 3253improvement and may result in missed attacks. Using this does not affect rules 3254that look at protocol headers, only those with content, PCRE, or byte test 3255options. The default is "off".\\ 3256 3257\hline 3258\end{tabular} 3259\end{center} 3260 3261\begin{note} 3262 3263With the ignore\_any\_rules option, a UDP rule will be ignored except when 3264there is another port specific rule that may be applied to the traffic. For 3265example, if a UDP rule specifies destination port 53, the 'ignored' any 3266\texttt{->} any rule will be applied to traffic to/from port 53, but NOT to any 3267other source or destination port. A list of rule SIDs affected by this option 3268are printed at Snort's startup. 3269 3270\end{note} 3271 3272\begin{note} 3273 3274With the ignore\_any\_rules option, if a UDP rule that uses any \texttt{->} any 3275ports includes either flow or flowbits, the ignore\_any\_rules option is 3276effectively pointless. Because of the potential impact of disabling a flowbits 3277rule, the ignore\_any\_rules option will be disabled in this case. 3278 3279\end{note} 3280 3281\subsubsection{Stream ICMP Configuration} 3282 3283Configuration for ICMP session tracking. Since there is no target based 3284binding, there should be only one occurrence of the ICMP configuration. 3285 3286\begin{note} 3287 3288ICMP is currently untested, in minimal code form and is NOT ready for use in 3289production networks. It is not turned on by default. 3290 3291\end{note} 3292 3293\begin{verbatim} 3294 preprocessor stream5_icmp: [timeout <number secs>] 3295\end{verbatim} 3296 3297\begin{center} 3298\begin{tabular}{| l | p{4.5in} |} 3299 3300\hline 3301\textbf{Option} & \textbf{Description}\\ 3302\hline 3303 3304\hline 3305\texttt{timeout <num seconds>} & 3306 3307Session timeout. The default is "30", the minimum is "1", and the maximum is 3308"86400" (approximately 1 day).\\ 3309 3310\hline 3311\end{tabular} 3312\end{center} 3313 3314\subsubsection{Stream IP Configuration} 3315 3316Configuration for IP session tracking. Since there is no target based 3317binding, there should be only one occurrence of the IP configuration. 3318 3319\begin{note} 3320 3321"IP" includes all non-TCP/UDP traffic over IP including ICMP if ICMP 3322not otherwise configured. It is not turned on by default. 3323 3324\end{note} 3325 3326\begin{verbatim} 3327 preprocessor stream5_ip: [timeout <number secs>] 3328\end{verbatim} 3329 3330\begin{center} 3331\begin{tabular}{| l | p{4.5in} |} 3332 3333\hline 3334\textbf{Option} & \textbf{Description}\\ 3335\hline 3336 3337\hline 3338\texttt{timeout <num seconds>} & 3339 3340Session timeout. The default is "30", the minimum is "1", and the maximum is 3341"86400" (approximately 1 day).\\ 3342 3343\hline 3344\end{tabular} 3345\end{center} 3346 3347\subsubsection{Example Configurations} 3348 3349\begin{enumerate} 3350 3351\item{} 3352 3353This example configuration is the default configuration in snort.conf and 3354can be used for repeatable tests of stream reassembly in readback mode. 3355 3356\begin{verbatim} 3357 preprocessor stream5_global: \ 3358 max_tcp 8192, track_tcp yes, track_udp yes, track_icmp no 3359 3360 preprocessor stream5_tcp: \ 3361 policy first, use_static_footprint_sizes 3362 3363 preprocessor stream5_udp: \ 3364 ignore_any_rules 3365\end{verbatim} 3366 3367\item{} 3368 3369This configuration maps two network segments to different OS policies, one for 3370Windows and one for Linux, with all other traffic going to the default policy 3371of Solaris. 3372 3373\begin{verbatim} 3374 preprocessor stream5_global: track_tcp yes 3375 preprocessor stream5_tcp: bind_to 192.168.1.0/24, policy windows 3376 preprocessor stream5_tcp: bind_to 10.1.1.0/24, policy linux 3377 preprocessor stream5_tcp: policy solaris 3378\end{verbatim} 3379 3380\end{enumerate} 3381 3382\subsection{sfPortscan} 3383 3384The sfPortscan module, developed by Sourcefire, is designed to detect the first 3385phase in a network attack: Reconnaissance. In the Reconnaissance phase, an 3386attacker determines what types of network protocols or services a host 3387supports. This is the traditional place where a portscan takes place. This 3388phase assumes the attacking host has no prior knowledge of what protocols or 3389services are supported by the target; otherwise, this phase would not be 3390necessary. 3391 3392As the attacker has no beforehand knowledge of its intended target, most 3393queries sent by the attacker will be negative (meaning that the service ports 3394are closed). In the nature of legitimate network communications, negative 3395responses from hosts are rare, and rarer still are multiple negative responses 3396within a given amount of time. Our primary objective in detecting portscans is 3397to detect and track these negative responses. 3398 3399One of the most common portscanning tools in use today is Nmap. Nmap 3400encompasses many, if not all, of the current portscanning techniques. 3401sfPortscan was designed to be able to detect the different types of scans Nmap 3402can produce. 3403 3404sfPortscan will currently alert for the following types of Nmap scans: 3405 3406\begin{itemize} 3407\item TCP Portscan 3408\item UDP Portscan 3409\item IP Portscan 3410\end{itemize} 3411 3412These alerts are for one$\rightarrow$one portscans, which are the traditional 3413types of scans; one host scans multiple ports on another host. Most of the port 3414queries will be negative, since most hosts have relatively few services 3415available. 3416 3417sfPortscan also alerts for the following types of decoy portscans: 3418 3419\begin{itemize} 3420\item TCP Decoy Portscan 3421\item UDP Decoy Portscan 3422\item IP Decoy Portscan 3423\end{itemize} 3424 3425Decoy portscans are much like the Nmap portscans described above, only the 3426attacker has a spoofed source address inter-mixed with the real scanning 3427address. This tactic helps hide the true identity of the attacker. 3428 3429sfPortscan alerts for the following types of distributed portscans: 3430 3431\begin{itemize} 3432\item TCP Distributed Portscan 3433\item UDP Distributed Portscan 3434\item IP Distributed Portscan 3435\end{itemize} 3436 3437These are many$\rightarrow$one portscans. Distributed portscans occur when 3438multiple hosts query one host for open services. This is used to evade an IDS 3439and obfuscate command and control hosts. 3440 3441\begin{note} 3442 3443Negative queries will be distributed among scanning hosts, so we track this 3444type of scan through the scanned host. 3445 3446\end{note} 3447 3448sfPortscan alerts for the following types of portsweeps: 3449 3450\begin{itemize} 3451\item TCP Portsweep 3452\item UDP Portsweep 3453\item IP Portsweep 3454\item ICMP Portsweep 3455\end{itemize} 3456 3457These alerts are for one$\rightarrow$many portsweeps. One host scans a single 3458port on multiple hosts. This usually occurs when a new exploit comes out and 3459the attacker is looking for a specific service. 3460 3461\begin{note} 3462 3463The characteristics of a portsweep scan may not result in many negative 3464responses. For example, if an attacker portsweeps a web farm for port 80, we 3465will most likely not see many negative responses. 3466 3467\end{note} 3468 3469sfPortscan alerts on the following filtered portscans and portsweeps: 3470 3471\begin{itemize} 3472\item TCP Filtered Portscan 3473\item UDP Filtered Portscan 3474\item IP Filtered Portscan 3475 3476\item TCP Filtered Decoy Portscan 3477\item UDP Filtered Decoy Portscan 3478\item IP Filtered Decoy Portscan 3479 3480\item TCP Filtered Portsweep 3481\item UDP Filtered Portsweep 3482\item IP Filtered Portsweep 3483\item ICMP Filtered Portsweep 3484 3485\item TCP Filtered Distributed Portscan 3486\item UDP Filtered Distributed Portscan 3487\item IP Filtered Distributed Portscan 3488\end{itemize} 3489 3490``Filtered'' alerts indicate that there were no network errors (ICMP 3491unreachables or TCP RSTs) or responses on closed ports have been suppressed. 3492It's also a good indicator of whether the alert is just a very active 3493legitimate host. Active hosts, such as NATs, can trigger these alerts because 3494they can send out many connection attempts within a very small amount of time. 3495A filtered alert may go off before responses from the remote hosts are 3496received. 3497 3498sfPortscan only generates one alert for each host pair in question during the 3499time window (more on windows below). On TCP scan alerts, sfPortscan will also 3500display any open ports that were scanned. On TCP sweep alerts however, 3501sfPortscan will only track open ports after the alert has been triggered. Open 3502port events are not individual alerts, but tags based on the original scan 3503alert. 3504 3505\subsubsection{sfPortscan Configuration} 3506 3507Use of the Stream preprocessor is required for sfPortscan. Stream gives 3508portscan direction in the case of connectionless protocols like ICMP and UDP. 3509You should enable the Stream preprocessor in your \texttt{snort.conf}, as 3510described in Section \ref{stream5 section}. 3511 3512The parameters you can use to configure the portscan module are: 3513 3514\begin{slist} 3515\item \textbf{proto $<$protocol$>$} 3516 3517Available options: 3518 3519\begin{itemize} 3520\item \texttt{TCP} 3521\item \texttt{UDP} 3522\item \texttt{ICMP} 3523\item \texttt{ip\_proto} 3524\item \texttt{all} 3525\end{itemize} 3526 3527\item \textbf{scan\_type $<$scan\_type$>$} 3528 3529Available options: 3530 3531\begin{itemize} 3532\item \texttt{portscan} 3533\item \texttt{portsweep} 3534\item \texttt{decoy\_portscan} 3535\item \texttt{distributed\_portscan} 3536\item \texttt{all} 3537\end{itemize} 3538 3539\item \textbf{sense\_level $<$level$>$} 3540 3541Available options: 3542 3543\begin{itemize} 3544 3545\item \texttt{low} - ``Low'' alerts are only generated on error packets sent 3546from the target host, and because of the nature of error responses, this 3547setting should see very few false positives. However, this setting will never 3548trigger a Filtered Scan alert because of a lack of error responses. This 3549setting is based on a static time window of 60 seconds, after which this window 3550is reset. 3551 3552\item \texttt{medium} - ``Medium'' alerts track connection counts, and so will 3553generate filtered scan alerts. This setting may false positive on active hosts 3554(NATs, proxies, DNS caches, etc), so the user may need to deploy the use of 3555Ignore directives to properly tune this directive. 3556 3557\item \texttt{high} - ``High'' alerts continuously track hosts on a network 3558using a time window to evaluate portscan statistics for that host. A "High" 3559setting will catch some slow scans because of the continuous monitoring, but is 3560very sensitive to active hosts. This most definitely will require the user to 3561tune sfPortscan. 3562 3563\end{itemize} 3564 3565\item \textbf{watch\_ip $<$ip1$|$ip2/cidr[ [port$|$port2-port3]]$>$ } 3566 3567Defines which IPs, networks, and specific ports on those hosts to watch. The 3568list is a comma separated list of IP addresses, IP address using CIDR notation. 3569Optionally, ports are specified after the IP address/CIDR using a space and can 3570be either a single port or a range denoted by a dash. IPs or networks not 3571falling into this range are ignored if this option is used. 3572 3573\item \textbf{ignore\_scanners $<$ip1$|$ip2/cidr[ [port$|$port2-port3]]$>$ } 3574 3575Ignores the source of scan alerts. The parameter is the same format as that of 3576\texttt{watch\_ip}. 3577 3578\item \textbf{ignore\_scanned $<$ip1$|$ip2/cidr[ [port$|$port2-port3]]$>$ } 3579 3580Ignores the destination of scan alerts. The parameter is the same format as 3581that of \texttt{watch\_ip}. 3582 3583\item \textbf{logfile $<$file$>$ } 3584 3585This option will output portscan events to the file specified. If \texttt{file} 3586does not contain a leading slash, this file will be placed in the Snort config 3587dir. 3588 3589\item \textbf{include\_midstream} 3590 3591This option will include sessions picked up in midstream by Stream. 3592This can lead to false alerts, especially under heavy load with dropped 3593packets; which is why the option is off by default. 3594 3595\item \textbf{detect\_ack\_scans} 3596 3597This option will include sessions picked up in midstream by the stream module, 3598which is necessary to detect ACK scans. However, this can lead to false 3599alerts, especially under heavy load with dropped packets; which is why the 3600option is off by default. 3601 3602\item \textbf{disabled} 3603 3604This optional keyword is allowed with any policy to avoid packet processing. 3605This option disables the preprocessor. When the preprocessor is disabled 3606only the memcap option is applied when specified with the configuration. 3607The other options are parsed but not used. Any valid configuration may have 3608"disabled" added to it. 3609 3610\end{slist} 3611 3612\subsubsection{Format} 3613 3614\begin{verbatim} 3615 preprocessor sfportscan: proto <protocols> \ 3616 scan_type <portscan|portsweep|decoy_portscan|distributed_portscan|all> \ 3617 sense_level <low|medium|high> \ 3618 watch_ip <IP or IP/CIDR> \ 3619 ignore_scanners <IP list> \ 3620 ignore_scanned <IP list> \ 3621 logfile <path and filename> \ 3622 disabled 3623\end{verbatim} 3624 3625\subsubsection{Example} 3626 3627\begin{verbatim} 3628 preprocessor flow: stats_interval 0 hash 2 3629 preprocessor sfportscan:\ 3630 proto { all } \ 3631 scan_type { all } \ 3632 sense_level { low } 3633\end{verbatim} 3634 3635\subsubsection{sfPortscan Alert Output} 3636 3637\paragraph{Unified Output} 3638 3639In order to get all the portscan information logged with the alert, snort 3640generates a pseudo-packet and uses the payload portion to store the additional 3641portscan information of priority count, connection count, IP count, port count, 3642IP range, and port range. The characteristics of the packet are: 3643 3644\begin{verbatim} 3645 Src/Dst MAC Addr == MACDAD 3646 IP Protocol == 255 3647 IP TTL == 0 3648\end{verbatim} 3649 3650Other than that, the packet looks like the IP portion of the packet that caused 3651the portscan alert to be generated. This includes any IP options, etc. The 3652payload and payload size of the packet are equal to the length of the 3653additional portscan information that is logged. The size tends to be around 3654100 - 200 bytes. 3655 3656Open port alerts differ from the other portscan alerts, because open port 3657alerts utilize the tagged packet output system. This means that if an output 3658system that doesn't print tagged packets is used, then the user won't see open 3659port alerts. The open port information is stored in the IP payload and 3660contains the port that is open. 3661 3662The sfPortscan alert output was designed to work with unified2 packet logging, 3663so it is possible to extend favorite Snort GUIs to display portscan alerts and 3664the additional information in the IP payload using the above packet 3665characteristics. 3666 3667\paragraph{Log File Output} 3668 3669Log file output is displayed in the following format, and explained further 3670below: 3671 3672\begin{verbatim} 3673 Time: 09/08-15:07:31.603880 3674 event_id: 2 3675 192.168.169.3 -> 192.168.169.5 (portscan) TCP Filtered Portscan 3676 Priority Count: 0 3677 Connection Count: 200 3678 IP Count: 2 3679 Scanner IP Range: 192.168.169.3:192.168.169.4 3680 Port/Proto Count: 200 3681 Port/Proto Range: 20:47557 3682\end{verbatim} 3683 3684If there are open ports on the target, one or more additional tagged packet(s) 3685will be appended: 3686 3687\begin{verbatim} 3688 Time: 09/08-15:07:31.603881 3689 event_ref: 2 3690 192.168.169.3 -> 192.168.169.5 (portscan) Open Port 3691 Open Port: 38458 3692\end{verbatim} 3693 3694\begin{slist} 3695 3696\item \textbf{Event\_id/Event\_ref} 3697 3698These fields are used to link an alert with the corresponding \texttt{Open 3699Port} tagged packet 3700 3701\item \textbf{Priority Count} 3702 3703\texttt{Priority Count} keeps track of bad responses (resets, unreachables). 3704The higher the priority count, the more bad responses have been received. 3705 3706\item \textbf{Connection Count} 3707 3708\texttt{Connection Count} lists how many connections are active on the hosts 3709(src or dst). This is accurate for connection-based protocols, and is more of 3710an estimate for others. Whether or not a portscan was filtered is determined 3711here. High connection count and low priority count would indicate filtered (no 3712response received from target). 3713 3714\item \textbf{IP Count} 3715 3716IP Count keeps track of the last IP to contact a host, and increments the count 3717if the next IP is different. For one-to-one scans, this is a low number. For 3718active hosts this number will be high regardless, and one-to-one scans may 3719appear as a distributed scan. 3720 3721\item \textbf{Scanned/Scanner IP Range} 3722 3723This field changes depending on the type of alert. Portsweep (one-to-many) 3724scans display the scanned IP range; Portscans (one-to-one) display the scanner 3725IP. 3726 3727\item \textbf{Port Count} 3728 3729Port Count keeps track of the last port contacted and increments this number 3730when that changes. We use this count (along with IP Count) to determine the 3731difference between one-to-one portscans and one-to-one decoys. \end{slist} 3732 3733\subsubsection{Tuning sfPortscan} 3734\label{tuning sfportscan} 3735 3736The most important aspect in detecting portscans is tuning the detection engine 3737for your network(s). Here are some tuning tips: 3738 3739\begin{slist} 3740 3741\item \textbf{Use the watch\_ip, ignore\_scanners, and ignore\_scanned options.} 3742 3743It's important to correctly set these options. The \texttt{watch\_ip} option 3744is easy to understand. The analyst should set this option to the list of CIDR 3745blocks and IPs that they want to watch. If no \texttt{watch\_ip} is defined, 3746sfPortscan will watch all network traffic. 3747 3748The \texttt{ignore\_scanners} and \texttt{ignore\_scanned} options come into 3749play in weeding out legitimate hosts that are very active on your network. 3750Some of the most common examples are NAT IPs, DNS cache servers, syslog 3751servers, and nfs servers. sfPortscan may not generate false positives for 3752these types of hosts, but be aware when first tuning sfPortscan for these IPs. 3753Depending on the type of alert that the host generates, the analyst will know 3754which to ignore it as. If the host is generating portsweep events, then add it 3755to the \texttt{ignore\_scanners} option. If the host is generating portscan 3756alerts (and is the host that is being scanned), add it to the 3757\texttt{ignore\_scanned} option. 3758 3759\item \textbf{Filtered scan alerts are much more prone to false positives.} 3760 3761When determining false positives, the alert type is very important. Most of 3762the false positives that sfPortscan may generate are of the filtered scan alert 3763type. So be much more suspicious of filtered portscans. Many times this just 3764indicates that a host was very active during the time period in question. If 3765the host continually generates these types of alerts, add it to the 3766\texttt{ignore\_scanners} list or use a lower sensitivity level. 3767 3768\item \textbf{Make use of the Priority Count, Connection Count, IP Count, Port 3769Count, IP Range, and Port Range to determine false positives.} 3770 3771The portscan alert details are vital in determining the scope of a portscan and 3772also the confidence of the portscan. In the future, we hope to automate much 3773of this analysis in assigning a scope level and confidence level, but for now 3774the user must manually do this. The easiest way to determine false positives 3775is through simple ratio estimations. The following is a list of ratios to 3776estimate and the associated values that indicate a legitimate scan and not a 3777false positive. 3778 3779\textbf{Connection Count / IP Count:} This ratio indicates an estimated 3780average of connections per IP. For portscans, this ratio should be high, the 3781higher the better. For portsweeps, this ratio should be low. 3782 3783\textbf{Port Count / IP Count:} This ratio indicates an estimated average of 3784ports connected to per IP. For portscans, this ratio should be high and 3785indicates that the scanned host's ports were connected to by fewer IPs. For 3786portsweeps, this ratio should be low, indicating that the scanning host 3787connected to few ports but on many hosts. 3788 3789\textbf{Connection Count / Port Count:} This ratio indicates an estimated 3790average of connections per port. For portscans, this ratio should be low. 3791This indicates that each connection was to a different port. For portsweeps, 3792this ratio should be high. This indicates that there were many connections to 3793the same port. 3794 3795The reason that \texttt{Priority Count} is not included, is because the 3796priority count is included in the connection count and the above comparisons 3797take that into consideration. The Priority Count play an important role in 3798tuning because the higher the priority count the more likely it is a real 3799portscan or portsweep (unless the host is firewalled). 3800 3801\item \textbf{If all else fails, lower the sensitivity level.} 3802 3803If none of these other tuning techniques work or the analyst doesn't have the 3804time for tuning, lower the sensitivity level. You get the best protection the 3805higher the sensitivity level, but it's also important that the portscan 3806detection engine generate alerts that the analyst will find informative. The 3807low sensitivity level only generates alerts based on error responses. These 3808responses indicate a portscan and the alerts generated by the low sensitivity 3809level are highly accurate and require the least tuning. The low sensitivity 3810level does not catch filtered scans; since these are more prone to false 3811positives. \end{slist} 3812 3813\subsection{RPC Decode} 3814\label{sub:rpc-decoder} 3815 3816The rpc\_decode preprocessor normalizes RPC multiple fragmented records into a 3817single un-fragmented record. It does this by normalizing the packet into the 3818packet buffer. If stream5 is enabled, it will only process client-side 3819traffic. By default, it runs against traffic on ports 111 and 32771. 3820 3821\subsubsection{Format} 3822 3823\begin{verbatim} 3824 preprocessor rpc_decode: \ 3825 <ports> [ alert_fragments ] \ 3826 [no_alert_multiple_requests] \ 3827 [no_alert_large_fragments] \ 3828 [no_alert_incomplete] 3829\end{verbatim} 3830 3831\begin{table}[h] 3832\begin{center} 3833\begin{tabular}{| l | l |} 3834 3835\hline 3836\textbf{Option}& \textbf{Description}\\ 3837\hline 3838 3839\hline 3840\texttt{alert\_fragments}& 3841 3842Alert on any fragmented RPC record.\\ 3843 3844\hline 3845\texttt{no\_alert\_multiple\_requests}& 3846 3847Don't alert when there are multiple records in one packet.\\ 3848 3849\hline 3850\texttt{no\_alert\_large\_fragments}& 3851 3852Don't alert when the sum of fragmented records exceeds one packet.\\ 3853 3854\hline 3855\texttt{no\_alert\_incomplete}& 3856 3857Don't alert when a single fragment record exceeds the size of one packet.\\ 3858 3859\hline 3860\end{tabular} 3861\end{center} 3862\end{table} 3863 3864\subsection{Performance Monitor} 3865\label{sub:perfmonitor} 3866 3867This preprocessor measures Snort's real-time and theoretical maximum 3868performance. Whenever this preprocessor is turned on, it should have an output 3869mode enabled, either ``console'' which prints statistics to the console window 3870or ``file'' with a file name, where statistics get printed to the specified 3871file name. By default, Snort's real-time statistics are processed. This 3872includes: 3873 3874\begin{itemize} 3875\item Time Stamp 3876\item Drop Rate 3877\item Mbits/Sec (wire) [duplicated below for easy comparison with other rates] 3878\item Alerts/Sec 3879\item K-Pkts/Sec (wire) [duplicated below for easy comparison with other rates] 3880\item Avg Bytes/Pkt (wire) [duplicated below for easy comparison with other rates] 3881\item Pat-Matched [percent of data received that Snort processes in pattern matching] 3882\item Syns/Sec 3883\item SynAcks/Sec 3884\item New Sessions Cached/Sec 3885\item Sessions Del fr Cache/Sec 3886\item Current Cached Sessions 3887\item Max Cached Sessions 3888\item Stream Flushes/Sec 3889\item Stream Session Cache Faults 3890\item Stream Session Cache Timeouts 3891\item New Frag Trackers/Sec 3892\item Frag-Completes/Sec 3893\item Frag-Inserts/Sec 3894\item Frag-Deletes/Sec 3895\item Frag-Auto Deletes/Sec [memory DoS protection] 3896\item Frag-Flushes/Sec 3897\item Frag-Current [number of current Frag Trackers] 3898\item Frag-Max [max number of Frag Trackers at any time] 3899\item Frag-Timeouts 3900\item Frag-Faults 3901\item Number of CPUs [*** Only if compiled with LINUX\_SMP ***, the next three appear for each CPU] 3902\item CPU usage (user) 3903\item CPU usage (sys) 3904\item CPU usage (Idle) 3905\item Mbits/Sec (wire) [average mbits of total traffic] 3906\item Mbits/Sec (ipfrag) [average mbits of IP fragmented traffic] 3907\item Mbits/Sec (ipreass) [average mbits Snort injects after IP reassembly] 3908\item Mbits/Sec (tcprebuilt) [average mbits Snort injects after TCP reassembly] 3909\item Mbits/Sec (applayer) [average mbits seen by rules and protocol decoders] 3910\item Avg Bytes/Pkt (wire) 3911\item Avg Bytes/Pkt (ipfrag) 3912\item Avg Bytes/Pkt (ipreass) 3913\item Avg Bytes/Pkt (tcprebuilt) 3914\item Avg Bytes/Pkt (applayer) 3915\item K-Pkts/Sec (wire) 3916\item K-Pkts/Sec (ipfrag) 3917\item K-Pkts/Sec (ipreass) 3918\item K-Pkts/Sec (tcprebuilt) 3919\item K-Pkts/Sec (applayer) 3920\item Total Packets Received 3921\item Total Packets Dropped (not processed) 3922\item Total Packets Blocked (inline) 3923\item Percentage of Packets Dropped 3924\item Total Filtered TCP Packets 3925\item Total Filtered UDP Packets 3926\item Midstream TCP Sessions/Sec 3927\item Closed TCP Sessions/Sec 3928\item Pruned TCP Sessions/Sec 3929\item TimedOut TCP Sessions/Sec 3930\item Dropped Async TCP Sessions/Sec 3931\item TCP Sessions Initializing 3932\item TCP Sessions Established 3933\item TCP Sessions Closing 3934\item Max TCP Sessions (interval) 3935\item New Cached UDP Sessions/Sec 3936\item Cached UDP Ssns Del/Sec 3937\item Current Cached UDP Sessions 3938\item Max Cached UDP Sessions 3939\item Current Attribute Table Hosts (Target Based) 3940\item Attribute Table Reloads (Target Based) 3941\item Mbits/Sec (Snort) 3942\item Mbits/Sec (sniffing) 3943\item Mbits/Sec (combined) 3944\item uSeconds/Pkt (Snort) 3945\item uSeconds/Pkt (sniffing) 3946\item uSeconds/Pkt (combined) 3947\item KPkts/Sec (Snort) 3948\item KPkts/Sec (sniffing) 3949\item KPkts/Sec (combined) 3950\end{itemize} 3951 3952There are over 100 individual statistics included. A header line is output at startup and 3953rollover that labels each column. 3954 3955The following options can be used with the performance monitor: 3956 3957\begin{itemize} 3958 3959\item \texttt{flow} - Prints out statistics about the type and amount of traffic 3960and protocol distributions that Snort is seeing. This option can produce large 3961amounts of output. 3962 3963\item \texttt{flow-file} - Prints \texttt{flow} statistics in a comma-delimited 3964format to the file that is specified. 3965\begin{itemize} 3966\item Timestamp 3967\item Total \% TCP bytes 3968\item Total \% UDP bytes 3969\item Total \% ICMP bytes 3970\item Total \% OTHER bytes 3971\item Number of Packet length entries 3972\item Packet length entries - bytes,\%total 3973\item Number of TCP port flow entries 3974\item TCP port flow entries : port,\%total,\%src,\%dst 3975\item \% TCP high port to high port 3976\item Number of UDP port flow entries 3977\item UDP port flow entries : port,\%total,\%src,\%dst 3978\item \% UDP high port to high port 3979\item Number of ICMP type entries 3980\item ICMP type entries : type,\%total 3981\end{itemize} 3982Specifying this option implicitly enables \texttt{flow} statistics. 3983 3984\item \texttt{events} - Turns on event reporting. This prints out statistics 3985as to the number of rules that were evaluated and didn't match 3986(\textit{non-qualified events}) vs. the number of rules that were evaluated and 3987matched (\textit{qualified events}). A high \textit{non-qualified event} to 3988\textit{qualified event} ratio can indicate there are many rules with either 3989minimal content or no content that are being evaluated without success. The 3990fast pattern matcher is used to select a set of rules for evaluation based on 3991the longest \texttt{content} or a \texttt{content} modified with the 3992\texttt{fast\_pattern} rule option in a rule. Rules with short, generic 3993contents are more likely to be selected for evaluation than those with 3994longer, more unique contents. Rules without \texttt{content} are not 3995filtered via the fast pattern matcher and are always evaluated, so if 3996possible, adding a \texttt{content} rule option to those rules can decrease the 3997number of times they need to be evaluated and improve performance. 3998 3999\item \texttt{max} - Turns on the theoretical maximum performance that Snort 4000calculates given the processor speed and current performance. This is only 4001valid for uniprocessor machines, since many operating systems don't keep 4002accurate kernel statistics for multiple CPUs. 4003 4004\item \texttt{console} - Prints statistics at the console. 4005 4006\item \texttt{file} - Prints statistics in a comma-delimited format to the file 4007that is specified. Not all statistics are output to this file. You may also 4008use \texttt{snortfile} which will output into your defined Snort log directory. 4009Both of these directives can be overridden on the command line with the 4010\texttt{-Z} or \texttt{--perfmon-file} options. At startup, Snort will log 4011a distinctive line to this file with a timestamp to all readers to easily identify 4012gaps in the stats caused by Snort not running. 4013 4014\item \texttt{pktcnt} - Adjusts the number of packets to process before 4015checking for the time sample. This boosts performance, since checking the time 4016sample reduces Snort's performance. By default, this is 10000. 4017 4018\item \texttt{time} - Represents the number of seconds between intervals. 4019 4020\item \texttt{accumulate} or \texttt{reset} - Defines which type of drop 4021statistics are kept by the operating system. By default, \texttt{reset} is 4022used. 4023 4024\item \texttt{atexitonly} - Dump stats for entire life of Snort. 4025One or more of the following arguments can be given to specify specific 4026statistic types to dump at exit: 4027\begin{itemize} 4028\item \texttt{base-stats} 4029\item \texttt{flow-stats} 4030\item \texttt{flow-ip-stats} 4031\item \texttt{events-stats} 4032\end{itemize} 4033Without any arguments, all enabled stats will be dumped only when Snort exits. 4034 4035\item \texttt{max\_file\_size} - Defines the maximum size of the 4036comma-delimited file. Before the file exceeds this size, it will be rolled 4037into a new date stamped file of the format YYYY-MM-DD, followed by 4038YYYY-MM-DD.x, where x will be incremented each time the comma delimited file 4039is rolled over. The minimum is 4096 bytes and the maximum is 2147483648 bytes 4040(2GB). The default is the same as the maximum. 4041 4042\item \texttt{flow-ip} - Collects IP traffic distribution statistics based on 4043host pairs. For each pair of hosts for which IP traffic has been seen, the 4044following statistics are collected for both directions (A to B and B to A): 4045\begin{itemize} 4046\item TCP Packets 4047\item TCP Traffic in Bytes 4048\item TCP Sessions Established 4049\item TCP Sessions Closed 4050\item UDP Packets 4051\item UDP Traffic in Bytes 4052\item UDP Sessions Created 4053\item Other IP Packets 4054\item Other IP Traffic in Bytes 4055\end{itemize} 4056These statistics are printed and reset at the end of each interval. 4057 4058\item \texttt{flow-ip-file} - Prints the flow IP statistics in a 4059comma-delimited format to the file that is specified. All of the statistics 4060mentioned above, as well as the IP addresses of the host pairs in 4061human-readable format, are included. 4062 4063Each line in the file will have its values correspond (in order) to those below: 4064\begin{itemize} 4065\item IP Address A (String) 4066\item IP Address B (String) 4067\item TCP Packets from A to B 4068\item TCP Traffic in Bytes from A to B 4069\item TCP Packets from B to A 4070\item TCP Traffic in Bytes from B to A 4071\item UDP Packets from A to B 4072\item UDP Traffic in Bytes from A to B 4073\item UDP Packets from B to A 4074\item UDP Traffic in Bytes from B to A 4075\item Other IP Packets from A to B 4076\item Other IP Traffic in Bytes from A to B 4077\item Other IP Packets from B to A 4078\item Other IP Traffic in Bytes from B to A 4079\item TCP Sessions Established 4080\item TCP Sessions Closed 4081\item UDP Sessions Created 4082\end{itemize} 4083 4084\item \texttt{flow-ip-memcap} - Sets the memory cap on the hash table used to 4085store IP traffic statistics for host pairs. Once the cap has been reached, the 4086table will start to prune the statistics for the least recently seen host pairs 4087to free memory. This value is in bytes and the default value is 408852428800 (50MB). 4089 4090\end{itemize} 4091\subsubsection{Examples} 4092 4093\begin{verbatim} 4094 preprocessor perfmonitor: \ 4095 time 30 events flow file stats.profile max console pktcnt 10000 4096 4097 preprocessor perfmonitor: \ 4098 time 300 file /var/tmp/snortstat pktcnt 10000 4099 4100 preprocessor perfmonitor: \ 4101 time 30 flow-ip flow-ip-file flow-ip-stats.csv pktcnt 1000 4102 4103 preprocessor perfmonitor: \ 4104 time 30 pktcnt 1000 snortfile base.csv flow-file flows.csv atexitonly flow-stats 4105 4106 preprocessor perfmonitor: \ 4107 time 30 pktcnt 1000 flow events atexitonly base-stats flow-stats console 4108\end{verbatim} 4109 4110\subsection{HTTP Inspect} 4111\label{sub:http-inspect} 4112 4113HTTP Inspect is a generic HTTP decoder for user applications. Given a data 4114buffer, HTTP Inspect will decode the buffer, find HTTP fields, and normalize 4115the fields. HTTP Inspect works on both client requests and server responses. 4116 4117HTTP Inspect has a very ``rich'' user configuration. Users can configure 4118individual HTTP servers with a variety of options, which should allow the user 4119to emulate any type of web server. Within HTTP Inspect, there are two areas of 4120configuration: global and server. 4121 4122\subsubsection{Global Configuration} 4123 4124The global configuration deals with configuration options that determine the 4125global functioning of HTTP Inspect. The following example gives the generic 4126global configuration format: 4127 4128\subsubsection{Format} 4129\begin{verbatim} 4130 preprocessor http_inspect: \ 4131 global \ 4132 iis_unicode_map <map_filename> \ 4133 codemap <integer> \ 4134 [detect_anomalous_servers] \ 4135 [proxy_alert] \ 4136 [max_gzip_mem <num>] \ 4137 [compress_depth <num>] [decompress_depth <num>] \ 4138 [memcap <num>] \ 4139 disabled 4140\end{verbatim} 4141 4142You can only have a single global configuration, you'll get an error if you try 4143otherwise. 4144 4145\paragraph{Configuration} 4146\begin{slist} 4147\item \texttt{iis\_unicode\_map $<$map\_filename$>$ [codemap $<$integer$>$]} 4148 4149This is the global \texttt{iis\_unicode\_map} file. The 4150\texttt{iis\_unicode\_map} is a required configuration parameter. The map file 4151can reside in the same directory as \texttt{snort.conf} or be specified via a 4152fully-qualified path to the map file. 4153 4154The \texttt{iis\_unicode\_map} file is a Unicode codepoint map which tells HTTP 4155Inspect which codepage to use when decoding Unicode characters. For US 4156servers, the codemap is usually 1252. 4157 4158A Microsoft US Unicode codepoint map is provided in the Snort source 4159\texttt{etc} directory by default. It is called \texttt{unicode.map} and 4160should be used if no other codepoint map is available. A tool is supplied with 4161Snort to generate custom Unicode \texttt{maps--ms\_unicode\_generator.c}, which 4162is available at \url{http://www.snort.org/dl/contrib/}. 4163 4164\begin{note} 4165 4166Remember that this configuration is for the global IIS Unicode map, individual 4167servers can reference their own IIS Unicode map. 4168 4169\end{note} 4170 4171\item \texttt{detect\_anomalous\_servers} 4172 4173This global configuration option enables generic HTTP server traffic inspection 4174on non-HTTP configured ports, and alerts if HTTP traffic is seen. Don't turn 4175this on if you don't have a default server configuration that encompasses all 4176of the HTTP server ports that your users might access. In the future, we want 4177to limit this to specific networks so it's more useful, but for right now, this 4178inspects all network traffic. This option is turned off by default. 4179 4180\item \texttt{proxy\_alert} 4181 4182This enables global alerting on HTTP server proxy usage. By configuring HTTP 4183Inspect servers and enabling \texttt{allow\_proxy\_use}, you will only receive 4184proxy use alerts for web users that aren't using the configured proxies or are 4185using a rogue proxy server. 4186 4187Please note that if users aren't required to configure web proxy use, then you 4188may get a lot of proxy alerts. So, please only use this feature with 4189traditional proxy environments. Blind firewall proxies don't count. 4190 4191\item \texttt{compress\_depth $<$integer$>$} 4192This option specifies the maximum amount of packet payload to decompress. This 4193value can be set from 1 to 65535. The default for this option is 1460. 4194 4195\begin{note} 4196 4197Please note, in case of multiple policies, the value specified in the default policy 4198is used and this value overwrites the values specified in the other policies. In case 4199of \texttt{unlimited\_decompress} this should be set to its max value. This value should 4200be specified in the default policy even when the HTTP inspect preprocessor is turned off 4201using the \texttt{disabled} keyword. 4202 4203\end{note} 4204 4205\item \texttt{decompress\_depth $<$integer$>$} 4206This option specifies the maximum amount of decompressed data to obtain from the 4207compressed packet payload. This value can be set from 1 to 65535. The default for 4208this option is 2920. 4209 4210\begin{note} 4211 4212Please note, in case of multiple policies, the value specified in the default policy 4213is used and this value overwrites the values specified in the other policies. In case 4214of \texttt{unlimited\_decompress} this should be set to its max value. This value should 4215be specified in the default policy even when the HTTP inspect preprocessor is turned off 4216using the \texttt{disabled} keyword. 4217 4218\end{note} 4219 4220\item \texttt{max\_gzip\_mem $<$integer$>$} 4221 4222This option determines (in bytes) the maximum amount of memory the HTTP Inspect preprocessor 4223will use for decompression. The minimum allowed value for this option is 3276 bytes. This option 4224determines the number of concurrent sessions that can be decompressed at any given instant. 4225The default value for this option is 838860. 4226 4227This value is also used for the optional SWF/PDF file decompression. If these modes are enabled 4228this same value sets the maximum about of memory used for file decompression session state 4229information. 4230 4231\begin{note} 4232 4233This value should be specified in the default policy even when the HTTP inspect preprocessor is 4234turned off using the \texttt{disabled} keyword. 4235 4236\end{note} 4237 4238\item \texttt{memcap $<$integer$>$} 4239 4240This option determines (in bytes) the maximum amount of memory the HTTP Inspect preprocessor 4241will use for logging the URI and Hostname data. This value can be set from 2304 to 603979776 (576 MB). 4242This option along with the maximum uri and hostname logging size (which is defined in snort) will 4243determine the maximum HTTP sessions that will log the URI and hostname data at any given instant. The 4244maximum size for logging URI data is 2048 and for hostname is 256. The default value for this 4245option is 150994944 (144 MB). 4246 4247\begin {note} 4248 4249This value should be specified in the default policy even when the HTTP inspect preprocessor is turned off 4250using the \texttt{disabled} keyword. In case of multiple policies, the value specified in the 4251default policy will overwrite the value specified in other policies. 4252 4253max http sessions logged = memcap /( max uri logging size + max hostname logging size ) 4254max uri logging size defined in snort : 2048 4255max hostname logging size defined in snort : 256 4256 4257\end{note} 4258 4259\item \texttt{normalize\_random\_nulls\_in\_text} 4260 4261This option normalizes the text content with randomly encoded null bytes in 16LE,16BE,32LE and 426232BE UTF encodings to UTF8 in the server response. It relies on file preprocessor to determine 4263if the content is text. Hence file preprocessor should be enabled and configured with prepackaged 4264file magics wihtout which this option is not effective. 4265 4266\begin {note} 4267This opton relies on file prepreprocessor to determine if content can safely be considered as text 4268before normalizing. However, it is possible that non text file types unknown to file preprocessor 4269may get normalized as this option treats file types unknown to file preprocessor as text. Such cases 4270may result in false positives or false negatives in detection. 4271 4272\end{note} 4273 4274\item \texttt{fast\_blocking} 4275 4276This option enables inspecting http data before the data is flushed. This enables early IPS rule 4277evaluation so that the block rules will take into effect and the connection is blocked at the earliest 4278instead of blocking later after flushing the data. This config will be effective only when inline 4279normalisation is enabled. 4280 4281\item \texttt{disabled} 4282 4283This optional keyword is allowed with any policy to avoid packet processing. 4284This option disables the preprocessor. When the preprocessor is disabled 4285only the "memcap", "max\_gzip\_mem", "compress\_depth" and "decompress\_depth" 4286options are applied when specified with the configuration. Other options are 4287parsed but not used. Any valid configuration may have "disabled" added to it. 4288 4289\end{slist} 4290\subsubsection{Example Global Configuration} 4291 4292\begin{verbatim} 4293 preprocessor http_inspect: \ 4294 global iis_unicode_map unicode.map 1252 4295\end{verbatim} 4296 4297\subsubsection{Server Configuration} 4298 4299There are two types of server configurations: default and by IP address. 4300 4301\paragraph{Default} 4302 4303This configuration supplies the default server configuration for any server 4304that is not individually configured. Most of your web servers will most likely 4305end up using the default configuration. 4306 4307\subsubsection{Example Default Configuration} 4308 4309\begin{verbatim} 4310 preprocessor http_inspect_server: \ 4311 server default profile all ports { 80 } 4312\end{verbatim} 4313 4314\paragraph{Configuration by IP Address} 4315 4316This format is very similar to ``default'', the only difference being that 4317specific IPs can be configured. 4318 4319\subsubsection{Example IP Configuration} 4320 4321\begin{verbatim} 4322 preprocessor http_inspect_server: \ 4323 server 10.1.1.1 profile all ports { 80 } 4324\end{verbatim} 4325 4326\paragraph{Configuration by Multiple IP Addresses} 4327 4328This format is very similar to ``Configuration by IP Address'', the only 4329difference being that multiple IPs can be specified via a space separated list. 4330There is a limit of 40 IP addresses or CIDR notations per 4331\texttt{http\_inspect\_server} line. 4332 4333\subsubsection{Example Multiple IP Configuration} 4334 4335\begin{verbatim} 4336 preprocessor http_inspect_server: \ 4337 server { 10.1.1.1 10.2.2.0/24 } profile all ports { 80 } 4338\end{verbatim} 4339 4340\subsubsection{Server Configuration Options} 4341 4342Important: Some configuration options have an argument of `yes' or `no'. This 4343argument specifies whether the user wants the configuration option to generate 4344an HTTP Inspect alert or not. The `yes/no' argument does not specify whether 4345the configuration option itself is on or off, only the alerting functionality. 4346In other words, whether set to `yes' or 'no', HTTP normalization will still 4347occur, and rules based on HTTP traffic will still trigger. 4348 4349\begin{slist} 4350\item \texttt{profile $<$all$|$apache$|$iis$|$iis5\_0$|$iis4\_0$>$} 4351 4352Users can configure HTTP Inspect by using pre-defined HTTP server profiles. 4353Profiles allow the user to easily configure the preprocessor for a certain type 4354of server, but are not required for proper operation. 4355 4356There are five profiles available: all, apache, iis, iis5\_0, and iis4\_0. 4357 4358\begin{subslist} 4359 4360\item \texttt{all} 4361 4362The \texttt{all} profile is meant to normalize the URI using most of the common 4363tricks available. We alert on the more serious forms of evasions. This is a 4364great profile for detecting all types of attacks, regardless of the HTTP 4365server. \texttt{profile all} sets the configuration options described in Table 4366\ref{profile_all_options}. 4367 4368\begin{table}[h] 4369\begin{center} 4370\caption{Options for the ``all'' Profile} 4371\label{profile_all_options} 4372\begin{tabular}{| l | p{3in} |} 4373 4374\hline 4375\textbf{Option} & \textbf{Setting} \\ 4376\hline 4377 4378\hline 4379server\_flow\_depth & 300 \\ 4380\hline 4381client\_flow\_depth & 300 \\ 4382\hline 4383post\_depth & 0 \\ 4384\hline 4385chunk encoding & alert on chunks larger than 500000 bytes \\ 4386\hline 4387iis\_unicode\_map & codepoint map in the global configuration \\ 4388\hline 4389ASCII decoding & on, alert off \\ 4390\hline 4391multiple slash & on, alert off \\ 4392\hline 4393directory normalization & on, alert off \\ 4394\hline 4395apache whitespace & on, alert off \\ 4396\hline 4397double decoding & on, alert on \\ 4398\hline 4399\%u decoding & on, alert on \\ 4400\hline 4401bare byte decoding & on, alert on \\ 4402\hline 4403iis unicode codepoints & on, alert on \\ 4404\hline 4405iis backslash & on, alert off \\ 4406\hline 4407iis delimiter & on, alert off \\ 4408\hline 4409webroot & on, alert on\\ 4410\hline 4411non\_strict URL parsing & on\\ 4412\hline 4413tab\_uri\_delimiter & is set\\ 4414\hline 4415max\_header\_length & 0, header length not checked\\ 4416\hline 4417max\_spaces & 200 \\ 4418\hline 4419max\_headers & 0, number of headers not checked\\ 4420 4421\hline 4422\end{tabular} 4423\end{center} 4424\end{table} 4425 4426\item \texttt{apache} 4427 4428The \texttt{apache} profile is used for Apache web servers. This differs from 4429the \texttt{iis} profile by only accepting UTF-8 standard Unicode encoding and 4430not accepting backslashes as legitimate slashes, like IIS does. Apache also 4431accepts tabs as whitespace. \texttt{profile apache} sets the configuration 4432options described in Table \ref{profile_apache_options}. 4433 4434\begin{table}[h] 4435\begin{center} 4436\caption{Options for the \texttt{apache} Profile} 4437\label{profile_apache_options} 4438\begin{tabular}{| l | p{3in} |} 4439 4440\hline 4441\textbf{Option} & \textbf{Setting}\\ 4442\hline 4443 4444\hline 4445server\_flow\_depth & 300 \\ 4446\hline 4447client\_flow\_depth & 300 \\ 4448\hline 4449post\_depth & 0 \\ 4450\hline 4451chunk encoding & alert on chunks larger than 500000 bytes \\ 4452\hline 4453ASCII decoding & on, alert off \\ 4454\hline 4455multiple slash & on, alert off \\ 4456\hline 4457directory normalization & on, alert off \\ 4458\hline 4459webroot & on, alert on\\ 4460\hline 4461apache whitespace & on, alert on \\ 4462\hline 4463utf\_8 encoding & on, alert off \\ 4464\hline 4465non\_strict url parsing & on \\ 4466\hline 4467tab\_uri\_delimiter & is set\\ 4468\hline 4469max\_header\_length & 0, header length not checked\\ 4470\hline 4471max\_spaces & 200 \\ 4472\hline 4473max\_headers & 0, number of headers not checked\\ 4474\hline 4475 4476\hline 4477\end{tabular} 4478\end{center} 4479\end{table} 4480 4481\item \texttt{iis} 4482 4483The \texttt{iis} profile mimics IIS servers. So that means we use IIS Unicode 4484codemaps for each server, \%u encoding, bare-byte encoding, double decoding, 4485backslashes, etc. \texttt{profile iis} sets the configuration options described 4486in Table \ref{profile_iis_options}. 4487 4488\begin{table}[h] 4489\begin{center} 4490\caption{Options for the \texttt{iis} Profile} 4491\label{profile_iis_options} 4492\begin{tabular}{| l | p{3in} |} 4493 4494\hline 4495\textbf{Option} & \textbf{Setting}\\ 4496\hline 4497 4498\hline 4499server\_flow\_depth & 300 \\ 4500\hline 4501client\_flow\_depth & 300 \\ 4502\hline 4503post\_depth & -1 \\ 4504\hline 4505chunk encoding & alert on chunks larger than 500000 bytes\\ 4506\hline 4507iis\_unicode\_map & codepoint map in the global configuration \\ 4508\hline 4509ASCII decoding & on, alert off \\ 4510\hline 4511multiple slash & on, alert off \\ 4512\hline 4513directory normalization & on, alert off \\ 4514\hline 4515webroot & on, alert on\\ 4516\hline 4517double decoding & on, alert on \\ 4518\hline 4519\%u decoding & on, alert on \\ 4520\hline 4521bare byte decoding & on, alert on \\ 4522\hline 4523iis unicode codepoints & on, alert on \\ 4524\hline 4525iis backslash & on, alert off \\ 4526\hline 4527iis delimiter & on, alert on \\ 4528\hline 4529apache whitespace & on, alert on \\ 4530\hline 4531non\_strict URL parsing & on\\ 4532\hline 4533max\_header\_length & 0, header length not checked\\ 4534\hline 4535max\_spaces & 200 \\ 4536\hline 4537max\_headers & 0, number of headers not checked\\ 4538 4539\hline 4540\end{tabular} 4541\end{center} 4542\end{table} 4543 4544\item \texttt{iis4\_0, iis5\_0} 4545 4546In IIS 4.0 and IIS 5.0, there was a double decoding vulnerability. These two 4547profiles are identical to \texttt{iis}, except they will alert by default if a 4548URL has a double encoding. Double decode is not supported in IIS 5.1 and 4549beyond, so it's disabled by default. 4550 4551\item \texttt{default, no profile} 4552 4553The default options used by HTTP Inspect do not use a profile and are described 4554in Table \ref{default_HTTP_Inspect_options}. 4555 4556\begin{table}[h] 4557\begin{center} 4558\caption{Default HTTP Inspect Options} 4559\label{default_HTTP_Inspect_options} 4560\begin{tabular}{| l | p{3in} |} 4561 4562\hline 4563\textbf{Option} & \textbf{Setting}\\ 4564\hline 4565 4566\hline 4567port & 80\\ 4568\hline 4569server\_flow\_depth & 300 \\ 4570\hline 4571client\_flow\_depth & 300 \\ 4572\hline 4573post\_depth & -1 \\ 4574\hline 4575chunk encoding & alert on chunks larger than 500000 bytes\\ 4576\hline 4577ASCII decoding & on, alert off \\ 4578\hline 4579utf\_8 encoding & on, alert off\\ 4580\hline 4581multiple slash & on, alert off \\ 4582\hline 4583directory normalization & on, alert off \\ 4584\hline 4585webroot & on, alert on\\ 4586\hline 4587iis backslash & on, alert off \\ 4588\hline 4589apache whitespace & on, alert off \\ 4590\hline 4591iis delimiter & on, alert off \\ 4592\hline 4593non\_strict URL parsing & on\\ 4594\hline 4595max\_header\_length & 0, header length not checked\\ 4596\hline 4597max\_spaces & 200 \\ 4598\hline 4599max\_headers & 0, number of headers not checked\\ 4600\hline 4601\end{tabular} 4602\end{center} 4603\end{table} 4604 4605Profiles must be specified as the first server option and cannot be combined 4606with any other options except: 4607 4608\begin{itemize} 4609\item \texttt{ports} 4610\item \texttt{iis\_unicode\_map} 4611\item \texttt{allow\_proxy\_use} 4612\item \texttt{server\_flow\_depth} 4613\item \texttt{client\_flow\_depth} 4614\item \texttt{post\_depth} 4615\item \texttt{no\_alerts} 4616\item \texttt{inspect\_uri\_only} 4617\item \texttt{oversize\_dir\_length} 4618\item \texttt{normalize\_headers} 4619\item \texttt{normalize\_cookies} 4620\item \texttt{normalize\_utf} 4621\item \texttt{max\_header\_length} 4622\item \texttt{max\_spaces} 4623\item \texttt{max\_headers} 4624\item \texttt{extended\_response\_inspection} 4625\item \texttt{enable\_cookie} 4626\item \texttt{inspect\_gzip} 4627\item \texttt{unlimited\_decompress} 4628\item \texttt{normalize\_javascript} 4629\item \texttt{max\_javascript\_whitespaces} 4630\item \texttt{enable\_xff} 4631\item \texttt{http\_methods} 4632\item \texttt{log\_uri} 4633\item \texttt{log\_hostname} 4634\item \texttt{small\_chunk\_length} 4635\item \texttt{decompress\_swf} 4636\item \texttt{decompress\_pdf} 4637\item \texttt{legacy\_mode} 4638\end{itemize} 4639 4640These options must be specified after the \texttt{profile} option. 4641 4642\end{subslist} 4643 4644\subsubsection{Example} 4645 4646\begin{verbatim} 4647 preprocessor http_inspect_server: \ 4648 server 1.1.1.1 profile all ports { 80 3128 } 4649\end{verbatim} 4650 4651\item \texttt{ports $\{ <$port$> [<$port$> <...>] \}$} 4652 4653This is how the user configures which ports to decode on the HTTP server. 4654However, HTTPS traffic is encrypted and cannot be decoded with HTTP Inspect. 4655To ignore HTTPS traffic, use the SSL preprocessor. 4656 4657\item \texttt{iis\_unicode\_map $<$map\_filename$>$ codemap $<$integer$>$} 4658 4659The IIS Unicode map is generated by the program ms\_unicode\_generator.c. This 4660program is located on the Snort.org web site at 4661\url{http://www.snort.org/dl/contrib/} directory. Executing this program 4662generates a Unicode map for the system that it was run on. So, to get the 4663specific Unicode mappings for an IIS web server, you run this program on that 4664server and use that Unicode map in this configuration. 4665 4666When using this option, the user needs to specify the file that contains the 4667IIS Unicode map and also specify the Unicode map to use. For US servers, this 4668is usually 1252. But the ms\_unicode\_generator program tells you which 4669codemap to use for you server; it's the ANSI code page. You can select the 4670correct code page by looking at the available code pages that the 4671ms\_unicode\_generator outputs. 4672 4673\item \texttt{extended\_response\_inspection} 4674 4675This enables the extended HTTP response inspection. The default http response 4676inspection does not inspect the various fields of a HTTP response. By turning 4677this option the HTTP response will be thoroughly inspected. The different fields 4678of a HTTP response such as status code, status message, headers, cookie (when 4679enable\_cookie is configured) and body are extracted and saved into buffers. 4680Different rule options are provided to inspect these buffers. 4681 4682This option must be enabled to make use of the decompress\_swf or decompress\_pdf 4683options. 4684 4685\begin{note} 4686 4687When this option is turned on, if the HTTP response packet has a body then any 4688content pattern matches ( without http modifiers ) will search the response body 4689((decompressed in case of gzip) and not the entire packet payload. To search for 4690patterns in the header of the response, one should use the http modifiers with 4691content such as \texttt{http\_header}, \texttt{http\_stat\_code}, \texttt{http\_stat\_msg} 4692and \texttt{http\_cookie}. 4693 4694\end{note} 4695 4696\item \texttt{enable\_cookie} 4697 4698This options turns on the cookie extraction from HTTP requests and HTTP response. 4699By default the cookie inspection and extraction will be turned off. The cookie from 4700the \texttt{Cookie} header line is extracted and stored in HTTP Cookie buffer for 4701HTTP requests and cookie from the \texttt{Set-Cookie} is extracted and stored in 4702HTTP Cookie buffer for HTTP responses. The \texttt{Cookie:} and \texttt{Set-Cookie:} 4703header names itself along with leading spaces and the CRLF terminating the header 4704line are stored in the HTTP header buffer and are not stored in the HTTP cookie buffer. 4705 4706\begin{verbatim} 4707Ex: Set-Cookie: mycookie \r\n 4708 4709In this case, Set-Cookie: \r\n will be in the HTTP header buffer and the pattern 4710mycookie will be in the HTTP cookie buffer. 4711 4712\end{verbatim} 4713 4714\item \texttt{inspect\_gzip} 4715 4716This option specifies the HTTP inspect module to uncompress the compressed 4717data(gzip/deflate) in HTTP response. You should select the config option 4718"extended\_response\_inspection" before configuring this option. Decompression 4719is done across packets. So the decompression will end when either the 4720'compress\_depth' or 'decompress\_depth' is reached or when the compressed data ends. 4721When the compressed data is spanned across multiple packets, the state of the last 4722decompressed packet is used to decompressed the data of the next packet. 4723But the decompressed data are individually inspected. (i.e. the 4724decompressed data from different packets are not combined while inspecting). 4725Also the amount of decompressed data that will be inspected depends on the 4726'server\_flow\_depth' configured. 4727 4728Http Inspect generates a preprocessor alert with gid 120 and sid 6 when the decompression 4729fails. When the decompression fails due to a CRC error encountered by zlib, HTTP Inspect 4730will also provide the detection module with the data that was decompressed by zlib. 4731 4732\item \texttt{unlimited\_decompress} 4733 4734This option enables the user to decompress unlimited gzip data (across multiple 4735packets).Decompression will stop when the compressed data ends or when a out of 4736sequence packet is received. To ensure unlimited decompression, user should set 4737the 'compress\_depth' and 'decompress\_depth' to its maximum values in the default 4738policy. The decompression in a single packet is still limited by the 'compress\_depth' 4739and 'decompress\_depth'. 4740 4741\item \texttt{decompress\_swf $\{ mode [mode] \}$ } 4742 4743This option will enable decompression of compressed SWF (Adobe Flash content) files 4744encountered as the HTTP Response body in a GET transaction. The available decompression 4745modes are 'deflate' and 'lzma'. A prerequisite is enabling 4746extended\_response\_inspection (described above). When enabled, the preprocessor will 4747examine the response body for the corresponding file signature. 'CWS' for Deflate/ZLIB 4748compressed and 'ZWS' for LZMA compressed. Each decompression mode can be individually enabled. 4749e.g. ... { lzma } or { deflate } or { lzma deflate }. The compressed content is decompressed 4750'in-place' with the content made available to the detection/rules 'file\_data' option. 4751If enabled and located, the compressed SWF file signature is converted to 'FWS' to indicate 4752an uncompressed file. 4753 4754The 'decompress\_depth', 'compress\_depth', and 'unlimited\_decompress' are optionally used to 4755place limits on the decompression process. The semantics for SWF files are similar to the 4756gzip decompression process. 4757 4758During the decompression process, the preprocessor may generate alert 120:12 if Deflate 4759decompression fails or alert 120:13 if LZMA decompression fails. 4760 4761\begin{note} 4762LZMA decompression is only available if Snort is built with the liblzma package present 4763and functional. If the LZMA package is not present, then the { lzma } option will indicate 4764a fatal parsing error. If the liblzma package IS present, but one desires to disable LZMA 4765support, then the --disable-lzma option on configure will disable usage of the library. 4766\end{note} 4767 4768\item \texttt{decompress\_pdf $\{ mode [mode] \}$ } 4769 4770This option will enable decompression of the compressed portions of PDF files encountered 4771as the HTTP Response body in a GET transaction. A prerequisite is enabling 4772extended\_response\_inspection (described above). 4773 4774When enabled, the preprocessor will examine the response body for the '%PDF-' file signature. 4775PDF files are then parsed, locating PDF 'streams' with a single '/FlateDecode' filter. These 4776streams are decompressed in-place, replacing the compressed content. 4777 4778The 'decompress\_depth', 'compress\_depth', and 'unlimited\_decompress' are optionally used to 4779place limits on the decompression process. The semantics for PDF files are similar to the 4780gzip decompression process. 4781 4782During the file parsing/decompression process, the preprocessor may generate several alerts: 4783 4784\begin{center} 4785\begin{tabular}{| l | p{4.5in} |} 4786 4787\hline 4788\textbf{Alert} & \textbf{Description}\\ 4789\hline 4790 4791\hline 4792120:14 & Deflate decompression failure \\ 4793 4794\hline 4795120:15 & Located a 'stream' with an unsupported compression ('/Filter') algorithm \\ 4796 4797\hline 4798120:16 & Located a 'stream' with unsupported cascaded '/FlateDecode' options, e.g.: \begin{verbatim}/Filter [ /FlateDecode /FlateDecode ]\end{verbatim} \\ 4799 4800\hline 4801120:17 & PDF File parsing error \\ 4802 4803\hline 4804\end{tabular} 4805\end{center} 4806 4807\item \texttt{normalize\_javascript} 4808This option enables the normalization of Javascript within the HTTP response body. 4809You should select the config option \texttt{extended\_response\_inspection} before configuring 4810this option. When this option is turned on, Http Inspect searches for a Javascript within the 4811HTTP response body by searching for the $<$script$>$ tags and starts normalizing it. 4812When Http Inspect sees the $<$script$>$ tag without a type, it is considered as a javascript. 4813The obfuscated data within the javascript functions such as unescape, String.fromCharCode, decodeURI, 4814decodeURIComponent will be normalized. The different encodings handled within the unescape/ 4815decodeURI/decodeURIComponent are \texttt{\%XX}, \texttt{\%uXXXX}, \texttt{\\XX} and \texttt{\\uXXXXi}. 4816Apart from these encodings, Http Inspect will also detect the consecutive whitespaces and normalize 4817it to a single space. Http Inspect will also normalize the plus and concatenate the strings. 4818The rule option \texttt{file\_data} can be used to access this normalized buffer from the rule. 4819A preprocessor alert with SID 9 and GID 120 is generated when the obfuscation levels within the 4820Http Inspect is equal to or greater than 2. 4821 4822\begin{verbatim} 4823 4824Example: 4825 4826HTTP/1.1 200 OK\r\n 4827Date: Wed, 29 Jul 2009 13:35:26 GMT\r\n 4828Server: Apache/2.2.3 (Debian) PHP/5.2.0-8+etch10 mod_ssl/2.2.3 OpenSSL/0.9.8c\r\n 4829Last-Modified: Sun, 20 Jan 2008 12:01:21 GMT\r\n 4830Accept-Ranges: bytes\r\n 4831Content-Length: 214\r\n 4832Keep-Alive: timeout=15, max=99\r\n 4833Connection: Keep-Alive\r\n 4834Content-Type: application/octet-stream\r\n\r\n 4835<html xmlns="http://www.w3.org/1999/xhtml"> 4836<head> 4837<title>FIXME</title> 4838</head> 4839<body> 4840<script>document.write(unescape(unescape("%48%65%6C%6C%6F%2C%20%73%6E%6F%72%74%20%74%65%61%6D%21"))); 4841</script> 4842</body> 4843</html> 4844 4845\end{verbatim} 4846 4847The above javascript will generate the preprocessor alert with SID 9 and GIDF 120 when \texttt{normalize\_javascript} 4848is turned on. 4849 4850Http Inspect will also generate a preprocessor alert with GID 120 and SID 11 when there are more than one type 4851of encodings within the escaped/encoded data. 4852 4853\begin{verbatim} 4854 4855For example: 4856 4857unescape("%48\x65%6C%6C%6F%2C%20%73%6E%6F%72%74%20%74%65%61%6D%21"); 4858String.fromCharCode(0x48, 0x65, 0x6c, 0x6c, 111, 44, 32, 115, 110, 111, 114, 116, 32, 116, 101, 97, 109, 33) 4859 4860\\end{verbatim} 4861 4862The above obfuscation will generate the preprocessor alert with GID 120 and SID 11. 4863 4864This option is turned off by default in HTTP Inspect. 4865 4866\item \texttt{max\_javascript\_whitespaces $<$positive integer up to 65535$>$} 4867This option takes an integer as an argument. The integer determines the maximum number 4868of consecutive whitespaces allowed within the Javascript obfuscated data in a HTTP 4869response body. The config option \texttt{normalize\_javascript} should be turned on before configuring 4870 this config option. When the whitespaces in the javascript obfuscated data is equal to or more 4871than this value a preprocessor alert with GID 120 and SID 10 is generated. The default value for 4872this option is 200. To enable, specify an integer argument to \texttt{max\_javascript\_spaces} of 1 to 65535. 4873Specifying a value of 0 is treated as disabling the alert. 4874 4875\item \texttt{enable\_xff} 4876 4877This option enables Snort to parse and log the original client IP present in the 4878X-Forwarded-For or True-Client-IP HTTP request headers along with the generated 4879events. The XFF/True-Client-IP Original client IP address is logged only with 4880unified2 output and is not logged with console (-A cmg) output. 4881 4882\item \texttt{xff\_headers} 4883 4884If/When the \texttt{enable\_xff} option is present, the \texttt{xff\_headers} option specifies a set of custom 'xff' 4885headers. This option allows the definition of up to six custom headers in addition to the 4886two default (and always present) X-Forwarded-For and True-Client-IP headers. The option 4887permits both the custom and default headers to be prioritized. The headers/priority pairs 4888are specified as a list. Lower numerical values imply a higher priority. The headers do 4889not need to be specified in priority order. Nor do the priorities need to be contiguous. 4890Priority values can range from 1 to 255. The priority values and header names must be unique. 4891The header names must not collide with known http headers such as 'host', 'cookie', 4892'content-length', etc. 4893 4894A example of the \texttt{xff\_header} syntax is: 4895\begin{verbatim} 4896xff_headers { [ x-forwarded-highest-priority 1 ] [ x-forwarded-second-highest-priority 2 ] \ 4897 [ x-forwarded-lowest-priority-custom 3 ] } 4898\end{verbatim} 4899 4900The default X-Forwarded-For and True-Client-IP headers are always present. They may be explicitly 4901specified in the \texttt{xff\_headers} config in order to determine their priority. If not specified, they 4902will be automatically added to the xff list as the lowest priority headers. 4903 4904For example, let us say that we have the following (abbreviated) HTTP request header: 4905 4906\begin{verbatim} 4907... 4908Host: www.snort.org 4909X-Forwarded-For: 192.168.1.1 4910X-Was-Originally-Forwarded-From: 10.1.1.1 4911... 4912\end{verbatim} 4913 4914With the default xff behavior (no \texttt{xff\_headers}), the 'X-Forwarded-For' header would be used to 4915provide a 192.168.1.1 Original Client IP address in the unified2 log. Custom headers are not 4916parsed. 4917 4918With: 4919\begin{verbatim} 4920xff_headers { [ x-was-originally-forwarded-from 1 ] [ x-another-forwarding-header 2 ] \ 4921 [ x-forwarded-for 3 ] } 4922\end{verbatim} 4923 4924The X-Was-Originally-Forwarded-From header is the highest priority present and its value 4925of 10.1.1.1 will be logged as the Original Client IP in the unified2 log. 4926 4927But with: 4928\begin{verbatim} 4929xff_headers { [ x-was-originally-forwarded-from 3 ] [ x-another-forwarding-header 2 ] \ 4930 [ x-forwarded-for 1 ] } 4931\end{verbatim} 4932 4933Now the X-Forwarded-For header is the highest priority and its value of 192.168.1.1 is logged. 4934 4935 4936\begin{note} 4937 4938The original client IP from XFF/True-Client-IP in unified2 logs can be viewed using 4939the tool u2spewfoo. This tool is present in the tools/u2spewfoo directory of snort 4940source tree. 4941 4942\end{note} 4943 4944\item \texttt{server\_flow\_depth $<$integer$>$} 4945 4946This specifies the amount of server response payload to inspect. When 4947\texttt{extended\_response\_inspection} is turned on, it is applied to the HTTP response 4948body (decompressed data when \texttt{inspect\_gzip} is turned on) and not the HTTP headers. 4949When \texttt{extended\_response\_inspection} is turned off the \texttt{server\_flow\_depth} 4950is applied to the entire HTTP response (including headers). Unlike \texttt{client\_flow\_depth} 4951this option is applied per TCP session. This option can be used to balance the needs of 4952IDS performance and level of inspection of HTTP server response data. Snort rules are 4953targeted at HTTP server response traffic and when used with a small flow\_depth value 4954may cause false negatives. Most of these rules target either the HTTP header, or 4955the content that is likely to be in the first hundred or so bytes of non-header data. 4956Headers are usually under 300 bytes long, but your mileage may vary. 4957It is suggested to set the \texttt{server\_flow\_depth} to its maximum value. 4958 4959This value can be set from -1 to 65535. A value of -1 causes Snort 4960to ignore all server side traffic for ports defined in \texttt{ports} when 4961\texttt{extended\_response\_inspection} is turned off. When the \texttt{extended\_response\_inspection} 4962 is turned on, value of -1 causes Snort to ignore the HTTP response body data and 4963 not the HTTP headers. Inversely, a value of 0 causes Snort to inspect all HTTP server 4964payloads defined in "ports" (note that this will likely slow down IDS 4965performance). Values above 0 tell Snort the number of bytes to 4966inspect of the server response (excluding the HTTP headers when \texttt{extended\_response\_inspection} 4967is turned on) in a given HTTP session. Only packets payloads starting with 'HTTP' will 4968be considered as the first packet of a server response. If less than flow\_depth bytes 4969are in the payload of the HTTP response packets in a given session, the entire payload will be 4970inspected. If more than flow\_depth bytes are in the payload of the HTTP response packet in a session 4971only flow\_depth bytes of the payload will be inspected for that session. Rules that are meant to 4972inspect data in the payload of the HTTP response packets in a session beyond 65535 bytes will be 4973ineffective unless flow\_depth is set to 0. The default value for \texttt{server\_flow\_depth} is 300. 4974Note that the 65535 byte maximum flow\_depth applies to stream reassembled packets as well. 4975It is suggested to set the \texttt{server\_flow\_depth} to its maximum value. 4976 4977\begin{note} 4978 4979\texttt{server\_flow\_depth} is the same as the old \texttt{flow\_depth} 4980option, which will be deprecated in a future release. 4981 4982\end{note} 4983 4984\item \texttt{client\_flow\_depth $<$integer$>$} 4985 4986This specifies the amount of raw client request payload to inspect. This 4987value can be set from -1 to 1460. Unlike \texttt{server\_flow\_depth} this value is applied 4988to the first packet of the HTTP request. It is not a session based flow depth. 4989It has a default value of 300. It primarily eliminates Snort from inspecting 4990larger HTTP Cookies that appear at the end of many client request Headers. 4991 4992A value of -1 causes Snort to ignore all client side traffic for ports 4993defined in "ports." Inversely, a value of 0 causes Snort to inspect all HTTP client 4994 side traffic defined in "ports" (note that this will likely slow down IDS 4995performance). Values above 0 tell Snort the number of bytes to 4996inspect in the first packet of the client request. If less than flow\_depth bytes 4997are in the TCP payload (HTTP request) of the first packet, the entire payload will be inspected. 4998If more than flow\_depth bytes are in the payload of the first packet only flow\_depth 4999bytes of the payload will be inspected. Rules that are meant to 5000inspect data in the payload of the first packet of a client request beyond 1460 bytes 5001will be ineffective unless flow\_depth is set to 0. Note that the 1460 byte 5002maximum flow\_depth applies to stream reassembled packets as well. It is 5003suggested to set the \texttt{client\_flow\_depth} to its maximum value. 5004 5005\item \texttt{post\_depth $<$integer$>$} 5006 5007This specifies the amount of data to inspect in a client post message. The 5008value can be set from -1 to 65495. The default value is -1. A value of -1 5009causes Snort to ignore all the data in the post message. Inversely, a value 5010of 0 causes Snort to inspect all the client post message. This increases 5011the performance by inspecting only specified bytes in the post message. 5012 5013\item \texttt{ascii $<$yes$|$no$>$} 5014 5015The \texttt{ascii} decode option tells us whether to decode encoded ASCII 5016chars, a.k.a \%2f = /, \%2e = ., etc. It is normal to see ASCII encoding usage 5017in URLs, so it is recommended that you disable HTTP Inspect alerting for this 5018option. 5019 5020\item \texttt{extended\_ascii\_uri} 5021 5022This option enables the support for extended ASCII codes in the HTTP request 5023URI. This option is turned off by default and is not supported with any of 5024the profiles. 5025 5026\item \texttt{utf\_8 $<$yes$|$no$>$} 5027 5028The \texttt{utf-8} decode option tells HTTP Inspect to decode standard UTF-8 5029Unicode sequences that are in the URI. This abides by the Unicode standard and 5030only uses \% encoding. Apache uses this standard, so for any Apache servers, 5031make sure you have this option turned on. As for alerting, you may be 5032interested in knowing when you have a UTF-8 encoded URI, but this will be prone 5033to false positives as legitimate web clients use this type of encoding. When 5034\texttt{utf\_8} is enabled, ASCII decoding is also enabled to enforce correct 5035functioning. 5036 5037\item \texttt{u\_encode $<$yes$|$no$>$} 5038 5039This option emulates the IIS \%u encoding scheme. How the \%u encoding scheme 5040works is as follows: the encoding scheme is started by a \%u followed by 4 5041characters, like \%uxxxx. The xxxx is a hex-encoded value that correlates to 5042an IIS Unicode codepoint. This value can most definitely be ASCII. An ASCII 5043character is encoded like \%u002f = /, \%u002e = ., etc. If no 5044iis\_unicode\_map is specified before or after this option, the default codemap 5045is used. 5046 5047You should alert on \%u encodings, because we are not aware of any legitimate 5048clients that use this encoding. So it is most likely someone trying to be 5049covert. 5050 5051\item \texttt{bare\_byte $<$yes$|$no$>$} 5052 5053Bare byte encoding is an IIS trick that uses non-ASCII characters as valid 5054values when decoding UTF-8 values. This is not in the HTTP standard, as all 5055non-ASCII values have to be encoded with a \%. Bare byte encoding allows the 5056user to emulate an IIS server and interpret non-standard encodings correctly. 5057 5058The alert on this decoding should be enabled, because there are no legitimate 5059clients that encode UTF-8 this way since it is non-standard. 5060 5061\item \texttt{iis\_unicode $<$yes$|$no$>$} 5062 5063The \texttt{iis\_unicode} option turns on the Unicode codepoint mapping. If 5064there is no iis\_unicode\_map option specified with the server config, 5065\texttt{iis\_unicode} uses the default codemap. The \texttt{iis\_unicode} 5066option handles the mapping of non-ASCII codepoints that the IIS server accepts 5067and decodes normal UTF-8 requests. 5068 5069You should alert on the \texttt{iis\_unicode option}, because it is seen mainly 5070in attacks and evasion attempts. When \texttt{iis\_unicode} is enabled, ASCII 5071and UTF-8 decoding are also enabled to enforce correct decoding. To alert on 5072UTF-8 decoding, you must enable also enable \texttt{utf\_8 yes}. 5073 5074\item \texttt{double\_decode $<$yes$|$no$>$} 5075 5076The \texttt{double\_decode} option is once again IIS-specific and emulates IIS 5077functionality. How this works is that IIS does two passes through the request 5078URI, doing decodes in each one. In the first pass, it seems that all types of 5079iis encoding is done: utf-8 unicode, ASCII, bare byte, and \%u. In the second 5080pass, the following encodings are done: ASCII, bare byte, and \%u. We leave 5081out utf-8 because I think how this works is that the \% encoded utf-8 is 5082decoded to the Unicode byte in the first pass, and then UTF-8 is decoded in the 5083second stage. Anyway, this is really complex and adds tons of different 5084encodings for one character. When \texttt{double\_decode} is enabled, so ASCII 5085is also enabled to enforce correct decoding. 5086 5087\item \texttt{non\_rfc\_char $\{ <$byte$> [<$byte ...$>] \}$} 5088 5089This option lets users receive an alert if certain non-RFC chars are used in a 5090request URI. For instance, a user may not want to see null bytes in the 5091request URI and we can alert on that. Please use this option with care, 5092because you could configure it to say, alert on all `/' or something like that. 5093It's flexible, so be careful. 5094 5095\item \texttt{multi\_slash $<$yes$|$no$>$} 5096 5097This option normalizes multiple slashes in a row, so something like: 5098``foo/////////bar'' get normalized to ``foo/bar.'' 5099 5100If you want an alert when multiple slashes are seen, then configure with a 5101\texttt{yes}; otherwise, use \texttt{no}. 5102 5103\item \texttt{iis\_backslash $<$yes$|$no$>$} 5104 5105Normalizes backslashes to slashes. This is again an IIS emulation. So a 5106request URI of ``/foo$\backslash$bar'' gets normalized to ``/foo/bar.'' 5107 5108\item \texttt{directory $<$yes$|$no$>$} 5109 5110This option normalizes directory traversals and self-referential directories. 5111 5112The directory: 5113 5114\begin{verbatim} 5115 /foo/fake\_dir/../bar 5116\end{verbatim} 5117 5118gets normalized to: 5119 5120\begin{verbatim} 5121 /foo/bar 5122\end{verbatim} 5123 5124The directory: 5125 5126\begin{verbatim} 5127 /foo/./bar 5128\end{verbatim} 5129 5130gets normalized to: 5131 5132\begin{verbatim} 5133 /foo/bar 5134\end{verbatim} 5135 5136If you want to configure an alert, specify \texttt{yes}, otherwise, specify 5137\texttt{no}. This alert may give false positives, since some web sites refer 5138to files using directory traversals. 5139 5140\item \texttt{apache\_whitespace $<$yes$|$no$>$} 5141 5142This option deals with the non-RFC standard of using tab for a space delimiter. 5143Apache uses this, so if the emulated web server is Apache, enable this option. 5144Alerts on this option may be interesting, but may also be false positive prone. 5145 5146\item \texttt{iis\_delimiter $<$yes$|$no$>$} 5147 5148This started out being IIS-specific, but Apache takes this non-standard 5149delimiter was well. Since this is common, we always take this as standard 5150since the most popular web servers accept it. But you can still get an alert 5151on this option. 5152 5153\item \texttt{chunk\_length $<$non-zero positive integer$>$} 5154 5155This option is an anomaly detector for abnormally large chunk sizes. This 5156picks up the Apache chunk encoding exploits, and may also alert on HTTP 5157tunneling that uses chunk encoding. 5158 5159\item \texttt{small\_chunk\_length \{ $<$chunk size$>$ $<$consecutive chunks$>$ \} } 5160 5161This option is an evasion detector for consecutive small chunk sizes when 5162either the client or server use \texttt{Transfer-Encoding: chunked}. 5163$<$chunk size$>$ specifies the maximum chunk size for which a chunk will be 5164considered small. $<$consecutive chunks$>$ specifies the number of consecutive 5165small chunks $<$= $<$chunk size$>$ before an event will be generated. This option 5166is turned off by default. Maximum values for each are 255 and a $<$chunk size$>$ of 0 5167disables. Events generated are gid:119, sid:26 for client small 5168chunks and gid:120, sid:7 for server small chunks. 5169 5170Example: 5171\begin{verbatim} 5172small_chunk_length { 10 5 } 5173\end{verbatim} 5174Meaning alert if we see 5 consecutive chunk sizes of 10 or less. 5175 5176\item \texttt{no\_pipeline\_req} 5177 5178This option turns HTTP pipeline decoding off, and is a performance enhancement 5179if needed. By default, pipeline requests are inspected for attacks, but when 5180this option is enabled, pipeline requests are not decoded and analyzed per HTTP 5181protocol field. It is only inspected with the generic pattern matching. 5182 5183\item \texttt{non\_strict} 5184 5185This option turns on non-strict URI parsing for the broken way in which Apache 5186servers will decode a URI. Only use this option on servers that will accept 5187URIs like this: "get /index.html alsjdfk alsj lj aj la jsj s$\backslash$n". 5188The non\_strict option assumes the URI is between the first and second space 5189even if there is no valid HTTP identifier after the second space. 5190 5191\item \texttt{allow\_proxy\_use} 5192 5193By specifying this keyword, the user is allowing proxy use on this server. 5194This means that no alert will be generated if the \texttt{proxy\_alert} global 5195keyword has been used. If the proxy\_alert keyword is not enabled, then this 5196option does nothing. The \texttt{allow\_proxy\_use} keyword is just a way to 5197suppress unauthorized proxy use for an authorized server. 5198 5199\item \texttt{no\_alerts} 5200 5201This option turns off all alerts that are generated by the HTTP Inspect 5202preprocessor module. This has no effect on HTTP rules in the rule set. No 5203argument is specified. 5204 5205\item \texttt{oversize\_dir\_length $<$non-zero positive integer$>$} 5206 5207This option takes a non-zero positive integer as an argument. The argument 5208specifies the max char directory length for URL directory. If a url directory 5209is larger than this argument size, an alert is generated. A good argument value 5210is 300 characters. This should limit the alerts to IDS evasion type attacks, 5211like whisker -i 4. 5212 5213\item \texttt{inspect\_uri\_only} 5214 5215This is a performance optimization. When enabled, only the URI portion of HTTP 5216requests will be inspected for attacks. As this field usually contains 90-95\% 5217of the web attacks, you'll catch most of the attacks. So if you need extra 5218performance, enable this optimization. It's important to note that if this 5219option is used without any \texttt{uricontent} rules, then no inspection will 5220take place. This is obvious since the URI is only inspected with 5221\texttt{uricontent} rules, and if there are none available, then there is 5222nothing to inspect. 5223 5224For example, if we have the following rule set: 5225 5226\begin{verbatim} 5227 alert tcp any any -> any 80 ( msg:"content"; content: "foo"; ) 5228\end{verbatim} 5229 5230and the we inspect the following URI: 5231 5232\begin{verbatim} 5233 get /foo.htm http/1.0\r\n\r\n 5234\end{verbatim} 5235 5236No alert will be generated when \texttt{inspect\_uri\_only} is enabled. The 5237\texttt{inspect\_uri\_only} configuration turns off all forms of detection 5238except \texttt{uricontent} inspection. 5239 5240\item \texttt{max\_header\_length $<$positive integer up to 65535$>$} 5241 5242This option takes an integer as an argument. The integer is the maximum length 5243allowed for an HTTP client request header field. Requests that exceed this 5244length will cause a "Long Header" alert. This alert is off by default. To 5245enable, specify an integer argument to max\_header\_length of 1 to 65535. 5246Specifying a value of 0 is treated as disabling the alert. 5247 5248\item \texttt{max\_spaces $<$positive integer up to 65535$>$} 5249 5250This option takes an integer as an argument. The integer determines the maximum number 5251of whitespaces allowed with HTTP client request line folding. Requests headers 5252folded with whitespaces equal to or more than this value will cause a 5253"Space Saturation" alert with SID 26 and GID 119. The default value for this 5254option is 200. To enable, specify an integer argument to \texttt{max\_spaces} of 1 to 65535. 5255Specifying a value of 0 is treated as disabling the alert. 5256 5257 5258\item \texttt{webroot $<$yes$|$no$>$} 5259 5260This option generates an alert when a directory traversal traverses past the 5261web server root directory. This generates much fewer false positives than the 5262directory option, because it doesn't alert on directory traversals that stay 5263within the web server directory structure. It only alerts when the directory 5264traversals go past the web server root directory, which is associated with 5265certain web attacks. 5266 5267\item \texttt{tab\_uri\_delimiter} 5268 5269This option turns on the use of the tab character (0x09) as a delimiter for a 5270URI. Apache accepts tab as a delimiter; IIS does not. For IIS, a tab in the 5271URI should be treated as any other character. Whether this option is on or 5272not, a tab is treated as whitespace if a space character (0x20) precedes it. 5273No argument is specified. 5274 5275\item \texttt{normalize\_headers} 5276 5277This option turns on normalization for HTTP Header Fields, not including 5278Cookies (using the same configuration parameters as the URI normalization (i.e., 5279multi-slash, directory, etc.). It is useful for normalizing Referrer URIs that 5280may appear in the HTTP Header. 5281 5282\item \texttt{normalize\_cookies} 5283 5284This option turns on normalization for HTTP Cookie Fields (using the same 5285configuration parameters as the URI normalization (i.e., multi-slash, directory, 5286etc.). It is useful for normalizing data in HTTP Cookies that may be encoded. 5287 5288\item \texttt{normalize\_utf} 5289 5290This option turns on normalization of HTTP response bodies where the Content-Type 5291header lists the character set as "utf-16le", "utf-16be", "utf-32le", or 5292"utf-32be". HTTP Inspect will attempt to normalize these back into 8-bit encoding, 5293generating an alert if the extra bytes are non-zero. 5294 5295\item \texttt{max\_headers $<$positive integer up to 1024$>$} 5296 5297This option takes an integer as an argument. The integer is the maximum number 5298of HTTP client request header fields. Requests that contain more HTTP Headers 5299than this value will cause a "Max Header" alert. The alert is off by default. 5300To enable, specify an integer argument to max\_headers of 1 to 1024. 5301Specifying a value of 0 is treated as disabling the alert. 5302 5303\item \texttt{http\_methods $\{ cmd [cmd] \}$ } 5304This specifies additional HTTP Request Methods outside of those checked by 5305default within the preprocessor (GET and POST). The list should be enclosed 5306within braces and delimited by spaces, tabs, line feed or carriage return. 5307The config option, braces and methods also needs to be separated by braces. 5308 5309\begin{verbatim} 5310 http_methods { PUT CONNECT } 5311\end{verbatim} 5312 5313\begin{note} 5314 5315Please note the maximum length for a method name is 256. 5316 5317\end{note} 5318 5319\item \texttt{log\_uri} 5320 5321This option enables HTTP Inspect preprocessor to parse the URI data from the 5322HTTP request and log it along with all the generated events for that session. 5323Stream reassembly needs to be turned on HTTP ports to enable the logging. 5324If there are multiple HTTP requests in the session, the URI data of the most recent 5325HTTP request during the alert will be logged. The maximum URI logged is 2048. 5326 5327\begin{note} 5328 5329Please note, this is logged only with the unified2 output and is not logged 5330with console output (-A cmg). \texttt{u2spewfoo} can be used to read this data from 5331the unified2. 5332 5333\end{note} 5334 5335\item \texttt{log\_hostname} 5336 5337This option enables HTTP Inspect preprocessor to parse the hostname data from the 5338"Host" header of the HTTP request and log it along with all the generated events 5339for that session. Stream reassembly needs to be turned on HTTP ports to enable 5340the logging. If there are multiple HTTP requests in the session, the Hostname data 5341of the most recent HTTP request during the alert will be logged. In case of 5342multiple "Host" headers within one HTTP request, a preprocessor alert with sid 24 is 5343generated. The maximum hostname length logged is 256. 5344 5345\begin{note} 5346 5347Please note, this is logged only with the unified2 output and is not logged 5348with console output (-A cmg). \texttt{u2spewfoo} can be used to read this data from 5349the unified2. 5350 5351\end{note} 5352 5353\begin{verbatim} 5354########################################## 5355# HTTP2 SUPPORT IS STILL EXPERIMENTAL! 5356# DO NOT USE IN PRODUCTION ENVIRONMENTS. 5357# Please send any issues to the Snort team 5358########################################## 5359\end{verbatim} 5360 5361\item \texttt{legacy\_mode} 5362By default, HTTP2 traffic is not supported. You can use "legacy\_mode no" 5363to enable HTTP2 support. 5364If http legacy mode is configured, HTTP2 inspection is disabled. 5365 5366\end{slist} 5367 5368\subsubsection{Examples} 5369 5370\begin{verbatim} 5371 preprocessor http_inspect_server: \ 5372 server 10.1.1.1 \ 5373 ports { 80 3128 8080 } \ 5374 server_flow_depth 0 \ 5375 ascii no \ 5376 double_decode yes \ 5377 non_rfc_char { 0x00 } \ 5378 chunk_length 500000 \ 5379 non_strict \ 5380 no_alerts 5381 5382 preprocessor http_inspect_server: \ 5383 server default \ 5384 ports { 80 3128 } \ 5385 non_strict \ 5386 non_rfc_char { 0x00 } \ 5387 server_flow_depth 300 \ 5388 apache_whitespace yes \ 5389 directory no \ 5390 iis_backslash no \ 5391 u_encode yes \ 5392 ascii no \ 5393 chunk_length 500000 \ 5394 bare_byte yes \ 5395 double_decode yes \ 5396 iis_unicode yes \ 5397 iis_delimiter yes \ 5398 multi_slash no 5399 5400 preprocessor http_inspect_server: \ 5401 server default \ 5402 profile all \ 5403 ports { 80 8080 } 5404\end{verbatim} 5405 5406\subsection{SMTP Preprocessor} 5407\label{SMTP} 5408 5409The SMTP preprocessor is an SMTP decoder for user applications. Given a data 5410buffer, SMTP will decode the buffer and find SMTP commands and responses. It 5411will also mark the command, data header data body sections, and TLS data. 5412 5413SMTP handles stateless and stateful processing. It saves state between 5414individual packets. However maintaining correct state is dependent on the 5415reassembly of the client side of the stream (i.e., a loss of coherent stream data 5416results in a loss of state). 5417 5418\subsubsection{Configuration} 5419 5420SMTP has the usual configuration items, such as \texttt{port} and 5421\texttt{inspection\_type}. Also, SMTP command lines can be normalized to 5422remove extraneous spaces. TLS-encrypted traffic can be ignored, which improves 5423performance. In addition, regular mail data can be ignored for an additional 5424performance boost. Since so few (none in the current snort rule set) exploits 5425are against mail data, this is relatively safe to do and can improve the 5426performance of data inspection. 5427 5428The configuration options are described below: 5429 5430\begin{slist} 5431 5432\item \texttt{ports \{ <port> [<port>] ... \}} 5433 5434This specifies on what ports to check for SMTP data. Typically, this will 5435include 25 and possibly 465, for encrypted SMTP. 5436 5437\item \texttt{inspection\_type <stateful | stateless>} 5438 5439Indicate whether to operate in stateful or stateless mode. 5440 5441\item \texttt{normalize <all | none | cmds>} 5442 5443This turns on normalization. Normalization checks for more than one space 5444character after a command. Space characters are defined as space (ASCII 0x20) 5445or tab (ASCII 0x09). 5446 5447\texttt{all} checks all commands 5448 5449\texttt{none} turns off normalization for all commands. 5450 5451\texttt{cmds} just checks commands listed with the \texttt{normalize\_cmds} parameter. 5452 5453\item \texttt{ignore\_data} 5454 5455Ignore data section of mail (except for mail headers) when processing rules. 5456 5457\item \texttt{ignore\_tls\_data} 5458 5459Ignore TLS-encrypted data when processing rules. 5460 5461\item \texttt{max\_command\_line\_len <int>} 5462 5463Alert if an SMTP command line is longer than this value. Absence of this 5464option or a "0" means never alert on command line length. RFC 2821 recommends 5465512 as a maximum command line length. 5466 5467\item \texttt{max\_header\_line\_len <int>} 5468 5469Alert if an SMTP DATA header line is longer than this value. Absence of this 5470option or a "0" means never alert on data header line length. RFC 2821 5471recommends 1024 as a maximum data header line length. 5472 5473\item \texttt{max\_response\_line\_len <int>} 5474 5475Alert if an SMTP response line is longer than this value. Absence of this 5476option or a "0" means never alert on response line length. RFC 2821 recommends 5477512 as a maximum response line length. 5478 5479\item \texttt{alt\_max\_command\_line\_len <int> \{ <cmd> [<cmd>] \}} 5480 5481Overrides \texttt{max\_command\_line\_len} for specific commands. 5482 5483\item \texttt{no\_alerts} 5484 5485Turn off all alerts for this preprocessor. 5486 5487\item \texttt{invalid\_cmds \{ <Space-delimited list of commands> \}} 5488 5489Alert if this command is sent from client side. Default is an empty list. 5490 5491\item \texttt{valid\_cmds \{ <Space-delimited list of commands> \}} 5492 5493List of valid commands. We do not alert on commands in this list. Default is 5494an empty list, but preprocessor has this list hard-coded: 5495 5496\begin{itemize} 5497\item[] 5498\{ ATRN AUTH BDAT DATA DEBUG EHLO EMAL ESAM ESND ESOM ETRN EVFY EXPN 5499HELO HELP IDENT MAIL NOOP QUIT RCPT RSET SAML SOML SEND ONEX QUEU 5500STARTTLS TICK TIME TURN TURNME VERB VRFY X-EXPS X-LINK2STATE 5501XADR XAUTH XCIR XEXCH50 XGEN XLICENSE XQUE XSTA XTRN XUSR \} 5502\end{itemize} 5503 5504\item \texttt{data\_cmds \{ <Space-delimited list of commands> \}} 5505 5506List of commands that initiate sending of data with an end of data delimiter 5507the same as that of the DATA command per RFC 5321 - \texttt{"<CRLF>.<CRLF>"}. 5508Default is \{ DATA \}. 5509 5510\item \texttt{binary\_data\_cmds \{ <Space-delimited list of commands> \}} 5511 5512List of commands that initiate sending of data and use a length value after 5513the command to indicate the amount of data to be sent, similar to that of the 5514BDAT command per RFC 3030. Default is \{ BDAT XEXCH50 \}. 5515 5516\item \texttt{auth\_cmds \{ <Space-delimited list of commands> \}} 5517 5518List of commands that initiate an authentication exchange between client 5519and server. Default is \{ AUTH XAUTH X-EXPS \}. 5520 5521\item \texttt{alert\_unknown\_cmds} 5522 5523Alert if we don't recognize command. Default is off. 5524 5525\item \texttt{normalize\_cmds \{ <Space-delimited list of commands> \}} 5526 5527Normalize this list of commands Default is \{ RCPT VRFY EXPN \}. 5528 5529\item \texttt{xlink2state \{ enable | disable [drop] \}} 5530 5531Enable/disable xlink2state alert. Drop if alerted. Default is 5532\texttt{enable}. 5533 5534\item \texttt{print\_cmds} 5535 5536List all commands understood by the preprocessor. This not normally printed 5537out with the configuration because it can print so much data. 5538 5539\item \texttt{disabled} 5540 5541Disables the SMTP preprocessor in a config. This is useful when specifying 5542the decoding depths such as \texttt{b64\_decode\_depth}, \texttt{qp\_decode\_depth}, 5543\texttt{uu\_decode\_depth}, \texttt{bitenc\_decode\_depth} or the memcap used for 5544decoding \texttt{max\_mime\_mem} in default config without turning on the SMTP preprocessor. 5545 5546\item \texttt{b64\_decode\_depth} 5547 5548This config option is used to turn off/on or set the base64 decoding depth used to 5549decode the base64 encoded MIME attachments. The value ranges from -1 to 65535. 5550A value of -1 turns off the base64 decoding of MIME attachments. The value of 0 5551sets the decoding of base64 encoded MIME attachments to unlimited. A value other 5552than 0 or -1 restricts the decoding of base64 MIME attachments, and applies per attachment. 5553A SMTP preprocessor alert with sid 10 is generated (if enabled) when the decoding fails. 5554 5555Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 5556is turned on the base64 encoded MIME attachments/data across multiple packets are decoded too. 5557 5558The decoded data is available for detection using the rule option \texttt{file\_data}. 5559See \ref{sub:file_data} rule option for more details. 5560 5561This option replaces the deprecated options, \texttt{enable\_mime\_decoding} and 5562\texttt{max\_mime\_depth}. It is recommended that user inputs a value that is a 5563multiple of 4. When the value specified is not a multiple of 4, the SMTP preprocessor 5564will round it up to the next multiple of 4. 5565 5566In case of multiple configs, the value specified in the non-default config cannot 5567exceed the value specified in the default config. 5568 5569\item \texttt{qp\_decode\_depth} 5570 5571This config option is used to turn off/on or set the Quoted-Printable decoding depth 5572used to decode the Quoted-Printable(QP) encoded MIME attachments. The value ranges 5573from -1 to 65535. A value of -1 turns off the QP decoding of MIME attachments. 5574The value of 0 sets the decoding of QP encoded MIME attachments to unlimited. A 5575value other than 0 or -1 restricts the decoding of QP MIME attachments, and applies per 5576attachment. A SMTP preprocessor alert with sid 11 is generated (if enabled) when the decoding fails. 5577 5578Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 5579is turned on the QP encoded MIME attachments/data across multiple packets are decoded too. 5580 5581The decoded data is available for detection using the rule option \texttt{file\_data}. 5582See \ref{sub:file_data} rule option for more details. 5583 5584In case of multiple configs, the value specified in the non-default config cannot exceed 5585the value specified in the default config. 5586 5587\item \texttt{bitenc\_decode\_depth} 5588 5589This config option is used to turn off/on or set the non-encoded MIME extraction 5590depth used to extract the non-encoded MIME attachments. The value ranges from -1 5591to 65535. A value of -1 turns off the extraction of these MIME attachments. 5592The value of 0 sets the extraction of these MIME attachments to unlimited. 5593A value other than 0 or -1 restricts the extraction of these MIME attachments, and applies 5594per attachment. 5595 5596Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 5597is turned on the non-encoded MIME attachments/data across multiple packets are extracted too. 5598 5599The extracted data is available for detection using the rule option \texttt{file\_data}. 5600See \ref{sub:file_data} rule option for more details. 5601 5602In case of multiple configs, the value specified in the non-default config cannot exceed 5603the value specified in the default config. 5604 5605\item \texttt{uu\_decode\_depth} 5606 5607This config option is used to turn off/on or set the Unix-to-Unix decoding depth 5608used to decode the Unix-to-Unix(UU) encoded attachments. The value ranges 5609from -1 to 65535. A value of -1 turns off the UU decoding of SMTP attachments. 5610The value of 0 sets the decoding of UU encoded SMTP attachments to unlimited. A 5611value other than 0 or -1 restricts the decoding of UU SMTP attachments, and applies 5612per attachment. A SMTP preprocessor alert with sid 13 is generated (if enabled) when the decoding fails. 5613 5614Multiple UU attachments/data in one packet are pipelined. When stateful inspection 5615is turned on the UU encoded SMTP attachments/data across multiple packets are decoded too. 5616 5617The decoded data is available for detection using the rule option \texttt{file\_data}. 5618See \ref{sub:file_data} rule option for more details. 5619 5620In case of multiple configs, the value specified in the non-default config cannot exceed 5621the value specified in the default config. 5622 5623\item \texttt{enable\_mime\_decoding} 5624 5625Enables Base64 decoding of Mime attachments/data. Multiple base64 encoded MIME 5626attachments/data in one packet are pipelined. When stateful inspection is turned 5627on the base64 encoded MIME attachments/data across multiple packets are decoded too. 5628The decoding of base64 encoded attachments/data ends when either the 5629\texttt{max\_mime\_depth} or maximum MIME sessions (calculated using 5630\texttt{max\_mime\_depth} and \texttt{max\_mime\_mem}) is reached or when the 5631encoded data ends. The decoded data is available for detection using the rule option 5632\texttt{file\_data}. See \ref{sub:file_data} rule option for more details. 5633 5634This option is deprecated. Use the option \texttt{b64\_decode\_depth} to turn off 5635or on the base64 decoding instead. 5636 5637\item \texttt{max\_mime\_depth <int>} 5638 5639Specifies the maximum number of base64 encoded data to decode per SMTP attachment. 5640The option take values ranging from 4 to 20480 bytes. The default value for this 5641in snort in 1460 bytes. 5642 5643It is recommended that user inputs a value that is a multiple of 4. When the value 5644specified is not a multiple of 4, the SMTP preprocessor will round it up to the next 5645multiple of 4. 5646 5647This option is deprecated. Use the option \texttt{b64\_decode\_depth} to turn off 5648or on the base64 decoding instead. 5649 5650\item \texttt{max\_mime\_mem <int>} 5651 5652This option determines (in bytes) the maximum amount of memory the SMTP preprocessor 5653will use for decoding base64 encoded/quoted-printable/non-encoded MIME attachments/data 5654or Unix-to-Unix encoded attachments. This value can be set from 3276 bytes to 100MB. 5655 5656This option along with the maximum of the decoding depths will determine the SMTP 5657sessions that will be decoded at any given instant. The default value for this option 5658is 838860. 5659 5660Note: It is suggested to set this value such that the max smtp session calculated as 5661follows is at least 1. 5662 5663max smtp session = \texttt{max\_mime\_mem} /(2 * max of (\texttt{b64\_decode\_depth}, 5664 \texttt{uu\_decode\_depth}, \texttt{qp\_decode\_depth} 5665 or \texttt{bitenc\_decode\_depth})) 5666 5667For example, if \texttt{b64\_decode\_depth} is 0 (indicates unlimited decoding) and 5668\texttt{qp\_decode\_depth} is 100, then 5669 5670max smtp session = \texttt{max\_mime\_mem}/2*65535 (max value for \texttt{b64\_decode\_depth}) 5671 5672In case of multiple configs, the \texttt{max\_mime\_mem} of the non-default configs will be overwritten by the 5673default config's value. Hence user needs to define it in the default config with the new keyword 5674disabled (used to disable SMTP preprocessor in a config). 5675 5676\item \texttt{log\_mailfrom} 5677This option enables SMTP preprocessor to parse and log the sender's email address extracted 5678from the "MAIL FROM" command along with all the generated events for that session. The maximum 5679number of bytes logged for this option is 1024. 5680 5681Please note, this is logged only with the unified2 output and is not logged with console output (-A cmg). 5682u2spewfoo can be used to read this data from the unified2. 5683 5684\item \texttt{log\_rcptto} 5685This option enables SMTP preprocessor to parse and log the recipient's email addresses 5686extracted from the "RCPT TO" command along with all the generated events for that session. 5687Multiple recipients are appended with commas. The maximum number of bytes logged for this option is 1024. 5688 5689Please note, this is logged only with the unified2 output and is not logged with console output (-A cmg). 5690 u2spewfoo can be used to read this data from the unified2. 5691 5692\item \texttt{log\_filename} 5693This option enables SMTP preprocessor to parse and log the MIME attachment filenames extracted 5694from the Content-Disposition header within the MIME body along with all the generated events 5695for that session. Multiple filenames are appended with commas. The maximum number of bytes logged 5696for this option is 1024. 5697 5698Please note, this is logged only with the unified2 output and is not logged with the 5699console output (-A cmg). u2spewfoo can be used to read this data from the unified2. 5700 5701\item \texttt{log\_email\_hdrs} 5702This option enables SMTP preprocessor to parse and log the SMTP email headers extracted from 5703SMTP data along with all generated events for that session. The number of bytes extracted and 5704logged depends upon the \texttt{email\_hdrs\_log\_depth}. 5705 5706Please note, this is logged only with the unified2 output and is not logged with the console output (-A cmg). 5707u2spewfoo can be used to read this data from the unified2. 5708 5709\item \texttt{email\_hdrs\_log\_depth <int>} 5710This option specifies the depth for logging email headers. The allowed range for this option is 57110 - 20480. A value of 0 will disable email headers logging. The default value for this option is 1464. 5712 5713Please note, in case of multiple policies, the value specified in the default policy is used and the values 5714specified in the targeted policies are overwritten by the default value. 5715This option must be configured in the default policy even if the SMTP configuration is disabled. 5716 5717\item \texttt{memcap <int>} 5718This option determines in bytes the maximum amount of memory the SMTP preprocessor will 5719use for logging of filename, MAIL FROM addresses, RCPT TO addresses and email headers. This value 5720along with the buffer size used to log MAIL FROM, RCPT TO, filenames and \texttt{email\_hdrs\_log\_depth} 5721will determine the maximum SMTP sessions that will log the email headers at any given time. When this memcap 5722is reached SMTP will stop logging the filename, MAIL FROM address, RCPT TO addresses and email headers 5723until memory becomes available. 5724 5725Max SMTP sessions logging email headers at any given time 5726 = memcap/(1024 + 1024 + 1024 + \texttt{email\_hdrs\_log\_depth}) 5727 5728The size 1024 is the maximum buffer size used for logging filename, RCPTTO and MAIL FROM addresses. 5729 5730Default value for this option is 838860. The allowed range for this option is 3276 to 104857600. 5731The value specified in the default config is used when this option is specified in multiple configs. 5732This option must be configured in the default config even if the SMTP configuration is disabled. 5733 5734Please note, in case of multiple policies, the value specified in the default policy is used and the values 5735specified in the targeted policies are overwritten by the default value. 5736This option must be configured in the default policy even if the SMTP configuration is disabled. 5737 5738\end{slist} 5739 5740\subsubsection{Example} 5741 5742\begin{verbatim} 5743 preprocessor SMTP: \ 5744 ports { 25 } \ 5745 inspection_type stateful \ 5746 normalize cmds \ 5747 normalize_cmds { EXPN VRFY RCPT } \ 5748 ignore_data \ 5749 ignore_tls_data \ 5750 max_command_line_len 512 \ 5751 max_header_line_len 1024 \ 5752 max_response_line_len 512 \ 5753 no_alerts \ 5754 alt_max_command_line_len 300 { RCPT } \ 5755 invalid_cmds { } \ 5756 valid_cmds { } \ 5757 xlink2state { disable } \ 5758 print_cmds \ 5759 log_filename \ 5760 log_email_hdrs \ 5761 log_mailfrom \ 5762 log_rcptto \ 5763 email_hdrs_log_depth 2920 \ 5764 memcap 6000 5765 5766 preprocessor SMTP: \ 5767 b64_decode_depth 0\ 5768 max_mime_mem 4000 \ 5769 memcap 6000 \ 5770 email_hdrs_log_depth 2920 \ 5771 disabled 5772\end{verbatim} 5773 5774\subsubsection{Default} 5775 5776\begin{verbatim} 5777 preprocessor SMTP: \ 5778 ports { 25 } \ 5779 inspection_type stateful \ 5780 normalize cmds \ 5781 normalize_cmds { EXPN VRFY RCPT } \ 5782 alt_max_command_line_len 260 { MAIL } \ 5783 alt_max_command_line_len 300 { RCPT } \ 5784 alt_max_command_line_len 500 { HELP HELO ETRN } \ 5785 alt_max_command_line_len 255 { EXPN VRFY } 5786\end{verbatim} 5787 5788\subsubsection{Note} 5789 5790\texttt{RCPT TO:} and \texttt{MAIL FROM:} are SMTP commands. For the 5791preprocessor configuration, they are referred to as RCPT and MAIL, 5792respectively. Within the code, the preprocessor actually maps RCPT and MAIL to 5793the correct command name. 5794 5795\subsection{POP Preprocessor} 5796\label{POP} 5797 5798POP is an POP3 decoder for user applications. Given a data buffer, 5799POP will decode the buffer and find POP3 commands and responses. 5800It will also mark the command, data header data body sections and 5801extract the POP3 attachments and decode it appropriately. 5802 5803POP will handle stateful processing. It saves state between individual 5804packets. However maintaining correct state is dependent on the reassembly 5805of the server side of the stream (i.e., a loss of coherent stream data results 5806in a loss of state). 5807 5808Stream should be turned on for POP. Please ensure that the POP ports are added 5809 to the stream5 ports for proper reassembly. 5810 5811The POP preprocessor uses GID 142 to register events. 5812 5813\subsubsection{Configuration} 5814 5815The configuration options are described below: 5816 5817\begin{slist} 5818 5819\item \texttt{ports \{ <port> [<port>] ... \}} 5820 5821This specifies on what ports to check for POP data. Typically, this will 5822include 110. Default ports if none are specified are 110 . 5823 5824\item \texttt{disabled} 5825 5826Disables the POP preprocessor in a config. This is useful when specifying 5827the decoding depths such as \texttt{b64\_decode\_depth}, \texttt{qp\_decode\_depth}, 5828\texttt{uu\_decode\_depth}, \texttt{bitenc\_decode\_depth} or the memcap used for 5829decoding \texttt{memcap} in default config without turning on the POP preprocessor. 5830 5831\item \texttt{b64\_decode\_depth} 5832 5833This config option is used to turn off/on or set the base64 decoding depth used to 5834decode the base64 encoded MIME attachments. The value ranges from -1 to 65535. 5835A value of -1 turns off the base64 decoding of MIME attachments. The value of 0 5836sets the decoding of base64 encoded MIME attachments to unlimited. A value other 5837than 0 or -1 restricts the decoding of base64 MIME attachments, and applies per 5838attachment. A POP preprocessor alert with sid 4 is generated (if enabled) when the decoding fails. 5839 5840Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 5841is turned on the base64 encoded MIME attachments/data across multiple packets are decoded too. 5842 5843The decoded data is available for detection using the rule option \texttt{file\_data}. 5844See \ref{sub:file_data} rule option for more details. 5845 5846It is recommended that user inputs a value that is a multiple of 4. When the value specified 5847is not a multiple of 4, the POP preprocessor will round it up to the next multiple of 4. 5848 5849In case of multiple configs, the value specified in the non-default config cannot 5850exceed the value specified in the default config. 5851 5852\item \texttt{qp\_decode\_depth} 5853 5854This config option is used to turn off/on or set the Quoted-Printable decoding depth 5855used to decode the Quoted-Printable(QP) encoded MIME attachments. The value ranges 5856from -1 to 65535. A value of -1 turns off the QP decoding of MIME attachments. 5857The value of 0 sets the decoding of QP encoded MIME attachments to unlimited. A 5858value other than 0 or -1 restricts the decoding of QP MIME attachments, and applies per 5859attachment. A POP preprocessor alert with sid 5 is generated (if enabled) when the decoding fails. 5860 5861Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 5862is turned on the QP encoded MIME attachments/data across multiple packets are decoded too. 5863 5864The decoded data is available for detection using the rule option \texttt{file\_data}. 5865See \ref{sub:file_data} rule option for more details. 5866 5867In case of multiple configs, the value specified in the non-default config cannot exceed 5868the value specified in the default config. 5869 5870\item \texttt{bitenc\_decode\_depth} 5871 5872This config option is used to turn off/on or set the non-encoded MIME extraction 5873depth used to extract the non-encoded MIME attachments. The value ranges from -1 5874to 65535. A value of -1 turns off the extraction of these MIME attachments. 5875The value of 0 sets the extraction of these MIME attachments to unlimited. 5876A value other than 0 or -1 restricts the extraction of these MIME attachments, and applies 5877per attachment. 5878 5879Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 5880is turned on the non-encoded MIME attachments/data across multiple packets are extracted too. 5881 5882The extracted data is available for detection using the rule option \texttt{file\_data}. 5883See \ref{sub:file_data} rule option for more details. 5884 5885In case of multiple configs, the value specified in the non-default config cannot exceed 5886the value specified in the default config. 5887 5888\item \texttt{uu\_decode\_depth} 5889 5890This config option is used to turn off/on or set the Unix-to-Unix decoding depth 5891used to decode the Unix-to-Unix(UU) encoded attachments. The value ranges 5892from -1 to 65535. A value of -1 turns off the UU decoding of POP attachments. 5893The value of 0 sets the decoding of UU encoded POP attachments to unlimited. A 5894value other than 0 or -1 restricts the decoding of UU POP attachments, and applies per 5895attachment. A POP preprocessor alert with sid 7 is generated (if enabled) when the decoding fails. 5896 5897Multiple UU attachments/data in one packet are pipelined. When stateful inspection 5898is turned on the UU encoded POP attachments/data across multiple packets are decoded too. 5899 5900The decoded data is available for detection using the rule option \texttt{file\_data}. 5901See \ref{sub:file_data} rule option for more details. 5902 5903In case of multiple configs, the value specified in the non-default config cannot exceed 5904the value specified in the default config. 5905 5906\item \texttt{memcap <int>} 5907 5908This option determines (in bytes) the maximum amount of memory the POP preprocessor 5909will use for decoding base64 encoded/quoted-printable/non-encoded MIME attachments/data 5910or Unix-to-Unix encoded attachments. This value can be set from 3276 bytes to 100MB. 5911 5912This option along with the maximum of the decoding depths will determine the POP 5913sessions that will be decoded at any given instant. The default value for this option 5914is 838860. 5915 5916Note: It is suggested to set this value such that the max pop session calculated as 5917follows is at least 1. 5918 5919max pop session = \texttt{memcap} /(2 * max of (\texttt{b64\_decode\_depth}, 5920 \texttt{uu\_decode\_depth}, \texttt{qp\_decode\_depth} 5921 or \texttt{bitenc\_decode\_depth})) 5922 5923For example, if \texttt{b64\_decode\_depth} is 0 (indicates unlimited decoding) and 5924\texttt{qp\_decode\_depth} is 100, then 5925 5926max pop session = \texttt{memcap}/2*65535 (max value for \texttt{b64\_decode\_depth}) 5927 5928In case of multiple configs, the \texttt{memcap} of the non-default configs will be overwritten by the 5929default config's value. Hence user needs to define it in the default config with the new keyword 5930disabled (used to disable POP preprocessor in a config). 5931 5932When the memcap for decoding (\texttt{memcap}) is exceeded the POP preprocessor alert with sid 3 is 5933generated (when enabled). 5934 5935\end{slist} 5936 5937\subsubsection{Example} 5938 5939\begin{verbatim} 5940 preprocessor pop: \ 5941 ports { 110 } \ 5942 memcap 1310700 \ 5943 qp_decode_depth -1 \ 5944 b64_decode_depth 0 \ 5945 bitenc_decode_depth 100 5946 5947 5948 preprocessor pop: \ 5949 memcap 1310700 \ 5950 qp_decode_depth 0 \ 5951 disabled 5952\end{verbatim} 5953 5954\subsubsection{Default} 5955 5956\begin{verbatim} 5957 preprocessor pop: \ 5958 ports { 110 } \ 5959 b64_decode_depth 1460 \ 5960 qp_decode_depth 1460 \ 5961 bitenc_decode_depth 1460 \ 5962 uu_decode_depth 1460 5963\end{verbatim} 5964 5965\subsection{IMAP Preprocessor} 5966\label{IMAP} 5967 5968IMAP is an IMAP4 decoder for user applications. Given a data buffer, 5969IMAP will decode the buffer and find IMAP4 commands and responses. 5970It will also mark the command, data header data body sections and 5971extract the IMAP4 attachments and decode it appropriately. 5972 5973IMAP will handle stateful processing. It saves state between individual 5974packets. However maintaining correct state is dependent on the reassembly 5975of the server side of the stream (i.e., a loss of coherent stream data results 5976in a loss of state). 5977 5978Stream should be turned on for IMAP. Please ensure that the IMAP ports are added 5979 to the stream5 ports for proper reassembly. 5980 5981The IMAP preprocessor uses GID 141 to register events. 5982 5983\subsubsection{Configuration} 5984 5985The configuration options are described below: 5986 5987\begin{slist} 5988 5989\item \texttt{ports \{ <port> [<port>] ... \}} 5990 5991This specifies on what ports to check for IMAP data. Typically, this will 5992include 143. Default ports if none are specified are 143 . 5993 5994\item \texttt{disabled} 5995 5996Disables the IMAP preprocessor in a config. This is useful when specifying 5997the decoding depths such as \texttt{b64\_decode\_depth}, \texttt{qp\_decode\_depth}, 5998\texttt{uu\_decode\_depth}, \texttt{bitenc\_decode\_depth} or the memcap used for 5999decoding \texttt{memcap} in default config without turning on the IMAP preprocessor. 6000 6001\item \texttt{b64\_decode\_depth} 6002 6003This config option is used to turn off/on or set the base64 decoding depth used to 6004decode the base64 encoded MIME attachments. The value ranges from -1 to 65535. 6005A value of -1 turns off the base64 decoding of MIME attachments. The value of 0 6006sets the decoding of base64 encoded MIME attachments to unlimited. A value other 6007than 0 or -1 restricts the decoding of base64 MIME attachments, and applies per attachment. 6008A IMAP preprocessor alert with sid 4 is generated (if enabled) when the decoding fails. 6009 6010Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 6011is turned on the base64 encoded MIME attachments/data across multiple packets are decoded too. 6012 6013The decoded data is available for detection using the rule option \texttt{file\_data}. 6014See \ref{sub:file_data} rule option for more details. 6015 6016It is recommended that user inputs a value that is a multiple of 4. When the value specified 6017is not a multiple of 4, the IMAP preprocessor will round it up to the next multiple of 4. 6018 6019In case of multiple configs, the value specified in the non-default config cannot 6020exceed the value specified in the default config. 6021 6022\item \texttt{qp\_decode\_depth} 6023 6024This config option is used to turn off/on or set the Quoted-Printable decoding depth 6025used to decode the Quoted-Printable(QP) encoded MIME attachments. The value ranges 6026from -1 to 65535. A value of -1 turns off the QP decoding of MIME attachments. 6027The value of 0 sets the decoding of QP encoded MIME attachments to unlimited. A 6028value other than 0 or -1 restricts the decoding of QP MIME attachments, and applies per 6029attachment. A IMAP preprocessor alert with sid 5 is generated (if enabled) when the decoding fails. 6030 6031Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 6032is turned on the QP encoded MIME attachments/data across multiple packets are decoded too. 6033 6034The decoded data is available for detection using the rule option \texttt{file\_data}. 6035See \ref{sub:file_data} rule option for more details. 6036 6037In case of multiple configs, the value specified in the non-default config cannot exceed 6038the value specified in the default config. 6039 6040\item \texttt{bitenc\_decode\_depth} 6041 6042This config option is used to turn off/on or set the non-encoded MIME extraction 6043depth used to extract the non-encoded MIME attachments. The 6044value ranges from -1 to 65535. A value of -1 turns off the extraction of these MIME 6045attachments. The value of 0 sets the extraction of these MIME attachments to unlimited. 6046A value other than 0 or -1 restricts the extraction of these MIME attachments, and applies 6047per attachment. 6048 6049Multiple MIME attachments/data in one packet are pipelined. When stateful inspection 6050is turned on the non-encoded MIME attachments/data across multiple packets are extracted too. 6051 6052The extracted data is available for detection using the rule option \texttt{file\_data}. 6053See \ref{sub:file_data} rule option for more details. 6054 6055In case of multiple configs, the value specified in the non-default config cannot exceed 6056the value specified in the default config. 6057 6058\item \texttt{uu\_decode\_depth} 6059 6060This config option is used to turn off/on or set the Unix-to-Unix decoding depth 6061used to decode the Unix-to-Unix(UU) encoded attachments. The value ranges 6062from -1 to 65535. A value of -1 turns off the UU decoding of IMAP attachments. 6063The value of 0 sets the decoding of UU encoded IMAP attachments to unlimited. A 6064value other than 0 or -1 restricts the decoding of UU IMAP attachments, and applies per 6065attachment. A IMAP preprocessor alert with sid 7 is generated (if enabled) when the decoding fails. 6066 6067Multiple UU attachments/data in one packet are pipelined. When stateful inspection 6068is turned on the UU encoded IMAP attachments/data across multiple packets are decoded too. 6069 6070The decoded data is available for detection using the rule option \texttt{file\_data}. 6071See \ref{sub:file_data} rule option for more details. 6072 6073In case of multiple configs, the value specified in the non-default config cannot exceed 6074the value specified in the default config. 6075 6076\item \texttt{memcap <int>} 6077 6078This option determines (in bytes) the maximum amount of memory the IMAP preprocessor 6079will use for decoding base64 encoded/quoted-printable/non-encoded MIME attachments/data 6080or Unix-to-Unix encoded attachments. This value can be set from 3276 bytes to 100MB. 6081 6082This option along with the maximum of the decoding depths will determine the IMAP 6083sessions that will be decoded at any given instant. The default value for this option 6084is 838860. 6085 6086Note: It is suggested to set this value such that the max imap session calculated as 6087follows is at least 1. 6088 6089max imap session = \texttt{memcap} /(2 * max of (\texttt{b64\_decode\_depth}, 6090 \texttt{uu\_decode\_depth}, \texttt{qp\_decode\_depth} 6091 or \texttt{bitenc\_decode\_depth})) 6092 6093For example, if \texttt{b64\_decode\_depth} is 0 (indicates unlimited decoding) and 6094\texttt{qp\_decode\_depth} is 100, then 6095 6096max imap session = \texttt{memcap}/2*65535 (max value for \texttt{b64\_decode\_depth}) 6097 6098In case of multiple configs, the \texttt{memcap} of the non-default configs will be overwritten by the 6099default config's value. Hence user needs to define it in the default config with the new keyword 6100disabled (used to disable IMAP preprocessor in a config). 6101 6102When the memcap for decoding (\texttt{memcap}) is exceeded the IMAP preprocessor alert with sid 3 is 6103generated (when enabled). 6104 6105\end{slist} 6106 6107\subsubsection{Example} 6108 6109\begin{verbatim} 6110 preprocessor imap: \ 6111 ports { 110 } \ 6112 memcap 1310700 \ 6113 qp_decode_depth -1 \ 6114 b64_decode_depth 0 \ 6115 bitenc_decode_depth 100 6116 6117 6118 preprocessor imap: \ 6119 memcap 1310700 \ 6120 qp_decode_depth 0 \ 6121 disabled 6122\end{verbatim} 6123 6124\subsubsection{Default} 6125 6126\begin{verbatim} 6127 preprocessor imap: \ 6128 ports { 110 } \ 6129 b64_decode_depth 1460 \ 6130 qp_decode_depth 1460 \ 6131 bitenc_decode_depth 1460 \ 6132 uu_decode_depth 1460 6133\end{verbatim} 6134 6135\subsection{FTP/Telnet Preprocessor} 6136\label{sub:ftptelnet} 6137 6138FTP/Telnet is an improvement to the Telnet decoder and provides stateful 6139inspection capability for both FTP and Telnet data streams. FTP/Telnet will 6140decode the stream, identifying FTP commands and responses and Telnet escape 6141sequences and normalize the fields. FTP/Telnet works on both client requests 6142and server responses. 6143 6144FTP/Telnet has the capability to handle stateless processing, meaning it only 6145looks for information on a packet-by-packet basis. 6146 6147The default is to run FTP/Telnet in stateful inspection mode, meaning it looks 6148for information and handles reassembled data correctly. 6149 6150FTP/Telnet has a very ``rich'' user configuration, similar to that of HTTP 6151Inspect (See \ref{sub:http-inspect}). Users can configure individual FTP 6152servers and clients with a variety of options, which should allow the user to 6153emulate any type of FTP server or FTP Client. Within FTP/Telnet, there are 6154four areas of configuration: Global, Telnet, FTP Client, and FTP Server. 6155 6156\begin{note} 6157 6158Some configuration options have an argument of \texttt{yes} or \texttt{no}. 6159This argument specifies whether the user wants the configuration option to 6160generate a ftptelnet alert or not. The presence of the option indicates the 6161option itself is on, while the \texttt{yes/no} argument applies to the alerting 6162functionality associated with that option. 6163 6164\end{note} 6165 6166\subsubsection{Global Configuration} 6167 6168The global configuration deals with configuration options that determine the 6169global functioning of FTP/Telnet. The following example gives the generic 6170global configuration format: 6171 6172\subsubsection{Format} 6173 6174\begin{verbatim} 6175 preprocessor ftp_telnet: \ 6176 global \ 6177 inspection_type stateful \ 6178 encrypted_traffic yes \ 6179 check_encrypted 6180\end{verbatim} 6181 6182You can only have a single global configuration, you'll get an error if you try 6183otherwise. The FTP/Telnet global configuration must appear before the other 6184three areas of configuration. 6185 6186\paragraph{Configuration} 6187\begin{slist} 6188\item \texttt{inspection\_type} 6189 6190This indicates whether to operate in stateful or stateless mode. 6191 6192\item \texttt{encrypted\_traffic $<$yes|no$>$} 6193 6194This option enables detection and alerting on encrypted Telnet and FTP command 6195channels. 6196 6197\begin{note} 6198 6199When \texttt{inspection\_type} is in stateless mode, checks for encrypted 6200traffic will occur on every packet, whereas in stateful mode, a particular 6201session will be noted as encrypted and not inspected any further. 6202 6203\end{note} 6204 6205\item \texttt{check\_encrypted} 6206 6207Instructs the preprocessor to continue to check an encrypted session for a 6208subsequent command to cease encryption. 6209 6210\end{slist} 6211 6212\subsubsection{Example Global Configuration} 6213 6214\begin{verbatim} 6215 preprocessor ftp_telnet: \ 6216 global inspection_type stateful encrypted_traffic no 6217\end{verbatim} 6218 6219\subsubsection{Telnet Configuration} 6220 6221The telnet configuration deals with configuration options that determine the 6222functioning of the Telnet portion of the preprocessor. The following example 6223gives the generic telnet configuration format: 6224 6225\subsubsection{Format} 6226\begin{verbatim} 6227 preprocessor ftp_telnet_protocol: \ 6228 telnet \ 6229 ports { 23 } \ 6230 normalize \ 6231 ayt_attack_thresh 6 \ 6232 detect_anomalies 6233 6234\end{verbatim} 6235 6236There should only be a single telnet configuration, and subsequent instances 6237will override previously set values. 6238 6239\paragraph{Configuration} 6240\begin{slist} 6241\item \texttt{ports $\{ <$port$> [<$port$> <...>] \}$} 6242 6243This is how the user configures which ports to decode as telnet traffic. SSH 6244tunnels cannot be decoded, so adding port 22 will only yield false positives. 6245Typically port 23 will be included. 6246 6247\item \texttt{normalize} 6248 6249This option tells the preprocessor to normalize the telnet traffic by 6250eliminating the telnet escape sequences. It functions similarly to its 6251predecessor, the telnet\_decode preprocessor. Rules written with 'raw' content 6252options will ignore the normalized buffer that is created when this option is 6253in use. 6254 6255\item \texttt{ayt\_attack\_thresh $<$ number $>$} 6256 6257This option causes the preprocessor to alert when the number of consecutive 6258telnet Are You There (AYT) commands reaches the number specified. It is only 6259applicable when the mode is stateful. 6260 6261\item \texttt{detect\_anomalies} 6262 6263In order to support certain options, Telnet supports subnegotiation. Per the 6264Telnet RFC, subnegotiation begins with SB (subnegotiation begin) and must end 6265with an SE (subnegotiation end). However, certain implementations of Telnet 6266servers will ignore the SB without a corresponding SE. This is anomalous 6267behavior which could be an evasion case. Being that FTP uses the Telnet 6268protocol on the control connection, it is also susceptible to this behavior. 6269The \texttt{detect\_anomalies} option enables alerting on Telnet SB without the 6270corresponding SE. 6271 6272\end{slist} 6273 6274\subsubsection{Example Telnet Configuration} 6275 6276\begin{verbatim} 6277 preprocessor ftp_telnet_protocol: \ 6278 telnet ports { 23 } normalize ayt_attack_thresh 6 6279\end{verbatim} 6280 6281\subsubsection{FTP Server Configuration} 6282 6283There are two types of FTP server configurations: default and by IP address. 6284 6285\paragraph{Default} 6286 6287This configuration supplies the default server configuration for any FTP server 6288that is not individually configured. Most of your FTP servers will most likely 6289end up using the default configuration. 6290 6291\subsubsection{Example Default FTP Server Configuration} 6292 6293\begin{verbatim} 6294 preprocessor ftp_telnet_protocol: \ 6295 ftp server default ports { 21 } 6296\end{verbatim} 6297 6298Refer to \pageref{sub:default ftp server config} for the list of options set in default ftp server configuration. 6299 6300\paragraph{Configuration by IP Address} 6301 6302This format is very similar to ``default'', the only difference being that 6303specific IPs can be configured. 6304 6305\subsubsection{Example IP specific FTP Server Configuration} 6306 6307\begin{verbatim} 6308 preprocessor _telnet_protocol: \ 6309 ftp server 10.1.1.1 ports { 21 } ftp_cmds { XPWD XCWD } 6310\end{verbatim} 6311 6312\subsubsection{FTP Server Configuration Options} 6313 6314\begin{slist} 6315\item \texttt{ports $\{ <$port$> [<$port$> <...>] \}$} 6316 6317This is how the user configures which ports to decode as FTP command channel 6318traffic. Typically port 21 will be included. 6319 6320\item \texttt{print\_cmds} 6321 6322During initialization, this option causes the preprocessor to print the 6323configuration for each of the FTP commands for this server. 6324 6325\item \texttt{ftp\_cmds $\{ cmd [cmd] \}$ } 6326 6327The preprocessor is configured to alert when it sees an FTP command that is not 6328allowed by the server. 6329 6330This option specifies a list of additional commands allowed by this server, 6331outside of the default FTP command set as specified in RFC 959. This may be 6332used to allow the use of the 'X' commands identified in RFC 775, as well as any 6333additional commands as needed. 6334 6335For example: 6336 6337\begin{verbatim} 6338 ftp_cmds { XPWD XCWD XCUP XMKD XRMD } 6339\end{verbatim} 6340 6341\item \texttt{def\_max\_param\_len $<$number$>$} 6342 6343This specifies the default maximum allowed parameter length for an FTP command. 6344It can be used as a basic buffer overflow detection. 6345 6346\item \texttt{alt\_max\_param\_len $<$number$>$ $\{ cmd [cmd] \}$} 6347 6348This specifies the maximum allowed parameter length for the specified FTP 6349command(s). It can be used as a more specific buffer overflow detection. For 6350example the USER command -- usernames may be no longer than 16 bytes, so the 6351appropriate configuration would be: 6352 6353\begin{verbatim} 6354 alt_max_param_len 16 { USER } 6355\end{verbatim} 6356 6357\item \texttt{chk\_str\_fmt $\{ cmd [cmd] \}$} 6358 6359This option causes a check for string format attacks in the specified commands. 6360 6361\item \texttt{cmd\_validity cmd $<$ fmt $>$} 6362 6363This option specifies the valid format for parameters of a given command. 6364 6365fmt must be enclosed in $<>$'s and may contain the following: 6366 6367\begin{center} 6368\begin{tabular}{| l | p{3in} |} 6369 6370\hline 6371\textbf{Value} & \textbf{Description} \\ 6372\hline 6373 6374\hline 6375int & Parameter must be an integer \\ 6376 6377\hline 6378number & Parameter must be an integer between 1 and 255 \\ 6379 6380\hline 6381char $<$chars$>$ & Parameter must be a single character, one of $<$chars$>$ \\ 6382 6383\hline 6384date $<$datefmt$>$ & Parameter follows format specified, where: 6385 6386\begin{tabular}{ l l } 6387n & Number \\ 6388C & Character \\ 6389$[]$ & optional format enclosed \\ 6390$|$ & OR \\ 6391$\{\}$ & choice of options \\ 6392. + - & literal \\ 6393\end{tabular} \\ 6394 6395\hline 6396string & Parameter is a string (effectively unrestricted) \\ 6397 6398\hline 6399host\_port & Parameter must be a host/port specified, per RFC 959 \\ 6400 6401\hline 6402long\_host\_port & Parameter must be a long host port specified, per RFC 1639 \\ 6403 6404\hline 6405extended\_host\_port & Parameter must be an extended host port specified, per RFC 2428 \\ 6406 6407\hline 6408$\{\}$, $|$ & One of choices enclosed within, separated by $|$ \\ 6409 6410\hline 6411$\{\}$, $[]$ & One of the choices enclosed within $\{\}$, optional value enclosed within $[]$ \\ 6412 6413\hline 6414\end{tabular} 6415\end{center} 6416 6417Examples of the cmd\_validity option are shown below. These examples are the 6418default checks, per RFC 959 and others performed by the preprocessor. 6419 6420\begin{verbatim} 6421 cmd_validity MODE <char SBC> 6422 cmd_validity STRU <char FRP> 6423 cmd_validity ALLO < int [ char R int ] > 6424 cmd_validity TYPE < { char AE [ char NTC ] | char I | char L [ number ] } > 6425 cmd_validity PORT < host_port > 6426\end{verbatim} 6427 6428A cmd\_validity line can be used to override these defaults and/or add a check 6429for other commands. 6430 6431\begin{verbatim} 6432 # This allows additional modes, including mode Z which allows for 6433 # zip-style compression. 6434 cmd_validity MODE < char ASBCZ > 6435 6436 # Allow for a date in the MDTM command. 6437 cmd_validity MDTM < [ date nnnnnnnnnnnnnn[.n[n[n]]] ] string > 6438\end{verbatim} 6439 6440MDTM is an off case that is worth discussing. While not part of an established 6441standard, certain FTP servers accept MDTM commands that set the modification 6442time on a file. The most common among servers that do, accept a format using 6443YYYYMMDDHHmmss[.uuu]. Some others accept a format using YYYYMMDDHHmmss[+|-]TZ 6444format. The example above is for the first case (time format as specified in 6445http://www.ietf.org/internet-drafts/draft-ietf-ftpext-mlst-16.txt) 6446 6447To check validity for a server that uses the TZ format, use the following: 6448 6449\begin{verbatim} 6450 cmd_validity MDTM < [ date nnnnnnnnnnnnnn[{+|-}n[n]] ] string > 6451\end{verbatim} 6452 6453\item \texttt{telnet\_cmds $<$yes$|$no$>$} 6454 6455This option turns on detection and alerting when telnet escape sequences are 6456seen on the FTP command channel. Injection of telnet escape sequences could be 6457used as an evasion attempt on an FTP command channel. 6458 6459\item \texttt{ignore\_telnet\_erase\_cmds $<$yes|no$>$} 6460 6461This option allows Snort to ignore telnet escape sequences for erase character 6462(TNC EAC) and erase line (TNC EAL) when normalizing FTP command channel. Some FTP 6463servers do not process those telnet escape sequences. 6464 6465\item \texttt{data\_chan} 6466 6467This option causes the rest of snort (rules, other preprocessors) to ignore FTP 6468data channel connections. Using this option means that \textbf{NO INSPECTION} 6469other than TCP state will be performed on FTP data transfers. It can be used 6470to improve performance, especially with large file transfers from a trusted 6471source. If your rule set includes virus-type rules, it is recommended that 6472this option not be used. 6473 6474Use of the "data\_chan" option is deprecated in favor of the 6475"ignore\_data\_chan" option. "data\_chan" will be removed in a future release. 6476 6477\item \texttt{ignore\_data\_chan $<$yes$|$no$>$} 6478 6479This option causes the rest of Snort (rules, other preprocessors) to ignore FTP 6480data channel connections. Setting this option to "yes" means that \textbf{NO 6481INSPECTION} other than TCP state will be performed on FTP data transfers. It 6482can be used to improve performance, especially with large file transfers from a 6483trusted source. If your rule set includes virus-type rules, it is recommended 6484that this option not be used. 6485 6486\end{slist} 6487 6488\subsubsection{FTP Server Base Configuration Options} 6489\label{sub:default ftp server config} 6490 6491The base FTP server configuration is as follows. Options specified in the 6492configuration file will modify this set of options. FTP commands are added to 6493the set of allowed commands. The other options will override those in the base 6494configuration. 6495 6496\begin{verbatim} 6497 def_max_param_len 100 6498 ftp_cmds { USER PASS ACCT CWD CDUP SMNT 6499 QUIT REIN TYPE STRU MODE RETR 6500 STOR STOU APPE ALLO REST RNFR 6501 RNTO ABOR DELE RMD MKD PWD LIST 6502 NLST SITE SYST STAT HELP NOOP } 6503 ftp_cmds { AUTH ADAT PROT PBSZ CONF ENC } 6504 ftp_cmds { PORT PASV LPRT LPSV EPRT EPSV } 6505 ftp_cmds { FEAT OPTS } 6506 ftp_cmds { MDTM REST SIZE MLST MLSD } 6507 alt_max_param_len 0 { CDUP QUIT REIN PASV STOU ABOR PWD SYST NOOP } 6508 cmd_validity MODE < char SBC > 6509 cmd_validity STRU < char FRPO [ string ] > 6510 cmd_validity ALLO < int [ char R int ] > 6511 cmd_validity TYPE < { char AE [ char NTC ] | char I | char L [ number ] } > 6512 cmd_validity PORT < host_port > 6513 cmd_validity LPRT < long_host_port > 6514 cmd_validity EPRT < extd_host_port > 6515 cmd_validity EPSV < [ { '1' | '2' | 'ALL' } ] > 6516\end{verbatim} 6517 6518\subsubsection{FTP Client Configuration} 6519 6520Similar to the FTP Server configuration, the FTP client configurations has two 6521types: default, and by IP address. 6522 6523\paragraph{Default} 6524 6525This configuration supplies the default client configuration for any FTP client 6526that is not individually configured. Most of your FTP clients will most likely 6527end up using the default configuration. 6528 6529\subsubsection{Example Default FTP Client Configuration} 6530\begin{verbatim} 6531 preprocessor ftp_telnet_protocol: \ 6532 ftp client default bounce no max_resp_len 200 6533\end{verbatim} 6534 6535\paragraph{Configuration by IP Address} 6536 6537This format is very similar to ``default'', the only difference being that 6538specific IPs can be configured. 6539 6540\subsubsection{Example IP specific FTP Client Configuration} 6541 6542\begin{verbatim} 6543 preprocessor ftp_telnet_protocol: \ 6544 ftp client 10.1.1.1 bounce yes max_resp_len 500 6545\end{verbatim} 6546 6547\subsubsection{FTP Client Configuration Options} 6548 6549\begin{slist} 6550\item \texttt{max\_resp\_len $<$number$>$} 6551 6552This specifies the maximum allowed response length to an FTP command accepted 6553by the client. It can be used as a basic buffer overflow detection. 6554 6555\item \texttt{bounce $<$yes|no$>$} 6556 6557This option turns on detection and alerting of FTP bounce attacks. An FTP 6558bounce attack occurs when the FTP PORT command is issued and the specified host 6559does not match the host of the client. 6560 6561\item \texttt{bounce\_to $<$ CIDR,[port$|$portlow,porthi] $>$} 6562 6563When the bounce option is turned on, this allows the PORT command to use the IP 6564address (in CIDR format) and port (or inclusive port range) without generating 6565an alert. It can be used to deal with proxied FTP connections where the FTP 6566data channel is different from the client. 6567 6568A few examples: 6569 6570\begin{itemize} 6571\item Allow bounces to 192.162.1.1 port 20020 -- i.e., the use of 6572\texttt{PORT 192,168,1,1,78,52}. 6573 6574\begin{verbatim} 6575 bounce_to { 192.168.1.1,20020 } 6576\end{verbatim} 6577 6578\item Allow bounces to 192.162.1.1 ports 20020 through 20040 -- i.e., the use of 6579\texttt{PORT 192,168,1,1,78,xx}, where xx is 52 through 72 inclusive. 6580 6581\begin{verbatim} 6582 bounce_to { 192.168.1.1,20020,20040 } 6583\end{verbatim} 6584 6585\item Allow bounces to 192.162.1.1 port 20020 and 192.168.1.2 port 20030. 6586 6587\begin{verbatim} 6588 bounce_to { 192.168.1.1,20020 192.168.1.2,20030 } 6589\end{verbatim} 6590 6591\item Allows bounces to IPv6 address fe8::5 port 59340. 6592 6593\begin{verbatim} 6594 bounce_to { fe8::5,59340 } 6595\end{verbatim} 6596 6597 6598\end{itemize} 6599 6600\item \texttt{telnet\_cmds $<$yes|no$>$} 6601 6602This option turns on detection and alerting when telnet escape sequences are 6603seen on the FTP command channel. Injection of telnet escape sequences could be 6604used as an evasion attempt on an FTP command channel. 6605 6606\item \texttt{ignore\_telnet\_erase\_cmds $<$yes|no$>$} 6607 6608This option allows Snort to ignore telnet escape sequences for erase character 6609(TNC EAC) and erase line (TNC EAL) when normalizing FTP command channel. Some FTP 6610clients do not process those telnet escape sequences. 6611 6612\end{slist} 6613 6614\subsubsection{Examples/Default Configuration from snort.conf} 6615\begin{verbatim} 6616 preprocessor ftp_telnet: \ 6617 global \ 6618 encrypted_traffic yes \ 6619 inspection_type stateful 6620 6621 preprocessor ftp_telnet_protocol:\ 6622 telnet \ 6623 normalize \ 6624 ayt_attack_thresh 200 6625 6626 # This is consistent with the FTP rules as of 18 Sept 2004. 6627 # Set CWD to allow parameter length of 200 6628 # MODE has an additional mode of Z (compressed) 6629 # Check for string formats in USER & PASS commands 6630 # Check MDTM commands that set modification time on the file. 6631 6632 preprocessor ftp_telnet_protocol: \ 6633 ftp server default \ 6634 def_max_param_len 100 \ 6635 alt_max_param_len 200 { CWD } \ 6636 cmd_validity MODE < char ASBCZ > \ 6637 cmd_validity MDTM < [ date nnnnnnnnnnnnnn[.n[n[n]]] ] string > \ 6638 chk_str_fmt { USER PASS RNFR RNTO SITE MKD } \ 6639 telnet_cmds yes \ 6640 ignore_data_chan yes 6641 6642 preprocessor ftp_telnet_protocol: \ 6643 ftp client default \ 6644 max_resp_len 256 \ 6645 bounce yes \ 6646 telnet_cmds yes 6647\end{verbatim} 6648 6649\subsection{SSH} 6650\label{sub:ssh} 6651 6652The SSH preprocessor detects the following exploits: Challenge-Response Buffer 6653Overflow, CRC 32, Secure CRT, and the Protocol Mismatch exploit. 6654 6655Both Challenge-Response Overflow and CRC 32 attacks occur after the key 6656exchange, and are therefore encrypted. Both attacks involve sending a large 6657payload (20kb+) to the server immediately after the authentication challenge. 6658To detect the attacks, the SSH preprocessor counts the number of bytes 6659transmitted to the server. If those bytes exceed a predefined limit within a 6660predefined number of packets, an alert is generated. Since the 6661Challenge-Response Overflow only effects SSHv2 and CRC 32 only effects SSHv1, 6662the SSH version string exchange is used to distinguish the attacks. 6663 6664The Secure CRT and protocol mismatch exploits are observable before the key 6665exchange. 6666 6667\subsubsection{Configuration} 6668 6669By default, all alerts are disabled and the preprocessor checks traffic on port 667022. 6671 6672The available configuration options are described below. 6673 6674\begin{slist} 6675 6676\item \texttt{server\_ports $\{ <$port$> [<$port$> <...>] \}$} 6677 6678This option specifies which ports the SSH preprocessor should inspect traffic 6679to. 6680 6681\item \texttt{max\_encrypted\_packets $<$ number $>$} 6682 6683The number of stream reassembled encrypted packets that Snort will inspect before ignoring a given 6684SSH session. The SSH vulnerabilities that Snort can detect all happen at the 6685very beginning of an SSH session. Once max\_encrypted\_packets packets have been 6686seen, Snort ignores the session to increase performance. The default is set to 25. 6687This value can be set from 0 to 65535. 6688 6689\item \texttt{max\_client\_bytes $<$ number $>$} 6690 6691The number of unanswered bytes allowed to be transferred before alerting on 6692Challenge-Response Overflow or CRC 32. This number must be hit before 6693max\_encrypted\_packets packets are sent, or else Snort will ignore the traffic. 6694The default is set to 19600. This value can be set from 0 to 65535. 6695 6696\item \texttt{max\_server\_version\_len $<$ number $>$} 6697 6698The maximum number of bytes allowed in the SSH server version string before 6699alerting on the Secure CRT server version string overflow. The default is set to 670080. This value can be set from 0 to 255. 6701 6702\item \texttt{autodetect} 6703 6704Attempt to automatically detect SSH. 6705 6706\item \texttt{enable\_respoverflow} 6707 6708Enables checking for the Challenge-Response Overflow exploit. 6709 6710\item \texttt{enable\_ssh1crc32} 6711 6712Enables checking for the CRC 32 exploit. 6713 6714\item \texttt{enable\_srvoverflow} 6715 6716Enables checking for the Secure CRT exploit. 6717 6718\item \texttt{enable\_protomismatch} 6719 6720Enables checking for the Protocol Mismatch exploit. 6721 6722\item \texttt{enable\_badmsgdir} 6723 6724Enable alerts for traffic flowing the wrong direction. For instance, if the 6725presumed server generates client traffic, or if a client generates server 6726traffic. 6727 6728\item \texttt{enable\_paysize} 6729 6730Enables alerts for invalid payload sizes. 6731 6732\item \texttt{enable\_recognition} 6733 6734Enable alerts for non-SSH traffic on SSH ports. 6735 6736\end{slist} 6737 6738The SSH preprocessor should work by default. After max\_encrypted\_packets is 6739reached, the preprocessor will stop processing traffic for a given session. If 6740Challenge-Response Overflow or CRC 32 false positive, try increasing the number 6741of required client bytes with max\_client\_bytes. 6742 6743\subsubsection{Example Configuration from snort.conf} 6744 6745Looks for attacks on SSH server port 22. Alerts at 19600 unacknowledged bytes 6746within 20 encrypted packets for the Challenge-Response Overflow/CRC32 exploits. 6747 6748\begin{verbatim} 6749 preprocessor ssh: \ 6750 server_ports { 22 } \ 6751 max_client_bytes 19600 \ 6752 max_encrypted_packets 20 \ 6753 enable_respoverflow \ 6754 enable_ssh1crc32 6755\end{verbatim} 6756 6757\subsection{DNS} 6758\label{sub:dns} 6759 6760The DNS preprocessor decodes DNS Responses and can detect the following 6761exploits: DNS Client RData Overflow, Obsolete Record Types, and Experimental 6762Record Types. 6763 6764DNS looks at DNS Response traffic over UDP and TCP and it requires Stream 6765preprocessor to be enabled for TCP decoding. 6766 6767\subsubsection{Configuration} 6768 6769By default, all alerts are disabled and the preprocessor checks traffic on port 677053. 6771 6772The available configuration options are described below. 6773 6774\begin{slist} 6775 6776\item \texttt{ports $\{ <$port$> [<$port$> <...>] \}$} 6777 6778This option specifies the source ports that the DNS preprocessor should inspect 6779traffic. 6780 6781\item \texttt{enable\_obsolete\_types} 6782 6783Alert on Obsolete (per RFC 1035) Record Types 6784 6785\item \texttt{enable\_experimental\_types} 6786 6787Alert on Experimental (per RFC 1035) Record Types 6788 6789\item \texttt{enable\_rdata\_overflow} 6790 6791Check for DNS Client RData TXT Overflow 6792 6793\end{slist} 6794 6795The DNS preprocessor does nothing if none of the 3 vulnerabilities it checks 6796for are enabled. It will not operate on TCP sessions picked up midstream, and 6797it will cease operation on a session if it loses state because of missing data 6798(dropped packets). 6799 6800\subsubsection{Examples/Default Configuration from snort.conf} 6801 6802Looks for traffic on DNS server port 53. Check for the DNS Client RData 6803overflow vulnerability. Do not alert on obsolete or experimental RData record 6804types. 6805 6806\begin{verbatim} 6807 preprocessor dns: \ 6808 ports { 53 } \ 6809 enable_rdata_overflow 6810\end{verbatim} 6811 6812\subsection{SSL/TLS} 6813\label{sub:SSL/TLS} 6814 6815Encrypted traffic should be ignored by Snort for both performance reasons and 6816to reduce false positives. The SSL Dynamic Preprocessor (SSLPP) decodes SSL 6817and TLS traffic and optionally determines if and when Snort should stop 6818inspection of it. 6819 6820Typically, SSL is used over port 443 as HTTPS. By enabling the SSLPP to 6821inspect port 443 and enabling the noinspect\_encrypted option, only the SSL 6822handshake of each connection will be inspected. Once the traffic is determined 6823to be encrypted, no further inspection of the data on the connection is made. 6824 6825By default, SSLPP looks for a handshake followed by encrypted traffic traveling 6826to both sides. If one side responds with an indication that something has 6827failed, such as the handshake, the session is not marked as encrypted. 6828Verifying that faultless encrypted traffic is sent from both endpoints ensures 6829two things: the last client-side handshake packet was not crafted to evade 6830Snort, and that the traffic is legitimately encrypted. 6831 6832In some cases, especially when packets may be missed, the only observed 6833response from one endpoint will be TCP ACKs. Therefore, if a user knows that 6834server-side encrypted data can be trusted to mark the session as encrypted, the 6835user should use the 'trustservers' option, documented below. 6836 6837\subsubsection{Configuration} 6838 6839\begin{slist} 6840 6841\item \texttt{ports $\{ <$port$> [<$port$> <...>] \}$} 6842 6843This option specifies which ports SSLPP will inspect traffic on. 6844 6845By default, SSLPP watches the following ports: 6846 6847\begin{itemize} 6848 \item \texttt{443} HTTPS 6849 \item \texttt{465} SMTPS 6850 \item \texttt{563} NNTPS 6851 \item \texttt{636} LDAPS 6852 \item \texttt{989} FTPS 6853 \item \texttt{992} TelnetS 6854 \item \texttt{993} IMAPS 6855 \item \texttt{994} IRCS 6856 \item \texttt{995} POPS 6857\end{itemize} 6858 6859\item \texttt{noinspect\_encrypted} 6860 6861Disable inspection on traffic that is encrypted. Default is off. 6862 6863\item \texttt{max\_heartbeat\_length} 6864 6865Maximum length of heartbeat record allowed. This config option is 6866used to detect the heartbleed attacks. The allowed range is 0 to 65535. 6867Setting the value to 0 turns off the heartbeat length checks. For heartbeat 6868requests, if the payload size of the request record is greater than the 6869max\_heartbeat\_length an alert with sid 3 and gid 137 is generated. 6870For heartbeat responses, if the record size itself is greater than 6871the max\_heartbeat\_length an alert with sid 4 and gid 137 is generated. Default 6872is off. 6873 6874\item \texttt{trustservers} 6875 6876Disables the requirement that application (encrypted) data must be observed on 6877both sides of the session before a session is marked encrypted. Use this 6878option for slightly better performance if you trust that your servers are not 6879compromised. This requires the \texttt{noinspect\_encrypted} option to be 6880useful. Default is off. \end{slist} 6881 6882\subsubsection{Examples/Default Configuration from snort.conf} 6883 6884Enables the SSL preprocessor and tells it to disable inspection on encrypted 6885traffic. 6886 6887\begin{verbatim} 6888 preprocessor ssl: noinspect_encrypted 6889\end{verbatim} 6890 6891\subsubsection{Rule Options} 6892 6893The following rule options are supported by enabling the \texttt{ssl} preprocessor: 6894 6895\begin{itemize} 6896\item[] 6897\begin{verbatim} 6898 ssl_version 6899 ssl_state 6900\end{verbatim} 6901\end{itemize} 6902 6903\texttt{ssl\_version} 6904\label{ssl:ssl_version} 6905\begin{itemize} 6906 6907\item[] The \texttt{ssl\_version} rule option tracks the version negotiated between 6908the endpoints of the SSL encryption. The list of version identifiers are below, and 6909more than one identifier can be specified, via a comma separated list. Lists of 6910identifiers are OR'ed together. 6911 6912The option will match if any one of the OR'ed versions are used in the SSL 6913connection. To check for two or more SSL versions in use simultaneously, multiple 6914\texttt{ssl\_version} rule options should be used. 6915 6916\textit{Syntax} 6917\footnotesize 6918\begin{verbatim} 6919 ssl_version: <version-list> 6920 6921 version-list = version | version , version-list 6922 version = ["!"] "sslv2" | "sslv3" | "tls1.0" | "tls1.1" | "tls1.2" 6923\end{verbatim} 6924 6925\textit{Examples} 6926\begin{verbatim} 6927 ssl_version:sslv3; 6928 ssl_version:tls1.0,tls1.1,tls1.2; 6929 ssl_version:!sslv2; 6930\end{verbatim} 6931 6932\end{itemize} 6933 6934\texttt{ssl\_state} 6935\label{ssl:ssl_state} 6936\begin{itemize} 6937 6938\item[] The \texttt{ssl\_state} rule option tracks the state of the SSL encryption 6939during the process of hello and key exchange. The list of states are below. More than 6940one state can be specified, via a comma separated list, and are OR'ed together. 6941 6942The option will match if the connection is currently in any one of the OR'ed states. 6943To ensure the connection has reached each of a set of states, multiple rules using 6944the \texttt{ssl\_state} rule option should be used. 6945 6946\textit{Syntax} 6947\footnotesize 6948\begin{verbatim} 6949 ssl_state: <state-list> 6950 6951 state-list = state | state , state-list 6952 state = ["!"] "client_hello" | "server_hello" | "client_keyx" | "server_keyx" | "unknown" 6953\end{verbatim} 6954 6955 6956\textit{Examples} 6957\begin{verbatim} 6958 ssl_state:client_hello; 6959 ssl_state:client_keyx,server_keyx; 6960 ssl_state:!server_hello; 6961\end{verbatim} 6962 6963\end{itemize} 6964 6965\subsection{ARP Spoof Preprocessor} 6966\label{sub:arpspoof} 6967 6968The ARP spoof preprocessor decodes ARP packets and detects ARP attacks, unicast 6969ARP requests, and inconsistent Ethernet to IP mapping. 6970 6971When no arguments are specified to arpspoof, the preprocessor inspects Ethernet 6972addresses and the addresses in the ARP packets. When inconsistency occurs, an 6973alert with GID 112 and SID 2 or 3 is generated. 6974 6975When "\texttt{-unicast}" is specified as the argument of arpspoof, the 6976preprocessor checks for unicast ARP requests. An alert with GID 112 and SID 1 6977will be generated if a unicast ARP request is detected. 6978 6979Specify a pair of IP and hardware address as the argument to 6980\texttt{arpspoof\_detect\_host}. The host with the IP address should be on the 6981same layer 2 segment as Snort is. Specify one host IP MAC combo per line. The 6982preprocessor will use this list when detecting ARP cache overwrite attacks. 6983Alert SID 4 is used in this case. 6984 6985\subsubsection{Format} 6986 6987\begin{verbatim} 6988 preprocessor arpspoof[: -unicast] 6989 preprocessor arpspoof_detect_host: ip mac 6990\end{verbatim} 6991 6992\begin{table}[h] 6993\begin{center} 6994\begin{tabular}{| l | l |} 6995 6996\hline 6997\textbf{Option} & \textbf{Description}\\ 6998\hline 6999 7000\hline 7001\texttt{ip} & IP address.\\ 7002 7003\hline 7004\texttt{mac} & The Ethernet address corresponding to the preceding IP. \\ 7005\hline 7006 7007\end{tabular} 7008\end{center} 7009\end{table} 7010 7011\subsubsection{Example Configuration} 7012 7013The first example configuration does neither unicast detection nor ARP mapping 7014monitoring. The preprocessor merely looks for Ethernet address inconsistencies. 7015 7016\begin{verbatim} 7017 preprocessor arpspoof 7018\end{verbatim} 7019 7020The next example configuration does not do unicast detection but monitors ARP 7021mapping for hosts 192.168.40.1 and 192.168.40.2. 7022 7023\begin{verbatim} 7024 preprocessor arpspoof 7025 preprocessor arpspoof_detect_host: 192.168.40.1 f0:0f:00:f0:0f:00 7026 preprocessor arpspoof_detect_host: 192.168.40.2 f0:0f:00:f0:0f:01 7027\end{verbatim} 7028 7029The third example configuration has unicast detection enabled. 7030 7031\begin{verbatim} 7032 preprocessor arpspoof: -unicast 7033 preprocessor arpspoof_detect_host: 192.168.40.1 f0:0f:00:f0:0f:00 7034 preprocessor arpspoof_detect_host: 192.168.40.2 f0:0f:00:f0:0f:01 7035\end{verbatim} 7036 7037\subsection{DCE/RPC 2 Preprocessor} 7038\label{sub:dcerpc2} 7039 7040The main purpose of the preprocessor is to perform SMB desegmentation and 7041DCE/RPC defragmentation to avoid rule evasion using these techniques. SMB 7042desegmentation is performed for the following commands that can be used to 7043transport DCE/RPC requests and responses: \texttt{Write}, \texttt{Write Block 7044Raw}, \texttt{Write and Close}, \texttt{Write AndX}, \texttt{Transaction}, 7045\texttt{Transaction Secondary}, \texttt{Read}, \texttt{Read Block Raw} and 7046\texttt{Read AndX}. The following transports are supported for DCE/RPC: SMB, 7047TCP, UDP and RPC over HTTP v.1 proxy and server. New rule options have been 7048implemented to improve performance, reduce false positives and reduce the count 7049and complexity of DCE/RPC based rules. 7050 7051\subsubsection{Dependency Requirements} 7052 7053For proper functioning of the preprocessor: 7054 7055\begin{itemize} 7056 7057\item Stream session tracking must be enabled, i.e. \texttt{stream5}. The 7058preprocessor requires a session tracker to keep its data. 7059 7060\item Stream reassembly must be performed for TCP sessions. If it is decided 7061that a session is SMB or DCE/RPC, either through configured ports, servers or 7062autodetecting, the \texttt{dcerpc2} preprocessor will enable stream reassembly 7063for that session if necessary. 7064 7065\item IP defragmentation should be enabled, i.e. the \texttt{frag3} 7066preprocessor should be enabled and configured. 7067 7068\end{itemize} 7069 7070\subsubsection{Target Based} 7071 7072There are enough important differences between Windows and Samba versions that 7073a target based approach has been implemented. Some important differences:\\ 7074 7075\textit{Named pipe instance tracking} 7076 7077\begin{itemize} 7078 7079\item[] A combination of valid login handle or UID, share handle or TID and 7080file/named pipe handle or FID must be used to write data to a named pipe. The 7081binding between these is dependent on OS/software version. 7082 7083\begin{itemize} 7084 7085\item[] Samba 3.0.22 and earlier 7086 7087\begin{itemize} 7088 7089\item[] Any valid UID and TID, along with a valid FID can be used to make a 7090request, however, if the TID used in creating the FID is deleted (via a tree 7091disconnect), the FID that was created using this TID becomes invalid, i.e. no 7092more requests can be written to that named pipe instance. 7093 7094\end{itemize} 7095 7096\item[] Samba greater than 3.0.22 7097 7098\begin{itemize} 7099 7100\item[] Any valid TID, along with a valid FID can be used to make a request. 7101However, only the UID used in opening the named pipe can be used to make a 7102request using the FID handle to the named pipe instance. If the TID used to 7103create the FID is deleted (via a tree disconnect), the FID that was created 7104using this TID becomes invalid, i.e. no more requests can be written to that 7105named pipe instance. If the UID used to create the named pipe instance is 7106deleted (via a \texttt{Logoff AndX}), since it is necessary in making a request 7107to the named pipe, the FID becomes invalid. 7108 7109\end{itemize} 7110 7111\item[] Windows 2003 7112\item[] Windows XP 7113\item[] Windows Vista 7114 7115\begin{itemize} 7116 7117\item[] These Windows versions require strict binding between the UID, TID and 7118FID used to make a request to a named pipe instance. Both the UID and TID used 7119to open the named pipe instance must be used when writing data to the same 7120named pipe instance. Therefore, deleting either the UID or TID invalidates the 7121FID. 7122 7123\end{itemize} 7124 7125\item[] Windows 2000 7126 7127\begin{itemize} 7128 7129\item[] Windows 2000 is interesting in that the first request to a named pipe 7130must use the same binding as that of the other Windows versions. However, 7131requests after that follow the same binding as Samba 3.0.22 and earlier, i.e. 7132no binding. It also follows Samba greater than 3.0.22 in that deleting the UID 7133or TID used to create the named pipe instance also invalidates it. 7134 7135\end{itemize} 7136\end{itemize} 7137\end{itemize} 7138 7139\textit{Accepted SMB commands} 7140\begin{itemize} 7141 7142\item[] Samba in particular does not recognize certain commands under an 7143\texttt{IPC\$} tree. 7144\begin{itemize} 7145\item[] Samba (all versions) 7146\begin{itemize} 7147\item[] Under an \texttt{IPC\$} tree, does not accept: 7148\begin{itemize} 7149\item[] \texttt{Open} 7150\item[] \texttt{Write And Close} 7151\item[] \texttt{Read} 7152\item[] \texttt{Read Block Raw} 7153\item[] \texttt{Write Block Raw} 7154\end{itemize} 7155\end{itemize} 7156 7157\item[] Windows (all versions) 7158\begin{itemize} 7159 7160\item[] Accepts all of the above commands under an \texttt{IPC\$} tree. 7161\end{itemize} 7162\end{itemize} 7163\end{itemize} 7164 7165\textit{AndX command chaining} 7166\begin{itemize} 7167 7168\item[] Windows is very strict in what command combinations it allows to be 7169chained. Samba, on the other hand, is very lax and allows some nonsensical 7170combinations, e.g. multiple logins and tree connects (only one place to return 7171handles for these), login/logoff and tree connect/tree disconnect. Ultimately, 7172we don't want to keep track of data that the server won't accept. An evasion 7173possibility would be accepting a fragment in a request that the server won't 7174accept that gets sandwiched between an exploit. 7175 7176\end{itemize} 7177 7178\textit{Transaction tracking} 7179\begin{itemize} 7180 7181\item[] The differences between a \texttt{Transaction} request and using one of 7182the \texttt{Write*} commands to write data to a named pipe are that (1) a 7183\texttt{Transaction} performs the operations of a write and a read from the 7184named pipe, whereas in using the \texttt{Write*} commands, the client has to 7185explicitly send one of the \texttt{Read*} requests to tell the server to send 7186the response and (2) a \texttt{Transaction} request is not written to the named 7187pipe until all of the data is received (via potential \texttt{Transaction 7188Secondary} requests) whereas with the \texttt{Write*} commands, data is written 7189to the named pipe as it is received by the server. Multiple Transaction 7190requests can be made simultaneously to the same named pipe. These requests can 7191also be segmented with \texttt{Transaction Secondary} commands. What 7192distinguishes them (when the same named pipe is being written to, i.e. having 7193the same FID) are fields in the SMB header representing a process id (PID) and 7194multiplex id (MID). The PID represents the process this request is a part of. 7195An MID represents different sub-processes within a process (or under a PID). 7196Segments for each "thread" are stored separately and written to the named pipe 7197when all segments are received. It is necessary to track this so as not to 7198munge these requests together (which would be a potential evasion opportunity). 7199 7200\begin{itemize} 7201\item[] Windows (all versions) 7202\begin{itemize} 7203\item[] Uses a combination of PID and MID to define a "thread". 7204\end{itemize} 7205\item[] Samba (all versions) 7206\begin{itemize} 7207\item[] Uses just the MID to define a "thread". 7208\end{itemize} 7209\end{itemize} 7210\end{itemize} 7211 7212\textit{Multiple Bind Requests} 7213\begin{itemize} 7214 7215\item[] A \texttt{Bind} request is the first request that must be made in a 7216connection-oriented DCE/RPC session in order to specify the 7217interface/interfaces that one wants to communicate with. 7218 7219\begin{itemize} 7220\item[] Windows (all versions) 7221\begin{itemize} 7222 7223\item[] For all of the Windows versions, only one \texttt{Bind} can ever be 7224made on a session whether or not it succeeds or fails. Any binding after that 7225must use the \texttt{Alter Context} request. If another \texttt{Bind} is made, 7226all previous interface bindings are invalidated. 7227 7228\end{itemize} 7229\item[] Samba 3.0.20 and earlier 7230\begin{itemize} 7231\item[] Any amount of \texttt{Bind} requests can be made. 7232\end{itemize} 7233\item[] Samba later than 3.0.20 7234\begin{itemize} 7235 7236\item[] Another \texttt{Bind} request can be made if the first failed and no 7237interfaces were successfully bound to. If a \texttt{Bind} after a successful 7238\texttt{Bind} is made, all previous interface bindings are invalidated. 7239 7240\end{itemize} 7241\end{itemize} 7242\end{itemize} 7243 7244\textit{DCE/RPC Fragmented requests - Context ID} 7245\begin{itemize} 7246 7247\item[] Each fragment in a fragmented request carries the context id of the 7248bound interface it wants to make the request to. 7249 7250\begin{itemize} 7251\item[] Windows (all versions) 7252\begin{itemize} 7253 7254\item[] The context id that is ultimately used for the request is contained in 7255the first fragment. The context id field in any other fragment can contain any 7256value. 7257 7258\end{itemize} 7259\item[] Samba (all versions) 7260\begin{itemize} 7261 7262\item[] The context id that is ultimately used for the request is contained in 7263the last fragment. The context id field in any other fragment can contain any 7264value. 7265 7266\end{itemize} 7267\end{itemize} 7268\end{itemize} 7269 7270\textit{DCE/RPC Fragmented requests - Operation number} 7271\begin{itemize} 7272 7273\item[] Each fragment in a fragmented request carries an operation number 7274(opnum) which is more or less a handle to a function offered by the interface. 7275 7276\begin{itemize} 7277\item[] Samba (all versions) 7278\item[] Windows 2000 7279\item[] Windows 2003 7280\item[] Windows XP 7281\begin{itemize} 7282 7283\item[] The opnum that is ultimately used for the request is contained in the 7284last fragment. The opnum field in any other fragment can contain any value. 7285\end{itemize} 7286 7287\item[] Windows Vista 7288\begin{itemize} 7289 7290\item[] The opnum that is ultimately used for the request is contained in the 7291first fragment. The opnum field in any other fragment can contain any value. 7292 7293\end{itemize} 7294\end{itemize} 7295\end{itemize} 7296 7297\textit{DCE/RPC Stub data byte order} 7298\begin{itemize} 7299 7300\item[] The byte order of the stub data is determined differently for Windows 7301and Samba. 7302 7303\begin{itemize} 7304\item[] Windows (all versions) 7305\begin{itemize} 7306 7307\item[] The byte order of the stub data is that which was used in the 7308\texttt{Bind} request. 7309 7310\end{itemize} 7311 7312\item[] Samba (all versions) 7313 7314\begin{itemize} 7315 7316\item[] The byte order of the stub data is that which is used in the request 7317carrying the stub data. 7318 7319\end{itemize} 7320\end{itemize} 7321\end{itemize} 7322 7323\subsubsection{Configuration} 7324 7325The \texttt{dcerpc2} preprocessor has a global configuration and one or more 7326server configurations. The global preprocessor configuration name is 7327\texttt{dcerpc2} and the server preprocessor configuration name is 7328\texttt{dcerpc2\_server}.\\ 7329 7330\underline{Global Configuration} 7331 7332\begin{verbatim} 7333 preprocessor dcerpc2 7334\end{verbatim} 7335 7336The global \texttt{dcerpc2} configuration is required. Only one global 7337\texttt{dcerpc2} configuration can be specified.\\ 7338 7339\textit{Option syntax} 7340\begin{itemize} 7341 7342\item[] 7343\begin{tabular}{|l|c|c|p{6cm}|} 7344\hline 7345Option & Argument & Required & Default\\ 7346\hline 7347\hline 7348\texttt{memcap} & \texttt{<memcap>} & NO & \texttt{memcap 102400}\\ 7349\hline 7350\texttt{disable\_defrag} & NONE & NO & OFF\\ 7351\hline 7352\texttt{max\_frag\_len} & \texttt{<max-frag-len>} & NO & OFF\\ 7353\hline 7354\texttt{events} & \texttt{<events>} & NO & OFF\\ 7355\hline 7356\texttt{reassemble\_threshold} & \texttt{<re-thresh>} & NO & OFF\\ 7357\hline 7358\texttt{disabled} & NONE & NO & OFF\\ 7359\hline 7360\texttt{smb\_fingerprint\_policy} & \texttt{<fp-policy>} & NO & OFF\\ 7361\hline 7362\texttt{smb\_legacy\_mode} & NONE & NO & OFF\\ 7363\hline 7364\end{tabular} 7365\end{itemize} 7366 7367\footnotesize 7368\begin{verbatim} 7369 memcap = 1024-4194303 (kilobytes) 7370 max-frag-len = 1514-65535 7371 events = pseudo-event | event | '[' event-list ']' 7372 pseudo-event = "none" | "all" 7373 event-list = event | event ',' event-list 7374 event = "memcap" | "smb" | "co" | "cl" 7375 re-thresh = 0-65535 7376 fp-policy = "server" | "client" | "both" 7377\end{verbatim} 7378\normalsize 7379 7380\textit{Option explanations} 7381\begin{itemize} 7382\item[] \texttt{memcap} 7383\begin{itemize} 7384 7385\item[] Specifies the maximum amount of run-time memory that can be allocated. 7386Run-time memory includes any memory allocated after configuration. Default is 7387100 MB. 7388 7389\end{itemize} 7390 7391\item[] \texttt{disabled} 7392\begin{itemize} 7393 7394\item[] Disables the preprocessor. By default this value is turned off. When the 7395preprocessor is disabled only the memcap option is applied when specified 7396with the configuration. 7397 7398\end{itemize} 7399 7400\item[] \texttt{disable\_defrag} 7401 7402\begin{itemize} 7403 7404\item[] Tells the preprocessor not to do DCE/RPC defragmentation. Default is 7405to do defragmentation. 7406 7407\end{itemize} 7408 7409\item[] \texttt{max\_frag\_len} 7410 7411\begin{itemize} 7412 7413\item[] Specifies the maximum fragment size that will be added to the 7414defragmentation module. If a fragment is greater than this size, it is truncated 7415before being added to the defragmentation module. The allowed range for this 7416option is 1514 - 65535. 7417 7418\end{itemize} 7419 7420\item[] \texttt{events} 7421 7422\begin{itemize} 7423 7424\item[] Specifies the classes of events to enable. (See Events section for an 7425enumeration and explanation of events.) 7426 7427\begin{itemize} 7428\item[] \texttt{memcap} 7429 7430\begin{itemize} 7431\item[] Only one event. If the memcap is reached or exceeded, alert. 7432 7433\end{itemize} 7434 7435\item[] \texttt{smb} 7436 7437\begin{itemize} 7438\item[] Alert on events related to SMB processing. 7439\end{itemize} 7440 7441\item[] \texttt{co} 7442 7443\begin{itemize} 7444 7445\item[] Stands for connection-oriented DCE/RPC. Alert on events related to 7446connection-oriented DCE/RPC processing. 7447 7448\end{itemize} 7449 7450\item[] \texttt{cl} 7451\begin{itemize} 7452 7453\item[] Stands for connectionless DCE/RPC. Alert on events related to 7454connectionless DCE/RPC processing. 7455 7456\end{itemize} 7457\end{itemize} 7458\end{itemize} 7459 7460\item[] \texttt{reassemble\_threshold} 7461\begin{itemize} 7462 7463\item[] Specifies a minimum number of bytes in the DCE/RPC desegmentation and 7464defragmentation buffers before creating a reassembly packet to send to the 7465detection engine. This option is useful in inline mode so as to potentially 7466catch an exploit early before full defragmentation is done. A value of 0 7467supplied as an argument to this option will, in effect, disable this option. 7468Default is disabled. 7469 7470\end{itemize} 7471 7472\item[] \texttt{smb\_fingerprint\_policy} 7473\begin{itemize} 7474 7475\item[] By default, SMBv1, SMBv2, and SMBv3 files are inspected. 7476 If legacy mode is configured, only SMBv1 file inspection is enabled. 7477 7478 7479\end{itemize} 7480 7481\item[] \texttt{legacy\_mode} 7482\begin{itemize} 7483 7484\item[] In the initial phase of an SMB session, the client needs to authenticate 7485with a SessionSetupAndX. Both the request and response to this command 7486contain OS and version information that can allow the preprocessor to 7487dynamically set the policy for a session which allows for better 7488protection against Windows and Samba specific evasions. 7489 7490\end{itemize} 7491\end{itemize} 7492 7493\textit{Option examples} 7494\footnotesize 7495\begin{verbatim} 7496 memcap 30000 7497 max_frag_len 16840 7498 events none 7499 events all 7500 events smb 7501 events co 7502 events [co] 7503 events [smb, co] 7504 events [memcap, smb, co, cl] 7505 reassemble_threshold 500 7506 smb_fingerprint_policy both 7507 smb_fingerprint_policy client 7508 smb_legacy_mode 7509\end{verbatim} 7510\normalsize 7511 7512\textit{Configuration examples} 7513\footnotesize 7514\begin{verbatim} 7515 preprocessor dcerpc2 7516 preprocessor dcerpc2: memcap 500000 7517 preprocessor dcerpc2: max_frag_len 16840, memcap 300000, events smb 7518 preprocessor dcerpc2: memcap 50000, events [memcap, smb, co, cl], max_frag_len 14440 7519 preprocessor dcerpc2: disable_defrag, events [memcap, smb] 7520 preprocessor dcerpc2: reassemble_threshold 500 7521 preprocessor dcerpc2: memcap 50000, events [memcap, smb, co, cl], max_frag_len 14440, smb_fingerprint_policy both 7522\end{verbatim} 7523\normalsize 7524 7525\textit{Default global configuration} 7526\footnotesize 7527\begin{verbatim} 7528 preprocessor dcerpc2: memcap 102400 7529\end{verbatim} 7530\normalsize 7531 7532\underline{Server Configuration} 7533 7534\begin{verbatim} 7535 preprocessor dcerpc2_server 7536\end{verbatim} 7537 7538The \texttt{dcerpc2\_server} configuration is optional. A 7539\texttt{dcerpc2\_server} configuration must start with \texttt{default} or 7540\texttt{net} options. The \texttt{default} and \texttt{net} options are 7541mutually exclusive. At most one default configuration can be specified. If no 7542\texttt{default} configuration is specified, default values will be used for 7543the \texttt{default} configuration. Zero or more \texttt{net} configurations 7544can be specified. For any \texttt{dcerpc2\_server} configuration, if 7545non-required options are not specified, the defaults will be used. When 7546processing DCE/RPC traffic, the \texttt{default} configuration is used if no 7547net configurations match. If a \texttt{net} configuration matches, it will 7548override the \texttt{default} configuration. A \texttt{net} configuration 7549matches if the packet's server IP address matches an IP address or net 7550specified in the \texttt{net} configuration. The \texttt{net} option supports 7551IPv6 addresses. Note that port and ip variables defined in \texttt{snort.conf} 7552\textsc{cannot} be used. 7553 7554\textit{Option syntax} 7555\begin{itemize} 7556\item[] 7557\begin{tabular}{|l|c|c|p{6cm}|} 7558 7559\hline 7560Option & Argument & Required & Default\\ 7561\hline 7562 7563\hline 7564\texttt{default} & NONE & YES & NONE\\ 7565 7566\hline 7567\texttt{net} & \texttt{<net>} & YES & NONE\\ 7568 7569\hline 7570\texttt{policy} & \texttt{<policy>} & NO & \texttt{policy WinXP}\\ 7571 7572\hline 7573\texttt{detect} & \texttt{<detect>} & NO & \texttt{detect [smb [139,445], tcp 7574135, udp 135, rpc-over-http-server 593]}\\ 7575 7576\hline 7577\texttt{autodetect} & \texttt{<detect>} & NO & \texttt{autodetect [tcp 75781025:, udp 1025:, rpc-over-http-server 1025:]}\\ 7579 7580\hline 7581\texttt{no\_autodetect\_http\_proxy\_ports} & NONE & NO & DISABLED (The 7582preprocessor autodetects on all proxy ports by default)\\ 7583 7584\hline 7585\texttt{smb\_invalid\_shares} & \texttt{<shares>} & NO & NONE\\ 7586 7587\hline 7588\texttt{smb\_max\_chain} & \texttt{<max-chain>} & NO & \texttt{smb\_max\_chain 3}\\ 7589 7590\hline 7591\texttt{smb\_file\_inspection} & \texttt{<file-inspect>} & NO & \texttt{smb\_file\_inspection off}\\ 7592 7593\hline 7594\end{tabular} 7595\end{itemize} 7596 7597\footnotesize 7598\begin{verbatim} 7599 net = ip | '[' ip-list ']' 7600 ip-list = ip | ip ',' ip-list 7601 ip = ip-addr | ip-addr '/' prefix | ip4-addr '/' netmask 7602 ip-addr = ip4-addr | ip6-addr 7603 ip4-addr = a valid IPv4 address 7604 ip6-addr = a valid IPv6 address (can be compressed) 7605 prefix = a valid CIDR 7606 netmask = a valid netmask 7607 policy = "Win2000" | "Win2003" | "WinXP" | "WinVista" | 7608 "Samba" | "Samba-3.0.22" | "Samba-3.0.20" 7609 detect = "none" | detect-opt | '[' detect-list ']' 7610 detect-list = detect-opt | detect-opt ',' detect-list 7611 detect-opt = transport | transport port-item | 7612 transport '[' port-list ']' 7613 transport = "smb" | "tcp" | "udp" | "rpc-over-http-proxy" | 7614 "rpc-over-http-server" 7615 port-list = port-item | port-item ',' port-list 7616 port-item = port | port-range 7617 port-range = ':' port | port ':' | port ':' port 7618 port = 0-65535 7619 shares = share | '[' share-list ']' 7620 share-list = share | share ',' share-list 7621 share = word | '"' word '"' | '"' var-word '"' 7622 word = graphical ASCII characters except ',' '"' ']' '[' '$' 7623 var-word = graphical ASCII characters except ',' '"' ']' '[' 7624 max-chain = 0-255 7625 file-inspect = file-arg | '[' file-list ']' 7626 file-arg = "off" | "on" | "only" 7627 file-list = file-arg [ ',' "file-depth" <int64_t> ] 7628\end{verbatim} 7629\normalsize 7630 7631\begin{itemize} 7632 7633\item[] Because the Snort main parser treats '\$' as the start of a variable 7634and tries to expand it, shares with '\$' must be enclosed quotes. 7635 7636\end{itemize} 7637 7638\textit{Option explanations} 7639 7640\begin{itemize} 7641\item[] \texttt{default} 7642 7643\begin{itemize} 7644 7645\item[] Specifies that this configuration is for the default server 7646configuration. 7647 7648\end{itemize} 7649 7650\item[] \texttt{net} 7651 7652\begin{itemize} 7653 7654\item[] Specifies that this configuration is an IP or net specific 7655configuration. The configuration will only apply to the IP addresses and nets 7656supplied as an argument. 7657 7658\end{itemize} 7659 7660\item[] \texttt{policy} 7661 7662\begin{itemize} 7663 7664\item[] Specifies the target-based policy to use when processing. Default is 7665"WinXP". 7666 7667\end{itemize} 7668 7669\item[] \texttt{detect} 7670 7671\begin{itemize} 7672 7673\item[] Specifies the DCE/RPC transport and server ports that should be 7674detected on for the transport. Defaults are ports 139 and 445 for SMB, 135 for 7675TCP and UDP, 593 for RPC over HTTP server and 80 for RPC over HTTP proxy. 7676 7677\end{itemize} 7678 7679\item[] \texttt{autodetect} 7680 7681\begin{itemize} 7682 7683\item[] Specifies the DCE/RPC transport and server ports that the preprocessor 7684should attempt to autodetect on for the transport. The autodetect ports are 7685only queried if no detect transport/ports match the packet. The order in which 7686the preprocessor will attempt to autodetect will be - TCP/UDP, RPC over HTTP 7687server, RPC over HTTP proxy and lastly SMB. Note that most dynamic DCE/RPC 7688ports are above 1024 and ride directly over TCP or UDP. It would be very 7689uncommon to see SMB on anything other than ports 139 and 445. Defaults are 76901025-65535 for TCP, UDP and RPC over HTTP server. 7691 7692\end{itemize} 7693 7694\item[] \texttt{no\_autodetect\_http\_proxy\_ports} 7695 7696\begin{itemize} 7697 7698\item[] By default, the preprocessor will always attempt to autodetect for 7699ports specified in the detect configuration for rpc-over-http-proxy. This is 7700because the proxy is likely a web server and the preprocessor should not look 7701at all web traffic. This option is useful if the RPC over HTTP proxy configured 7702with the detect option is only used to proxy DCE/RPC traffic. Default is to 7703autodetect on RPC over HTTP proxy detect ports. 7704 7705\end{itemize} 7706 7707\item[] \texttt{smb\_invalid\_shares} 7708 7709\begin{itemize} 7710 7711\item[] Specifies SMB shares that the preprocessor should alert on if an 7712attempt is made to connect to them via a \texttt{Tree Connect} or \texttt{Tree 7713Connect AndX}. Default is empty. 7714 7715\end{itemize} 7716 7717\item[] \texttt{smb\_max\_chain} 7718 7719\begin{itemize} 7720 7721\item[] Specifies the maximum amount of AndX command chaining that is allowed 7722before an alert is generated. Default maximum is 3 chained commands. A value 7723of 0 disables this option. This value can be set from 0 to 255. 7724 7725\end{itemize} 7726 7727\item[] \texttt{smb\_file\_inspection} 7728 7729\begin{itemize} 7730 7731\item[] Instructs the preprocessor to do inspection of normal SMB file 7732transfers. This includes doing file type and signature through 7733the file API as well as setting a pointer for the \texttt{file\_data} 7734rule option. Note that the \texttt{file-depth} option only applies to the 7735maximum amount of file data for which it will set the pointer for the 7736\texttt{file\_data} rule option. For file type and signature it will use the 7737value configured for the file API. If \texttt{only} is specified, the 7738preprocessor will only do SMB file inspection, i.e. it will not do any DCE/RPC 7739tracking or inspection. If \texttt{on} is specified with no 7740arguments, the default file depth is 16384 bytes. An argument of -1 to 7741\texttt{file-depth} disables setting the pointer for \texttt{file\_data}, effectively 7742disabling SMB file inspection in rules. An argument of 0 to 7743\texttt{file-depth} means unlimited. Default is \texttt{off}, i.e. no SMB file 7744inspection is done in the preprocessor. SMBv1, SMBv2, and SMBv3 are 7745 supported. 7746 7747 7748\end{itemize} 7749 7750\end{itemize} 7751 7752\textit{Option examples} 7753\footnotesize 7754\begin{verbatim} 7755 net 192.168.0.10 7756 net 192.168.0.0/24 7757 net [192.168.0.0/24] 7758 net 192.168.0.0/255.255.255.0 7759 net feab:45b3:ab92:8ac4:d322:007f:e5aa:7845 7760 net feab:45b3:ab92:8ac4:d322:007f:e5aa:7845/128 7761 net feab:45b3::/32 7762 net [192.168.0.10, feab:45b3::/32] 7763 net [192.168.0.0/24, feab:45b3:ab92:8ac4:d322:007f:e5aa:7845] 7764 policy Win2000 7765 policy Samba-3.0.22 7766 detect none 7767 detect smb 7768 detect [smb] 7769 detect smb 445 7770 detect [smb 445] 7771 detect smb [139,445] 7772 detect [smb [139,445]] 7773 detect [smb, tcp] 7774 detect [smb 139, tcp [135,2103]] 7775 detect [smb [139,445], tcp 135, udp 135, rpc-over-http-server [593,6002:6004]] 7776 autodetect none 7777 autodetect tcp 7778 autodetect [tcp] 7779 autodetect tcp 2025: 7780 autodetect [tcp 2025:] 7781 autodetect tcp [2025:3001,3003:] 7782 autodetect [tcp [2025:3001,3003:]] 7783 autodetect [tcp, udp] 7784 autodetect [tcp 2025:, udp 2025:] 7785 autodetect [tcp 2025:, udp, rpc-over-http-server [1025:6001,6005:]] 7786 smb_invalid_shares private 7787 smb_invalid_shares "private" 7788 smb_invalid_shares "C$" 7789 smb_invalid_shares [private, "C$"] 7790 smb_invalid_shares ["private", "C$"] 7791 smb_max_chain 1 7792 smb_file_inspection on 7793 smb_file_inspection off 7794 smb_file_inspection [ on, file-depth -1 ] 7795 smb_file_inspection [ on, file-depth 0 ] 7796 smb_file_inspection [ on, file-depth 4294967296 ] 7797 smb_file_inspection [ only, file-depth -1 ] 7798\end{verbatim} 7799\normalsize 7800 7801\textit{Configuration examples} 7802\footnotesize 7803\begin{verbatim} 7804 preprocessor dcerpc2_server: \ 7805 default 7806 7807 preprocessor dcerpc2_server: \ 7808 default, policy Win2000 7809 7810 preprocessor dcerpc2_server: \ 7811 default, policy Win2000, detect [smb, tcp], autodetect tcp 1025:, \ 7812 smb_invalid_shares ["C$", "D$", "ADMIN$"] 7813 7814 preprocessor dcerpc2_server: net 10.4.10.0/24, policy Win2000 7815 7816 preprocessor dcerpc2_server: \ 7817 net [10.4.10.0/24,feab:45b3::/126], policy WinVista, smb_max_chain 1 7818 7819 preprocessor dcerpc2_server: \ 7820 net [10.4.10.0/24,feab:45b3::/126], policy WinVista, \ 7821 detect [smb, tcp, rpc-over-http-proxy 8081], 7822 autodetect [tcp, rpc-over-http-proxy [1025:6001,6005:]], \ 7823 smb_invalid_shares ["C$", "ADMIN$"], no_autodetect_http_proxy_ports 7824 7825 preprocessor dcerpc2_server: \ 7826 net [10.4.11.56,10.4.11.57], policy Samba, detect smb, autodetect none 7827 7828 preprocessor dcerpc2_server: default, policy WinXP, \ 7829 smb_file_inspection [ on, file-depth 0 ] 7830\end{verbatim} 7831\normalsize 7832 7833\textit{Default server configuration} 7834\footnotesize 7835\begin{verbatim} 7836 preprocessor dcerpc2_server: default, policy WinXP, \ 7837 detect [smb [139,445], tcp 135, udp 135, rpc-over-http-server 593], \ 7838 autodetect [tcp 1025:, udp 1025:, rpc-over-http-server 1025:], \ 7839 smb_max_chain 3, smb_file_inspection off 7840\end{verbatim} 7841\normalsize 7842 7843\underline{Complete \texttt{dcerpc2} default configuration} 7844\footnotesize 7845\begin{verbatim} 7846 preprocessor dcerpc2: memcap 102400 7847 7848 preprocessor dcerpc2_server: \ 7849 default, policy WinXP, \ 7850 detect [smb [139,445], tcp 135, udp 135, rpc-over-http-server 593], \ 7851 autodetect [tcp 1025:, udp 1025:, rpc-over-http-server 1025:], \ 7852 smb_max_chain 3, smb_file_inspection off 7853\end{verbatim} 7854\normalsize 7855 7856\subsubsection{Events} 7857The preprocessor uses GID 133 to register events.\\ 7858 7859\textit{Memcap events} 7860\begin{itemize} 7861\item[] 7862 7863\begin{longtable}{|r|p{13.5cm}|} 7864 7865\hline 7866SID & Description\\ 7867\hline 7868 7869\hline 7870 1 & 7871 7872If the memory cap is reached and the preprocessor is configured to alert.\\ 7873 7874\hline 7875\end{longtable} 7876\end{itemize} 7877 7878\textit{SMB events} 7879\begin{itemize} 7880 7881\item[] 7882\begin{longtable}{|r|p{13.5cm}|} 7883 7884\hline 7885SID & Description\\ 7886\hline 7887 7888\hline 7889 2 & An invalid NetBIOS Session Service type was specified in the header. 7890 Valid types are: \texttt{Message}, \texttt{Request} (only from client), 7891 \texttt{Positive Response} (only from server), \texttt{Negative Response} 7892 (only from server), \texttt{Retarget Response} (only from server) and 7893 \texttt{Keep Alive}.\\ 7894\hline 7895 3 & An SMB message type was specified in the header. Either a request was 7896 made by the server or a response was given by the client.\\ 7897\hline 7898 4 & The SMB id does not equal \texttt{\textbackslash xffSMB} or 7899 \texttt{\textbackslash xfeSMB}.\\ 7900\hline 7901 5 & The word count of the command header is invalid. SMB commands have 7902 pretty specific word counts and if the preprocessor sees a command with 7903 a word count that doesn't jive with that command, the preprocessor will 7904 alert.\\ 7905\hline 7906 6 & Some commands require a minimum number of bytes after the command 7907 header. If a command requires this and the byte count is less than the 7908 minimum required byte count for that command, the preprocessor will 7909 alert.\\ 7910\hline 7911 7 & Some commands, especially the commands from the SMB Core implementation 7912 require a data format field that specifies the kind of data that will be 7913 coming next. Some commands require a specific format for the data. The 7914 preprocessor will alert if the format is not that which is expected for 7915 that command.\\ 7916\hline 7917 8 & Many SMB commands have a field containing an offset from the beginning 7918 of the SMB header to where the data the command is carrying starts. If 7919 this offset puts us before data that has already been processed or after 7920 the end of payload, the preprocessor will alert.\\ 7921\hline 7922 9 & Some SMB commands, such as \texttt{Transaction}, have a field containing 7923 the total amount of data to be transmitted. If this field is zero, the 7924 preprocessor will alert.\\ 7925\hline 7926 10 & The preprocessor will alert if the NetBIOS Session Service length field 7927 contains a value less than the size of an SMB header.\\ 7928\hline 7929 11 & The preprocessor will alert if the remaining NetBIOS packet length is 7930 less than the size of the SMB command header to be decoded.\\ 7931\hline 7932 12 & The preprocessor will alert if the remaining NetBIOS packet length is 7933 less than the size of the SMB command byte count specified in the 7934 command header.\\ 7935\hline 7936 13 & The preprocessor will alert if the remaining NetBIOS packet length is 7937 less than the size of the SMB command data size specified in the command 7938 header.\\ 7939\hline 7940 14 & The preprocessor will alert if the total data count specified in the 7941 SMB command header is less than the data size specified in the SMB 7942 command header. (Total data count must always be greater than or equal 7943 to current data size.)\\ 7944\hline 7945 15 & The preprocessor will alert if the total amount of data sent in a 7946 transaction is greater than the total data count specified in the SMB 7947 command header.\\ 7948\hline 7949 16 & The preprocessor will alert if the byte count specified in the SMB 7950 command header is less than the data size specified in the SMB command. 7951 (The byte count must always be greater than or equal to the data size.)\\ 7952\hline 7953 17 & Some of the Core Protocol commands (from the initial SMB implementation) 7954 require that the byte count be some value greater than the data size 7955 exactly. The preprocessor will alert if the byte count minus a 7956 predetermined amount based on the SMB command is not equal to the data 7957 size.\\ 7958\hline 7959 18 & For the \texttt{Tree Connect} command (and not the 7960 \texttt{Tree Connect AndX} command), the preprocessor has to queue 7961 the requests up and wait for a server response to determine whether or 7962 not an IPC share was successfully connected to (which is what the 7963 preprocessor is interested in). Unlike the \texttt{Tree Connect AndX} 7964 response, there is no indication in the \texttt{Tree Connect} response 7965 as to whether the share is IPC or not. There should be under normal 7966 circumstances no more than a few pending tree connects at a time and 7967 the preprocessor will alert if this number is excessive.\\ 7968\hline 7969 19 & After a client is done writing data using the \texttt{Write*} commands, 7970 it issues a \texttt{Read*} command to the server to tell it to send a 7971 response to the data it has written. In this case the preprocessor is 7972 concerned with the server response. The \texttt{Read*} request contains 7973 the file id associated with a named pipe instance that the preprocessor 7974 will ultimately send the data to. The server response, however, does not 7975 contain this file id, so it need to be queued with the request and 7976 dequeued with the response. If multiple \texttt{Read*} requests are sent 7977 to the server, they are responded to in the order they were sent. There 7978 should be under normal circumstances no more than a few pending 7979 \texttt{Read*} requests at a time and the preprocessor will alert if this 7980 number is excessive.\\ 7981\hline 7982 20 & The preprocessor will alert if the number of chained commands in a 7983 single request is greater than or equal to the configured amount 7984 (default is 3).\\ 7985\hline 7986 21 & With \texttt{AndX} command chaining it is possible to chain multiple 7987 \texttt{Session Setup AndX} commands within the same request. There is, 7988 however, only one place in the SMB header to return a login handle 7989 (or Uid). Windows does not allow this behavior, however Samba does. This 7990 is anomalous behavior and the preprocessor will alert if it happens.\\ 7991\hline 7992 22 & With \texttt{AndX} command chaining it is possible to chain multiple 7993 \texttt{Tree Connect AndX} commands within the same request. There is, 7994 however, only one place in the SMB header to return a tree handle 7995 (or Tid). Windows does not allow this behavior, however Samba does. This 7996 is anomalous behavior and the preprocessor will alert if it happens.\\ 7997\hline 7998 23 & When a \texttt{Session Setup AndX} request is sent to the server, the 7999 server responds (if the client successfully authenticates) which a user 8000 id or login handle. This is used by the client in subsequent requests to 8001 indicate that it has authenticated. A \texttt{Logoff AndX} request is 8002 sent by the client to indicate it wants to end the session and invalidate 8003 the login handle. With commands that are chained after a 8004 \texttt{Session Setup AndX} request, the login handle returned by the 8005 server is used for the subsequent chained commands. The combination of a 8006 \texttt{Session Setup AndX} command with a chained \texttt{Logoff AndX} 8007 command, essentially logins in and logs off in the same request and is 8008 anomalous behavior. The preprocessor will alert if it sees this.\\ 8009\hline 8010 24 & A \texttt{Tree Connect AndX} command is used to connect to a share. The 8011 \texttt{Tree Disconnect} command is used to disconnect from that share. 8012 The combination of a \texttt{Tree Connect AndX} command with a chained 8013 \texttt{Tree Disconnect} command, essentially connects to a share and 8014 disconnects from the same share in the same request and is anomalous 8015 behavior. The preprocessor will alert if it sees this.\\ 8016\hline 8017 25 & An \texttt{Open AndX} or \texttt{Nt Create AndX} command is used to 8018 open/create a file or named pipe. (The preprocessor is only interested in 8019 named pipes as this is where DCE/RPC requests are written to.) The 8020 \texttt{Close} command is used to close that file or named pipe. The 8021 combination of a \texttt{Open AndX} or \texttt{Nt Create AndX} command 8022 with a chained \texttt{Close} command, essentially opens and closes the 8023 named pipe in the same request and is anomalous behavior. The 8024 preprocessor will alert if it sees this.\\ 8025\hline 8026 26 & The preprocessor will alert if it sees any of the invalid SMB shares 8027 configured. It looks for a \texttt{Tree Connect} or 8028 \texttt{Tree Connect AndX} to the share.\\ 8029\hline 8030 48 & The preprocessor will alert if a data count for a Core dialect write 8031 command is zero.\\ 8032\hline 8033 49 & For some of the Core dialect commands such as \texttt{Write} and 8034 \texttt{Read}, there are two data count fields, one in the main command 8035 header and one in the data format section. If these aren't the same, the 8036 preprocessor will alert.\\ 8037\hline 8038 50 & In the initial negotiation phase of an SMB session, the server in a 8039 \texttt{Negotiate} response and the client in a \texttt{SessionSetupAndX} 8040 request will advertise the maximum number of outstanding requests 8041 supported. The preprocessor will alert if the lesser of the two is 8042 exceeded.\\ 8043\hline 8044 51 & When a client sends a request it uses a value called the MID (multiplex 8045 id) to match a response, which the server is supposed to echo, to a 8046 request. If there are multiple outstanding requests with the same 8047 MID, the preprocessor will alert.\\ 8048\hline 8049 52 & In the \texttt{Negotiate} request a client gives a list of SMB dialects it 8050 supports, normally in order from least desirable to most desirable 8051 and the server responds with the index of the dialect to be used on 8052 the SMB session. Anything less than "NT LM 0.12" would be very odd 8053 these days (even Windows 98 supports it) and the preprocessor will 8054 alert if the client doesn't offer it as a supported dialect or the 8055 server chooses a lesser dialect.\\ 8056\hline 8057 53 & There are a number of commands that are considered deprecated and/or 8058 obsolete by Microsoft (see MS-CIFS and MS-SMB). If the preprocessor 8059 detects the use of a deprecated/obsolete command used it will alert.\\ 8060\hline 8061 54 & There are some commands that can be used that can be considered unusual 8062 in the context they are used. These include some of the transaction 8063 commands such as: 8064 \texttt{SMB\_COM\_TRANSACTION / TRANS\_READ\_NMPIPE} 8065 \texttt{SMB\_COM\_TRANSACTION / TRANS\_WRITE\_NMPIPE} 8066 \texttt{SMB\_COM\_TRANSACTION2 / TRANS2\_OPEN2} 8067 \texttt{SMB\_COM\_NT\_TRANSACT / NT\_TRANSACT\_CREATE} 8068 The preprocessor will alert if it detects unusual use of a command.\\ 8069\hline 8070 55 & Transaction commands have a setup count field that indicates the 8071 number of 16bit words in the transaction setup. The preprocessor 8072 will alert if the setup count is invalid for the transaction 8073 command / sub command.\\ 8074\hline 8075 56 & There can be only one Negotiate transaction per session and it is the 8076 first thing a client and server do to determine the SMB dialect each 8077 supports. The preprocessor will alert if the client attempts multiple 8078 dialect negotiations.\\ 8079\hline 8080 57 & Malware will often set a file's attributes to ReadOnly/Hidden/System if 8081 it is successful in installing itself as a Windows service or is able to 8082 write an autorun.inf file since it doesn't want the user to see the file 8083 and the default folder options in Windows is not to display Hidden files. 8084 The preprocessor will alert if it detects a client attempt to set a 8085 file's attributes to ReadOnly/Hidden/System.\\ 8086\hline 8087 58 & File offset provided is greater than file size specified. This is applied 8088 to read / write requests for file.\\ 8089\hline 8090 59 & Nextcommand specified in SMBv2 or SMBv3 header is beyond payload boundary.\\ 8091\hline 8092\end{longtable} 8093\end{itemize} 8094 8095\textit{Connection-oriented DCE/RPC events} 8096\begin{itemize} 8097\item[] 8098 8099\begin{longtable}[h]{|r|p{13.5cm}|} 8100\hline 8101SID & Description\\ 8102\hline 8103 8104\hline 8105 27 & The preprocessor will alert if the connection-oriented DCE/RPC major 8106 version contained in the header is not equal to 5.\\ 8107\hline 8108 28 & The preprocessor will alert if the connection-oriented DCE/RPC minor 8109 version contained in the header is not equal to 0.\\ 8110\hline 8111 29 & The preprocessor will alert if the connection-oriented DCE/RPC PDU type 8112 contained in the header is not a valid PDU type.\\ 8113\hline 8114 30 & The preprocessor will alert if the fragment length defined in the header 8115 is less than the size of the header.\\ 8116\hline 8117 31 & The preprocessor will alert if the remaining fragment length is less 8118 than the remaining packet size.\\ 8119\hline 8120 32 & The preprocessor will alert if in a \texttt{Bind} or 8121 \texttt{Alter Context} request, there are no context items specified.\\ 8122\hline 8123 33 & The preprocessor will alert if in a \texttt{Bind} or 8124 \texttt{Alter Context} request, there are no transfer syntaxes to go with 8125 the requested interface.\\ 8126\hline 8127 34 & The preprocessor will alert if a non-last fragment is less than the size 8128 of the negotiated maximum fragment length. Most evasion techniques try 8129 to fragment the data as much as possible and usually each fragment comes 8130 well below the negotiated transmit size.\\ 8131\hline 8132 35 & The preprocessor will alert if a fragment is larger than the maximum 8133 negotiated fragment length.\\ 8134\hline 8135 36 & The byte order of the request data is determined by the Bind in 8136 connection-oriented DCE/RPC for Windows. It is anomalous behavior 8137 to attempt to change the byte order mid-session.\\ 8138\hline 8139 37 & The call id for a set of fragments in a fragmented request should stay 8140 the same (it is incremented for each complete request). The preprocessor 8141 will alert if it changes in a fragment mid-request.\\ 8142\hline 8143 38 & The operation number specifies which function the request is calling on 8144 the bound interface. If a request is fragmented, this number should stay 8145 the same for all fragments. The preprocessor will alert if the opnum 8146 changes in a fragment mid-request.\\ 8147\hline 8148 39 & The context id is a handle to a interface that was bound to. If a 8149 request if fragmented, this number should stay the same for all 8150 fragments. The preprocessor will alert if the context id changes in a 8151 fragment mid-request.\\ 8152\hline 8153\end{longtable} 8154\end{itemize} 8155 8156\textit{Connectionless DCE/RPC events} 8157\begin{itemize} 8158\item[] 8159\begin{longtable}{|r|p{13.5cm}|} 8160\hline 8161SID & Description\\ 8162\hline 8163\hline 8164 40 & The preprocessor will alert if the connectionless DCE/RPC major version 8165 is not equal to 4.\\ 8166\hline 8167 41 & The preprocessor will alert if the connectionless DCE/RPC PDU type is 8168 not a valid PDU type.\\ 8169\hline 8170 42 & The preprocessor will alert if the packet data length is less than the 8171 size of the connectionless header.\\ 8172\hline 8173 43 & The preprocessor will alert if the sequence number uses in a request is 8174 the same or less than a previously used sequence number on the session. 8175 In testing, wrapping the sequence number space produces strange behavior 8176 from the server, so this should be considered anomalous behavior.\\ 8177\hline 8178\end{longtable} 8179\end{itemize} 8180 8181\subsubsection{Rule Options} 8182 8183New rule options are supported by enabling the \texttt{dcerpc2} preprocessor: 8184 8185\begin{itemize} 8186\item[] 8187\begin{verbatim} 8188 dce_iface 8189 dce_opnum 8190 dce_stub_data 8191\end{verbatim} 8192\end{itemize} 8193 8194New modifiers to existing \texttt{byte\_test} and \texttt{byte\_jump} rule 8195options: 8196 8197\begin{itemize} 8198\item[] 8199\begin{verbatim} 8200 byte_test:dce 8201 byte_jump:dce 8202\end{verbatim} 8203\end{itemize} 8204 8205\texttt{dce\_iface} 8206\label{dcerpc2:dce_iface} 8207\begin{itemize} 8208 8209\item[] For DCE/RPC based rules it has been necessary to set flow-bits based on 8210a client bind to a service to avoid false positives. It is necessary for a 8211client to bind to a service before being able to make a call to it. When a 8212client sends a bind request to the server, it can, however, specify one or more 8213service interfaces to bind to. Each interface is represented by a UUID. Each 8214interface UUID is paired with a unique index (or context id) that future 8215requests can use to reference the service that the client is making a call to. 8216The server will respond with the interface UUIDs it accepts as valid and will 8217allow the client to make requests to those services. When a client makes a 8218request, it will specify the context id so the server knows what service the 8219client is making a request to. Instead of using flow-bits, a rule can simply 8220ask the preprocessor, using this rule option, whether or not the client has 8221bound to a specific interface UUID and whether or not this client request is 8222making a request to it. This can eliminate false positives where more than one 8223service is bound to successfully since the preprocessor can correlate the bind 8224UUID to the context id used in the request. A DCE/RPC request can specify 8225whether numbers are represented as big endian or little endian. The 8226representation of the interface UUID is different depending on the endianness 8227specified in the DCE/RPC previously requiring two rules - one for big endian 8228and one for little endian. The preprocessor eliminates the need for two rules 8229by normalizing the UUID. An interface contains a version. Some versions of an 8230interface may not be vulnerable to a certain exploit. Also, a DCE/RPC request 8231can be broken up into 1 or more fragments. Flags (and a field in the 8232connectionless header) are set in the DCE/RPC header to indicate whether the 8233fragment is the first, a middle or the last fragment. Many checks for data in 8234the DCE/RPC request are only relevant if the DCE/RPC request is a first 8235fragment (or full request), since subsequent fragments will contain data deeper 8236into the DCE/RPC request. A rule which is looking for data, say 5 bytes into 8237the request (maybe it's a length field), will be looking at the wrong data on a 8238fragment other than the first, since the beginning of subsequent fragments are 8239already offset some length from the beginning of the request. This can be a 8240source of false positives in fragmented DCE/RPC traffic. By default it is 8241reasonable to only evaluate if the request is a first fragment (or full 8242request). However, if the \texttt{any\_frag} option is used to specify 8243evaluating on all fragments.\\ 8244 8245\textit{Syntax} 8246\footnotesize 8247\begin{verbatim} 8248 dce_iface:<uuid>[, <operator><version>][, any_frag]; 8249 8250 uuid = hexlong '-' hexshort '-' hexshort '-' 2hexbyte '-' 6hexbyte 8251 hexlong = 4hexbyte 8252 hexshort = 2hexbyte 8253 hexbyte = 2HEXDIGIT 8254 operator = '<' | '>' | '=' | '!' 8255 version = 0-65535 8256\end{verbatim} 8257\normalsize 8258\textit{Examples} 8259\footnotesize 8260\begin{verbatim} 8261 dce_iface:4b324fc8-1670-01d3-1278-5a47bf6ee188; 8262 dce_iface:4b324fc8-1670-01d3-1278-5a47bf6ee188, <2; 8263 dce_iface:4b324fc8-1670-01d3-1278-5a47bf6ee188, any_frag; 8264 dce_iface:4b324fc8-1670-01d3-1278-5a47bf6ee188, =1, any_frag; 8265\end{verbatim} 8266\normalsize 8267 8268This option is used to specify an interface UUID. Optional arguments are an 8269interface version and operator to specify that the version be less than 8270('\textless'), greater than ('\textgreater'), equal to ('=') or not equal to 8271('!') the version specified. Also, by default the rule will only be evaluated 8272for a first fragment (or full request, i.e. not a fragment) since most rules 8273are written to start at the beginning of a request. The \texttt{any\_frag} 8274argument says to evaluate for middle and last fragments as well. This option 8275requires tracking client \texttt{Bind} and \texttt{Alter Context} requests as 8276well as server \texttt{Bind Ack} and \texttt{Alter Context} responses for 8277connection-oriented DCE/RPC in the preprocessor. For each \texttt{Bind} and 8278\texttt{Alter Context} request, the client specifies a list of interface UUIDs 8279along with a handle (or context id) for each interface UUID that will be used 8280during the DCE/RPC session to reference the interface. The server response 8281indicates which interfaces it will allow the client to make requests to - it 8282either accepts or rejects the client's wish to bind to a certain interface. 8283This tracking is required so that when a request is processed, the context id 8284used in the request can be correlated with the interface UUID it is a handle 8285for. 8286 8287\texttt{hexlong} and \texttt{hexshort} will be specified and interpreted to be 8288in big endian order (this is usually the default way an interface UUID will be 8289seen and represented). As an example, the following Messenger interface UUID as 8290taken off the wire from a little endian \texttt{Bind} request: 8291 8292\begin{verbatim} 8293 |f8 91 7b 5a 00 ff d0 11 a9 b2 00 c0 4f b6 e6 fc| 8294\end{verbatim} 8295 8296must be written as: 8297 8298\begin{verbatim} 8299 5a7b91f8-ff00-11d0-a9b2-00c04fb6e6fc 8300\end{verbatim} 8301 8302The same UUID taken off the wire from a big endian \texttt{Bind} request: 8303 8304\begin{verbatim} 8305 |5a 7b 91 f8 ff 00 11 d0 a9 b2 00 c0 4f b6 e6 fc| 8306\end{verbatim} 8307 8308must be written the same way: 8309 8310\begin{verbatim} 8311 5a7b91f8-ff00-11d0-a9b2-00c04fb6e6fc 8312\end{verbatim} 8313 8314This option matches if the specified interface UUID matches the interface UUID 8315(as referred to by the context id) of the DCE/RPC request and if supplied, the 8316version operation is true. This option will not match if the fragment is not a 8317first fragment (or full request) unless the \texttt{any\_frag} option is 8318supplied in which case only the interface UUID and version need match. Note 8319that a defragmented DCE/RPC request will be considered a full request. 8320 8321\begin{note} 8322Using this rule option will automatically insert fast pattern contents into 8323the fast pattern matcher. For UDP rules, the interface UUID, in both big and 8324little endian format will be inserted into the fast pattern matcher. For TCP 8325rules, (1) if the rule option \texttt{flow:to\_server|from\_client} is used, $|$05 00 00$|$ 8326will be inserted into the fast pattern matcher, (2) if the rule option 8327\texttt{flow:from\_server|to\_client} is used, $|$05 00 02$|$ will be inserted into the 8328fast pattern matcher and (3) if the flow isn't known, $|$05 00$|$ will be inserted 8329into the fast pattern matcher. Note that if the rule already has content rule 8330options in it, the best (meaning longest) pattern will be used. If a content 8331in the rule uses the \texttt{fast\_pattern} rule option, it will unequivocally be used 8332over the above mentioned patterns. 8333\end{note} 8334 8335\end{itemize} 8336 8337\texttt{dce\_opnum} 8338\label{dcerpc2:dce_opnum} 8339\begin{itemize} 8340 8341\item[] The opnum represents a specific function call to an interface. After is 8342has been determined that a client has bound to a specific interface and is 8343making a request to it (see above - \texttt{dce\_iface}) usually we want to 8344know what function call it is making to that service. It is likely that an 8345exploit lies in the particular DCE/RPC function call.\\ 8346 8347\textit{Syntax} 8348\footnotesize 8349\begin{verbatim} 8350 dce_opnum:<opnum-list>; 8351 8352 opnum-list = opnum-item | opnum-item ',' opnum-list 8353 opnum-item = opnum | opnum-range 8354 opnum-range = opnum '-' opnum 8355 opnum = 0-65535 8356\end{verbatim} 8357\normalsize 8358\textit{Examples} 8359\footnotesize 8360\begin{verbatim} 8361 dce_opnum:15; 8362 dce_opnum:15-18; 8363 dce_opnum:15, 18-20; 8364 dce_opnum:15, 17, 20-22; 8365\end{verbatim} 8366\normalsize 8367 8368This option is used to specify an opnum (or operation number), opnum range or 8369list containing either or both opnum and/or opnum-range. The opnum of a DCE/RPC 8370request will be matched against the opnums specified with this option. This 8371option matches if any one of the opnums specified match the opnum of the 8372DCE/RPC request. 8373 8374\end{itemize} 8375 8376\texttt{dce\_stub\_data} 8377\label{dcerpc2:dce_stub_data} 8378\begin{itemize} 8379 8380\item[] Since most netbios rules were doing protocol decoding only to get to 8381the DCE/RPC stub data, i.e. the remote procedure call or function call data, 8382this option will alleviate this need and place the cursor at the beginning of 8383the DCE/RPC stub data. This reduces the number of rule option checks and the 8384complexity of the rule. 8385 8386This option takes no arguments.\\ 8387 8388\textit{Example} 8389\footnotesize 8390\begin{verbatim} 8391 dce_stub_data; 8392\end{verbatim} 8393\normalsize 8394 8395This option is used to place the cursor (used to walk the packet payload in 8396rules processing) at the beginning of the DCE/RPC stub data, regardless of 8397preceding rule options. There are no arguments to this option. This option 8398matches if there is DCE/RPC stub data. 8399 8400The cursor is moved to the beginning of the stub data. All ensuing rule 8401options will be considered "sticky" to this buffer. The first rule option 8402following \texttt{dce\_stub\_data} should use absolute location modifiers if it is 8403position-dependent. Subsequent rule options should use a relative modifier if 8404they are meant to be relative to a previous rule option match in the stub data 8405buffer. Any rule option that does not specify a relative modifier will be 8406evaluated from the start of the stub data buffer. To leave the stub data buffer 8407and return to the main payload buffer, use the \texttt{pkt\_data} rule option - 8408see section \ref{sub:pkt_data} for details). 8409 8410\end{itemize} 8411\texttt{byte\_test} and \texttt{byte\_jump} with \texttt{dce}\label{dcerpc2:byte_test_jump} 8412\begin{itemize} 8413 8414\item[] A DCE/RPC request can specify whether numbers are represented in big or 8415little endian. These rule options will take as a new argument \texttt{dce} and 8416will work basically the same as the normal 8417\texttt{byte\_test}/\texttt{byte\_jump}, but since the DCE/RPC preprocessor 8418will know the endianness of the request, it will be able to do the correct 8419conversion. 8420 8421\texttt{byte\_test} 8422\begin{itemize} 8423\item[] \textit{Syntax} 8424\footnotesize 8425\begin{verbatim} 8426 byte_test:<convert>, [!]<operator>, <value>, <offset> [, relative], dce; 8427 8428 convert = 1 | 2 | 4 (only with option "dce") 8429 operator = '<' | '=' | '>' | '<=' | '>=' | '&' | '^' 8430 value = 0 - 4294967295 8431 offset = -65535 to 65535 8432\end{verbatim} 8433\normalsize 8434 8435\textit{Examples} 8436\footnotesize 8437\begin{verbatim} 8438 byte_test:4, >, 35000, 0, relative, dce; 8439 byte_test:2, !=, 2280, -10, relative, dce; 8440\end{verbatim} 8441\normalsize 8442 8443When using the \texttt{dce} argument to a \texttt{byte\_test}, the following 8444normal \texttt{byte\_test} arguments will not be allowed: \texttt{big}, 8445\texttt{little}, \texttt{string}, \texttt{hex}, \texttt{dec} and \texttt{oct}. 8446\end{itemize} 8447 8448\texttt{byte\_jump} 8449\begin{itemize} 8450\item[] \textit{Syntax} 8451\footnotesize 8452\begin{verbatim} 8453 byte_jump:<convert>, <offset>[, relative][, multiplier <mult_value>] \ 8454 [, align][, post_offset <adjustment_value>], dce; 8455 8456 convert = 1 | 2 | 4 (only with option "dce") 8457 offset = -65535 to 65535 8458 mult_value = 0 - 65535 8459 adjustment_value = -65535 to 65535 8460\end{verbatim} 8461\normalsize 8462 8463\textit{Example} 8464\footnotesize 8465\begin{verbatim} 8466 byte_jump:4,-4,relative,align,multiplier 2,post_offset -4,dce; 8467\end{verbatim} 8468\normalsize 8469 8470When using the \texttt{dce} argument to a \texttt{byte\_jump}, the following 8471normal \texttt{byte\_jump} arguments will not be allowed: \texttt{big}, 8472\texttt{little}, \texttt{string}, \texttt{hex}, \texttt{dec}, \texttt{oct} and 8473\texttt{from\_beginning}. 8474 8475\end{itemize} 8476\end{itemize} 8477 8478\textit{Example of rule complexity reduction} 8479\begin{itemize} 8480 8481\item[] The following two rules using the new rule options replace 64 (set and 8482isset flowbit) rules that are necessary if the new rule options are not used: 8483 8484\footnotesize 8485\begin{verbatim} 8486 alert tcp $EXTERNAL_NET any -> $HOME_NET [135,139,445,593,1024:] \ 8487 (msg:"dns R_Dnssrv funcs2 overflow attempt"; flow:established,to_server; \ 8488 dce_iface:50abc2a4-574d-40b3-9d66-ee4fd5fba076; dce_opnum:0-11; dce_stub_data; \ 8489 pcre:"/^.{12}(\x00\x00\x00\x00|.{12})/s"; byte_jump:4,-4,relative,align,dce; \ 8490 byte_test:4,>,256,4,relative,dce; reference:bugtraq,23470; reference:cve,2007-1748; \ 8491 classtype:attempted-admin; sid:1000068;) 8492 8493 alert udp $EXTERNAL_NET any -> $HOME_NET [135,1024:] \ 8494 (msg:"dns R_Dnssrv funcs2 overflow attempt"; flow:established,to_server; \ 8495 dce_iface:50abc2a4-574d-40b3-9d66-ee4fd5fba076; dce_opnum:0-11; dce_stub_data; \ 8496 pcre:"/^.{12}(\x00\x00\x00\x00|.{12})/s"; byte_jump:4,-4,relative,align,dce; \ 8497 byte_test:4,>,256,4,relative,dce; reference:bugtraq,23470; reference:cve,2007-1748; \ 8498 classtype:attempted-admin; sid:1000069;) 8499\end{verbatim} 8500\normalsize 8501\end{itemize} 8502 8503\subsection{Sensitive Data Preprocessor} 8504\label{sub:sensitive_data} 8505 8506The Sensitive Data preprocessor is a Snort module that performs detection and 8507filtering of Personally Identifiable Information (PII). This information 8508includes credit card numbers, U.S. Social Security numbers, and email addresses. 8509A limited regular expression syntax is also included for defining your own PII. 8510 8511\subsubsection{Dependencies} 8512 8513The Stream preprocessor must be enabled for the Sensitive Data preprocessor 8514to work. 8515 8516\subsubsection{Preprocessor Configuration} 8517 8518Sensitive Data configuration is split into two parts: the preprocessor config, 8519and the rule options. The preprocessor config starts with: 8520 8521\begin{verbatim} 8522preprocessor sensitive_data: 8523\end{verbatim} 8524 8525\textit{Option syntax} 8526\begin{itemize} 8527 8528\item[] 8529\begin{tabular}{|l|c|c|p{6cm}|} 8530\hline 8531Option & Argument & Required & Default\\ 8532\hline 8533\hline 8534\texttt{alert\_threshold} & \texttt{<number>} & NO & \texttt{alert\_threshold 25}\\ 8535\hline 8536\texttt{mask\_output} & NONE & NO & OFF\\ 8537\hline 8538\texttt{ssn\_file} & \texttt{<filename>} & NO & OFF\\ 8539\hline 8540\end{tabular} 8541\end{itemize} 8542 8543\footnotesize 8544\begin{verbatim} 8545 alert_threshold = 1 - 65535 8546\end{verbatim} 8547\normalsize 8548 8549\textit{Option explanations} 8550\begin{itemize} 8551\item[] \texttt{alert\_threshold} 8552\begin{itemize} 8553 8554\item[] The preprocessor will alert when any combination of PII are detected 8555in a session. This option specifies how many need to be detected before 8556alerting. 8557This should be set higher than the highest individual count in your 8558"sd\_pattern" rules. 8559 8560\end{itemize} 8561 8562\item[] \texttt{mask\_output} 8563\begin{itemize} 8564 8565\item[] This option replaces all but the last 4 digits of a detected PII with 8566"X"s. This is only done on credit card \& Social Security numbers, where 8567an organization's regulations may prevent them from seeing unencrypted 8568numbers. 8569 8570\end{itemize} 8571 8572\item[] \texttt{ssn\_file} 8573\begin{itemize} 8574 8575\item[] A Social Security number is broken up into 3 sections: 8576Area (3 digits), Group (2 digits), and Serial (4 digits). 8577On a monthly basis, the Social Security Administration publishes a list 8578of which Group numbers are in use for each Area. 8579These numbers can be updated in Snort by supplying a CSV file with the 8580new maximum Group numbers to use. 8581By default, Snort recognizes Social Security numbers issued up through 8582November 2009. 8583 8584\end{itemize} 8585\end{itemize} 8586 8587\textit{Example preprocessor config} 8588\begin{verbatim} 8589preprocessor sensitive_data: alert_threshold 25 \ 8590 mask_output \ 8591 ssn_file ssn_groups_Jan10.csv 8592\end{verbatim} 8593 8594\subsubsection{Rule Options} 8595 8596Snort rules are used to specify which PII the preprocessor should look for. 8597A new rule option is provided by the preprocessor: 8598 8599\begin{verbatim} 8600sd_pattern 8601\end{verbatim} 8602 8603This rule option specifies what type of PII a rule should detect. 8604 8605\textit{Syntax} 8606\begin{verbatim} 8607 sd_pattern:<count>, <pattern>; 8608\end{verbatim} 8609\footnotesize 8610\begin{verbatim} 8611 8612 count = 1 - 255 8613 pattern = any string 8614\end{verbatim} 8615\normalsize 8616 8617\textit{Option Explanations} 8618 8619\begin{itemize} 8620\item[] \texttt{count} 8621 8622\begin{itemize} 8623\item[] This dictates how many times a PII pattern must be matched for an alert 8624to be generated. The count is tracked across all packets in a session. 8625\end{itemize} 8626 8627\item[] \texttt{pattern} 8628 8629\begin{itemize} 8630\item[] This is where the pattern of the PII gets specified. There are a few 8631built-in patterns to choose from: 8632 8633\begin{itemize} 8634\item[] \texttt{credit\_card} 8635 8636\begin{itemize} 8637\item[] The "credit\_card" pattern matches 15- and 16-digit credit card 8638numbers. These numbers may have spaces, dashes, or nothing in 8639between groups. This covers Visa, Mastercard, Discover, and 8640American Express. 8641Credit card numbers matched this way have their check digits 8642verified using the Luhn algorithm. 8643\end{itemize} 8644 8645\item[] \texttt{us\_social} 8646 8647\begin{itemize} 8648\item[] This pattern matches against 9-digit U.S. Social Security numbers. 8649The SSNs are expected to have dashes between the Area, Group, and 8650Serial sections. 8651 8652SSNs have no check digits, but the preprocessor will check matches 8653against the list of currently allocated group numbers. 8654\end{itemize} 8655 8656\item[] \texttt{us\_social\_nodashes} 8657 8658\begin{itemize} 8659\item[] This pattern matches U.S. Social Security numbers without dashes 8660separating the Area, Group, and Serial sections. 8661\end{itemize} 8662 8663\item[] \texttt{email} 8664 8665\begin{itemize} 8666\item[] This pattern matches against email addresses. 8667\end{itemize} 8668\end{itemize} 8669 8670\item[] If the pattern specified is not one of the above built-in patterns, 8671then it is the definition of a custom PII pattern. Custom PII types 8672are defined using a limited regex-style syntax. The following 8673special characters and escape sequences are supported: 8674 8675\item[] 8676\begin{tabular}{|c|p{10cm}|} 8677 8678\hline 8679\texttt{\textbackslash d} & matches any digit\\ 8680\hline 8681\texttt{\textbackslash D} & matches any non-digit\\ 8682\hline 8683\texttt{\textbackslash l} & matches any letter\\ 8684\hline 8685\texttt{\textbackslash L} & matches any non-letter\\ 8686\hline 8687\texttt{\textbackslash w} & matches any alphanumeric character\\ 8688\hline 8689\texttt{\textbackslash W} & matches any non-alphanumeric character\\ 8690\hline 8691\texttt{\{num\}} & used to repeat a character or escape sequence "num" times. 8692example: "\d\{3\}" matches 3 digits.\\ 8693\hline 8694\texttt{?} & makes the previous character or escape sequence optional. 8695example: " ?" matches an optional space. 8696This behaves in a greedy manner.\\ 8697\hline 8698\texttt{\textbackslash\textbackslash} & matches a backslash\\ 8699\hline 8700\textbackslash \{, \textbackslash \} & matches \{ and \}\\ 8701\hline 8702\textbackslash ? & matches a question mark.\\ 8703\hline 8704\end{tabular} 8705 8706\item[] Other characters in the pattern will be matched literally. 8707 8708\begin{note} 8709Unlike PCRE, \texttt{\textbackslash w} in this rule option does NOT match underscores. 8710\end{note} 8711\end{itemize} 8712 8713\item[] \textit{Examples} 8714\begin{verbatim} 8715 sd_pattern: 2,us_social; 8716\end{verbatim} 8717 Alerts when 2 social security numbers (with dashes) appear in a session. 8718 8719\begin{verbatim} 8720 sd_pattern: 5,(\d{3})\d{3}-\d{4}; 8721\end{verbatim} 8722 Alerts on 5 U.S. phone numbers, following the format (123)456-7890 8723 8724 Whole rule example: 8725 8726\begin{verbatim} 8727 alert tcp $HOME_NET $HIGH_PORTS -> $EXTERNAL_NET $SMTP_PORTS \ 8728 (msg:"Credit Card numbers sent over email"; gid:138; sid:1000; rev:1; \ 8729 sd_pattern:4,credit_card; metadata:service smtp;) 8730\end{verbatim} 8731 8732 8733\item[] \textit{Caveats} 8734\begin{itemize} 8735\item[] \texttt{sd\_pattern} is not compatible with other rule options. Trying to use 8736other rule options with \texttt{sd\_pattern} will result in an error message. 8737 8738Rules using \texttt{sd\_pattern} must use GID 138. 8739\end{itemize} 8740\end{itemize} 8741 8742\subsection{Normalizer} 8743 8744When operating Snort in inline mode, it is helpful to normalize packets to help 8745minimize the chances of evasion. 8746 8747To enable the normalizer, use the following when configuring Snort: 8748 8749\begin{verbatim} 8750 ./configure --enable-normalizer 8751\end{verbatim} 8752 8753The normalize preprocessor is activated via the conf as outlined below. There 8754are also many new preprocessor and decoder rules to alert on or drop packets 8755with "abnormal" encodings. 8756 8757Note that in the following, fields are cleared only if they are non-zero. 8758Also, normalizations will only be enabled if the selected DAQ supports packet 8759replacement and is operating in inline mode. 8760 8761If a policy is configured for \texttt{inline\_test} or passive mode, any 8762normalization statements in the policy config are ignored. 8763 8764\subsubsection{IP4 Normalizations} 8765 8766IP4 normalizations are enabled with: 8767 8768\begin{verbatim} 8769 preprocessor normalize_ip4: [df], [rf], [tos], [trim] 8770\end{verbatim} 8771 8772Base normalizations enabled with "preprocessor \texttt{normalize\_ip4}" include: 8773 8774\begin{itemize} 8775\item 8776TTL normalization if enabled (explained below). 8777 8778\item 8779Clear the differentiated services field (formerly TOS). 8780 8781\item 8782NOP all options octets. 8783\end{itemize} 8784 8785Optional normalizations include: 8786 8787\begin{itemize} 8788\item \texttt{df} 8789don't fragment: clear this bit on incoming packets. 8790 8791\item \texttt{rf} 8792reserved flag: clear this bit on incoming packets. 8793 8794\item \texttt{tos} 8795type of service (differentiated services): clear this byte. 8796 8797\item \texttt{trim} 8798truncate packets with excess payload to the datagram length specified in the 8799IP header + the layer 2 header (e.g. ethernet), but don't truncate below minimum 8800frame length. This is automatically disabled if the DAQ can't inject packets. 8801\end{itemize} 8802 8803\subsubsection{IP6 Normalizations} 8804 8805IP6 normalizations are enabled with: 8806 8807\begin{verbatim} 8808 preprocessor normalize_ip6 8809\end{verbatim} 8810 8811Base normalizations enabled with "preprocessor \texttt{normalize\_ip6}" include: 8812 8813\begin{itemize} 8814\item 8815Hop limit normalization if enabled (explained below). 8816 8817\item 8818NOP all options octets in hop-by-hop and destination options extension headers. 8819\end{itemize} 8820 8821 8822\subsubsection{ICMP4/6 Normalizations} 8823 8824ICMP4 and ICMP6 normalizations are enabled with: 8825 8826\begin{verbatim} 8827 preprocessor normalize_icmp4 8828 preprocessor normalize_icmp6 8829\end{verbatim} 8830 8831Base normalizations enabled with the above include: 8832 8833\begin{itemize} 8834\item 8835Clear the code field in echo requests and replies. 8836\end{itemize} 8837 8838 8839\subsubsection{TCP Normalizations} 8840 8841TCP normalizations are enabled with: 8842 8843\begin{verbatim} 8844 preprocessor normalize_tcp: \ 8845 [block], [rsv], [pad], \ 8846 [req_urg], [req_pay], [req_urp], \ 8847 [ips], [urp], [trim], \ 8848 [trim_syn], [trim_rst], \ 8849 [trim_win], [trim_mss], \ 8850 [ecn <ecn_type>], \ 8851 [opts [allow <allowed_opt>+]] 8852 8853 <ecn_type> ::= stream | packet 8854 8855 <allowed_opt> ::= \ 8856 sack | echo | partial_order | conn_count | alt_checksum | md5 | <num> 8857 8858 <sack> ::= { 4, 5 } 8859 <echo> ::= { 6, 7 } 8860 <partial_order> ::= { 9, 10 } 8861 <conn_count> ::= { 11, 12, 13 } 8862 <alt_checksum> ::= { 14, 15 } 8863 <md5> ::= { 19 } 8864 <num> ::= (3..255) 8865\end{verbatim} 8866 8867Normalizations include: 8868 8869\begin{itemize} 8870\item \texttt{block} 8871allow packet drops during TCP normalization. 8872 8873\item \texttt{rsv} 8874clear the reserved bits in the TCP header. 8875 8876\item \texttt{pad} 8877clear any option padding bytes. 8878 8879\item \texttt{req\_urg} 8880clear the urgent pointer if the urgent flag is not set. 8881 8882\item \texttt{req\_pay} 8883clear the urgent pointer and the urgent flag if there is no payload. 8884 8885\item \texttt{req\_urp} 8886clear the urgent flag if the urgent pointer is not set. 8887 8888\item \texttt{ips} 8889ensure consistency in retransmitted data (also forces reassembly policy to 8890"first"). Any segments that can't be properly reassembled will be dropped. 8891 8892\item \texttt{trim\_syn} 8893remove data on SYN. 8894 8895\item \texttt{trim\_rst} 8896remove any data from RST packet. 8897 8898\item \texttt{trim\_win} 8899trim data to window. 8900 8901\item \texttt{trim\_mss} 8902trim data to MSS. 8903 8904\item \texttt{trim} 8905enable all of the above trim options. 8906 8907\item \texttt{ecn packet} 8908 8909clear ECN flags on a per packet basis (regardless of negotiation). 8910 8911\item \texttt{ecn stream} 8912 8913clear ECN flags if usage wasn't negotiated. Should also enable \texttt{require\_3whs}. 8914 8915\item \texttt{opts} 8916 8917NOP all option bytes other than maximum segment size, window scaling, 8918timestamp, and any explicitly allowed with the allow keyword. You can allow 8919options to pass by name or number. 8920 8921\item \texttt{opts} 8922 8923if timestamp is present but invalid, or valid but not negotiated, NOP the 8924timestamp octets. 8925 8926\item \texttt{opts} 8927 8928if timestamp was negotiated but not present, block the packet. 8929 8930\item \texttt{opts} 8931 8932clear TS ECR if ACK flag is not set. 8933 8934\item \texttt{opts} 8935 8936MSS and window scale options are NOP'd if SYN flag is not set. 8937 8938\end{itemize} 8939 8940\subsubsection{TTL Normalization} 8941 8942TTL normalization pertains to both IP4 TTL (time-to-live) and IP6 (hop limit) 8943and is only performed if both the relevant base normalization is enabled (as 8944described above) and the minimum and new TTL values are configured, as follows: 8945 8946\begin{verbatim} 8947 config min_ttl: <min_ttl> 8948 config new_ttl: <new_ttl> 8949 8950 <min_ttl> ::= (1..255) 8951 <new_ttl> ::= (<min_ttl>+1..255) 8952\end{verbatim} 8953 8954If \texttt{new\_ttl }$>$ \texttt{min\_ttl}, then if a packet is received with a 8955TTL $<$ \texttt{min\_ttl}, the TTL will be set to \texttt{new\_ttl}. 8956 8957Note that this configuration item was deprecated in 2.8.6: 8958 8959\begin{verbatim} 8960 preprocessor stream5_tcp: min_ttl <#> 8961\end{verbatim} 8962 8963By default \texttt{min\_ttl} = 1 (TTL normalization is disabled). 8964When TTL normalization is turned on the \texttt{new\_ttl} is set 8965to 5 by default. 8966 8967\subsection{SIP Preprocessor} 8968\label{sub:sip} 8969Session Initiation Protocol (SIP) is an application-layer control (signaling) 8970protocol for creating, modifying, and terminating sessions with one or more 8971participants. These sessions include Internet telephone calls, multimedia 8972distribution, and multimedia conferences. SIP Preprocessor provides ways to 8973tackle Common Vulnerabilities and Exposures (CVEs) related with SIP found over 8974the past few years. It also makes detecting new attacks easier. 8975 8976\subsubsection{Dependency Requirements} 8977 8978For proper functioning of the preprocessor: 8979 8980\begin{itemize} 8981 8982\item Stream session tracking must be enabled, i.e. stream5. Both TCP and UDP must be 8983 enabled in stream5. The preprocessor requires a session tracker to keep its 8984 data. In addition, Stream API is able to provide correct support for ignoring 8985 audio/video data channel. 8986 8987\item IP defragmentation should be enabled, i.e. the frag3 preprocessor should be 8988 enabled and configured. 8989 8990\end{itemize} 8991 8992\subsubsection{Configuration} 8993The preprocessor configuration name is \texttt{sip}.\\ 8994\begin{verbatim} 8995 preprocessor sip 8996\end{verbatim} 8997\textit{Option syntax} 8998\begin{itemize} 8999 9000\item[] 9001\begin{tabular}{|l|c|c|p{6cm}|} 9002\hline 9003Option & Argument & Required & Default\\ 9004\hline 9005\hline 9006\texttt{disabled} & NONE & NO & OFF\\ 9007\hline 9008\texttt{max\_sessions} & \texttt{<max\_sessions>} & NO & \texttt{max\_sessions 10000}\\ 9009\hline 9010\texttt{max\_dialogs} & \texttt{<max\_dialogs>} & NO & \texttt{max\_dialogs 4}\\ 9011\hline 9012\texttt{ports} & \texttt{<ports>} & NO & \texttt{ports \{ 5060 5061 \} }\\ 9013\hline 9014\texttt{methods} & \texttt{<methods>} & NO & \texttt{methods \{ invite cancel ack bye 9015 register options \} }\\ 9016\hline 9017\texttt{max\_uri\_len} & \texttt{<max\_uri\_len>} & NO & \texttt{max\_uri\_len 256 }\\ 9018\hline 9019\texttt{max\_call\_id\_len} & \texttt{<max\_call\_id\_len>} & NO & \texttt{max\_call\_id\_len 256 }\\ 9020\hline 9021\texttt{max\_requestName\_len} & \texttt{<max\_requestName\_len>} & NO & \texttt{max\_requestName\_len 20 }\\ 9022\hline 9023\texttt{max\_from\_len} & \texttt{<max\_from\_len>} & NO & \texttt{max\_from\_len 256 }\\ 9024\hline 9025\texttt{max\_to\_len} & \texttt{<max\_to\_len>} & NO & \texttt{max\_to\_len 256 }\\ 9026\hline 9027\texttt{max\_via\_len} & \texttt{<max\_via\_len>} & NO & \texttt{max\_via\_len 1024 }\\ 9028\hline 9029\texttt{max\_contact\_len} & \texttt{<max\_contact\_len>} & NO & \texttt{max\_contact\_len 256 }\\ 9030\hline 9031\texttt{max\_content\_len} & \texttt{<max\_content\_len>} & NO & \texttt{max\_content\_len 1024 }\\ 9032\hline 9033\texttt{ignore\_call\_channel} & NONE & NO & OFF\\ 9034\hline 9035\end{tabular} 9036\end{itemize} 9037\footnotesize 9038\begin{verbatim} 9039 max_sessions = 1024-4194303 9040 max_dialogs = 1-4194303 9041 methods = "invite"|"cancel"|"ack"|"bye"|"register"| "options"\ 9042 |"refer" |"subscribe"|"update"|"join"|"info"|"message"\ 9043 |"notify"|"prack" 9044 max_uri_len = 0-65535 9045 max_call_id_len = 0-65535 9046 max_requestName_len = 0-65535 9047 max_from_len = 0-65535 9048 max_to_len = 0-65535 9049 max_via_len = 0-65535 9050 max_contact_len = 0-65535 9051 max_content_len = 0-65535 9052\end{verbatim} 9053\normalsize 9054\textit{Option explanations} 9055\begin{itemize} 9056\item[] \texttt{disabled} 9057\begin{itemize} 9058\item[] SIP dynamic preprocessor can be enabled/disabled through configuration. 9059 By default this value is turned off. When the preprocessor is disabled, 9060 only the max\_sessions option is applied when specified with the configuration. 9061\end{itemize} 9062\item[] \texttt{max\_sessions} 9063\begin{itemize} 9064\item[] This specifies the maximum number of sessions that can be allocated. 9065 Those sessions are stream sessions, so they are bounded by maximum number of 9066 stream sessions. Default is 10000. 9067\end{itemize} 9068\item[] \texttt{max\_dialogs} 9069\begin{itemize} 9070\item[] This specifies the maximum number of dialogs within one stream session. If exceeded, 9071 the oldest dialog will be dropped. Default is 4. 9072\end{itemize} 9073\item[] \texttt{ports} 9074\begin{itemize} 9075\item[] This specifies on what ports to check for SIP messages. Typically, this will 9076 include 5060, 5061. 9077\item[] \textit{Syntax} 9078\begin{verbatim} 9079 ports { <port> [<port>< ... >] } 9080\end{verbatim} 9081\item[] \textit{Examples} 9082\begin{verbatim} 9083 ports { 5060 5061 } 9084\end{verbatim} 9085\item[] Note: there are spaces before and after `\{' and `\}'. 9086\end{itemize} 9087 \item[] \texttt{methods} 9088\begin{itemize} 9089 \item[] This specifies on what methods to check for SIP messages: (1) invite, 9090 (2) cancel, (3) ack, (4) bye, (5) register, (6) options, (7) refer, 9091 (8) subscribe, (9) update (10) join (11) info (12) message (13) notify 9092 (14) prack. 9093 Note: those 14 methods are up to date list (Feb. 2011). New methods can be 9094 added to the list. Up to 32 methods supported. 9095 9096\item[] \textit{Syntax} 9097\begin{verbatim} 9098 methods { <method-list> } 9099 method-list = method|method method-list 9100 methods = "invite"|"cancel"|"ack"|"bye"|"register"| "options"\ 9101 |"refer"|"subscribe"|"update"|"join"|"info"|"message"\ 9102 |"notify"|"prack" 9103\end{verbatim} 9104\item[] \textit{Examples} 9105\begin{verbatim} 9106 methods { invite cancel ack bye register options } 9107 methods { invite cancel ack bye register options information } 9108\end{verbatim} 9109\item[] Note: there are spaces before and after `\{' and `\}'. 9110\end{itemize} 9111\item[] \texttt{max\_uri\_len} 9112\begin{itemize} 9113 \item[] This specifies the maximum Request URI field size. If the Request URI field 9114 is greater than this size, an alert is generated. Default is set to 256. 9115 The allowed range for this option is 0 - 65535. ``0'' means never alert. 9116\end{itemize} 9117 9118\item[] \texttt{max\_call\_id\_len} 9119\begin{itemize} 9120 \item[] This specifies the maximum Call-ID field size. If the Call-ID field is 9121 greater than this size, an alert is generated. Default is set to 256. 9122 The allowed range for this option is 0 - 65535. ``0'' means never alert. 9123\end{itemize} 9124 9125\item[] \texttt{max\_requestName\_len} 9126\begin{itemize} 9127 \item[] This specifies the maximum request name size that is part of the CSeq ID. 9128 If the request name is greater than this size, an alert is generated. 9129 Default is set to 20. The allowed range for this option is 0 - 65535. 9130 ``0'' means never alert. 9131\end{itemize} 9132 9133\item[] \texttt{max\_from\_len} 9134\begin{itemize} 9135 \item[] This specifies the maximum From field size. If the From field is greater 9136 than this size, an alert is generated. Default is set to 256. The allowed 9137 range for this option is 0 - 65535. ``0'' means never alert. 9138\end{itemize} 9139 9140\item[] \texttt{max\_to\_len} 9141\begin{itemize} 9142 \item[] This specifies the maximum To field size. If the To field is greater than 9143 this size, an alert is generated. Default is set to 256. The allowed range 9144 for this option is 0 - 65535. ``0'' means never alert. 9145\end{itemize} 9146 9147\item[] \texttt{max\_via\_len} 9148\begin{itemize} 9149 \item[] This specifies the maximum Via field size. If the Via field is greater than 9150 this size, an alert is generated. Default is set to 1024. The allowed range 9151 for this option is 0 - 65535. ``0'' means never alert. 9152\end{itemize} 9153\item[] \texttt{max\_contact\_len} 9154\begin{itemize} 9155 \item[] This specifies the maximum Contact field size. If the Contact field is 9156 greater than this size, an alert is generated. Default is set to 256. 9157 The allowed range for this option is 0 - 65535. ``0'' means never alert. 9158\end{itemize} 9159\item[] \texttt{max\_content\_len} 9160\begin{itemize} 9161 \item[] This specifies the maximum content length of the message body. If the 9162 content length is greater than this number, an alert is generated. 9163 Default is set to 1024. The allowed range for this option is 0 - 65535. 9164 ``0'' means never alert. 9165\end{itemize} 9166\item[] \texttt{ignore\_call\_channel} 9167\begin{itemize} 9168 \item[] This enables the support for ignoring audio/video data channel 9169 (through Stream API). By default, this is disabled. 9170\end{itemize} 9171 9172\end{itemize} 9173\textit{Option examples} 9174\footnotesize 9175\begin{verbatim} 9176 max_sessions 30000 9177 disabled 9178 ports { 5060 5061 } 9179 methods { invite cancel ack bye register options } 9180 methods { invite cancel ack bye register options information } 9181 max_uri_len 1024 9182 max_call_id_len 1024 9183 max_requestName_len 10 9184 max_from_len 1024 9185 max_to_len 1024 9186 max_via_len 1024 9187 max_contact_len 1024 9188 max_content_len 1024 9189 max_content_len 9190 ignore_call_channel 9191\end{verbatim} 9192\normalsize 9193 9194\textit{Configuration examples} 9195\footnotesize 9196\begin{verbatim} 9197 preprocessor sip 9198 preprocessor sip: max_sessions 500000 9199 preprocessor sip: max_contact_len 512, max_sessions 300000, methods { invite \ 9200 cancel ack bye register options } , ignore_call_channel 9201 preprocessor sip: ports { 5060 49848 36780 10270 }, max_call_id_len 200, \ 9202 max_from_len 100, max_to_len 200, max_via_len 1000, \ 9203 max_requestName_len 50, max_uri_len 100, ignore_call_channel,\ 9204 max_content_len 1000 9205 preprocessor sip: disabled 9206 preprocessor sip: ignore_call_channel 9207\end{verbatim} 9208\normalsize 9209 9210\textit{Default configuration} 9211\footnotesize 9212\begin{verbatim} 9213 preprocessor sip 9214\end{verbatim} 9215\normalsize 9216\subsubsection{Events} 9217The preprocessor uses GID 140 to register events. 9218\begin{longtable}{|r|p{13.5cm}|} 9219 9220\hline 9221SID & Description\\ 9222\hline 9223 1 & If the memory cap is reached and the preprocessor is configured to alert, 9224 this alert will be created. \\ 9225\hline 9226 2 & Request URI is required. When Request URI is empty, this alert will be created. \\ 9227\hline 9228 3 & The Request URI is larger than the defined length in configuration.\\ 9229\hline 9230 4 & When Call-ID is empty, this alert will be created.\\ 9231\hline 9232 5 & The Call-ID is larger than the defined length in configuration.\\ 9233\hline 9234 6 & The sequence e number value MUST be expressible as a 32-bit unsigned integer 9235 and MUST be less than $2^{31}$.\\ 9236\hline 9237 7 & The request name in the CSeq is larger than the defined length in configuration.\\ 9238\hline 9239 8 & From field is empty.\\ 9240\hline 9241 9 & From field is larger than the defined length in configuration.\\ 9242\hline 9243 10 & To field is empty.\\ 9244\hline 9245 11 & To field is larger than the defined length in configuration.\\ 9246\hline 9247 12 & Via filed is empty.\\ 9248\hline 9249 13 & Via filed is larger than the defined length in configuration.\\ 9250\hline 9251 14 & Contact is empty, but it is required non-empty for the message.\\ 9252\hline 9253 15 & The Contact is larger than the defined length in configuration. \\ 9254\hline 9255 16 & The content length is larger than the defined length in configuration or is negative. \\ 9256\hline 9257 17 & There are multiple requests in a single packet. Old SIP protocol supports 9258 multiple sip messages within one packet.\\ 9259\hline 9260 18 & There are inconsistencies between Content-Length in SIP header and 9261 actual body data.\\ 9262\hline 9263 19 & Request name is invalid in response.\\ 9264\hline 9265 20 & Authenticated invite message received, but no challenge from server received. 9266 This is the case of InviteReplay billing attack.\\ 9267\hline 9268 21 & Authenticated invite message received, but session information has been changed. 9269 This is different from re-INVITE, where the dialog has been established. 9270 and authenticated. This is can prevent FakeBusy billing attack.\\ 9271\hline 9272 22 & Response status code is not a 3 digit number.\\ 9273\hline 9274 23 & Content type header field is required if the message body is not empty.\\ 9275\hline 9276 24 & SIP version other than 2.0, 1.0, and 1.1 is invalid \\ 9277\hline 9278 25 & Mismatch in Method of request and the CSEQ header\\ 9279\hline 9280 26 & The method is unknown \\ 9281\hline 9282 27 & The number of dialogs in the stream session exceeds the maximal value. \\ 9283\hline 9284\end{longtable} 9285\subsubsection{Rule Options} 9286New rule options are supported by enabling the \texttt{sip} preprocessor: 9287\begin{itemize} 9288\item[] 9289\begin{verbatim} 9290 sip_method 9291 sip_stat_code 9292 sip_header 9293 sip_body 9294\end{verbatim} 9295\end{itemize} 9296Overload modifiers to existing \texttt{pcre} rule options: 9297\begin{itemize} 9298\item[] H: Match SIP request or SIP response header, Similar to \texttt{sip\_header}. 9299\item[] P: Match SIP request or SIP response body, Similar to \texttt{sip\_body}. 9300\end{itemize} 9301\texttt{sip\_method} 9302\label{sip:sip_method} 9303\begin{itemize} 9304 \item[] The \texttt{sip\_method} keyword is used to check for specific SIP request methods. 9305 The list of methods is: invite, cancel, ack, bye, register, options, refer, 9306 subscribe, update, join, info, message, notify, prack. More than one method 9307 can be specified, via a comma separated list, and are OR'ed together. 9308 It will be applied in fast pattern match if available. If the method used in 9309 this rule is not listed in the preprocessor configuration, it will be added 9310 to the preprocessor configuration for the associated policy.\\ 9311 9312\textit{Syntax} 9313\footnotesize 9314\begin{verbatim} 9315 sip_method:<method-list>; 9316 method-list = method|method, method-list 9317 method = ["!"] "invite"|"cancel"|"ack"|"bye"|"register"| "options"\ 9318 |"refer"|"subscribe"|"update"|"join"|"info"|"message"\ 9319 |"notify"|"prack" 9320 Note: if "!" is used, only one method is allowed in sip_method. 9321\end{verbatim} 9322\normalsize 9323\textit{Examples} 9324\footnotesize 9325\begin{verbatim} 9326 sip_method:invite, cancel 9327 sip_method:!invite 9328 9329 Note: If a user wants to use "and", they can use something like this: 9330 sip_method:!invite; sip_method:!bye 9331\end{verbatim} 9332\normalsize 9333\end{itemize} 9334 9335\texttt{sip\_stat\_code} 9336\label{sip:sip_stat_code} 9337\begin{itemize} 9338 \item[] The \texttt{sip\_stat\_code} is used to check the SIP response status code. This option 9339 matches if any one of the state codes specified matches the status codes of 9340 the SIP response.\\ 9341 9342\textit{Syntax} 9343\footnotesize 9344\begin{verbatim} 9345 sip_stat_code:<code _list> ; 9346 code_list = state_code|state_code, code_list 9347 code = "100-999"|"1-9" 9348\end{verbatim} 9349 \item[] Note: 1,2,3,4,5,6... mean to check for "1xx", "2xx", '3xx', '4xx', '5xx', 9350 '6xx'... responses. \\ 9351\normalsize 9352 9353\textit{Examples} 9354\footnotesize 9355\begin{verbatim} 9356 sip_stat_code:200 9357 sip_stat_code: 2 9358 sip_stat_code: 200, 180 9359\end{verbatim} 9360\normalsize 9361\end{itemize} 9362 9363\texttt{sip\_header} 9364\label{sip:sip_header} 9365\begin{itemize} 9366 \item[] The \texttt{sip\_header} keyword restricts the search to the extracted Header fields of 9367 a SIP message request or a response. This works similar to \texttt{file\_data}. \\ 9368 9369\textit{Syntax} 9370\footnotesize 9371\begin{verbatim} 9372 sip_header; 9373\end{verbatim} 9374\normalsize 9375 9376\textit{Examples} 9377\footnotesize 9378\begin{verbatim} 9379 alert udp any any -> any 5060 (sip_header; content:"CSeq"; ) 9380\end{verbatim} 9381\normalsize 9382\end{itemize} 9383 9384\texttt{sip\_body} 9385\label{sip:sip_body} 9386\begin{itemize} 9387 \item[] The \texttt{sip\_body} keyword places the cursor at the beginning of the Body fields 9388 of a SIP message. This works similar to \texttt{file\_data} and \texttt{dce\_stub\_data}. The message 9389 body includes channel information using SDP protocol (Session Description Protocol).\\ 9390 9391\textit{Syntax} 9392\footnotesize 9393\begin{verbatim} 9394 sip_body; 9395\end{verbatim} 9396\normalsize 9397 9398\textit{Examples} 9399\footnotesize 9400\begin{verbatim} 9401 alert udp any any -> any 5060 (sip_body; content:"C=IN 0.0.0.0"; within 100;) 9402\end{verbatim} 9403\normalsize 9404\end{itemize} 9405\texttt{pcre} 9406\label{sip:pcre} 9407\begin{itemize} 9408 \item[] SIP overloads two options for \texttt{pcre}:\\ 9409\begin{itemize} 9410\item H: Match SIP header for request or response , Similar to \texttt{sip\_header}.\\ 9411\item P: Match SIP body for request or response , Similar to \texttt{sip\_body}.\\ 9412\end{itemize} 9413\textit{Examples} 9414\footnotesize 9415\begin{verbatim} 9416 alert udp any any -> any 5060 (pcre:"/INVITE/H"; sid:1000000;) 9417 alert udp any any -> any 5060 (pcre:"/m=/P"; sid:2000000;) 9418\end{verbatim} 9419\normalsize 9420\end{itemize} 9421 9422\subsection{Reputation Preprocessor} 9423\label{sub:reputation} 9424Reputation preprocessor provides basic IP blacklist/whitelist capabilities, to 9425block/drop/pass traffic from IP addresses listed. In the past, we use standard 9426Snort rules to implement Reputation-based IP blocking. This preprocessor will 9427address the performance issue and make the IP reputation management easier. 9428This preprocessor runs before other preprocessors. 9429\subsubsection{Configuration} 9430The preprocessor configuration name is \texttt{reputation}.\\ 9431 9432\begin{verbatim} 9433 preprocessor reputation 9434\end{verbatim} 9435\textit{Option syntax} 9436\begin{itemize} 9437 9438\item[] 9439\begin{tabular}{|l|c|c|p{6cm}|} 9440\hline 9441Option & Argument & Required & Default\\ 9442\hline 9443\hline 9444\texttt{memcap} & \texttt{<memcap>} & NO & \texttt{memcap 500}\\ 9445\hline 9446\texttt{scan\_local} & NONE & NO & OFF\\ 9447\hline 9448\texttt{blacklist} & \texttt{<list file name>} & NO & NONE\\ 9449\hline 9450\texttt{whitelist} & \texttt{<list file name>} & NO & NONE\\ 9451\hline 9452\texttt{priority} & [blacklist whitelist] & NO & \texttt{priority whitelist}\\ 9453\hline 9454\texttt{nested\_ip} & [inner outer both] & NO & \texttt{nested\_ip inner}\\ 9455\hline 9456\texttt{white} & [unblack trust] & NO & \texttt{white unblack}\\ 9457\hline 9458\end{tabular} 9459\end{itemize} 9460\footnotesize 9461\begin{verbatim} 9462 memcap = 1-4095 Mbytes 9463\end{verbatim} 9464\normalsize 9465\textit{Option explanations} 9466\begin{itemize} 9467 9468\item[] \texttt{memcap} 9469\begin{itemize} 9470\item[] Maximum total memory supported. It can be set up to 4095 Mbytes. 9471\end{itemize} 9472 9473\item[] \texttt{scan\_local} 9474\begin{itemize} 9475\item[] Enable to inspect local address defined in RFC 1918: 9476\begin{itemize} 9477 \item[] 10.0.0.0 - 10.255.255.255 (10/8 prefix) 9478 \item[] 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) 9479 \item[] 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) 9480\end{itemize} 9481\end{itemize} 9482 9483\item[] \texttt{blacklist/whitelist} 9484\begin{itemize} 9485\item[] The IP lists are loaded from external files. It supports relative 9486 paths for inclusion and \$variables for path. Multiple blacklists or 9487 whitelists are supported. 9488 9489 \item[] Note: if the same IP is redefined later, it will overwrite the 9490 previous one. In other words, IP lists always favors the last file or 9491 entry processed. 9492\end{itemize} 9493 9494\item[] \texttt{priority} 9495\begin{itemize} 9496\item[] Specify either blacklist or whitelist has higher priority when 9497 source/destination is on blacklist while destination/source is on 9498 whitelist. By default, whitelist has higher priority. In other words, 9499 the packet will be passed when either source or destination is 9500 whitelisted. 9501 9502\item[] Note: this only defines priority when there is a decision conflict, 9503 during run-time. During initialization time, if the same IP address 9504 is defined in whitelist and blacklist, whoever the last one defined 9505 will be the final one. Priority does not work on this case. 9506\end{itemize} 9507 9508\item[] \texttt{nested\_ip} 9509\begin{itemize} 9510\item[] Specify which IP address to be used when there is IP 9511 encapsulation. 9512\end{itemize} 9513 9514\item[] \texttt{white} 9515\begin{itemize} 9516\item[] Specify the meaning of whitelist. When white means unblack, it 9517 unblacks IPs that are in blacklists; when white means trust, the 9518 packet gets bypassed, without further detection by snort. You can 9519 only specify either unblack or trust. 9520 9521 \item[] Note: when white means unblack, whitelist always has higher priority 9522 than blacklist. 9523\end{itemize} 9524 9525\end{itemize} 9526 9527\textit{Configuration examples} 9528\footnotesize 9529\begin{verbatim} 9530 preprocessor reputation:\ 9531 blacklist /etc/snort/default.blacklist, \ 9532 whitelist /etc/snort/default.whitelist 9533 9534 preprocessor reputation: \ 9535 nested_ip both, \ 9536 blacklist /etc/snort/default.blacklist, \ 9537 whitelist /etc/snort/default.whitelist 9538 9539 preprocessor reputation: \ 9540 memcap 4095, scan_local, nested_ip both, \ 9541 priority whitelist, \ 9542 blacklist /etc/snort/default.blacklist, \ 9543 whitelist /etc/snort/default.whitelist, 9544 white trust 9545 9546 $REP_BLACK_FILE1 = ../dshield.list 9547 $REP_BLACK_FILE2 = ../snort.org.list 9548 preprocessor reputation: \ 9549 blacklist $REP_BLACK_FILE1,\ 9550 blacklist $REP_BLACK_FILE2 9551 9552\end{verbatim} 9553\normalsize 9554\textit{IP List File Format} 9555\begin{itemize} 9556 9557\item[] \texttt{Syntax} 9558\begin{itemize} 9559\item[] The IP list file has 1 entry per line. The entry can be either IP entry or 9560 comment. 9561\end{itemize} 9562 9563\begin{itemize} 9564\item[] \texttt{IP Entry} 9565\begin{itemize} 9566\item[] CIDR notation $<$comments$>$ line break. 9567\item[] Example: 9568\footnotesize 9569\begin{verbatim} 9570 172.16.42.32/32 9571 172.33.42.32/16 9572\end{verbatim} 9573\normalsize 9574\end{itemize} 9575 9576\item[] \texttt{Comment} 9577\begin{itemize} 9578\item[] The comment start with \# 9579\item[] \# $<$comments$>$ 9580\item[] Example 9581\footnotesize 9582\begin{verbatim} 9583 # This is a full line comment 9584 172.33.42.32/16 # This is a in-line comment 9585\end{verbatim} 9586\normalsize 9587\end{itemize} 9588 9589\end{itemize} 9590 9591\item[] \texttt{IP List File Example} 9592\begin{itemize} 9593 9594\item[] 9595\footnotesize 9596\begin{verbatim} 9597 # This is a full line comment 9598 172.16.42.32/32 # This is an inline comment, line with single CIDR block 9599 172.33.42.32/16 9600\end{verbatim} 9601\normalsize 9602\end{itemize} 9603\end{itemize} 9604 9605\textit{Use case} 9606\begin{itemize} 9607 \item[] A user wants to protect his/her network from unwanted/unknown IPs, only allowing 9608 some trusted IPs. Here is the configuration: 9609\item[] \footnotesize 9610\begin{verbatim} 9611 preprocessor reputation: \ 9612 blacklist /etc/snort/default.blacklist 9613 whitelist /etc/snort/default.whitelist 9614 9615 In file "default.blacklist" 9616 # These two entries will match all ipv4 addresses 9617 1.0.0.0/1 9618 128.0.0.0/1 9619 9620 In file "default.whitelist" 9621 68.177.102.22 # sourcefire.com 9622 74.125.93.104 # google.com 9623\end{verbatim} 9624\end{itemize} 9625\normalsize 9626 9627\subsubsection{Events} 9628Reputation preprocessor uses GID 136 to register events. 9629\begin{longtable}{|r|p{13.5cm}|} 9630 9631\hline 9632SID & Description\\ 9633\hline 9634 1 & Packet is blacklisted. \\ 9635\hline 9636 2 & Packet is whitelisted. \\ 9637\hline 9638 3 & Packet is inspected. \\ 9639\hline 9640\end{longtable} 9641\subsubsection{Shared memory support} 9642 9643\begin{itemize} 9644 \item[] 9645 In order to minimize memory consumption when multiple Snort instances are 9646 running concurrently, we introduce the support of shared memory. After 9647 configured, all the snort instances share the same IP tables in shared memory. 9648 9649 \item[]\textit{System requirement} 9650\begin{itemize} 9651 \item[]This feature is supported only in Linux. 9652\end{itemize} 9653 9654 \item[]\textit{Build configuration} 9655 9656 \begin{itemize} \item[]A new option, \texttt{--enable-shared-rep} is introduced to 9657 \texttt{./configure} command. 9658 This option enables the support for shared memory. 9659\end{itemize} 9660 \item[]\textit{Configuration} 9661 9662\begin{itemize} 9663 9664 \item[]\texttt{shared\_mem} 9665\begin{itemize} 9666 9667 \item[] If the build supports shared memory, this configuration will enable shared 9668 memory. If this option isn't set, standard memory is used. This option must 9669 specify a path or directory where IP lists will be loaded in shared memory. 9670 One snort instance will create and maintain the shared IP lists. 9671 We use instance ID 1, specified in the snort \texttt{-G} option to be the master snort. 9672 All the other snort instances are clients (readers). 9673 9674 \item[] \textit{Syntax} 9675 \begin{verbatim} 9676 shared_mem: path 9677 \end{verbatim} 9678 \item[] \textit{Examples} 9679 \begin{verbatim} 9680 shared_mem /user/reputation/iplists 9681 \end{verbatim} 9682\end{itemize} 9683 \item[]\texttt{shared\_refresh} 9684 9685\begin{itemize} 9686 \item[]This option changes the period of checking new shared memory segment, in the unit of second. 9687 By default, the refresh rate is $60$ seconds. 9688 9689 \item[]\textit{Syntax} 9690 \begin{verbatim} 9691 shared_refresh <period> 9692 period = "1 - 4294967295" 9693 \end{verbatim} 9694 \item[]\textit{Examples} 9695 \begin{verbatim} 9696 shared_refresh 60 9697 \end{verbatim} 9698\end{itemize} 9699\end{itemize} 9700 9701 \item[]\textit{Steps to configure shared memory} 9702 9703\begin{itemize} 9704 9705 \item When building Snort, add option \texttt{--enable-shared-rep} to \texttt{./configure}\\ 9706 For example: 9707 \begin{verbatim} 9708 ./configure --enable-gre --enable-sourcefire --enable-flexresp3 9709 --enable-pthread --enable-linux-smp-stats 9710 --enable-targetbased --enable-shared-rep --enable-control-socket 9711 \end{verbatim} 9712 \item Put your IP list file into a directory, where snort has full access. \\ 9713 For example: 9714 9715 \begin{verbatim} 9716 /user/reputation/iplists 9717 \end{verbatim} 9718 9719 In order to separate whitelist with blacklist, you need to specify 9720 whitelist with \texttt{.wlf} extension and blacklist with \texttt{.blf} extension. 9721 \item In snort config file, specify shared memory support with the path to IP files.\\ 9722 For example: 9723 9724 \begin{verbatim} 9725 shared_mem /user/reputation/iplists 9726 \end{verbatim} 9727 9728 If you want to change the period of checking new IP lists, add refresh period.\\ 9729 For example: 9730 9731 \begin{verbatim} 9732 shared_refresh 300 9733 \end{verbatim} 9734 9735 \item Start shared memory master(writer) with \texttt{-G} 0 option. Note: only one master 9736 should be enabled. 9737 \item Start shared memory clients (readers) with \texttt{-G} 1 or other IDs. Note: for 9738 one ID, only one snort instance should be enabled. 9739 \item You will see the IP lists got loaded and shared across snort instances! 9740\end{itemize} 9741 9742 \item[]\textit{Reload IP lists using control socket} 9743\begin{itemize} 9744 \item Run snort using command line with option \texttt{--cs-dir <path>} 9745 or configure snort with: 9746 \begin{verbatim} 9747 config cs_dir:<path> 9748 \end{verbatim} 9749 \item (Optional) you can create a version file named ``IPRVersion.dat'' in the IP list 9750 directory. This file helps managing reloading IP lists, by specifying a version. 9751 When the version isn't changed, IP lists will not be reloaded if they are 9752 already in shared memory. The version number should be a 32 bit number.\\ 9753 For example: 9754 \begin{verbatim} 9755 VERSION=1 9756 \end{verbatim} 9757 \item In the \texttt{<snort root>/src/tools/control} directory, you will find \texttt{snort\_control} command if 9758 built with \texttt{--enable-control-socket} option. 9759 \item Type the following command to reload IP lists. Before typing this command, 9760 make sure to update version file if you are using version file. 9761 The \texttt{<path>} is the same path in first step.\\ 9762 \begin{verbatim} 9763 <snort root>/src/tools/control/snort_control <path> 1361 9764 \end{verbatim} 9765\end{itemize} 9766 \item[]\textit{Using manifest file to manage loading (optional)} 9767\begin{itemize} 9768 \item[] Using manifest file, you can control the file loading sequence, action taken, 9769 and support zone based detection. You can create a manifest file named ``zone.info'' 9770 in the IP list directory.\\ 9771 9772 \item[] When Snort is signaled to load new lists, a manifest file is read first to 9773 determine which zones the IPs in each list are applicable to and what action 9774 to take per list (Block, White, Monitor). \\ 9775 9776 \item[] Files listed in manifest are loaded from top to bottom. You should put files 9777 that have higher priority first. In manifest file, you can put up to 255 9778 files. Without manifest file, files will be loaded in alphabet order.\\ 9779 9780 \item[] Here's the format of the manifest file. Each line of the file has the 9781 following format:\\ 9782 \begin{verbatim} 9783 <filename>, <list id>,<action>[, <zone>]+ 9784 9785 <list id> ::= 32 bit integer 9786 <action> ::= "monitor"|"block"|"white" 9787 <zone> ::= [0-1051] 9788 \end{verbatim} 9789 9790 \item[] Using manifest file, you can specify a new action called ``monitor'', which 9791 indicates a packet needs to be inspected, but does not disable detection. This is 9792 different from ``block'' action, which disables further detection. This new 9793 action helps users evaluate their IP lists before applying it. 9794 \item[] An example manifest file: 9795 \begin{verbatim} 9796 #ipreputation manifest file 9797 white.wlf, 111 ,white, 9798 black1.blf, 1112, black, 3, 12 9799 black2.blf, 1113, black, 3, 12 9800 monitor.blf,2222, monitor, 0, 2, 8 9801 \end{verbatim} 9802\end{itemize} 9803\end{itemize} 9804\subsection{GTP Decoder and Preprocessor} 9805\label{sub:gtp} 9806GTP (GPRS Tunneling Protocol) is used in core communication networks to establish 9807a channel between GSNs (GPRS Serving Node). GTP decoding preprocessor provides 9808ways to tackle intrusion attempts to those networks through GTP. It also makes 9809detecting new attacks easier. 9810 9811Two components are developed: GTP decoder and GTP preprocessor. 9812\begin{itemize} 9813\item GTP decoder extracts payload inside GTP PDU; 9814\item GTP preprocessor inspects all the signaling messages and provide keywords for 9815further inspection 9816\end{itemize} 9817 9818When the decoder is enabled and configured, the decoder strips the GTP headers 9819and parses the underlying IP/TCP/UDP encapsulated packets. Therefore all rules 9820and detection work as if there was no GTP header. 9821 9822Example: 9823 9824\begin{itemize} 9825\item[] 9826Most GTP packets look like this 9827\begin{verbatim} 9828IP -> UDP -> GTP -> IP -> TCP -> HTTP 9829\end{verbatim} 9830 9831If you had a standard HTTP rule: 9832\begin{verbatim} 9833alert tcp any any -> any $HTTP_PORTS (msg:"Test HTTP"; flow:to_server,established; 9834content:"SOMETHINGEVIL"; http_uri; .... sid:X; rev:Y;) 9835\end{verbatim} 9836it would alert on the inner HTTP data that is encapsulated in GTP without any changes 9837 to the rule other than enabling and configuring the GTP decoder. 9838\end{itemize} 9839 9840\subsubsection{Dependency Requirements} 9841 9842For proper functioning of the preprocessor: 9843\begin{itemize} 9844 9845\item Stream session tracking must be enabled, i.e. stream5. UDP must be 9846 enabled in stream5. The preprocessor requires a session tracker to keep its 9847 data. 9848 9849\item IP defragmentation should be enabled, i.e. the frag3 preprocessor should be 9850 enabled and configured. 9851 9852\end{itemize} 9853 9854\subsubsection{GTP Data Channel Decoder Configuration} 9855GTP decoder extracts payload from GTP PDU. The following configuration sets 9856GTP decoding: 9857\begin{verbatim} 9858config enable_gtp 9859\end{verbatim} 9860By default, GTP decoder uses port number $2152$ (GTPv1) and $3386$ (GTPv0). 9861If users want to change those values, they can use \texttt{portvar GTP\_PORTS}: 9862 9863\begin{verbatim} 9864portvar GTP_PORTS [2152,3386] 9865\end{verbatim} 9866 9867\subsubsection{GTP Control Channel Preprocessor Configuration} 9868 9869Different from GTP decoder, GTP preprocessor examines all signaling messages. 9870The preprocessor configuration name is \texttt{gtp}. 9871\begin{verbatim} 9872preprocessor gtp 9873\end{verbatim} 9874\textit{Option syntax} 9875\begin{itemize} 9876\item[] 9877\begin{tabular}{|l|c|c|p{6cm}|} 9878\hline 9879Option & Argument & Required & Default\\ 9880\hline 9881\hline 9882\texttt{ports} & \texttt{<ports>} & NO & \texttt{ports \{ 2123 3386 \} }\\ 9883\hline 9884\end{tabular} 9885\end{itemize} 9886\normalsize 9887\textit{Option explanations} 9888\begin{itemize} 9889\item[] \texttt{ports} 9890\begin{itemize} 9891\item[] This specifies on what ports to check for GTP messages. Typically, 9892 this will include 2123, 3386. 9893\item[] \textit{Syntax} 9894\begin{verbatim} 9895 ports { <port> [<port>< ... >] } 9896\end{verbatim} 9897\item[] \textit{Examples} 9898\begin{verbatim} 9899 ports { 2123 3386 2152 } 9900\end{verbatim} 9901\item[] Note: there are spaces before and after `\{' and `\}'. 9902\end{itemize} 9903\end{itemize} 9904\normalsize 9905 9906\textit{Default configuration} 9907\footnotesize 9908\begin{verbatim} 9909 preprocessor gtp 9910\end{verbatim} 9911\normalsize 9912\subsubsection{GTP Decoder Events} 9913\begin{longtable}{|r|p{13.5cm}|} 9914\hline 9915SID & Description\\ 9916\hline 9917 297 & Two or more GTP encapsulation layers present \\ 9918\hline 9919 298 & GTP header length is invalid \\ 9920\hline 9921\end{longtable} 9922 9923\subsubsection{GTP Preprocessor Events} 9924\begin{longtable}{|r|p{13.5cm}|} 9925\hline 9926SID & Description\\ 9927\hline 9928 1 & Message length is invalid. \\ 9929\hline 9930 2 & Information element length is invalid. \\ 9931\hline 9932 3 & Information elements are out of order. \\ 9933\hline 9934\end{longtable} 9935\subsubsection{Rule Options} 9936New rule options are supported by enabling the \texttt{gtp} preprocessor: 9937\begin{itemize} 9938\item[] 9939\begin{verbatim} 9940 gtp_type 9941 gtp_info 9942 gtp_version 9943\end{verbatim} 9944\end{itemize} 9945 9946\texttt{gtp\_type} 9947\label{gtp:gtp_method} 9948\begin{itemize} 9949 \item[] The \texttt{gtp\_type} keyword is used to check for specific GTP types. 9950 User can input message type value, an integer in [0, 255], or a string defined 9951 in the Table below. More than one type can be specified, via a comma separated 9952 list, and are OR'ed together. If the type used in a rule is not listed in the 9953 preprocessor configuration, an error will be thrown. 9954 9955 \item[] A message type can have different type value in different GTP 9956 versions. For example, \texttt{sgsn\_\-context\_\-request} has message type 9957 value $50$ in GTPv0 and GTPv1, but $130$ in GTPv2. \texttt{gtp\_type} will 9958 match to a different value depending on the version number in the packet. 9959 In this example, evaluating a GTPv0 or GTPv1 packet will check whether the 9960 message type value is $50$; evaluating a GTPv2 packet will check whether the 9961 message type value is $130$. When a message type is not defined in a version, 9962 any packet in that version will always return ``No match''. 9963 9964 \item[] If an integer is used to specify message type, every GTP packet is 9965 evaluated, no matter what version the packet is. If the message type matches 9966 the value in packet, it will return ``Match''. \\ 9967 9968\textit{Syntax} 9969\footnotesize 9970\begin{verbatim} 9971 gtp_type:<type-list>; 9972 type-list = type|type, type-list 9973 type = "0-255"| 9974 | "echo_request" | "echo_response" ... 9975\end{verbatim} 9976\normalsize 9977\textit{Examples} 9978\footnotesize 9979\begin{verbatim} 9980 gtp_type:10, 11, echo_request; 9981\end{verbatim} 9982\normalsize 9983 9984\textit{GTP message types} 9985\small 9986\begin{longtable}{|r|c|c|c|p{13.5cm}|} 9987\hline 9988Type & GTPv0 & GTPv1 & GTPv2\\ 9989\hline 99900 & N/A & N/A & N/A\\ 9991\hline 99921 & echo\_request & echo\_request & echo\_request\\ 9993\hline 99942 & echo\_response & echo\_response & echo\_response\\ 9995\hline 99963 & version\_not\_supported & version\_not\_supported & version\_not\_supported\\ 9997\hline 99984 & node\_alive\_request & node\_alive\_request & N/A\\ 9999\hline 100005 & node\_alive\_response & node\_alive\_response & N/A\\ 10001\hline 100026 & redirection\_request & redirection\_request & N/A\\ 10003\hline 100047 & redirection\_response & redirection\_response & N/A \\ 10005\hline 1000616 & create\_pdp\_context\_request & create\_pdp\_context\_request & N/A\\ 10007\hline 1000817 & create\_pdp\_context\_response & create\_pdp\_context\_response & N/A \\ 10009\hline 1001018 & update\_pdp\_context\_request & update\_pdp\_context\_request & N/A\\ 10011\hline 1001219 & update\_pdp\_context\_response & update\_pdp\_context\_response & N/A\\ 10013\hline 1001420 & delete\_pdp\_context\_request & delete\_pdp\_context\_request & N/A\\ 10015\hline 1001621 & delete\_pdp\_context\_response & delete\_pdp\_context\_response & N/A\\ 10017\hline 1001822 & create\_aa\_pdp\_context\_request & init\_pdp\_context\_activation\_request & N/A\\ 10019\hline 1002023 & create\_aa\_pdp\_context\_response & init\_pdp\_context\_activation\_response & N/A\\ 10021\hline 1002224 & delete\_aa\_pdp\_context\_request & N/A & N/A\\ 10023\hline 1002425 & delete\_aa\_pdp\_context\_response & N/A & N/A\\ 10025\hline 1002626 & error\_indication & error\_indication & N/A\\ 10027\hline 1002827 & pdu\_notification\_request & pdu\_notification\_request & N/A\\ 10029\hline 1003028 & pdu\_notification\_response & pdu\_notification\_response & N/A\\ 10031\hline 1003229 & pdu\_notification\_reject\_request & pdu\_notification\_reject\_request & N/A\\ 10033\hline 1003430 & pdu\_notification\_reject\_response & pdu\_notification\_reject\_response & N/A\\ 10035\hline 1003631 & N/A & supported\_ext\_header\_notification & N/A \\ 10037\hline 1003832 & send\_routing\_info\_request & send\_routing\_info\_request & create\_session\_request \\ 10039\hline 1004033 & send\_routing\_info\_response & send\_routing\_info\_response & create\_session\_response \\ 10041\hline 1004234 & failure\_report\_request & failure\_report\_request & modify\_bearer\_request \\ 10043\hline 1004435 & failure\_report\_response & failure\_report\_response & modify\_bearer\_response \\ 10045\hline 1004636 & note\_ms\_present\_request & note\_ms\_present\_request & delete\_session\_request \\ 10047\hline 1004837 & note\_ms\_present\_response & note\_ms\_present\_response & delete\_session\_response \\ 10049\hline 1005038 & N/A & N/A & change\_notification\_request \\ 10051\hline 1005239 & N/A & N/A & change\_notification\_response \\ 10053\hline 1005448 & identification\_request & identification\_request & N/A \\ 10055\hline 1005649 & identification\_response & identification\_response & N/A \\ 10057\hline 1005850 & sgsn\_context\_request & sgsn\_context\_request & N/A \\ 10059\hline 1006051 & sgsn\_context\_response & sgsn\_context\_response & N/A \\ 10061\hline 1006252 & sgsn\_context\_ack & sgsn\_context\_ack & N/A \\ 10063\hline 1006453 & N/A & forward\_relocation\_request & N/A \\ 10065\hline 1006654 & N/A & forward\_relocation\_response & N/A \\ 10067\hline 1006855 & N/A & forward\_relocation\_complete & N/A \\ 10069\hline 1007056 & N/A & relocation\_cancel\_request & N/A \\ 10071\hline 1007257 & N/A & relocation\_cancel\_response & N/A \\ 10073\hline 1007458 & N/A & forward\_srns\_contex & N/A \\ 10075\hline 1007659 & N/A & forward\_relocation\_complete\_ack & N/A \\ 10077\hline 1007860 & N/A & forward\_srns\_contex\_ack & N/A \\ 10079\hline 1008064 & N/A & N/A & modify\_bearer\_command \\ 10081\hline 1008265 & N/A & N/A & modify\_bearer\_failure\_indication \\ 10083\hline 1008466 & N/A & N/A & delete\_bearer\_command \\ 10085\hline 1008667 & N/A & N/A & delete\_bearer\_failure\_indication \\ 10087\hline 1008868 & N/A & N/A & bearer\_resource\_command \\ 10089\hline 1009069 & N/A & N/A & bearer\_resource\_failure\_indication \\ 10091\hline 1009270 & N/A & ran\_info\_relay & downlink\_failure\_indication \\ 10093\hline 1009471 & N/A & N/A & trace\_session\_activation \\ 10095\hline 1009672 & N/A & N/A & trace\_session\_deactivation \\ 10097\hline 1009873 & N/A & N/A & stop\_paging\_indication \\ 10099\hline 1010095 & N/A & N/A & create\_bearer\_request \\ 10101\hline 1010296 & N/A & mbms\_notification\_request & create\_bearer\_response \\ 10103\hline 1010497 & N/A & mbms\_notification\_response & update\_bearer\_request \\ 10105\hline 1010698 & N/A & mbms\_notification\_reject\_request & update\_bearer\_response \\ 10107\hline 1010899 & N/A & mbms\_notification\_reject\_response & delete\_bearer\_request \\ 10109\hline 10110100 & N/A & create\_mbms\_context\_request & delete\_bearer\_response \\ 10111\hline 10112101 & N/A & create\_mbms\_context\_response & delete\_pdn\_request \\ 10113\hline 10114102 & N/A & update\_mbms\_context\_request & delete\_pdn\_response \\ 10115\hline 10116103 & N/A & update\_mbms\_context\_response & N/A \\ 10117\hline 10118104 & N/A & delete\_mbms\_context\_request & N/A \\ 10119\hline 10120105 & N/A & delete\_mbms\_context\_response & N/A \\ 10121\hline 10122112 & N/A & mbms\_register\_request & N/A \\ 10123\hline 10124113 & N/A & mbms\_register\_response & N/A \\ 10125\hline 10126114 & N/A & mbms\_deregister\_request & N/A \\ 10127\hline 10128115 & N/A & mbms\_deregister\_response & N/A \\ 10129\hline 10130116 & N/A & mbms\_session\_start\_request & N/A \\ 10131\hline 10132117 & N/A & mbms\_session\_start\_response & N/A \\ 10133\hline 10134118 & N/A & mbms\_session\_stop\_request & N/A \\ 10135\hline 10136119 & N/A & mbms\_session\_stop\_response & N/A \\ 10137\hline 10138120 & N/A & mbms\_session\_update\_request & N/A \\ 10139\hline 10140121 & N/A & mbms\_session\_update\_response & N/A \\ 10141\hline 10142128 & N/A & ms\_info\_change\_request & identification\_request \\ 10143\hline 10144129 & N/A & ms\_info\_change\_response & identification\_response \\ 10145\hline 10146130 & N/A & N/A & sgsn\_context\_request \\ 10147\hline 10148131 & N/A & N/A & sgsn\_context\_response \\ 10149\hline 10150132 & N/A & N/A & sgsn\_context\_ack \\ 10151\hline 10152133 & N/A & N/A & forward\_relocation\_request \\ 10153\hline 10154134 & N/A & N/A & forward\_relocation\_response \\ 10155\hline 10156135 & N/A & N/A & forward\_relocation\_complete \\ 10157\hline 10158136 & N/A & N/A & forward\_relocation\_complete\_ack \\ 10159\hline 10160137 & N/A & N/A & forward\_access \\ 10161\hline 10162138 & N/A & N/A & forward\_access\_ack \\ 10163\hline 10164139 & N/A & N/A & relocation\_cancel\_request \\ 10165\hline 10166140 & N/A & N/A & relocation\_cancel\_response \\ 10167\hline 10168141 & N/A & N/A & configuration\_transfer\_tunnel \\ 10169\hline 10170149 & N/A & N/A & detach \\ 10171\hline 10172150 & N/A & N/A & detach\_ack \\ 10173\hline 10174151 & N/A & N/A & cs\_paging \\ 10175\hline 10176152 & N/A & N/A & ran\_info\_relay \\ 10177\hline 10178153 & N/A & N/A & alert\_mme \\ 10179\hline 10180154 & N/A & N/A & alert\_mme\_ack \\ 10181\hline 10182155 & N/A & N/A & ue\_activity \\ 10183\hline 10184156 & N/A & N/A & ue\_activity\_ack \\ 10185\hline 10186160 & N/A & N/A & create\_forward\_tunnel\_request \\ 10187\hline 10188161 & N/A & N/A & create\_forward\_tunnel\_response \\ 10189\hline 10190162 & N/A & N/A & suspend \\ 10191\hline 10192163 & N/A & N/A & suspend\_ack \\ 10193\hline 10194164 & N/A & N/A & resume \\ 10195\hline 10196165 & N/A & N/A & resume\_ack \\ 10197\hline 10198166 & N/A & N/A & create\_indirect\_forward\_tunnel\_request \\ 10199\hline 10200167 & N/A & N/A & create\_indirect\_forward\_tunnel\_response \\ 10201\hline 10202168 & N/A & N/A & delete\_indirect\_forward\_tunnel\_request \\ 10203\hline 10204169 & N/A & N/A & delete\_indirect\_forward\_tunnel\_response \\ 10205\hline 10206170 & N/A & N/A & release\_access\_bearer\_request \\ 10207\hline 10208171 & N/A & N/A & release\_access\_bearer\_response \\ 10209\hline 10210176 & N/A & N/A & downlink\_data \\ 10211\hline 10212177 & N/A & N/A & downlink\_data\_ack \\ 10213\hline 10214178 & N/A & N/A & N/A \\ 10215\hline 10216179 & N/A & N/A & pgw\_restart \\ 10217\hline 10218199 & N/A & N/A & pgw\_restart\_ack \\ 10219\hline 10220200 & N/A & N/A & update\_pdn\_request \\ 10221\hline 10222201 & N/A & N/A & update\_pdn\_response \\ 10223\hline 10224211 & N/A & N/A & modify\_access\_bearer\_request \\ 10225\hline 10226212 & N/A & N/A & modify\_access\_bearer\_response \\ 10227\hline 10228231 & N/A & N/A & mbms\_session\_start\_request \\ 10229\hline 10230232 & N/A & N/A & mbms\_session\_start\_response \\ 10231\hline 10232233 & N/A & N/A & mbms\_session\_update\_request \\ 10233\hline 10234234 & N/A & N/A & mbms\_session\_update\_response \\ 10235\hline 10236235 & N/A & N/A & mbms\_session\_stop\_request \\ 10237\hline 10238236 & N/A & N/A & mbms\_session\_stop\_response \\ 10239\hline 10240240 & data\_record\_transfer\_request & data\_record\_transfer\_request & N/A \\ 10241\hline 10242241 & data\_record\_transfer\_response & data\_record\_transfer\_response & N/A \\ 10243\hline 10244254 & N/A & end\_marker & N/A \\ 10245\hline 10246255 & pdu & pdu & N/A \\ 10247\hline 10248\end{longtable} 10249\end{itemize} 10250 10251\texttt{gtp\_info} 10252\label{gtp:gtp_info} 10253\begin{itemize} 10254\item[] The \texttt{gtp\_info} keyword is used to check for specific GTP 10255 information element. This keyword restricts the search to the information 10256 element field. User can input information element value, an integer in 10257 $[0, 255]$, or a string defined in the Table below. If the information 10258 element used in this rule is not listed in the preprocessor configuration, 10259 an error will be thrown. 10260 10261\item[] When there are several information elements with the same type in the 10262 message, this keyword restricts the search to the total consecutive buffer. 10263 Because the standard requires same types group together, this feature will be 10264 available for all valid messages. In the case of ``out of order information 10265 elements'', this keyword restricts the search to the last buffer. 10266 10267\item[] Similar to message type, same information element might have different 10268 information element value in different GTP versions. For example, 10269 \texttt{cause} has value $1$ in GTPv0 and GTPv1, but $2$ in GTPv2. 10270 \texttt{gtp\_info} will match to a different 10271 value depending on the version number in the packet. When an information 10272 element is not defined in a version, any packet in that version will always 10273 return ``No match''. 10274 10275 If an integer is used to specify information element type, every GTP packet 10276 is evaluated, no matter what version the packet is. If the message type 10277 matches the value in packet, it will return ``Match''.\\ 10278 10279\textit{Syntax} 10280\footnotesize 10281\begin{verbatim} 10282 gtp_info:<ie>; 10283 ie = "0-255"| 10284 "rai" | "tmsi"... 10285\end{verbatim} 10286\normalsize 10287\textit{Examples} 10288\footnotesize 10289\begin{verbatim} 10290 gtp_info: 16; 10291 gtp_info: tmsi 10292\end{verbatim} 10293\normalsize 10294\textit{GTP information elements} 10295\small 10296\begin{longtable}{|r|c|c|c|p{13.5cm}|} 10297\hline 10298Type & GTPv0 & GTPv1 & GTPv2\\ 10299\hline 103000 & N/A & N/A & N/A \\ 10301\hline 103021 & cause & cause & imsi\\ 10303\hline 103042 & imsi & imsi & cause \\ 10305\hline 103063 & rai & rai & recovery\\ 10307\hline 103084 & tlli & tlli & N/A\\ 10309\hline 103105 & p\_tmsi & p\_tmsi & N/A\\ 10311\hline 103126 & qos & N/A & N/A\\ 10313\hline 103147 & N/A & N/A & N/A \\ 10315\hline 103168 & recording\_required & recording\_required & N/A\\ 10317\hline 103189 & authentication & authentication & N/A\\ 10319\hline 1032010 & N/A & N/A & N/A\\ 10321\hline 1032211 & map\_cause & map\_cause & N/A\\ 10323\hline 1032412 & p\_tmsi\_sig & p\_tmsi\_sig & N/A\\ 10325\hline 1032613 & ms\_validated & ms\_validated & N/A\\ 10327\hline 1032814 & recovery & recovery & N/A\\ 10329\hline 1033015 & selection\_mode & selection\_mode & N/A\\ 10331\hline 1033216 & flow\_label\_data\_1 & teid\_1 & N/A\\ 10333\hline 1033417 & flow\_label\_signalling & teid\_control & N/A\\ 10335\hline 1033618 & flow\_label\_data\_2 & teid\_2 & N/A\\ 10337\hline 1033819 & ms\_unreachable & teardown\_ind & N/A\\ 10339\hline 1034020 & N/A & nsapi & N/A\\ 10341\hline 1034221 & N/A & ranap & N/A\\ 10343\hline 1034422 & N/A & rab\_context & N/A\\ 10345\hline 1034623 & N/A & radio\_priority\_sms & N/A\\ 10347\hline 1034824 & N/A & radio\_priority & N/A\\ 10349\hline 1035025 & N/A & packet\_flow\_id & N/A\\ 10351\hline 1035226 & N/A & charging\_char & N/A\\ 10353\hline 1035427 & N/A & trace\_ref & N/A\\ 10355\hline 1035628 & N/A & trace\_type & N/A\\ 10357\hline 1035829 & N/A & ms\_unreachable & N/A\\ 10359\hline 1036071 & N/A & N/A & apn\\ 10361\hline 1036272 & N/A & N/A & ambr\\ 10363\hline 1036473 & N/A & N/A & ebi\\ 10365\hline 1036674 & N/A & N/A & ip\_addr\\ 10367\hline 1036875 & N/A & N/A & mei\\ 10369\hline 1037076 & N/A & N/A & msisdn\\ 10371\hline 1037277 & N/A & N/A & indication\\ 10373\hline 1037478 & N/A & N/A & pco\\ 10375\hline 1037679 & N/A & N/A & paa\\ 10377\hline 1037880 & N/A & N/A & bearer\_qos\\ 10379\hline 1038081 & N/A & N/A & flow\_qos\\ 10381\hline 1038282 & N/A & N/A & rat\_type\\ 10383\hline 1038483 & N/A & N/A & serving\_network\\ 10385\hline 1038684 & N/A & N/A & bearer\_tft\\ 10387\hline 1038885 & N/A & N/A & tad\\ 10389\hline 1039086 & N/A & N/A & uli\\ 10391\hline 1039287 & N/A & N/A & f\_teid\\ 10393\hline 1039488 & N/A & N/A & tmsi\\ 10395\hline 1039689 & N/A & N/A & cn\_id\\ 10397\hline 1039890 & N/A & N/A & s103pdf\\ 10399\hline 1040091 & N/A & N/A & s1udf\\ 10401\hline 1040292 & N/A & N/A & delay\_value\\ 10403\hline 1040493 & N/A & N/A & bearer\_context\\ 10405\hline 1040694 & N/A & N/A & charging\_id\\ 10407\hline 1040895 & N/A & N/A & charging\_char\\ 10409\hline 1041096 & N/A & N/A & trace\_info\\ 10411\hline 1041297 & N/A & N/A & bearer\_flag\\ 10413\hline 1041498 & N/A & N/A & N/A\\ 10415\hline 1041699 & N/A & N/A & pdn\_type\\ 10417\hline 10418100 & N/A & N/A & pti\\ 10419\hline 10420101 & N/A & N/A & drx\_parameter\\ 10421\hline 10422102 & N/A & N/A & N/A\\ 10423\hline 10424103 & N/A & N/A & gsm\_key\_tri\\ 10425\hline 10426104 & N/A & N/A & umts\_key\_cipher\_quin\\ 10427\hline 10428105 & N/A & N/A & gsm\_key\_cipher\_quin\\ 10429\hline 10430106 & N/A & N/A & umts\_key\_quin\\ 10431\hline 10432107 & N/A & N/A & eps\_quad\\ 10433\hline 10434108 & N/A & N/A & umts\_key\_quad\_quin\\ 10435\hline 10436109 & N/A & N/A & pdn\_connection\\ 10437\hline 10438110 & N/A & N/A & pdn\_number\\ 10439\hline 10440111 & N/A & N/A & p\_tmsi\\ 10441\hline 10442112 & N/A & N/A & p\_tmsi\_sig\\ 10443\hline 10444113 & N/A & N/A & hop\_counter\\ 10445\hline 10446114 & N/A & N/A & ue\_time\_zone\\ 10447\hline 10448115 & N/A & N/A & trace\_ref\\ 10449\hline 10450116 & N/A & N/A & complete\_request\_msg\\ 10451\hline 10452117 & N/A & N/A & guti\\ 10453\hline 10454118 & N/A & N/A & f\_container\\ 10455\hline 10456119 & N/A & N/A & f\_cause\\ 10457\hline 10458120 & N/A & N/A & plmn\_id\\ 10459\hline 10460121 & N/A & N/A & target\_id\\ 10461\hline 10462122 & N/A & N/A & N/A\\ 10463\hline 10464123 & N/A & N/A & packet\_flow\_id\\ 10465\hline 10466124 & N/A & N/A & rab\_contex\\ 10467\hline 10468125 & N/A & N/A & src\_rnc\_pdcp\\ 10469\hline 10470126 & N/A & N/A & udp\_src\_port\\ 10471\hline 10472127 & charge\_id & charge\_id & apn\_restriction\\ 10473\hline 10474128 & end\_user\_address & end\_user\_address & selection\_mode\\ 10475\hline 10476129 & mm\_context & mm\_context & src\_id\\ 10477\hline 10478130 & pdp\_context & pdp\_context & N/A\\ 10479\hline 10480131 & apn & apn & change\_report\_action\\ 10481\hline 10482132 & protocol\_config & protocol\_config & fq\_csid\\ 10483\hline 10484133 & gsn & gsn & channel\\ 10485\hline 10486134 & msisdn & msisdn & emlpp\_pri\\ 10487\hline 10488135 & N/A & qos & node\_type\\ 10489\hline 10490136 & N/A & authentication\_qu & fqdn\\ 10491\hline 10492137 & N/A & tft & ti\\ 10493\hline 10494138 & N/A & target\_id & mbms\_session\_duration\\ 10495\hline 10496139 & N/A & utran\_trans & mbms\_service\_area\\ 10497\hline 10498140 & N/A & rab\_setup & mbms\_session\_id\\ 10499\hline 10500141 & N/A & ext\_header & mbms\_flow\_id\\ 10501\hline 10502142 & N/A & trigger\_id & mbms\_ip\_multicast\\ 10503\hline 10504143 & N/A & omc\_id & mbms\_distribution\_ack\\ 10505\hline 10506144 & N/A & ran\_trans & rfsp\_index\\ 10507\hline 10508145 & N/A & pdp\_context\_pri & uci\\ 10509\hline 10510146 & N/A & addi\_rab\_setup & csg\_info\\ 10511\hline 10512147 & N/A & sgsn\_number & csg\_id\\ 10513\hline 10514148 & N/A & common\_flag & cmi\\ 10515\hline 10516149 & N/A & apn\_restriction & service\_indicator\\ 10517\hline 10518150 & N/A & radio\_priority\_lcs & detach\_type\\ 10519\hline 10520151 & N/A & rat\_type & ldn\\ 10521\hline 10522152 & N/A & user\_loc\_info & node\_feature\\ 10523\hline 10524153 & N/A & ms\_time\_zone & mbms\_time\_to\_transfer\\ 10525\hline 10526154 & N/A & imei\_sv & throttling\\ 10527\hline 10528155 & N/A & camel & arp\\ 10529\hline 10530156 & N/A & mbms\_ue\_context & epc\_timer\\ 10531\hline 10532157 & N/A & tmp\_mobile\_group\_id & signalling\_priority\_indication\\ 10533\hline 10534158 & N/A & rim\_routing\_addr & tmgi\\ 10535\hline 10536159 & N/A & mbms\_config & mm\_srvcc\\ 10537\hline 10538160 & N/A & mbms\_service\_area & flags\_srvcc\\ 10539\hline 10540161 & N/A & src\_rnc\_pdcp & mmbr\\ 10541\hline 10542162 & N/A & addi\_trace\_info & N/A\\ 10543\hline 10544163 & N/A & hop\_counter & N/A\\ 10545\hline 10546164 & N/A & plmn\_id & N/A\\ 10547\hline 10548165 & N/A & mbms\_session\_id & N/A\\ 10549\hline 10550166 & N/A & mbms\_2g3g\_indicator & N/A\\ 10551\hline 10552167 & N/A & enhanced\_nsapi & N/A\\ 10553\hline 10554168 & N/A & mbms\_session\_duration & N/A\\ 10555\hline 10556169 & N/A & addi\_mbms\_trace\_info & N/A\\ 10557\hline 10558170 & N/A & mbms\_session\_repetition\_num & N/A\\ 10559\hline 10560171 & N/A & mbms\_time\_to\_data & N/A\\ 10561\hline 10562173 & N/A & bss & N/A\\ 10563\hline 10564174 & N/A & cell\_id & N/A\\ 10565\hline 10566175 & N/A & pdu\_num & N/A\\ 10567\hline 10568176 & N/A & N/A & N/A\\ 10569\hline 10570177 & N/A & mbms\_bearer\_capab & N/A\\ 10571\hline 10572178 & N/A & rim\_routing\_disc & N/A\\ 10573\hline 10574179 & N/A & list\_pfc & N/A\\ 10575\hline 10576180 & N/A & ps\_xid & N/A\\ 10577\hline 10578181 & N/A & ms\_info\_change\_report & N/A\\ 10579\hline 10580182 & N/A & direct\_tunnel\_flags & N/A\\ 10581\hline 10582183 & N/A & correlation\_id & N/A\\ 10583\hline 10584184 & N/A & bearer\_control\_mode & N/A\\ 10585\hline 10586185 & N/A & mbms\_flow\_id & N/A\\ 10587\hline 10588186 & N/A & mbms\_ip\_multicast & N/A\\ 10589\hline 10590187 & N/A & mbms\_distribution\_ack & N/A\\ 10591\hline 10592188 & N/A & reliable\_inter\_rat\_handover & N/A\\ 10593\hline 10594189 & N/A & rfsp\_index & N/A\\ 10595\hline 10596190 & N/A & fqdn & N/A\\ 10597\hline 10598191 & N/A & evolved\_allocation1 & N/A\\ 10599\hline 10600192 & N/A & evolved\_allocation2 & N/A\\ 10601\hline 10602193 & N/A & extended\_flags & N/A\\ 10603\hline 10604194 & N/A & uci & N/A\\ 10605\hline 10606195 & N/A & csg\_info & N/A\\ 10607\hline 10608196 & N/A & csg\_id & N/A\\ 10609\hline 10610197 & N/A & cmi & N/A\\ 10611\hline 10612198 & N/A & apn\_ambr & N/A\\ 10613\hline 10614199 & N/A & ue\_network & N/A\\ 10615\hline 10616200 & N/A & ue\_ambr & N/A\\ 10617\hline 10618201 & N/A & apn\_ambr\_nsapi & N/A\\ 10619\hline 10620202 & N/A & ggsn\_backoff\_timer & N/A\\ 10621\hline 10622203 & N/A & signalling\_priority\_indication & N/A\\ 10623\hline 10624204 & N/A & signalling\_priority\_indication\_nsapi & N/A\\ 10625\hline 10626205 & N/A & high\_bitrate & N/A\\ 10627\hline 10628206 & N/A & max\_mbr & N/A\\ 10629\hline 10630250 & N/A & N/A & N/A\\ 10631\hline 10632 & N/A & N/A & N/A\\ 10633\hline 10634251 & charging\_gateway\_addr & charging\_gateway\_addr & N/A\\ 10635\hline 10636255 & private\_extension & private\_extension & private\_extension\\ 10637\hline 10638\end{longtable} 10639\end{itemize} 10640\texttt{gtp\_version} 10641\label{gtp:gtp_version} 10642\begin{itemize} 10643 \item[] The \texttt{gtp\_version} keyword is used to check for specific 10644GTP version. 10645 \item[] Because different GTP version defines different message types and 10646 information elements, this keyword should combine with \texttt{gtp\_type} 10647and \texttt{gtp\_info.}\\ 10648 10649\textit{Syntax} 10650\footnotesize 10651\begin{verbatim} 10652 gtp_version:<version>; 10653 version = "0, 1, 2' 10654\end{verbatim} 10655\normalsize 10656\textit{Examples} 10657\footnotesize 10658\begin{verbatim} 10659 gtp_version: 1; 10660\end{verbatim} 10661\normalsize 10662\end{itemize} 10663 10664\subsection{Modbus Preprocessor} 10665\label{sub:modbus} 10666The Modbus preprocessor is a Snort module that decodes the Modbus protocol. 10667It also provides rule options to access certain protocol fields. 10668This allows a user to write rules for Modbus packets without decoding the protocol 10669with a series of "content" and "byte\_test" options. 10670 10671Modbus is a protocol used in SCADA networks. If your network does not contain any 10672Modbus-enabled devices, we recommend leaving this preprocessor turned off. 10673 10674\subsubsection{Dependency Requirements} 10675 10676For proper functioning of the preprocessor: 10677\begin{itemize} 10678 10679\item Stream session tracking must be enabled, i.e. stream5. TCP must be 10680 enabled in stream5. The preprocessor requires a session tracker to keep its 10681 data. 10682 10683\item Protocol Aware Flushing (PAF) must be enabled. 10684 10685\item IP defragmentation should be enabled, i.e. the frag3 preprocessor should be 10686 enabled and configured. 10687 10688\end{itemize} 10689 10690\subsubsection{Preprocessor Configuration} 10691To get started, the Modbus preprocessor must be enabled. 10692The preprocessor name is \texttt{modbus}. 10693\begin{verbatim} 10694preprocessor modbus 10695\end{verbatim} 10696\textit{Option syntax} 10697\begin{itemize} 10698\item[] 10699\begin{tabular}{|l|c|c|p{6cm}|} 10700\hline 10701Option & Argument & Required & Default\\ 10702\hline 10703\hline 10704\texttt{ports} & \texttt{<ports>} & NO & \texttt{ports \{ 502 \} }\\ 10705\hline 10706\end{tabular} 10707\end{itemize} 10708\normalsize 10709\textit{Option explanations} 10710\begin{itemize} 10711\item[] \texttt{ports} 10712\begin{itemize} 10713\item[] This specifies on what ports to check for Modbus messages. Typically, 10714 this will include 502. 10715\item[] \textit{Syntax} 10716\begin{verbatim} 10717 ports { <port> [<port>< ... >] } 10718\end{verbatim} 10719\item[] \textit{Examples} 10720\begin{verbatim} 10721 ports { 1237 3945 5067 } 10722\end{verbatim} 10723\item[] Note: there are spaces before and after `\{' and `\}'. 10724\end{itemize} 10725\end{itemize} 10726\normalsize 10727 10728\textit{Default configuration} 10729\footnotesize 10730\begin{verbatim} 10731 preprocessor modbus 10732\end{verbatim} 10733\normalsize 10734 10735\subsubsection{Rule Options} 10736The Modbus preprocessor adds 3 new rule options. These rule options match on 10737various pieces of the Modbus headers: 10738 10739\begin{itemize} 10740\item[] 10741\begin{verbatim} 10742 modbus_func 10743 modbus_unit 10744 modbus_data 10745\end{verbatim} 10746\end{itemize} 10747 10748The preprocessor must be enabled for these rule option to work. 10749 10750\texttt{modbus\_func} 10751\label{modbus:modbus_func} 10752\begin{itemize} 10753 \item[] This option matches against the Function Code inside of a Modbus 10754 header. The code may be a number (in decimal format), or a string from the 10755 list provided below. 10756\end{itemize} 10757 10758\textit{Syntax} 10759\footnotesize 10760\begin{verbatim} 10761 modbus_func:<code> 10762 10763 code = 0-255 | 10764 "read_coils" | 10765 "read_discrete_inputs" | 10766 "read_holding_registers" | 10767 "read_input_registers" | 10768 "write_single_coil" | 10769 "write_single_register" | 10770 "read_exception_status" | 10771 "diagnostics" | 10772 "get_comm_event_counter" | 10773 "get_comm_event_log" | 10774 "write_multiple_coils" | 10775 "write_multiple_registers" | 10776 "report_slave_id" | 10777 "read_file_record" | 10778 "write_file_record" | 10779 "mask_write_register" | 10780 "read_write_multiple_registers" | 10781 "read_fifo_queue" | 10782 "encapsulated_interface_transport" 10783\end{verbatim} 10784\normalsize 10785\textit{Examples} 10786\footnotesize 10787\begin{verbatim} 10788 modbus_func:1; 10789 modbus_func:write_multiple_coils; 10790\end{verbatim} 10791\normalsize 10792 10793\texttt{modbus\_unit} 10794\label{modbus:modbus_unit} 10795\begin{itemize} 10796 \item[] This option matches against the Unit ID field in a Modbus header. 10797\end{itemize} 10798 10799\textit{Syntax} 10800\footnotesize 10801\begin{verbatim} 10802 modbus_unit:<unit> 10803 10804 unit = 0-255 10805\end{verbatim} 10806\normalsize 10807\textit{Examples} 10808\footnotesize 10809\begin{verbatim} 10810 modbus_unit:1; 10811\end{verbatim} 10812\normalsize 10813 10814\texttt{modbus\_data} 10815\label{modbus:modbus_data} 10816\begin{itemize} 10817 \item[] This rule option sets the cursor at the beginning of the Data field 10818 in a Modbus request/response. 10819\end{itemize} 10820 10821\textit{Syntax} 10822\footnotesize 10823\begin{verbatim} 10824 modbus_data; 10825\end{verbatim} 10826\normalsize 10827 10828\textit{Examples} 10829\footnotesize 10830\begin{verbatim} 10831 modbus_data; content:"badstuff"; 10832\end{verbatim} 10833\normalsize 10834 10835\subsubsection{Preprocessor Events} 10836The Modbus preprocessor uses GID 144 for its preprocessor events. 10837\begin{longtable}{|r|p{13.5cm}|} 10838 10839\hline 10840SID & Description\\ 10841\hline 10842 1 & The length in the Modbus header does not match the length needed \\ 10843 & by the Modbus function code. \\ 10844&\\ 10845 & Each Modbus function has an expected format for requests and responses. \\ 10846 & If the length of the message does not match the expected format, this \\ 10847 & alert is generated. \\ 10848\hline 10849 2 & Modbus protocol ID is non-zero. \\ 10850&\\ 10851 & The protocol ID field is used for multiplexing other protocols with \\ 10852 & Modbus. Since the preprocessor cannot handle these other protocols, \\ 10853 & this alert is generated instead. \\ 10854\hline 10855 3 & Reserved Modbus function code in use. \\ 10856\hline 10857\end{longtable} 10858 10859\subsection{DNP3 Preprocessor} 10860\label{sub:dnp3} 10861The DNP3 preprocessor is a Snort module that decodes the DNP3 protocol. 10862It also provides rule options to access certain protocol fields. 10863This allows a user to write rules for DNP3 packets without decoding the protocol 10864with a series of "content" and "byte\_test" options. 10865 10866DNP3 is a protocol used in SCADA networks. If your network does not contain any 10867DNP3-enabled devices, we recommend leaving this preprocessor turned off. 10868 10869\subsubsection{Dependency Requirements} 10870 10871For proper functioning of the preprocessor: 10872\begin{itemize} 10873 10874\item Stream session tracking must be enabled, i.e. stream5. TCP or UDP must be 10875 enabled in stream5. The preprocessor requires a session tracker to keep its 10876 data. 10877 10878\item Protocol Aware Flushing (PAF) must be enabled. 10879 10880\item IP defragmentation should be enabled, i.e. the frag3 preprocessor should be 10881 enabled and configured. 10882 10883\end{itemize} 10884 10885\subsubsection{Preprocessor Configuration} 10886To get started, the DNP3 preprocessor must be enabled. 10887The preprocessor name is \texttt{dnp3}. 10888\begin{verbatim} 10889preprocessor dnp3 10890\end{verbatim} 10891\textit{Option syntax} 10892\begin{itemize} 10893\item[] 10894\begin{tabular}{|l|c|c|p{6cm}|} 10895\hline 10896Option & Argument & Required & Default\\ 10897\hline 10898\hline 10899\texttt{ports} & \texttt{<ports>} & NO & \texttt{ports \{ 20000 \} }\\ 10900\texttt{memcap} & \texttt{<number} & NO & \texttt{memcap 262144}\\ 10901\texttt{check\_crc} & NONE & NO & OFF\\ 10902\texttt{disabled} & NONE & NO & OFF\\ 10903\hline 10904\end{tabular} 10905\end{itemize} 10906\normalsize 10907\textit{Option explanations} 10908\begin{itemize} 10909\item[] \texttt{ports} 10910\begin{itemize} 10911\item[] This specifies on what ports to check for DNP3 messages. Typically, 10912 this will include 20000. 10913\item[] \textit{Syntax} 10914\begin{verbatim} 10915 ports { <port> [<port>< ... >] } 10916\end{verbatim} 10917\item[] \textit{Examples} 10918\begin{verbatim} 10919 ports { 1237 3945 5067 } 10920\end{verbatim} 10921\item[] Note: there are spaces before and after `\{' and `\}'. 10922\end{itemize} 10923 10924\item[] \texttt{memcap} 10925\begin{itemize} 10926\item[] This sets a maximum to the amount of memory allocated to the DNP3 10927 preprocessor for session-tracking purposes. The argument is given 10928 in bytes. 10929 Each session requires about 4 KB to track, and the default is 256 kB. 10930 This gives the preprocessor the ability to track 63 DNP3 sessions 10931 simultaneously. 10932 Setting the memcap below 4144 bytes will cause a fatal error. 10933 When multiple configs are used, the memcap in the non-default configs 10934 will be overwritten by the memcap in the default config. If the default 10935 config isn't intended to inspect DNP3 traffic, use the "disabled" 10936 keyword. 10937\end{itemize} 10938 10939\item[] \texttt{check\_crc} 10940\begin{itemize} 10941\item[] This option makes the preprocessor validate the checksums contained in 10942 DNP3 Link-Layer Frames. Frames with invalid checksums will be ignored. 10943 If the corresponding preprocessor rule is enabled, invalid checksums 10944 will generate alerts. 10945 The corresponding rule is GID 145, SID 1. 10946\end{itemize} 10947 10948\item[] \texttt{disabled} 10949\begin{itemize} 10950\item[] This option is used for loading the preprocessor without inspecting 10951 any DNP3 traffic. The \texttt{disabled} keyword is only useful when the DNP3 10952 preprocessor is turned on in a separate policy. 10953\end{itemize} 10954\end{itemize} 10955\normalsize 10956 10957\textit{Default configuration} 10958\footnotesize 10959\begin{verbatim} 10960 preprocessor dnp3 10961\end{verbatim} 10962\normalsize 10963 10964\subsubsection{Rule Options} 10965The DNP3 preprocessor adds 4 new rule options. These rule options match on 10966various pieces of the DNP3 headers: 10967 10968\begin{itemize} 10969\item[] 10970\begin{verbatim} 10971 dnp3_func 10972 dnp3_obj 10973 dnp3_ind 10974 dnp3_data 10975\end{verbatim} 10976\end{itemize} 10977 10978The preprocessor must be enabled for these rule option to work. 10979 10980\texttt{dnp3\_func} 10981\label{dnp3:dnp3_func} 10982\begin{itemize} 10983 \item[] This option matches against the Function Code inside of a DNP3 10984 Application-Layer request/response header. The code may be a number 10985 (in decimal format), or a string from the list provided below. 10986\end{itemize} 10987 10988\textit{Syntax} 10989\footnotesize 10990\begin{verbatim} 10991 dnp3_func:<code> 10992 10993 code = 0-255 | 10994 "confirm" | 10995 "read" | 10996 "write" | 10997 "select" | 10998 "operate" | 10999 "direct_operate" | 11000 "direct_operate_nr" | 11001 "immed_freeze" | 11002 "immed_freeze_nr" | 11003 "freeze_clear" | 11004 "freeze_clear_nr" | 11005 "freeze_at_time" | 11006 "freeze_at_time_nr" | 11007 "cold_restart" | 11008 "warm_restart" | 11009 "initialize_data" | 11010 "initialize_appl" | 11011 "start_appl" | 11012 "stop_appl" | 11013 "save_config" | 11014 "enable_unsolicited" | 11015 "disable_unsolicited" | 11016 "assign_class" | 11017 "delay_measure" | 11018 "record_current_time" | 11019 "open_file" | 11020 "close_file" | 11021 "delete_file" | 11022 "get_file_info" | 11023 "authenticate_file" | 11024 "abort_file" | 11025 "activate_config" | 11026 "authenticate_req" | 11027 "authenticate_err" | 11028 "response" | 11029 "unsolicited_response" | 11030 "authenticate_resp" 11031 11032\end{verbatim} 11033\normalsize 11034\textit{Examples} 11035\footnotesize 11036\begin{verbatim} 11037 dnp3_func:1; 11038 dnp3_func:delete_file; 11039\end{verbatim} 11040\normalsize 11041 11042\texttt{dnp3\_ind} 11043\label{dnp3:dnp3_ind} 11044\begin{itemize} 11045 \item[] This option matches on the Internal Indicators flags present in a 11046 DNP3 Application Response Header. Much like the TCP flags rule option, 11047 providing multiple flags in one option will cause the rule to fire if \emph{ANY} 11048 one of the flags is set. To alert on a combination of flags, use multiple rule 11049 options. 11050\end{itemize} 11051 11052\textit{Syntax} 11053\footnotesize 11054\begin{verbatim} 11055 dnp3_ind:<flag>{,<flag>...] 11056 11057 flag = "all_stations" 11058 "class_1_events" 11059 "class_2_events" 11060 "class_3_events" 11061 "need_time" 11062 "local_control" 11063 "defice_trouble" 11064 "device_restart" 11065 "no_func_code_support" 11066 "object_unknown" 11067 "parameter_error" 11068 "event_buffer_overflow" 11069 "already_executing" 11070 "config_corrupt" 11071 "reserved_2" 11072 "reserved_1" 11073\end{verbatim} 11074\normalsize 11075\textit{Examples} 11076\footnotesize 11077\begin{verbatim} 11078 # Alert on reserved_1 OR reserved_2 11079 dnp3_ind:reserved_1,reserved_2; 11080 11081 # Alert on class_1 AND class_2 AND class_3 events 11082 dnp3_ind:class_1_events; dnp3_ind:class_2_events; dnp3_ind:class_3_events; 11083\end{verbatim} 11084\normalsize 11085 11086\texttt{dnp3\_obj} 11087\label{dnp3:dnp3_obj} 11088\begin{itemize} 11089 \item[] This option matches on DNP3 object headers present in a request or response. 11090\end{itemize} 11091 11092\textit{Syntax} 11093\footnotesize 11094\begin{verbatim} 11095 dnp3_obj:<group>,<var> 11096 11097 group = 0 - 255 11098 var = 0 - 255 11099\end{verbatim} 11100\normalsize 11101\textit{Examples} 11102\footnotesize 11103\begin{verbatim} 11104 # Alert on DNP3 "Date and Time" object 11105 dnp3_obj:50,1; 11106\end{verbatim} 11107\normalsize 11108 11109\texttt{dnp3\_data} 11110\label{dnp3:dnp3_data} 11111\begin{itemize} 11112 \item[] As Snort processes DNP3 packets, the DNP3 preprocessor collects 11113 Link-Layer Frames and reassembles them back into Application-Layer Fragments. 11114 This rule option sets the cursor to the beginning of an Application-Layer 11115 Fragment, so that other rule options can work on the reassembled data. 11116 11117 With the dnp3\_data rule option, you can write rules based on the data within 11118 Fragments without splitting up the data and adding CRCs every 16 bytes. 11119\end{itemize} 11120 11121\textit{Syntax} 11122\footnotesize 11123\begin{verbatim} 11124 dnp3_data; 11125\end{verbatim} 11126\normalsize 11127 11128\textit{Examples} 11129\footnotesize 11130\begin{verbatim} 11131 dnp3_data; content:"badstuff_longer_than_16chars"; 11132\end{verbatim} 11133\normalsize 11134 11135\subsubsection{Preprocessor Events} 11136The DNP3 preprocessor uses GID 145 for its preprocessor events. 11137\begin{longtable}{|r|p{13.5cm}|} 11138 11139\hline 11140SID & Description\\ 11141\hline 11142 1 & A Link-Layer Frame contained an invalid CRC. \\ 11143 & (Enable \texttt{check\_crc} in the preprocessor config to get this alert.) \\ 11144\hline 11145 2 & A DNP3 Link-Layer Frame was dropped, due to an invalid length. \\ 11146\hline 11147 3 & A Transport-Layer Segment was dropped during reassembly. \\ 11148 & This happens when segments have invalid sequence numbers. \\ 11149\hline 11150 4 & The DNP3 Reassembly buffer was cleared before a complete fragment could \\ 11151 & be reassembled. \\ 11152 & This happens when a segment carrying the "FIR" flag appears after some \\ 11153 & other segments have been queued. \\ 11154\hline 11155 5 & A DNP3 Link-Layer Frame is larger than 260 bytes. \\ 11156\hline 11157 6 & A DNP3 Link-Layer Frame uses an address that is reserved. \\ 11158\hline 11159 7 & A DNP3 request or response uses a reserved function code. \\ 11160\hline 11161\end{longtable} 11162 11163 11164\subsection{AppId Preprocessor} 11165\label{sub:appid} 11166With increasingly complex networks and growing network traffic, network administrators 11167require application awareness in managing networks. An administrator may allow only 11168applications that are business relevant, low bandwidth and/or deal with certain 11169subject matter. 11170 11171AppId preprocessor adds application level view to manage networks. It does this by adding the following features 11172\begin{itemize} 11173 11174\item Network control: The preprocessor provides simplified single point application awareness by making a set of application 11175identifiers (AppId) available to Snort Rule writers. 11176 11177\item Network usage awareness: the preprocessor outputs statistics to 11178show network bandwidth used by each application seen on network. Administrators can 11179monitor bandwidth usage and may decide to block applications that are wasteful. 11180 11181\item Custom applications: The preprocessor enables administrators to create their own application detectors 11182to detect new applications. The detectors are written in Lua and interface with Snort 11183using a well-defined C-Lua API. 11184 11185\end{itemize} 11186 11187\subsubsection{Dependency Requirements} 11188 11189For proper functioning of the preprocessor: 11190\begin{itemize} 11191 11192\item Stream session tracking must be enabled, i.e. stream5. TCP or UDP must be 11193 enabled in stream5. The preprocessor requires a session tracker to keep its 11194 data. 11195 11196\item Protocol Aware Flushing (PAF) must be enabled. 11197 11198\item IP defragmentation should be enabled, i.e. the frag3 preprocessor should be 11199 enabled and configured. 11200 11201\item HTTP preprocessor must be enabled and configured. The processor does not require 11202 any AppId specific configuration. The preprocessor provides parsed HTTP headers 11203 for application determination. Without HTTP preprocessor, AppId preprocessor will 11204 identify only non-HTTP applications. 11205 11206\item LuaJIT version 2.0.2 must be installed on 11207 host where snort is being compiled and run. Newer versions of LuaJIT are not tested for compatibility. 11208\end{itemize} 11209 11210\subsubsection{Preprocessor Configuration} 11211AppId dynamic preprocessor is enabled by default(from snort-2.9.12). 11212The preprocessor can be disabled during build time by including the following option in ./configure: 11213 11214--disable-open-appid 11215 11216The configuration name is "appid": 11217 11218The preprocessor name is \texttt{appid}. 11219\begin{verbatim} 11220preprocessor appid 11221\end{verbatim} 11222\textit{Option syntax} 11223\begin{itemize} 11224\item[] 11225\begin{tabular}{|l|c|c|p{6cm}|} 11226\hline 11227Option & Argument & Required & Default\\ 11228\hline 11229\hline 11230\texttt{app\_detector\_dir} & \texttt{<directory>} & NO & \texttt{app\_detector\_dir \{ /usr/local/etc/appid \} }\\ 11231\texttt{app\_stats\_filename} & \texttt{<filename>} & NO & \texttt{NULL}\\ 11232\texttt{app\_stats\_period} & \texttt{<time in seconds>} & NO & \texttt{300 seconds}\\ 11233\texttt{app\_stats\_rollover\_size} & \texttt{<disk size in bytes>} & NO & \texttt{20 MB}\\ 11234\texttt{app\_stats\_rollover\_time} & \texttt{<time in seconds>} & NO & \texttt{1 day}\\ 11235\texttt{memcap} & \texttt{<memory limit bytes>} & NO & \texttt{256 MB}\\ 11236\texttt{debug} & \texttt{<"yes">} & NO & \texttt{disabled}\\ 11237\texttt{dump\_ports} & \texttt{No} & NO & \texttt{disabled}\\ 11238\hline 11239\end{tabular} 11240\end{itemize} 11241\normalsize 11242\textit{Option explanations} 11243\begin{itemize} 11244\item[] \texttt{app\_detector\_dir} 11245\begin{itemize} 11246\item[] 11247 specifies base path where Cisco provided detectors and application 11248 configuration files are installed by ODP (Open Detector Package) package. 11249 The package contains Lua detectors and some application metadata. Customer 11250 written detectors are stored in subdirectory "custom" under the same base path. 11251\item[] \textit{Syntax} 11252\begin{verbatim} 11253 app_detector_dir <directory name> 11254\end{verbatim} 11255\item[] \textit{Examples} 11256\begin{verbatim} 11257 app_detector_dir /usr/local/cisco/apps 11258\end{verbatim} 11259\end{itemize} 11260 11261\item[] \texttt{app\_stats\_filename} 11262\begin{itemize} 11263\item[] name of file. If this configuration is missing, application stats are disabled. 11264\item[] \textit{Syntax} 11265\begin{verbatim} 11266 app_stats_filename <filename> 11267\end{verbatim} 11268\item[] \textit{Examples} 11269\begin{verbatim} 11270 app_stats_filename appStats.log 11271\end{verbatim} 11272\end{itemize} 11273 11274\item[] \texttt{app\_stats\_period} 11275\begin{itemize} 11276\item[] 11277 bucket size in seconds. Default 5 minutes. 11278\item[] \textit{Syntax} 11279\begin{verbatim} 11280 app_stats_period <time in seconds> 11281\end{verbatim} 11282\item[] \textit{Examples} 11283\begin{verbatim} 11284 app_stats_period 15 11285\end{verbatim} 11286\end{itemize} 11287 11288\item[] \texttt{app\_stats\_rollover\_size} 11289\begin{itemize} 11290\item[] file size which will cause file rollover. Default 20 MB. 11291\item[] \textit{Syntax} 11292\begin{verbatim} 11293 app_stats_rollover_size <file size in bytes> 11294\end{verbatim} 11295\item[] \textit{Examples} 11296\begin{verbatim} 11297 app_stats_rollover_size 2000000 11298\end{verbatim} 11299\end{itemize} 11300 11301\item[] \texttt{app\_stats\_rollover\_time >} 11302\begin{itemize} 11303\item[] 11304 time since file creation which will cause rollover. Default 1 day. 11305\item[] \textit{Syntax} 11306\begin{verbatim} 11307 app_stats_rollover_time <time in seconds> 11308\end{verbatim} 11309\item[] \textit{Examples} 11310\begin{verbatim} 11311 app_stats_rollover_time 3600 11312\end{verbatim} 11313\end{itemize} 11314 11315\item[] \texttt{memcap >} 11316\begin{itemize} 11317\item[] 11318 upper bound for memory used by AppId internal structures. Default 32MB. 11319\item[] \textit{Syntax} 11320\begin{verbatim} 11321 memcap <memory in bytes> 11322\end{verbatim} 11323\item[] \textit{Examples} 11324\begin{verbatim} 11325 memcap 100000000 11326\end{verbatim} 11327\end{itemize} 11328 11329\item[] \texttt{dump\_ports >} 11330\begin{itemize} 11331\item[] 11332 prints port only detectors and information on active detectors. Used for troubleshooting. 11333\item[] \textit{Syntax} 11334\begin{verbatim} 11335 dump_ports <"yes"|"no"> 11336\end{verbatim} 11337\item[] \textit{Examples} 11338\begin{verbatim} 11339 dump_ports "yes" 11340\end{verbatim} 11341\end{itemize} 11342 11343\item[] \texttt{debug} 11344\begin{itemize} 11345\item[] 11346 Used in some old detectors for debugging. 11347\item[] \textit{Syntax} 11348\begin{verbatim} 11349 debug 11350\end{verbatim} 11351\item[] \textit{Examples} 11352\begin{verbatim} 11353 debug 11354\end{verbatim} 11355\end{itemize} 11356 11357\end{itemize} 11358\normalsize 11359 11360\textit{Default configuration} 11361\footnotesize 11362\begin{verbatim} 11363 preprocessor appid 11364\end{verbatim} 11365\normalsize 11366 11367\subsubsection{Rule Options} 11368The AppId preprocessor adds 1 new rule option as follows: 11369 11370\begin{itemize} 11371\item[] 11372\begin{verbatim} 11373 appid 11374\end{verbatim} 11375\end{itemize} 11376 11377The preprocessor must be enabled for this rule option to work. 11378 11379\texttt{appid} 11380\label{appid:appid} 11381\begin{itemize} 11382 \item[] 11383The rule option allows users to customize 11384rules to specific application in a simple manner. The option can take up to 10 11385application names separated by spaces, tabs, or commas. Application names in 11386rules are the names you will see in last column in appMapping.data file. A 11387rule is considered a match if one of the appId in a rule match an appId in a 11388session. 11389 11390For client side packets, payloadAppId in a session is matched with all AppIds 11391in a rule. Thereafter miscAppId, clientAppId and serviceAppId are matched. 11392Since Alert Events contain one AppId, only the first match is reported. If rule 11393without appId option matches, then the most specific appId (in order of 11394payload, misc, client, server) is reported. 11395 11396The same logic is followed for server side packets with one exception. Order of 11397matching is changed to make serviceAppId higher then clientAppId. 11398 11399\end{itemize} 11400 11401\textit{Syntax} 11402\footnotesize 11403\begin{verbatim} 11404 appid:<list of application names> 11405\end{verbatim} 11406\normalsize 11407\textit{Examples} 11408\footnotesize 11409\begin{verbatim} 11410 appid: http; 11411 appid: ftp, ftp-data; 11412 appid: cnn.com, zappos; 11413\end{verbatim} 11414\normalsize 11415 11416\subsubsection{Application Rule Events} 11417A new event type is defined for logging application name in Snort 11418Alerts in unified2 format only. These events contain only one application name. 11419The Events can be enabled for unified2 output using 'appid\_event\_types keyword. 11420 11421For example, the following configuration will log alert in my.alert file with 11422application name. 11423\footnotesize 11424\begin{verbatim} 11425 output alert\_unified2: filename my.alert, appid\_event\_types 11426\end{verbatim} 11427\normalsize 11428 11429u2spewfoo, u2openappid, u2streamer tools can be used to print alerts in new format. 11430Each event will display additional application name at the end of the event. 11431 11432\textit{Examples} 11433\footnotesize 11434\begin{verbatim} 11435#> u2spewfoo outputs the following event format 11436(Event) 11437 sensor id: 0 event id: 6 event second: 1292962302 event microsecond: 227323 11438 sig id: 18763 gen id: 1 revision: 4 classification: 0 11439 priority: 0 ip source: 98.27.88.56 ip destination: 10.4.10.79 11440 src port: 80 dest port: 54767 protocol: 6 impact\_flag: 0 blocked: 0 11441 mpls label: 0 vland id: 0 policy id: 0 appid: zappos 11442\end{verbatim} 11443\normalsize 11444 11445\subsubsection{Application Usage Statistics} 11446 11447AppId preprocessor prints application network usage periodically in snort 11448log directory in unified2 format. File name, time interval for statistic and 11449file rollover are controlled by appId preprocessor configuration. u2spewfoo, 11450u2openappid, u2streamer tools can be used to print contents of these files. An 11451example output from u2openappid tools is as follows: 11452\footnotesize 11453\begin{verbatim} 11454 11455 statTime="1292962290",appName="firefox",txBytes="9395",rxBytes="77021" 11456 statTime="1292962290",appName="google\_analytic",txBytes="2024",rxBytes="928" 11457 statTime="1292962290",appName="http",txBytes="28954",rxBytes="238000" 11458 statTime="1292962290",appName="zappos",txBytes="26930",rxBytes="237072" 11459\end{verbatim} 11460\normalsize 11461 11462\subsubsection{Open Detector Package (ODP) Installation} 11463Application detectors from Snort team will be delivered in a separate package 11464called Open Detector Package. ODP is a package that contains the following 11465artifacts: 11466\begin{enumerate} 11467 11468\item Application detectors in Lua language. 11469 11470\item Port detectors, which are port only application detectors, in meta-data in YAML format. 11471 11472\item appMapping.data file containing application metadata. This file should not 11473 be modified. The first column contains application identifier and second column 11474 contains application name. Other columns contain internal information. 11475 11476\item Lua library files DetectorCommon.lua, flowTrackerModule.lua and 11477 hostServiceTrackerModule.lua 11478\end{enumerate} 11479User can install ODP package in any directory of its choosing and configure 11480this directory in app\_detector\_dir option in appId preprocessor configuration. 11481Installing ODP will not modify any subdirectory named custom, where 11482user-created detectors are located. 11483 11484When installed, ODP will create following sub-directories: 11485\footnotesize 11486\begin{verbatim} 11487 odp/port //Cisco port-only detectors 11488 odp/lua //Cisco Lua detectors 11489 odp/libs //Cisco Lua modules 11490\end{verbatim} 11491\normalsize 11492 11493\subsubsection{User Created Application Detectors} 11494 11495Users can create new applications by coding detectors in Lua language. Users can also 11496copy Snort team provided detectors into custom subdirectory and customize the detector. A 11497document will be posted on Snort Website with details on API usage. 11498 11499\par \noindent Users must organize their Lua detectors and libraries by creating the following 11500directory structure, under ODP installation directory. 11501\footnotesize 11502\begin{verbatim} 11503 11504 custom/port //port-only detectors 11505 custom/lua //Lua detectors 11506 custom/libs //Lua modules 11507\end{verbatim} 11508\normalsize 11509 11510\section{Decoder and Preprocessor Rules} 11511 11512Decoder and preprocessor rules allow one to enable and disable decoder and 11513preprocessor events on a rule by rule basis. They also allow one to specify 11514the rule type or action of a decoder or preprocessor event on a rule by rule 11515basis. 11516 11517Decoder config options will still determine whether or not to generate decoder 11518events. For example, if \texttt{config disable\_decode\_alerts} is in 11519\texttt{snort.conf}, decoder events will not be generated regardless of whether 11520or not there are corresponding rules for the event. Also note that if the 11521decoder is configured to enable drops, e.g. \texttt{config 11522enable\_decode\_drops}, these options will take precedence over the event type 11523of the rule. A packet will be dropped if either a decoder config drop option 11524is in \texttt{snort.conf} or the decoder or preprocessor rule type is 11525\texttt{drop}. Of course, the drop cases only apply if Snort is running 11526inline. See \texttt{doc/README.decode} for config options that control decoder 11527events. 11528 11529\subsection{Configuring} 11530 11531The decoder and preprocessor rules are located in the \texttt{preproc\_rules/} 11532directory in the top level source tree, and have the names 11533\texttt{decoder.rules} and \texttt{preprocessor.rules} respectively. These 11534files are updated as new decoder and preprocessor events are added to Snort. 11535The \texttt{gen-msg.map} under \texttt{etc} directory is also updated with 11536new decoder and preprocessor rules. 11537 11538To enable these rules in \texttt{snort.conf}, define the path to where the 11539rules are located and uncomment the \texttt{include} lines in 11540\texttt{snort.conf} that reference the rules files. 11541 11542\begin{verbatim} 11543 var PREPROC_RULE_PATH /path/to/preproc_rules 11544 ... 11545 include $PREPROC_RULE_PATH/preprocessor.rules 11546 include $PREPROC_RULE_PATH/decoder.rules 11547\end{verbatim} 11548 11549To disable any rule, just comment it with a \texttt{\#} or remove the rule 11550completely from the file (commenting is recommended). 11551 11552To change the rule type or action of a decoder/preprocessor rule, just replace 11553\texttt{alert} with the desired rule type. Any one of the following rule types 11554can be used: 11555 11556\begin{verbatim} 11557 alert 11558 log 11559 pass 11560 drop 11561 sdrop 11562 reject 11563\end{verbatim} 11564 11565For example one can change: 11566 11567\begin{verbatim} 11568 alert ( msg: "DECODE_NOT_IPV4_DGRAM"; sid: 1; gid: 116; rev: 1; \ 11569 metadata: rule-type decode ; classtype:protocol-command-decode;) 11570\end{verbatim} 11571 11572to 11573 11574\begin{verbatim} 11575 drop ( msg: "DECODE_NOT_IPV4_DGRAM"; sid: 1; gid: 116; rev: 1; \ 11576 metadata: rule-type decode ; classtype:protocol-command-decode;) 11577\end{verbatim} 11578 11579to drop (as well as alert on) packets where the Ethernet protocol is IPv4 but 11580version field in IPv4 header has a value other than 4. 11581 11582See \texttt{README.decode}, \texttt{README.gre} and the various preprocessor 11583READMEs for descriptions of the rules in \texttt{decoder.rules} and 11584\texttt{preprocessor.rules}. 11585 11586The generator ids ( gid ) for different preprocessors and the decoder are as follows: 11587 11588\begin{table}[h] 11589\begin{center} 11590\begin{tabular}{| l | l |} 11591 11592\hline 11593\textbf{Generator Id} & \textbf{Module}\\ 11594\hline 11595 11596\hline 11597\texttt{105} & Back Orifice preprocessor \\ 11598 11599\hline 11600\texttt{106} & RPC Decode preprocessor \\ 11601 11602\hline 11603\texttt{112} & Arpspoof preprocessor \\ 11604 11605\hline 11606\texttt{116} & Snort Decoder \\ 11607 11608\hline 11609\texttt{119} & HTTP Inspect preprocessor ( Client ) \\ 11610 11611\hline 11612\texttt{120} & HTTP Inspect preprocessor ( Server ) \\ 11613 11614\hline 11615\texttt{122} & Portscan preprocessor \\ 11616 11617\hline 11618\texttt{123} & Frag3 preprocessor \\ 11619 11620\hline 11621\texttt{124} & SMTP preprocessor \\ 11622 11623\hline 11624\texttt{125} & FTP (FTP) preprocessor \\ 11625 11626\hline 11627\texttt{126} & FTP (Telnet) preprocessor \\ 11628 11629\hline 11630\texttt{127} & ISAKMP preprocessor \\ 11631 11632\hline 11633\texttt{128} & SSH preprocessor \\ 11634 11635\hline 11636\texttt{129} & Stream preprocessor \\ 11637 11638\hline 11639\texttt{131} & DNS preprocessor \\ 11640 11641\hline 11642\texttt{132} & Skype preprocessor \\ 11643 11644\hline 11645\texttt{133} & DceRpc2 preprocessor \\ 11646 11647\hline 11648\texttt{134} & PPM preprocessor \\ 11649 11650\hline 11651\texttt{136} & Reputation preprocessor \\ 11652 11653\hline 11654\texttt{137} & SSL preprocessor \\ 11655 11656\hline 11657\texttt{139} & SDF preprocessor \\ 11658 11659\hline 11660\texttt{140} & SIP preprocessor \\ 11661 11662\hline 11663\texttt{141} & IMAP preprocessor \\ 11664 11665\hline 11666\texttt{142} & POP preprocessor \\ 11667 11668\hline 11669\texttt{143} & GTP preprocessor \\ 11670\hline 11671\end{tabular} 11672\end{center} 11673\end{table} 11674 11675 11676\subsection{Reverting to original behavior} 11677 11678The following config option in \texttt{snort.conf} will make Snort revert to the 11679old behavior: 11680 11681\begin{verbatim} 11682 config autogenerate_preprocessor_decoder_rules 11683\end{verbatim} 11684 11685Note that if you want to revert to the old behavior, you also have to remove 11686the decoder and preprocessor rules and any reference to them from 11687\texttt{snort.conf}, otherwise they will be loaded. This option applies to 11688rules not specified and the default behavior is to alert. 11689 11690\section{Event Processing} 11691 11692Snort provides a variety of mechanisms to tune event processing to suit your 11693needs: 11694 11695\begin{itemize} 11696\item \texttt{Detection Filters} 11697 11698You can use detection filters to specify a threshold that must be exceeded 11699before a rule generates an event. This is covered in section 11700\ref{detection_filter}. 11701 11702\item \texttt{Rate Filters} 11703 11704You can use rate filters to change a rule action when the number or rate of 11705events indicates a possible attack. 11706 11707\item \texttt{Event Filters} 11708 11709You can use event filters to reduce the number of logged events for noisy 11710rules. This can be tuned to significantly reduce false alarms. 11711 11712\item \texttt{Event Suppression} 11713 11714You can completely suppress the logging of uninteresting events. 11715 11716\end{itemize} 11717 11718\subsection{Rate Filtering} 11719\label{rate_filtering} 11720 11721\texttt{rate\_filter} provides rate based attack prevention by allowing users 11722to configure a new action to take for a specified time when a given rate is 11723exceeded. Multiple rate filters can be defined on the same rule, in which case 11724they are evaluated in the order they appear in the configuration file, and the 11725first applicable action is taken. 11726 11727\subsubsection{Format} 11728 11729Rate filters are used as standalone configurations (outside of a rule) and have 11730the following format: 11731 11732\begin{verbatim} 11733 rate_filter \ 11734 gen_id <gid>, sig_id <sid>, \ 11735 track <by_src|by_dst|by_rule>, \ 11736 count <c>, seconds <s>, \ 11737 new_action alert|drop|pass|log|sdrop|reject, \ 11738 timeout <seconds> \ 11739 [, apply_to <ip-list>] 11740\end{verbatim} 11741 11742The options are described in the table below - all are required except 11743\texttt{apply\_to}, which is optional. 11744 11745% fixthis this table should appear here with the [h] but floats away! 11746\begin{table}[h] 11747\begin{center} 11748\begin{tabular}{| p{2in} | p{4in} |} 11749 11750\hline 11751\textbf{Option} & \textbf{Description}\\ 11752\hline 11753 11754\hline 11755\texttt{track by\_src | by\_dst | by\_rule} & 11756 11757rate is tracked either by source IP address, destination IP address, or by 11758rule. This means the match statistics are maintained for each unique source IP 11759address, for each unique destination IP address, or they are aggregated at rule 11760level. For rules related to Stream sessions, source and destination means 11761client and server respectively. \texttt{track by\_rule} and \texttt{apply\_to} 11762may not be used together.\\ 11763 11764\hline 11765\texttt{count c} & 11766 11767the maximum number of rule matches in \texttt{s} seconds before the rate filter 11768limit to is exceeded. \texttt{c} must be nonzero value.\\ 11769 11770\hline 11771\texttt{seconds s} & 11772 11773the time period over which \texttt{count} is accrued. 0 seconds means 11774\texttt{count} is a total count instead of a specific rate. For example, 11775\texttt{rate\_filter} may be used to detect if the number of connections to a 11776specific server exceed a specific count. 0 seconds only applies to internal 11777rules (gen\_id 135) and other use will produce a fatal error by Snort.\\ 11778 11779\hline 11780\texttt{new\_action alert | drop | pass | log | sdrop | reject} & 11781 11782\texttt{new\_action} replaces rule action for \texttt{t} seconds. 11783\texttt{drop}, \texttt{reject}, and \texttt{sdrop} can be used only when snort 11784is used in inline mode. \texttt{sdrop} and \texttt{reject} are conditionally 11785compiled with GIDS.\\ 11786 11787\hline 11788\texttt{timeout t} & 11789 11790revert to the original rule action after \texttt{t} seconds. If \texttt{t} is 117910, then rule action is never reverted back. An \texttt{event\_filter} may be 11792used to manage number of alerts after the rule action is enabled by 11793\texttt{rate\_filter}.\\ 11794 11795\hline 11796\texttt{apply\_to <ip-list>} & 11797 11798restrict the configuration to only to source or destination IP address 11799(indicated by track parameter) determined by \texttt{<ip-list>}. \texttt{track 11800by\_rule} and \texttt{apply\_to} may not be used together. Note that events 11801are generated during the timeout period, even if the rate falls below the 11802configured limit.\\ 11803 11804\hline 11805\end{tabular} 11806\end{center} 11807\end{table} 11808 11809\subsubsection{Examples} 11810 11811Example 1 - allow a maximum of 100 connection attempts per second from any one 11812IP address, and block further connection attempts from that IP address for 10 11813seconds: 11814 11815\begin{verbatim} 11816 rate_filter \ 11817 gen_id 135, sig_id 1, \ 11818 track by_src, \ 11819 count 100, seconds 1, \ 11820 new_action drop, timeout 10 11821\end{verbatim} 11822 11823Example 2 - allow a maximum of 100 successful simultaneous connections from any 11824one IP address, and block further connections from that IP address for 10 11825seconds: 11826 11827\begin{verbatim} 11828 rate_filter \ 11829 gen_id 135, sig_id 2, \ 11830 track by_src, \ 11831 count 100, seconds 0, \ 11832 new_action drop, timeout 10 11833\end{verbatim} 11834 11835\subsection{Event Filtering} 11836\label{event_filtering} 11837 11838Event filtering can be used to reduce the number of logged alerts for noisy 11839rules by limiting the number of times a particular event is logged during a 11840specified time interval. This can be tuned to significantly reduce false 11841alarms. 11842 11843There are 3 types of event filters: 11844 11845\begin{itemize} 11846\item \texttt{limit} 11847 11848Alerts on the 1st \textit{m} events during the time interval, then ignores 11849events for the rest of the time interval. 11850 11851\item \texttt{threshold} 11852 11853Alerts every \textit{m} times we see this event during the time interval. 11854 11855\item \texttt{both} 11856 11857Alerts once per time interval after seeing \textit{m} occurrences of the event, 11858then ignores any additional events during the time interval. 11859 11860\end{itemize} 11861 11862\subsubsection{Format} 11863 11864\begin{verbatim} 11865 event_filter \ 11866 gen_id <gid>, sig_id <sid>, \ 11867 type <limit|threshold|both>, \ 11868 track <by_src|by_dst>, \ 11869 count <c>, seconds <s> 11870 11871 threshold \ 11872 gen_id <gid>, sig_id <sid>, \ 11873 type <limit|threshold|both>, \ 11874 track <by_src|by_dst>, \ 11875 count <c>, seconds <s> 11876\end{verbatim} 11877 11878\texttt{threshold} is an alias for \texttt{event\_filter}. Both formats are 11879equivalent and support the options described below - all are required. 11880\texttt{threshold} is deprecated and will not be supported in future releases. 11881 11882\begin{table}[h] 11883\begin{center} 11884\begin{tabular}{| l | p{4.5in} |} 11885 11886\hline 11887\textbf{Option} & \textbf{Description}\\ 11888\hline 11889 11890\hline 11891\texttt{gen\_id <gid>} & 11892 11893Specify the generator ID of an associated rule. \texttt{gen\_id 0, sig\_id 0} 11894can be used to specify a "global" threshold that applies to all rules.\\ 11895 11896\hline \texttt{sig\_id <sid>} & 11897 11898Specify the signature ID of an associated rule. \texttt{sig\_id 0} specifies a 11899"global" filter because it applies to all \texttt{sig\_id}s for the given 11900\texttt{gen\_id}.\\ 11901 11902\hline 11903\texttt{type limit|threshold|both} & 11904 11905type \texttt{limit} alerts on the 1st m events during the time interval, then 11906ignores events for the rest of the time interval. Type \texttt{threshold} 11907alerts every m times we see this event during the time interval. Type 11908\texttt{both} alerts once per time interval after seeing m occurrences of the 11909event, then ignores any additional events during the time interval.\\ 11910 11911\hline 11912\texttt{track by\_src|by\_dst} & 11913 11914rate is tracked either by source IP address, or destination IP address. This 11915means count is maintained for each unique source IP addresses, or for each 11916unique destination IP addresses. Ports or anything else are not tracked.\\ 11917 11918\hline 11919\texttt{count c} & 11920 11921number of rule matching in s seconds that will cause \texttt{event\_filter} 11922limit to be exceeded. \texttt{c} must be nonzero value. A value of -1 disables 11923the event filter and can be used to override the global \texttt{event\_filter}.\\ 11924 11925\hline 11926\texttt{seconds s} & 11927 11928time period over which \texttt{count} is accrued. \texttt{s} must be nonzero 11929value.\\ 11930 11931\hline 11932\end{tabular} 11933\end{center} 11934\end{table} 11935 11936\begin{note} 11937 11938Only one \texttt{event\_filter} may be defined for a given \texttt{gen\_id, 11939sig\_id}. If more than one \texttt{event\_filter} is applied to a specific 11940\texttt{gen\_id, sig\_id} pair, Snort will terminate with an error while 11941reading the configuration information. 11942 11943\end{note} 11944 11945\texttt{event\_filter}s with \texttt{sig\_id} 0 are considered "global" because 11946they apply to all rules with the given \texttt{gen\_id}. If \texttt{gen\_id} 11947is also 0, then the filter applies to all rules. (\texttt{gen\_id 0, sig\_id 11948!= 0} is not allowed). Standard filtering tests are applied first, if they do 11949not block an event from being logged, the global filtering test is applied. 11950Thresholds in a rule (deprecated) will override a global 11951\texttt{event\_filter}. Global \texttt{event\_filter}s do not override what's 11952in a signature or a more specific stand-alone \texttt{event\_filter}. 11953 11954\begin{note} 11955\texttt{event\_filters} can be used to suppress excessive \texttt{rate\_filter} 11956alerts, however, the first \texttt{new\_action} event of the timeout period is 11957never suppressed. Such events indicate a change of state that are significant 11958to the user monitoring the network. 11959\end{note} 11960 11961\subsubsection{Examples} 11962 11963Limit logging to 1 event per 60 seconds: 11964 11965\begin{verbatim} 11966 event_filter \ 11967 gen_id 1, sig_id 1851, \ 11968 type limit, track by_src, \ 11969 count 1, seconds 60 11970\end{verbatim} 11971 11972Limit logging to every 3rd event: 11973 11974\begin{verbatim} 11975 event_filter \ 11976 gen_id 1, sig_id 1852, \ 11977 type threshold, track by_src, \ 11978 count 3, seconds 60 11979\end{verbatim} 11980 11981Limit logging to just 1 event per 60 seconds, but only if we exceed 30 events 11982in 60 seconds: 11983 11984\begin{verbatim} 11985 event_filter \ 11986 gen_id 1, sig_id 1853, \ 11987 type both, track by_src, \ 11988 count 30, seconds 60 11989\end{verbatim} 11990 11991Limit to logging 1 event per 60 seconds per IP triggering each rule (rule 11992gen\_id is 1): 11993 11994\begin{verbatim} 11995 event_filter \ 11996 gen_id 1, sig_id 0, \ 11997 type limit, track by_src, \ 11998 count 1, seconds 60 11999\end{verbatim} 12000 12001Limit to logging 1 event per 60 seconds per IP, triggering each rule for each 12002event generator: 12003 12004\begin{verbatim} 12005 event_filter \ 12006 gen_id 0, sig_id 0, \ 12007 type limit, track by_src, \ 12008 count 1, seconds 60 12009\end{verbatim} 12010 12011Events in Snort are generated in the usual way, event filters are handled as 12012part of the output system. Read gen-msg.map for details on gen ids. 12013 12014Users can also configure a memcap for threshold with a ``config:'' option: 12015 12016\begin{verbatim} 12017 config event_filter: memcap <bytes> 12018 12019 # this is deprecated: 12020 config threshold: memcap <bytes> 12021\end{verbatim} 12022 12023\subsection{Event Suppression} 12024\label{event_suppression} 12025 12026Event suppression stops specified events from firing without removing the rule 12027from the rule base. Suppression uses an IP list to select specific networks and 12028users for suppression. Suppression tests are performed prior to either 12029standard or global thresholding tests. 12030 12031Suppression are standalone configurations that reference generators, SIDs, and 12032IP addresses via an IP list . This allows a rule to be completely suppressed, 12033or suppressed when the causative traffic is going to or coming from a specific 12034IP or group of IP addresses. 12035 12036You may apply multiple suppressions to a non-zero SID. You may also combine 12037one \texttt{event\_filter} and several suppressions to the same non-zero SID. 12038 12039\subsubsection{Format} 12040 12041The suppress configuration has two forms: 12042 12043\begin{verbatim} 12044 suppress \ 12045 gen_id <gid>, sig_id <sid> 12046\end{verbatim} 12047 12048\begin{verbatim} 12049 suppress \ 12050 gen_id <gid>, sig_id <sid>, \ 12051 track <by_src|by_dst>, ip <ip-list> 12052\end{verbatim} 12053 12054\begin{table}[h] 12055\begin{center} 12056\begin{tabular}{| l | p{4.5in} |} 12057 12058\hline 12059\textbf{Option} & \textbf{Description}\\ 12060\hline 12061 12062\hline 12063\texttt{gen\_id <gid>} & 12064 12065Specify the generator ID of an associated rule. \texttt{gen\_id 0, sig\_id 0} 12066can be used to specify a "global" threshold that applies to all rules.\\ 12067 12068\hline \texttt{sig\_id <sid>} & 12069 12070Specify the signature ID of an associated rule. \texttt{sig\_id 0} specifies a 12071"global" filter because it applies to all \texttt{sig\_id}s for the given 12072\texttt{gen\_id}.\\ 12073 12074\hline 12075\texttt{track by\_src|by\_dst} & 12076 12077Suppress by source IP address or destination IP address. This is optional, but 12078if present, \texttt{ip} must be provided as well.\\ 12079 12080\hline 12081\texttt{ip <list>} & 12082 12083Restrict the suppression to only source or destination IP addresses (indicated 12084by \texttt{track} parameter) determined by $<$list$>$. If track is provided, ip 12085must be provided as well.\\ 12086 12087\hline 12088\end{tabular} 12089\end{center} 12090\end{table} 12091 12092\subsubsection{Examples} 12093 12094Suppress this event completely: 12095 12096\begin{verbatim} 12097 suppress gen_id 1, sig_id 1852: 12098\end{verbatim} 12099 12100Suppress this event from this IP: 12101 12102\begin{verbatim} 12103 suppress gen_id 1, sig_id 1852, track by_src, ip 10.1.1.54 12104\end{verbatim} 12105 12106Suppress this event to this CIDR block: 12107 12108\begin{verbatim} 12109 suppress gen_id 1, sig_id 1852, track by_dst, ip 10.1.1.0/24 12110\end{verbatim} 12111 12112\subsection{Event Logging} 12113\label{eventqueue} 12114 12115Snort supports logging multiple events per packet/stream that are prioritized 12116with different insertion methods, such as max content length or event ordering 12117using the event queue. 12118 12119The general configuration of the event queue is as follows: 12120 12121\begin{verbatim} 12122 config event_queue: [max_queue [size]] [log [size]] [order_events [TYPE]] 12123\end{verbatim} 12124 12125\subsubsection{Event Queue Configuration Options} 12126 12127There are three configuration options to the configuration parameter 12128'event\_queue'. 12129 12130\begin{slist} 12131\item \texttt{max\_queue} 12132 12133This determines the maximum size of the event queue. For example, if the event 12134queue has a max size of 8, only 8 events will be stored for a single packet or 12135stream. 12136 12137The default value is 8. 12138 12139\item \texttt{log} 12140 12141This determines the number of events to log for a given packet or stream. You 12142can't log more than the max\_event number that was specified. 12143 12144The default value is 3. 12145 12146\item \texttt{order\_events} 12147 12148This argument determines the way that the incoming events are ordered. We 12149currently have two different methods: 12150 12151\begin{itemize} 12152 12153\item \texttt{priority} - The highest priority (1 being the highest) events are 12154ordered first. 12155 12156\item \texttt{content\_length} - Rules are ordered before decode or 12157preprocessor alerts, and rules that have a longer content are ordered before 12158rules with shorter contents. 12159 12160\end{itemize} 12161 12162The method in which events are ordered does not affect rule types such as pass, 12163alert, log, etc. 12164 12165The default value is content\_length. 12166\end{slist} 12167 12168\subsubsection{Event Queue Configuration Examples} 12169 12170The default configuration: 12171 12172\begin{verbatim} 12173 config event_queue: max_queue 8 log 3 order_events content_length 12174\end{verbatim} 12175 12176Example of a reconfigured event queue: 12177 12178\begin{verbatim} 12179 config event_queue: max_queue 10 log 3 order_events content_length 12180\end{verbatim} 12181 12182Use the default event queue values, but change event order: 12183 12184\begin{verbatim} 12185 config event_queue: order_events priority 12186\end{verbatim} 12187 12188Use the default event queue values but change the number of logged events: 12189 12190\begin{verbatim} 12191 config event_queue: log 2 12192\end{verbatim} 12193 12194\subsection{Event Trace} 12195\label{eventtrace} 12196 12197Snort supports logging additional information to a file about the events it is 12198generating relative to specific blocks of data that are matching the rule. 12199The blocks of data logged include information about the event, the GID, SID, 12200and other data related to the event itself, plus packet data including sizes, 12201timestamps, raw, normalized, and decompressed buffers extracted from the packet 12202that may have been used in evaluating the rule. The amount of packet data 12203written is limited with each entry. This is useful in debugging rules. 12204 12205The \texttt{config} option \texttt{event\_trace} to \texttt{snort.conf} 12206provides this control. 12207 12208The general configuration for event tracing is as follows: 12209 12210\begin{verbatim} 12211 config event_trace: [file <filename>] [max_data <int>] 12212\end{verbatim} 12213 12214The are two configuration options for \texttt{event\_trace}. 12215 12216\begin{slist} 12217\item \texttt{file} 12218 12219This sets the file name into which the trace data is written, within 12220Snort's log directory (see -l command line option). 12221 12222The default is event\_trace.txt. 12223 12224\item \texttt{max\_data} 12225 12226This specifies the maximum number of bytes from each buffer of data to write into 12227the file. 12228 12229The default is 64 bytes and valid values range from 1 to 65535 bytes. 12230 12231\end{slist} 12232 12233\subsubsection{Event Trace Examples} 12234 12235The default configuration: 12236 12237\begin{verbatim} 12238 config event_trace: file event_trace.txt max_data 64 12239\end{verbatim} 12240 12241Use the default file, but change the amount of data logged: 12242 12243\begin{verbatim} 12244 config event_trace: max_data 128 12245\end{verbatim} 12246 12247Change the file name to which event traces are logged: 12248 12249\begin{verbatim} 12250 config event_trace: file snort_event_trace.out 12251\end{verbatim} 12252 12253\section{Performance Profiling} 12254 12255Snort can provide statistics on rule and preprocessor performance. Each 12256require only a simple \texttt{config} option to \texttt{snort.conf} and Snort 12257will print statistics on the worst (or all) performers on exit. When a file 12258name is provided in \texttt{profile\_rules} or \texttt{profile\_preprocs}, the 12259statistics will be saved in these files. If \texttt{append} is not specified, 12260a new file will be created each time Snort is run. The filenames will have 12261timestamps appended to them. These files will be found in the logging 12262directory. 12263 12264To use this feature, you must build snort with the \texttt{--enable-perfprofiling} 12265option to the configure script. 12266 12267\subsection{Rule Profiling} 12268\label{rule profiling} 12269 12270\subsubsection{Format} 12271 12272\begin{verbatim} 12273 config profile_rules: \ 12274 print [all | <num>], \ 12275 sort <sort_option> \ 12276 [,filename <filename> [append]] 12277\end{verbatim} 12278 12279\begin{itemize} 12280\item \texttt{<num>} is the number of rules to print 12281\item \texttt{<sort\_option>} is one of: 12282 12283 \subitem \texttt{checks} 12284 \subitem \texttt{matches} 12285 \subitem \texttt{nomatches} 12286 \subitem \texttt{avg\_ticks} 12287 \subitem \texttt{avg\_ticks\_per\_match} 12288 \subitem \texttt{avg\_ticks\_per\_nomatch} 12289 \subitem \texttt{total\_ticks} 12290 12291\item \texttt{<filename>} is the output filename 12292 12293\item \texttt{[append]} dictates that the output will go to the same file each 12294time (optional) 12295 12296\end{itemize} 12297 12298\subsubsection{Examples} 12299\begin{itemize} 12300 12301\item Print all rules, sort by avg\_ticks (default configuration if option is turned on) 12302\subitem \texttt{config profile\_rules} 12303 12304\item Print all rules, sort by avg\_ticks, and append to file \texttt{rules\_stats.txt} 12305\subitem \texttt{config profile\_rules: filename \texttt{rules\_stats.txt} append} 12306 12307\item Print the top 10 rules, based on highest average time 12308\subitem \texttt{config profile\_rules: print 10, sort avg\_ticks} 12309 12310\item Print all rules, sorted by number of checks 12311\subitem \texttt{config profile\_rules: print all, sort checks} 12312 12313\item Print top 100 rules, based on total time 12314\subitem \texttt{config profile\_rules: print 100, sort total\_ticks} 12315 12316\item Print with default options, save results to performance.txt each time 12317\subitem \texttt{config profile\_rules: filename performance.txt append} 12318 12319\item Print top 20 rules, save results to perf.txt with timestamp in filename 12320\subitem \texttt{config profile\_rules: print 20, filename perf.txt} 12321 12322\end{itemize} 12323 12324\subsubsection{Output} 12325 12326Snort will print a table much like the following at exit. 12327 12328\begin{figure} 12329\footnotesize{ 12330\begin{verbatim} 12331Rule Profile Statistics (worst 4 rules) 12332========================================================== 12333 Num SID GID Rev Checks Matches Alerts Ticks Avg/Check Avg/Match Avg/Nonmatch 12334 === === === === ====== ======= ====== ===== ========= ========= ============ 12335 1 2389 1 12 1 1 1 385698 385698.0 385698.0 0.0 12336 2 2178 1 17 2 0 0 107822 53911.0 0.0 53911.0 12337 3 2179 1 8 2 0 0 92458 46229.0 0.0 46229.0 12338 4 1734 1 37 2 0 0 90054 45027.0 0.0 45027.0 12339\end{verbatim} 12340} 12341\caption{\label{rule profiling example output}Rule Profiling Example Output} 12342\end{figure} 12343 12344Configuration line used to print the above table: 12345 12346\subitem \texttt{config profile\_rules: print 4, sort total\_ticks} 12347 12348The columns represent: 12349 12350\begin{itemize} 12351\item Number (rank) 12352\item Sig ID 12353\item Generator ID 12354\item Checks (number of times rule was evaluated after fast pattern match 12355 within portgroup or any-$>$any rules) 12356\item Matches (number of times ALL rule options matched, will be high for 12357 rules that have no options) 12358\item Alerts (number of alerts generated from this rule) 12359\item CPU Ticks 12360\item Avg Ticks per Check 12361\item Avg Ticks per Match 12362\item Avg Ticks per Nonmatch 12363\end{itemize} 12364 12365Interpreting this info is the key. The Microsecs (or Ticks) column is 12366important because that is the total time spent evaluating a given rule. But, 12367if that rule is causing alerts, it makes sense to leave it alone. 12368 12369A high Avg/Check is a poor performing rule, that most likely contains PCRE. 12370High Checks and low Avg/Check is usually an any-$>$any rule with few rule 12371options and no content. Quick to check, the few options may or may not match. 12372We are looking at moving some of these into code, especially those with low 12373SIDs. 12374 12375By default, this information will be printed to the console when Snort exits. 12376You can use the "filename" option in snort.conf to specify a file where this 12377will be written. If "append" is not specified, a new file will be created each 12378time Snort is run. The filenames will have timestamps appended to them. These 12379files will be found in the logging directory. 12380 12381\subsection{Preprocessor Profiling} 12382\label{preproc profiling} 12383 12384\subsubsection{Format} 12385 12386\begin{verbatim} 12387 config profile_preprocs: \ 12388 print [all | <num>], \ 12389 sort <sort_option> \ 12390 [, filename <filename> [append]] 12391\end{verbatim} 12392 12393\begin{itemize} 12394\item \texttt{<num>} is the number of preprocessors to print 12395\item \texttt{<sort\_option>} is one of: 12396\subitem \texttt{checks} 12397\subitem \texttt{avg\_ticks} 12398\subitem \texttt{total\_ticks} 12399\item \texttt{<filename>} is the output filename 12400\item \texttt{[append]} dictates that the output will go to the same file each time (optional) 12401\end{itemize} 12402 12403\subsubsection{Examples} 12404 12405\begin{itemize} 12406 12407\item Print all preprocessors, sort by avg\_ticks (default configuration if 12408option is turned on) 12409\subitem \texttt{config profile\_preprocs} 12410 12411\item Print all preprocessors, sort by avg\_ticks, and append to file 12412\texttt{preprocs\_stats.txt} 12413\subitem \texttt{config profile\_preprocs: filename \texttt{preprocs\_stats.txt} append} 12414 12415\item Print the top 10 preprocessors, based on highest average time 12416\subitem \texttt{config profile\_preprocs: print 10, sort avg\_ticks} 12417 12418\item Print all preprocessors, sorted by number of checks 12419\subitem \texttt{config profile\_preprocs: print all, sort checks} 12420 12421\end{itemize} 12422 12423\subsubsection{Output} 12424 12425Snort will print a table much like the following at exit. 12426 12427\begin{figure} 12428\footnotesize{ 12429\begin{verbatim} 12430Preprocessor Profile Statistics (worst 10) 12431========================================================== 12432 Num Preprocessor Layer Checks Exits Microsecs Avg/Check Pct of Caller Pct of Total 12433 === ============ ===== ====== ===== ========= ========= ============= ============ 12434 1 detect 0 338181 338181 9054573 26.77 64.62 64.62 12435 1 rule eval 1 256978 256978 2570596 10.00 28.39 18.35 12436 1 rule tree eval 2 399860 399860 2520629 6.30 98.06 17.99 12437 1 pcre 3 51328 51328 505636 9.85 20.06 3.61 12438 2 byte_jump 3 6 6 7 1.30 0.00 0.00 12439 3 content 3 1077588 1077588 1123373 1.04 44.57 8.02 12440 4 uricontent 3 106498 106498 79685 0.75 3.16 0.57 12441 5 byte_test 3 9951 9951 5709 0.57 0.23 0.04 12442 6 isdataat 3 8486 8486 3192 0.38 0.13 0.02 12443 7 flowbits 3 135739 135739 35365 0.26 1.40 0.25 12444 8 flags 3 2 2 0 0.20 0.00 0.00 12445 9 preproc_rule_options 3 15499 15499 1939 0.13 0.08 0.01 12446 10 flow 3 394817 394817 36420 0.09 1.44 0.26 12447 11 file_data 3 15957 15957 1264 0.08 0.05 0.01 12448 12 ack 3 4 4 0 0.07 0.00 0.00 12449 2 rtn eval 2 36928 36928 17500 0.47 0.68 0.12 12450 2 mpse 1 646528 646528 5840244 9.03 64.50 41.68 12451 2 s5 0 310080 310080 3270702 10.55 23.34 23.34 12452 1 s5tcp 1 310080 310080 2993020 9.65 91.51 21.36 12453 1 s5TcpState 2 304484 304484 2559085 8.40 85.50 18.26 12454 1 s5TcpFlush 3 22148 22148 70681 3.19 2.76 0.50 12455 1 s5TcpProcessRebuilt 4 22132 22132 2018748 91.21 2856.11 14.41 12456 2 s5TcpBuildPacket 4 22132 22132 34965 1.58 49.47 0.25 12457 2 s5TcpData 3 184186 184186 120794 0.66 4.72 0.86 12458 1 s5TcpPktInsert 4 46249 46249 89299 1.93 73.93 0.64 12459 2 s5TcpNewSess 2 5777 5777 37958 6.57 1.27 0.27 12460 3 httpinspect 0 204751 204751 1814731 8.86 12.95 12.95 12461 4 ssl 0 10780 10780 16283 1.51 0.12 0.12 12462 5 decode 0 312638 312638 437860 1.40 3.12 3.12 12463 6 DceRpcMain 0 155358 155358 186061 1.20 1.33 1.33 12464 1 DceRpcSession 1 155358 155358 156193 1.01 83.95 1.11 12465 7 backorifice 0 77 77 42 0.55 0.00 0.00 12466 8 smtp 0 45197 45197 17126 0.38 0.12 0.12 12467 9 ssh 0 26453 26453 7195 0.27 0.05 0.05 12468 10 dns 0 28 28 5 0.18 0.00 0.00 12469 total total 0 311202 311202 14011946 45.03 0.00 0.00 12470\end{verbatim} 12471} 12472\caption{Preprocessor Profiling Example Output} 12473\label{preprocessor profiling example output} 12474\end{figure} 12475 12476Configuration line used to print the above table: 12477 12478\begin{verbatim} 12479 config profile_preprocs: \ 12480 print 10, sort total_ticks 12481\end{verbatim} 12482 12483The columns represent: 12484 12485\begin{itemize} 12486 12487\item Number (rank) - The number is indented for each layer. Layer 1 12488preprocessors are listed under their respective caller (and sorted similarly). 12489 12490\item Preprocessor Name 12491 12492\item Layer - When printing a specific number of preprocessors all subtasks 12493info for a particular preprocessor is printed for each layer 0 preprocessor 12494stat. 12495 12496\item Checks (number of times preprocessor decided to look at a packet, ports 12497matched, app layer header was correct, etc) 12498 12499\item Exits (number of corresponding exits -- just to verify code is 12500instrumented correctly, should ALWAYS match Checks, unless an exception was 12501trapped) 12502 12503\item CPU Ticks 12504 12505\item Avg Ticks per Check 12506 12507\item Percent of caller - For non layer 0 preprocessors, i.e. subroutines 12508within preprocessors, this identifies the percent of the caller's ticks that is 12509spent for this subtask. 12510 12511\end{itemize} 12512 12513Because of task swapping, non-instrumented code, and other factors, the Pct of 12514Caller field will not add up to 100\% of the caller's time. It does give a 12515reasonable indication of how much relative time is spent within each subtask. 12516 12517By default, this information will be printed to the console when Snort exits. 12518You can use the "filename" option in snort.conf to specify a file where this 12519will be written. If "append" is not specified, a new file will be created each 12520time Snort is run. The filenames will have timestamps appended to them. These 12521files will be found in the logging directory. 12522 12523\subsection{Packet Performance Monitoring (PPM)} 12524\label{ppm} 12525PPM provides thresholding mechanisms that can be used to provide a basic 12526level of latency control for snort. It does not provide a hard and fast 12527latency guarantee but should in effect provide a good average latency 12528control. Both rules and packets can be checked for latency. The action 12529taken upon detection of excessive latency is configurable. The following 12530sections describe configuration, sample output, and some implementation 12531details worth noting. 12532 12533To use PPM, you must build with the --enable-ppm or the --enable-sourcefire 12534option to configure. 12535 12536PPM is configured as follows: 12537 12538\begin{verbatim} 12539 # Packet configuration: 12540 config ppm: max-pkt-time <micro-secs>, \ 12541 fastpath-expensive-packets, \ 12542 pkt-log, \ 12543 debug-pkts 12544 12545 # Rule configuration: 12546 config ppm: max-rule-time <micro-secs>, \ 12547 threshold count, \ 12548 suspend-expensive-rules, \ 12549 suspend-timeout <seconds>, \ 12550 rule-log [log] [alert] 12551\end{verbatim} 12552 12553Packets and rules can be configured separately, as above, or together in just 12554one config ppm statement. Packet and rule monitoring is independent, so one or 12555both or neither may be enabled. 12556 12557\subsubsection{Configuration} 12558 12559Packet Configuration Options 12560 12561\texttt{max-pkt-time <micro-secs>} 12562\begin{itemize} 12563\item enables packet latency thresholding using 'micros-secs' as the limit. 12564\item default is 0 (packet latency thresholding disabled) 12565\item reasonable starting defaults: 100/250/1000 for 1G/100M/5M nets 12566\end{itemize} 12567 12568\texttt{fastpath-expensive-packets} 12569\begin{itemize} 12570\item enables stopping further inspection of a packet if the max time is 12571 exceeded 12572\item default is off 12573\end{itemize} 12574 12575\texttt{pkt-log} 12576\begin{itemize} 12577\item enables logging packet event if packet exceeds max-pkt-time 12578\item default is no logging 12579\item if no option is given for 'pkt-log', 'pkt-log log' is implied 12580\item the log option enables output to syslog or console depending 12581 upon snort configuration 12582\end{itemize} 12583 12584\texttt{debug-pkts} 12585\begin{itemize} 12586\item must build with the --enable-debug option to configure 12587\item enables per packet timing stats to be printed after each packet 12588\item default is off 12589\end{itemize} 12590 12591Rule Configuration Options 12592 12593\texttt{max-rule-time <micro-secs>} 12594\begin{itemize} 12595\item enables rule latency thresholding using 'micros-secs' as the limit. 12596\item default is 0 (rule latency thresholding disabled) 12597\item reasonable starting defaults: 100/250/1000 for 1G/100M/5M nets 12598\end{itemize} 12599 12600\texttt{threshold <count>} 12601\begin{itemize} 12602\item sets the number of cumulative rule time excesses before disabling 12603 a rule 12604\item default is 5 12605\end{itemize} 12606 12607\texttt{suspend-expensive-rules} 12608\begin{itemize} 12609\item enables suspending rule inspection if the max rule time is exceeded 12610\item default is off 12611\end{itemize} 12612 12613\texttt{suspend-timeout <seconds>} 12614\begin{itemize} 12615\item rule suspension time in seconds 12616\item default is 60 seconds 12617\item set to zero to permanently disable expensive rules 12618\end{itemize} 12619 12620\texttt{rule-log [log] [alert]} 12621\begin{itemize} 12622\item enables event logging output for rules 12623\item default is no logging 12624\item one or both of the options 'log' and 'alert' must be used with 12625 'rule-log' 12626\item the log option enables output to syslog or console depending 12627 upon snort configuration 12628\end{itemize} 12629 12630\subsubsection{Examples} 12631 12632Example 1: 12633The following enables packet tracking: 12634 12635\begin{verbatim} 12636 config ppm: max-pkt-time 100 12637\end{verbatim} 12638 12639The following enables rule tracking: 12640 12641\begin{verbatim} 12642 config ppm: max-rule-time 50, threshold 5 12643\end{verbatim} 12644 12645If fastpath-expensive-packets or suspend-expensive-rules is not used, then 12646no action is taken other than to increment the count of the number of 12647packets that should be fastpath'd or the rules that should be suspended. A 12648summary of this information is printed out when snort exits. 12649 12650Example 2: 12651 12652The following suspends rules and aborts packet inspection. These rules were 12653used to generate the sample output that follows. 12654 12655\begin{verbatim} 12656 config ppm: \ 12657 max-pkt-time 50, fastpath-expensive-packets, \ 12658 pkt-log, debug-pkts 12659 12660 config ppm: \ 12661 max-rule-time 50, threshold 5, suspend-expensive-rules, \ 12662 suspend-timeout 300, rule-log log alert 12663\end{verbatim} 12664 12665\subsubsection{Sample Snort Output} 12666 12667Sample Snort Startup Output 12668 12669\begin{verbatim} 12670 Packet Performance Monitor Config: 12671 ticks per usec : 1600 ticks 12672 max packet time : 50 usecs 12673 packet action : fastpath-expensive-packets 12674 packet logging : log 12675 debug-pkts : disabled 12676 12677 Rule Performance Monitor Config: 12678 ticks per usec : 1600 ticks 12679 max rule time : 50 usecs 12680 rule action : suspend-expensive-rules 12681 rule threshold : 5 12682 suspend timeout : 300 secs 12683 rule logging : alert log 12684\end{verbatim} 12685 12686Sample Snort Run-time Output 12687 12688\begin{verbatim} 12689 ... 12690 PPM: Process-BeginPkt[61] caplen=60 12691 PPM: Pkt[61] Used= 8.15385 usecs 12692 PPM: Process-EndPkt[61] 12693 12694 PPM: Process-BeginPkt[62] caplen=342 12695 PPM: Pkt[62] Used= 65.3659 usecs 12696 PPM: Process-EndPkt[62] 12697 12698 PPM: Pkt-Event Pkt[63] used=56.0438 usecs, 0 rules, 1 nc-rules tested, packet fastpathed 12699 (10.4.12.224:0 -> 10.4.14.108:54321). 12700 PPM: Process-BeginPkt[63] caplen=60 12701 PPM: Pkt[63] Used= 8.394 usecs 12702 PPM: Process-EndPkt[63] 12703 12704 PPM: Process-BeginPkt[64] caplen=60 12705 PPM: Pkt[64] Used= 8.21764 usecs 12706 PPM: Process-EndPkt[64] 12707 ... 12708\end{verbatim} 12709 12710Sample Snort Exit Output 12711 12712\begin{verbatim} 12713 Packet Performance Summary: 12714 max packet time : 50 usecs 12715 packet events : 1 12716 avg pkt time : 0.633125 usecs 12717 Rule Performance Summary: 12718 max rule time : 50 usecs 12719 rule events : 0 12720 avg nc-rule time : 0.2675 usecs 12721\end{verbatim} 12722 12723\subsubsection{Implementation Details} 12724 12725\begin{itemize} 12726 12727\item Enforcement of packet and rule processing times is done after processing 12728each rule. Latency control is not enforced after each preprocessor. 12729 12730\item This implementation is software based and does not use an interrupt 12731driven timing mechanism and is therefore subject to the granularity of the 12732software based timing tests. Due to the granularity of the timing measurements 12733any individual packet may exceed the user specified packet or rule processing 12734time limit. Therefore this implementation cannot implement a precise latency 12735guarantee with strict timing guarantees. Hence the reason this is considered a 12736best effort approach. 12737 12738\item Since this implementation depends on hardware based high performance 12739frequency counters, latency thresholding is presently only available on Intel 12740and PPC platforms. 12741 12742\item Time checks are made based on the total system time, not processor usage 12743by Snort. This was a conscious design decision because when a system is 12744loaded, the latency for a packet is based on the total system time, not just 12745the processor time the Snort application receives. Therefore, it is 12746recommended that you tune your thresholding to operate optimally when your 12747system is under load. 12748 12749\end{itemize} 12750 12751\section{Output Modules} 12752\label{output config} 12753 12754Output modules are new as of version 1.6. They allow Snort to be much more 12755flexible in the formatting and presentation of output to its users. The output 12756modules are run when the alert or logging subsystems of Snort are called, after 12757the preprocessors and detection engine. The format of the directives in the 12758config file is very similar to that of the preprocessors. 12759 12760Multiple output plugins may be specified in the Snort configuration file. When 12761multiple plugins of the same type (log, alert) are specified, they are stacked 12762and called in sequence when an event occurs. As with the standard logging and 12763alerting systems, output plugins send their data to /var/log/snort by default 12764or to a user directed directory (using the -l command line switch). 12765 12766Output modules are loaded at runtime by specifying the output keyword in the 12767config file: 12768 12769\begin{verbatim} 12770 output <name>: <options> 12771\end{verbatim} 12772 12773\begin{verbatim} 12774 output alert_syslog: log_auth log_alert 12775\end{verbatim} 12776 12777\subsection{alert\_syslog} 12778\label{alert syslog label} 12779 12780This module sends alerts to the syslog facility (much like the -s command line 12781switch). This module also allows the user to specify the logging facility and 12782priority within the Snort config file, giving users greater flexibility in 12783logging alerts. 12784 12785\subsubsection{Available Keywords} 12786 12787\paragraph{Facilities} 12788 12789\begin{itemize} 12790\item \texttt{log\_auth} 12791\item \texttt{log\_authpriv} 12792\item \texttt{log\_daemon} 12793\item \texttt{log\_local0} 12794\item \texttt{log\_local1} 12795\item \texttt{log\_local2} 12796\item \texttt{log\_local3} 12797\item \texttt{log\_local4} 12798\item \texttt{log\_local5} 12799\item \texttt{log\_local6} 12800\item \texttt{log\_local7} 12801\item \texttt{log\_user} 12802\end{itemize} 12803 12804\paragraph{Priorities} 12805 12806\begin{itemize} 12807\item \texttt{log\_emerg} 12808\item \texttt{log\_alert} 12809\item \texttt{log\_crit} 12810\item \texttt{log\_err} 12811\item \texttt{log\_warning} 12812\item \texttt{log\_notice} 12813\item \texttt{log\_info} 12814\item \texttt{log\_debug} 12815\end{itemize} 12816 12817\paragraph{Options} 12818 12819\begin{itemize} 12820\item \texttt{log\_cons} 12821\item \texttt{log\_ndelay} 12822\item \texttt{log\_perror} 12823\item \texttt{log\_pid} 12824\end{itemize} 12825 12826\subsubsection{Format} 12827 12828\begin{verbatim} 12829 alert_syslog: \ 12830 <facility> <priority> <options> 12831\end{verbatim} 12832 12833\begin{note} 12834 12835As WIN32 does not run syslog servers locally by default, a hostname and port 12836can be passed as options. The default host is 127.0.0.1. The default port is 12837514. 12838 12839\end{note} 12840 12841\begin{verbatim} 12842 output alert_syslog: \ 12843 [host=<hostname[:<port>],] \ 12844 <facility> <priority> <options> 12845\end{verbatim} 12846 12847\subsubsection{Example} 12848 12849\begin{verbatim} 12850 output alert_syslog: host=10.1.1.1:514, <facility> <priority> <options> 12851\end{verbatim} 12852 12853\subsection{alert\_fast} 12854 12855This will print Snort alerts in a quick one-line format to a specified output 12856file. It is a faster alerting method than full alerts because it doesn't need 12857to print all of the packet headers to the output file and because it logs to 12858only 1 file. 12859 12860\subsubsection{Format} 12861 12862\begin{verbatim} 12863 output alert_fast: [<filename> ["packet"] [<limit>]] 12864 <limit> ::= <number>[('G'|'M'|K')] 12865\end{verbatim} 12866 12867\begin{itemize} 12868\item \texttt{filename}: the name of the log file. The default name is 12869$<$logdir$>$/alert. You may specify "stdout" for terminal output. The name may 12870include an absolute or relative path. 12871 12872\item \texttt{packet}: this option will cause multiline entries with full 12873packet headers to be logged. By default, only brief single-line entries are 12874logged. 12875 12876\item \texttt{limit}: an optional limit on file size which defaults to 128 MB. 12877The minimum is 1 KB. See \ref{Log Limits} for more information. 12878\end{itemize} 12879 12880\subsubsection{Example} 12881 12882\begin{verbatim} 12883 output alert_fast: alert.fast 12884\end{verbatim} 12885 12886\subsection{alert\_full} 12887 12888This will print Snort alert messages with full packet headers. The alerts will 12889be written in the default logging directory (/var/log/snort) or in the logging 12890directory specified at the command line. 12891 12892Inside the logging directory, a directory will be created per IP. These files 12893will be decoded packet dumps of the packets that triggered the alerts. The 12894creation of these files slows Snort down considerably. This output method is 12895discouraged for all but the lightest traffic situations. 12896 12897\subsubsection{Format} 12898 12899\begin{verbatim} 12900 output alert_full: [<filename> [<limit>]] 12901 <limit> ::= <number>[('G'|'M'|K')] 12902\end{verbatim} 12903 12904\begin{itemize} 12905\item \texttt{filename}: the name of the log file. The default name is 12906$<$logdir$>$/alert. You may specify "stdout" for terminal output. The name may 12907include an absolute or relative path. 12908 12909\item \texttt{limit}: an optional limit on file size which defaults to 128 MB. 12910The minimum is 1 KB. See \ref{Log Limits} for more information. 12911\end{itemize} 12912 12913\subsubsection{Example} 12914 12915\begin{verbatim} 12916 output alert_full: alert.full 12917\end{verbatim} 12918 12919\subsection{alert\_unixsock} 12920 12921Sets up a UNIX domain socket and sends alert reports to it. External 12922programs/processes can listen in on this socket and receive Snort alert and 12923packet data in real time. 12924 12925\subsubsection{Format} 12926 12927\begin{verbatim} 12928 alert_unixsock 12929\end{verbatim} 12930 12931\subsubsection{Example} 12932 12933\begin{verbatim} 12934 output alert_unixsock 12935\end{verbatim} 12936 12937\begin{note} 12938On FreeBSD, the default \texttt{sysctl} value for \texttt{net.local.dgram.recvspace} 12939is too low for \texttt{alert\_unixsock} datagrams and you will likely not receive any 12940data. You can change this value after booting by running: 12941\begin{verbatim} 12942 12943$ sudo sysctl net.local.dgram.recvspace=100000 12944 12945\end{verbatim} 12946To have this value set on each boot automatically, add the following to \texttt{/etc/sysctl.conf}: 12947\begin{verbatim} 12948 12949net.local.dgram.recvspace=100000 12950 12951\end{verbatim} 12952Note that the value of 100000 may be slightly generous, but the value should be at least 65864. 12953\end{note} 12954 12955\subsection{log\_tcpdump} 12956 12957The log\_tcpdump module logs packets to a tcpdump-formatted file. This is 12958useful for performing post-process analysis on collected traffic with the vast 12959number of tools that are available for examining tcpdump-formatted files. 12960 12961\subsubsection{Format} 12962 12963\begin{verbatim} 12964 output log_tcpdump: [<filename> [<limit>]] 12965 <limit> ::= <number>[('G'|'M'|K')] 12966\end{verbatim} 12967 12968\begin{itemize} 12969\item \texttt{filename}: the name of the log file. The default name is 12970$<$logdir$>$/snort.log. The name may include an absolute or relative path. A 12971UNIX timestamp is appended to the filename. 12972 12973\item \texttt{limit}: an optional limit on file size which defaults to 128 MB. 12974When a sequence of packets is to be logged, the aggregate size is used to test 12975the rollover condition. See \ref{Log Limits} for more information. 12976\end{itemize} 12977 12978\subsubsection{Example} 12979 12980\begin{verbatim} 12981 output log_tcpdump: snort.log 12982\end{verbatim} 12983 12984\subsection{csv} 12985 12986The csv output plugin allows alert data to be written in a format easily 12987importable to a database. The output fields and their order may be customized. 12988 12989\subsubsection{Format} 12990 12991\begin{verbatim} 12992 output alert_csv: [<filename> [<format> [<limit>]]] 12993 <format> ::= "default"|<list> 12994 <list> ::= <field>(,<field>)* 12995 <field> ::= "dst"|"src"|"ttl" ... 12996 <limit> ::= <number>[('G'|'M'|K')] 12997\end{verbatim} 12998 12999\begin{itemize} 13000\item \texttt{filename}: the name of the log file. The default name is 13001$<$logdir$>$/alert.csv. You may specify "stdout" for terminal output. The name 13002may include an absolute or relative path. 13003 13004\item \texttt{format}: The list of formatting options is below. If the 13005formatting option is "default", the output is in the order of the formatting 13006options listed. 13007 13008\begin{itemize} 13009\item \texttt{timestamp} 13010\item \texttt{sig\_generator} 13011\item \texttt{sig\_id} 13012\item \texttt{sig\_rev} 13013\item \texttt{msg} 13014\item \texttt{proto} 13015\item \texttt{src} 13016\item \texttt{srcport} 13017\item \texttt{dst} 13018\item \texttt{dstport} 13019\item \texttt{ethsrc} 13020\item \texttt{ethdst} 13021\item \texttt{ethlen} 13022\item \texttt{tcpflags} 13023\item \texttt{tcpseq} 13024\item \texttt{tcpack} 13025\item \texttt{tcplen} 13026\item \texttt{tcpwindow} 13027\item \texttt{ttl} 13028\item \texttt{tos} 13029\item \texttt{id} 13030\item \texttt{dgmlen} 13031\item \texttt{iplen} 13032\item \texttt{icmptype} 13033\item \texttt{icmpcode} 13034\item \texttt{icmpid} 13035\item \texttt{icmpseq} 13036\end{itemize} 13037 13038\item \texttt{limit}: an optional limit on file size which defaults to 128 MB. 13039The minimum is 1 KB. See \ref{Log Limits} for more information. 13040\end{itemize} 13041 13042\subsubsection{Example} 13043 13044\begin{verbatim} 13045 output alert_csv: /var/log/alert.csv default 13046 13047 output alert_csv: /var/log/alert.csv timestamp, msg 13048\end{verbatim} 13049 13050\subsection{unified 2} 13051 13052Unified2 can work in one of three modes, packet logging, alert logging, or true 13053unified logging. Packet logging includes a capture of the entire packet and is 13054specified with \texttt{log\_unified2}. Likewise, alert logging will only log 13055events and is specified with \texttt{alert\_unified2}. To include both logging 13056styles in a single, unified file, simply specify \texttt{unified2}. 13057 13058When MPLS support is turned on, MPLS labels can be included in unified2 events. 13059Use option \texttt{mpls\_event\_types} to enable this. If option 13060\texttt{mpls\_event\_types} is not used, then MPLS labels will be not be 13061included in unified2 events. 13062 13063\begin{note} 13064 13065By default, unified 2 files have the file creation time (in Unix Epoch format) 13066appended to each file when it is created. 13067 13068\end{note} 13069 13070\subsubsection{Format} 13071 13072\begin{verbatim} 13073 output alert_unified2: \ 13074 filename <base filename> [, <limit <size in MB>] [, nostamp] [, mpls_event_types] \ 13075 [, vlan_event_types] 13076 13077 output log_unified2: \ 13078 filename <base filename> [, <limit <size in MB>] [, nostamp] 13079 13080 output unified2: \ 13081 filename <base file name> [, <limit <size in MB>] [, nostamp] [, mpls_event_types] \ 13082 [, vlan_event_types] 13083\end{verbatim} 13084 13085\subsubsection{Example} 13086 13087\begin{verbatim} 13088 output alert_unified2: filename snort.alert, limit 128, nostamp 13089 output log_unified2: filename snort.log, limit 128, nostamp 13090 output unified2: filename merged.log, limit 128, nostamp 13091 output unified2: filename merged.log, limit 128, nostamp, mpls_event_types 13092 output unified2: filename merged.log, limit 128, nostamp, vlan_event_types 13093\end{verbatim} 13094 13095\subsubsection{Extra Data Configurations} 13096 13097 Unified2 also has logging support for various extra data. The 13098 following configuration items will enable these extra data logging 13099 facilities. 13100 13101\begin{verbatim} 13102config log_ipv6_extra_data 13103\end{verbatim} 13104 13105This option enables Snort to log IPv6 source and destination 13106address as unified2 extra data events. 13107 13108See section \ref{Config} for more information 13109 13110\begin{verbatim} 13111enable_xff 13112\end{verbatim} 13113 13114This option enables HTTP Inspect to parse and log the original 13115client IP present in the X-Forwarded-For, True-Client-IP, or custom 13116HTTP request headers along with the generated events. 13117 13118See section \ref{sub:http-inspect} for more information 13119 13120\begin{verbatim} 13121log_uri 13122\end{verbatim} 13123 13124This option enables HTTP Inspect to parse and log the URI data 13125from the HTTP request and log it along with all the generated 13126events for that session. 13127 13128See section \ref{sub:http-inspect} for more information 13129 13130\begin{verbatim} 13131log_hostname 13132\end{verbatim} 13133 13134This option enables HTTP Inspect to parse and log the Host header 13135data from the HTTP request and log it along with all the generated 13136events for that session. 13137 13138See section \ref{sub:http-inspect} for more information 13139 13140\begin{verbatim} 13141log_hostname 13142\end{verbatim} 13143 13144This option enables HTTP Inspect to parse and log the Host header 13145data from the HTTP request and log it along with all the generated 13146events for that session. 13147 13148See section \ref{sub:http-inspect} for more information 13149 13150\begin{verbatim} 13151log_mailfrom 13152\end{verbatim} 13153 13154This option enables SMTP preprocessor to parse and log the senders 13155email address extracted from the "MAIL FROM" command along with 13156all the generated events for that session. 13157 13158See section \ref{SMTP} for more information 13159 13160\begin{verbatim} 13161log_rcptto 13162\end{verbatim} 13163 13164This option enables SMTP preprocessor to parse and log the 13165recipients email address extracted from the "RCPT TO" command 13166along with all the generated events for that session. 13167 13168See section \ref{SMTP} for more information 13169 13170\begin{verbatim} 13171log_filename 13172\end{verbatim} 13173 13174This option enables SMTP preprocessor to parse and log the MIME 13175attachment filenames extracted from the Content-Disposition header 13176within the MIME body along with all the generated events for that 13177session. 13178 13179See section \ref{SMTP} for more information 13180 13181\begin{verbatim} 13182log_email_hdrs 13183\end{verbatim} 13184 13185This option enables SMTP preprocessor to parse and log the SMTP 13186email headers extracted from the SMTP data along with all the 13187generated events for that session. 13188 13189See section \ref{SMTP} for more information 13190 13191\subsubsection{Reading Unified2 Files} 13192 13193\subsubsection{U2SpewFoo} 13194 13195U2SpewFoo is a lightweight tool for dumping the contents of unified2 files to stdout. 13196 13197\textbf Example usage: 13198 13199\begin{verbatim} 13200 u2spewfoo snort.log 13201\end{verbatim} 13202 13203 13204\textbf Example Output: 13205 13206\begin{verbatim} 13207(Event) 13208 sensor id: 0 event id: 4 event second: 1299698138 event microsecond: 146591 13209 sig id: 1 gen id: 1 revision: 0 classification: 0 13210 priority: 0 ip source: 10.1.2.3 ip destination: 10.9.8.7 13211 src port: 60710 dest port: 80 protocol: 6 impact_flag: 0 blocked: 0 13212 13213Packet 13214 sensor id: 0 event id: 4 event second: 1299698138 13215 packet second: 1299698138 packet microsecond: 146591 13216 linktype: 1 packet_length: 54 13217[ 0] 02 09 08 07 06 05 02 01 02 03 04 05 08 00 45 00 ..............E. 13218[ 16] 00 28 00 06 00 00 40 06 5C B7 0A 01 02 03 0A 09 .(....@.\....... 13219[ 32] 08 07 ED 26 00 50 00 00 00 62 00 00 00 2D 50 10 ...&.P...b...-P. 13220[ 48] 01 00 A2 BB 00 00 ...... 13221 13222(ExtraDataHdr) 13223 event type: 4 event length: 33 13224 13225(ExtraData) 13226 sensor id: 0 event id: 2 event second: 1299698138 13227 type: 9 datatype: 1 bloblength: 9 HTTP URI: / 13228 13229(ExtraDataHdr) 13230 event type: 4 event length: 78 13231 13232(ExtraData) 13233 sensor id: 0 event id: 2 event second: 1299698138 13234 type: 10 datatype: 1 bloblength: 12 HTTP Hostname: example.com 13235\end{verbatim} 13236 13237\subsubsection{U2Boat} 13238 13239U2boat is a tool for converting unified2 files into different formats. 13240 13241Currently supported conversion formats are: pcap 13242 13243\textbf Example usage: 13244\begin{verbatim} 13245 u2boat -t pcap <infile> <outfile> 13246\end{verbatim} 13247 13248\subsection{log null} 13249 13250Sometimes it is useful to be able to create rules that will alert to certain 13251types of traffic but will not cause packet log entries. In Snort 1.8.2, the 13252log\_null plugin was introduced. This is equivalent to using the -n command 13253line option but it is able to work within a ruletype. 13254 13255\subsubsection{Format} 13256 13257\begin{verbatim} 13258 output log_null 13259\end{verbatim} 13260 13261\subsubsection{Example} 13262 13263\begin{verbatim} 13264 output log_null # like using snort -n 13265 13266 ruletype info { 13267 type alert 13268 output alert_fast: info.alert 13269 output log_null 13270 } 13271\end{verbatim} 13272 13273\subsection{Log Limits} 13274\label{Log Limits} 13275 13276This section pertains to logs produced by \texttt{alert\_fast}, 13277\texttt{alert\_full}, \texttt{alert\_csv}, and \texttt{log\_tcpdump}. 13278\texttt{unified2} also may be given limits. Those limits 13279are described in the respective sections. 13280 13281When a configured limit is reached, the current log is closed and a new log is 13282opened with a UNIX timestamp appended to the configured log name. 13283 13284Limits are configured as follows: 13285 13286\begin{verbatim} 13287 <limit> ::= <number>[(<gb>|<mb>|<kb>)] 13288 <gb> ::= 'G'|'g' 13289 <mb> ::= 'M'|'m' 13290 <kb> ::= 'K'|'k' 13291\end{verbatim} 13292 13293Rollover will occur at most once per second so if limit is too small for 13294logging rate, limit will be exceeded. Rollover works correctly if snort is 13295stopped/restarted. 13296 13297%============================================================================== 13298% HOST ATTRIBUTE TABLE 13299%============================================================================== 13300\section{Host Attribute Table} 13301\label{targetbased} 13302 13303Snort can use information from an external source(s) to more accurately inspect 13304network traffic. This information saved to a file is known as a host attributes 13305table. Host attributes are used in IPS rule evalution, IP fragment (see section 13306\ref{frag3 section})/TCP stream (see section \ref{stream5 section}) reassembly 13307policy selection, and by the application preprocessors. Host attribute table is 13308loaded during initialization and supports runtime reloads; Snort reloads the 13309host attributes table when it receives the signal SIGNAL\_SNORT\_READ\_ATTR\_TBL 13310(See \ref{signalactions} to learn more). 13311 13312\begin{note} 13313To use a host attribute table and service information, Snort must be configured 13314with the --enable-targetbased flag. 13315\end{note} 13316 13317%=============================== 13318\subsection{Rule evaluation} 13319 13320In rule evaluation, service information can be used instead of the ports when the 13321metadata service(s) in the rule matches the service corresponding to the traffic. 13322If the rule does not have metadata service(s), or the packet service was not 13323matched then the port checks are used exclusively. 13324 13325%=============================== 13326\subsection{Snort Configuration} 13327 13328\begin{verbatim} 13329attribute_table filename <PATH/TO/HOSTS.XML> 13330\end{verbatim} 13331 13332%=============================== 13333\subsection{Host Attribute Table File Format} 13334 13335The attribute table uses an XML format and consists of two sections, a mapping 13336section, used to reduce the size of the file for common data elements, and the 13337host attribute section. The mapping section is optional. 13338 13339Provided below is an example attribute table 13340 13341%=============================== 13342\begin{verbatim} 13343<SNORT_ATTRIBUTES> 13344 <ATTRIBUTE_MAP> 13345 <ENTRY> 13346 <ID>1</ID> 13347 <VALUE>Linux</VALUE> 13348 </ENTRY> 13349 <ENTRY> 13350 <ID>2</ID> 13351 <VALUE>ssh</VALUE> 13352 </ENTRY> 13353 </ATTRIBUTE_MAP> 13354 <ATTRIBUTE_TABLE> 13355 <HOST> 13356 <IP>192.168.1.234</IP> 13357 <OPERATING_SYSTEM> 13358 <NAME> 13359 <ATTRIBUTE_ID>1</ATTRIBUTE_ID> 13360 <CONFIDENCE>100</CONFIDENCE> 13361 </NAME> 13362 <VENDOR> 13363 <ATTRIBUTE_VALUE>Red Hat</ATTRIBUTE_VALUE> 13364 <CONFIDENCE>99</CONFIDENCE> 13365 </VENDOR> 13366 <VERSION> 13367 <ATTRIBUTE_VALUE>2.6</ATTRIBUTE_VALUE> 13368 <CONFIDENCE>98</CONFIDENCE> 13369 </VERSION> 13370 <FRAG_POLICY>linux</FRAG_POLICY> 13371 <STREAM_POLICY>linux</STREAM_POLICY> 13372 </OPERATING_SYSTEM> 13373 <SERVICES> 13374 <SERVICE> 13375 <PORT> 13376 <ATTRIBUTE_VALUE>22</ATTRIBUTE_VALUE> 13377 <CONFIDENCE>100</CONFIDENCE> 13378 </PORT> 13379 <IPPROTO> 13380 <ATTRIBUTE_VALUE>tcp</ATTRIBUTE_VALUE> 13381 <CONFIDENCE>100</CONFIDENCE> 13382 </IPPROTO> 13383 <PROTOCOL> 13384 <ATTRIBUTE_ID>2</ATTRIBUTE_ID> 13385 <CONFIDENCE>100</CONFIDENCE> 13386 </PROTOCOL> 13387 <APPLICATION> 13388 <ATTRIBUTE_VALUE>OpenSSH</ATTRIBUTE_VALUE> 13389 <CONFIDENCE>100</CONFIDENCE> 13390 <VERSION> 13391 <ATTRIBUTE_VALUE>3.9p1</ATTRIBUTE_VALUE> 13392 <CONFIDENCE>93</CONFIDENCE> 13393 </VERSION> 13394 </APPLICATION> 13395 </SERVICE> 13396 <SERVICE> 13397 <PORT> 13398 <ATTRIBUTE_VALUE>2300</ATTRIBUTE_VALUE> 13399 <CONFIDENCE>100</CONFIDENCE> 13400 </PORT> 13401 <IPPROTO> 13402 <ATTRIBUTE_VALUE>tcp</ATTRIBUTE_VALUE> 13403 <CONFIDENCE>100</CONFIDENCE> 13404 </IPPROTO> 13405 <PROTOCOL> 13406 <ATTRIBUTE_VALUE>telnet</ATTRIBUTE_VALUE> 13407 <CONFIDENCE>100</CONFIDENCE> 13408 </PROTOCOL> 13409 <APPLICATION> 13410 <ATTRIBUTE_VALUE>telnet</ATTRIBUTE_VALUE> 13411 <CONFIDENCE>50</CONFIDENCE> 13412 </APPLICATION> 13413 </SERVICE> 13414 </SERVICES> 13415 <CLIENTS> 13416 <CLIENT> 13417 <IPPROTO> 13418 <ATTRIBUTE_VALUE>tcp</ATTRIBUTE_VALUE> 13419 <CONFIDENCE>100</CONFIDENCE> 13420 </IPPROTO> 13421 <PROTOCOL> 13422 <ATTRIBUTE_VALUE>http</ATTRIBUTE_VALUE> 13423 <CONFIDENCE>91</CONFIDENCE> 13424 </PROTOCOL> 13425 <APPLICATION> 13426 <ATTRIBUTE_VALUE>IE Http Browser</ATTRIBUTE_VALUE> 13427 <CONFIDENCE>90</CONFIDENCE> 13428 <VERSION> 13429 <ATTRIBUTE_VALUE>6.0</ATTRIBUTE_VALUE> 13430 <CONFIDENCE>89</CONFIDENCE> 13431 </VERSION> 13432 </APPLICATION> 13433 </CLIENT> 13434 </CLIENTS> 13435 </HOST> 13436 </ATTRIBUTE_TABLE> 13437</SNORT_ATTRIBUTES> 13438\end{verbatim} 13439 13440A DTD for verification of the Host Attribute Table XML file is provided with 13441the snort packages. 13442 13443The confidence metric may be used to indicate the validity of a given service 13444or client application and its respective elements. That field is not 13445currently used by Snort, but may be in future releases. 13446 13447\begin{note} 13448 13449 Snort requires that the file be a properly formatted schema of the 13450 format defined above. Empty or incorrectly formatted files will likely 13451 cause a Fatal Error. 13452 13453\end{note} 13454 13455%=============================== 13456% 13457%=============================== 13458\subsection{Attribute Table Example} 13459 13460In the example above, a host running Red Hat 2.6 is described. This host has 13461an IP address of 192.168.1.234. On that host, TCP port 22 is ssh (running 13462Open SSH), and TCP port 2300 is telnet. 13463 13464The IP fragmentation and TCP stream reassembly is mimicked by the "linux" 13465configuration (see sections \ref{frag3 section} and \ref{stream5 section}). 13466 13467%=============================== 13468% 13469%=============================== 13470\subsection{Attribute Table Affect on preprocessors} 13471 13472\begin{itemize} 13473 13474\item{Network Layer Preprocessors} 13475 13476Each of the network layer preprocessors (frag3 and stream5) make use of the 13477respective \texttt{FRAG\_POLICY} and \texttt{STREAM\_POLICY} in terms of 13478how data is handled for reassembly for packets being received by that host. 13479 13480\item{Application Layer Preprocessors} 13481 13482The application layer preprocessors (HTTP, SMTP, FTP, Telnet, etc) make use of 13483the \texttt{SERVICE} information for connections destined to that host on that 13484port. 13485 13486For example, even if the telnet portion of the FTP/Telnet preprocessor is only 13487configured to inspect port 23, Snort will inspect packets for a connection to 13488192.168.1.234 port 2300 as telnet. 13489 13490Conversely, if, for example, HTTP Inspect is configured to inspect traffic on 13491port 2300, HTTP Inspect will NOT process the packets on a connection to 13492192.168.1.234 port 2300 because it is identified as telnet. 13493 13494\end{itemize} 13495 13496Below is a list of the common services used by Snort's application layer 13497preprocessors and Snort rules (see below). 13498 13499\begin{table}[h] 13500\label{attribute:service names} 13501\begin{center} 13502\begin{tabular}{| l | l | l | l | l | l | l |} 13503\hline 13504http & ftp & ftp-data & telnet & smtp & ssh & tftp \\ 13505\hline 13506dcerpc & netbios-dgm & netbios-ns & netbios-ssn & nntp & finger & sunrpc \\ 13507\hline 13508dns & isakmp & mysql & oracle & cvs & shell & x11 \\ 13509\hline 13510imap & pop2 & pop3 & snmp & & & \\ 13511\hline 13512\end{tabular} 13513\end{center} 13514\end{table} 13515 13516\subsubsection{Attribute Table Affect on rules} 13517 13518Snort uses service information in two ways; initialization of detection engine 13519and as a detection criteria. To take advantage of this, Snort rules must 13520contain the \texttt{metadata: service SERVICE} convention specified. During rule 13521evaluation the default behavior will check first that the packet has been matched 13522to a service, and then check that the packet's service matches the service(s) 13523specified in the rule; if both these checks passed then Snort will disable 13524source and destination port checks for the rule. 13525 13526Snort 2.9.8 provides new functionality to control how rules use service 13527information known as "service overrides". Service overrides are specified in 13528the same way that services are specified in the rule, or more simply as a 13529"reserved" \texttt{SERVICE}. The table below defines the new reserved service 13530override names. 13531 13532\begin{longtable}{| p{1.5in} | p{4.5in} |} 13533\hline 13534{\bf Metadata} & {\bf Description}\\ 13535\hline 13536 13537\hline 13538\textbf{service and-ports} & 13539\begin{itemize} 13540\item{Packet service must be set.} 13541\item{Packet service must match one of the rule services.} 13542\item{Packet must match the ports specified in the rule header.} 13543\end{itemize} \\ 13544 13545\hline 13546\textbf{service or-ports} & 13547\begin{itemize} 13548\item{Packet service is set and it matches one of the rule services (skipping port checks).} 13549\item{Packet service is set but it DOES NOT match one of the rule services; packet must match the ports specified in the rule header.} 13550\item{Packet service is NOT set, only perform port checks.} 13551\end{itemize} \\ 13552 13553\hline 13554\textbf{service else-ports} & 13555\begin{itemize} 13556\item{Packet service is set, packet must match one of the rule services.} 13557\item{Packet service is NOT set; then packet must match the ports specified in the rule header.} 13558\end{itemize} 13559 13560This is the default behavior of a rule containing metadata service information. \\ 13561 13562\hline 13563\textbf{service unknown} & 13564 13565The keyword "unknown" is an alias for "service else-ports" above. It is intended 13566for use in rules that do not contain metadata service information (port only 13567rules). When used in a rule that doesn't otherwise contain metadata (rule only 13568specifies ports), the evaluation is: 13569 13570\begin{itemize} 13571\item{Packet service must NOT be set; then match ports.} 13572\end{itemize} \\ 13573 13574\hline 13575\end{longtable} 13576 13577\section{Dynamic Modules} 13578 13579Dynamically loadable modules were introduced with Snort 2.6. They can be 13580loaded via directives in \texttt{snort.conf} or via command-line options. 13581 13582\subsection{Format} 13583 13584\begin{verbatim} 13585 <directive> <parameters> 13586\end{verbatim} 13587 13588\subsection{Directives} 13589 13590\begin{longtable}{| p{2in} | p{4in} |} 13591\hline 13592{\bf Syntax} & {\bf Description}\\ 13593\hline 13594 13595\hline 13596\texttt{dynamicpreprocessor $[$ file $<$shared library path$>$ $|$ directory 13597$<$directory of shared libraries$>$ $]$} & 13598 13599Tells snort to load the dynamic preprocessor shared library (if file is used) 13600or all dynamic preprocessor shared libraries (if directory is used). Specify 13601\texttt{file}, followed by the full or relative path to the shared library. Or, 13602specify \texttt{directory}, followed by the full or relative path to a directory of 13603preprocessor shared libraries. (Same effect as 13604\texttt{--dynamic-preprocessor-lib} or \texttt{--dynamic-preprocessor-lib-dir} 13605options). See chapter \ref{Dynamic Modules} for more information on dynamic 13606preprocessor libraries.\\ 13607 13608\hline 13609\texttt{dynamicengine $[$ file $<$shared library path$>$ $|$ directory 13610$<$directory of shared libraries$>$ $]$} & 13611 13612Tells snort to load the dynamic engine shared library (if file is used) or all 13613dynamic engine shared libraries (if directory is used). Specify \texttt{file}, 13614followed by the full or relative path to the shared library. Or, specify 13615\texttt{directory}, followed by the full or relative path to a directory of 13616preprocessor shared libraries. (Same effect as \texttt{--dynamic-engine-lib} 13617or \texttt{--dynamic-preprocessor-lib-dir} options). See chapter \ref{Dynamic 13618Modules} for more information on dynamic engine libraries.\\ 13619 13620\hline 13621\texttt{dynamicdetection $[$ file $<$shared library path$>$ $|$ directory 13622$<$directory of shared libraries$>$ $]$} & 13623 13624Tells snort to load the dynamic detection rules shared library (if file is 13625used) or all dynamic detection rules shared libraries (if directory is used). 13626Specify \texttt{file}, followed by the full or relative path to the shared library. 13627Or, specify \texttt{directory}, followed by the full or relative path to a directory 13628of detection rules shared libraries. (Same effect as 13629\texttt{--dynamic-detection-lib} or \texttt{--dynamic-detection-lib-dir} 13630options). See chapter \ref{Dynamic Modules} for more information on dynamic 13631detection rules libraries.\\ 13632 13633\hline 13634\end{longtable} 13635 13636 13637\section{Reloading a Snort Configuration} 13638 13639Snort now supports reloading a configuration in lieu of restarting Snort in 13640so as to provide seamless traffic inspection during a configuration change. 13641A separate thread will parse and create a swappable configuration object while 13642the main Snort packet processing thread continues inspecting traffic under the 13643current configuration. When a swappable configuration object is ready for use, 13644the main Snort packet processing thread will swap in the new configuration to 13645use and will continue processing under the new configuration. Note that for 13646some preprocessors, existing session data will continue to use the configuration 13647under which they were created in order to continue with proper state for that 13648session. All newly created sessions will, however, use the new configuration. 13649 13650 13651\subsection{Enabling support} 13652\label{reload:enable} 13653To enable support for reloading a configuration, add \texttt{--enable-reload} to 13654configure when compiling. 13655 13656There is also an ancillary option that determines how Snort should behave 13657if any non-reloadable options are changed (see section \ref{reload:nonreloadable} below). 13658This option is enabled by default and the behavior is for 13659Snort to restart if any non-reloadable options are added/modified/removed. 13660To disable this behavior and have Snort exit instead of restart, add 13661\texttt{--disable-reload-error-restart} in addition to \texttt{--enable-reload} to configure 13662when compiling. 13663 13664\begin{note} 13665This functionality is not currently supported in Windows. 13666 13667Caveat : When Snort is run on the primary network interface of an OpenBSD system, the reload and failopen operations may not function as expected. 13668 13669\end{note} 13670 13671 13672\subsection{Reloading a configuration} 13673\label{reload:reload} 13674First modify your snort.conf (the file passed to the \texttt{-c} option on the 13675command line). 13676 13677Then, to initiate a reload, send Snort a \texttt{SIGHUP} signal, e.g. 13678 13679\begin{verbatim} 13680$ kill -SIGHUP <snort pid> 13681\end{verbatim} 13682 13683\begin{note} 13684If reload support is not enabled, Snort will restart (as it always has) 13685upon receipt of a SIGHUP. 13686\end{note} 13687 13688\begin{note} 13689An invalid configuration will still result in a fatal error, so 13690you should test your new configuration before issuing a reload, e.g. 13691\texttt{\$ snort -c snort.conf -T} 13692\end{note} 13693 13694 13695\subsection{Non-reloadable configuration options} 13696\label{reload:nonreloadable} 13697There are a number of option changes that are currently non-reloadable because 13698they require changes to output, startup memory allocations, etc. Modifying any 13699of these options will cause Snort to restart (as a \texttt{SIGHUP} previously did) or 13700exit (if \texttt{--disable-reload-error-restart} was used to configure Snort). 13701 13702Reloadable configuration options of note: 13703\begin{itemize} 13704\item Adding/modifying/removing text rules and variables are reloadable. 13705\item Adding/modifying/removing preprocessor configurations are reloadable (except 13706 as noted below). 13707\end{itemize} 13708 13709Non-reloadable configuration options of note: 13710\begin{itemize} 13711\item Adding/modifying/removing shared objects via dynamicdetection, dynamicengine 13712 and dynamicpreprocessor are not reloadable, i.e. any new/modified/removed 13713 shared objects will require a restart. 13714\item Any changes to output will require a restart. 13715\end{itemize} 13716 13717Changes to the following options are not reloadable: 13718 13719\begin{verbatim} 13720attribute_table 13721config alertfile 13722config asn1 13723config chroot 13724config daemon 13725config detection_filter 13726config flowbits_size 13727config interface 13728config logdir 13729config max_attribute_hosts 13730config max_attribute_services_per_host 13731config nolog 13732config no_promisc 13733config pkt_count 13734config rate_filter 13735config response 13736config set_gid 13737config set_uid 13738config snaplen 13739config threshold 13740dynamicdetection 13741dynamicengine 13742dynamicpreprocessor 13743output 13744\end{verbatim} 13745 13746In certain cases, only some of the parameters to a config option or 13747preprocessor configuration are not reloadable. Those parameters are 13748listed below the relevant config option or preprocessor. 13749 13750\begin{verbatim} 13751config ppm: max-rule-time <int> 13752 rule-log 13753config profile_rules 13754 filename 13755 print 13756 sort 13757config profile_preprocs 13758 filename 13759 print 13760 sort 13761preprocessor dcerpc2 13762 memcap 13763preprocessor frag3_global 13764 max_frags 13765 memcap 13766 prealloc_frags 13767 prealloc_memcap 13768 disabled 13769preprocessor perfmonitor 13770 file 13771 snortfile 13772preprocessor sfportscan 13773 memcap 13774 logfile 13775 disabled 13776preprocessor stream5_global 13777 memcap 13778 max_tcp 13779 max_udp 13780 max_icmp 13781 track_tcp 13782 track_udp 13783 track_icmp 13784\end{verbatim} 13785 13786\section{Multiple Configurations} 13787 13788Snort now supports multiple configurations based on VLAN Id or IP subnet within 13789a single instance of Snort. This will allow administrators to specify multiple 13790snort configuration files and bind each configuration to one or more VLANs or 13791subnets rather than running one Snort for each configuration required. Each 13792unique snort configuration file will create a new configuration instance within 13793snort. VLANs/Subnets not bound to any specific configuration will use the default 13794configuration. Each configuration can have different preprocessor settings and 13795detection rules. 13796 13797\subsection{Creating Multiple Configurations} 13798Default configuration for snort is specified using the existing -c option. A 13799default configuration binds multiple vlans or networks to non-default configurations, 13800using the following configuration line: 13801 13802\begin{verbatim} 13803config binding: <path_to_snort.conf> vlan <vlanIdList> 13804config binding: <path_to_snort.conf> net <ipList> 13805config binding: <path_to_snort.conf> policy_id <id> 13806\end{verbatim} 13807 13808\begin{description}{} 13809 13810\item [\texttt{path\_to\_snort.conf}] - Refers to the absolute or relative path to 13811the snort.conf for specific configuration. 13812 13813\item [\texttt{vlanIdList}] - Refers to the comma separated list of vlandIds and 13814vlanId ranges. The format for ranges is two vlanId separated by a "-". Spaces are 13815allowed within ranges. Valid vlanId is any number in 0-4095 range. Negative vland 13816Ids and alphanumeric are not supported. 13817 13818\item [\texttt{ipList}] - Refers to ip subnets. Subnets can be CIDR blocks for 13819IPV6 or IPv4. A maximum of 512 individual IPv4 or IPv6 addresses or CIDRs can be 13820specified. 13821 13822\item [\texttt{policy\_id}] - Refers to the specific policyi\_id to be applied. Valid policyi\_id is any number in 0-4095 range. 13823\end{description} 13824 13825\begin{note} 13826Vlan and Subnets can not be used in the same line. Configurations can be applied 13827based on either Vlans or Subnets not both. 13828\end{note} 13829 13830\begin{note} 13831Even though Vlan Ids 0 and 4095 are reserved, they are included as valid in terms 13832of configuring Snort. 13833\end{note} 13834 13835\subsection{Configuration Specific Elements} 13836 13837\subsubsection{Config Options} 13838Generally config options defined within the default configuration are global by 13839default i.e. their value applies to all other configurations. The following config 13840options are specific to each configuration. 13841 13842\begin{verbatim} 13843policy_id 13844policy_mode 13845policy_version 13846\end{verbatim} 13847 13848The following config options are specific to each configuration. If not defined in 13849a configuration, the default values of the option (not the default configuration 13850values) take effect. 13851 13852\begin{verbatim} 13853config checksum_drop 13854config disable_decode_alerts 13855config disable_decode_drops 13856config disable_ipopt_alerts 13857config disable_ipopt_drops 13858config disable_tcpopt_alerts 13859config disable_tcpopt_drops 13860config disable_tcpopt_experimental_alerts 13861config disable_tcpopt_experimental_drops 13862config disable_tcpopt_obsolete_alerts 13863config disable_tcpopt_obsolete_drops 13864config disable_ttcp_alerts 13865config disable_tcpopt_ttcp_alerts 13866config disable_ttcp_drops 13867\end{verbatim} 13868 13869\subsubsection{Rules} 13870Rules are specific to configurations but only some parts of a rule can be customized 13871for performance reasons. If a rule is not specified in a configuration then the rule 13872will never raise an event for the configuration. A rule shares all parts of the rule 13873options, including the general options, payload detection options, non-payload detection 13874options, and post-detection options. Parts of the rule header can be specified differently 13875across configurations, limited to: 13876 13877\begin{verbatim} 13878Source IP address and port 13879Destination IP address and port 13880Action 13881\end{verbatim} 13882 13883A higher revision of a rule in one configuration will override other revisions of 13884the same rule in other configurations. 13885 13886\subsubsection{Variables} 13887Variables defined using "var", "portvar" and "ipvar" are specific to configurations. 13888If the rules in a configuration use variables, those variables must be defined in 13889that configuration. 13890 13891\subsubsection{Preprocessors} 13892Preprocessors configurations can be defined within each vlan or subnet specific 13893configuration. Options controlling specific preprocessor memory usage, through specific 13894limit on memory usage or number of instances, are processed only in default policy. 13895The options control total memory usage for a preprocessor across all policies. These 13896options are ignored in non-default policies without raising an error. A preprocessor 13897must be configured in default configuration before it can be configured in non-default 13898configuration. This is required as some mandatory preprocessor configuration options 13899are processed only in default configuration. 13900 13901\subsubsection{Events and Output} 13902An unique policy id can be assigned by user, to each configuration using the following 13903config line: 13904 13905\begin{verbatim} 13906config policy_id: <id> 13907\end{verbatim} 13908 13909\begin{description}{} 13910\item [\texttt{id}] - Refers to a 16-bit unsigned value. This policy id will be used to 13911identify alerts from a specific configuration in the unified2 records. 13912\end{description} 13913 13914\begin{note} 13915If no policy id is specified, snort assigns 0 (zero) value to the configuration. 13916\end{note} 13917 13918To enable vlanId logging in unified2 records the following option can be used. 13919 13920\begin{verbatim} 13921output alert_unified2: vlan_event_types (alert logging only) 13922output unified2: filename <filename>, vlan_event_types (true unified logging) 13923\end{verbatim} 13924 13925\begin{description}{} 13926\item [\texttt{filename}] - Refers to the absolute or relative filename. 13927\item [\texttt{vlan\_event\_types}] - When this option is set, snort will use unified2 event 13928type 104 and 105 for IPv4 and IPv6 respectively. 13929\end{description} 13930 13931\begin{note} 13932Each event logged will have the vlanId from the packet if vlan headers are present 13933otherwise 0 will be used. 13934\end{note} 13935 13936\subsection{How Configuration is applied?} 13937Snort assigns every incoming packet to a unique configuration based on the following criteria. 13938If VLANID is present, then the innermost VLANID is used to find bound configuration. If the 13939bound configuration is the default configuration, then destination IP address is searched to 13940the most specific subnet that is bound to a non-default configuration. The packet is assigned 13941non-default configuration if found otherwise the check is repeated using source IP address. 13942In the end, default configuration is used if no other matching configuration is found. 13943 13944For addressed based configuration binding, this can lead to conflicts between configurations 13945if source address is bound to one configuration and destination address is bound to another. 13946In this case, snort will use the first configuration in the order of definition, that can be 13947applied to the packet. 13948 13949\section{Active Response} 13950 13951Snort 2.9 includes a number of changes to better handle inline operation, 13952including: 13953 13954\begin{itemize} 13955\item a single mechanism for all responses 13956\item fully encoded reset or icmp unreachable packets 13957\item updated flexible response rule option 13958\item updated react rule option 13959\item added block and sblock rule actions 13960\end{itemize} 13961 13962These changes are outlined below. 13963 13964\subsection{Enabling Active Response} 13965 13966This enables active responses (snort will send TCP RST or ICMP 13967unreachable/port) when dropping a session. 13968 13969\begin{verbatim} 13970 ./configure --enable-active-response / -DACTIVE_RESPONSE 13971 13972 preprocessor stream5_global: \ 13973 max_active_responses <max_rsp>, \ 13974 min_response_seconds <min_sec> 13975 13976 <max_rsp> ::= (0..25) 13977 <min_sec> ::= (1..300) 13978\end{verbatim} 13979 13980Active responses will be encoded based on the triggering packet. TTL will be 13981set to the value captured at session pickup. 13982 13983\subsection{Configure Sniping} 13984 13985Configure the number of attempts to land a TCP RST within the session's current 13986window (so that it is accepted by the receiving TCP). This sequence "strafing" 13987is really only useful in passive mode. In inline mode the reset is put 13988straight into the stream in lieu of the triggering packet so strafing is not 13989necessary. 13990 13991Each attempt (sent in rapid succession) has a different sequence number. Each 13992active response will actually cause this number of TCP resets to be sent. TCP 13993data (sent for react) is multiplied similarly. At most 1 ICMP unreachable is 13994sent, if and only if attempts $>$ 0. 13995 13996\begin{verbatim} 13997 ./configure --enable-active-response 13998 13999 config response: [device <dev>] [dst_mac <MAC address>] attempts <att> 14000 14001 <dev> ::= ip | eth0 | etc. 14002 <att> ::= (1..20) 14003 <MAC address> ::= nn:nn:nn:nn:nn:nn 14004 (n is a hex number from 0-F) 14005\end{verbatim} 14006 14007device ip will perform network layer injection. It is probably a better choice 14008to specify an interface and avoid kernel routing tables, etc. 14009 14010dst\_mac will change response destination MAC address, if the device is eth0, eth1, eth2 etc. 14011Otherwise, response destination MAC address is derived from packet. 14012Example: 14013\begin{verbatim} 14014 config response: device eth0 dst_mac 00:06:76:DD:5F:E3 attempts 2 14015\end{verbatim} 14016 14017\subsection{Flexresp} 14018\label{resp section} 14019 14020Flexresp and flexresp2 are replaced with flexresp3. 14021 14022* Flexresp is deleted; these features are no longer available: 14023 14024\begin{verbatim} 14025 ./configure --enable-flexresp / -DENABLE_RESPOND -DENABLE_RESPONSE 14026 config flexresp: attempts 1 14027\end{verbatim} 14028 14029* Flexresp2 is deleted; these features are deprecated, non-functional, and will 14030 be deleted in a future release: 14031 14032\begin{verbatim} 14033 ./configure --enable-flexresp2 / -DENABLE_RESPOND -DENABLE_RESPONSE2 14034 14035 config flexresp2_interface: eth0 14036 config flexresp2_attempts: 4 14037 config flexresp2_memcap: 1000000 14038 config flexresp2_rows: 1000 14039\end{verbatim} 14040 14041* Flexresp3 is new: the resp rule option keyword is used to configure active 14042 responses for rules that fire. 14043 14044\begin{verbatim} 14045 ./configure --enable-flexresp3 / -DENABLE_RESPOND -DENABLE_RESPONSE3 14046 14047 alert tcp any any -> any 80 (content:"a"; resp:<resp_t>; sid:1;) 14048\end{verbatim} 14049 14050* \texttt{resp\_t} includes all flexresp and flexresp2 options: 14051 14052\begin{verbatim} 14053 <resp_t> ::= \ 14054 rst_snd | rst_rcv | rst_all | \ 14055 reset_source | reset_dest | reset_both | icmp_net | \ 14056 icmp_host | icmp_port | icmp_all 14057\end{verbatim} 14058 14059\subsection{React} 14060\label{react section} 14061 14062react is a rule option keyword that enables sending an HTML page on a session 14063and then resetting it. This is built with: 14064 14065\begin{verbatim} 14066 ./configure --enable-react / -DENABLE_REACT 14067\end{verbatim} 14068 14069The page to be sent can be read from a file: 14070 14071\begin{verbatim} 14072 config react: <block.html> 14073\end{verbatim} 14074 14075or else the default is used: 14076 14077\begin{verbatim} 14078 <default_page> ::= \ 14079 "HTTP/1.1 403 Forbidden\r\n" 14080 "Connection: close\r\n" 14081 "Content-Type: text/html; charset=utf-8\r\n" 14082 "\r\n" 14083 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n" \ 14084 " \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n" \ 14085 "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\r\n" \ 14086 "<head>\r\n" \ 14087 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\r\n" \ 14088 "<title>Access Denied</title>\r\n" \ 14089 "</head>\r\n" \ 14090 "<body>\r\n" \ 14091 "<h1>Access Denied</h1>\r\n" \ 14092 "<p>%s</p>\r\n" \ 14093 "</body>\r\n" \ 14094 "</html>\r\n"; 14095\end{verbatim} 14096 14097Note that the file must contain the entire response, including any HTTP headers. 14098In fact, the response isn't strictly limited to HTTP. You could craft a binary 14099payload of arbitrary content. 14100 14101Be aware of size when creating such responses. While it may be possible 14102to respond with arbitrarily large responses, responses for TCP sessions will need 14103to take into account that the receiver's window may only accept up to a certain 14104amount of data. Sending past this limit will result in truncated data. In general, 14105the smaller the response, the more likely it will be successful. 14106 14107When the rule is configured, the page is loaded and the %s is replaced with the 14108selected message, which defaults to: 14109 14110\begin{verbatim} 14111 <default_msg> ::= \ 14112 "You are attempting to access a forbidden site.<br />" \ 14113 "Consult your system administrator for details."; 14114\end{verbatim} 14115 14116Additional formatting operators beyond a single %s are prohibited, including 14117%d, %x, %s, as well as any URL encodings such as as %20 (space) that may be 14118within a reference URL. 14119 14120This is an example rule: 14121 14122\begin{verbatim} 14123 drop tcp any any -> any $HTTP_PORTS ( \ 14124 content: "d"; msg:"Unauthorized Access Prohibited!"; \ 14125 react: <react_opts>; sid:4;) 14126 14127 <react_opts> ::= [msg] [, <dep_opts>] 14128\end{verbatim} 14129 14130These options are deprecated: 14131 14132\begin{verbatim} 14133 <dep_opts> ::= [block|warn], [proxy <port#>] 14134\end{verbatim} 14135 14136The original version sent the web page to one end of the session only if the 14137other end of the session was port 80 or the optional proxy port. The new 14138version always sends the page to the client. If no page should be sent, a resp 14139option can be used instead. The deprecated options are ignored. 14140 14141\subsection{Rule Actions} 14142 14143The block and sblock actions have been introduced as synonyms for drop and 14144sdrop to help avoid confusion between packets dropped due to load (e.g. lack of 14145available buffers for incoming packets) and packets blocked due to Snort's 14146analysis. 14147 14148 14149\chapter{Writing Snort Rules} 14150\label{Writing Snort Rules} 14151 14152\section{The Basics} 14153 14154Snort uses a simple, lightweight rules description language that is flexible 14155and quite powerful. There are a number of simple guidelines to remember when 14156developing Snort rules that will help safeguard your sanity. 14157 14158Most Snort rules are written in a single line. This was required in versions 14159prior to 1.8. In current versions of Snort, rules may span multiple lines by 14160adding a backslash \textbackslash{} to the end of the line. 14161 14162Snort rules are divided into two logical sections, the rule header and the rule 14163options. The rule header contains the rule's action, protocol, source and 14164destination IP addresses and netmasks, and the source and destination ports 14165information. The rule option section contains alert messages and information on 14166which parts of the packet should be inspected to determine if the rule action 14167should be taken. 14168 14169Figure \ref{Sample Snort Rule} illustrates a sample Snort rule. 14170 14171\begin{center} 14172\begin{figure} 14173\begin{verbatim} 14174 alert tcp any any -> 192.168.1.0/24 111 \ 14175 (content:"|00 01 86 a5|"; msg:"mountd access";) 14176\end{verbatim} 14177 14178\caption{Sample Snort Rule} 14179\label{Sample Snort Rule} 14180\end{figure} 14181\end{center} 14182 14183The text up to the first parenthesis is the rule header and the section 14184enclosed in parenthesis contains the rule options. The words before the colons 14185in the rule options section are called option \emph{keywords}. 14186 14187\begin{note} 14188 14189Note that the rule options section is not specifically required by any rule, 14190they are just used for the sake of making tighter definitions of packets to 14191collect or alert on (or drop, for that matter). 14192 14193\end{note} 14194 14195All of the elements in that make up a rule must be true for the indicated rule 14196action to be taken. When taken together, the elements can be considered to form 14197a logical \textsc{and} statement. At the same time, the various rules in a 14198Snort rules library file can be considered to form a large logical \textsc{or} 14199statement. 14200 14201\section{Rules Headers} 14202 14203\subsection{Rule Actions} 14204\label{rules action section} 14205 14206The rule header contains the information that defines the who, where, and what 14207of a packet, as well as what to do in the event that a packet with all the 14208attributes indicated in the rule should show up. The first item in a rule is 14209the rule action. The rule action tells Snort what to do when it finds a packet 14210that matches the rule criteria. There are 3 available default actions in Snort, 14211alert, log, pass. In addition, if you are running Snort 14212in inline mode, you have additional options which include drop, reject, and 14213sdrop. 14214 14215\begin{enumerate} 14216 14217\item alert - generate an alert using the selected alert method, and then 14218log the packet 14219 14220\item log - log the packet 14221 14222\item pass - ignore the packet 14223 14224\item drop - block and log the packet 14225 14226\item reject - block the packet, log it, and then send a TCP reset 14227if the protocol is TCP or an ICMP port unreachable message if the protocol is 14228UDP. 14229 14230\item sdrop - block the packet but do not log it. 14231 14232\end{enumerate} 14233 14234You can also define your own rule types and associate one or more output 14235plugins with them. You can then use the rule types as actions in Snort rules. 14236 14237This example will create a type that will log to just tcpdump: 14238 14239\begin{verbatim} 14240 ruletype suspicious 14241 { 14242 type log 14243 output log_tcpdump: suspicious.log 14244 } 14245\end{verbatim} 14246 14247This example will create a rule type that will log to syslog and tcpdump: 14248database: 14249 14250\begin{verbatim} 14251 ruletype redalert 14252 { 14253 type alert 14254 output alert_syslog: LOG_AUTH LOG_ALERT 14255 output log_tcpdump: suspicious.log 14256 } 14257\end{verbatim} 14258 14259\subsection{Protocols} 14260 14261The next field in a rule is the protocol. There are four protocols that Snort 14262currently analyzes for suspicious behavior -- TCP, UDP, ICMP, and IP. In the 14263future there may be more, such as ARP, IGRP, GRE, OSPF, RIP, IPX, etc. 14264 14265\subsection{IP Addresses} 14266 14267The next portion of the rule header deals with the IP address and port 14268information for a given rule. The keyword any may be used to define any 14269address. Snort does not have a mechanism to provide host name lookup for the IP 14270address fields in the config file. The addresses are formed by a straight 14271numeric IP address and a CIDR\cite{cidrnotation} block. The CIDR block 14272indicates the netmask that should be applied to the rule's address and any 14273incoming packets that are tested against the rule. A CIDR block mask of /24 14274indicates a Class C network, /16 a Class B network, and /32 indicates a 14275specific machine address. For example, the address/CIDR combination 14276192.168.1.0/24 would signify the block of addresses from 192.168.1.1 to 14277192.168.1.255. Any rule that used this designation for, say, the destination 14278address would match on any address in that range. The CIDR designations give us 14279a nice short-hand way to designate large address spaces with just a few 14280characters. 14281 14282In Figure \ref{Sample Snort Rule}, the source IP address was set to match for 14283any computer talking, and the destination address was set to match on the 14284192.168.1.0 Class C network. 14285 14286There is an operator that can be applied to IP addresses, the negation 14287operator. This operator tells Snort to match any IP address except the one 14288indicated by the listed IP address. The negation operator is indicated with a 14289!. For example, an easy modification to the initial example is to make it alert 14290on any traffic that originates outside of the local net with the negation 14291operator as shown in Figure \ref{Example Negation}. 14292 14293\begin{center} 14294\begin{figure} 14295\begin{verbatim} 14296 alert tcp !192.168.1.0/24 any -> 192.168.1.0/24 111 \ 14297 (content:"|00 01 86 a5|"; msg:"external mountd access";) 14298\end{verbatim} 14299 14300\caption{\label{Example Negation} Example IP Address Negation Rule} 14301\end{figure} 14302\end{center} 14303 14304This rule's IP addresses indicate any tcp packet with a source IP address not 14305originating from the internal network and a destination address on the internal 14306network. 14307 14308You may also specify lists of IP addresses. An IP list is specified by 14309enclosing a comma separated list of IP addresses and CIDR blocks within square 14310brackets. For the time being, the IP list may not include spaces between the 14311addresses. See Figure \ref{IP list usage} for an example of an IP list in 14312action. 14313 14314\begin{center} 14315\begin{figure} 14316\begin{verbatim} 14317 alert tcp ![192.168.1.0/24,10.1.1.0/24] any -> \ 14318 [192.168.1.0/24,10.1.1.0/24] 111 (content:"|00 01 86 a5|"; \ 14319 msg:"external mountd access";) 14320\end{verbatim} 14321 14322\caption{\label{IP list usage}IP Address Lists} 14323\end{figure} 14324\end{center} 14325 14326\subsection{Port Numbers} 14327 14328Port numbers may be specified in a number of ways, including any ports, static 14329port definitions, ranges, and by negation. Any ports are a wildcard value, 14330meaning literally any port. Static ports are indicated by a single port number, 14331such as 111 for portmapper, 23 for telnet, or 80 for http, etc. Port ranges are 14332indicated with the range operator :. The range operator may be applied in a 14333number of ways to take on different meanings, such as in Figure \ref{port range 14334examples}. 14335 14336\begin{center} 14337\begin{figure} 14338\begin{verbatim} 14339 log udp any any -> 192.168.1.0/24 1:1024 14340\end{verbatim} 14341 14342log udp traffic coming from any port and destination ports ranging from 1 to 1024 14343 14344\begin{verbatim} 14345 log tcp any any -> 192.168.1.0/24 :6000 14346\end{verbatim} 14347 14348log tcp traffic from any port going to ports less than or equal to 6000 14349 14350\begin{verbatim} 14351 log tcp any :1024 -> 192.168.1.0/24 500: 14352\end{verbatim} 14353 14354log tcp traffic from privileged ports less than or equal to 1024 going to ports 14355greater than or equal to 500 14356 14357\caption{\label{port range examples}Port Range Examples} 14358\end{figure} 14359\end{center} 14360 14361Port negation is indicated by using the negation operator !. The negation 14362operator may be applied against any of the other rule types (except any, which 14363would translate to none, how Zen...). For example, if for some twisted reason 14364you wanted to log everything except the X Windows ports, you could do something 14365like the rule in Figure \ref{example port negation}. 14366 14367\begin{figure} 14368\begin{verbatim} 14369 log tcp any any -> 192.168.1.0/24 !6000:6010 14370\end{verbatim} 14371 14372\caption{\label{example port negation}Example of Port Negation} 14373\end{figure} 14374 14375\subsection{The Direction Operator} 14376 14377The direction operator -$>$ indicates the orientation, or direction, of the 14378traffic that the rule applies to. The IP address and port numbers on the left 14379side of the direction operator is considered to be the traffic coming from the 14380source host, and the address and port information on the right side of the 14381operator is the destination host. There is also a bidirectional operator, which 14382is indicated with a $<>$ symbol. This tells Snort to consider the address/port 14383pairs in either the source or destination orientation. This is handy for 14384recording/analyzing both sides of a conversation, such as telnet or POP3 14385sessions. An example of the bidirectional operator being used to record both 14386sides of a telnet session is shown in Figure \ref{bidirectional operator}. 14387 14388Also, note that there is no $<$- operator. In Snort versions before 1.8.7, the 14389direction operator did not have proper error checking and many people used an 14390invalid token. The reason the $<$- does not exist is so that rules always read 14391consistently. 14392 14393\begin{figure} 14394\begin{verbatim} 14395 log tcp !192.168.1.0/24 any <> 192.168.1.0/24 23 14396\end{verbatim} 14397 14398\caption{\label{bidirectional operator}Snort rules using the Bidirectional 14399Operator} 14400\end{figure} 14401 14402\subsection{Activate/Dynamic Rules} 14403\label{dynamic rules} 14404 14405Activate and Dynamic rules are phased out in favor of a combination of 14406tagging (\ref{tag section}) and flowbits (\ref{flowbits}). 14407 14408\section{Rule Options} 14409 14410Rule options form the heart of Snort's intrusion detection engine, combining 14411ease of use with power and flexibility. All Snort rule options are separated 14412from each other using the semicolon (;) character. Rule option keywords are 14413separated from their arguments with a colon (:) character. 14414 14415There are four major categories of rule options. 14416 14417\begin{description} 14418 14419\item [general] These options provide information about the rule but do not 14420have any affect during detection 14421 14422\item [payload] These options all look for data inside the packet payload and 14423can be inter-related 14424 14425\item [non-payload] These options look for non-payload data 14426 14427\item [post-detection] These options are rule specific triggers that happen 14428after a rule has ``fired.'' 14429 14430\end{description} 14431 14432\section{General Rule Options} 14433 14434\subsection{msg} 14435 14436The msg rule option tells the logging and alerting engine the message to print 14437along with a packet dump or to an alert. It is a simple text string that 14438utilizes the \textbackslash{} as an escape character to indicate a discrete 14439character that might otherwise confuse Snort's rules parser (such as the 14440semi-colon ; character). 14441 14442\subsubsection{Format} 14443 14444\begin{verbatim} 14445 msg:"<message text>"; 14446\end{verbatim} 14447 14448\subsection{reference} 14449 14450The reference keyword allows rules to include references to external attack 14451identification systems. The plugin currently supports several specific systems 14452as well as unique URLs. This plugin is to be used by output plugins to provide 14453a link to additional information about the alert produced. 14454 14455Make sure to also take a look at 14456\url{http://www.snort.org/pub-bin/sigs-search.cgi/} for a system that is 14457indexing descriptions of alerts based on of the sid (See Section \ref{keyword 14458sid}). 14459 14460\begin{table}[h] 14461\begin{center} 14462\caption{Supported Systems} 14463\label{references systems} 14464\begin{tabular}{|c|c|} 14465 14466\hline 14467System& 14468URL Prefix\\ 14469\hline 14470 14471\hline 14472bugtraq& 14473http://www.securityfocus.com/bid/\\ 14474 14475\hline 14476cve& 14477http://cve.mitre.org/cgi-bin/cvename.cgi?name=\\ 14478 14479\hline 14480nessus & 14481http://cgi.nessus.org/plugins/dump.php3?id=\\ 14482 14483\hline 14484arachnids& 14485(currently down) http://www.whitehats.com/info/IDS\\ 14486 14487\hline 14488mcafee& 14489http://vil.nai.com/vil/content/v\_\\ 14490 14491\hline 14492osvdb& 14493http://osvdb.org/show/osvdb/\\ 14494 14495\hline 14496msb& 14497http://technet.microsoft.com/en-us/security/bulletin/\\ 14498 14499\hline 14500url& 14501http://\\ 14502 14503\hline 14504\end{tabular} 14505\end{center} 14506\end{table} 14507 14508\subsubsection{Format} 14509 14510\begin{verbatim} 14511 reference:<id system>, <id>; [reference:<id system>, <id>;] 14512\end{verbatim} 14513 14514\subsubsection{Examples} 14515 14516\begin{verbatim} 14517 alert tcp any any -> any 7070 (msg:"IDS411/dos-realaudio"; \ 14518 flags:AP; content:"|fff4 fffd 06|"; reference:arachnids,IDS411;) 14519 14520 alert tcp any any -> any 21 (msg:"IDS287/ftp-wuftp260-venglin-linux"; \ 14521 flags:AP; content:"|31c031db 31c9b046 cd80 31c031db|"; \ 14522 reference:arachnids,IDS287; reference:bugtraq,1387; \ 14523 reference:cve,CAN-2000-1574;) 14524\end{verbatim} 14525 14526\subsection{gid} 14527\label{keyword gid} 14528 14529The \texttt{gid} keyword (generator id) is used to identify what part of Snort 14530generates the event when a particular rule fires. For example gid 1 is 14531associated with the rules subsystem and various gids over 100 are designated 14532for specific preprocessors and the decoder. See etc/generators in the source 14533tree for the current generator ids in use. Note that the gid keyword is 14534optional and if it is not specified in a rule, it will default to 1 and the 14535rule will be part of the general rule subsystem. To avoid potential conflict 14536with gids defined in Snort (that for some reason aren't noted it 14537etc/generators), it is recommended that values starting at 1,000,000 be used. 14538For general rule writing, it is not recommended that the \texttt{gid} keyword 14539be used. This option should be used with the \texttt{sid} keyword. (See 14540section \ref{keyword sid}) 14541 14542The file etc/gen-msg.map contains contains more information on preprocessor and 14543decoder gids. 14544 14545\subsubsection{Format} 14546 14547\begin{verbatim} 14548 gid:<generator id>; 14549\end{verbatim} 14550 14551\subsubsection{Example} 14552 14553This example is a rule with a generator id of 1000001. 14554 14555\begin{verbatim} 14556 alert tcp any any -> any 80 (content:"BOB"; gid:1000001; sid:1; rev:1;) 14557\end{verbatim} 14558 14559\subsection{sid} 14560\label{keyword sid} 14561 14562The \texttt{sid} keyword is used to uniquely identify Snort rules. This 14563information allows output plugins to identify rules easily. This option should 14564be used with the \texttt{rev} keyword. (See section \ref{keyword rev}) 14565 14566\begin{itemize} 14567\item $<$100 Reserved for future use 14568\item 100-999,999 Rules included with the Snort distribution 14569\item $>=$1,000,000 Used for local rules 14570\end{itemize} 14571 14572The file sid-msg.map contains a mapping of alert messages to Snort rule IDs. 14573This information is useful when post-processing alert to map an ID to an alert 14574message. 14575 14576\subsubsection{Format} 14577 14578\begin{verbatim} 14579 sid:<snort rules id>; 14580\end{verbatim} 14581 14582\subsubsection{Example} 14583 14584This example is a rule with the Snort Rule ID of 1000983. 14585 14586\begin{verbatim} 14587 alert tcp any any -> any 80 (content:"BOB"; sid:1000983; rev:1;) 14588\end{verbatim} 14589 14590\subsection{rev} 14591\label{keyword rev} 14592 14593The \texttt{rev} keyword is used to uniquely identify revisions of Snort rules. 14594Revisions, along with Snort rule id's, allow signatures and descriptions to be 14595refined and replaced with updated information. This option should be used with 14596the \texttt{sid} keyword. (See section \ref{keyword sid}) 14597 14598\subsubsection{Format} 14599 14600\begin{verbatim} 14601 rev:<revision integer>; 14602\end{verbatim} 14603 14604\subsubsection{Example} 14605 14606This example is a rule with the Snort Rule Revision of 1. 14607 14608\begin{verbatim} 14609 alert tcp any any -> any 80 (content:"BOB"; sid:1000983; rev:1;) 14610\end{verbatim} 14611 14612\subsection{classtype} 14613 14614The \texttt{classtype} keyword is used to categorize a rule as detecting an 14615attack that is part of a more general type of attack class. Snort provides a 14616default set of attack classes that are used by the default set of rules it 14617provides. Defining classifications for rules provides a way to better organize 14618the event data Snort produces. 14619 14620\subsubsection{Format} 14621 14622\begin{verbatim} 14623 classtype:<class name>; 14624\end{verbatim} 14625 14626\subsubsection{Example} 14627 14628\begin{verbatim} 14629 alert tcp any any -> any 25 (msg:"SMTP expn root"; flags:A+; \ 14630 content:"expn root"; nocase; classtype:attempted-recon;) 14631\end{verbatim} 14632 14633Attack classifications defined by Snort reside in the 14634\texttt{classification.config} file. The file uses the following syntax: 14635 14636\begin{verbatim} 14637 config classification: <class name>,<class description>,<default priority> 14638\end{verbatim} 14639 14640These attack classifications are listed in Table \ref{Snort Default 14641Classifications}. They are currently ordered with 4 default priorities. A 14642priority of 1 (high) is the most severe and 4 (very low) is the least severe. 14643 14644\begin{center} 14645\begin{longtable}[h]{|p{2in}|p{2.5in}|c|} 14646\caption{Snort Default Classifications} 14647\label{Snort Default Classifications} \\ 14648\hline 14649Classtype & Description & Priority \\ 14650\hline 14651\hline 14652attempted-admin& 14653Attempted Administrator Privilege Gain & high \\ 14654\hline 14655attempted-user& 14656Attempted User Privilege Gain & high\\ 14657\hline 14658inappropriate-content& 14659Inappropriate Content was Detected & high\\ 14660\hline 14661policy-violation& 14662Potential Corporate Privacy Violation & high\\ 14663\hline 14664shellcode-detect& 14665Executable code was detected & high\\ 14666\hline 14667successful-admin& 14668Successful Administrator Privilege Gain & high\\ 14669\hline 14670successful-user& 14671Successful User Privilege Gain & high\\ 14672\hline 14673trojan-activity& 14674A Network Trojan was detected & high\\ 14675\hline 14676unsuccessful-user& 14677Unsuccessful User Privilege Gain & high\\ 14678\hline 14679web-application-attack& 14680Web Application Attack & high\\ 14681\hline 14682attempted-dos& 14683Attempted Denial of Service & medium\\ 14684\hline 14685attempted-recon& 14686Attempted Information Leak & medium\\ 14687\hline 14688bad-unknown& 14689Potentially Bad Traffic & medium\\ 14690\hline 14691default-login-attempt& 14692Attempt to login by a default username and password & medium\\ 14693\hline 14694denial-of-service& 14695Detection of a Denial of Service Attack & medium\\ 14696\hline 14697misc-attack& 14698Misc Attack & medium\\ 14699\hline 14700non-standard-protocol& 14701Detection of a non-standard protocol or event & medium\\ 14702\hline 14703rpc-portmap-decode& 14704Decode of an RPC Query & medium\\ 14705\hline 14706successful-dos& 14707Denial of Service & medium\\ 14708\hline 14709successful-recon-largescale& 14710Large Scale Information Leak & medium\\ 14711\hline 14712successful-recon-limited& 14713Information Leak & medium\\ 14714\hline 14715suspicious-filename-detect& 14716A suspicious filename was detected & medium\\ 14717\hline 14718suspicious-login& 14719An attempted login using a suspicious username was detected & medium\\ 14720\hline 14721system-call-detect& 14722A system call was detected & medium\\ 14723\hline 14724unusual-client-port-connection& 14725A client was using an unusual port & medium\\ 14726\hline 14727web-application-activity& 14728Access to a potentially vulnerable web application & medium\\ 14729\hline 14730icmp-event& 14731Generic ICMP event & low\\ 14732\hline 14733misc-activity& 14734Misc activity & low\\ 14735\hline 14736network-scan& 14737Detection of a Network Scan & low\\ 14738\hline 14739not-suspicious& 14740Not Suspicious Traffic & low\\ 14741\hline 14742protocol-command-decode& 14743Generic Protocol Command Decode & low\\ 14744\hline 14745string-detect& 14746A suspicious string was detected & low\\ 14747\hline 14748unknown& 14749Unknown Traffic & low\\ 14750\hline 14751tcp-connection& 14752A TCP connection was detected & very low\\ 14753\hline 14754\end{longtable} 14755\end{center} 14756 14757\subsubsection{Warnings} 14758 14759The \texttt{classtype} option can only use classifications that have been 14760defined in \texttt{snort.conf} by using the \texttt{config classification} 14761option. Snort provides a default set of classifications in 14762\texttt{classification.config} that are used by the rules it provides. 14763 14764\subsection{priority} 14765 14766The \texttt{priority} tag assigns a severity level to rules. A 14767\texttt{classtype} rule assigns a default priority (defined by the 14768\texttt{config classification} option) that may be overridden with a priority 14769rule. Examples of each case are given below. 14770 14771\subsubsection{Format} 14772 14773\begin{verbatim} 14774 priority:<priority integer>; 14775\end{verbatim} 14776 14777\subsubsection{Examples} 14778 14779\begin{verbatim} 14780 alert tcp any any -> any 80 (msg:"WEB-MISC phf attempt"; flags:A+; \ 14781 content:"/cgi-bin/phf"; priority:10;) 14782 14783 alert tcp any any -> any 80 (msg:"EXPLOIT ntpdx overflow"; \ 14784 dsize:>128; classtype:attempted-admin; priority:10 ); 14785\end{verbatim} 14786 14787\subsection{metadata} 14788 14789The \texttt{metadata} tag allows a rule writer to embed additional information 14790about the rule, typically in a key-value format. Certain metadata keys and 14791values have meaning to Snort and are listed in Table \ref{Snort Metadata Keys}. 14792Keys other than those listed in the table are effectively ignored by Snort and 14793can be free-form, with a key and a value. Multiple keys are separated by a 14794comma, while keys and values are separated by a space. 14795 14796\begin{table}[h] 14797\begin{center} 14798\caption{Snort Metadata Keys} 14799\label{Snort Metadata Keys} 14800\begin{tabular}{|p{1in}|p{2.5in}|c|} 14801 14802\hline 14803Key & Description & Value Format \\ 14804\hline 14805 14806\hline 14807\texttt{engine} & 14808Indicate a Shared Library Rule & "shared" \\ 14809 14810\hline 14811\texttt{soid} & 14812Shared Library Rule Generator and SID & gid$|$sid \\ 14813 14814\hline 14815\texttt{service} & 14816Target-Based Service Identifier & "http" \\ 14817 14818\hline 14819\end{tabular} 14820\end{center} 14821\end{table} 14822 14823\begin{note} 14824 14825The \texttt{service} Metadata Key is only meaningful when a Host Attribute 14826Table is provided. See Section \ref{targetbased} for details on the Host Attribute Table. 14827 14828\end{note}. 14829 14830\subsubsection{Format} 14831 14832The examples below show an stub rule from a shared library rule. The first 14833uses multiple metadata keywords, the second a single metadata keyword, with 14834keys separated by commas. 14835 14836\begin{verbatim} 14837 metadata:key1 value1; 14838 metadata:key1 value1, key2 value2; 14839\end{verbatim} 14840 14841\subsubsection{Examples} 14842 14843\begin{verbatim} 14844 alert tcp any any -> any 80 (msg:"Shared Library Rule Example"; \ 14845 metadata:engine shared; metadata:soid 3|12345;) 14846 14847 alert tcp any any -> any 80 (msg:"Shared Library Rule Example"; \ 14848 metadata:engine shared, soid 3|12345;) 14849 14850 alert tcp any any -> any 80 (msg:"HTTP Service Rule Example"; \ 14851 metadata:service http;) 14852\end{verbatim} 14853 14854\subsection{General Rule Quick Reference} 14855\begin{center} 14856\begin{longtable}[h]{| p{1in} | p{4.5in} |} 14857\caption{General rule option keywords} \\ 14858 14859\hline 14860Keyword & Description \\ 14861\hline 14862 14863\hline 14864\texttt{msg} & 14865 14866The msg keyword tells the logging and alerting engine the message to print with 14867the packet dump or alert. \\ 14868 14869\hline 14870\texttt{reference} & 14871 14872The reference keyword allows rules to include references to external attack 14873identification systems. \\ 14874 14875\hline 14876\texttt{gid} & 14877 14878The gid keyword (generator id) is used to identify what part of Snort generates 14879the event when a particular rule fires. \\ 14880 14881\hline 14882\texttt{sid} & 14883 14884The sid keyword is used to uniquely identify Snort rules. \\ 14885 14886\hline 14887\texttt{rev} & 14888 14889The rev keyword is used to uniquely identify revisions of Snort rules. \\ 14890 14891\hline 14892\texttt{classtype} & 14893 14894The classtype keyword is used to categorize a rule as detecting an attack that 14895is part of a more general type of attack class. \\ 14896 14897\hline 14898\texttt{priority} & 14899 14900The priority keyword assigns a severity level to rules. \\ 14901 14902\hline 14903\texttt{metadata} & 14904 14905The metadata keyword allows a rule writer to embed additional information about 14906the rule, typically in a key-value format. \\ 14907 14908\hline 14909\end{longtable} 14910\end{center} 14911 14912\section{Payload Detection Rule Options} 14913\subsection{content} 14914\label{sub:content} 14915 14916The content keyword is one of the more important features of Snort. It allows 14917the user to set rules that search for specific content in the packet payload 14918and trigger response based on that data. Whenever a content option pattern 14919match is performed, the Boyer-Moore pattern match function is called and the 14920(rather computationally expensive) test is performed against the packet 14921contents. If data exactly matching the argument data string is contained 14922anywhere within the packet's payload, the test is successful and the remainder 14923of the rule option tests are performed. Be aware that this test is case 14924sensitive. 14925 14926The option data for the content keyword is somewhat complex; it can contain 14927mixed text and binary data. The binary data is generally enclosed within the 14928pipe ($|$) character and represented as bytecode. Bytecode represents binary 14929data as hexadecimal numbers and is a good shorthand method for describing 14930complex binary data. The example below shows use of mixed text and binary data 14931in a Snort rule. 14932 14933Note that multiple content rules can be specified in one rule. This allows 14934rules to be tailored for less false positives. 14935 14936If the rule is preceded by a \texttt{!}, the alert will be triggered on packets 14937that do not contain this content. This is useful when writing rules that want 14938to alert on packets that do not match a certain pattern 14939 14940\begin{note} 14941 14942Also note that the following characters must be escaped inside a content rule: 14943 14944\begin{verbatim} 14945 ; \ " 14946\end{verbatim} 14947\end{note} 14948 14949\subsubsection{Format} 14950 14951\begin{verbatim} 14952 content:[!]"<content string>"; 14953\end{verbatim} 14954 14955\subsubsection{Examples} 14956 14957\begin{verbatim} 14958 alert tcp any any -> any 139 (content:"|5c 00|P|00|I|00|P|00|E|00 5c|";) 14959\end{verbatim} 14960 14961\begin{verbatim} 14962 alert tcp any any -> any 80 (content:!"GET";) 14963\end{verbatim} 14964 14965\begin{note} 14966 14967A \texttt{!} modifier negates the results of the entire content search, 14968modifiers included. For example, if using \texttt{content:!"A"; within:50;} 14969and there are only 5 bytes of payload and there is no "A" in those 5 bytes, the 14970result will return a match. If there must be 50 bytes for a valid match, use 14971\texttt{isdataat} as a pre-cursor to the content. 14972 14973\end{note} 14974 14975\subsubsection{Changing content behavior} 14976 14977The \texttt{content} keyword has a number of modifier keywords. The modifier 14978keywords change how the previously specified content works. These modifier 14979keywords are: 14980 14981\begin{table}[h] 14982\begin{center} 14983\caption{Content Modifiers} 14984\label{Content Modifiers} 14985\begin{tabular}{|p{1in}|p{1in}|} 14986 14987\hline 14988Modifier & Section \\ 14989\hline 14990 14991\hline 14992nocase & \ref{sub:nocase} \\ 14993 14994\hline 14995rawbytes & \ref{sub:rawbytes} \\ 14996 14997\hline 14998depth & \ref{sub:depth} \\ 14999 15000\hline 15001offset & \ref{sub:offset} \\ 15002 15003\hline 15004distance & \ref{sub:Distance} \\ 15005 15006\hline 15007within & \ref{sub:Within} \\ 15008 15009\hline 15010http\_client\_body & \ref{sub:HttpClientBody} \\ 15011 15012\hline 15013http\_cookie & \ref{sub:HttpCookie} \\ 15014 15015\hline 15016http\_raw\_cookie & \ref{sub:RawHttpCookie} \\ 15017 15018\hline 15019http\_header & \ref{sub:HttpHeader} \\ 15020 15021\hline 15022http\_raw\_header & \ref{sub:RawHttpHeader} \\ 15023 15024\hline 15025http\_method & \ref{sub:HttpMethod} \\ 15026 15027\hline 15028http\_uri & \ref{sub:HttpUri} \\ 15029 15030\hline 15031http\_raw\_uri & \ref{sub:RawHttpUri} \\ 15032 15033\hline 15034http\_stat\_code & \ref{sub:HttpStatCode} \\ 15035 15036\hline 15037http\_stat\_msg & \ref{sub:HttpStatMsg} \\ 15038 15039\hline 15040fast\_pattern & \ref{sub:FastPattern} \\ 15041 15042\hline 15043\end{tabular} 15044\end{center} 15045\end{table} 15046 15047\subsection{protected\_content} 15048\label{sub:protectedcontent} 15049 15050The protected\_content keyword provides much of the functionality of the content keyword, however it performs and is utilized in a very different manner. The primary advantage protected\_content has over content is that protected allows one to hide the target contents by only revealing secure hash digests of said content. As with the content keyword, its primary purpose is to match strings of specific bytes. The search is performed by hashing portions of incoming packets and comparing the results against the hash provided, and as such, it is computationally expensive. 15051 15052Currently, it is possible to utilize the MD5, SHA256, and SHA512 hash algorithms with the protected\_content keyword. A hashing algorithm must be specified in the rule using \texttt{hash} if a default has not be set in the Snort configuration. Additionally, a \texttt{length} modifier must be specified with protected to indicate the length of the raw data. 15053 15054As with content, it is possible to use multiple protected\_content rules can in one rule. Additionally, it is possible to mix multiple protected\_content rules with multiple content rules. 15055 15056If the rule is preceded by a \texttt{!}, the alert will be triggered on packets 15057that do not contain the target content. This is useful when writing rules that want 15058to alert on packets that do not match a certain pattern 15059 15060\begin{note} 15061 15062The protected\_content keyword can be used with some (but not all) of the content modifiers. Those not supported include: 15063\begin{verbatim} 15064 nocase 15065 fast_pattern 15066 depth 15067 within 15068\end{verbatim} 15069 15070\end{note} 15071 15072\subsubsection{Format} 15073 15074\begin{verbatim} 15075 protected_content:[!]"<content hash>", length:orig_len[, hash:md5|sha256|sha512]; 15076\end{verbatim} 15077 15078\subsubsection{Examples} 15079The following alert on the string "HTTP": 15080 15081\begin{verbatim} 15082 alert tcp any any <> any 80 (msg:"MD5 Alert"; 15083 protected_content:"293C9EA246FF9985DC6F62A650F78986"; hash:md5; offset:0; length:4;) 15084\end{verbatim} 15085 15086\begin{verbatim} 15087 alert tcp any any <> any 80 (msg:"SHA256 Alert"; 15088 protected_content:"56D6F32151AD8474F40D7B939C2161EE2BBF10023F4AF1DBB3E13260EBDC6342"; 15089 hash:sha256; offset:0; length:4;) 15090\end{verbatim} 15091 15092\begin{note} 15093 15094A \texttt{!} modifier negates the results of the entire content search, 15095modifiers included. For example, if using \texttt{content:!"A"; within:50;} 15096and there are only 5 bytes of payload and there is no "A" in those 5 bytes, the 15097result will return a match. If there must be 50 bytes for a valid match, use 15098\texttt{isdataat} as a pre-cursor to the content. 15099 15100\end{note} 15101 15102\subsection{hash} 15103\label{sub:hash} 15104 15105The hash keyword is used to specify the hashing algorithm to use when matching a protected\_content rule. If a default algorithm is not specified in the Snort configuration, a protected\_content rule must specify the algorithm used. Currently, MD5, SHA256, and SHA512 are supported. 15106 15107\subsubsection{Format} 15108 15109\begin{verbatim} 15110 hash:[md5|sha256|sha512]; 15111\end{verbatim} 15112 15113\subsection{length} 15114\label{sub:length} 15115 15116The length keyword is used to specify the original length of the content specified in a protected\_content rule digest. The value provided must be greater than 0 and less than 65536. 15117 15118\subsubsection{Format} 15119 15120\begin{verbatim} 15121 length:[<original_length>]; 15122\end{verbatim} 15123 15124\subsection{nocase} 15125\label{sub:nocase} 15126 15127The nocase keyword allows the rule writer to specify that the Snort should look 15128for the specific pattern, ignoring case. nocase modifies the previous 15129\texttt{content} keyword in the rule. 15130 15131\subsubsection{Format} 15132 15133\begin{verbatim} 15134 nocase; 15135\end{verbatim} 15136 15137\subsubsection{Example} 15138 15139\begin{verbatim} 15140 alert tcp any any -> any 21 (msg:"FTP ROOT"; content:"USER root"; nocase;) 15141\end{verbatim} 15142 15143\subsection{rawbytes} 15144\label{sub:rawbytes} 15145 15146The rawbytes keyword allows rules to look at the raw packet data, ignoring any 15147decoding that was done by preprocessors. This acts as a modifier to the 15148previous content \ref{sub:content} option. 15149 15150HTTP Inspect has a set of keywords to use raw data, such as 15151\texttt{http\_raw\_cookie}, \texttt{http\_raw\_header}, \texttt{http\_raw\_uri} etc 15152that match on specific portions of the raw HTTP requests and responses. 15153 15154Most other preprocessors use decoded/normalized data for content match by default, if 15155\texttt{rawbytes} is not specified explicitly. Therefore, \texttt{rawbytes} should 15156be specified in order to inspect arbitrary raw data from the packet. 15157 15158\subsubsection{format} 15159 15160\begin{verbatim} 15161 rawbytes; 15162\end{verbatim} 15163 15164\subsubsection{Example} 15165 15166This example tells the content pattern matcher to look at the raw traffic, 15167instead of the decoded traffic provided by the Telnet decoder. 15168 15169\begin{verbatim} 15170 alert tcp any any -> any 21 (msg:"Telnet NOP"; content:"|FF F1|"; rawbytes;) 15171\end{verbatim} 15172 15173\subsection{depth} 15174\label{sub:depth} 15175 15176The depth keyword allows the rule writer to specify how far into a packet Snort 15177should search for the specified pattern. depth modifies the previous `content' 15178keyword in the rule. 15179 15180A depth of 5 would tell Snort to only look for the specified pattern within the 15181first 5 bytes of the payload. 15182 15183As the depth keyword is a modifier to the previous \texttt{content} keyword, there 15184must be a content in the rule before \texttt{depth} is specified. 15185 15186This keyword allows values greater than or equal to the pattern length being 15187searched. The minimum allowed value is 1. The maximum allowed value for this 15188keyword is 65535. 15189 15190The value can also be set to a string value referencing a variable extracted by the 15191\texttt{byte\_extract} keyword in the same rule. 15192 15193\subsubsection{Format} 15194 15195\begin{verbatim} 15196 depth:[<number>|<var_name>]; 15197\end{verbatim} 15198 15199\subsection{offset} 15200\label{sub:offset} 15201 15202The offset keyword allows the rule writer to specify where to start searching 15203for a pattern within a packet. offset modifies the previous 'content' keyword 15204in the rule. 15205 15206An offset of 5 would tell Snort to start looking for the specified pattern 15207after the first 5 bytes of the payload. 15208 15209As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15210a content in the rule before \texttt{offset} is specified. 15211 15212This keyword allows values from -65535 to 65535. 15213 15214The value can also be set to a string value referencing a variable extracted by the 15215\texttt{byte\_extract} keyword in the same rule. 15216 15217\subsubsection{Format} 15218 15219\begin{verbatim} 15220 offset:[<number>|<var_name>]; 15221\end{verbatim} 15222 15223\subsubsection{Example} 15224 15225The following example shows use of a combined content, offset, and depth search 15226rule. 15227 15228\begin{verbatim} 15229 alert tcp any any -> any 80 (content:"cgi-bin/phf"; offset:4; depth:20;) 15230\end{verbatim} 15231 15232\subsection{distance} 15233\label{sub:Distance} 15234 15235The distance keyword allows the rule writer to specify how far into a packet 15236Snort should ignore before starting to search for the specified pattern 15237relative to the end of the previous pattern match. 15238 15239This can be thought of as exactly the same thing as offset (See Section 15240\ref{sub:offset}), except it is relative to the end of the last pattern match 15241instead of the beginning of the packet. 15242 15243This keyword allows values from -65535 to 65535. 15244 15245The value can also be set to a string value referencing a variable extracted by the 15246\texttt{byte\_extract} keyword in the same rule. 15247 15248\subsubsection{Format} 15249 15250\begin{verbatim} 15251 distance:[<byte_count>|<var_name>]; 15252\end{verbatim} 15253 15254\subsubsection{Example} 15255 15256The rule below maps to a regular expression of /ABC.\{1,\}DEF/. 15257 15258\begin{verbatim} 15259 alert tcp any any -> any any (content:"ABC"; content:"DEF"; distance:1;) 15260\end{verbatim} 15261 15262\subsection{within} 15263\label{sub:Within} 15264 15265The within keyword is a content modifier that makes sure that at most N bytes 15266are between pattern matches using the content keyword ( See Section 15267\ref{sub:content} ). It's designed to be used in conjunction with the distance 15268(Section \ref{sub:Distance}) rule option. 15269 15270This keyword allows values greater than or equal to pattern length being searched. 15271The maximum allowed value for this keyword is 65535. 15272 15273The value can also be set to a string value referencing a variable extracted by the 15274\texttt{byte\_extract} keyword in the same rule. 15275 15276\subsubsection{Format} 15277 15278\begin{verbatim} 15279 within:[<byte_count>|<var_name>]; 15280\end{verbatim} 15281 15282\subsubsection{Examples} 15283 15284This rule constrains the search of EFG to not go past 10 bytes past the ABC match. 15285 15286\begin{verbatim} 15287 alert tcp any any -> any any (content:"ABC"; content:"EFG"; within:10;) 15288\end{verbatim} 15289 15290\subsection{http\_client\_body} 15291\label{sub:HttpClientBody} 15292 15293The http\_client\_body keyword is a content modifier that restricts the search 15294to the body of an HTTP client request. 15295 15296As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15297a content in the rule before 'http\_client\_body' is specified. 15298 15299The amount of data that is inspected with this option depends on the \texttt{post\_depth} 15300config option of HttpInspect. Pattern matches with this keyword wont work when 15301 \texttt{post\_depth} is set to -1. 15302 15303\subsubsection{Format} 15304 15305\begin{verbatim} 15306 http_client_body; 15307\end{verbatim} 15308 15309\subsubsection{Examples} 15310 15311This rule constrains the search for the pattern "EFG" to the raw body of 15312an HTTP client request. 15313 15314\begin{verbatim} 15315 alert tcp any any -> any 80 (content:"ABC"; content:"EFG"; http_client_body;) 15316\end{verbatim} 15317 15318\begin{note} 15319The \texttt{http\_client\_body} modifier is not allowed to be used with 15320the \texttt{rawbytes} modifier for the same content. 15321\end{note} 15322 15323\subsection{http\_cookie} 15324\label{sub:HttpCookie} 15325 15326The http\_cookie keyword is a content modifier that restricts the search to the 15327extracted Cookie Header field (excluding the header name itself and the CRLF terminating 15328the header line) of a HTTP client request or a HTTP server response (per the configuration 15329of HttpInspect \ref{sub:http-inspect}). The Cookie buffer does not include the header 15330names (\texttt{Cookie:} for HTTP requests or \texttt{Set-Cookie:} for HTTP responses) 15331or leading spaces and the CRLF terminating the header line. These are included in the HTTP 15332header buffer. 15333 15334As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15335a content in the rule before \texttt{http\_cookie} is specified. This keyword is dependent 15336on the \texttt{enable\_cookie} config option. The Cookie Header field will be extracted only 15337when this option is configured. If \texttt{enable\_cookie} is not specified, the cookie 15338still ends up in HTTP header. When \texttt{enable\_cookie} is not specified, using 15339\texttt{http\_cookie} is the same as using \texttt{http\_header}. 15340 15341The extracted Cookie Header field may be NORMALIZED, per the configuration of 15342HttpInspect (see \ref{sub:http-inspect}). 15343 15344\subsubsection{Format} 15345 15346\begin{verbatim} 15347 http_cookie; 15348\end{verbatim} 15349 15350\subsubsection{Examples} 15351 15352This rule constrains the search for the pattern "EFG" to the extracted Cookie 15353Header field of a HTTP client request. 15354 15355\begin{verbatim} 15356 alert tcp any any -> any 80 (content:"ABC"; content:"EFG"; http_cookie;) 15357\end{verbatim} 15358 15359\begin{note} 15360 15361The \texttt{http\_cookie} modifier is not allowed to be used with the 15362\texttt{rawbytes} or \texttt{fast\_pattern} modifiers for the same content. 15363 15364\end{note} 15365 15366\subsection{http\_raw\_cookie} 15367\label{sub:RawHttpCookie} 15368 15369The http\_raw\_cookie keyword is a content modifier that restricts the search to the 15370extracted UNNORMALIZED Cookie Header field of a HTTP client request or a HTTP server 15371response (per the configuration of HttpInspect \ref{sub:http-inspect}). 15372 15373As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15374a content in the rule before \texttt{http\_raw\_cookie} is specified. This keyword is dependent 15375on the \texttt{enable\_cookie} config option. The Cookie Header field will be extracted only 15376when this option is configured. 15377 15378\subsubsection{Format} 15379 15380\begin{verbatim} 15381 http_raw_cookie; 15382\end{verbatim} 15383 15384\subsubsection{Examples} 15385 15386This rule constrains the search for the pattern "EFG" to the extracted Unnormalized 15387Cookie Header field of a HTTP client request. 15388 15389\begin{verbatim} 15390 alert tcp any any -> any 80 (content:"ABC"; content:"EFG"; http_raw_cookie;) 15391\end{verbatim} 15392 15393\begin{note} 15394 15395The \texttt{http\_raw\_cookie} modifier is not allowed to be used with the 15396\texttt{rawbytes}, \texttt{http\_cookie} or \texttt{fast\_pattern} modifiers for the same 15397content. 15398 15399\end{note} 15400 15401\subsection{http\_header} 15402\label{sub:HttpHeader} 15403 15404The http\_header keyword is a content modifier that restricts the search to the 15405extracted Header fields of a HTTP client request or a HTTP server response (per the 15406configuration of HttpInspect \ref{sub:http-inspect}). 15407 15408As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15409a content in the rule before \texttt{http\_header} is specified. 15410 15411The extracted Header fields may be NORMALIZED, per the configuration of 15412HttpInspect (see \ref{sub:http-inspect}). 15413 15414\subsubsection{Format} 15415 15416\begin{verbatim} 15417 http_header; 15418\end{verbatim} 15419 15420\subsubsection{Examples} 15421 15422This rule constrains the search for the pattern "EFG" to the extracted Header 15423fields of a HTTP client request or a HTTP server response. 15424 15425\begin{verbatim} 15426 alert tcp any any -> any 80 (content:"ABC"; content:"EFG"; http_header;) 15427\end{verbatim} 15428 15429\begin{note} 15430 15431The \texttt{http\_header} modifier is not allowed to be used with the 15432\texttt{rawbytes} modifier for the same content. 15433 15434\end{note} 15435 15436\subsection{http\_raw\_header} 15437\label{sub:RawHttpHeader} 15438 15439The http\_raw\_header keyword is a content modifier that restricts the search to the 15440extracted UNNORMALIZED Header fields of a HTTP client request or a HTTP server 15441response (per the configuration of HttpInspect \ref{sub:http-inspect}). 15442 15443As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15444a content in the rule before \texttt{http\_raw\_header} is specified. 15445 15446\subsubsection{Format} 15447 15448\begin{verbatim} 15449 http_raw_header; 15450\end{verbatim} 15451 15452\subsubsection{Examples} 15453 15454This rule constrains the search for the pattern "EFG" to the extracted Header fields 15455of a HTTP client request or a HTTP server response. 15456 15457\begin{verbatim} 15458 alert tcp any any -> any 80 (content:"ABC"; content:"EFG"; http_raw_header;) 15459\end{verbatim} 15460 15461\begin{note} 15462 15463The \texttt{http\_raw\_header} modifier is not allowed to be used with the 15464\texttt{rawbytes}, \texttt{http\_header} or \texttt{fast\_pattern} modifiers for the same 15465content. 15466 15467\end{note} 15468 15469\subsection{http\_method} 15470\label{sub:HttpMethod} 15471 15472The http\_method keyword is a content modifier that restricts the search to the 15473extracted Method from a HTTP client request. 15474 15475As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15476a content in the rule before \texttt{http\_method} is specified. 15477 15478\subsubsection{Format} 15479 15480\begin{verbatim} 15481 http_method; 15482\end{verbatim} 15483 15484\subsubsection{Examples} 15485 15486This rule constrains the search for the pattern "GET" to the extracted Method 15487from a HTTP client request. 15488 15489\begin{verbatim} 15490 alert tcp any any -> any 80 (content:"ABC"; content:"GET"; http_method;) 15491\end{verbatim} 15492 15493\begin{note} 15494 15495The \texttt{http\_method} modifier is not allowed to be used with the 15496\texttt{rawbytes} or \texttt{fast\_pattern} modifiers for the same content. 15497 15498\end{note} 15499 15500\subsection{http\_uri} 15501\label{sub:HttpUri} 15502 15503The http\_uri keyword is a content modifier that restricts the search to the 15504NORMALIZED request \textsc{URI} field . Using a content rule option followed 15505by a http\_uri modifier is the same as using a uricontent by itself (see: 15506\ref{sub:UriContent}). 15507 15508As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15509a content in the rule before \texttt{http\_uri} is specified. 15510 15511\subsubsection{Format} 15512 15513\begin{verbatim} 15514 http_uri; 15515\end{verbatim} 15516 15517\subsubsection{Examples} 15518 15519This rule constrains the search for the pattern "EFG" to the NORMALIZED URI. 15520 15521\begin{verbatim} 15522 alert tcp any any -> any 80 (content:"ABC"; content:"EFG"; http_uri;) 15523\end{verbatim} 15524 15525\begin{note} 15526 15527The \texttt{http\_uri} modifier is not allowed to be used with the 15528\texttt{rawbytes} modifier for the same content. 15529 15530\end{note} 15531 15532\subsection{http\_raw\_uri} 15533\label{sub:RawHttpUri} 15534The http\_raw\_uri keyword is a content modifier that restricts the search to the 15535UNNORMALIZED request \textsc{URI} field . 15536 15537As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15538a content in the rule before \texttt{http\_raw\_uri} is specified. 15539 15540\subsubsection{Format} 15541 15542\begin{verbatim} 15543 http_raw_uri; 15544\end{verbatim} 15545 15546\subsubsection{Examples} 15547 15548This rule constrains the search for the pattern "EFG" to the UNNORMALIZED URI. 15549 15550\begin{verbatim} 15551 alert tcp any any -> any 80 (content:"ABC"; content:"EFG"; http_raw_uri;) 15552\end{verbatim} 15553\begin{note} 15554 15555The \texttt{http\_raw\_uri} modifier is not allowed to be used with the 15556\texttt{rawbytes}, \texttt{http\_uri} or \texttt{fast\_pattern} modifiers for the same 15557content. 15558 15559\end{note} 15560 15561\subsection{http\_stat\_code} 15562\label{sub:HttpStatCode} 15563 15564The http\_stat\_code keyword is a content modifier that restricts the search to the 15565extracted Status code field from a HTTP server response. 15566 15567As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15568a content in the rule before \texttt{http\_stat\_code} is specified. 15569 15570The Status Code field will be extracted only if the extended\_response\_inspection is 15571configured for the HttpInspect (see \ref{sub:http-inspect}). 15572 15573\subsubsection{Format} 15574 15575\begin{verbatim} 15576 http_stat_code; 15577\end{verbatim} 15578 15579\subsubsection{Examples} 15580 15581This rule constrains the search for the pattern "200" to the extracted Status Code field 15582of a HTTP server response. 15583 15584\begin{verbatim} 15585 alert tcp any any -> any 80 (content:"ABC"; content:"200"; http_stat_code;) 15586\end{verbatim} 15587 15588\begin{note} 15589 15590The \texttt{http\_stat\_code} modifier is not allowed to be used with the 15591\texttt{rawbytes} or \texttt{fast\_pattern} modifiers for the same content. 15592 15593\end{note} 15594 15595\subsection{http\_stat\_msg} 15596\label{sub:HttpStatMsg} 15597 15598The http\_stat\_msg keyword is a content modifier that restricts the search to the 15599extracted Status Message field from a HTTP server response. 15600 15601As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15602a content in the rule before \texttt{http\_stat\_msg} is specified. 15603 15604The Status Message field will be extracted only if the extended\_response\_inspection is 15605configured for the HttpInspect (see \ref{sub:http-inspect}). 15606 15607\subsubsection{Format} 15608 15609\begin{verbatim} 15610 http_stat_msg; 15611\end{verbatim} 15612 15613\subsubsection{Examples} 15614 15615This rule constrains the search for the pattern "Not Found" to the extracted Status 15616Message field of a HTTP server response. 15617 15618\begin{verbatim} 15619 alert tcp any any -> any 80 (content:"ABC"; content:"Not Found"; http_stat_msg;) 15620\end{verbatim} 15621 15622\begin{note} 15623 15624The \texttt{http\_stat\_msg} modifier is not allowed to be used with the 15625\texttt{rawbytes} or \texttt{fast\_pattern} modifiers for the same content. 15626 15627\end{note} 15628 15629\subsection{http\_encode} 15630\label{sub:HttpEncode} 15631 15632The \texttt{http\_encode} keyword will enable alerting based on encoding type present 15633in a HTTP client request or a HTTP server response (per the configuration of 15634HttpInspect \ref{sub:http-inspect}). 15635 15636There are several keywords associated with \texttt{http\_encode}. The keywords 15637'uri', 'header' and 'cookie' determine the HTTP fields used to search for a 15638particular encoding type. The keywords 'utf8', 'double\_encode', 'non\_ascii', 15639'uencode', 'iis\_encode', 'ascii' and 'bare\_byte' determine the encoding 15640type which would trigger the alert. These keywords can be combined using a OR operation. 15641Negation is allowed on these keywords. 15642 15643The config option 'normalize\_headers' needs to be turned on for rules to work 15644with the keyword 'header'. The keyword 'cookie' is dependent on config options 15645'enable\_cookie' and 'normalize\_cookies' (see \ref{sub:http-inspect}). This 15646rule option will not be able to detect encodings if the specified HTTP fields 15647are not NORMALIZED. 15648 15649\begin{tabular}{| l | p{4.5in} |} 15650\hline 15651{\bf Option} & {\bf Description}\\ 15652\hline 15653\hline 15654\texttt{uri} & Check for the specified encoding type in HTTP client request URI field.\\ 15655\hline 15656\texttt{header} & Check for the specified encoding type in HTTP request or HTTP response header fields 15657(depending on the packet flow)\\ 15658\hline 15659\texttt{cookie} & Check for the specified encoding type in HTTP request or HTTP response cookie 15660header fields (depending on the packet flow)\\ 15661\hline 15662\texttt{utf8} & Check for utf8 encoding in the specified buffer\\ 15663\hline 15664\texttt{double\_encode} & Check for double encoding in the specified buffer\\ 15665\hline 15666\texttt{non\_ascii} & Check for non-ASCII encoding in the specified buffer\\ 15667\hline 15668\texttt{uencode} & Check for u-encoding in the specified buffer\\ 15669\hline 15670\texttt{bare\_byte} & Check for bare byte encoding in the specified buffer\\ 15671\hline 15672\texttt{ascii} & Check for ascii encoding in the specified buffer\\ 15673\hline 15674\texttt{iis\_encode} & Check for IIS Unicode encoding in the specified buffer\\ 15675\hline 15676\end{tabular} 15677 15678\subsubsection{Format} 15679 15680\begin{verbatim} 15681 http_encode:<http buffer type>, [!]<encoding type> 15682 http_encode:[uri|header|cookie], [!][<utf8|double_encode|non_ascii|uencode|bare_byte|ascii|iis_encode>]; 15683\end{verbatim} 15684 15685\subsubsection{Examples} 15686\begin{verbatim} 15687 alert tcp any any -> any any (msg:"UTF8/UEncode Encoding present"; http_encode:uri,utf8|uencode;) 15688 alert tcp any any -> any any (msg:"No UTF8"; http_encode:uri,!utf8;) 15689\end{verbatim} 15690 15691 15692\begin{note} 15693 15694Negation(!) and OR({\tt |}) operations cannot be used in conjunction with each other for the 15695\texttt{http\_encode} keyword. The OR and negation operations work only on the encoding type 15696field and not on http buffer type field. 15697 15698\end{note} 15699 15700\subsection{fast\_pattern} 15701\label{sub:FastPattern} 15702 15703The \texttt{fast\_pattern} keyword is a content modifier that sets the content 15704within a rule to be used with the fast pattern matcher. The default behavior of 15705fast pattern determination is to use the longest HTTP buffer content. If no HTTP 15706buffer is present, then the fast pattern is the longest content. Given this behavior, 15707it is useful if a shorter content is more "unique" than the longer content, 15708meaning the shorter content is less likely to be found in a packet than the longer content. 15709 15710The fast pattern matcher is used to select only those rules that have a 15711chance of matching by using a content in the rule for selection and only 15712evaluating that rule if the content is found in the payload. Though this 15713may seem to be overhead, it can significantly reduce the number of rules 15714that need to be evaluated and thus increases performance. The better the 15715content used for the fast pattern matcher, the less likely the rule will 15716needlessly be evaluated. 15717 15718As this keyword is a modifier to the previous \texttt{content} keyword, there must be 15719a \texttt{content} rule option in the rule before \texttt{fast\_pattern} is specified. 15720The \texttt{fast\_pattern} option may be specified only once per rule. 15721 15722\begin{note} 15723The \texttt{fast\_pattern} modifier cannot be used with the following http 15724content modifiers: \texttt{http\_cookie}, \texttt{http\_raw\_uri}, 15725\texttt{http\_raw\_header}, \texttt{http\_raw\_cookie}, \texttt{http\_method}, 15726\texttt{http\_stat\_code}, \texttt{http\_stat\_msg}. 15727\end{note} 15728 15729\begin{note} 15730The \texttt{fast\_pattern} modifier can be used with negated contents only if 15731those contents are not modified with \texttt{offset}, \texttt{depth}, 15732\texttt{distance} or \texttt{within}. 15733\end{note} 15734 15735\begin{note} 15736The fast pattern matcher is always case insensitive. 15737\end{note} 15738 15739\subsubsection{Format} 15740The \texttt{fast\_pattern} option can be used alone or optionally take arguments. 15741When used alone, the meaning is simply to use the specified content as the 15742fast pattern content for the rule. 15743 15744\begin{verbatim} 15745fast_pattern; 15746\end{verbatim} 15747 15748The optional argument \texttt{only} can be used to specify that the content 15749should only be used for the fast pattern matcher and should not be evaluated 15750as a rule option. This is useful, for example, if a known content must be 15751located in the payload independent of location in the payload, as it saves 15752the time necessary to evaluate the rule option. 15753Note that (1) the modified content must be case insensitive since 15754patterns are inserted into the pattern matcher in a case insensitive manner, 15755(2) negated contents cannot be used and (3) contents cannot have any positional 15756modifiers such as \texttt{offset}, \texttt{depth}, \texttt{distance} 15757or \texttt{within}. 15758\begin{verbatim} 15759fast_pattern:only; 15760\end{verbatim} 15761 15762The optional argument \texttt{<offset>,<length>} can be used to specify that 15763only a portion of the content should be used for the fast pattern matcher. 15764This is useful if the pattern is very long and only a portion of the pattern 15765is necessary to satisfy "uniqueness" thus reducing the memory required to 15766store the entire pattern in the fast pattern matcher. 15767\begin{verbatim} 15768fast_pattern:<offset>,<length>; 15769\end{verbatim} 15770 15771\begin{note} 15772The optional arguments \texttt{only} and \texttt{<offset>,<length>} are 15773mutually exclusive. 15774\end{note} 15775 15776\subsubsection{Examples} 15777 15778This rule causes the pattern "IJKLMNO" to be used with the fast pattern matcher, 15779even though it is shorter than the earlier pattern "ABCDEFGH". 15780 15781\begin{verbatim} 15782alert tcp any any -> any 80 (content:"ABCDEFGH"; content:"IJKLMNO"; fast_pattern;) 15783\end{verbatim} 15784 15785This rule says to use the content "IJKLMNO" for the fast pattern matcher and that 15786the content should only be used for the fast pattern matcher and not evaluated 15787as a \texttt{content} rule option. 15788\begin{verbatim} 15789alert tcp any any -> any 80 (content:"ABCDEFGH"; content:"IJKLMNO"; nocase; fast_pattern:only;) 15790\end{verbatim} 15791 15792This rule says to use "JKLMN" as the fast pattern content, but still evaluate 15793the \texttt{content} rule option as "IJKLMNO". 15794\begin{verbatim} 15795alert tcp any any -> any 80 (content:"ABCDEFGH"; content:"IJKLMNO"; fast_pattern:1,5;) 15796\end{verbatim} 15797 15798\subsection{uricontent} 15799\label{sub:UriContent} 15800 15801The \texttt{uricontent} keyword in the Snort rule language searches the 15802NORMALIZED request \textsc{URI} field. This is equivalent to using the 15803\texttt{http\_uri} modifier to a \texttt{content} keyword. As such if you 15804are writing rules that include things that are normalized, such as \%2f or 15805directory traversals, these rules will not alert. The reason is that the 15806things you are looking for are normalized out of the URI buffer. 15807 15808For example, the URI: 15809 15810\begin{verbatim} 15811 /scripts/..%c0%af../winnt/system32/cmd.exe?/c+ver 15812\end{verbatim} 15813 15814will get normalized into: 15815 15816\begin{verbatim} 15817 /winnt/system32/cmd.exe?/c+ver 15818\end{verbatim} 15819 15820Another example, the URI: 15821 15822\begin{verbatim} 15823 /cgi-bin/aaaaaaaaaaaaaaaaaaaaaaaaaa/..%252fp%68f? 15824\end{verbatim} 15825 15826will get normalized into: 15827 15828\begin{verbatim} 15829 /cgi-bin/phf? 15830\end{verbatim} 15831 15832When writing a \texttt{uricontent} rule, write the content that you want to 15833find in the context that the URI will be normalized. For example, if Snort 15834normalizes directory traversals, do not include directory traversals. 15835 15836You can write rules that look for the non-normalized content by using the 15837content option. (See Section \ref{sub:content}) 15838 15839\texttt{uricontent} can be used with several of the modifiers available to the 15840\texttt{content} keyword. These include: 15841 15842\begin{table}[h] 15843\begin{center} 15844\caption{Uricontent Modifiers} 15845\label{Uricontent Modifiers} 15846\begin{tabular}{|p{1in}|p{1in}|} 15847 15848\hline 15849Modifier & Section \\ 15850\hline 15851 15852\hline 15853nocase & \ref{sub:nocase} \\ 15854 15855\hline 15856depth & \ref{sub:depth} \\ 15857 15858\hline 15859offset & \ref{sub:offset} \\ 15860 15861\hline 15862distance & \ref{sub:Distance} \\ 15863 15864\hline 15865within & \ref{sub:Within} \\ 15866 15867\hline 15868fast\_pattern & \ref{sub:FastPattern} \\ 15869 15870\hline 15871\end{tabular} 15872\end{center} 15873\end{table} 15874 15875 15876This option works in conjunction with the HTTP Inspect preprocessor specified 15877in Section \ref{sub:http-inspect}. 15878 15879\subsubsection{Format} 15880 15881\begin{verbatim} 15882 uricontent:[!]"<content string>"; 15883\end{verbatim} 15884 15885\begin{note} 15886 15887\texttt{uricontent} cannot be modified by a \texttt{rawbytes} modifier or any 15888of the other HTTP modifiers. If you wish to search the UNNORMALIZED 15889request \textsc{URI} field, use the \texttt{http\_raw\_uri} modifier with a 15890\texttt{content} option. 15891 15892\end{note} 15893 15894\subsection{urilen} 15895 15896The \texttt{urilen} keyword in the Snort rule language specifies the exact 15897length, the minimum length, the maximum length, or range of URI lengths to 15898match. By default the raw uri buffer will be used. With the optional 15899\texttt{<uribuf>} argument, you can specify whether the raw or normalized 15900buffer are used. 15901 15902\subsubsection{Format} 15903 15904\begin{verbatim} 15905 urilen:min<>max[,<uribuf>]; 15906 urilen:[<|>]<number>[,<uribuf>]; 15907 15908 <uribuf> : "norm" | "raw" 15909\end{verbatim} 15910 15911The following example will match URIs that are 5 bytes long: 15912 15913\begin{verbatim} 15914 urilen:5; 15915\end{verbatim} 15916 15917The following example will match URIs that are shorter than 5 bytes: 15918 15919\begin{verbatim} 15920 urilen:<5; 15921\end{verbatim} 15922 15923The following example will match URIs that are greater than 5 bytes and less 15924than 10 bytes (inclusive): 15925 15926\begin{verbatim} 15927 urilen:5<>10; 15928\end{verbatim} 15929 15930The following example will match URIs that are greater than 500 bytes using the 15931normalized URI buffer: 15932 15933\begin{verbatim} 15934 urilen:>500,norm; 15935\end{verbatim} 15936 15937The following example will match URIs that are greater than 500 bytes explicitly 15938stating to use the raw URI buffer: 15939 15940\begin{verbatim} 15941 urilen:>500,raw; 15942\end{verbatim} 15943 15944This option works in conjunction with the HTTP Inspect preprocessor specified 15945in Section \ref{sub:http-inspect}. 15946 15947\subsection{isdataat} 15948 15949Verify that the payload has data at a specified location, optionally looking 15950for data relative to the end of the previous content match. 15951 15952\subsubsection{Format} 15953 15954\begin{verbatim} 15955 isdataat:[!]<int>[, relative|rawbytes]; 15956\end{verbatim} 15957 15958\subsubsection{Example} 15959 15960\begin{verbatim} 15961 alert tcp any any -> any 111 (content:"PASS"; isdataat:50,relative; \ 15962 content:!"|0a|"; within:50;) 15963\end{verbatim} 15964 15965This rule looks for the string PASS exists in the packet, then verifies there 15966is at least 50 bytes after the end of the string PASS, then verifies that there 15967is not a newline character within 50 bytes of the end of the PASS string. 15968 15969When the \texttt{rawbytes} modifier is specified with \texttt{isdataat}, it 15970looks at the raw packet data, ignoring any decoding that was done by the 15971preprocessors. This modifier will work with the \texttt{relative} modifier 15972as long as the previous content match was in the raw packet data. 15973 15974A \texttt{!} modifier negates the results of the isdataat test. It will alert 15975if a certain amount of data is not present within the payload. For example, 15976the rule with modifiers \texttt{content:"foo"; isdataat:!10,relative;} would 15977alert if there were not 10 bytes after "foo" before the payload ended. 15978 15979\subsection{pcre} 15980\label{pcre} 15981 15982The pcre keyword allows rules to be written using perl compatible regular 15983expressions. For more detail on what can be done via a pcre regular 15984expression, check out the PCRE web site \url{http://www.pcre.org} 15985 15986\subsubsection{Format} 15987 15988\begin{verbatim} 15989 pcre:[!]"(/<regex>/|m<delim><regex><delim>)[ismxAEGRUBPHMCOIDKYS]"; 15990\end{verbatim} 15991 15992The post-re modifiers set compile time flags for the regular expression. See 15993tables \ref{pcre-mod_perl}, \ref{pcre-mod_pcre}, and \ref{pcre-mod_snort} for 15994descriptions of each modifier. 15995 15996\begin{table}[ht] 15997\begin{center} 15998\caption{Perl compatible modifiers for \texttt{pcre}} 15999\label{pcre-mod_perl} 16000\begin{tabular}{|c|p{4.5in}|} 16001 16002\hline 16003i & case insensitive \\ 16004 16005\hline 16006s & include newlines in the dot metacharacter \\ 16007 16008\hline 16009m & 16010 16011By default, the string is treated as one big line of characters. \^\ and \$ 16012match at the beginning and ending of the string. When m is set, \^\ and \$ 16013match immediately following or immediately before any newline in the buffer, as 16014well as the very start and very end of the buffer. \\ 16015 16016\hline 16017x & 16018 16019whitespace data characters in the pattern are ignored except when escaped or 16020inside a character class \\ 16021 16022\hline 16023\end{tabular} 16024\end{center} 16025\end{table} 16026 16027\begin{table}[ht] 16028\begin{center} 16029\caption{PCRE compatible modifiers for \texttt{pcre}} 16030\label{pcre-mod_pcre} 16031\begin{tabular}{|c|p{4.5in}|} 16032 16033\hline 16034A & 16035 16036the pattern must match only at the start of the buffer (same as \^\ ) \\ 16037 16038\hline 16039E & 16040 16041Set \$ to match only at the end of the subject string. Without E, \$ also 16042matches immediately before the final character if it is a newline (but not 16043before any other newlines). \\ 16044 16045\hline 16046G & 16047 16048Inverts the "greediness" of the quantifiers so that they are not greedy by 16049default, but become greedy if followed by "?". \\ 16050 16051\hline 16052\end{tabular} 16053\end{center} 16054\end{table} 16055 16056\begin{table}[ht] 16057\begin{center} 16058\caption{Snort specific modifiers for \texttt{pcre}} 16059\label{pcre-mod_snort} 16060\begin{tabular}{|c|p{4.5in}|} 16061 16062\hline 16063R & 16064Match relative to the end of the last pattern match. (Similar to distance:0;) \\ 16065 16066\hline 16067U & 16068Match the decoded URI buffers (Similar to \texttt{uricontent} and \texttt{http\_uri}). 16069This modifier is not allowed with the unnormalized HTTP request uri buffer modifier(I) 16070for the same content. \\ 16071 16072\hline 16073I & 16074Match the unnormalized HTTP request uri buffer (Similar to \texttt{http\_raw\_uri}). 16075This modifier is not allowed with the HTTP request uri buffer modifier(U) for the 16076same content. \\ 16077 16078\hline 16079P & 16080Match unnormalized HTTP request body (Similar to \texttt{http\_client\_body}).\\ 16081 16082 & For SIP message, match SIP body for request or response (Similar to \texttt{sip\_body}). \\ 16083 16084\hline 16085H & 16086Match normalized HTTP request or HTTP response header (Similar to \texttt{http\_header}). 16087This modifier is not allowed with the unnormalized HTTP request or HTTP response header 16088modifier(D) for the same content. \\ 16089 & For SIP message, match SIP header for request or response (Similar to \texttt{sip\_header}). \\ 16090 16091\hline 16092D & 16093Match unnormalized HTTP request or HTTP response header (Similar to \texttt{http\_raw\_header}). 16094This modifier is not allowed with the normalized HTTP request or HTTP response header 16095modifier(H) for the same content. \\ 16096 16097\hline 16098M & 16099Match normalized HTTP request method (Similar to \texttt{http\_method}) \\ 16100 16101\hline 16102C & 16103Match normalized HTTP request or HTTP response cookie (Similar to \texttt{http\_cookie}). 16104This modifier is not allowed with the unnormalized HTTP request or HTTP response cookie 16105modifier(K) for the same content. \\ 16106 16107\hline 16108K & 16109Match unnormalized HTTP request or HTTP response cookie (Similar to \texttt{http\_raw\_cookie}). 16110This modifier is not allowed with the normalized HTTP request or HTTP response cookie 16111modifier(C) for the same content. \\ 16112 16113\hline 16114S & 16115Match HTTP response status code (Similar to \texttt{http\_stat\_code}) \\ 16116 16117\hline 16118Y & 16119Match HTTP response status message (Similar to \texttt{http\_stat\_msg}) \\ 16120 16121\hline 16122B & 16123Do not use the decoded buffers (Similar to rawbytes) \\ 16124 16125\hline 16126O & 16127Override the configured pcre match limit and pcre match limit recursion for 16128this expression (See section \ref{Config}). It completely ignores the limits 16129while evaluating the pcre pattern specified. \\ 16130 16131\hline 16132\end{tabular} 16133\end{center} 16134\end{table} 16135 16136\begin{note} 16137The modifiers R (relative) and B (rawbytes) are not allowed with any of the HTTP modifiers such as U, I, 16138P, H, D, M, C, K, S and Y. 16139\end{note} 16140 16141\subsubsection{Example} 16142 16143This example performs a case-insensitive search for the HTTP URI \texttt{foo.php?id=<some numbers>} 16144 16145\begin{verbatim} 16146 alert tcp any any -> any 80 (content:"/foo.php?id="; pcre:"/\/foo.php?id=[0-9]{1,10}/iU";) 16147\end{verbatim} 16148 16149\begin{note} 16150It is wise to have at least one \texttt{content} keyword in a rule that uses \texttt{pcre}. This 16151allows the fast-pattern matcher to filter out non-matching packets so that the pcre evaluation is 16152not performed on each and every packet coming across the wire. 16153\end{note} 16154 16155\begin{note} 16156 16157Snort's handling of multiple URIs with PCRE does not work as expected. PCRE 16158when used without a \texttt{uricontent} only evaluates the first URI. In order 16159to use pcre to inspect all URIs, you must use either a content or a uricontent. 16160 16161\end{note} 16162 16163\subsection{pkt\_data} 16164\label{sub:pkt_data} 16165This option sets the cursor used for detection to the raw transport payload. 16166 16167Any relative or absolute content matches (without HTTP modifiers or rawbytes) and other 16168payload detecting rule options that follow \texttt{pkt\_data} in a rule will apply to the 16169raw TCP/UDP payload or the normalized buffers (in case of telnet, smtp normalization) until 16170the cursor (used for detection) is set again. 16171 16172This rule option can be used several times in a rule. 16173 16174\subsubsection{Format} 16175 16176\begin{verbatim} 16177 pkt_data; 16178\end{verbatim} 16179 16180\subsubsection{Example} 16181 16182\begin{verbatim} 16183 16184 alert tcp any any -> any any(msg:"Absolute Match"; pkt_data; content:"BLAH"; offset:0; depth:10;) 16185 alert tcp any any -> any any(msg:"PKT DATA"; pkt_data; content:"foo"; within:10;) 16186 alert tcp any any -> any any(msg:"PKT DATA"; pkt_data; content:"foo";) 16187 alert tcp any any -> any any(msg:"PKT DATA"; pkt_data; pcre:"/foo/i";) 16188 16189\end{verbatim} 16190 16191\subsection{file\_data} 16192\label{sub:file_data} 16193This option sets the cursor used for detection to one of the following buffers: 161941. When the traffic being detected is HTTP it sets the buffer to, 16195 a. HTTP response body (without chunking/compression/normalization) 16196 b. HTTP de-chunked response body 16197 c. HTTP decompressed response body (when \texttt{inspect\_gzip} is turned on) 16198 d. HTTP normalized response body (when \texttt{normalized\_javascript} is turned on) 16199 e. HTTP UTF normalized response body (when \texttt{normalize\_utf} is turned on) 16200 f. All of the above 162012. When the traffic being detected is SMTP/POP/IMAP it sets the buffer to, 16202 a. SMTP/POP/IMAP data body (including Email headers and MIME when decoding 16203 is turned off) 16204 b. Base64 decoded MIME attachment (when \texttt{b64\_decode\_depth} is greater than -1) 16205 c. Non-Encoded MIME attachment (when \texttt{bitenc\_decode\_depth} is greater than -1) 16206 d. Quoted-Printable decoded MIME attachment (when \texttt{qp\_decode\_depth} is greater than -1) 16207 e. Unix-to-Unix decoded attachment (when \texttt{uu\_decode\_depth} is greater than -1) 162083. If it is not set by 1 and 2, it will be set to the payload. 16209 16210Any relative or absolute content matches (without HTTP modifiers or rawbytes) and payload detecting 16211rule options that follow \texttt{file\_data} in a rule will apply to this buffer until explicitly reset 16212by other rule options. 16213 16214This rule option can be used several time in a rule. 16215 16216The argument \texttt{mime} to \texttt{file\_data} is deprecated. The rule options \texttt{file\_data} will 16217itself point to the decoded MIME attachment. 16218 16219\subsubsection{Format} 16220 16221\begin{verbatim} 16222 file_data; 16223\end{verbatim} 16224 16225\subsubsection{Example} 16226 16227\begin{verbatim} 16228 alert tcp any any -> any any(msg:"Absolute Match"; file_data; content:"BLAH"; offset:0; depth:10;) 16229 alert tcp any any -> any any(msg:"FILE DATA"; file_data; content:"foo"; within:10;) 16230 alert tcp any any -> any any(msg:"FILE DATA"; file_data; content:"foo";) 16231 alert tcp any any -> any any(msg:"FILE DATA"; file_data; pcre:"/foo/i";) 16232 16233 The following rule searches for content "foo" within the file_data buffer and content "bar" within the 16234 entire packet payload. The rule option pkt_data will reset the cursor used for detection to the 16235 TCP payload. 16236 alert tcp any any -> any any(msg:"FILE DATA"; file_data; content:"foo"; pkt_data; content:"bar";) 16237 16238\end{verbatim} 16239 16240 16241\subsection{base64\_decode} 16242\label{sub:base64_decode} 16243 16244This option is used to decode the base64 encoded data. This option is particularly useful 16245in case of HTTP headers such as HTTP authorization headers. This option unfolds the data 16246before decoding it. 16247 16248\subsubsection{Format} 16249 16250\begin{verbatim} 16251 base64_decode[:[bytes <bytes_to_decode>][, ][offset <offset>[, relative]]]; 16252\end{verbatim} 16253 16254\begin{tabular}{| l | p{4.5in} |} 16255\hline 16256{\bf Option} & {\bf Description}\\ 16257\hline 16258\hline 16259\texttt{bytes} & 16260 16261Number of base64 encoded bytes to decode. This argument takes positive and 16262non-zero values only. When this option is not specified we look for base64 16263encoded data till either the end of header line is reached or end of packet 16264payload is reached.\\ 16265\hline 16266\texttt{offset} & 16267 16268Determines the offset relative to the doe\_ptr when the option \texttt{relative} 16269is specified or relative to the start of the packet payload to begin inspection 16270of base64 encoded data. This argument takes positive and non-zero values only.\\ 16271\hline 16272\texttt{relative} & 16273 16274Specifies the inspection for base64 encoded data is relative to the doe\_ptr.\\ 16275 16276\hline 16277\end{tabular} 16278 16279The above arguments to \texttt{base64\_decode} are optional. 16280 16281\begin{note} 16282 16283This option can be extended to protocols with folding similar to HTTP. If folding is not 16284present the search for base64 encoded data will end when we see a carriage return or line feed 16285or both without a following space or tab. 16286 16287This option needs to be used in conjunction with \texttt{base64\_data} for any other 16288payload detecting rule options to work on base64 decoded buffer. 16289\end{note} 16290 16291\subsubsection{Examples} 16292 16293\begin{verbatim} 16294 alert tcp $EXTERNAL_NET any -> $HOME_NET any \ 16295 (msg:"Base64 Encoded Data"; base64_decode; base64_data; \ 16296 content:"foo bar"; within:20;) 16297 16298 alert tcp $EXTERNAL_NET any -> $HOME_NET any \ 16299 (msg:"Authorization NTLM"; content:"Authorization: NTLM"; 16300 base64_decode:relative; base64_data; content:"NTLMSSP"; ) 16301 16302 alert tcp any any -> any any (msg:"Authorization NTLM"; \ 16303 content:"Authorization:"; http_header; \ 16304 base64_decode:bytes 12, offset 6, relative; base64_data; \ 16305 content:"NTLMSSP"; within:8;) 16306\end{verbatim} 16307 16308\subsection{base64\_data} 16309\label{sub:base64_data} 16310This option is similar to the rule option \texttt{file\_data} and is used 16311to set the cursor used for detection to the beginning of the base64 decoded 16312buffer if present. 16313 16314This option does not take any arguments. The rule option \texttt{base64\_decode} 16315needs to be specified before the \texttt{base64\_data} option. 16316 16317\subsubsection{Format} 16318 16319\begin{verbatim} 16320 base64_data; 16321\end{verbatim} 16322 16323This option matches if there is base64 decoded buffer. 16324 16325\begin{note} 16326 16327Fast pattern content matches are not allowed with this buffer. 16328\end{note} 16329 16330 16331\subsubsection{Example} 16332 16333\begin{verbatim} 16334 alert tcp any any -> any any (msg:"Authorization NTLM"; \ 16335 content:"Authorization:"; http_header; \ 16336 base64_decode:bytes 12, offset 6, relative; base64_data; \ 16337 content:"NTLMSSP"; within:8;) 16338\end{verbatim} 16339 16340 16341\subsection{byte\_test} 16342\label{sub:byte_test} 16343 16344Test a byte field against a specific value (with operator). Capable of testing 16345binary values or converting representative byte strings to their binary 16346equivalent and testing them. 16347 16348For a more detailed explanation, please read Section \ref{testing numerical 16349values}. 16350 16351\subsubsection{Format} 16352 16353\footnotesize 16354\begin{verbatim} 16355 byte_test:<bytes to convert>, [!]<operator>, <value>, <offset> \ 16356 [, relative][, <endian>][, string, <number type>][, dce] \ 16357 [, bitmask <bitmask_value>]; 16358 16359 bytes = 1 - 10 16360 operator = '<' | '=' | '>' | '<=' | '>=' | '&' | '^' 16361 value = 0 - 4294967295 16362 offset = -65535 to 65535 16363 bitmask_value = 1 to 4 byte hexadecimal value 16364\end{verbatim} 16365\normalsize 16366 16367\begin{tabular}{| l | p{4.5in} |} 16368\hline 16369{\bf Option} & {\bf Description}\\ 16370\hline 16371\hline 16372\texttt{bytes\_to\_convert} & 16373 16374Number of bytes to pick up from the packet. The allowed values are 1 to 10 when 16375used without \texttt{dce}. If used with \texttt{dce} allowed values are 1, 2 and 4.\\ 16376 16377\hline 16378\texttt{operator} & Operation to perform to test the value: 16379\begin{itemize} 16380\item \textless{} - less than 16381\item \textgreater{} - greater than 16382\item \textless{}= - less than or equal 16383\item \textgreater{}= - greater than or equal 16384\item = - equal 16385\item \& - bitwise AND 16386\item \textasciicircum{} - bitwise OR 16387\end{itemize}\\ 16388\hline 16389\texttt{value} & Value to test the converted value against\\ 16390\hline 16391\texttt{offset} & Number of bytes into the payload to start processing\\ 16392\hline 16393\texttt{relative} & Use an offset relative to last pattern match\\ 16394\hline 16395\texttt{endian} & Endian type of the number being read: 16396\begin{itemize} 16397\item \texttt{big} - Process data as big endian (default) 16398\item \texttt{little} - Process data as little endian 16399\end{itemize}\\ 16400\hline 16401\texttt{string} & Data is stored in string format in packet\\ 16402\hline 16403\texttt{number type} & Type of number being read: 16404\begin{itemize} 16405\item \texttt{hex} - Converted string data is represented in hexadecimal 16406\item \texttt{dec} - Converted string data is represented in decimal 16407\item \texttt{oct} - Converted string data is represented in octal 16408\end{itemize}\\ 16409 16410\hline 16411\texttt{dce} & 16412 16413Let the DCE/RPC 2 preprocessor determine the byte order of the value to be 16414converted. See section \ref{sub:dcerpc2} for a description and examples 16415(\ref{dcerpc2:byte_test_jump} for quick reference).\\ 16416 16417\hline 16418\texttt{bitmask} & 16419Applies the AND operator on the bytes converted. The result will be 16420right-shifted by the number of bits equal to the number of trailing zeros 16421in the mask.\\ 16422\hline 16423\end{tabular} 16424 16425Any of the operators can also include \emph{!} to check if the operator is not 16426true. If \emph{!} is specified without an operator, then the operator is set 16427to \emph{=}. 16428 16429\begin{note} 16430 16431Snort uses the C operators for each of these operators. If the \emph{\&} 16432operator is used, then it would be the same as using \emph{if (data \& value) 16433\{ do\_something();\} } 16434 16435\end{note} 16436 16437\subsubsection{Examples} 16438 16439\begin{verbatim} 16440 alert udp $EXTERNAL_NET any -> $HOME_NET any \ 16441 (msg:"AMD procedure 7 plog overflow"; \ 16442 content:"|00 04 93 F3|"; \ 16443 content:"|00 00 00 07|"; distance:4; within:4; \ 16444 byte_test:4, >, 1000, 20, relative;) 16445 16446 alert tcp $EXTERNAL_NET any -> $HOME_NET any \ 16447 (msg:"AMD procedure 7 plog overflow"; \ 16448 content:"|00 04 93 F3|"; \ 16449 content:"|00 00 00 07|"; distance:4; within:4; \ 16450 byte_test:4, >, 1000, 20, relative;) 16451 16452 alert udp any any -> any 1234 \ 16453 (byte_test:4, =, 1234, 0, string, dec; \ 16454 msg:"got 1234!";) 16455 16456 alert udp any any -> any 1235 \ 16457 (byte_test:3, =, 123, 0, string, dec; \ 16458 msg:"got 123!";) 16459 16460 alert udp any any -> any 1236 \ 16461 (byte_test:2, =, 12, 0, string, dec; \ 16462 msg:"got 12!";) 16463 16464 alert udp any any -> any 1237 \ 16465 (byte_test:10, =, 1234567890, 0, string, dec; \ 16466 msg:"got 1234567890!";) 16467 16468 alert udp any any -> any 1238 \ 16469 (byte_test:8, =, 0xdeadbeef, 0, string, hex; \ 16470 msg:"got DEADBEEF!";) 16471 16472 alert tcp any any -> any any \ 16473 (byte_test:2, =, 568, 0, bitmask 0x3FF0; \ 16474 msg:"got 568 after applying bitmask 0x3FF0 on 2 bytes extracted";) 16475\end{verbatim} 16476 16477\subsection{byte\_jump} 16478\label{sub:byte_jump} 16479 16480The \texttt{byte\_jump} keyword allows rules to be written for length encoded 16481protocols trivially. By having an option that reads the length of a portion of 16482data, then skips that far forward in the packet, rules can be written that skip 16483over specific portions of length-encoded protocols and perform detection in 16484very specific locations. 16485 16486The \texttt{byte\_jump} option does this by reading some number of bytes, 16487convert them to their numeric representation, move that many bytes forward and 16488set a pointer for later detection. This pointer is known as the detect offset 16489end pointer, or doe\_ptr. 16490 16491For a more detailed explanation, please read Section \ref{testing numerical 16492values}. 16493 16494\subsubsection{Format} 16495 16496\begin{verbatim} 16497 byte_jump:<bytes_to_convert>, <offset> [, relative][, multiplier <mult_value>] \ 16498 [, <endian>][, string, <number_type>][, align][, from_beginning][, from_end] \ 16499 [, post_offset <adjustment value>][, dce][, bitmask <bitmask_value>]; 16500 16501 bytes = 1 - 10 16502 offset = -65535 to 65535 16503 mult_value = 0 - 65535 16504 post_offset = -65535 to 65535 16505 bitmask_value = 1 to 4 bytes hexadecimal value 16506 16507\end{verbatim} 16508 16509\begin{tabular}{| l | p{4.5in} |} 16510\hline 16511{\bf Option} & {\bf Description}\\ 16512\hline 16513\hline 16514\texttt{bytes\_to\_convert} & 16515 16516Number of bytes to pick up from the packet. The allowed values are 1 to 10 when 16517used without \texttt{dce}. If used with \texttt{dce} allowed values are 1, 2 and 4. 16518 16519If used with \texttt{from\_end} argument, bytes\_to\_convert can be 0. If 16520bytes\_to\_convert is 0, the extracted value is 0.\\ 16521\hline 16522\texttt{offset} & Number of bytes into the payload to start processing\\ 16523\hline 16524\texttt{relative} & Use an offset relative to last pattern match\\ 16525\hline 16526\texttt{multiplier $<$value$>$} & Multiply the number of calculated bytes by 16527\texttt{$<$value$>$} and skip forward that number of bytes.\\ 16528\hline 16529\texttt{big} & Process data as big endian (default)\\ 16530\hline 16531\texttt{little} & Process data as little endian\\ 16532\hline 16533\texttt{string} & Data is stored in string format in packet\\ 16534\hline 16535\texttt{hex} & Converted string data is represented in hexadecimal\\ 16536\hline 16537\texttt{dec} & Converted string data is represented in decimal\\ 16538\hline 16539\texttt{oct} & Converted string data is represented in octal\\ 16540\hline 16541\texttt{align} & Round the number of converted bytes up to the next 32-bit boundary\\ 16542\hline 16543\texttt{from\_beginning} & Skip forward from the beginning of the packet 16544payload instead of from the current position in the packet.\\ 16545\hline 16546\texttt{from\_end} & The jump will originate from the end of payload\\ 16547\hline 16548\texttt{post\_offset $<$value$>$} & Skip forward or backwards (positive of 16549negative value) \texttt{by $<$value$>$} number of bytes after the other jump 16550options have been applied.\\ 16551\hline 16552\texttt{dce} & Let the DCE/RPC 2 preprocessor determine the byte order of the 16553value to be converted. See section \ref{sub:dcerpc2} for a description and 16554examples (\ref{dcerpc2:byte_test_jump} for quick reference).\\ 16555\hline 16556\texttt{bitmask} & Applies the AND operator on the \texttt{bytes\_to\_convert} 16557argument. The result will be right-shifted by the number of bits equal to the 16558number of trailing zeros in the mask.\\ 16559\hline 16560\end{tabular} 16561 16562\subsubsection{Example} 16563 16564\begin{verbatim} 16565 alert udp any any -> any 32770:34000 (content:"|00 01 86 B8|"; \ 16566 content:"|00 00 00 01|"; distance:4; within:4; \ 16567 byte_jump:4, 12, relative, align; \ 16568 byte_test:4, >, 900, 20, relative; \ 16569 msg:"statd format string buffer overflow";) 16570 16571 alert tcp any any -> any any (content:"Begin"; \ 16572 byte_jump:0, 0, from_end, post_offset -6; \ 16573 content:"end.."; distance:0; within:5; \ 16574 msg:"Content match from end of the payload";) 16575 16576 alert tcp any any -> any any (content:"catalog"; \ 16577 byte_jump:2, 1, relative, post_offset 2, bitmask 0x03f0; \ 16578 byte_test:2, =, 968, 0, relative; \ 16579 msg:"Bitmask applied on the 2 bytes extracted for byte_jump";) 16580 16581 alert tcp any any -> any any (content:"catalog"; \ 16582 byte_jump:1, 2, from_end, post_offset -5, bitmask 0x3c; \ 16583 byte_test:1, =, 106, 0, relative; \ 16584 msg:"Byte jump calculated from end of payload after bitmask applied";) 16585\end{verbatim} 16586 16587\subsection{byte\_extract} 16588\label{byte_extract} 16589 16590The \texttt{byte\_extract} keyword is another useful option for writing rules 16591against length-encoded protocols. It reads in some number of bytes from the 16592packet payload and saves it to a variable. These variables can be referenced 16593later in the rule, instead of using hard-coded values. 16594 16595\begin{note} 16596 16597Only two \texttt{byte\_extract} variables may be created per rule. They can be 16598re-used in the same rule any number of times. 16599 16600\end{note} 16601 16602\subsubsection{Format} 16603 16604\begin{verbatim} 16605 byte_extract:<bytes_to_extract>, <offset>, <name> [, relative] \ 16606 [, multiplier <multiplier value>][, <endian>][, string][, hex][, dec][, oct] \ 16607 [, align <align value>][, dce][, bitmask <bitmask>]; 16608 16609 bytes_to_extract = 1 - 10 16610 operator = '<' | '=' | '>' | '<=' | '>=' | '&' | '^' 16611 value = 0 - 4294967295 16612 offset = -65535 to 65535 16613 bitmask_value = 1 to 4 byte hexadecimal value 16614\end{verbatim} 16615 16616\begin{tabular}{| l | p{4.5in} |} 16617\hline 16618{\bf Option} & {\bf Description}\\ 16619\hline 16620\hline 16621\texttt{bytes\_to\_extract} & Number of bytes to pick up from the packet\\ 16622\hline 16623\texttt{offset} & Number of bytes into the payload to start processing\\ 16624\hline 16625\texttt{name} & Name of the variable. This will be used to reference the 16626variable in other rule options.\\ 16627\hline 16628\texttt{relative} & Use an offset relative to last pattern match\\ 16629\hline 16630\texttt{multiplier $<$value$>$} & Multiply the bytes read from the packet by 16631\texttt{$<$value$>$} and save that number into the variable.\\ 16632\hline 16633\texttt{big} & Process data as big endian (default)\\ 16634\hline 16635\texttt{little} & Process data as little endian\\ 16636\hline 16637\texttt{dce} & Use the DCE/RPC 2 preprocessor to determine the byte-ordering. 16638The DCE/RPC 2 preprocessor must be enabled for this option to work.\\ 16639\hline 16640\texttt{string} & Data is stored in string format in packet\\ 16641\hline 16642\texttt{hex} & Converted string data is represented in hexadecimal\\ 16643\hline 16644\texttt{dec} & Converted string data is represented in decimal\\ 16645\hline 16646\texttt{oct} & Converted string data is represented in octal\\ 16647\hline 16648\texttt{align $<$value$>$} & Round the number of converted bytes up to the next 16649\texttt{$<$value$>$-byte} boundary. \texttt{$<$value$>$} may be \texttt{2} or 16650\texttt{4}.\\ 16651\hline 16652\texttt{bitmask} & Applies the AND operator on the value of \texttt{bytes\_to\_extract} 16653argument. The result will be right-shifted by the number of bits equal to the 16654number of trailing zeros in the mask.\\ 16655\hline 16656\end{tabular} 16657 16658\subsubsection{Other options which use byte\_extract variables} 16659 16660A \texttt{byte\_extract} rule option detects nothing by itself. Its use is in 16661extracting packet data for use in other rule options. Here is a list of places 16662where \texttt{byte\_extract} variables can be used: 16663 16664\begin{tabular}{| l | p{4.5in} |} 16665\hline 16666{\bf Rule Option} & {\bf Arguments that Take Variables}\\ 16667\hline 16668\hline 16669\texttt{content}/\texttt{uricontent} & \texttt{offset}, \texttt{depth}, 16670\texttt{distance}, \texttt{within}\\ 16671\hline 16672\texttt{byte\_test} & \texttt{offset}, \texttt{value}\\ 16673\hline 16674\texttt{byte\_jump} & \texttt{offset}\\ 16675\hline 16676\texttt{isdataat} & \texttt{offset}\\ 16677\hline 16678\end{tabular} 16679 16680\subsubsection{Examples} 16681 16682This example uses two variables to: 16683\begin{itemize} 16684\item Read the offset of a string from a byte at offset 0. 16685\item Read the depth of a string from a byte at offset 1. 16686\item Use these values to constrain a pattern match to a smaller area. 16687\end{itemize} 16688 16689\begin{verbatim} 16690 alert tcp any any -> any any (byte_extract:1, 0, str_offset; \ 16691 byte_extract:1, 1, str_depth; \ 16692 content:"bad stuff"; offset:str_offset; depth:str_depth; \ 16693 msg:"Bad Stuff detected within field";) 16694 16695 alert tcp any any -> any any (content:"|04 63 34 35|"; offset:4; depth:4; \ 16696 byte_extract: 2, 0, var_match, relative, bitmask 0x03ff; \ 16697 byte_test: 2, =, var_match, 2, relative; \ 16698 msg:"Byte test value matches bitmask applied on bytes extracted";) 16699\end{verbatim} 16700 16701\subsection{byte\_math} 16702\label{sub:byte_math} 16703 16704Perform a mathematical operation on an extracted value and a specified value 16705or existing variable, and store the outcome in a new resulting variable. 16706These resulting variables can be referenced later in the rule, 16707instead of using hard-coded values. 16708 16709\subsubsection{Format} 16710 16711\footnotesize 16712\begin{verbatim} 16713 byte_math:bytes <bytes_to_extract>, offset <offset_value>, oper <operator>, 16714 rvalue <r_value>, result <result_variable> [, relative] 16715 [, endian <endian>] [, string <number type>][, dce] 16716 [, bitmask <bitmask_value>]; 16717 16718 bytes_to_extract = 1 - 10 16719 operator = '+' | '-' | '*' | '/' | '<<' | '>>' 16720 r_value = 0 - 4294967295 | byte extract variable 16721 offset_value = -65535 to 65535 16722 bitmask_value = 1 to 4 byte hexadecimal value 16723 result_variable = Result Variable name 16724\end{verbatim} 16725\normalsize 16726 16727\begin{tabular}{| l | p{4.5in} |} 16728\hline 16729{\bf Option} & {\bf Description}\\ 16730\hline 16731\hline 16732\texttt{bytes\_to\_extract} & 16733 16734Number of bytes to pick up from the packet. The allowed values are 1 to 10 when 16735used without \texttt{dce}. If used with \texttt{dce} allowed values are 1, 2 and 4. 16736If used with $<<$ or $>>$ operator, allowed values are 1 to 4.\\ 16737 16738\hline 16739\texttt{oper} & Mathematical Operation to perform on the extracted value 16740Operations allowed: +, -, *, /, $<<$, $>>$\\ 16741\hline 16742\texttt{rvalue} & Value to use mathematical operation against\\ 16743\hline 16744\texttt{offset} & Number of bytes into the payload to start processing\\ 16745\hline 16746\texttt{relative} & Use an offset relative to last pattern match\\ 16747\hline 16748\texttt{endian} & Endian type of the number being read: 16749\begin{itemize} 16750\item \texttt{big} - Process data as big endian (default) 16751\item \texttt{little} - Process data as little endian 16752\end{itemize}\\ 16753\hline 16754\texttt{string} & Data is stored in string format in packet\\ 16755\hline 16756\texttt{number type} & Type of number being read: 16757\begin{itemize} 16758\item \texttt{hex} - Converted string data is represented in hexadecimal 16759\item \texttt{dec} - Converted string data is represented in decimal 16760\item \texttt{oct} - Converted string data is represented in octal 16761\end{itemize}\\ 16762\hline 16763\texttt{dce} & 16764 16765Let the DCE/RPC 2 preprocessor determine the byte order of the value to be 16766converted. See section \ref{sub:dcerpc2} for a description and examples 16767(\ref{dcerpc2:byte_test_jump} for quick reference).\\ 16768 16769\hline 16770\texttt{bitmask} & 16771Applies the AND operator on the bytes extracted. The result will be 16772right-shifted by the number of bits equal to the number of trailing zeros 16773in the mask.\\ 16774\hline 16775\end{tabular} 16776 16777\subsubsection{Other rule options which use byte\_math result variable} 16778 16779\begin{tabular}{| l | p{4.5in} |} 16780\hline 16781{\bf Rule Option} & {\bf Arguments that take result variable}\\ 16782\hline 16783\hline 16784\texttt{content} & \texttt{offset}, \texttt{depth}, 16785\texttt{distance}, \texttt{within}\\ 16786\hline 16787\texttt{byte\_test} & \texttt{offset}, \texttt{value}\\ 16788\hline 16789\texttt{byte\_jump} & \texttt{offset}\\ 16790\hline 16791\texttt{isdataat} & \texttt{offset}\\ 16792\hline 16793\end{tabular} 16794 16795 16796\subsubsection{Examples} 16797 16798\begin{verbatim} 16799 alert udp $EXTERNAL_NET any -> $HOME_NET any \ 16800 (msg:"Perform Arithmetic Operation on the extracted bytes"; \ 16801 content:"|00 04 93 F3|"; \ 16802 content:"|00 00 00 07|"; distance:4; within:4; \ 16803 byte_math:bytes 4, offset 0, oper +, rvalue 248, result var, relative; \ 16804 byte_test:4, >, var, 2, relative;) 16805 16806 alert tcp $EXTERNAL_NET any -> $HOME_NET any \ 16807 (msg:"Bitwise shift operator"; \ 16808 content:"|00 00 00 07|"; distance:4; within:4; \ 16809 byte_extract: 1, 0, extracted_val, relative; \ 16810 byte_math: bytes 1, offset 2, oper >>, rvalue extracted_val, result var, relative; \ 16811 byte_test:2, =, var, 0, relative;) 16812 16813 alert udp any any -> any 1234 \ 16814 (content: "Packets start"; \ 16815 byte_math: bytes 2, offset 0, oper -, rvalue 100, result var, relative, bitmask 0x7FF0; \ 16816 content: "Packets end"; distance: 2; within var; \ 16817 msg:"Content match with bitmask applied to the bytes extracted";) 16818 16819 alert udp any any -> any 1235 \ 16820 (byte_extract: 4, 3, extracted_val, relative; \ 16821 byte_math: bytes 5, offset 0, oper +, rvalue extracted_val, result var, string hex; \ 16822 byte_test:5, =, var, 4, string, hex; \ 16823 msg:"String operator used with math rule option";) 16824 16825\end{verbatim} 16826 16827\subsection{ftpbounce} 16828 16829The ftpbounce keyword detects FTP bounce attacks. 16830 16831\subsubsection{Format} 16832 16833\begin{verbatim} 16834 ftpbounce; 16835\end{verbatim} 16836 16837\subsubsection{Example} 16838 16839\begin{verbatim} 16840 alert tcp $EXTERNAL_NET any -> $HOME_NET 21 (msg:"FTP PORT bounce attempt"; \ 16841 flow:to_server,established; content:"PORT"; nocase; ftpbounce; pcre:"/^PORT/smi";\ 16842 classtype:misc-attack; sid:3441; rev:1;) 16843\end{verbatim} 16844 16845\subsection{asn1} 16846\label{asn1} 16847 16848The ASN.1 detection plugin decodes a packet or a portion of a packet, and looks 16849for various malicious encodings. 16850 16851Multiple options can be used in an 'asn1' option and the implied logic is 16852boolean OR. So if any of the arguments evaluate as true, the whole option 16853evaluates as true. 16854 16855The ASN.1 options provide programmatic detection capabilities as well as some 16856more dynamic type detection. If an option has an argument, the option and the 16857argument are separated by a space or a comma. The preferred usage is to use a 16858space between option and argument. 16859 16860\subsubsection{Format} 16861 16862\begin{verbatim} 16863 asn1:[bitstring_overflow][, double_overflow][, oversize_length <value>][, absolute_offset <value>|relative_offset <value>]; 16864\end{verbatim} 16865 16866\begin{tabular}{| l | p{4.5in} |} 16867\hline 16868{\bf Option} & {\bf Description}\\ 16869\hline 16870 16871\hline 16872\texttt{bitstring\_overflow} & 16873 16874Detects invalid bitstring encodings that are known to be remotely exploitable. 16875\\ 16876 16877\hline 16878\texttt{double\_overflow} & 16879 16880Detects a double ASCII encoding that is larger than a standard buffer. This is 16881known to be an exploitable function in Microsoft, but it is unknown at this 16882time which services may be exploitable. \\ 16883 16884\hline 16885\texttt{oversize\_length $<$value$>$} & 16886 16887Compares ASN.1 type lengths with the supplied argument. The syntax looks like, 16888``oversize\_length 500''. This means that if an ASN.1 type is greater than 16889500, then this keyword is evaluated as true. This keyword must have one 16890argument which specifies the length to compare against. \\ 16891 16892\hline 16893\texttt{absolute\_offset $<$value$>$} & 16894 16895This is the absolute offset from the beginning of the packet. For example, if 16896you wanted to decode snmp packets, you would say ``absolute\_offset 0''. 16897\texttt{absolute\_offset} has one argument, the offset value. Offset may be 16898positive or negative. \\ 16899 16900\hline 16901\texttt{relative\_offset $<$value$>$} & 16902 16903This is the relative offset from the last content match, pcre or byte\_jump. 16904\texttt{relative\_offset} has one argument, the offset number. So if you 16905wanted to start decoding an ASN.1 sequence right after the content ``foo'', 16906you would specify \verb!'content:"foo"; asn1:bitstring_overflow, relative_offset 0'!. 16907Offset values may be positive or negative. \\ 16908 16909\hline 16910\end{tabular} 16911 16912\subsubsection{Examples} 16913 16914\begin{verbatim} 16915 alert udp any any -> any 161 (msg:"Oversize SNMP Length"; \ 16916 asn1:oversize_length 10000, absolute_offset 0;) 16917 16918 alert tcp any any -> any 80 (msg:"ASN1 Relative Foo"; content:"foo"; \ 16919 asn1:bitstring_overflow, relative_offset 0;) 16920\end{verbatim} 16921 16922\subsection{cvs} 16923 16924The CVS detection plugin aids in the detection of: Bugtraq-10384, 16925CVE-2004-0396: "Malformed Entry Modified and Unchanged flag insertion". 16926Default CVS server ports are 2401 and 514 and are included in the default ports 16927for stream reassembly. 16928 16929\begin{note} 16930 16931This plugin cannot do detection over encrypted sessions, e.g. SSH (usually port 1693222). 16933 16934\end{note} 16935 16936\subsubsection{Format} 16937 16938\begin{verbatim} 16939 cvs:<option>; 16940\end{verbatim} 16941 16942\begin{tabular}{| l | p{4.5in} |} 16943\hline 16944{\bf Option} & {\bf Description}\\ 16945\hline 16946 16947\hline 16948\texttt{invalid-entry} & 16949 16950Looks for an invalid Entry string, which is a way of causing a heap overflow 16951(see CVE-2004-0396) and bad pointer dereference in versions of CVS 1.11.15 and 16952before.\\ 16953 16954\hline 16955\end{tabular} 16956 16957\subsubsection{Examples} 16958 16959\begin{verbatim} 16960 alert tcp any any -> any 2401 (msg:"CVS Invalid-entry"; \ 16961 flow:to_server,established; cvs:invalid-entry;) 16962\end{verbatim} 16963 16964\subsection{dce\_iface} 16965 16966See the DCE/RPC 2 Preprocessor section \ref{sub:dcerpc2} for a description and 16967examples of using this rule option. 16968 16969\subsection{dce\_opnum} 16970 16971See the DCE/RPC 2 Preprocessor section \ref{sub:dcerpc2} for a description and 16972examples of using this rule option. 16973 16974\subsection{dce\_stub\_data} 16975 16976See the DCE/RPC 2 Preprocessor section \ref{sub:dcerpc2} for a description and 16977examples of using this rule option. 16978 16979\subsection{sip\_method} 16980 16981See the SIP Preprocessor section \ref{sub:sip} for a description and 16982examples of using this rule option. 16983 16984\subsection{sip\_stat\_code} 16985 16986See the SIP Preprocessor section \ref{sub:sip} for a description and 16987examples of using this rule option. 16988 16989\subsection{sip\_header} 16990 16991See the SIP Preprocessor section \ref{sub:sip} for a description and 16992examples of using this rule option. 16993 16994\subsection{sip\_body} 16995 16996See the SIP Preprocessor section \ref{sub:sip} for a description and 16997examples of using this rule option. 16998 16999\subsection{gtp\_type} 17000 17001See the GTP Preprocessor section \ref{sub:gtp} for a description and 17002examples of using this rule option. 17003 17004\subsection{gtp\_info} 17005 17006See the GTP Preprocessor section \ref{sub:gtp} for a description and 17007examples of using this rule option. 17008 17009\subsection{gtp\_version} 17010 17011See the GTP Preprocessor section \ref{sub:gtp} for a description and 17012examples of using this rule option. 17013 17014%\subsection{content-list} 17015% 17016%The content-list keyword is broken and should not be used. 17017 17018%The content-list keyword allows multiple content strings to be specified 17019%in the place of a single content option. The patterns to be searched 17020%for must each be on a single line of content-list file as shown in 17021%Figure \ref{content-list example}, but they are treated otherwise 17022%identically to content strings specified as an argument to a standard 17023%content directive. This option is the basis for the react keyword. 17024% 17025%% 17026%\begin{figure} 17027%\begin{verbatim} 17028%# adult sites 17029%\end{verbatim} 17030%\caption{\label{content-list example}Content-list adults 17031%file example} 17032%\end{figure} 17033% 17034% 17035%\subsubsection{Format} 17036% 17037%\begin{verbatim} 17038%content-list: <file_name>; 17039%\end{verbatim} 17040 17041\subsection{ssl\_version} 17042 17043See the SSL/TLS Preprocessor section \ref{sub:SSL/TLS} for a description and examples of 17044using this rule option. 17045 17046\subsection{ssl\_state} 17047 17048See the SSL/TLS Preprocessor section \ref{sub:SSL/TLS} for a description and examples of 17049using this rule option. 17050 17051\subsection{Payload Detection Quick Reference} 17052\begin{center} 17053\begin{longtable}[h]{| p{1in} | p{4.5in} |} 17054\caption{Payload detection rule option keywords} \\ 17055 17056\hline 17057Keyword & Description \\ 17058\hline 17059 17060\hline 17061\texttt{content} & 17062 17063The content keyword allows the user to set rules that search for specific 17064content in the packet payload and trigger response based on that data. \\ 17065 17066\hline 17067\texttt{rawbytes} & 17068 17069The rawbytes keyword allows rules to look at the raw packet data, ignoring any 17070decoding that was done by preprocessors. \\ 17071 17072\hline 17073\texttt{depth} & 17074 17075The depth keyword allows the rule writer to specify how far into a packet Snort 17076should search for the specified pattern. \\ 17077 17078\hline 17079\texttt{offset} & 17080 17081The offset keyword allows the rule writer to specify where to start searching 17082for a pattern within a packet. \\ 17083 17084\hline 17085\texttt{distance} & 17086 17087The distance keyword allows the rule writer to specify how far into a packet 17088Snort should ignore before starting to search for the specified pattern 17089relative to the end of the previous pattern match. \\ 17090 17091\hline 17092\texttt{within} & 17093 17094The within keyword is a content modifier that makes sure that at most N bytes 17095are between pattern matches using the content keyword. \\ 17096 17097\hline 17098\texttt{uricontent} & 17099 17100The uricontent keyword in the Snort rule language searches the normalized 17101request URI field. \\ 17102 17103\hline 17104\texttt{isdataat} & 17105 17106The isdataat keyword verifies that the payload has data at a specified 17107location. \\ 17108 17109\hline 17110\texttt{pcre} & 17111 17112The pcre keyword allows rules to be written using perl compatible regular 17113expressions. \\ 17114 17115\hline 17116\texttt{byte\_test} & 17117 17118The byte\_test keyword tests a byte field against a specific value (with 17119operator). \\ 17120 17121\hline 17122\texttt{byte\_jump} & 17123 17124The byte\_jump keyword allows rules to read the length of a portion of data, 17125then skip that far forward in the packet. \\ 17126 17127\hline 17128\texttt{ftpbounce} & 17129 17130The ftpbounce keyword detects FTP bounce attacks. \\ 17131 17132%\hline 17133%\texttt{content-list} & 17134%The content-list keyword is broken and should not be used. \\ 17135 17136\hline 17137\texttt{asn1} & 17138 17139The asn1 detection plugin decodes a packet or a portion of a packet, and looks 17140for various malicious encodings. \\ 17141 17142\hline 17143\texttt{cvs} & 17144 17145The cvs keyword detects invalid entry strings. \\ 17146 17147\hline 17148\texttt{dce\_iface} & 17149 17150See the DCE/RPC 2 Preprocessor section \ref{dcerpc2:dce_iface}. \\ 17151 17152\hline 17153\texttt{dce\_opnum} & 17154 17155See the DCE/RPC 2 Preprocessor section \ref{dcerpc2:dce_opnum}. \\ 17156 17157\hline 17158\texttt{dce\_stub\_data} & 17159 17160See the DCE/RPC 2 Preprocessor section \ref{dcerpc2:dce_stub_data}. \\ 17161 17162\hline 17163\texttt{sip\_method} & 17164 17165See the SIP Preprocessor section \ref{sub:sip}. \\ 17166 17167\hline 17168\texttt{sip\_stat\_code} & 17169 17170See the SIP Preprocessor section \ref{sub:sip}.\\ 17171 17172\hline 17173\texttt{sip\_header} & 17174 17175See the SIP Preprocessor section \ref{sub:sip}.\\ 17176 17177\hline 17178\texttt{sip\_body} & 17179 17180See the SIP Preprocessor section \ref{sub:sip}.\\ 17181 17182\hline 17183\texttt{gtp\_type} & 17184 17185See the GTP Preprocessor section \ref{sub:gtp}.\\ 17186 17187\hline 17188\texttt{gtp\_info} & 17189 17190See the GTP Preprocessor section \ref{sub:gtp}.\\ 17191 17192\hline 17193\texttt{gtp\_version} & 17194 17195See the GTP Preprocessor section \ref{sub:gtp}.\\ 17196 17197\hline 17198\end{longtable} 17199\end{center} 17200 17201\section{Non-Payload Detection Rule Options} 17202\subsection{fragoffset} 17203\label{fragoffset section} 17204 17205The fragoffset keyword allows one to compare the IP fragment offset field 17206against a decimal value. To catch all the first fragments of an IP session, you 17207could use the fragbits keyword and look for the More fragments option in 17208conjunction with a fragoffset of 0. 17209 17210\subsubsection{Format} 17211 17212\begin{verbatim} 17213 fragoffset:[!|<|>]<number>; 17214\end{verbatim} 17215 17216\subsubsection{Example} 17217 17218\begin{verbatim} 17219 alert ip any any -> any any \ 17220 (msg:"First Fragment"; fragbits:M; fragoffset:0;) 17221\end{verbatim} 17222 17223\subsection{ttl} 17224 17225The ttl keyword is used to check the IP time-to-live value. This option 17226keyword was intended for use in the detection of traceroute attempts. This 17227 keyword takes numbers from 0 to 255. 17228 17229\subsubsection{Format} 17230 17231\begin{verbatim} 17232 ttl:[<, >, =, <=, >=]<number>; 17233 ttl:[<number>]-[<number>]; 17234\end{verbatim} 17235 17236\subsubsection{Example} 17237 17238This example checks for a time-to-live value that is less than 3. 17239 17240\begin{verbatim} 17241 ttl:<3; 17242\end{verbatim} 17243 17244This example checks for a time-to-live value that between 3 and 5. 17245 17246\begin{verbatim} 17247 ttl:3-5; 17248\end{verbatim} 17249 17250This example checks for a time-to-live value that between 0 and 5. 17251 17252\begin{verbatim} 17253 ttl:-5; 17254\end{verbatim} 17255 17256This example checks for a time-to-live value that between 5 and 255. 17257 17258\begin{verbatim} 17259 ttl:5-; 17260\end{verbatim} 17261 17262Few other examples are as follows: 17263 17264\begin{verbatim} 17265 ttl:<=5; 17266 ttl:>=5; 17267 ttl:=5; 17268\end{verbatim} 17269 17270The following examples are NOT allowed by ttl keyword: 17271 17272\begin{verbatim} 17273 ttl:=>5; 17274 ttl:=<5; 17275 ttl:5-3; 17276\end{verbatim} 17277 17278 17279 17280\subsection{tos} 17281 17282The tos keyword is used to check the IP TOS field for a specific value. 17283 17284\subsubsection{Format} 17285 17286\begin{verbatim} 17287 tos:[!]<number>; 17288\end{verbatim} 17289 17290\subsubsection{Example} 17291 17292This example looks for a tos value that is not 4 17293 17294\begin{verbatim} 17295 tos:!4; 17296\end{verbatim} 17297 17298\subsection{id} 17299 17300The id keyword is used to check the IP ID field for a specific value. Some 17301tools (exploits, scanners and other odd programs) set this field specifically 17302for various purposes, for example, the value 31337 is very popular with some 17303hackers. 17304 17305\subsubsection{Format} 17306 17307\begin{verbatim} 17308 id:<number>; 17309\end{verbatim} 17310 17311\subsubsection{Example} 17312 17313This example looks for the IP ID of 31337. 17314 17315\begin{verbatim} 17316 id:31337; 17317\end{verbatim} 17318 17319\subsection{ipopts} 17320 17321The ipopts keyword is used to check if a specific IP option is present. 17322 17323The following options may be checked: 17324 17325\begin{description} 17326\item [rr] - Record Route 17327\item [eol] - End of list 17328\item [nop] - No Op 17329\item [ts] - Time Stamp 17330\item [sec] - IP Security 17331\item [esec] - IP Extended Security 17332\item [lsrr] - Loose Source Routing 17333\item [lsrre] - Loose Source Routing (For MS99-038 and CVE-1999-0909) 17334\item [ssrr] - Strict Source Routing 17335\item [satid] - Stream identifier 17336\item [any] - any IP options are set 17337\end{description} 17338 17339The most frequently watched for IP options are strict and loose source routing 17340which aren't used in any widespread internet applications. 17341 17342\subsubsection{Format} 17343 17344\begin{verbatim} 17345 ipopts:<rr|eol|nop|ts|sec|esec|lsrr|lsrre|ssrr|satid|any>; 17346\end{verbatim} 17347 17348\subsubsection{Example} 17349 17350This example looks for the IP Option of Loose Source Routing. 17351 17352\begin{verbatim} 17353 ipopts:lsrr; 17354\end{verbatim} 17355 17356\subsubsection{Warning} 17357 17358Only a single ipopts keyword may be specified per rule. 17359 17360\subsection{fragbits} 17361 17362The \texttt{fragbits} keyword is used to check if fragmentation and reserved 17363bits are set in the IP header. 17364 17365The following bits may be checked: 17366 17367\begin{description} 17368\item [M] - More Fragments 17369\item [D] - Don't Fragment 17370\item [R] - Reserved Bit 17371\end{description} 17372 17373The following modifiers can be set to change the match criteria: 17374 17375\begin{description} 17376\item [+] match on the specified bits, plus any others 17377\item [*] match if any of the specified bits are set 17378\item [!] match if the specified bits are not set 17379\end{description} 17380 17381\subsubsection{Format} 17382 17383\begin{verbatim} 17384 fragbits:[+*!]<[MDR]>; 17385\end{verbatim} 17386 17387\subsubsection{Example} 17388 17389This example checks if the More Fragments bit and the Do not Fragment bit are 17390set. 17391 17392\begin{verbatim} 17393 fragbits:MD+; 17394\end{verbatim} 17395 17396\subsection{dsize} 17397 17398The dsize keyword is used to test the packet payload size. This may be used to 17399check for abnormally sized packets that might cause buffer overflows. 17400 17401\subsubsection{Format} 17402 17403\begin{verbatim} 17404 dsize:min<>max; 17405 dsize:[<|>]<number>; 17406\end{verbatim} 17407 17408\subsubsection{Example} 17409 17410This example looks for a dsize that is between 300 and 400 bytes (inclusive). 17411 17412\begin{verbatim} 17413 dsize:300<>400; 17414\end{verbatim} 17415 17416\subsubsection{Warning} 17417 17418Note that segmentation makes dsize less reliable for TCP based protocols such 17419as HTTP. Furthermore, dsize will fail on stream rebuilt packets, regardless of 17420the size of the payload, unless protocol aware flushing (PAF) marks this packet 17421as the start of a message. 17422 17423\subsection{flags} 17424 17425The flags keyword is used to check if specific TCP flag bits are present. 17426 17427The following bits may be checked: 17428 17429\begin{description} 17430\item [F] - FIN - Finish (LSB in TCP Flags byte) 17431\item [S] - SYN - Synchronize sequence numbers 17432\item [R] - RST - Reset 17433\item [P] - PSH - Push 17434\item [A] - ACK - Acknowledgment 17435\item [U] - URG - Urgent 17436\item [C] - CWR - Congestion Window Reduced (MSB in TCP Flags byte) 17437\item [E] - ECE - ECN-Echo (If SYN, then ECN capable. Else, CE flag in IP header is set) 17438\item [0] - No TCP Flags Set 17439\end{description} 17440 17441The following modifiers can be set to change the match criteria: 17442 17443\begin{description} 17444\item [+] - match on the specified bits, plus any others 17445\item [*] - match if any of the specified bits are set 17446\item [!] - match if the specified bits are not set 17447\end{description} 17448 17449To handle writing rules for session initiation packets such as ECN where a SYN 17450packet is sent with CWR and ECE set, an option mask 17451may be specified by preceding the mask with a comma. A rule could check for a flags value of S,CE if one wishes to 17452find packets with just the syn bit, regardless of the values of the reserved 17453bits. 17454 17455\subsubsection{Format} 17456 17457\begin{verbatim} 17458 flags:[!|*|+]<FSRPAUCE0>[,<FSRPAUCE>]; 17459\end{verbatim} 17460 17461\subsubsection{Example} 17462 17463This example checks if just the SYN and the FIN bits are set, ignoring CWR (reserved 17464bit 1) and ECN (reserved bit 2). 17465 17466\begin{verbatim} 17467 alert tcp any any -> any any (flags:SF,CE;) 17468\end{verbatim} 17469 17470\begin{note} 17471 17472The reserved bits '1' and '2' have been replaced with 'C' and 'E', respectively, 17473to match RFC 3168, "The Addition of Explicit Congestion Notification (ECN) to IP". 17474The old values of '1' and '2' are still valid for the \texttt{flag} keyword, but 17475are now deprecated. 17476 17477\end{note} 17478\subsection{flow} 17479\label{flow section} 17480 17481The flow keyword is used in conjunction with session tracking (see Section 17482\ref{session section}). It allows rules to only apply to certain directions of 17483the traffic flow. 17484 17485This allows rules to only apply to clients or servers. This allows packets 17486related to \$HOME\_NET clients viewing web pages to be distinguished from 17487servers running in the \$HOME\_NET. 17488 17489The established keyword will replace the \texttt{flags:+A} used in many places 17490to show established TCP connections. 17491 17492\subsubsection*{Options} 17493 17494\begin{tabular}{| l | p{4.5in} |} 17495\hline 17496{\bf Option} & {\bf Description}\\ 17497\hline 17498\hline 17499\texttt{to\_client} & Trigger on server responses from A to B\\ 17500\hline 17501\texttt{to\_server} & Trigger on client requests from A to B\\ 17502\hline 17503\texttt{from\_client} & Trigger on client requests from A to B\\ 17504\hline 17505\texttt{from\_server} & Trigger on server responses from A to B\\ 17506\hline 17507\texttt{established} & Trigger only on established TCP connections\\ 17508\hline 17509\texttt{not\_established} & Trigger only when no TCP connection is established\\ 17510\hline 17511\texttt{stateless} & Trigger regardless of the state of the stream processor 17512(useful for packets that are designed to cause machines to crash)\\ 17513\hline 17514\texttt{no\_stream} & Do not trigger on rebuilt stream packets (useful 17515for dsize and stream5)\\ 17516\hline 17517\texttt{only\_stream} & Only trigger on rebuilt stream 17518packets\\ 17519\hline 17520\texttt{no\_frag} & Do not trigger on rebuilt frag packets\\ 17521\hline 17522\texttt{only\_frag} & Only trigger on rebuilt frag packets\\ 17523\hline 17524\end{tabular} 17525 17526\subsubsection{Format} 17527 17528\begin{verbatim} 17529 flow:[(established|not_established|stateless)] 17530 [,(to_client|to_server|from_client|from_server)] 17531 [,(no_stream|only_stream)] 17532 [,(no_frag|only_frag)]; 17533\end{verbatim} 17534 17535\subsubsection{Examples} 17536 17537\begin{verbatim} 17538 alert tcp !$HOME_NET any -> $HOME_NET 21 (msg:"cd incoming detected"; \ 17539 flow:from_client; content:"CWD incoming"; nocase;) 17540 17541 alert tcp !$HOME_NET 0 -> $HOME_NET 0 (msg:"Port 0 TCP traffic"; \ 17542 flow:stateless;) 17543\end{verbatim} 17544 17545\subsection{flowbits} 17546\label{flowbits} 17547 17548The \texttt{flowbits} keyword is used in conjunction with conversation tracking 17549from the Session preprocessor (see Section\ref{session section}). It allows 17550rules to track states during a transport protocol session. The flowbits option 17551is most useful for TCP sessions, as it allows rules to generically track the 17552state of an application protocol. 17553 17554There are several keywords associated with flowbits. Most of the options need a 17555user-defined name for the specific state that is being checked. Some keyword 17556uses group name. When no group name is specified the flowbits will belong to a 17557default group. A particular flowbit can belong to more than one group. 17558Flowbit name and group name should be limited to any alphanumeric string 17559including periods, dashes, and underscores. 17560 17561\subsubsection{General Format} 17562 17563\begin{verbatim} 17564 flowbits:[set|setx|unset|toggle|isset|isnotset|noalert|reset][, <bits/bats>][, <GROUP_NAME>]; 17565 bits ::= bit[|bits] 17566 bats ::= bit[&bats] 17567\end{verbatim} 17568 17569\begin{tabular}{| l | p{4.5in} |} 17570\hline 17571{\bf Option} & {\bf Description}\\ 17572\hline 17573\hline 17574\texttt{set} & Sets the specified states for the current flow and assign them to a group when a GROUP\_NAME is specified.\\ 17575\hline 17576\texttt{setx} & Sets the specified states for the current flow and clear other states in the group\\ 17577\hline 17578\texttt{unset} & Unsets the specified states for the current flow.\\ 17579\hline 17580\texttt{toggle} & For every state specified, sets the specified state if the state is unset and unsets it if the state is set.\\ 17581\hline 17582\texttt{isset} & Checks if the specified states are set.\\ 17583\hline 17584\texttt{isnotset} & Checks if the specified states are not set.\\ 17585\hline 17586\texttt{noalert} & Cause the rule to not generate an alert, regardless of the rest of the detection options.\\ 17587\hline 17588\texttt{reset} & Reset all states on a given flow.\\ 17589\hline 17590\end{tabular} 17591 17592\subsubsection{set} 17593This keyword sets bits to group for a particular flow. When no group specified, set the default group. This keyword always returns true. 17594 17595\begin{verbatim} 17596Syntax: 17597 flowbits:set,bats[,group] 17598Usage: 17599 flowbits:set,bit1,doc; 17600 flowbits:set,bit2&bit3,doc; 17601 First rule sets bit1 in doc group, second rule sets bit2 and bit3 in doc group. 17602 So doc group has bit 1, bit2 and bit3 set 17603\end{verbatim} 17604 17605\subsubsection{setx} 17606This keyword sets bits to group exclusively. This clears other bits in group. 17607Group must present.This keyword always returns true. 17608\begin{verbatim} 17609Syntax: 17610 flowbits:setx,bats,group 17611Usage: 17612 flowbits: setx, bit1, doc 17613 flowbits: setx, bit2&bit3, doc 17614 First rule sets bit1 in doc group, second rule sets bit2 and bit3 in doc group. 17615 So doc group has bit2 and bit3 set, because bit1 is cleared by rule 2. 17616 \end{verbatim} 17617 17618\subsubsection{unset} 17619This keyword clears bits specified for a particular flow or clears all bits in the 17620group (Group must present). This keyword always returns true. 17621 17622\begin{verbatim} 17623Syntax: 17624 flowbits:unset,bats 17625 flowbits:unset,all,group 17626 17627Usage: 17628 flowbits: unset, bit1 17629 Clear bit1. 17630 17631 flowbits: unset, bit1&bit2 17632 Clear bit1 and bit2 17633 17634 flowbits: unset, all, doc 17635 This clears all bits in the doc group. 17636\end{verbatim} 17637 17638 17639\subsubsection{toggle} 17640If flowbit is set, unset it. If it is unset, set it. Toggle every bit specified or 17641toggle all the bits in group (Group must be present). This keyword always returns true. 17642 17643\begin{verbatim} 17644Syntax: 17645 flowbits:toggle,bats 17646 flowbits:toggle,all,group 17647 17648Usage: 17649 flowbits: toggle, bit1&bit2 17650 If bit1 is 0 and bit2 is 1 before, after this rule, bit1 is 1 and bit2 is 0. 17651 17652 flowbits:toggle,all,doc 17653 Toggle all the bits in group doc as described above. 17654\end{verbatim} 17655 17656\subsubsection{isset} 17657This keyword checks a bit or several bits to see if it is set. It returns true or 17658false based on the following syntax. 17659 17660\begin{verbatim} 17661Syntax: 17662 flowbits:isset, bits => Check whether any bit is set 17663 flowbits:isset, bats => Check whether all bits are set 17664 flowbits:isset, any, group => Check whether any bit in the group is set. 17665 flowbits:isset, all, group => Check whether all bits in the group are set. 17666 17667Usage 17668 flowbits:isset, bit1|bit2 => If either bit1 or bit2 is set, return true 17669 flowbits:isset, bit1&bit2 => If both bit1 and bit2 are set, return true, otherwise false 17670 flowbits:isset, any, doc => If any bit in group doc is set, return true 17671 flowbits:isset, all, doc => If all the bits in doc group are set, return true 17672\end{verbatim} 17673 17674\subsubsection{isnotset} 17675This keyword is the reverse of isset. It returns true if isset is false, it returns 17676false if isset is true. Isnotset works on the final result, not on individual bits. 17677 17678\begin{verbatim} 17679Syntax: 17680 flowbits:isnotset, bits => Check whether not any bit is set 17681 flowbits:isnotset, bats => Check whether not all bits are set 17682 flowbits:isnotset, any, group => Check whether not bit in the group is set. 17683 flowbits:isnotset, all, group => Check whether not all bits in the group are set. 17684 17685Usage 17686 flowbits:isnotset, bit1|bit2 => If either bit1 or bit2 is set, return true 17687 flowbits:isnotset, bit1&bit2 => If both bit1 and bit2 are set, return true, otherwise false 17688 flowbits:isnotset, any, doc => If any bit in group doc is set, return true 17689 flowbits:isnotset, all, doc => If all the bits in doc group are set, return true 17690\end{verbatim} 17691 17692 17693\subsubsection{noalert} 17694This keyword always returns false. It allows users to write rules that set, 17695unset, and toggle bit without generating an alert. This is most useful 17696for writing flowbit rules that set bit on normal traffic and significantly reduces 17697unwanted alerts. There is no bit specified with this keyword. 17698 17699\begin{verbatim} 17700 flowbits:noalert; 17701\end{verbatim} 17702 17703\subsubsection{reset} 17704 17705This keyword resets all of the states on a given flow if no group specified, otherwise, 17706reset all the bits in a group. This always returns true. There is no bit specified with 17707 this keyword. 17708 17709\begin{verbatim} 17710Syntax: 17711 flowbits:reset[,group] 17712 17713Usage: 17714 flowbits:reset => reset all the bits in the flow 17715 flowbits: reset, doc => reset all the bits in the doc group 17716\end{verbatim} 17717 17718\subsubsection{Examples} 17719 17720\begin{verbatim} 17721 alert tcp any 143 -> any any (msg:"IMAP login"; 17722 content:"OK LOGIN"; flowbits:set,logged_in; 17723 flowbits:noalert;) 17724 17725 alert tcp any any -> any 143 (msg:"IMAP LIST"; content:"LIST"; 17726 flowbits:isset,logged_in;) 17727 17728\end{verbatim} 17729 17730\subsection{seq} 17731 17732The seq keyword is used to check for a specific TCP sequence number. 17733 17734\subsubsection{Format} 17735 17736\begin{verbatim} 17737 seq:<number>; 17738\end{verbatim} 17739 17740\subsubsection{Example} 17741 17742This example looks for a TCP sequence number of 0. 17743 17744\begin{verbatim} 17745 seq:0; 17746\end{verbatim} 17747 17748\subsection{ack} 17749 17750The ack keyword is used to check for a specific TCP acknowledge number. 17751 17752\subsubsection{Format} 17753 17754\begin{verbatim} 17755 ack:<number>; 17756\end{verbatim} 17757 17758\subsubsection{Example} 17759 17760This example looks for a TCP acknowledge number of 0. 17761 17762\begin{verbatim} 17763 ack:0; 17764\end{verbatim} 17765 17766\subsection{window} 17767 17768The window keyword is used to check for a specific TCP window size. 17769 17770\subsubsection{Format} 17771 17772\begin{verbatim} 17773 window:[!]<number>; 17774\end{verbatim} 17775 17776\subsubsection{Example} 17777 17778This example looks for a TCP window size of 55808. 17779 17780\begin{verbatim} 17781 window:55808; 17782\end{verbatim} 17783 17784\subsection{itype} 17785 17786The itype keyword is used to check for a specific ICMP type value. 17787 17788\subsubsection{Format} 17789 17790\begin{verbatim} 17791 itype:min<>max; 17792 itype:[<|>]<number>; 17793\end{verbatim} 17794 17795\subsubsection{Example} 17796 17797This example looks for an ICMP type greater than 30. 17798 17799\begin{verbatim} 17800 itype:>30; 17801\end{verbatim} 17802 17803\subsection{icode} 17804 17805The icode keyword is used to check for a specific ICMP code value. 17806 17807\subsubsection{Format} 17808 17809\begin{verbatim} 17810 icode:min<>max; 17811 icode:[<|>]<number>; 17812\end{verbatim} 17813 17814The \texttt{<>} operator in the first format checks for an ICMP code within a specified range (exclusive). That is, strictly greater than the min value and strictly less than the max value. Note that the min value can a \texttt{-1} allowing an ICMP code of zero to be included in the range. 17815 17816Numerical values are validated with respect to permissible ICMP code values between 0 and 255 and other criteria. 17817 17818\begin{verbatim} 17819 icode:min<>max 17820 -1 <= min <= 254 17821 1 <= max <= 256 17822 (max - min) > 1 17823 17824 icode:number 17825 0 <= number <= 255 17826 17827 icode:<number 17828 1 <= number <= 256 17829 17830 icode:>number 17831 0 <= number <= 254 17832\end{verbatim} 17833 17834\subsubsection{Examples} 17835 17836This example looks for an ICMP code greater than 30. 17837 17838\begin{verbatim} 17839 icode:>30; 17840\end{verbatim} 17841 17842This example looks for an ICMP code greater than zero and less than 30. 17843 17844\begin{verbatim} 17845 icode:-1<>30; 17846\end{verbatim} 17847 17848\subsection{icmp\_id} 17849 17850The icmp\_id keyword is used to check for a specific ICMP ID value. 17851 17852This is useful because some covert channel programs use static ICMP fields when 17853they communicate. This particular plugin was developed to detect the 17854stacheldraht DDoS agent. 17855 17856\subsubsection{Format} 17857 17858\begin{verbatim} 17859 icmp_id:<number>; 17860\end{verbatim} 17861 17862\subsubsection{Example} 17863 17864This example looks for an ICMP ID of 0. 17865 17866\begin{verbatim} 17867 icmp_id:0; 17868\end{verbatim} 17869 17870\subsection{icmp\_seq} 17871 17872The icmp\_seq keyword is used to check for a specific ICMP sequence value. 17873 17874This is useful because some covert channel programs use static ICMP fields when 17875they communicate. This particular plugin was developed to detect the 17876stacheldraht DDoS agent. 17877 17878\subsubsection{Format} 17879 17880\begin{verbatim} 17881 icmp_seq:<number>; 17882\end{verbatim} 17883 17884\subsubsection{Example} 17885 17886This example looks for an ICMP Sequence of 0. 17887 17888\begin{verbatim} 17889 icmp_seq:0; 17890\end{verbatim} 17891 17892\subsection{rpc} 17893 17894The rpc keyword is used to check for a RPC application, version, and procedure 17895numbers in SUNRPC CALL requests. 17896 17897Wildcards are valid for both version and procedure numbers by using '*'; 17898 17899\subsubsection{Format} 17900 17901\begin{verbatim} 17902 rpc:<application number>, [<version number>|*], [<procedure number>|*]>; 17903\end{verbatim} 17904 17905\subsubsection{Example} 17906 17907The following example looks for an RPC portmap GETPORT request. 17908 17909\begin{verbatim} 17910 alert tcp any any -> any 111 (rpc:100000, *, 3;); 17911\end{verbatim} 17912 17913\subsubsection{Warning} 17914 17915Because of the fast pattern matching engine, the RPC keyword is slower than 17916looking for the RPC values by using normal content matching. 17917 17918\subsection{ip\_proto} 17919 17920The ip\_proto keyword allows checks against the IP protocol header. For a list 17921of protocols that may be specified by name, see /etc/protocols. 17922 17923\subsubsection{Format} 17924 17925\begin{verbatim} 17926 ip_proto:[!|>|<] <name or number>; 17927\end{verbatim} 17928 17929\subsubsection{Example} 17930 17931This example looks for IGMP traffic. 17932 17933\begin{verbatim} 17934 alert ip any any -> any any (ip_proto:igmp;) 17935\end{verbatim} 17936 17937\subsection{sameip} 17938 17939The sameip keyword allows rules to check if the source ip is the same as the 17940destination IP. 17941 17942\subsubsection{Format} 17943 17944\begin{verbatim} 17945 sameip; 17946\end{verbatim} 17947 17948\subsubsection{Example} 17949 17950This example looks for any traffic where the Source IP and the Destination IP 17951is the same. 17952 17953\begin{verbatim} 17954 alert ip any any -> any any (sameip;) 17955\end{verbatim} 17956 17957\subsection{stream\_reassemble} 17958 17959The stream\_reassemble keyword allows a rule to enable or disable TCP stream reassembly 17960on matching traffic. 17961 17962\begin{note} 17963 17964The stream\_reassemble option is only available when the Stream preprocessor is 17965enabled. 17966 17967\end{note} 17968 17969\subsubsection{Format} 17970 17971\begin{verbatim} 17972 stream_reassemble:<enable|disable>, <server|client|both>[, noalert][, fastpath]; 17973\end{verbatim} 17974 17975\begin{itemize} 17976\item The optional \texttt{noalert} parameter causes the rule to not generate 17977an alert when it matches. 17978\item The optional \texttt{fastpath} parameter causes Snort to ignore the rest of the 17979connection. 17980\end{itemize} 17981 17982\subsubsection{Example} 17983 17984For example, to disable TCP reassembly for client traffic when we see a 17985HTTP 200 Ok Response message, use: 17986 17987\begin{verbatim} 17988 alert tcp any 80 -> any any (flow:to_client, established; content:"200 OK"; 17989 stream_reassemble:disable,client,noalert;) 17990\end{verbatim} 17991 17992\subsection{stream\_size} 17993 17994The stream\_size keyword allows a rule to match traffic according to the number 17995of bytes observed, as determined by the TCP sequence numbers. 17996 17997\begin{note} 17998 17999The stream\_size option is only available when the Stream preprocessor is 18000enabled. 18001 18002\end{note} 18003 18004\subsubsection{Format} 18005 18006\begin{verbatim} 18007 stream_size:<server|client|both|either>, <operator>, <number>; 18008\end{verbatim} 18009 18010Where the operator is one of the following: 18011 18012\begin{itemize} 18013\item $<$ - less than 18014\item $>$ - greater than 18015\item = - equal 18016\item != - not equal 18017\item $<$= - less than or equal 18018\item $>$= - greater than or equal 18019\end{itemize} 18020 18021\subsubsection{Example} 18022 18023For example, to look for a session that is less that 6 bytes from the client 18024side, use: 18025 18026\begin{verbatim} 18027 alert tcp any any -> any any (stream_size:client,<,6;) 18028\end{verbatim} 18029 18030\subsection{Non-Payload Detection Quick Reference} 18031\begin{center} 18032\begin{longtable}[h]{| p{1in} | p{4.5in} |} 18033\caption{Non-payload detection rule option keywords} \\ 18034 18035\hline 18036Keyword & Description \\ 18037\hline 18038 18039\hline 18040\texttt{fragoffset} & 18041 18042The fragoffset keyword allows one to compare the IP fragment offset field 18043against a decimal value. \\ 18044 18045\hline 18046\texttt{ttl} & 18047 18048The ttl keyword is used to check the IP time-to-live value. \\ 18049 18050\hline 18051\texttt{tos} & 18052 18053The tos keyword is used to check the IP TOS field for a specific value. \\ 18054 18055\hline 18056\texttt{id} & 18057 18058The id keyword is used to check the IP ID field for a specific value. \\ 18059 18060\hline 18061\texttt{ipopts} & 18062 18063The ipopts keyword is used to check if a specific IP option is present. \\ 18064 18065\hline 18066\texttt{fragbits} & 18067 18068The fragbits keyword is used to check if fragmentation and reserved bits are 18069set in the IP header. \\ 18070 18071\hline 18072\texttt{dsize} & 18073 18074The dsize keyword is used to test the packet payload size. \\ 18075 18076\hline 18077\texttt{flags} & 18078 18079The flags keyword is used to check if specific TCP flag bits are present. \\ 18080 18081\hline 18082\texttt{flow} & 18083 18084The flow keyword allows rules to only apply to certain directions of the 18085traffic flow. \\ 18086 18087\hline 18088\texttt{flowbits} & 18089 18090The flowbits keyword allows rules to track states during a transport protocol 18091session. \\ 18092 18093\hline 18094\texttt{seq} & 18095 18096The seq keyword is used to check for a specific TCP sequence number. \\ 18097 18098\hline 18099\texttt{ack} & 18100 18101The ack keyword is used to check for a specific TCP acknowledge number. \\ 18102 18103\hline 18104\texttt{window} & 18105 18106The window keyword is used to check for a specific TCP window size. \\ 18107 18108\hline 18109\texttt{itype} & 18110 18111The itype keyword is used to check for a specific ICMP type value. \\ 18112 18113\hline 18114\texttt{icode} & 18115 18116The icode keyword is used to check for a specific ICMP code value. \\ 18117 18118\hline 18119\texttt{icmp\_id} & 18120 18121The icmp\_id keyword is used to check for a specific ICMP ID value. \\ 18122 18123\hline 18124\texttt{icmp\_seq} & 18125 18126The icmp\_seq keyword is used to check for a specific ICMP sequence value. \\ 18127 18128\hline 18129\texttt{rpc} & 18130 18131The rpc keyword is used to check for a RPC application, version, and procedure 18132numbers in SUNRPC CALL requests. \\ 18133 18134\hline 18135\texttt{ip\_proto} & 18136 18137The ip\_proto keyword allows checks against the IP protocol header. \\ 18138 18139\hline 18140\texttt{sameip} & 18141 18142The sameip keyword allows rules to check if the source ip is the same as the 18143destination IP. \\ 18144 18145\hline 18146\end{longtable} 18147\end{center} 18148 18149\section{Post-Detection Rule Options} 18150\subsection{logto} 18151 18152The logto keyword tells Snort to log all packets that trigger this rule to a 18153special output log file. This is especially handy for combining data from 18154things like NMAP activity, HTTP CGI scans, etc. It should be noted that this 18155option does not work when Snort is in binary logging mode. 18156 18157\subsubsection{Format} 18158 18159\begin{verbatim} 18160 logto:"filename"; 18161\end{verbatim} 18162 18163\subsection{session} 18164 18165The session keyword is built to extract user data from TCP Sessions. There are 18166many cases where seeing what users are typing in telnet, rlogin, ftp, or even 18167web sessions is very useful. 18168 18169There are three available argument keywords for the session rule option: 18170\texttt{printable}, \texttt{binary}, or \texttt{all}. 18171 18172The \texttt{printable} keyword only prints out data that the user 18173would normally see or be able to type. The \texttt{binary} keyword prints out data in a 18174binary format. The \texttt{all} keyword substitutes non-printable characters with 18175their hexadecimal equivalents. 18176 18177\subsubsection{Format} 18178 18179\begin{verbatim} 18180 session:[printable|binary|all]; 18181\end{verbatim} 18182 18183\subsubsection{Example} 18184 18185The following example logs all printable strings in a telnet packet. 18186 18187\begin{verbatim} 18188 log tcp any any <> any 23 (session:printable;) 18189\end{verbatim} 18190 18191Given an FTP data session on port 12345, this example logs the payload bytes 18192in binary form. 18193 18194\begin{verbatim} 18195 log tcp any any <> any 12345 (metadata:service ftp-data; session:binary;) 18196\end{verbatim} 18197 18198\subsubsection{Warnings} 18199 18200Using the session keyword can slow Snort down considerably, so it should not be 18201used in heavy load situations. The session keyword is best suited for 18202post-processing binary (pcap) log files. 18203 18204The \texttt{binary} keyword does not log any protocol headers below the 18205application layer, and Stream reassembly will cause duplicate data when 18206the reassembled packets are logged. 18207 18208\subsection{resp} 18209 18210The resp keyword enables an active response that kills the offending session. 18211Resp can be used in both passive or inline modes. See \ref{resp section} for 18212details. 18213 18214\subsection{react} 18215 18216The react keyword enables an active response that includes sending a web page 18217or other content to the client and then closing the connection. React can be 18218used in both passive and inline modes. See \ref{react section} for details. 18219 18220\subsection{tag} 18221\label{tag section} 18222 18223The tag keyword allow rules to log more than just the single packet that 18224triggered the rule. Once a rule is triggered, additional traffic involving the 18225source and/or destination host is \emph{tagged}. Tagged traffic is logged to 18226allow analysis of response codes and post-attack traffic. \emph{tagged} alerts 18227will be sent to the same output plugins as the original alert, but it is the 18228responsibility of the output plugin to properly handle these special alerts. 18229 18230\subsubsection{Format} 18231 18232\begin{verbatim} 18233 tag:host, <count>, <metric>, <direction>; 18234 tag:session[, <count>, <metric>][, exclusive]; 18235\end{verbatim} 18236 18237\begin{description}{} 18238\item [\texttt{type}]~ 18239 18240\begin{itemize}{} 18241\item \texttt{session} - Log packets in the session that set off the rule 18242 18243\item \texttt{host} - Log packets from the host that caused the tag to activate 18244(uses {[}direction{]} modifier) 18245 18246\end{itemize} 18247 18248\item [\texttt{count}]~ 18249\begin{itemize}{} 18250 18251\item \texttt{<integer>} - Count is specified as a number of units. Units are 18252specified in the $<$metric$>$ field. 18253 18254\end{itemize}{} 18255 18256\item [\texttt{metric}]~ 18257 18258\begin{itemize}{} 18259\item \texttt{packets} - Tag the host/session for $<$count$>$ packets 18260\item \texttt{seconds} - Tag the host/session for $<$count$>$ seconds 18261\item \texttt{bytes} - Tag the host/session for $<$count$>$ bytes 18262\end{itemize} 18263 18264\item [\texttt{other}] 18265 18266\begin{itemize}{} 18267 18268\item \texttt{src} - Tag packets containing the source IP address of the packet 18269that generated the initial event. Only relevant if host type is used. 18270 18271\item \texttt{dst} - Tag packets containing the destination IP address of the 18272packet that generated the initial event. Only relevant if host type is used. 18273 18274\item \texttt{exclusive} - Tag packets only in the first matching session. 18275Only relevant if session type is used. 18276 18277\end{itemize} 18278\end{description} 18279 18280Note that neither subsequent alerts nor event filters will prevent a tagged 18281packet from being logged. Subsequent tagged alerts will cause the limit to 18282reset. 18283 18284\begin{verbatim} 18285 alert tcp any any <> 10.1.1.1 any \ 18286 (flowbits:isnotset,tagged; content:"foobar"; nocase; \ 18287 flowbits:set,tagged; tag:host,600,seconds,src;) 18288\end{verbatim} 18289 18290Also note that if you have a tag option in a rule that uses a metric other than 18291\texttt{packets}, a \texttt{tagged\_packet\_limit} will be used to limit the 18292number of tagged packets regardless of whether the \texttt{seconds} or 18293\texttt{bytes} count has been reached. The default 18294\texttt{tagged\_packet\_limit} value is 256 and can be modified by using a 18295config option in your snort.conf file (see Section \ref{Config} on how to use 18296the \texttt{tagged\_packet\_limit} config option). You can disable this packet 18297limit for a particular rule by adding a \texttt{packets} metric to your tag 18298option and setting its count to 0 (This can be done on a global scale by 18299setting the \texttt{tagged\_packet\_limit} option in snort.conf to 0). Doing 18300this will ensure that packets are tagged for the full amount of 18301\texttt{seconds} or \texttt{bytes} and will not be cut off by the 18302\texttt{tagged\_packet\_limit}. (Note that the \texttt{tagged\_packet\_limit} 18303was introduced to avoid DoS situations on high bandwidth sensors for tag rules 18304with a high \texttt{seconds} or \texttt{bytes} counts.) 18305 18306\begin{verbatim} 18307 alert tcp 10.1.1.4 any -> 10.1.1.1 any \ 18308 (content:"TAGMYPACKETS"; tag:host,0,packets,600,seconds,src;) 18309\end{verbatim} 18310 18311\subsubsection{Example} 18312 18313This example logs the first 10 seconds or the \texttt{tagged\_packet\_limit} 18314(whichever comes first) of any telnet session. 18315 18316\begin{verbatim} 18317 alert tcp any any -> any 23 (flags:S,CE; tag:session,10,seconds;) 18318\end{verbatim} 18319 18320While at least one count and metric is required for tag:host, tag:session 18321with exclusive without any metrics can be used to get a full session like 18322this: 18323 18324\begin{verbatim} 18325 pass tcp any any -> 192.168.1.1 80 (flags:S; tag:session,exclusive;) 18326\end{verbatim} 18327 18328\subsection{replace} 18329\label{replace} 18330 18331The \texttt{replace} keyword is a feature available in inline mode which will 18332cause Snort to replace the prior matching content with the given string. Both 18333the new string and the content it is to replace must have the same length. You 18334can have multiple replacements within a rule, one per content. 18335 18336\begin{verbatim} 18337 replace:"<string>"; 18338\end{verbatim} 18339 18340\subsection{detection\_filter} 18341\label{detection_filter} 18342 18343detection\_filter defines a rate which must be exceeded by a source or 18344destination host before a rule can generate an event. detection\_filter has 18345the following format: 18346 18347\begin{verbatim} 18348 detection_filter: \ 18349 track <by_src|by_dst>, \ 18350 count <c>, seconds <s>; 18351\end{verbatim} 18352 18353\begin{table}[h] 18354\begin{center} 18355\begin{tabular}{| p{1in} | p{4.5in} |} 18356 18357\hline 18358Option & Description \\ 18359\hline 18360 18361\hline 18362\texttt{track by\_src|by\_dst} & 18363 18364Rate is tracked either by source IP address or destination IP address. This 18365means count is maintained for each unique source IP address or each unique 18366destination IP address.\\ 18367 18368\hline 18369\texttt{count c} & 18370 18371The maximum number of rule matches in s seconds allowed before the detection 18372filter limit to be exceeded. C must be nonzero.\\ 18373 18374\hline 18375\texttt{seconds s} & 18376 18377Time period over which count is accrued. The value must be nonzero.\\ 18378 18379\hline 18380\end{tabular} 18381\end{center} 18382\end{table} 18383 18384Snort evaluates a \texttt{detection\_filter} as the last step of the detection 18385phase, after evaluating all other rule options (regardless of the position of 18386the filter within the rule source). At most one \texttt{detection\_filter} is 18387permitted per rule. 18388 18389Example - this rule will fire on every failed login attempt from 10.1.2.100 18390during one sampling period of 60 seconds, after the first 30 failed login 18391attempts: 18392 18393\begin{verbatim} 18394 drop tcp 10.1.2.100 any > 10.1.1.100 22 ( \ 18395 msg:"SSH Brute Force Attempt"; 18396 flow:established,to_server; \ 18397 content:"SSH"; nocase; offset:0; depth:4; \ 18398 detection_filter:track by_src, count 30, seconds 60; \ 18399 sid:1000001; rev:1;) 18400\end{verbatim} 18401 18402Since potentially many events will be generated, a \texttt{detection\_filter} 18403would normally be used in conjunction with an \texttt{event\_filter} to reduce 18404the number of logged events. 18405 18406\begin{note} 18407As mentioned above, Snort evaluates \texttt{detection\_filter} as the last step of 18408the detection and not in post-detection. 18409\end{note} 18410 18411\subsection{Post-Detection Quick Reference} 18412 18413\begin{center} 18414\begin{longtable}[h]{| p{1in} | p{4.5in} |} 18415\caption{Post-detection rule option keywords} \\ 18416 18417\hline 18418Keyword & Description \\ 18419\hline 18420 18421\hline 18422\texttt{logto} & 18423 18424The logto keyword tells Snort to log all packets that trigger this rule to a 18425special output log file. \\ 18426 18427\hline 18428\texttt{session} & 18429 18430The session keyword is built to extract user data from TCP Sessions. \\ 18431 18432\hline 18433\texttt{resp} & 18434 18435The resp keyword is used attempt to close sessions when an alert is triggered. 18436\\ 18437 18438\hline 18439\texttt{react} & 18440 18441This keyword implements an ability for users to react to traffic that matches a 18442Snort rule by closing connection and sending a notice. \\ 18443 18444\hline 18445\texttt{tag} & 18446 18447The tag keyword allow rules to log more than just the single packet that 18448triggered the rule. \\ 18449 18450\hline 18451\texttt{replace} & 18452 18453Replace the prior matching content with the given string of the same length. 18454Available in inline mode only.\\ 18455 18456\hline 18457\texttt{detection\_filter} & 18458 18459Track by source or destination IP address and if the rule otherwise matches 18460more than the configured rate it will fire.\\ 18461 18462\hline 18463\end{longtable} 18464\end{center} 18465 18466\section{Rule Thresholds} 18467 18468\begin{note} 18469Rule thresholds are deprecated and will not be supported in a future release. 18470Use \texttt{detection\_filter}s (\ref{detection_filter}) within rules, or 18471\texttt{event\_filter}s (\ref{event_filtering}) as standalone configurations 18472instead. 18473\end{note} 18474 18475\texttt{threshold} can be included as part of a rule, or you can use standalone 18476thresholds that reference the generator and SID they are applied to. There is 18477no functional difference between adding a threshold to a rule, or using a 18478standalone threshold applied to the same rule. There is a logical difference. 18479Some rules may only make sense with a threshold. These should incorporate the 18480threshold into the rule. For instance, a rule for detecting a too many login 18481password attempts may require more than 5 attempts. This can be done using the 18482`limit' type of threshold. It makes sense that the threshold feature is an 18483integral part of this rule. 18484 18485\paragraph{Format} 18486 18487\begin{verbatim} 18488 threshold: \ 18489 type <limit|threshold|both>, \ 18490 track <by_src|by_dst>, \ 18491 count <c>, seconds <s>; 18492\end{verbatim} 18493 18494\begin{table}[h] 18495\begin{center} 18496\begin{tabular}{| l | p{4.5in} |} 18497 18498\hline 18499\textbf{Option} & \textbf{Description}\\ 18500\hline 18501 18502\hline 18503\texttt{type limit|threshold|both} & 18504 18505type \texttt{limit} alerts on the 1st m events during the time interval, then 18506ignores events for the rest of the time interval. Type \texttt{threshold} 18507alerts every m times we see this event during the time interval. Type 18508\texttt{both} alerts once per time interval after seeing m occurrences of the 18509event, then ignores any additional events during the time interval.\\ 18510 18511\hline 18512\texttt{track by\_src|by\_dst} & 18513 18514rate is tracked either by source IP address, or destination IP address. This 18515means count is maintained for each unique source IP addresses, or for each 18516unique destination IP addresses. Ports or anything else are not tracked.\\ 18517 18518\hline 18519\texttt{count c} & 18520 18521number of rule matching in s seconds that will cause \texttt{event\_filter} 18522limit to be exceeded. \texttt{c} must be nonzero value.\\ 18523 18524\hline 18525\texttt{seconds s} & 18526 18527time period over which \texttt{count} is accrued. \texttt{s} must be nonzero 18528value.\\ 18529 18530\hline 18531\end{tabular} 18532\end{center} 18533\end{table} 18534 18535\subsubsection{Examples} 18536 18537This rule logs the first event of this SID every 60 seconds. 18538 18539\begin{verbatim} 18540 alert tcp $external_net any -> $http_servers $http_ports \ 18541 (msg:"web-misc robots.txt access"; flow:to_server, established; \ 18542 uricontent:"/robots.txt"; nocase; reference:nessus,10302; \ 18543 classtype:web-application-activity; threshold:type limit, track \ 18544 by_src, count 1 , seconds 60; sid:1000852; rev:1;) 18545\end{verbatim} 18546 18547This rule logs every 10th event on this SID during a 60 second interval. So if 18548less than 10 events occur in 60 seconds, nothing gets logged. Once an event is 18549logged, a new time period starts for type=threshold. 18550 18551\begin{verbatim} 18552 alert tcp $external_net any -> $http_servers $http_ports \ 18553 (msg:"web-misc robots.txt access"; flow:to_server, established; \ 18554 uricontent:"/robots.txt"; nocase; reference:nessus,10302; \ 18555 classtype:web-application-activity; threshold:type threshold, \ 18556 track by_dst, count 10 , seconds 60 ; sid:1000852; rev:1;) 18557\end{verbatim} 18558 18559This rule logs at most one event every 60 seconds if at least 10 events on this 18560SID are fired. 18561 18562\begin{verbatim} 18563 alert tcp $external_net any -> $http_servers $http_ports \ 18564 (msg:"web-misc robots.txt access"; flow:to_server, established; \ 18565 uricontent:"/robots.txt"; nocase; reference:nessus,10302; \ 18566 classtype:web-application-activity; threshold:type both, track \ 18567 by_dst, count 10, seconds 60; sid:1000852; rev:1;) 18568\end{verbatim} 18569 18570\section{Writing Good Rules} 18571 18572There are some general concepts to keep in mind when developing Snort rules to 18573maximize efficiency and speed. 18574 18575\subsection{Content Matching} 18576 18577Snort groups rules by protocol (ip, tcp, udp, icmp), then by ports 18578(ip and icmp use slightly different logic), then by those with \texttt{content} 18579and those without. For rules with \texttt{content}, a multi-pattern matcher is 18580used to select rules that have a chance at matching based on a single content. 18581Selecting rules for evaluation via this "fast" pattern matcher was found to 18582increase performance, especially when applied to large rule groups like HTTP. 18583The longer and more unique a \texttt{content} is, the less likely that rule and 18584all of its rule options will be evaluated unnecessarily - it's safe to say 18585there is generally more "good" traffic than "bad". Rules without 18586\texttt{content} are always evaluated (relative to the protocol and port group 18587in which they reside), potentially putting a drag on performance. 18588While some detection options, such as \texttt{pcre} and \texttt{byte\_test}, 18589perform detection in the payload section of the packet, they are not used by the 18590fast pattern matching engine. If at all possible, try and have at least one 18591\texttt{content} (or \texttt{uricontent}) rule option in your rule. 18592 18593\subsection{Catch the Vulnerability, Not the Exploit} 18594 18595Try to write rules that target the vulnerability, instead of a specific 18596exploit. 18597 18598For example, look for a the vulnerable command with an argument that is too 18599large, instead of shellcode that binds a shell. 18600 18601By writing rules for the vulnerability, the rule is less vulnerable to evasion 18602when an attacker changes the exploit slightly. 18603 18604\subsection{Catch the Oddities of the Protocol in the Rule} 18605 18606Many services typically send the commands in upper case letters. FTP is a good 18607example. In FTP, to send the username, the client sends: 18608 18609\begin{verbatim} 18610 user username_here 18611\end{verbatim} 18612 18613A simple rule to look for FTP root login attempts could be: 18614 18615\begin{verbatim} 18616 alert tcp any any -> any any 21 (content:"user root";) 18617\end{verbatim} 18618 18619While it may \emph{seem} trivial to write a rule that looks for the username 18620root, a good rule will handle all of the odd things that the protocol might 18621handle when accepting the user command. 18622 18623For example, each of the following are accepted by most FTP servers: 18624 18625\begin{verbatim} 18626 user root 18627 user root 18628 user root 18629 user root 18630 user<tab>root 18631\end{verbatim} 18632 18633To handle all of the cases that the FTP server might handle, the rule needs 18634more smarts than a simple string match. 18635 18636A good rule that looks for root login on ftp would be: 18637 18638\begin{verbatim} 18639 alert tcp any any -> any 21 (flow:to_server,established; \ 18640 content:"root"; pcre:"/user\s+root/i";) 18641\end{verbatim} 18642 18643There are a few important things to note in this rule: 18644 18645\begin{itemize} 18646 18647\item The rule has a \emph{flow} option, verifying this is traffic going to the 18648server on an established session. 18649 18650\item The rule has a \emph{content} option, looking for \emph{root}, which is 18651the longest, most unique string in the attack. This option is added to allow 18652the fast pattern matcher to select this rule for evaluation only if the 18653content \emph{root} is found in the payload. 18654 18655\item The rule has a \emph{pcre} option, looking for user, followed at least 18656one space character (which includes tab), followed by root, ignoring case. 18657 18658\end{itemize} 18659 18660% optimizing :) 18661\subsection{Optimizing Rules} 18662 18663The content matching portion of the detection engine has recursion to handle a 18664few evasion cases. Rules that are not properly written can cause Snort to 18665waste time duplicating checks. 18666 18667The way the recursion works now is if a pattern matches, and if any of the 18668detection options after that pattern fail, then look for the pattern again 18669after where it was found the previous time. Repeat until the pattern is not 18670found again or the opt functions all succeed. 18671 18672On first read, that may not sound like a smart idea, but it is needed. For 18673example, take the following rule: 18674 18675\begin{verbatim} 18676 alert ip any any -> any any (content:"a"; content:"b"; within:1;) 18677\end{verbatim} 18678 18679This rule would look for ``a'', immediately followed by ``b''. Without 18680recursion, the payload ``aab'' would fail, even though it is obvious that the 18681payload ``aab'' has ``a'' immediately followed by ``b'', because the first "a" 18682is not immediately followed by ``b''. 18683 18684While recursion is important for detection, the recursion implementation is not 18685very smart. 18686 18687For example, the following rule options are not optimized: 18688 18689\begin{verbatim} 18690 content:"|13|"; dsize:1; 18691\end{verbatim} 18692 18693By looking at this rule snippet, it is obvious the rule looks for a packet with 18694a single byte of 0x13. However, because of recursion, a packet with 1024 bytes 18695of 0x13 could cause 1023 too many pattern match attempts and 1023 too many 18696dsize checks. Why? The content 0x13 would be found in the first byte, then 18697the dsize option would fail, and because of recursion, the content 0x13 would 18698be found again starting after where the previous 0x13 was found, once it is 18699found, then check the dsize again, repeating until 0x13 is not found in the 18700payload again. 18701 18702Reordering the rule options so that discrete checks (such as dsize) are moved 18703to the beginning of the rule speed up Snort. 18704 18705The optimized rule snipping would be: 18706\begin{verbatim} 18707 dsize:1; content:"|13|"; 18708\end{verbatim} 18709 18710A packet of 1024 bytes of 0x13 would fail immediately, as the dsize check is 18711the first option checked and dsize is a discrete check without recursion. 18712 18713The following rule options are discrete and should generally be placed at the 18714beginning of any rule: 18715 18716\begin{itemize} 18717\item \texttt{dsize} 18718\item \texttt{flags} 18719\item \texttt{flow} 18720\item \texttt{fragbits} 18721\item \texttt{icmp\_id} 18722\item \texttt{icmp\_seq} 18723\item \texttt{icode} 18724\item \texttt{id} 18725\item \texttt{ipopts} 18726\item \texttt{ip\_proto} 18727\item \texttt{itype} 18728\item \texttt{seq} 18729\item \texttt{session} 18730\item \texttt{tos} 18731\item \texttt{ttl} 18732\item \texttt{ack} 18733\item \texttt{window} 18734\item \texttt{resp} 18735\item \texttt{sameip} 18736\end{itemize} 18737 18738\subsection{Testing Numerical Values} 18739\label{testing numerical values} 18740 18741The rule options \emph{byte\_test} and \emph{byte\_jump} were written to 18742support writing rules for protocols that have length encoded data. RPC was the 18743protocol that spawned the requirement for these two rule options, as RPC uses 18744simple length based encoding for passing data. 18745 18746In order to understand \emph{why} byte\_test and byte\_jump are useful, let's 18747go through an exploit attempt against the sadmind service. 18748 18749This is the payload of the exploit: 18750 18751\begin{verbatim} 1875289 09 9c e2 00 00 00 00 00 00 00 02 00 01 87 88 ................ 1875300 00 00 0a 00 00 00 01 00 00 00 01 00 00 00 20 ............... 1875440 28 3a 10 00 00 00 0a 4d 45 54 41 53 50 4c 4f @(:.....metasplo 1875549 54 00 00 00 00 00 00 00 00 00 00 00 00 00 00 it.............. 1875600 00 00 00 00 00 00 00 40 28 3a 14 00 07 45 df ........@(:...e. 1875700 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 1875800 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 ................ 1875900 00 00 00 00 00 00 04 00 00 00 00 00 00 00 04 ................ 187607f 00 00 01 00 01 87 88 00 00 00 0a 00 00 00 04 ................ 187617f 00 00 01 00 01 87 88 00 00 00 0a 00 00 00 11 ................ 1876200 00 00 1e 00 00 00 00 00 00 00 00 00 00 00 00 ................ 1876300 00 00 00 00 00 00 3b 4d 45 54 41 53 50 4c 4f .......;metasplo 1876449 54 00 00 00 00 00 00 00 00 00 00 00 00 00 00 it.............. 1876500 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 1876600 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 1876700 00 00 00 00 00 00 06 73 79 73 74 65 6d 00 00 ........system.. 1876800 00 00 15 2e 2e 2f 2e 2e 2f 2e 2e 2f 2e 2e 2f ....../../../../ 187692e 2e 2f 62 69 6e 2f 73 68 00 00 00 00 00 04 1e ../bin/sh....... 18770<snip> 18771\end{verbatim} 18772 18773Let's break this up, describe each of the fields, and figure out how to write a 18774rule to catch this exploit. 18775 18776There are a few things to note with RPC: 18777 18778\begin{itemize} 18779 18780\item Numbers are written as uint32s, taking four bytes. The number 26 would 18781show up as 0x0000001a. 18782 18783\item Strings are written as a uint32 specifying the length of the string, the 18784string, and then null bytes to pad the length of the string to end on a 4 byte 18785boundary. The string ``bob'' would show up as 0x00000003626f6200. 18786 18787\end{itemize} 18788 18789\begin{verbatim} 1879089 09 9c e2 - the request id, a random uint32, unique to each request 1879100 00 00 00 - rpc type (call = 0, response = 1) 1879200 00 00 02 - rpc version (2) 1879300 01 87 88 - rpc program (0x00018788 = 100232 = sadmind) 1879400 00 00 0a - rpc program version (0x0000000a = 10) 1879500 00 00 01 - rpc procedure (0x00000001 = 1) 1879600 00 00 01 - credential flavor (1 = auth\_unix) 1879700 00 00 20 - length of auth\_unix data (0x20 = 32 18798 18799## the next 32 bytes are the auth\_unix data 1880040 28 3a 10 - unix timestamp (0x40283a10 = 1076378128 = feb 10 01:55:28 2004 gmt) 1880100 00 00 0a - length of the client machine name (0x0a = 10) 188024d 45 54 41 53 50 4c 4f 49 54 00 00 - metasploit 18803 1880400 00 00 00 - uid of requesting user (0) 1880500 00 00 00 - gid of requesting user (0) 1880600 00 00 00 - extra group ids (0) 18807 1880800 00 00 00 - verifier flavor (0 = auth\_null, aka none) 1880900 00 00 00 - length of verifier (0, aka none) 18810\end{verbatim} 18811 18812The rest of the packet is the request that gets passed to procedure 1 of 18813sadmind. 18814 18815However, we know the vulnerability is that sadmind trusts the uid coming from 18816the client. sadmind runs any request where the client's uid is 0 as root. As 18817such, we have decoded enough of the request to write our rule. 18818 18819First, we need to make sure that our packet is an RPC call. 18820 18821\begin{verbatim} 18822 content:"|00 00 00 00|"; offset:4; depth:4; 18823\end{verbatim} 18824 18825Then, we need to make sure that our packet is a call to sadmind. 18826 18827\begin{verbatim} 18828 content:"|00 01 87 88|"; offset:12; depth:4; 18829\end{verbatim} 18830 18831Then, we need to make sure that our packet is a call to the procedure 1, the 18832vulnerable procedure. 18833 18834\begin{verbatim} 18835 content:"|00 00 00 01|"; offset:20; depth:4; 18836\end{verbatim} 18837 18838Then, we need to make sure that our packet has auth\_unix credentials. 18839 18840\begin{verbatim} 18841 content:"|00 00 00 01|"; offset:24; depth:4; 18842\end{verbatim} 18843 18844We don't care about the hostname, but we want to skip over it and check a 18845number value after the hostname. This is where byte\_test is useful. Starting 18846at the length of the hostname, the data we have is: 18847 18848\begin{verbatim} 1884900 00 00 0a 4d 45 54 41 53 50 4c 4f 49 54 00 00 1885000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1885100 00 00 00 18852\end{verbatim} 18853 18854We want to read 4 bytes, turn it into a number, and jump that many bytes 18855forward, making sure to account for the padding that RPC requires on strings. 18856If we do that, we are now at: 18857 18858\begin{verbatim} 1885900 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1886000 00 00 00 18861\end{verbatim} 18862 18863which happens to be the exact location of the uid, the value we want to check. 18864 18865In English, we want to read 4 bytes, 36 bytes from the beginning of the packet, 18866and turn those 4 bytes into an integer and jump that many bytes forward, 18867aligning on the 4 byte boundary. To do that in a Snort rule, we use: 18868 18869\begin{verbatim} 18870 byte_jump:4,36,align; 18871\end{verbatim} 18872 18873then we want to look for the uid of 0. 18874 18875\begin{verbatim} 18876 content:"|00 00 00 00|"; within:4; 18877\end{verbatim} 18878 18879Now that we have all the detection capabilities for our rule, let's put them 18880all together. 18881 18882\begin{verbatim} 18883 content:"|00 00 00 00|"; offset:4; depth:4; 18884 content:"|00 01 87 88|"; offset:12; depth:4; 18885 content:"|00 00 00 01|"; offset:20; depth:4; 18886 content:"|00 00 00 01|"; offset:24; depth:4; 18887 byte_jump:4,36,align; 18888 content:"|00 00 00 00|"; within:4; 18889\end{verbatim} 18890 18891The 3rd and fourth string match are right next to each other, so we should 18892combine those patterns. We end up with: 18893 18894\begin{verbatim} 18895 content:"|00 00 00 00|"; offset:4; depth:4; 18896 content:"|00 01 87 88|"; offset:12; depth:4; 18897 content:"|00 00 00 01 00 00 00 01|"; offset:20; depth:8; 18898 byte_jump:4,36,align; 18899 content:"|00 00 00 00|"; within:4; 18900\end{verbatim} 18901 18902If the sadmind service was vulnerable to a buffer overflow when reading the 18903client's hostname, instead of reading the length of the hostname and jumping 18904that many bytes forward, we would check the length of the hostname to make sure 18905it is not too large. 18906 18907To do that, we would read 4 bytes, starting 36 bytes into the packet, turn it 18908into a number, and then make sure it is not too large (let's say bigger than 18909200 bytes). In Snort, we do: 18910 18911\begin{verbatim} 18912 byte_test:4,>,200,36; 18913\end{verbatim} 18914 18915Our full rule would be: 18916 18917\begin{verbatim} 18918 content:"|00 00 00 00|"; offset:4; depth:4; 18919 content:"|00 01 87 88|"; offset:12; depth:4; 18920 content:"|00 00 00 01 00 00 00 01|"; offset:20; depth:8; 18921 byte_test:4,>,200,36; 18922\end{verbatim} 18923 18924\chapter{Dynamic Modules}\label{Dynamic Modules} 18925 18926Preprocessors, detection capabilities, and rules can now be developed as 18927dynamically loadable modules to snort. The dynamic API presents a means for 18928loading dynamic libraries and allowing the module to utilize certain functions 18929within the main snort code. 18930 18931The remainder of this chapter will highlight the data structures and API 18932functions used in developing preprocessors, detection engines, and rules as a 18933dynamic plugin to snort. 18934 18935Beware: the definitions herein may be out of date; check the appropriate 18936header files for the current definitions. 18937 18938\section{Data Structures} 18939 18940A number of data structures are central to the API. The definition of each is 18941defined in the following sections. 18942 18943\subsection{DynamicPluginMeta} 18944 18945The {\em DynamicPluginMeta} structure defines the type of dynamic module 18946(preprocessor, rules, or detection engine), the version information, and path 18947to the shared library. A shared library can implement all three types, but 18948typically is limited to a single functionality such as a preprocessor. It is 18949defined in \texttt{sf\_dynamic\_meta.h} as: 18950 18951\begin{verbatim} 18952#define MAX_NAME_LEN 1024 18953 18954#define TYPE_ENGINE 0x01 18955#define TYPE_DETECTION 0x02 18956#define TYPE_PREPROCESSOR 0x04 18957 18958typedef struct _DynamicPluginMeta 18959{ 18960 int type; 18961 int major; 18962 int minor; 18963 int build; 18964 char uniqueName[MAX_NAME_LEN]; 18965 char *libraryPath; 18966} DynamicPluginMeta; 18967\end{verbatim} 18968 18969\subsection{DynamicPreprocessorData} 18970 18971The {\em DynamicPreprocessorData} structure defines the interface the 18972preprocessor uses to interact with snort itself. This includes functions to 18973register the preprocessor's configuration parsing, restart, exit, and 18974processing functions. It includes function to log messages, errors, fatal 18975errors, and debugging info. It also includes information for setting alerts, 18976handling Inline drops, access to the StreamAPI, and it provides access to the 18977normalized http and alternate data buffers. This data structure should be 18978initialized when the preprocessor shared library is loaded. It is defined in 18979\texttt{sf\_dynamic\_preprocessor.h}. Check the header file for the current 18980definition. 18981 18982\subsection{DynamicEngineData} 18983 18984The {\em DynamicEngineData} structure defines the interface a detection engine 18985uses to interact with snort itself. This includes functions for logging 18986messages, errors, fatal errors, and debugging info as well as a means to 18987register and check flowbits. It also includes a location to store rule-stubs 18988for dynamic rules that are loaded, and it provides access to the normalized 18989http and alternate data buffers. It is defined in 18990\texttt{sf\_dynamic\_engine.h} as: 18991 18992\begin{verbatim} 18993typedef struct _DynamicEngineData 18994{ 18995 int version; 18996 u_int8_t *altBuffer; 18997 UriInfo *uriBuffers[MAX_URIINFOS]; 18998 RegisterRule ruleRegister; 18999 RegisterBit flowbitRegister; 19000 CheckFlowbit flowbitCheck; 19001 DetectAsn1 asn1Detect; 19002 LogMsgFunc logMsg; 19003 LogMsgFunc errMsg; 19004 LogMsgFunc fatalMsg; 19005 char *dataDumpDirectory; 19006 19007 GetPreprocRuleOptFuncs getPreprocOptFuncs; 19008 19009 SetRuleData setRuleData; 19010 GetRuleData getRuleData; 19011 19012 DebugMsgFunc debugMsg; 19013#ifdef HAVE_WCHAR_H 19014 DebugWideMsgFunc debugWideMsg; 19015#endif 19016 19017 char **debugMsgFile; 19018 int *debugMsgLine; 19019 19020 PCRECompileFunc pcreCompile; 19021 PCREStudyFunc pcreStudy; 19022 PCREExecFunc pcreExec; 19023 19024} DynamicEngineData; 19025\end{verbatim} 19026 19027\subsection{SFSnortPacket} 19028 19029The {\em SFSnortPacket} structure mirrors the snort Packet structure and 19030provides access to all of the data contained in a given packet. 19031 19032It and the data structures it incorporates are defined in 19033\texttt{sf\_snort\_packet.h}. Additional data structures may be defined to 19034reference other protocol fields. Check the header file for the current 19035definitions. 19036 19037\subsection{Dynamic Rules} 19038 19039A dynamic rule should use any of the following data structures. The following 19040structures are defined in \texttt{sf\_snort\_plugin\_api.h}. 19041 19042\subsubsection{Rule} 19043 19044The {\em Rule} structure defines the basic outline of a rule and contains the 19045same set of information that is seen in a text rule. That includes protocol, 19046address and port information and rule information (classification, generator 19047and signature IDs, revision, priority, classification, and a list of 19048references). It also includes a list of rule options and an optional 19049evaluation function. 19050 19051\begin{verbatim} 19052#define RULE_MATCH 1 19053#define RULE_NOMATCH 0 19054 19055typedef struct _Rule 19056{ 19057 IPInfo ip; 19058 RuleInformation info; 19059 19060 RuleOption **options; /* NULL terminated array of RuleOption union */ 19061 19062 ruleEvalFunc evalFunc; 19063 19064 char initialized; /* Rule Initialized, used internally */ 19065 u_int32_t numOptions; /* Rule option count, used internally */ 19066 char noAlert; /* Flag with no alert, used internally */ 19067 void *ruleData; /* Hash table for dynamic data pointers */ 19068} Rule; 19069\end{verbatim} 19070 19071The rule evaluation function is defined as 19072 19073\begin{verbatim} 19074typedef int (*ruleEvalFunc)(void *); 19075\end{verbatim} 19076 19077where the parameter is a pointer to the SFSnortPacket structure. 19078 19079\subsubsection{RuleInformation} 19080 19081The {\em RuleInformation} structure defines the meta data for a rule and 19082includes generator ID, signature ID, revision, classification, priority, 19083message text, and a list of references. 19084 19085\begin{verbatim} 19086typedef struct _RuleInformation 19087{ 19088 u_int32_t genID; 19089 u_int32_t sigID; 19090 u_int32_t revision; 19091 char *classification; /* String format of classification name */ 19092 u_int32_t priority; 19093 char *message; 19094 RuleReference **references; /* NULL terminated array of references */ 19095 RuleMetaData **meta; /* NULL terminated array of references */ 19096} RuleInformation; 19097\end{verbatim} 19098 19099\subsubsection{RuleReference} 19100 19101The {\em RuleReference} structure defines a single rule reference, including 19102the system name and rereference identifier. 19103 19104\begin{verbatim} 19105typedef struct _RuleReference 19106{ 19107 char *systemName; 19108 char *refIdentifier; 19109} RuleReference; 19110\end{verbatim} 19111 19112\subsubsection{IPInfo} 19113 19114The {\em IPInfo} structure defines the initial matching criteria for a rule and 19115includes the protocol, src address and port, destination address and port, and 19116direction. Some of the standard strings and variables are predefined - any, 19117HOME\_NET, HTTP\_SERVERS, HTTP\_PORTS, etc. 19118 19119\begin{verbatim} 19120typedef struct _IPInfo 19121{ 19122 u_int8_t protocol; 19123 char * src_addr; 19124 char * src_port; /* 0 for non TCP/UDP */ 19125 char direction; /* non-zero is bi-directional */ 19126 char * dst_addr; 19127 char * dst_port; /* 0 for non TCP/UDP */ 19128} IPInfo; 19129 19130#define ANY_NET "any" 19131#define HOME_NET "$HOME_NET" 19132#define EXTERNAL_NET "$EXTERNAL_NET" 19133#define ANY_PORT "any" 19134#define HTTP_SERVERS "$HTTP_SERVERS" 19135#define HTTP_PORTS "$HTTP_PORTS" 19136#define SMTP_SERVERS "$SMTP_SERVERS" 19137\end{verbatim} 19138 19139\subsubsection{RuleOption} 19140 19141The {\em RuleOption} structure defines a single rule option as an option type 19142and a reference to the data specific to that option. Each option has a flags 19143field that contains specific flags for that option as well as a "Not" flag. 19144The "Not" flag is used to negate the results of evaluating that option. 19145 19146\begin{verbatim} 19147typedef enum DynamicOptionType { 19148 OPTION_TYPE_PREPROCESSOR, 19149 OPTION_TYPE_CONTENT, 19150 OPTION_TYPE_PCRE, 19151 OPTION_TYPE_FLOWBIT, 19152 OPTION_TYPE_FLOWFLAGS, 19153 OPTION_TYPE_ASN1, 19154 OPTION_TYPE_CURSOR, 19155 OPTION_TYPE_HDR_CHECK, 19156 OPTION_TYPE_BYTE_TEST, 19157 OPTION_TYPE_BYTE_JUMP, 19158 OPTION_TYPE_BYTE_EXTRACT, 19159 OPTION_TYPE_SET_CURSOR, 19160 OPTION_TYPE_LOOP, 19161 OPTION_TYPE_MAX 19162}; 19163 19164typedef struct _RuleOption 19165{ 19166 int optionType; 19167 union 19168 { 19169 void *ptr; 19170 ContentInfo *content; 19171 CursorInfo *cursor; 19172 PCREInfo *pcre; 19173 FlowBitsInfo *flowBit; 19174 ByteData *byte; 19175 ByteExtract *byteExtract; 19176 FlowFlags *flowFlags; 19177 Asn1Context *asn1; 19178 HdrOptCheck *hdrData; 19179 LoopInfo *loop; 19180 PreprocessorOption *preprocOpt; 19181 } option_u; 19182} RuleOption; 19183 19184#define NOT_FLAG 0x10000000 19185\end{verbatim} 19186 19187Some options also contain information that is initialized at run time, such as 19188the compiled PCRE information, Boyer-Moore content information, the integer ID 19189for a flowbit, etc. 19190 19191The option types and related structures are listed below. 19192 19193\begin{itemize} 19194%\item {OptionType: Preprocessor defined \& Structure: {\em PreprocessorOption}} 19195% 19196%The {\em PreprocessorOption} structure defines an option for a 19197%preprocessor defined option. 19198% 19199%\begin{verbatim} 19200%typedef struct _PreprocessorOption 19201%{ 19202% char *optionName; 19203% char *optionParameters; 19204% u_int32_t flags; 19205% void *optionInit; 19206% void *optionEval; 19207% void *dataPtr; 19208%} PreprocessorOption; 19209%\end{verbatim} 19210 19211\item {OptionType: Content \& Structure: {\em ContentInfo}} 19212 19213The {\em ContentInfo} structure defines an option for a content search. It 19214includes the pattern, depth and offset, and flags (one of which must specify 19215the buffer -- raw, URI or normalized -- to search). Additional flags include 19216nocase, relative, unicode, and a designation that this content is to be used 19217for snorts fast pattern evaluation. The most unique content, that which 19218distinguishes this rule as a possible match to a packet, should be marked for 19219fast pattern evaluation. In the dynamic detection engine provided with Snort, 19220if no {\em ContentInfo} structure in a given rules uses that flag, the one with 19221the longest content length will be used. 19222 19223\begin{verbatim} 19224typedef struct _ContentInfo 19225{ 19226 u_int8_t *pattern; 19227 u_int32_t depth; 19228 int32_t offset; 19229 u_int32_t flags; /* must include a CONTENT_BUF_X */ 19230 void *boyer_ptr; 19231 u_int8_t *patternByteForm; 19232 u_int32_t patternByteFormLength; 19233 u_int32_t incrementLength; 19234} ContentInfo; 19235 19236#define CONTENT_NOCASE 0x01 19237#define CONTENT_RELATIVE 0x02 19238#define CONTENT_UNICODE2BYTE 0x04 19239#define CONTENT_UNICODE4BYTE 0x08 19240#define CONTENT_FAST_PATTERN 0x10 19241#define CONTENT_END_BUFFER 0x20 19242 19243#define CONTENT_BUF_NORMALIZED 0x100 19244#define CONTENT_BUF_RAW 0x200 19245#define CONTENT_BUF_URI 0x400 19246\end{verbatim} 19247 19248\item {OptionType: PCRE \& Structure: {\em PCREInfo}} 19249 19250The {\em PCREInfo} structure defines an option for a PCRE search. It includes 19251the PCRE expression, pcre\_flags such as caseless, as defined in PCRE.h, and 19252flags to specify the buffer. 19253 19254\begin{verbatim} 19255/* 19256pcre.h provides flags: 19257 19258PCRE_CASELESS 19259PCRE_MULTILINE 19260PCRE_DOTALL 19261PCRE_EXTENDED 19262PCRE_ANCHORED 19263PCRE_DOLLAR_ENDONLY 19264PCRE_UNGREEDY 19265*/ 19266 19267typedef struct _PCREInfo 19268{ 19269 char *expr; 19270 void *compiled_expr; 19271 void *compiled_extra; 19272 u_int32_t compile_flags; 19273 u_int32_t flags; /* must include a CONTENT_BUF_X */ 19274} PCREInfo; 19275\end{verbatim} 19276 19277\item {OptionType: Flowbit \& Structure: {\em FlowBitsInfo}} 19278 19279The {\em FlowBitsInfo} structure defines a flowbits option. It includes the 19280name of the flowbit and the operation (set, setx, unset, toggle, isset, isnotset). 19281 19282\begin{verbatim} 19283#define FLOWBIT_SET 0x01 19284#define FLOWBIT_UNSET 0x02 19285#define FLOWBIT_TOGGLE 0x04 19286#define FLOWBIT_ISSET 0x08 19287#define FLOWBIT_ISNOTSET 0x10 19288#define FLOWBIT_RESET 0x20 19289#define FLOWBIT_NOALERT 0x40 19290#define FLOWBIT_SETX 0x80 19291 19292typedef struct _FlowBitsInfo 19293{ 19294 char *flowBitsName; 19295 uint8_t operation; 19296 uint16_t id; 19297 uint32_t flags; 19298 char *groupName; 19299 uint8_t eval; 19300 uint16_t *ids; 19301 uint8_t num_ids; 19302 19303} FlowBitsInfo; 19304\end{verbatim} 19305 19306\item {OptionType: Flow Flags \& Structure: {\em FlowFlags}} 19307 19308The {\em FlowFlags} structure defines a flow option. It includes the flags, 19309which specify the direction (from\_server, to\_server), established session, 19310etc. 19311 19312\begin{verbatim} 19313#define FLOW_ESTABLISHED 0x10 19314#define FLOW_IGNORE_REASSEMBLED 0x1000 19315#define FLOW_ONLY_REASSMBLED 0x2000 19316#define FLOW_FR_SERVER 0x40 19317#define FLOW_TO_CLIENT 0x40 /* Just for redundancy */ 19318#define FLOW_TO_SERVER 0x80 19319#define FLOW_FR_CLIENT 0x80 /* Just for redundancy */ 19320 19321typedef struct _FlowFlags 19322{ 19323 u_int32_t flags; 19324} FlowFlags; 19325\end{verbatim} 19326 19327\item {OptionType: ASN.1 \& Structure: {\em Asn1Context}} 19328 19329The {\em Asn1Context} structure defines the information for an ASN1 option. It 19330mirrors the ASN1 rule option and also includes a flags field. 19331 19332\begin{verbatim} 19333#define ASN1_ABS_OFFSET 1 19334#define ASN1_REL_OFFSET 2 19335 19336typedef struct _Asn1Context 19337{ 19338 int bs_overflow; 19339 int double_overflow; 19340 int print; 19341 int length; 19342 unsigned int max_length; 19343 int offset; 19344 int offset_type; 19345 u_int32_t flags; 19346} Asn1Context; 19347\end{verbatim} 19348 19349\item {OptionType: Cursor Check \& Structure: {\em CursorInfo}} 19350 19351The {\em CursorInfo} structure defines an option for a cursor evaluation. The 19352cursor is the current position within the evaluation buffer, as related to 19353content and PCRE searches, as well as byte tests and byte jumps. It includes 19354an offset and flags that specify the buffer. This can be used to verify there 19355is sufficient data to continue evaluation, similar to the isdataat rule option. 19356 19357\begin{verbatim} 19358typedef struct _CursorInfo 19359{ 19360 int32_t offset; 19361 u_int32_t flags; /* specify one of CONTENT_BUF_X */ 19362} CursorInfo; 19363\end{verbatim} 19364 19365\item {OptionType: Protocol Header \& Structure: {\em HdrOptCheck}} 19366 19367The {\em HdrOptCheck} structure defines an option to check a protocol header 19368for a specific value. It includes the header field, the operation ($<$,$>$,=,etc), 19369a value, a mask to ignore that part of the header field, and flags. 19370 19371\begin{verbatim} 19372#define IP_HDR_ID 0x0001 /* IP Header ID */ 19373#define IP_HDR_PROTO 0x0002 /* IP Protocol */ 19374#define IP_HDR_FRAGBITS 0x0003 /* Frag Flags set in IP Header */ 19375#define IP_HDR_FRAGOFFSET 0x0004 /* Frag Offset set in IP Header */ 19376#define IP_HDR_OPTIONS 0x0005 /* IP Options -- is option xx included */ 19377#define IP_HDR_TTL 0x0006 /* IP Time to live */ 19378#define IP_HDR_TOS 0x0007 /* IP Type of Service */ 19379#define IP_HDR_OPTCHECK_MASK 0x000f 19380 19381#define TCP_HDR_ACK 0x0010 /* TCP Ack Value */ 19382#define TCP_HDR_SEQ 0x0020 /* TCP Seq Value */ 19383#define TCP_HDR_FLAGS 0x0030 /* Flags set in TCP Header */ 19384#define TCP_HDR_OPTIONS 0x0040 /* TCP Options -- is option xx included */ 19385#define TCP_HDR_WIN 0x0050 /* TCP Window */ 19386#define TCP_HDR_OPTCHECK_MASK 0x00f0 19387 19388#define ICMP_HDR_CODE 0x1000 /* ICMP Header Code */ 19389#define ICMP_HDR_TYPE 0x2000 /* ICMP Header Type */ 19390#define ICMP_HDR_ID 0x3000 /* ICMP ID for ICMP_ECHO/ICMP_ECHO_REPLY */ 19391#define ICMP_HDR_SEQ 0x4000 /* ICMP ID for ICMP_ECHO/ICMP_ECHO_REPLY */ 19392#define ICMP_HDR_OPTCHECK_MASK 0xf000 19393 19394typedef struct _HdrOptCheck 19395{ 19396 u_int16_t hdrField; /* Field to check */ 19397 u_int32_t op; /* Type of comparison */ 19398 u_int32_t value; /* Value to compare value against */ 19399 u_int32_t mask_value; /* bits of value to ignore */ 19400 u_int32_t flags; 19401} HdrOptCheck; 19402\end{verbatim} 19403 19404\item {OptionType: Byte Test \& Structure: {\em ByteData}} 19405 19406The {\em ByteData} structure defines the information for both ByteTest and 19407ByteJump operations. It includes the number of bytes, an operation (for 19408ByteTest, $<$,$>$,=,etc), a value, an offset, multiplier, and flags. The flags 19409must specify the buffer. 19410 19411\begin{verbatim} 19412#define CHECK_EQ 0 19413#define CHECK_NEQ 1 19414#define CHECK_LT 2 19415#define CHECK_GT 3 19416#define CHECK_LTE 4 19417#define CHECK_GTE 5 19418#define CHECK_AND 6 19419#define CHECK_XOR 7 19420#define CHECK_ALL 8 19421#define CHECK_ATLEASTONE 9 19422#define CHECK_NONE 10 19423 19424typedef struct _ByteData 19425{ 19426 u_int32_t bytes; /* Number of bytes to extract */ 19427 u_int32_t op; /* Type of byte comparison, for checkValue */ 19428 u_int32_t value; /* Value to compare value against, for checkValue, or extracted value */ 19429 int32_t offset; /* Offset from cursor */ 19430 u_int32_t multiplier; /* Used for byte jump -- 32bits is MORE than enough */ 19431 u_int32_t flags; /* must include a CONTENT_BUF_X */ 19432} ByteData; 19433\end{verbatim} 19434 19435\item {OptionType: Byte Jump \& Structure: {\em ByteData}} 19436 19437See {\em Byte Test} above. 19438 19439\item {OptionType: Set Cursor \& Structure: {\em CursorInfo}} 19440 19441See {\em Cursor Check} above. 19442 19443\item {OptionType: Loop \& Structures: {\em LoopInfo,ByteExtract,DynamicElement}} 19444 19445The {\em LoopInfo} structure defines the information for a set of options that 19446are to be evaluated repeatedly. The loop option acts like a FOR loop and 19447includes start, end, and increment values as well as the comparison operation 19448for termination. It includes a cursor adjust that happens through each 19449iteration of the loop, a reference to a RuleInfo structure that defines the 19450RuleOptions are to be evaluated through each iteration. One of those options 19451may be a ByteExtract. 19452 19453\begin{verbatim} 19454typedef struct _LoopInfo 19455{ 19456 DynamicElement *start; /* Starting value of FOR loop (i=start) */ 19457 DynamicElement *end; /* Ending value of FOR loop (i OP end) */ 19458 DynamicElement *increment; /* Increment value of FOR loop (i+= increment) */ 19459 u_int32_t op; /* Type of comparison for loop termination */ 19460 CursorInfo *cursorAdjust; /* How to move cursor each iteration of loop */ 19461 struct _Rule *subRule; /* Pointer to SubRule & options to evaluate within 19462 * the loop */ 19463 u_int8_t initialized; /* Loop initialized properly (safeguard) */ 19464 u_int32_t flags; /* can be used to negate loop results, specifies * relative. */ 19465} LoopInfo; 19466\end{verbatim} 19467 19468The {\em ByteExtract} structure defines the information to use when extracting 19469bytes for a DynamicElement used a in Loop evaluation. It includes the number of 19470bytes, an offset, multiplier, flags specifying the buffer, and a reference to 19471the DynamicElement. 19472 19473\begin{verbatim} 19474typedef struct _ByteExtract 19475{ 19476 u_int32_t bytes; /* Number of bytes to extract */ 19477 int32_t offset; /* Offset from cursor */ 19478 u_int32_t multiplier; /* Multiply value by this (similar to byte jump) */ 19479 u_int32_t flags; /* must include a CONTENT_BUF_X */ 19480 char *refId; /* To match up with a DynamicElement refId */ 19481 void *memoryLocation; /* Location to store the data extracted */ 19482} ByteExtract; 19483\end{verbatim} 19484 19485The {\em DynamicElement} structure is used to define the values for a looping 19486evaluation. It includes whether the element is static (an integer) or dynamic 19487(extracted from a buffer in the packet) and the value. For a dynamic element, 19488the value is filled by a related ByteExtract option that is part of the loop. 19489 19490\begin{verbatim} 19491#define DYNAMIC_TYPE_INT_STATIC 1 19492#define DYNAMIC_TYPE_INT_REF 2 19493 19494typedef struct _DynamicElement 19495{ 19496 char dynamicType; /* type of this field - static or reference */ 19497 char *refId; /* reference ID (NULL if static) */ 19498 union 19499 { 19500 void *voidPtr; /* Holder */ 19501 int32_t staticInt; /* Value of static */ 19502 int32_t *dynamicInt; /* Pointer to value of dynamic */ 19503 } data; 19504} DynamicElement; 19505\end{verbatim} 19506 19507\end{itemize} 19508 19509\section{Required Functions} 19510 19511Each dynamic module must define a set of functions and data objects to work 19512within this framework. 19513 19514\subsection{Preprocessors} 19515 19516Each dynamic preprocessor must define the following items. These must be defined 19517in the global scope of a source file (e.g. spp\_example.c). 19518 19519\begin{itemize} 19520\item {\em const int MAJOR\_VERSION} 19521 19522This specifies the major version of the preprocessor. 19523 19524\item {\em const int MINOR\_VERSION} 19525 19526This specifies the minor version of the preprocessor. 19527 19528\item {\em const int BUILD\_VERSION} 19529 19530This specifies the build version of the preprocessor. 19531 19532\item {\em const char *PREPROC\_NAME} 19533 19534This specifies the display name of the preprocessor. 19535 19536\item {\em void DYNAMIC\_PREPROC\_SETUP(void)} 19537 19538This function is called to register the preprocessor to be called with packets data. 19539 19540\end{itemize} 19541 19542The preprocessor must be built with the same macros defined as the Snort binary and 19543linked with the dynamic preprocessor library that was created during the Snort build. 19544A package configuration file is exported as part of the Snort build and can be accessed 19545using the following commands with PKG\_CONFIG\_PATH=$<$snort build prefix/lib/pkgconfig$>$: 19546 19547\begin{itemize} 19548\item {\em pkg-config --cflags snort\_preproc} 19549 19550Returns the macros and include path needed to compile the dynamic preprocessor. 19551 19552\item {\em pkg-config --libs snort\_preproc} 19553 19554Returns the library and library path needed to link the dynamic preprocessor. 19555 19556\end{itemize} 19557 19558\subsection{Detection Engine} 19559 19560Each dynamic detection engine library must define the following functions. 19561 19562\begin{itemize} 19563\item {\em int LibVersion(DynamicPluginMeta *)} 19564 19565This function returns the metadata for the shared library. 19566 19567\item {\em int InitializeEngineLib(DynamicEngineData *)} 19568 19569This function initializes the data structure for use by the engine. 19570 19571\end{itemize} 19572 19573The sample code provided with Snort predefines those functions and defines the 19574following APIs to be used by a dynamic rules library. 19575 19576\begin{itemize} 19577\item {\em int RegisterRules(Rule **)} 19578 19579This is the function to iterate through each rule in the list, initialize it to 19580setup content searches, PCRE evaluation data, and register flowbits. 19581 19582\item {\em int DumpRules(char *,Rule **)} 19583 19584This is the function to iterate through each rule in the list and write a 19585rule-stop to be used by snort to control the action of the rule (alert, log, 19586drop, etc). 19587 19588\item {\em int ruleMatch(void *p, Rule *rule)} 19589 19590This is the function to evaluate a rule if the rule does not have its own Rule 19591Evaluation Function. This uses the individual functions outlined below for 19592each of the rule options and handles repetitive content issues. 19593 19594Each of the functions below returns RULE\_MATCH if the option matches based on 19595the current criteria (cursor position, etc). 19596 19597\begin{itemize} 19598 19599\item {\em int contentMatch(void *p, ContentInfo* content, u\_int8\_t **cursor)} 19600 19601This function evaluates a single content for a given packet, checking for the 19602existence of that content as delimited by ContentInfo and cursor. Cursor 19603position is updated and returned in *cursor. 19604 19605With a text rule, the with option corresponds to depth, and the distance option 19606corresponds to offset. 19607 19608\item {\em int checkFlow(void *p, FlowFlags *flowflags)} 19609 19610This function evaluates the flow for a given packet. 19611 19612\item {\em int extractValue(void *p, ByteExtract *byteExtract, u\_int8\_t *cursor)} 19613 19614This function extracts the bytes from a given packet, as specified by 19615ByteExtract and delimited by cursor. Value extracted is stored in ByteExtract 19616memoryLocation parameter. 19617 19618\item {\em int processFlowbits(void *p, FlowBitsInfo *flowbits)} 19619 19620This function evaluates the flowbits for a given packet, as specified by 19621FlowBitsInfo. It will interact with flowbits used by text-based rules. 19622 19623\item {\em int setCursor(void *p, CursorInfo *cursorInfo, u\_int8\_t **cursor)} 19624 19625This function adjusts the cursor as delimited by CursorInfo. New cursor 19626position is returned in *cursor. It handles bounds checking for the specified 19627buffer and returns RULE\_NOMATCH if the cursor is moved out of bounds. 19628 19629It is also used by contentMatch, byteJump, and pcreMatch to adjust the cursor 19630position after a successful match. 19631 19632\item {\em int checkCursor(void *p, CursorInfo *cursorInfo, u\_int8\_t *cursor)} 19633 19634This function validates that the cursor is within bounds of the specified 19635buffer. 19636 19637\item {\em int checkValue(void *p, ByteData *byteData, u\_int32\_t value, u\_int8\_t *cursor)} 19638 19639This function compares the {\em value} to the value stored in ByteData. 19640 19641\item {\em int byteTest(void *p, ByteData *byteData, u\_int8\_t *cursor)} 19642 19643This is a wrapper for extractValue() followed by checkValue(). 19644 19645\item {\em int byteJump(void *p, ByteData *byteData, u\_int8\_t **cursor)} 19646 19647This is a wrapper for extractValue() followed by setCursor(). 19648 19649\item {\em int pcreMatch(void *p, PCREInfo *pcre, u\_int8\_t **cursor)} 19650 19651This function evaluates a single pcre for a given packet, checking for the 19652existence of the expression as delimited by PCREInfo and cursor. Cursor 19653position is updated and returned in *cursor. 19654 19655\item {\em int detectAsn1(void *p, Asn1Context *asn1, u\_int8\_t *cursor)} 19656 19657This function evaluates an ASN.1 check for a given packet, as delimited by 19658Asn1Context and cursor. 19659 19660\item {\em int checkHdrOpt(void *p, HdrOptCheck *optData)} 19661 19662This function evaluates the given packet's protocol headers, as specified by 19663HdrOptCheck. 19664 19665\item {\em int loopEval(void *p, LoopInfo *loop, u\_int8\_t **cursor)} 19666 19667This function iterates through the SubRule of LoopInfo, as delimited by 19668LoopInfo and cursor. Cursor position is updated and returned in *cursor. 19669 19670\item {\em int preprocOptionEval(void *p, PreprocessorOption *preprocOpt, u\_int8\_t **cursor)} 19671 19672This function evaluates the preprocessor defined option, as specified by 19673PreprocessorOption. Cursor position is updated and returned in *cursor. 19674 19675\item {\em void setTempCursor(u\_int8\_t **temp\_cursor, u\_int8\_t **cursor)} 19676 19677This function is used to handled repetitive contents to save off a cursor 19678position temporarily to be reset at later point. 19679 19680\item {\em void revertTempCursor(u\_int8\_t **temp\_cursor, u\_int8\_t **cursor)} 19681 19682This function is used to revert to a previously saved temporary cursor 19683position. 19684 19685\end{itemize} 19686 19687\begin{note} 19688 19689If you decide to write your own rule evaluation function, patterns that occur 19690more than once may result in false negatives. Take extra care to handle this 19691situation and search for the matched pattern again if subsequent rule options 19692fail to match. This should be done for both content and PCRE options. 19693 19694\end{note} 19695\end{itemize} 19696 19697\subsection{Rules} 19698 19699Each dynamic rules library must define the following functions. Examples are 19700defined in the file \texttt{sfnort\_dynamic\_detection\_lib.c}. The metadata 19701and setup function for the preprocessor should be defined in 19702\texttt{sfsnort\_dynamic\_detection\_lib.h}. 19703 19704\begin{itemize} 19705\item {\em int LibVersion(DynamicPluginMeta *)} 19706 19707This function returns the metadata for the shared library. 19708 19709\item {\em int EngineVersion(DynamicPluginMeta *)} 19710 19711This function defines the version requirements for the corresponding detection 19712engine library. 19713 19714\item {\em int DumpSkeletonRules()} 19715 19716This functions writes out the rule-stubs for rules that are loaded. 19717 19718\item {\em int InitializeDetection()} 19719 19720This function registers each rule in the rules library. It should set up fast 19721pattern-matcher content, register flowbits, etc. \end{itemize} 19722 19723The sample code provided with Snort predefines those functions and uses the 19724following data within the dynamic rules library. 19725 19726\begin{itemize} 19727 19728\item {\em Rule *rules[]} 19729 19730A NULL terminated list of Rule structures that this library defines. 19731 19732\end{itemize} 19733 19734\section{Examples} 19735 19736This section provides a simple example of a dynamic preprocessor and a dynamic 19737rule. 19738 19739\subsection{Preprocessor Example} 19740 19741The following is an example of a simple preprocessor. This preprocessor always 19742alerts on a packet if the TCP port matches the one configured. 19743 19744The following code is defined in {\em spp\_example.c} and is compiled 19745together with {\em libsf\_dynamic\_preproc.a}, using pkg-config, into 19746lib\_sfdynamic\_preprocessor\_example.so. 19747 19748Define the required meta data variables. 19749 19750\begin{verbatim} 19751#define GENERATOR_EXAMPLE 256 19752extern DynamicPreprocessorData _dpd; 19753 19754const int MAJOR_VERSION = 1; 19755const int MINOR_VERSION = 0; 19756const int BUILD_VERSION = 0; 19757const char *PREPROC_NAME = "SF_Dynamic_Example_Preprocessor"; 19758 19759#define ExampleSetup DYNAMIC_PREPROC_SETUP 19760\end{verbatim} 19761 19762Define the Setup function to register the initialization function. 19763 19764\begin{verbatim} 19765void ExampleInit(unsigned char *); 19766void ExampleProcess(void *, void *); 19767 19768void ExampleSetup() 19769{ 19770 _dpd.registerPreproc("dynamic_example", ExampleInit); 19771 19772 DEBUG_WRAP(_dpd.debugMsg(DEBUG_PLUGIN, "Preprocessor: Example is setup\n");); 19773} 19774\end{verbatim} 19775 19776The initialization function to parse the keywords from \texttt{snort.conf}. 19777 19778\begin{verbatim} 19779u_int16_t portToCheck; 19780 19781void ExampleInit(unsigned char *args) 19782{ 19783 char *arg; 19784 char *argEnd; 19785 unsigned long port; 19786 19787 _dpd.logMsg("Example dynamic preprocessor configuration\n"); 19788 19789 arg = strtok(args, " \t\n\r"); 19790 19791 if(!strcasecmp("port", arg)) 19792 { 19793 arg = strtok(NULL, "\t\n\r"); 19794 if (!arg) 19795 { 19796 _dpd.fatalMsg("ExamplePreproc: Missing port\n"); 19797 } 19798 19799 port = strtoul(arg, &argEnd, 10); 19800 if (port < 0 || port > 65535) 19801 { 19802 _dpd.fatalMsg("ExamplePreproc: Invalid port %d\n", port); 19803 } 19804 portToCheck = port; 19805 19806 _dpd.logMsg(" Port: %d\n", portToCheck); 19807 } 19808 else 19809 { 19810 _dpd.fatalMsg("ExamplePreproc: Invalid option %s\n", arg); 19811 } 19812 19813 /* Register the preprocessor function, Transport layer, ID 10000 */ 19814 _dpd.addPreproc(ExampleProcess, PRIORITY_TRANSPORT, 10000); 19815 19816 DEBUG_WRAP(_dpd.debugMsg(DEBUG_PLUGIN, "Preprocessor: Example is initialized\n");); 19817} 19818\end{verbatim} 19819 19820The function to process the packet and log an alert if the either port matches. 19821 19822\begin{verbatim} 19823#define SRC_PORT_MATCH 1 19824#define SRC_PORT_MATCH_STR "example_preprocessor: src port match" 19825#define DST_PORT_MATCH 2 19826#define DST_PORT_MATCH_STR "example_preprocessor: dest port match" 19827void ExampleProcess(void *pkt, void *context) 19828{ 19829 SFSnortPacket *p = (SFSnortPacket *)pkt; 19830 if (!p->ip4_header || p->ip4_header->proto != IPPROTO_TCP || !p->tcp_header) 19831 { 19832 /* Not for me, return */ 19833 return; 19834 } 19835 19836 if (p->src_port == portToCheck) 19837 { 19838 /* Source port matched, log alert */ 19839 _dpd.alertAdd(GENERATOR_EXAMPLE, SRC_PORT_MATCH, 19840 1, 0, 3, SRC_PORT_MATCH_STR, 0); 19841 return; 19842 } 19843 19844 if (p->dst_port == portToCheck) 19845 { 19846 /* Destination port matched, log alert */ 19847 _dpd.alertAdd(GENERATOR_EXAMPLE, DST_PORT_MATCH, 19848 1, 0, 3, DST_PORT_MATCH_STR, 0); 19849 return; 19850 } 19851} 19852\end{verbatim} 19853 19854\subsection{Rules} 19855 19856The following is an example of a simple rule, take from the current rule set, 19857SID 109. It is implemented to work with the detection engine provided with 19858snort. 19859 19860The snort rule in normal format: 19861 19862\begin{verbatim} 19863alert tcp $HOME_NET 12345:12346 -> $EXTERNAL_NET any \ 19864(msg:"BACKDOOR netbus active"; flow:from_server,established; \ 19865content:"NetBus"; reference:arachnids,401; classtype:misc-activity; \ 19866sid:109; rev:5;) 19867\end{verbatim} 19868 19869This is the metadata for this rule library, defined in {\em 19870detection\_lib\_meta.h}. 19871 19872\begin{verbatim} 19873/* Version for this rule library */ 19874#define DETECTION_LIB_MAJOR_VERSION 1 19875#define DETECTION_LIB_MINOR_VERSION 0 19876#define DETECTION_LIB_BUILD_VERSION 1 19877#define DETECTION_LIB_NAME "Snort_Dynamic_Rule_Example" 19878 19879/* Required version and name of the engine */ 19880#define REQ_ENGINE_LIB_MAJOR_VERSION 1 19881#define REQ_ENGINE_LIB_MINOR_VERSION 0 19882#define REQ_ENGINE_LIB_NAME "SF_SNORT_DETECTION_ENGINE" 19883 19884\end{verbatim} 19885 19886The definition of each data structure for this rule is in {\em sid109.c}. 19887 19888Declaration of the data structures. 19889 19890\begin{itemize} 19891 19892\item{Flow option} 19893 19894Define the {\em FlowFlags} structure and its corresponding {\em RuleOption}. 19895Per the text version, flow is from\_server,established. 19896 19897\begin{verbatim} 19898static FlowFlags sid109flow = 19899{ 19900 FLOW_ESTABLISHED|FLOW_TO_CLIENT 19901}; 19902 19903static RuleOption sid109option1 = 19904{ 19905 OPTION_TYPE_FLOWFLAGS, 19906 { 19907 &sid109flow 19908 } 19909}; 19910\end{verbatim} 19911 19912\item{Content Option} 19913 19914Define the {\em ContentInfo} structure and its corresponding {\em RuleOption}. 19915Per the text version, content is "NetBus", no depth or offset, case sensitive, 19916and non-relative. Search on the normalized buffer by default. {\bf NOTE}: 19917This content will be used for the fast pattern matcher since it is the longest 19918content option for this rule and no contents have a flag of {\em 19919CONTENT\_FAST\_PATTERN}. 19920 19921\begin{verbatim} 19922static ContentInfo sid109content = 19923{ 19924 "NetBus", /* pattern to search for */ 19925 0, /* depth */ 19926 0, /* offset */ 19927 CONTENT_BUF_NORMALIZED, /* flags */ 19928 NULL, /* holder for boyer/moore info */ 19929 NULL, /* holder for byte representation of "NetBus" */ 19930 0, /* holder for length of byte representation */ 19931 0 /* holder for increment length */ 19932}; 19933 19934static RuleOption sid109option2 = 19935{ 19936 OPTION_TYPE_CONTENT, 19937 { 19938 &sid109content 19939 } 19940}; 19941\end{verbatim} 19942 19943\item{Rule and Meta Data} 19944 19945Define the references. 19946 19947\begin{verbatim} 19948static RuleReference sid109ref_arachnids = 19949{ 19950 "arachnids", /* Type */ 19951 "401" /* value */ 19952}; 19953 19954static RuleReference *sid109refs[] = 19955{ 19956 &sid109ref_arachnids, 19957 NULL 19958}; 19959\end{verbatim} 19960 19961The list of rule options. Rule options are evaluated in the order specified. 19962 19963\begin{verbatim} 19964RuleOption *sid109options[] = 19965{ 19966 &sid109option1, 19967 &sid109option2, 19968 NULL 19969}; 19970\end{verbatim} 19971 19972The rule itself, with the protocol header, meta data (sid, classification, 19973message, etc). 19974 19975\begin{verbatim} 19976Rule sid109 = 19977{ 19978 /* protocol header, akin to => tcp any any -> any any */ 19979 { 19980 IPPROTO_TCP, /* proto */ 19981 HOME_NET, /* source IP */ 19982 "12345:12346", /* source port(s) */ 19983 0, /* Direction */ 19984 EXTERNAL_NET, /* destination IP */ 19985 ANY_PORT, /* destination port */ 19986 }, 19987 /* metadata */ 19988 { 19989 3, /* genid -- use 3 to distinguish a C rule */ 19990 109, /* sigid */ 19991 5, /* revision */ 19992 "misc-activity", /* classification */ 19993 0, /* priority */ 19994 "BACKDOOR netbus active", /* message */ 19995 sid109refs /* ptr to references */ 19996 }, 19997 sid109options, /* ptr to rule options */ 19998 NULL, /* Use internal eval func */ 19999 0, /* Holder, not yet initialized, used internally */ 20000 0, /* Holder, option count, used internally */ 20001 0, /* Holder, no alert, used internally for flowbits */ 20002 NULL /* Holder, rule data, used internally */ 20003\end{verbatim} 20004 20005\item{The List of rules defined by this rules library} 20006 20007The NULL terminated list of rules. The InitializeDetection iterates through 20008each Rule in the list and initializes the content, flowbits, pcre, etc. 20009 20010\begin{verbatim} 20011extern Rule sid109; 20012extern Rule sid637; 20013 20014Rule *rules[] = 20015{ 20016 &sid109, 20017 &sid637, 20018 NULL 20019}; 20020\end{verbatim} 20021 20022\end{itemize} 20023 20024\chapter{Snort Development} 20025 20026Currently, this chapter is here as a place holder. It will someday contain 20027references on how to create new detection plugins and preprocessors. End users 20028don't really need to be reading this section. This is intended to help 20029developers get a basic understanding of whats going on quickly. 20030 20031If you are going to be helping out with Snort development, please use the 20032\textsc{head} branch of cvs. We've had problems in the past of people 20033submitting patches only to the stable branch (since they are likely writing 20034this stuff for their own IDS purposes). Bug fixes are what goes into 20035\textsc{stable}. Features go into \textsc{head}. 20036 20037\section{Submitting Patches} 20038 20039Patches to Snort should be sent to the 20040\verb!snort-devel@lists.snort.org! 20041mailing list. Patches should done with the command 20042\verb!diff -nu snort-orig snort-new!. 20043 20044\section{Snort Data Flow} 20045 20046First, traffic is acquired from the network link via libpcap. Packets are 20047passed through a series of decoder routines that first fill out the packet 20048structure for link level protocols then are further decoded for things like TCP 20049and UDP ports. 20050 20051Packets are then sent through the registered set of preprocessors. Each 20052preprocessor checks to see if this packet is something it should look at. 20053 20054Packets are then sent through the detection engine. The detection engine checks 20055each packet against the various options listed in the Snort config files. Each 20056of the keyword options is a plugin. This allows this to be easily extensible. 20057 20058\subsection{Preprocessors} 20059 20060For example, a TCP analysis preprocessor could simply return if the packet does 20061not have a TCP header. It can do this by checking: 20062 20063\begin{verbatim} 20064if (p->tcph==null) 20065 return; 20066\end{verbatim} 20067 20068Similarly, there are a lot of packet\_flags available that can be used to mark 20069a packet as ``reassembled'' or logged. Check out src/decode.h for the list of 20070pkt\_{*} constants. 20071 20072\subsection{Detection Plugins} 20073 20074Basically, look at an existing output plugin and copy it to a new item and 20075change a few things. Later, we'll document what these few things are. 20076 20077\subsection{Output Plugins} 20078 20079Generally, new output plugins should go into the barnyard project rather than 20080the Snort project. We are currently cleaning house on the available output 20081options. 20082 20083\section{Unified2 File Format} 20084 20085 Unified 2 records should not be assumed to be in any order. All 20086 values are stored in network byte order. 20087 20088 An example structure of unified2 files 20089 20090\begin{verbatim} 20091 [ Serial Unified2 Header ] 20092 [ Unified2 IDS Event ] 20093 [ Unified2 Packet ] 20094 [ Unified2 Extra Data ] 20095 . 20096 . 20097 . 20098 [ Serial Unified2 Header ] 20099 [ Unified2 IDS Event ] 20100 [ Unified2 Packet ] 20101 [ Unified2 Extra Data ] 20102\end{verbatim} 20103 20104\subsection{Serial Unified2 Header} 20105 20106\begin{verbatim} 20107 record type 4 bytes 20108 record length 4 bytes 20109\end{verbatim} 20110 20111 All unified2 records are preceded by a Serial Unified2 header. This 20112 unified2 record allows an interpreting application to skip past and 20113 apply simple heuristics against records. 20114 20115 The Record Type indicates one of the following unified2 records 20116 follows the Serial Unified2 Header: 20117 20118\begin{verbatim} 20119 Value Record Type 20120 ---------- ----------- 20121 2 Unified2 Packet 20122 7 Unified2 IDS Event 20123 72 Unified2 IDS Event IP6 20124 104 Unified2 IDS Event (Version 2) 20125 105 Unified2 IDS Event IP6 (Version 2) 20126 110 Unified2 Extra Data 20127\end{verbatim} 20128 20129 The record length field specifies the entire length of the record 20130 (not including the Serial Unified2 Header itself) up to the next 20131 Serial Unified2 Header or EOF. 20132 20133\subsection{Unified2 Packet} 20134 20135\begin{verbatim} 20136 sensor id 4 bytes 20137 event id 4 bytes 20138 event seconds 4 bytes 20139 packet seconds 4 bytes 20140 packet microseconds 4 bytes 20141 linktype 4 bytes 20142 packet length 4 bytes 20143 packet data <variable length> 20144\end{verbatim} 20145 20146 A Unified2 Packet is provided with each Unified2 Event record. This 20147 packet is the `alerting' packet that caused a given event. 20148 20149 Unified2 Packet records contain contain a copy of the packet that 20150 caused an alert (Packet Data) and is packet length octets long. 20151 20152\subsection{Unified2 IDS Event} 20153 20154\begin{verbatim} 20155 sensor id 4 bytes 20156 event id 4 bytes 20157 event second 4 bytes 20158 event microsecond 4 bytes 20159 signature id 4 bytes 20160 generator id 4 bytes 20161 signature revision 4 bytes 20162 classification id 4 bytes 20163 priority id 4 bytes 20164 ip source 4 bytes 20165 ip destination 4 bytes 20166 source port/icmp type 2 bytes 20167 dest. port/icmp code 2 bytes 20168 protocol 1 byte 20169 impact flag 1 byte 20170 impact 1 byte 20171 blocked 1 byte 20172\end{verbatim} 20173 20174 Unified2 IDS Event is logged for IPv4 Events without VLAN or MPLS 20175 tagging. 20176 20177\subsection{Unified2 IDS Event IP6} 20178 20179\begin{verbatim} 20180 sensor id 4 bytes 20181 event id 4 bytes 20182 event second 4 bytes 20183 event microsecond 4 bytes 20184 signature id 4 bytes 20185 generator id 4 bytes 20186 signature revision 4 bytes 20187 classification id 4 bytes 20188 priority id 4 bytes 20189 ip source 16 bytes 20190 ip destination 16 bytes 20191 source port/icmp type 2 bytes 20192 dest. port/icmp code 2 bytes 20193 protocol 1 byte 20194 impact flag 1 byte 20195 impact 1 byte 20196 blocked 1 byte 20197\end{verbatim} 20198 20199 Unified2 IDS Event IP6 is logged for IPv6 Events without VLAN or 20200 MPLS tagging. 20201 20202\subsection{Unified2 IDS Event (Version 2)} 20203 20204\begin{verbatim} 20205 sensor id 4 bytes 20206 event id 4 bytes 20207 event second 4 bytes 20208 event microsecond 4 bytes 20209 signature id 4 bytes 20210 generator id 4 bytes 20211 signature revision 4 bytes 20212 classification id 4 bytes 20213 priority id 4 bytes 20214 ip source 4 bytes 20215 ip destination 4 bytes 20216 source port/icmp type 2 bytes 20217 dest. port/icmp code 2 bytes 20218 protocol 1 byte 20219 impact flag 1 byte 20220 impact 1 byte 20221 blocked 1 byte 20222 mpls label 4 bytes 20223 vlan id 2 bytes 20224 padding 2 bytes 20225\end{verbatim} 20226 20227 Unified2 IDS Event (Version 2) are logged for IPv4 packets which 20228 contain either MPLS or VLAN headers. Otherwise a Unified2 IDS Event 20229 is logged. 20230 20231\begin{note} 20232\begin{itemize} 20233\item Note that you'll need to pass --enable-mpls to configure in order to have Snort fill in the mpls label field. 20234 20235\item Note that you'll need to configure unified2 logging with either mpls\_event\_types or vlan\_event\_types to get this record type. 20236\end{itemize} 20237\end{note} 20238 20239\subsection{Unified2 IDS Event IP6 (Version 2)} 20240 20241\begin{verbatim} 20242 sensor id 4 bytes 20243 event id 4 bytes 20244 event second 4 bytes 20245 event microsecond 4 bytes 20246 signature id 4 bytes 20247 generator id 4 bytes 20248 signature revision 4 bytes 20249 classification id 4 bytes 20250 priority id 4 bytes 20251 ip source 16 bytes 20252 ip destination 16 bytes 20253 source port/icmp type 2 bytes 20254 dest. port/icmp code 2 bytes 20255 protocol 1 byte 20256 impact flag 1 byte 20257 impact 1 byte 20258 blocked 1 byte 20259 mpls label 4 bytes 20260 vlan id 2 bytes 20261 padding 2 bytes 20262\end{verbatim} 20263 20264 Unified2 IDS Event IP6 (Version 2) are logged for IPv6 packets which 20265 contain either MPLS or VLAN headers. Otherwise a Unified2 IDS Event 20266 IP6 is logged. 20267 20268\begin{note} 20269\begin{itemize} 20270\item Note that you'll need to pass --enable-mpls to configure in order to have Snort fill in the mpls label field. 20271 20272\item Note that you'll need to configure unified2 logging with either mpls\_event\_types or vlan\_event\_types to get this record type. 20273\end{itemize} 20274\end{note} 20275 20276\subsection{Unified2 Extra Data} 20277 20278\begin{verbatim} 20279 sensor id 4 bytes 20280 event id 4 bytes 20281 event second 4 bytes 20282 type 4 bytes 20283 data type 4 bytes 20284 data length 4 bytes 20285 data <variable length> 20286\end{verbatim} 20287 20288\subsection{Description of Fields} 20289 20290\begin{itemize}\itemsep2pt 20291\item Sensor ID 20292 20293Unused 20294 20295\item Event ID 20296 20297The upper 2 bytes represent the snort instance, if specified by passing the -G option to Snort. 20298 20299The lower 2 bytes indicate the unique id of the event. 20300 20301The Event ID field is used to facilitate the task of coalescing 20302events with packet data. 20303 20304\item Event Seconds and Event Microseconds 20305 20306Timestamp represented as seconds since the epoch of when the alert was generated. 20307 20308\item Link Type (Unified2 Packet) 20309 20310The Datalink type of the packet, typically EN10M but could be any of the values as returned by pcap\_datalink that Snort handles. 20311 20312\item Packet Length (Unified2 Packet) 20313 20314Length of the Packet Data. 20315 20316\item Packet Data (Unified2 Packet) 20317 20318The alerting packet, of Packet Length bytes long. 20319 20320\item Type (Unified2 Extra Data) 20321 20322Type specifies the type of extra data that was logged, the valid types are: 20323 20324\begin{verbatim} 20325 Value Description 20326 ---------- ----------- 20327 1 Original Client IPv4 20328 2 Original Client IPv6 20329 3 UNUSED 20330 4 GZIP Decompressed Data 20331 5 SMTP Filename 20332 6 SMTP Mail From 20333 7 SMTP RCPT To 20334 8 SMTP Email Headers 20335 9 HTTP URI 20336 10 HTTP Hostname 20337 11 IPv6 Source Address 20338 12 IPv6 Destination Address 20339 13 Normalized Javascript Data 20340\end{verbatim} 20341 20342\item Data Type (Unified2 Extra Data) 20343 20344 The type of extra data in the record. 20345 20346\begin{verbatim} 20347 Value Description 20348 ---------- ----------- 20349 1 Blob 20350\end{verbatim} 20351 20352\item Data Length (Unified2 Extra Data) 20353 20354 Length of the data stored in the extra data record 20355 20356\item Data (Unified2 Extra Data) 20357 20358 Raw extra event data up to Data Length bytes in size. 20359 20360 All of these Extra data types, with the exception of 1, 2, 11, and 20361 12 (IP Addresses) are stored in plain-text. The IP Address types 20362 need to be interpreted as if they were coming off the wire. 20363 20364\item Signature ID 20365 20366 The Signature ID of the alerting rule, as specified by the sid 20367 keyword. 20368 20369\item Generator ID 20370 20371 The Generator ID of the alerting rule, as specified by the gid 20372 keyword. 20373 20374\item Signature Revision 20375 20376 Revision of the rule as specified by the rev keyword. 20377 20378\item Classification ID 20379 20380 Classification ID as mapped in the file classifications.conf 20381 20382\item Priority ID 20383 20384 Priority of the rule as mapped in the file classifications.conf or 20385 overridden by the priority keyword for text rules. 20386 20387\item IP Source 20388 20389 Source IP of the packet that generated the event. 20390 20391\item IP Destination 20392 20393 Destination IP of the packet that generated the event. 20394 20395\item Source Port/ICMP Type 20396 20397 If Protocol is TCP or UDP than this field contains the source port 20398 of the alerting packet. 20399 20400 If Protocol is ICMP than this field contains the ICMP type of the 20401 alerting packet. 20402 20403\item Destination Port/ICMP Code 20404 20405 If protocol is TCP or UDP than this field contains the source port 20406 of the alerting packet. 20407 20408 If protocol is icmp than this field contains the icmp code of the 20409 alerting packet. 20410 20411\item Protocol 20412 20413 Transport protocol of the alerting packet. One of: ip, tcp, udp, or 20414 icmp. 20415 20416\item Impact flag 20417 20418 Legacy field, specifies whether a packet was dropped or not. 20419 20420\begin{verbatim} 20421 Value Description 20422 ---------- ----------- 20423 32 Blocked 20424\end{verbatim} 20425 20426\item Impact 20427 20428 UNUSED; deprecated. 20429 20430\item Blocked 20431 20432 Whether the packet was not dropped, was dropped or would have been 20433 dropped. 20434 20435\begin{verbatim} 20436 Value Description 20437 ---------- ----------- 20438 0 Was NOT Dropped 20439 1 Was Dropped 20440 2 Would Have Dropped* 20441\end{verbatim} 20442 20443\begin{note} 20444Note that you'll obtain Would Have Dropped on rules which are set to drop 20445while Snort is running in inline-test mode. Would Have Dropped is also 20446obtained when a drop rule fires while pruning sessions or during shutdown. 20447\end{note} 20448 20449\item MPLS Label (4 bytes) 20450 20451 The extracted mpls label from the mpls header in the alerting 20452 packet. 20453 20454\item VLAN ID 20455 20456 The extracted vlan id from the vlan header in the alerting packet. 20457 20458\item Padding 20459 20460 Padding is used to keep the event structures aligned on a 4 byte 20461 boundary. 20462\end{itemize} 20463 20464\section{Buffer dump utility} 20465 20466Buffer dump option will dump the buffers used by snort during different stages of packet processing path. 20467 20468\begin{verbatim} 20469 ./configure --enable-buffer-dump / -DDUMP_BUFFER 20470\end{verbatim} 20471 20472Two options are provided to dump buffers. '--buffer-dump-alert' will dump buffers only when there is an alert. 20473 20474'--buffer-dump' will dump buffers for every packet. 20475 20476\begin{verbatim} 20477 ./snort -A cmg -k none -Q --daq-dir=<dir> --daq dump -r <pcap> -c snort.conf --buffer-dump-alert=<file> 20478 or 20479 ./snort -A cmg -k none -Q --daq-dir=<dir> --daq dump -r <pcap> -c snort.conf --buffer-dump=<file> 20480 20481Note: If <file> parameter is not used, buffers are dumped on the console 20482\end{verbatim} 20483 20484\subsection{Example Buffer Dump output} 20485 20486\begin{verbatim} 20487METHOD_DUMP, 3 20488 2048900000000 47 45 54 |GET | 20490 20491URI_DUMP, 340 20492 2049300000000 2F 70 68 70 42 42 33 2F 76 69 65 77 74 6F 70 69 |/phpBB3/viewtopi| 2049400000010 63 2E 70 68 70 3F 70 3D 39 30 30 32 26 73 69 64 |c.php?p=9002&sid| 2049500000020 3D 66 35 33 39 39 61 32 64 32 34 33 63 65 61 64 |=f5399a2d243cead| 2049600000030 33 61 35 65 61 37 61 64 66 31 35 62 66 63 38 37 |3a5ea7adf15bfc87| 2049700000040 32 26 68 69 67 68 6C 69 67 68 74 3D 27 2E 66 77 |2&highlight='.fw| 2049800000050 72 69 74 65 28 66 6F 70 65 6E 28 63 68 72 28 31 |rite(fopen(chr(1| 2049900000060 30 39 29 2E 63 68 72 28 34 39 29 2E 63 68 72 28 |09).chr(49).chr(| 2050000000070 31 30 34 29 2E 63 68 72 28 31 31 31 29 2E 63 68 |104).chr(111).ch| 2050100000080 72 28 35 30 29 2E 63 68 72 28 31 31 31 29 2E 63 |r(50).chr(111).c| 2050200000090 68 72 28 31 30 32 29 2C 63 68 72 28 39 37 29 29 |hr(102),chr(97))| 20503000000a0 2C 63 68 72 28 33 35 29 2E 63 68 72 28 33 33 29 |,chr(35).chr(33)| 20504000000b0 2E 63 68 72 28 34 37 29 2E 63 68 72 28 31 31 37 |.chr(47).chr(117| 20505000000c0 29 2E 63 68 72 28 31 31 35 29 2E 63 68 72 28 31 |).chr(115).chr(1| 20506000000d0 31 34 29 2E 63 68 72 28 34 37 29 2E 63 68 72 28 |14).chr(47).chr(| 20507000000e0 39 38 29 2E 63 68 72 28 31 30 35 29 2E 63 68 72 |98).chr(105).chr| 20508000000f0 28 31 31 30 29 2E 63 68 72 28 34 37 29 2E 63 68 |(110).chr(47).ch| 2050900000100 72 28 31 31 32 29 2E 63 68 72 28 31 30 31 29 2E |r(112).chr(101).| 2051000000110 63 68 72 28 31 31 34 29 2E 63 68 72 28 31 30 38 |chr(114).chr(108| 2051100000120 29 2E 63 68 72 28 31 30 29 2E 63 68 72 28 31 31 |).chr(10).chr(11| 2051200000130 37 29 2E 63 68 72 28 31 31 35 29 2E 63 68 72 28 |7).chr(115).chr(| 2051300000140 31 30 31 29 2E 63 68 72 28 33 32 29 29 2C 65 78 |101).chr(32)),ex| 2051400000150 69 74 2E FF |it.. | 20515\end{verbatim} 20516 20517\section{The Snort Team} 20518 20519\begin{tabular}{p{3in} p{3in}} 20520 20521\textbf{Creator and Lead Architect} 20522& Marty Roesch\\ 20523\\ 20524\textbf{Lead Snort Developers} 20525& Steve Sturges\\ 20526& Bhagyashree Bantwal\\ 20527& Ed Borgoyn\\ 20528& Hui Cao\\ 20529& Russ Combs\\ 20530& Victor Roemer\\ 20531& Charles Summers\\ 20532& Josh Rosenbaum\\ 20533& Carter Waxman\\ 20534& Tom Peters\\ 20535& A V K Nageswara Rao (ANR)\\ 20536& Rahul Burman\\ 20537& Seshaiah Erugu\\ 20538& Krishnakanth K\\ 20539\\ 20540\textbf{Snort QA Team} 20541& Chris Spencer\\ 20542& Jigeshwar Patel\\ 20543& Albert Lewis\\ 20544& Nihal Desai\\ 20545\\ 20546\textbf{Vulnerability Research Team} 20547& Matt Watchinski\\ 20548& Aaron Benson\\ 20549& Nathan Benson\\ 20550& Andrew Blunck\\ 20551& Christoph Cordes\\ 20552& Joel Esler\\ 20553& Douglas Goddard\\ 20554& Ethan Gulla\\ 20555& Nigel Houghton\\ 20556& Pawel Janic\\ 20557& Richard Johnson\\ 20558& Tom Judge\\ 20559& Alex Kambis\\ 20560& Alex Kirk\\ 20561& Chris Marshall\\ 20562& Christopher McBee\\ 20563& Alex McDonnell\\ 20564& Kevin Miklavcic\\ 20565& Steve Morgan\\ 20566& Patrick Mullen\\ 20567& Katie Nolan\\ 20568& Matt Olney\\ 20569& Carlos Pacho\\ 20570& Ryan Pentney\\ 20571& Nick Randolph\\ 20572& Dave Raynor\\ 20573& Marcos Rodriguez\\ 20574& Ryan Steinmetz\\ 20575& Brandon Stultz\\ 20576& Andy Walker\\ 20577& Shawn Webb\\ 20578& Carl Wu\\ 20579& Yves Younan\\ 20580& Alain Zidouemba\\ 20581\\ 20582\end{tabular} 20583 20584\begin{tabular}{p{3in} p{3in}} 20585\textbf{Win32 Maintainer} 20586& Snort Team\\ 20587\\ 20588\textbf{Snort Community Manager} 20589& Joel Esler\\ 20590\\ 20591\textbf{Snort Web Team} 20592& Aaron Norling\\ 20593& Mike Verbeck\\ 20594\\ 20595\textbf{Major Contributors} 20596& Erek Adams\\ 20597& Michael Altizer\\ 20598& Ayushi Agarwal\\ 20599& Andrew Baker\\ 20600& Scott Campbell\\ 20601& Brian Caswell\\ 20602& Dilbagh Chahal\\ 20603& JJ Cummings\\ 20604& Scott Czajkowski\\ 20605& Roman D.\\ 20606& Michael Davis\\ 20607& Ron Dempster\\ 20608& Matt Donnan\\ 20609& Chris Green\\ 20610& Lurene Grenier\\ 20611& Mike Guiterman\\ 20612& Jed Haile\\ 20613& Justin Heath\\ 20614& Patrick Harper\\ 20615& Jeremy Hewlett\\ 20616& Ryan Jordan\\ 20617& Victor Julien\\ 20618& Glenn Mansfield Keeni\\ 20619& Adam Keeton\\ 20620& Keith Konecnik\\ 20621& Veronica Kovah\\ 20622& Chad Kreimendahl\\ 20623& Kevin Liu\\ 20624& Rob McMillen\\ 20625& William Metcalf\\ 20626& Andrew Mullican\\ 20627& Jeff Nathan\\ 20628& Marc Norton\\ 20629& Judy Novak\\ 20630& Andreas Ostling\\ 20631& William Parker\\ 20632& Chris Reid\\ 20633& Daniel Roelker\\ 20634& Dragos Ruiu\\ 20635& Chris Sherwin\\ 20636& Matt Smith\\ 20637& Jennifer Steffens\\ 20638& Todd Wease\\ 20639& JP Vossen\\ 20640& Leon Ward\\ 20641& Daniel Wittenberg\\ 20642& Phil Wood\\ 20643& Fyodor Yarochkin\\ 20644\end{tabular} 20645 20646\appendix 20647 20648\begin{thebibliography}{99} 20649\bibitem{phracknmaparticle}http://packetstorm.securify.com/mag/phrack/phrack49/p49-06 20650\bibitem{nmaphomepage}http://www.nmap.org 20651\bibitem{cidrnotation}http://public.pacbell.net/dedicated/cidr.html 20652\bibitem{whitehatsurl}http://www.whitehats.com 20653\bibitem{snortdb}http://www.incident.org/snortdb 20654\bibitem{pcre}http://www.pcre.org 20655\end{thebibliography} 20656 20657\end{document} 20658 20659