<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://commons.oreilly.com/wiki/index.php?title=Snort_Cookbook/Logging%2C_Alerts%2C_and_Output_Plug-ins&amp;action=history&amp;feed=atom</id>
		<title>Snort Cookbook/Logging, Alerts, and Output Plug-ins - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://commons.oreilly.com/wiki/index.php?title=Snort_Cookbook/Logging%2C_Alerts%2C_and_Output_Plug-ins&amp;action=history&amp;feed=atom"/>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Snort_Cookbook/Logging%2C_Alerts%2C_and_Output_Plug-ins&amp;action=history"/>
		<updated>2013-06-19T23:00:06Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.11.0</generator>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Snort_Cookbook/Logging%2C_Alerts%2C_and_Output_Plug-ins&amp;diff=25366&amp;oldid=prev</id>
		<title>Docbook2Wiki: Initial conversion from Docbook</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Snort_Cookbook/Logging%2C_Alerts%2C_and_Output_Plug-ins&amp;diff=25366&amp;oldid=prev"/>
				<updated>2009-08-26T17:56:22Z</updated>
		
		<summary type="html">&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Snort Cookbook/TOC}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
All the time, money, and effort invested into an IDS can quickly become meaningless if you're not looking at the logs and monitoring the alerts. If you're administering a fairly large network, this could take significant time and resources. Even if you're administering a small home network, looking at logs can still be a tedious task! Fortunately, Snort and many of its add-on products include numerous ways to make logging and alerting easier and more efficient. You can configure Snort to use a variety of output plug-ins, allowing you to log data as ASCII text files, binary files, databases, and more. Add-on products such as Swatch and Barnyard analyze the logs and alerts in easy-to-use formats. This chapter introduces you to the many options for viewing log and alert data, so there is no reason to let your IDS go a day unnoticed!&lt;br /&gt;
&lt;br /&gt;
Remember to consider security when transmitting log data via methods such as syslog, email, and pager notifications. Your logging methods should comply with your company's overall security policy. The event data that is logged and transmitted should be considered confidential, and possibly encrypted in transit and/or in storage.&lt;br /&gt;
&lt;br /&gt;
== Logging to a File Quickly ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to increase the speed of logging your output to a file.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Edit the ''/etc/snort.conf'' file to use unified logging:&lt;br /&gt;
&lt;br /&gt;
 output alert_unified: filename snort.alert, limit 128&lt;br /&gt;
 output log_unified: filename snort.log, limit 128&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Unified logging uses a Snort output plug-in to reduce the load on the Snort processing engine. To enable unified logging, you must uncomment and configure the following output plug-ins in the ''/etc/snort.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 # unified: Snort unified binary format alerting and logging&lt;br /&gt;
 # -------------------------------------------------------------&lt;br /&gt;
 # The unified output plugin provides two new formats for logging and &lt;br /&gt;
 # generating alerts from Snort, the &amp;quot;unified&amp;quot; format.  The unified &lt;br /&gt;
 # format is a straight binary format for logging data out of Snort &lt;br /&gt;
 # that is designed to be fast and efficient.  Used with barnyard (the &lt;br /&gt;
 # new alert/log processor), most of the overhead for logging and &lt;br /&gt;
 # alerting to various slow storage mechanisms such as databases or the&lt;br /&gt;
 # network can now be avoided.&lt;br /&gt;
 #&lt;br /&gt;
 # Check out the spo_unified.h file for the data formats.&lt;br /&gt;
 #&lt;br /&gt;
 # Two arguments are supported.&lt;br /&gt;
 #    filename - base filename to write to (current time_t is appended)&lt;br /&gt;
 #    limit    - maximum size of spool file in MB (default: 128)&lt;br /&gt;
 #&lt;br /&gt;
 output alert_unified: filename snort.alert, limit 128&lt;br /&gt;
 output log_unified: filename snort.log, limit 128&lt;br /&gt;
&lt;br /&gt;
Both the ttfilename/tt and ttfile/tt ttsize/tt ttlimit/tt parameters are configurable. Unified logs have a varying number assigned to them after the ''.alert'' and ''.log'' filename extensions. In our example, running Snort with the following command-line options created the unified logging files ''snort.alert.1086463191''and ''snort.log.1086463191'' in the ''C:\Snort\log'' directory:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin '''snort -l c:\snort\log -c c:\snort\etc\snort.conf'''&lt;br /&gt;
&lt;br /&gt;
If you're using Snort on a very high-speed network, such as 1Gbps or greater, you benefit from unified logging. This allows the Snort engine to write logs and alerts quickly to a binary file, while offloading the spooling and processing to another program. Offloading the processing of the logs and alerts means that Snort can spend more time capturing data, thus decreasing the likelihood that packets are dropped. You must use a unified log reader, such as Barnyard, to process the logfiles.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Administrative Tools#Installing and Configuring Barnyard|Recipe 5.9]]&lt;br /&gt;
&lt;br /&gt;
== Logging Only Alerts ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to log just the alerts to a file.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the fast alert mode with the -A fast command-line option:&lt;br /&gt;
&lt;br /&gt;
 [testuser@localhost snort]# '''snort -de -c /etc/snort.conf -A fast'''&lt;br /&gt;
&lt;br /&gt;
You can also use the Barnyard ttalert_fast/tt plug-in in the ''/etc/barnyard.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 # alert_fast&lt;br /&gt;
 #-----------------------------&lt;br /&gt;
 # Converts data from the dp_alert plugin into an approximation of &lt;br /&gt;
 # Snort's &amp;quot;fast alert&amp;quot; mode.  Argument: filename&lt;br /&gt;
    &lt;br /&gt;
 output alert_fast /var/log/snort/fast_output&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
By default, Snort logs in a decoded ASCII format and uses full alerts. A full alert includes the alert message and the full packet header. Snort also includes other alert output options and logging methods, such as fast, full, console, or none.&lt;br /&gt;
&lt;br /&gt;
To produce less output, you can use the fast alert mode with the -A fast command-line option:&lt;br /&gt;
&lt;br /&gt;
 [testuser@localhost snort]# '''snort -de -c /etc/snort.conf -A fast'''&lt;br /&gt;
&lt;br /&gt;
The tt-d/tt command-line option logs application-layer information and tt-e/tt logs data link-layer information. The output then looks like the following:&lt;br /&gt;
&lt;br /&gt;
 11/05-22:08:59.705515  [**] [1:469:3] ICMP PING NMAP [**] &lt;br /&gt;
 [Classification: Attempted Information Leak][Priority: 2] {ICMP} &lt;br /&gt;
 192.168.206.129 - 192.168.100.5&lt;br /&gt;
&lt;br /&gt;
If you are using unified logging and the Barnyard output utility, you can also log alerts by using the ttalert_fast/tt output plug-in. Barnyard takes the log processing load off of the Snort engine. Barnyard processing is controlled by input processors and output plug-ins. [[Snort Cookbook/Administrative Tools|Chapter 5]] contains more information. The following example is from the ''/etc/barnyard.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 # alert_fast&lt;br /&gt;
 #-----------------------------&lt;br /&gt;
 # Converts data from the dp_alert plugin into an approximation of &lt;br /&gt;
 # Snort's &amp;quot;fast alert&amp;quot; mode.  Argument: filename&lt;br /&gt;
    &lt;br /&gt;
 output alert_fast /var/log/snort/fast_output&lt;br /&gt;
&lt;br /&gt;
The Snort output passes to the Barnyard utility via the unified logging plug-in. By default, Barnyard processes the output and logs the alerts to the ''/var/log/snort/fast_output'' file. The output looks like the following:&lt;br /&gt;
&lt;br /&gt;
 [testuser@localhost snort]# '''more fast_output'''nowiki&lt;br /&gt;
11/06/04-00:32:05.706661 {ICMP} 192.168.206.129 - 192.168.100.5&lt;br /&gt;
[**] [1:469:3] ICMP PING NMAP [**]&lt;br /&gt;
[Classification: Attempted Information Leak] [Priority: 2]&lt;br /&gt;
[Xref = http://www.whitehats.com/info/IDS162]&lt;br /&gt;
---------------------------------------------------------------------&lt;br /&gt;
11/06/04-00:32:10.896823 {ICMP} 192.168.206.129 - 192.168.100.5&lt;br /&gt;
[**] [1:469:3] ICMP PING NMAP [**]&lt;br /&gt;
[Classification: Attempted Information Leak] [Priority: 2]&lt;br /&gt;
[Xref = http://www.whitehats.com/info/IDS162]&lt;br /&gt;
---------------------------------------------------------------------/nowiki&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Administrative Tools#Installing and Configuring Barnyard|Recipe 5.9]]&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Logging, Alerts, and Output Plug-ins#Logging to a File Quickly|Recipe 2.1]]&lt;br /&gt;
&lt;br /&gt;
== Logging to a CSV File ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to log your output to a comma-separated value (CSV) file.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the Barnyard ttalert_csv/tt plug-in by editing the ''/etc/barnyard.conf''file:&lt;br /&gt;
&lt;br /&gt;
 output alert_csv: /var/log/snort/csv.out timestamp,msg,srcip,sport,&lt;br /&gt;
 dstip,dport,protoname,itype,icode&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Snort alerts can be logged in comma-separated value format for ease of use with databases and spreadsheets. This also allows portability of output data to numerous software applications on a variety of operating systems. To do this, you must use the Barnyard output utility and Snort's unified logging feature. Barnyard contains the ttalert_csv/tt module, which you can configure to log your choice of the fields in the output, in any order you specify. You can use the Barnyard ttalert_csv/tt plug-in by editing the ''/etc/barnyard.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 # alert_csv (experimental)&lt;br /&gt;
 #---------------------------&lt;br /&gt;
 # Creates a CSV output file of alerts (optionally using a user &lt;br /&gt;
 # specified format) Arguments:  filepath [format]&lt;br /&gt;
 #&lt;br /&gt;
 # The format is a comma-seperated list of fields to output (no spaces &lt;br /&gt;
 # allowed)&lt;br /&gt;
 # The available fields are:&lt;br /&gt;
 #   sig_gen         - signature generator&lt;br /&gt;
 #   sig_id          - signature id&lt;br /&gt;
 #   sig_rev         - signatrue revision&lt;br /&gt;
 #   sid             - SID triplet&lt;br /&gt;
 #   class           - class id&lt;br /&gt;
 #   classname       - textual name of class&lt;br /&gt;
 #   priority        - priority id&lt;br /&gt;
 #   event_id        - event id&lt;br /&gt;
 #   event_reference - event reference&lt;br /&gt;
 #   ref_tv_sec      - reference seconds&lt;br /&gt;
 #   ref_tv_usec     - reference microseconds&lt;br /&gt;
 #   tv_sec          - event seconds&lt;br /&gt;
 #   tv_usec         - event microseconds&lt;br /&gt;
 #   timestamp       - timestamp (2001-01-01 01:02:03) in UTC&lt;br /&gt;
 #   src             - src address as a u_int32_t&lt;br /&gt;
 #   srcip           - src address as a dotted quad&lt;br /&gt;
 #   dst             - dst address as a u_int32_t&lt;br /&gt;
 #   dstip           - dst address as a dotted quad&lt;br /&gt;
 #   sport_itype     - source port or ICMP type (or 0)&lt;br /&gt;
 #   sport           - source port (if UDP or TCP)&lt;br /&gt;
 #   itype           - ICMP type (if ICMP)&lt;br /&gt;
 #   dport_icode     - dest port or ICMP code (or 0)&lt;br /&gt;
 #   dport           - dest port&lt;br /&gt;
 #   icode           - ICMP code (if ICMP)&lt;br /&gt;
 #   proto           - protocol number&lt;br /&gt;
 #   protoname       - protocol name&lt;br /&gt;
 #   flags           - flags from UnifiedAlertRecord&lt;br /&gt;
 #   msg             - message text&lt;br /&gt;
 #   hostname        - hostname (from barnyard.conf)&lt;br /&gt;
 #   interface       - interface (from barnyard.conf)&lt;br /&gt;
 #&lt;br /&gt;
 # Examples:&lt;br /&gt;
 #   output alert_csv: /var/log/snort/csv.out&lt;br /&gt;
 #   output alert_csv: /var/log/snort/csv.out  timestamp,&lt;br /&gt;
 msg,srcip,sport,dstip,dport,protoname,itype,icode&lt;br /&gt;
 #   output alert_csv: csv.out  timestamp,msg,srcip,sport,&lt;br /&gt;
 dstip,dport,protoname,itype,icode&lt;br /&gt;
    &lt;br /&gt;
 output alert_csv: /var/log/snort/csv.out timestamp,msg,&lt;br /&gt;
 srcip,sport,dstip,dport,protoname,itype,icode&lt;br /&gt;
&lt;br /&gt;
This logs the fields specified, in the order specified, to the file ''/var/log/snort/csv.out''. The output looks like the following:&lt;br /&gt;
&lt;br /&gt;
 [testuser@localhost snort]# '''more csv.out'''&lt;br /&gt;
 &amp;quot;2004-11-06 00:32:05&amp;quot;,ICMP PING NMAP,192.168.206.129,,192.168.100.5,,&lt;br /&gt;
 &amp;quot;ICMP&amp;quot;,8,0&lt;br /&gt;
 &amp;quot;2004-11-06 00:32:10&amp;quot;,ICMP PING NMAP,192.168.206.129,,192.168.100.5,,&lt;br /&gt;
 &amp;quot;ICMP&amp;quot;,8,0&lt;br /&gt;
 &amp;quot;2004-11-06 00:35:35&amp;quot;,SNMP request tcp,192.168.206.129,36252,192.168.100.5,161,&amp;quot;TCP&amp;quot;,,&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Administrative Tools#Installing and Configuring Barnyard|Recipe 5.9]]&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Logging, Alerts, and Output Plug-ins#Logging to a File Quickly|Recipe 2.1]]&lt;br /&gt;
&lt;br /&gt;
== Logging to a Specific File ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to log your output to a specific file and location.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the -L tt''filename''/tt option to log to a specific file:&lt;br /&gt;
&lt;br /&gt;
 [testuser@localhost snort]# '''snort -L test1'''&lt;br /&gt;
&lt;br /&gt;
You can also specify a location by using the -l tt''directory''/tt command-line option:&lt;br /&gt;
&lt;br /&gt;
 [testuser@localhost snort]# '''snort -l /snort/log -L test2'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Logging traffic in binary mode is far less resource intensive than in other modes. Binary files can then be reviewed later using Snort, TCPDump, Ethereal, or other binary log-compatible programs.&lt;br /&gt;
&lt;br /&gt;
You can log to a specific file by specifying the -L tt''filename''/tt command-line option. This logs the network traffic to a binary file. The following command logs all traffic to the file called ''test1'' in the default Snort log directory:&lt;br /&gt;
&lt;br /&gt;
 [testuser@localhost snort]# '''snort -L test1'''&lt;br /&gt;
&lt;br /&gt;
This command creates a file called ''test1.1084554709'' in the ''/var/log/snort'' directory. You can also specify a location by using the -l tt''directory''/tt command-line option:&lt;br /&gt;
&lt;br /&gt;
 [testuser@localhost snort]# '''snort -l /snort/log -L test2'''&lt;br /&gt;
&lt;br /&gt;
This command creates a file called ''test1.1084554711'' in the ''/snort/log'' directory.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Logging Packets That Snort Captures|Recipe 1.17]]&lt;br /&gt;
&lt;br /&gt;
== Logging to Multiple Locations ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to log to a file and a database at the same time.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use various output plug-ins such as the Snort output plug-ins in ''/etc/snort.conf'':&lt;br /&gt;
&lt;br /&gt;
 output alert_syslog: LOG_AUTH LOG_ALERT&lt;br /&gt;
 output log_tcpdump: tcpdump.log&lt;br /&gt;
 output database: log, mysql, user=root password=test dbname=db &lt;br /&gt;
 host=localhost&lt;br /&gt;
 output alert_unified: filename snort.alert, limit 128&lt;br /&gt;
 output log_unified: filename snort.log, limit 128&lt;br /&gt;
&lt;br /&gt;
You may also use the Barnyard plug-ins in the ''/etc/barnyard.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 output alert_fast /var/log/snort/fast_alert&lt;br /&gt;
 output log_dump /var/log/snort/dump_output&lt;br /&gt;
 output alert_csv: /var/log/snort/csv.out  timestamp,msg,srcip,&lt;br /&gt;
 sport,dstip,dport,protoname,itype,icode&lt;br /&gt;
 output alert_syslog&lt;br /&gt;
 output log_pcap /var/log/snort/pcap_log&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
You can log your Snort output to multiple locations by using multiple output plug-ins. These can be the standard Snort output plug-ins, as well as the Barnyard output utility plug-ins. For example, you can log fast alerts, CSV, and to a database all at the same time. The ''snort.conf'' file currently supports the syslog, TCPDump, database, and unified output plug-ins. Barnyard supports the fast alerts, ASCII log dump, CSV, syslog, pcap, ACID database, and SGUIL. However, the more ways you log, the more load it places on the Snort engine and the CPU. You must choose your hardware and operating system carefully when logging to multiple locations.&lt;br /&gt;
&lt;br /&gt;
Using the Snort output plug-ins in the ''/etc/snort.conf'' file and the following examples, you can log to syslog:&lt;br /&gt;
&lt;br /&gt;
 output alert_syslog: LOG_AUTH LOG_ALERT&lt;br /&gt;
&lt;br /&gt;
A TCPDump file:&lt;br /&gt;
&lt;br /&gt;
 output log_tcpdump: tcpdump.log&lt;br /&gt;
&lt;br /&gt;
A database:&lt;br /&gt;
&lt;br /&gt;
 output database: log, mysql, user=root password=test dbname=db &lt;br /&gt;
 host=localhost&lt;br /&gt;
&lt;br /&gt;
And unified logging:&lt;br /&gt;
&lt;br /&gt;
 output alert_unified: filename snort.alert, limit 128&lt;br /&gt;
 output log_unified: filename snort.log, limit 128&lt;br /&gt;
&lt;br /&gt;
The Barnyard output plug-ins can be configured in the ''/etc/barnyard.conf'' file using the following examples to log fast alerts with less information:&lt;br /&gt;
&lt;br /&gt;
 output alert_fast /var/log/snort/fast_alert&lt;br /&gt;
&lt;br /&gt;
Output ASCII packet dumps:&lt;br /&gt;
&lt;br /&gt;
 output log_dump /var/log/snort/dump_output&lt;br /&gt;
&lt;br /&gt;
Create a comma-separated value output file with various fields:&lt;br /&gt;
&lt;br /&gt;
 output alert_csv: /var/log/snort/csv.out &lt;br /&gt;
 timestamp,msg,srcip,sport,dstip,dport,protoname,itype,icode&lt;br /&gt;
&lt;br /&gt;
Create syslog output:&lt;br /&gt;
&lt;br /&gt;
 output alert_syslog&lt;br /&gt;
&lt;br /&gt;
And create pcap output:&lt;br /&gt;
&lt;br /&gt;
 output log_pcap /var/log/snort/pcap_log&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Administrative Tools#Installing and Configuring Barnyard|Recipe 5.9]]&lt;br /&gt;
&lt;br /&gt;
== Logging in Binary ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to log packets in binary format.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
There are several options available to log packets in binary format.&lt;br /&gt;
&lt;br /&gt;
Use the -b command-line option along with the -l tt''directory''/tt option:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -b'''&lt;br /&gt;
&lt;br /&gt;
Use the -L tt''filename''/tt option to specify a name for the binary file:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -L test'''&lt;br /&gt;
&lt;br /&gt;
Use the ''/etc/snort.conf'' file to enable the ttlog_tcpdump/tt output plug-in:&lt;br /&gt;
&lt;br /&gt;
 # log_tcpdump: log packets in binary tcpdump format&lt;br /&gt;
 # -------------------------------------------------&lt;br /&gt;
 # The only argument is the output file name.&lt;br /&gt;
 #&lt;br /&gt;
 output log_tcpdump: tcpdump.log&lt;br /&gt;
&lt;br /&gt;
Use the ''/etc/snort.conf'' file to enable the unified output plug-in&lt;br /&gt;
&lt;br /&gt;
 output alert_unified: filename snort.alert, limit 128&lt;br /&gt;
 output log_unified: filename snort.log, limit 128&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
To log in binary format, you use the tt-b/tt command-line option in conjunction with tt-l/tt. The tt-b/tt option specifies to log the packets in binary format. You won't see any data output on the screen when you are logging in binary format, unless you also use the tt-v/tt command-line option. You don't need to specify the tt-d/tt or tt-e/tt command-line options, because by default, the binary option logs the entire packet.&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -b'''&lt;br /&gt;
&lt;br /&gt;
The previous command creates a file called ''snort.log.1084553605'' in the ''C:\Snort\log'' directory. In addition, you can specify a name for the logfile by using the tt-L/tt tt''filename''/tt option. When using the -L option, you don't need to specify the tt-b/tt option because it automatically logs in binary format.&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -L test'''&lt;br /&gt;
&lt;br /&gt;
The previous command creates a file called ''test.1084554709'' in the ''C:\Snort\log'' directory.&lt;br /&gt;
&lt;br /&gt;
If you run Snort in network intrusion detection (NIDS) mode, you can also perform binary logging by uncommenting the following line from the ''/etc/snort.conf file'':&lt;br /&gt;
&lt;br /&gt;
 # log_tcpdump: log packets in binary tcpdump format&lt;br /&gt;
 # -------------------------------------------------&lt;br /&gt;
 # The only argument is the output file name.&lt;br /&gt;
 #&lt;br /&gt;
 output log_tcpdump: tcpdump.log&lt;br /&gt;
&lt;br /&gt;
Unified logging also logs in binary format; however, it uses a Snort output plug-in to reduce the load on the Snort processing engine. To enable unified logging, uncomment and configure the following output plug-ins in the ''/etc/snort.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 # unified: Snort unified binary format alerting and logging&lt;br /&gt;
 # -------------------------------------------------------------&lt;br /&gt;
 # The unified output plugin provides two new formats for logging and&lt;br /&gt;
 # generating alerts from Snort, the &amp;quot;unified&amp;quot; format.  The unified &lt;br /&gt;
 # format is a straight binary format for logging data out of Snort&lt;br /&gt;
 # that is designed to be fast and efficient.  Used with barnyard (the&lt;br /&gt;
 # new alert/log processor), most of the overhead for logging and&lt;br /&gt;
 # alerting to various slow storage mechanisms such as databases or the&lt;br /&gt;
 # network can now be avoided.&lt;br /&gt;
 #&lt;br /&gt;
 # Check out the spo_unified.h file for the data formats.&lt;br /&gt;
 #&lt;br /&gt;
 # Two arguments are supported.&lt;br /&gt;
 #    filename - base filename to write to (current time_t is appended)&lt;br /&gt;
 #    limit    - maximum size of spool file in MB (default: 128)&lt;br /&gt;
 #&lt;br /&gt;
 output alert_unified: filename snort.alert, limit 128&lt;br /&gt;
 output log_unified: filename snort.log, limit 128&lt;br /&gt;
&lt;br /&gt;
Both the ttfilename/tt and ttfile/tt ttsize/tt ttlimit/tt parameters are configurable. Unified logs have a unique, varying number appended to the filename (e.g., ''snort.alert.1099412241'') to ensure that existing files are not overwritten. This number is known as Epoch time: the number of seconds since 01-01-1970.&lt;br /&gt;
&lt;br /&gt;
Binary logging makes logging more efficient because the Snort engine doesn't have to translate the data into human-readable format. Logging traffic in binary mode is far less resource intensive than in other modes. Binary files can then be reviewed later using Snort, TCPDump, Ethereal, or other binary log-compatible programs. If you are using Snort on a high-speed network, such as 1Gbps or greater, you benefit more from unified logging. This allows the Snort engine to write logs and alerts quickly to a binary file, while offloading the spooling and processing to another program. Offloading the processing of the logs and alerts means that Snort can spend more time capturing data, thus decreasing the likelihood that packets are dropped. Use a unified log reader, such as Barnyard, to process the logfiles.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Administrative Tools#Installing and Configuring Barnyard|Recipe 5.9]]&lt;br /&gt;
&lt;br /&gt;
== Viewing Traffic While Logging ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You are logging your traffic to files, or some other output means, but you also want to view the traffic on the screen.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the tt-v/tt (verbose) command-line option when running Snort:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -vde -l c:\snort\log'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Using tt-v/tt on the command line always allows you to see your network traffic. Just remember, this can create a larger load on the CPU of the system running Snort. For networks with high, steady traffic, you probably won't want to run Snort in this mode very often, since it could become overloaded and drop packets.&lt;br /&gt;
&lt;br /&gt;
To see what is going on while your packets are being logged, simply use the tt-v/tt (verbose) command-line option when running Snort:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -vde -l c:\snort\log'''&lt;br /&gt;
 Running in packet logging mode&lt;br /&gt;
 Log directory = c:\snort\log&lt;br /&gt;
    &lt;br /&gt;
 Initializing Network Interface \Device\NPF_&lt;br /&gt;
 {572FF0E6-9A1E-42B5-A2AF-A5A307B613EF}&lt;br /&gt;
    &lt;br /&gt;
         --=  = Initializing Snort =  =--&lt;br /&gt;
 Initializing Output Plugins!&lt;br /&gt;
 Decoding Ethernet on interface \Device\NPF_&lt;br /&gt;
 {572FF0E6-9A1E-42B5-A2AF-A5A307B613EF}&lt;br /&gt;
    &lt;br /&gt;
         --=  = Initialization Complete =  =--&lt;br /&gt;
    &lt;br /&gt;
 -* Snort! *-&lt;br /&gt;
 Version 2.2.0-ODBC-MySQL-FlexRESP-WIN32 (Build 30)&lt;br /&gt;
 By Martin Roesch (roesch@sourcefire.com, www.snort.org)&lt;br /&gt;
 1.7-WIN32 Port By Michael Davis (mike@datanerds.net, &lt;br /&gt;
 www.datanerds.net/~mike)&lt;br /&gt;
 1.8 - 2.x WIN32 Port By Chris Reid &lt;br /&gt;
 (chris.reid@codecraftconsultants.com)&lt;br /&gt;
    &lt;br /&gt;
 11/01-11:44:37.537461 0:C:F1:11:D:66 - 0:5:5D:ED:3B:C6 type:0x800 &lt;br /&gt;
 len:0x3E&lt;br /&gt;
 192.168.100.70:4258 - 192.168.129.201:4243 TCP TTL:128 TOS:0x0 &lt;br /&gt;
 ID:45294 IpLen:2 0 DgmLen:48 DF&lt;br /&gt;
 ******S* Seq: 0x6C0D8FB0  Ack: 0x0  Win: 0x4000  TcpLen: 28&lt;br /&gt;
 TCP Options (4) = MSS: 1460 NOP NOP SackOK&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Logging Packets That Snort Captures|Recipe 1.17]]&lt;br /&gt;
&lt;br /&gt;
== Logging Application Data ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to capture the application data from network traffic—for example MySQL, HTTP, or FTP traffic.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
To see the actual application payload data in ASCII format, you can use the tt-C/tt command-line option to print out payloads with character data only (no hex). You must use this in conjunction with the tt-d/tt command-line option, which dumps the application layer:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -vdC'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
There are times when you may want to record all transactions related to a specific application. This may be for legal reasons, content checking, or usage monitoring. Another reason to log application data is to help application developers find bugs in network applications. By default, Snort displays only the header information of the packet. If you would like to see the actual payload data in ASCII format, you can use the tt-C/tt command-line option. You must use this in conjunction with the tt-d/tt command-line option, which dumps the application layer, as well as the tt-v/tt option:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -vdC'''nowiki&lt;br /&gt;
Running in packet dump mode&lt;br /&gt;
Log directory = log&lt;br /&gt;
   &lt;br /&gt;
Initializing Network Interface \Device\NPF_&lt;br /&gt;
{572FF0E6-9A1E-42B5-A2AF-A5A307B613EF}&lt;br /&gt;
   &lt;br /&gt;
        --=  = Initializing Snort =  =--&lt;br /&gt;
Initializing Output Plugins!&lt;br /&gt;
Decoding Ethernet on interface \Device\NPF_&lt;br /&gt;
{572FF0E6-9A1E-42B5-A2AF-A5A307B613EF}&lt;br /&gt;
   &lt;br /&gt;
        --=  = Initialization Complete =  =--&lt;br /&gt;
   &lt;br /&gt;
-* Snort! *-&lt;br /&gt;
Version 2.2.0-ODBC-MySQL-FlexRESP-WIN32 (Build 30)&lt;br /&gt;
By Martin Roesch (roesch@sourcefire.com, www.snort.org)&lt;br /&gt;
1.7-WIN32 Port By Michael Davis (mike@datanerds.net, &lt;br /&gt;
www.datanerds.net/~mike)&lt;br /&gt;
1.8 - 2.x WIN32 Port By Chris Reid &lt;br /&gt;
(chris.reid@codecraftconsultants.com)&lt;br /&gt;
   &lt;br /&gt;
11/01-12:15:26.305595 192.168.100.70:4435 - 216.239.51.147:80&lt;br /&gt;
TCP TTL:128 TOS:0x0 ID:50695 IpLen:20 DgmLen:323 DF&lt;br /&gt;
***AP*** Seq: 0x880283FF  Ack: 0xD0CF219E  Win: 0x4470  TcpLen: 20&lt;br /&gt;
GET / HTTP/1.1..Accept: */*..Accept-Language: en-us..Accept-Enco&lt;br /&gt;
ding: gzip, deflate..User-Agent: Mozilla/4.0 (compatible; MSIE 6&lt;br /&gt;
.0; Windows NT 5.0)..Host: www.google.com..Connection: Keep-Aliv&lt;br /&gt;
e..Cookie: PREF=ID=1c67539b15a71c3d:TM=1078849240:LM=1078849469:&lt;br /&gt;
TB=2:S=8BR7CQ3QdlExQhyo....&lt;br /&gt;
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+&lt;br /&gt;
   &lt;br /&gt;
11/01-12:15:26.341166 216.239.51.147:80 - 192.168.100.70:4435&lt;br /&gt;
TCP TTL:52 TOS:0x10 ID:34185 IpLen:20 DgmLen:1400&lt;br /&gt;
***AP*** Seq: 0xD0CF219E  Ack: 0x8802851A  Win: 0x7AE4  TcpLen: 20&lt;br /&gt;
HTTP/1.1 200 OK..Cache-Control: private..Content-Type: text/html&lt;br /&gt;
..Content-Encoding: gzip..Server: GWS/2.1..Content-Length: 1192.&lt;br /&gt;
.Date: Thu, 01 Jul 2004 16:14:53 GMT...............Vmo.6..._.([b&lt;br /&gt;
..h.q.....X....t-.a..Z:ID$.)+^....^...i.....{.w.....,. ..DA....&lt;br /&gt;
Z5.e.W..KaA..]+.H7.=...:.9.s........c/.,..D.Rf........kw.Y.d=..&lt;br /&gt;
.....oR49NY.......#.............'.p........'{.|...(......@;..5&lt;br /&gt;
W.?.dZ..r).I...D.U...S...80.ac.tzU...9L.Y.....C\...~2!..Wa..Y..&lt;br /&gt;
.l......4m..8.,...Q....1`lQ.YH...'$..0..\d.H.$iF(...'^f..8.(/Y..&lt;br /&gt;
.2.~.S...yx..%..g.......Iks.)...u.h..{...T...Rh...q...J.......&lt;br /&gt;
....!..)..\$..?B...&amp;quot;.........{'K%....VL.%.......bE...3...kH}4.&lt;br /&gt;
....o.z..pEk.Z..hP..a ..?N.......'o8r./.h..@a`..&amp;quot;........[iA._&lt;br /&gt;
...Sv....Yk.H\0c.e.8V..j......H..*....u...E./.F......$...6iB....&lt;br /&gt;
.M^`.........].....v...97....5D.(....#.L..@..@.ZV..@G..Dm...'.~.&lt;br /&gt;
..0.G0.n...P.$.{.u.'.0..........}.F..1J..S.lY......a...%...3:G..&lt;br /&gt;
f?v...p..U..'q.*K\..s.$ .6....H..6....`.....7.8tj^.H..%...5..l&lt;br /&gt;
.a6kU....4...M.(.....F.....V..rvP.....3r^.W...Y..........m..V.a&lt;br /&gt;
..SM.)KVL..|i.hK..m7...N7..=~.......t..3Oj.Ld....+e.+.w....l..&lt;br /&gt;
.Z..]..w...k.e....}...`H[7...4+..2[y.W.}G..+..c.`..j....e.Y..J&lt;br /&gt;
.....n.m.AE..?.......A...^.)........{..\.^.(m.4w........_......N&lt;br /&gt;
(.....P?.%=....9.j.-..@m.r..2[.)....s\z..~.bx.u...x.....K/..]A..&lt;br /&gt;
...4....u...woF....[=$q,.z~8.....]Q.29....F...G.^....D..EG..F..A&lt;br /&gt;
..._M.......^...&lt;br /&gt;
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+&lt;br /&gt;
   &lt;br /&gt;
11/01-12:15:26.373894 192.168.100.70:4435 - 216.239.51.147:80&lt;br /&gt;
TCP TTL:128 TOS:0x0 ID:50697 IpLen:20 DgmLen:421 DF&lt;br /&gt;
***AP*** Seq: 0x8802851A  Ack: 0xD0CF26EE  Win: 0x3F20  TcpLen: 20&lt;br /&gt;
GET /images/logo.gif HTTP/1.1..Accept: */*..Referer: http://www.&lt;br /&gt;
google.com/..Accept-Language: en-us..Accept-Encoding: gzip, defl&lt;br /&gt;
ate..If-Modified-Since: Mon, 22 Mar 2004 23:04:23 GMT..User-Agen&lt;br /&gt;
t: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)..Host: www&lt;br /&gt;
.google.com..Connection: Keep-Alive..Cookie: PREF=ID=1c67539b15a&lt;br /&gt;
71c3d:TM=1078849240:LM=1078849469:TB=2:S=8BR7CQ3QdlExQhyo....&lt;br /&gt;
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+/nowiki&lt;br /&gt;
&lt;br /&gt;
You can use the tt-C/tt and tt-d/tt command-line options in any of Snort's modes: packet dump, packet logger, and NIDS. Although Snort inspects the payload information, it doesn't print or log this information by default.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Capturing and Viewing Packets|Recipe 1.16]]&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Logging Packets That Snort Captures|Recipe 1.17]]&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Running Snort to Detect Intrusions|Recipe 1.18]]&lt;br /&gt;
&lt;br /&gt;
== Logging to the Windows Event Viewer ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to view your Snort alerts with the Windows Event Viewer.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Log your Snort alert messages to the Windows Event log by using the tt-E/tt command-line option:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -E -l C:\snort\log -c c:\snort\etc\snort.conf'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
The tt-E/tt command-line option is available only on Snort for Windows. However, this does make log viewing convenient by consolidating it into the same method as all other Windows events. You must use this command-line option when running Snort in NIDS mode so that alerts get properly generated in Windows Event log format. [[Snort Cookbook/Logging, Alerts, and Output Plug-ins#snortckbk-CHP-2-FIG-1|Figure 2-1]] shows what a Snort event looks like in the Event Viewer. You can see the details of the log entry by double-clicking on it, as shown in [[Snort Cookbook/Logging, Alerts, and Output Plug-ins#snortckbk-CHP-2-FIG-2|Figure 2-2]].&lt;br /&gt;
&lt;br /&gt;
div id=&amp;quot;snortckbk-CHP-2-FIG-1&amp;quot;&lt;br /&gt;
'''Figure 2-1. Event Viewer'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Snort Cookbook_I_2_tt194-web.png|Event Viewer]]&lt;br /&gt;
/div&lt;br /&gt;
&lt;br /&gt;
div id=&amp;quot;snortckbk-CHP-2-FIG-2&amp;quot;&lt;br /&gt;
'''Figure 2-2. Event Properties'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Snort Cookbook_I_2_tt195-web.png|Event Properties]]&lt;br /&gt;
/div&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Running Snort to Detect Intrusions|Recipe 1.18]]&lt;br /&gt;
&lt;br /&gt;
== Logging Alerts to a Database ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want your Snort alerts to be logged to a database.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Snort can log to a database by using the database output plug-ins in the ''snort.conf'' file. The following is the section of the ''snort.conf'' file where you must uncomment and configure the particular line for the database you are using:&lt;br /&gt;
&lt;br /&gt;
 # database: log to a variety of databases&lt;br /&gt;
 # ---------------------------------------&lt;br /&gt;
 # See the README.database file for more information about configuring&lt;br /&gt;
 # and using this plugin.&lt;br /&gt;
 #&lt;br /&gt;
 # output database: log, mysql, user=root password=test dbname=db &lt;br /&gt;
 # host=localhost&lt;br /&gt;
 # output database: alert, postgresql, user=snort dbname=snort&lt;br /&gt;
 # output database: log, odbc, user=snort dbname=snort&lt;br /&gt;
 # output database: log, mssql, dbname=snort user=snort password=test&lt;br /&gt;
 # output database: log, oracle, dbname=snort user=snort password=test&lt;br /&gt;
&lt;br /&gt;
You must run Snort in NIDS mode so that it uses the ''snort.conf'' file to invoke the output plug-in:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -c c:\snort\etc\snort.conf'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Currently, Snort has database output plug-ins for MySQL, PostgresSQL, unixODBC, Oracle, and MS-SQL Server. You must make sure that you have the appropriate parameters for the database configured including database type, username, password, and database name. You must also determine if you want to log both alerts and logs. If the database plug-in is configured for &amp;quot;alert,&amp;quot; it only logs output from alert rules. If it is configured for &amp;quot;log,&amp;quot; it logs both log and alert rules. You can log to multiple databases at once, including multiple instances of the same database, if desired. However, the more ways you log, the more load it places on the Snort engine and the CPU. Choose your hardware and operating system carefully when logging to multiple databases.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Logging, Alerts, and Output Plug-ins#Configuring MySQL for Snort|Recipe 2.12]]&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Logging, Alerts, and Output Plug-ins#Logging to Multiple Locations|Recipe 2.5]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Installing and Configuring MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to log to a MySQL database but don't have it installed.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Before you install MySQL, you must create a group and user for MySQL to run as:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''groupadd mysql'''&lt;br /&gt;
 [root@localhost root]# '''useradd -g mysql mysql'''&lt;br /&gt;
&lt;br /&gt;
Next, download MySQL (we saved it in the ''/root'' directory). Use the following commands to install and configure MySQL:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''cd /usr/loca'''l&lt;br /&gt;
 [root@localhost local]# '''tar zxvf''' &lt;br /&gt;
                '''/root/mysql-standard-4.0.20-pc-linux-i686.tar.gz'''&lt;br /&gt;
 [root@localhost local]# '''ln -s''' &lt;br /&gt;
                '''/usr/local/mysql-standard-4.0.20-pc-linux-i686/ mysql'''&lt;br /&gt;
 [root@localhost local]# '''cd mysql'''&lt;br /&gt;
 [root@localhost mysql]# '''scripts/mysql_install_db --user=mysql'''&lt;br /&gt;
 [root@localhost mysql]# '''chown -R root  .'''&lt;br /&gt;
 [root@localhost mysql]# '''chown -R mysql data'''&lt;br /&gt;
 [root@localhost mysql]# '''chgrp -R mysql .'''&lt;br /&gt;
&lt;br /&gt;
Next, to start the MySQL server, you can use the following command:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost mysql]# '''bin/mysqld_safe --user=mysql '''&lt;br /&gt;
&lt;br /&gt;
Finally, once MySQL is started, you must assign passwords to the local accounts for the database:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost mysql]# '''./bin/mysqladmin -u root password newpassword'''&lt;br /&gt;
 [root@localhost mysql]# '''./bin/mysqladmin -u root -h '''&lt;br /&gt;
                '''localhost.localdomain password newpassword'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
MySQL is a popular open source freeware database. Snort has built-in support for logging to a MySQL database. MySQL can be downloaded from the following site: . Be sure to download the latest production release for your platform, such as ''mysql-standard-4.x.yy-pc-linux-i686.tar.gz''.&lt;br /&gt;
&lt;br /&gt;
The MySQL installation creates a directory with a long name for the version of MySQL that you are installing in the ''/usr/local'' directory. It's easier to work with it if you create a symbolic link to it with the simple name ''mysql'', allowing you to refer to the directory as ''/usr/local/mysql''. The ''mysql_install_db'' script, located in the ''scripts'' subdirectory, initializes the database and creates the appropriate grant tables. Next you must change the ownership of the program binaries to root and the data directory to the user that MySQL runs as (which is ttmysql/tt, in this case). Once you start the MySQL server, you should see it listed in the process list by viewing it with ttps -aef/tt. After starting the server, you should assign passwords to the accounts that were created with the grant tables. You must use a stronger password than ''newpassword'', which we used in the example. Now that MySQL is officially installed and configured, you can access it by typing tt'''/usr/local/mysql/bin/mysql'''/tt.&lt;br /&gt;
&lt;br /&gt;
If you would like MySQL to start up automatically when you boot the system, you can add the following commands:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql'''&lt;br /&gt;
 [root@localhost root]# '''cd /etc/rc3.d'''&lt;br /&gt;
 [root@localhost rc3.d]# '''ln -s ../init.d/mysql S85mysql'''&lt;br /&gt;
 [root@localhost rc3.d]# '''ln -s ../init.d/mysql K85mysql'''&lt;br /&gt;
 [root@localhost rc3.d]# '''cd /etc/rc5.d'''&lt;br /&gt;
 [root@localhost rc5.d]# '''ln -s ../init.d/mysql S85mysql'''&lt;br /&gt;
 [root@localhost rc5.d]# '''ln -s ../init.d/mysql K85mysql'''&lt;br /&gt;
 [root@localhost rc5.d]# '''cd ../init.d'''&lt;br /&gt;
 [root@localhost init.d]# '''chmod 755 mysql'''&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Logging, Alerts, and Output Plug-ins#Configuring MySQL for Snort|Recipe 2.12]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''/usr/local/mysql/INSTALL-BINARY''&lt;br /&gt;
&lt;br /&gt;
== Configuring MySQL for Snort ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to use MySQL with Snort.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Install Snort with MySQL support with the following:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost snort-2.2.x]# '''./configure '''&lt;br /&gt;
                '''--with-mysql=/usr/local/mysql'''&lt;br /&gt;
 [root@localhost snort-2.2.x]# '''make'''&lt;br /&gt;
 [root@localhost snort-2.2.x]# '''make install'''&lt;br /&gt;
&lt;br /&gt;
Next, create the Snort database, set the password, and grant permissions:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''/usr/local/mysql/bin/mysql -u root -p'''&lt;br /&gt;
 Enter password:&lt;br /&gt;
 Welcome to the MySQL monitor.  Commands end with ; or \g.&lt;br /&gt;
 Your MySQL connection id is 4 to server version: 4.0.20-standard&lt;br /&gt;
  &lt;br /&gt;
 Type 'help;' or '\h' for help. Type '\c' to clear the buffer.&lt;br /&gt;
  &lt;br /&gt;
 mysql '''create database snort;'''&lt;br /&gt;
 Query OK, 1 row affected (0.07 sec)&lt;br /&gt;
    &lt;br /&gt;
 mysql '''SET PASSWORD FOR snort@localhost=PASSWORD('password');'''&lt;br /&gt;
 Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;
  &lt;br /&gt;
 mysql '''grant CREATE,INSERT,SELECT,DELETE,UPDATE on snort.* to '''&lt;br /&gt;
                '''snort@localhost;'''&lt;br /&gt;
 Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;
    &lt;br /&gt;
 mysql '''grant CREATE,INSERT,SELECT,DELETE,UPDATE on snort.* to snort;'''&lt;br /&gt;
 Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;
    &lt;br /&gt;
 mysql '''exit'''&lt;br /&gt;
&lt;br /&gt;
Next, run the Snort ''create_mysql'' script and ''snortdb-extra.gz'' to generate the appropriate tables in the database:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''cd snort-2.2.x'''&lt;br /&gt;
 [root@localhost snort-2.2.x]# '''/usr/local/mysql/bin/mysql -u root -p  ./contrib/create_mysql snort'''&lt;br /&gt;
 Enter password:&lt;br /&gt;
 [root@localhost snort-2.2.x]# '''cd contrib'''&lt;br /&gt;
 [root@localhost contrib]# '''zcat snortdb-extra.gz | '''&lt;br /&gt;
                '''/usr/local/mysql/bin/mysql -p snort'''&lt;br /&gt;
 Enter password:&lt;br /&gt;
&lt;br /&gt;
Finally, add a line in the ''snort.conf'' file to use the database output plug-in, making sure you configure it with the right parameters for your database:&lt;br /&gt;
&lt;br /&gt;
 output database: log, mysql, user=snort password=password dbname=snort host=localhost&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Once you have MySQL installed and configured, you must make the necessary Snort configurations. First, when you install Snort, you need to install it with MySQL support. There are quite a few things you must do when configuring Snort to interact with MySQL. Once you have followed the preceding steps, you can use the following commands to check that the Snort database was created correctly. First, log into MySQL using the following command and supply the password that you previously created:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost contrib]# '''/usr/local/mysql/bin/mysql -p'''&lt;br /&gt;
 Enter password:&lt;br /&gt;
 Welcome to the MySQL monitor.  Commands end with ; or \g.&lt;br /&gt;
 Your MySQL connection id is 7 to server version: 4.0.20-standard&lt;br /&gt;
  &lt;br /&gt;
 Type 'help;' or '\h' for help. Type '\c' to clear the buffer.&lt;br /&gt;
&lt;br /&gt;
The following command will show the current MySQL databases; make sure that your newly created Snort database is listed:&lt;br /&gt;
&lt;br /&gt;
 mysql '''show databases;'''&lt;br /&gt;
 +----------+&lt;br /&gt;
 | Database |&lt;br /&gt;
 +----------+&lt;br /&gt;
 | mysql    |&lt;br /&gt;
 | snort    |&lt;br /&gt;
 | test     |&lt;br /&gt;
 +----------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
The following commands will select the Snort database as the current database and then show the existing Snort tables:&lt;br /&gt;
&lt;br /&gt;
 mysql '''use snort;'''&lt;br /&gt;
 Reading table information for completion of table and column names&lt;br /&gt;
 You can turn off this feature to get a quicker startup with -A&lt;br /&gt;
  &lt;br /&gt;
 Database changed&lt;br /&gt;
 mysql '''show tables;'''&lt;br /&gt;
 +------------------+&lt;br /&gt;
 | Tables_in_snort  |&lt;br /&gt;
 +------------------+&lt;br /&gt;
 | data             |&lt;br /&gt;
 | detail           |&lt;br /&gt;
 | encoding         |&lt;br /&gt;
 | event            |&lt;br /&gt;
 | flags            |&lt;br /&gt;
 | icmphdr          |&lt;br /&gt;
 | iphdr            |&lt;br /&gt;
 | opt              |&lt;br /&gt;
 | protocols        |&lt;br /&gt;
 | reference        |&lt;br /&gt;
 | reference_system |&lt;br /&gt;
 | schema           |&lt;br /&gt;
 | sensor           |&lt;br /&gt;
 | services         |&lt;br /&gt;
 | sig_class        |&lt;br /&gt;
 | sig_reference    |&lt;br /&gt;
 | signature        |&lt;br /&gt;
 | tcphdr           |&lt;br /&gt;
 | udphdr           |&lt;br /&gt;
 +------------------+&lt;br /&gt;
 19 rows in set (0.00 sec)&lt;br /&gt;
    &lt;br /&gt;
 mysql '''exit'''&lt;br /&gt;
&lt;br /&gt;
Next, you can run some traffic that creates events—such as an Nmap scan—and check the database to make sure the events are logged:&lt;br /&gt;
&lt;br /&gt;
 mysql '''select * from event;'''&lt;br /&gt;
 +-----+-----+-----------+---------------------+&lt;br /&gt;
 | sid | cid | signature | timestamp           |&lt;br /&gt;
 +-----+-----+-----------+---------------------+&lt;br /&gt;
 |   1 |   1 |         1 | 2004-11-06 03:24:51 |&lt;br /&gt;
 |   1 |   2 |         1 | 2004-11-06 03:24:57 |&lt;br /&gt;
 |   1 |   3 |         2 | 2004-11-06 03:32:41 |&lt;br /&gt;
 |   1 |   4 |         2 | 2004-11-06 03:32:47 |&lt;br /&gt;
 |   1 |   5 |         3 | 2004-11-06 03:33:29 |&lt;br /&gt;
 |   1 |   6 |         3 | 2004-11-06 03:33:35 |&lt;br /&gt;
 |   1 |   7 |         4 | 2004-11-06 03:33:41 |&lt;br /&gt;
 |   1 |   8 |         4 | 2004-11-06 03:33:47 |&lt;br /&gt;
 |   1 |   9 |         5 | 2004-11-06 03:34:53 |&lt;br /&gt;
 |   1 |  10 |         5 | 2004-11-06 03:34:59 |&lt;br /&gt;
 |   1 |  11 |         6 | 2004-11-06 03:35:05 |&lt;br /&gt;
 |   1 |  12 |         6 | 2004-11-06 03:35:11 |&lt;br /&gt;
 |   1 |  13 |         7 | 2004-11-06 03:35:17 |&lt;br /&gt;
 |   1 |  14 |         7 | 2004-11-06 03:35:23 |&lt;br /&gt;
 |   1 |  15 |         7 | 2004-11-06 03:37:42 |&lt;br /&gt;
 +-----+-----+-----------+---------------------+&lt;br /&gt;
 15 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Logging, Alerts, and Output Plug-ins#Installing and Configuring MySQL|Recipe 2.11]]&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Installing Snort Binaries on Linux|Recipe 1.2]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using PostgreSQL with Snort and ACID ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to use Snort to log into a PostgreSQL database.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Setting up Snort to log to a PostgreSQL database is similar to how you'd set up MySQL. However, there are several different steps that have to be accomplished to get Snort to log there. For simplicity, we will set up Snort to use PostgreSQL as the database for an ACID web frontend, and we'll compile from PostgreSQL source to tweak our database.&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
The following steps enable a PostgreSQL database and Snort support.&lt;br /&gt;
&lt;br /&gt;
Download the database source from . Then, place the source file ''postgresql-7.4.5.tar.gz'' in a temp directory such as ''/tmp'' to compile:&lt;br /&gt;
&lt;br /&gt;
 root# '''pwd''' &lt;br /&gt;
 /tmp &lt;br /&gt;
 root# '''ls''' &lt;br /&gt;
 postgresql-7.4.5.tar.gz &lt;br /&gt;
 root# '''tar xvfz postgresql-7.4.5.tar.gz''' &lt;br /&gt;
 root# '''cd postgresql-7.4.5'''&lt;br /&gt;
 root# '''./configure OPTIONAL: SET HOME''' &lt;br /&gt;
                '''DIR:--prefix=/usr/local/postgres ; make; make install'''&lt;br /&gt;
&lt;br /&gt;
Create a user account to run as:&lt;br /&gt;
&lt;br /&gt;
 # Linux systems &lt;br /&gt;
 '''useradd postgres''' &lt;br /&gt;
 # BSD systems &lt;br /&gt;
 '''echo &amp;quot;postgres;;;;;;;;;no&amp;quot; | adduser -w - -f &amp;quot;no&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
Next, install the database using the optional tt--with-openssl/tt configure option, if you are considering encrypting your Snort-to-database connections:&lt;br /&gt;
&lt;br /&gt;
 root# '''./configure [--with-openssl]''' &lt;br /&gt;
 root# '''make; make install''' &lt;br /&gt;
 # Running make install places the database into the default directory &lt;br /&gt;
 # of &amp;quot;/usr/local/pgsql&amp;quot; with subdirectories.&lt;br /&gt;
&lt;br /&gt;
Make a data directory in which to hold the databases:&lt;br /&gt;
&lt;br /&gt;
 root# '''mkdir /usr/local/pgsql/data'''&lt;br /&gt;
 root# '''chown -R postgres /usr/local/pgsql/data'''&lt;br /&gt;
&lt;br /&gt;
Start the new PostgreSQL database:&lt;br /&gt;
&lt;br /&gt;
 root# '''su - postgres''' &lt;br /&gt;
 postgres$ '''/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data''' &lt;br /&gt;
 postgres$ '''/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data '''&lt;br /&gt;
&lt;br /&gt;
To have the PostgreSQL database start automatically when you boot the system, try the following example script. Thanks go to the postgresql.org archives for this example:&lt;br /&gt;
&lt;br /&gt;
 ##!/bin/sh&lt;br /&gt;
    &lt;br /&gt;
 ## Start postgres at boot time script&lt;br /&gt;
 # from postgresql.org site&lt;br /&gt;
 #&lt;br /&gt;
 ########&lt;br /&gt;
    &lt;br /&gt;
 # INSTALLATION Prefix&lt;br /&gt;
 prefix=/usr/local/pgsql&lt;br /&gt;
    &lt;br /&gt;
 # Data directory&lt;br /&gt;
 PGDATA=&amp;quot;/usr/local/pgsql/data&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
 # Who to run as&lt;br /&gt;
 PGUSER=postgres&lt;br /&gt;
    &lt;br /&gt;
 # Where to keep a log file&lt;br /&gt;
 PGLOG=&amp;quot;$PGDATA/serverlog&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
 # Path for the script to use&lt;br /&gt;
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/bin:/usr/sbin&lt;br /&gt;
    &lt;br /&gt;
 # What to use to start the postmaster&lt;br /&gt;
 DAEMON=&amp;quot;$prefix/bin/pg_ctl&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
 test -x &amp;quot;$DAEMON&amp;quot; || exit 0&lt;br /&gt;
    &lt;br /&gt;
 case $1 in&lt;br /&gt;
         start)&lt;br /&gt;
         su  $PGUSER -c &amp;quot;$DAEMON start -D $PGDATA -s $PGLOG&amp;quot;&lt;br /&gt;
         echo -n ' postgresql'&lt;br /&gt;
         ;;&lt;br /&gt;
         stop)&lt;br /&gt;
         su  $PGUSER -c &amp;quot;$DAEMON stop -D $PGDATA -s -m fast&amp;quot;&lt;br /&gt;
         ;;&lt;br /&gt;
         restart)&lt;br /&gt;
         su  $PGUSER -c &amp;quot;$DAEMON restart -D $PGDATA -s -m fast&amp;quot;&lt;br /&gt;
         ;;&lt;br /&gt;
         status)&lt;br /&gt;
         su  $PGUSER -c &amp;quot;$DAEMON status -D $PGDATA&amp;quot;&lt;br /&gt;
         ;;&lt;br /&gt;
         *)&lt;br /&gt;
         # PRINT HELP&lt;br /&gt;
         echo &amp;quot;Usage: `basename $0` (start|stop|restart|status)&amp;quot; 12&lt;br /&gt;
         exit 1&lt;br /&gt;
         ;;&lt;br /&gt;
 esac&lt;br /&gt;
&lt;br /&gt;
Next, since the new PostgreSQL instance has no databases or users, you must create them.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL has a much different look and feel to it if you are coming from a MySQL background. If you are uncomfortable running some of these commands from a console, try using a GUI application such as phpPgAdmin (available at ) for ease of use and management. However, for the brave, read on to find out how to create a PostgreSQL database, user account, and grants for a user.&lt;br /&gt;
&lt;br /&gt;
Create the database for Snort to log to:&lt;br /&gt;
&lt;br /&gt;
 root# '''/usr/local/pgsql/bin/createdb -U postgres acidpg''' &lt;br /&gt;
 # IF YOU ARE RUNNNG AS user 'postgres' you don't need the &lt;br /&gt;
 # &amp;quot;-U postgres&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Next, create the two user accounts: sensor(s) (ttsnortpguser/tt) and web interface(s) (ttwebpguser/tt):&lt;br /&gt;
&lt;br /&gt;
 root#'''/usr/local/pgsql/bin/createuser -U postgres -A -'''D &lt;br /&gt;
 '''-P set password snortpguser '''&lt;br /&gt;
 root#'''/usr/local/pgsql/bin/createuser -U postgres -A -D -P '''&lt;br /&gt;
                '''set password webpguser'''&lt;br /&gt;
&lt;br /&gt;
Next, import the correct database schema (ttstructure/tt) for Snort to use:&lt;br /&gt;
&lt;br /&gt;
 root# '''cat /tmp/snort-2.2.x/contrib/create_postgresql |'''&lt;br /&gt;
                '''/usr/local/pgsql/bin/psql -U postgres -d acidpg '''&lt;br /&gt;
 root# '''gunzip /tmp/snort-2.2.x/contrib/snortdb-extra.gz''' &lt;br /&gt;
 root# '''cat /tmp/snort-2.2.x/contrib/snortdb-extra |'''&lt;br /&gt;
                '''/usr/local/pgsql/bin/psql -U postgres -d acidpg'''&lt;br /&gt;
&lt;br /&gt;
Grant the two user accounts permissions on the database:&lt;br /&gt;
&lt;br /&gt;
 root#'''/usr/local/pgsql/bin/psql -U postgres -D acidpg '''&lt;br /&gt;
 acidpg=# '''GRANT ALL PRIVILEGES ON DATABASE acidpg TO webpguser;''' &lt;br /&gt;
 acidpg=#''' GRANT ALL PRIVILEGES ON DATABASE acidpg TO snortpguser;'''&lt;br /&gt;
&lt;br /&gt;
div class=&amp;quot;tip&amp;quot;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
You can have more than two accounts if you want every sensor to have a unique account to log in with.&lt;br /&gt;
/div&lt;br /&gt;
&lt;br /&gt;
If you want to restrict what the sensor accounts have access to, try pasting the following example into the PostgreSQL prompt in place of the ttALL PRIVILEGES/tt line:&lt;br /&gt;
&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON sensor to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON sensor_sid_seq to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON data to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON detail to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON encoding to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON event to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON flags to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON icmphdr to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON iphdr to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON opt to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON protocols to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON reference to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON reference_ref_id_seq to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON reference_system to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON reference_system_ref_system_id_seq to &lt;br /&gt;
  snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON schema to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON services to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON sig_class to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON sig_class_sig_class_id_seq to &lt;br /&gt;
  snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON sig_reference to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON signature to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON signature_sig_id_seq to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON tcphdr to snortpguser;&lt;br /&gt;
  GRANT UPDATE,SELECT,INSERT ON udphdr to snortpguser;&lt;br /&gt;
&lt;br /&gt;
If you are already trying to connect to the database with one or both of the accounts and get errors such as:&lt;br /&gt;
&lt;br /&gt;
 ERROR: Relation `table_name' does not exist&lt;br /&gt;
&lt;br /&gt;
then for some reason, one of the Snort database tables didn't apply all the correct privileges to that table. You can try to correct this by either adjusting the single table manually with one of the previous commands or pasting in the 24-line ttGRANT/tt statement in the previous code.&lt;br /&gt;
&lt;br /&gt;
ACID needs to add several additional tables to the PostgreSQL database to function properly. Unfortunately, the PostgreSQL language has changed since the original ACID code was written, so there is a small name change that must be implemented.&lt;br /&gt;
&lt;br /&gt;
As of PostgreSQL 7.4x, the function ttDATETIME/tt is now called ttTIMESTAMP/tt. This means you need to change the files found in the ACID directory that have to do with PostgreSQL (''.sql'' files) and the ACID ''.html'' and ''.php'' files. This actually only involves editing the following three files, replacing each occurrence of ttDATETIME/tt with ttTIMESTAMP/tt:&lt;br /&gt;
&lt;br /&gt;
* ''Create_acid_tbls_psql.sql''&lt;br /&gt;
* ''Create_acid_tbls_pgsql_extra.sql''&lt;br /&gt;
* ''Acid_db_setup.php''&lt;br /&gt;
&lt;br /&gt;
Also, before you begin trying to set up PostgreSQL ACID, remember to check that your Apache server is compiled with PostgreSQL support. Apache should be configured using a command line similar to the following:&lt;br /&gt;
&lt;br /&gt;
 # ./configure --with-pgsql --with-your-other-options&lt;br /&gt;
&lt;br /&gt;
Next, edit the file ''acid_conf.php'' with your database account:&lt;br /&gt;
&lt;br /&gt;
 $alert_dbname = &amp;quot;acidpg&amp;quot;;&lt;br /&gt;
 $alert_host = &amp;quot;localhost&amp;quot;;&lt;br /&gt;
 $alert_port = &amp;quot;5432&amp;quot;;&lt;br /&gt;
 $alert_user = &amp;quot;webpguser&amp;quot;;&lt;br /&gt;
 $alert_password = &amp;quot;webpass&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Next, set up the ACID schema through the ACID main page ''acid_main.php'' in a browser. This will redirect you to the ''acid_db_setup.php'' page to create the extra tables that ACID needs. If you get errors, check privileges in the database and try again.&lt;br /&gt;
&lt;br /&gt;
If you got no errors with the database or ACID, then set up Snort to log to the database by editing your ''snort.conf'' file such as:&lt;br /&gt;
&lt;br /&gt;
 output database: log, postgresql, user=snortpguser, &lt;br /&gt;
 password=snortpass, dbname=acidpg host=localhost&lt;br /&gt;
&lt;br /&gt;
If you are going to use more than one sensor, it's a good idea to use the ttsensor_name/tt parameter, as in this example:&lt;br /&gt;
&lt;br /&gt;
 output database: log, postgresql, user=snortpguser, &lt;br /&gt;
 password=snortpass, dbname=acidpg host=localhost &lt;br /&gt;
 sensor_name=oreilly_test&lt;br /&gt;
&lt;br /&gt;
Lastly, download and compile Snort from source again. First, extract the Snort source code:&lt;br /&gt;
&lt;br /&gt;
 root# '''ls''' &lt;br /&gt;
 snort-2.2.x.tar.gz&lt;br /&gt;
 root# '''tar xvfz snort-2.2.x.tar.gz''' &lt;br /&gt;
 root# '''cd snort-2.2.x'''&lt;br /&gt;
&lt;br /&gt;
Compile Snort to use your PostgreSQL database:&lt;br /&gt;
&lt;br /&gt;
 root# '''./configure --with-postgresql=/usr/local/pgsql (other options)''' &lt;br /&gt;
 root# '''make''' &lt;br /&gt;
 # WARNING! &lt;br /&gt;
 # YOU MAY HAVE TO PLACE THE FILE &amp;quot;libpq.so.3&amp;quot; in your /lib directory&lt;br /&gt;
 # in order for snort to work.&lt;br /&gt;
&lt;br /&gt;
The last part of the build is testing. Run Snort with the tt-T/tt option to make sure everything is working (see [[Snort Cookbook/Rules and Signatures#Testing Rules|Recipe 3.12]]). If no errors occur, restart Snort. You're now running Snort logging to a PostgreSQL database with an ACID frontend.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
PostgreSQL home ()&lt;br /&gt;
&lt;br /&gt;
Quick, local-only Snort/PostgreSQL setup ()&lt;br /&gt;
&lt;br /&gt;
== Logging in PCAP Format (TCPDump) ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to log your Snort data in PCAP format (TCPDump).&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
The Snort ttlog_tcpdump/tt output plug-in allows you to log and store data in PCAP format. Configure the ''snort.conf'' file with the name of the TCPDump logfile to use:&lt;br /&gt;
&lt;br /&gt;
 # log_tcpdump: log packets in binary tcpdump format&lt;br /&gt;
 # -------------------------------------------------&lt;br /&gt;
 # The only argument is the output file name.&lt;br /&gt;
 #&lt;br /&gt;
 output log_tcpdump: tcpdump.log&lt;br /&gt;
&lt;br /&gt;
Run Snort in NIDS mode so that it uses the ''snort.conf''file to invoke the output plug-in:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -c c:\snort\etc\snort.conf'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Snort's network architecture is based on the Packet Capture Library (PCAP) and uses libpcap for its underlying data capture. Many network analysis engines, sniffers, and statistics tools can read data in the PCAP format. You can use the ttlog_tcpdump/tt output plug-in to save the data and then view it with tools such as TCPDump and Ethereal.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Logging to Email ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to send your Snort logs to email.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
First, configure ''snort.conf'' to log alerts to syslog:&lt;br /&gt;
&lt;br /&gt;
 # alert_syslog: log alerts to syslog&lt;br /&gt;
 # ----------------------------------&lt;br /&gt;
 # Use one or more syslog facilities as arguments.  Win32 can also&lt;br /&gt;
 # optionally specify a particular hostname/port.  Under Win32, the&lt;br /&gt;
 # default hostname is '127.0.0.1', and the default port is 514.&lt;br /&gt;
 #&lt;br /&gt;
 # [Unix flavours should use this format...]&lt;br /&gt;
  output alert_syslog: LOG_AUTH LOG_ALERT&lt;br /&gt;
 #&lt;br /&gt;
 # [Win32 can use any of these formats...]&lt;br /&gt;
 # output alert_syslog: LOG_AUTH LOG_ALERT&lt;br /&gt;
 # output alert_syslog: host=hostname, LOG_AUTH LOG_ALERT&lt;br /&gt;
 # output alert_syslog: host=hostname:port, LOG_AUTH LOG_ALERT&lt;br /&gt;
&lt;br /&gt;
Snort sends alerts to the syslog file with the ttsnort/tt: prefix. Edit ''/.swatchrc'' to send an email when a Snort event is added to the syslog:&lt;br /&gt;
&lt;br /&gt;
 watchfor /snort:/&lt;br /&gt;
 mail security@company.com,subject=Snort Alert!&lt;br /&gt;
&lt;br /&gt;
Next, make sure you run Swatch to watch for syslog messages in ''/var/log/messages'' (some distributions use ''/var/log/syslog''):&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''swatch -t /var/log/messages'''&lt;br /&gt;
&lt;br /&gt;
Lastly, run Snort in NIDS mode to use the ''snort.conf'' file to invoke the syslog output plug-in:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost snort-2.2.x]# '''snort -l /var/log/snort -c '''&lt;br /&gt;
                '''./etc/snort.conf'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
The easiest way to receive Snort alerts via email is to configure Swatch (available at ) to monitor syslog and send an email when a Snort event is produced. Swatch is a log-monitoring utility that can filter messages from logfiles to display or log elsewhere. Syslog messages are one line, whereas Snort alert files are multiple lines and often produce a separate email for each line. Swatch uses sendmail, the default mail server on most Unix platforms, to send the email alerts. You must have sendmail configured and running on your syslog system to send emails.&lt;br /&gt;
&lt;br /&gt;
Configuring an outbound-only sendmail server is a simple matter of disabling the port 25/tcp listener. This prevents an internal attack from compromising your syslog server through a sendmail vulnerability.&lt;br /&gt;
&lt;br /&gt;
On Red Hat platforms, simply edit the file ''/etc/sysconfig/sendmail'' and change the line ttDAEMON=yes/tt to ttDAEMON=no/tt.&lt;br /&gt;
&lt;br /&gt;
On BSD platforms or custom sendmail configurations, use the following command:&lt;br /&gt;
&lt;br /&gt;
 sendmail -q 5&lt;br /&gt;
&lt;br /&gt;
This runs sendmail without a daemon listener and pushes out mail in five minute intervals (tt-q/tt tt5/tt). All mail that's located on the machine (your syslog server) will be sent out in five minute intervals without leaving a port open for internal attack.&lt;br /&gt;
&lt;br /&gt;
One point to remember is that if configured incorrectly, logging IDS alerts to email can quickly create a denial of service on your mail server.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Running Snort to Detect Intrusions|Recipe 1.18]]&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Administrative Tools#Installing and Configuring Swatch|Recipe 5.8]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Logging to a Pager or Cell Phone ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to send your Snort logs to a pager or cell phone.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
First, configure the ''snort.conf'' to log alerts to syslog:&lt;br /&gt;
&lt;br /&gt;
 # alert_syslog: log alerts to syslog&lt;br /&gt;
 # ----------------------------------&lt;br /&gt;
 # Use one or more syslog facilities as arguments.  Win32 can also&lt;br /&gt;
 # optionally specify a particular hostname/port.  Under Win32, the&lt;br /&gt;
 # default hostname is '127.0.0.1', and the default port is 514.&lt;br /&gt;
 #&lt;br /&gt;
 # [Unix flavours should use this format...]&lt;br /&gt;
  output alert_syslog: LOG_AUTH LOG_ALERT&lt;br /&gt;
 #&lt;br /&gt;
 # [Win32 can use any of these formats...]&lt;br /&gt;
 # output alert_syslog: LOG_AUTH LOG_ALERT&lt;br /&gt;
 # output alert_syslog: host=hostname, LOG_AUTH LOG_ALERT&lt;br /&gt;
 # output alert_syslog: host=hostname:port, LOG_AUTH LOG_ALERT&lt;br /&gt;
&lt;br /&gt;
Snort sends alerts to the syslog file with the ''snort:'' prefix. Use Swatch again to filter the log messages. Then edit ''/.swatchrc'' to send a page when a Snort event is added to the syslog:&lt;br /&gt;
&lt;br /&gt;
 watchfor /snort:/&lt;br /&gt;
 exec /usr/local/bin/qpage -p Security_Admin `$0'&lt;br /&gt;
&lt;br /&gt;
This sends a page to the number that is configured for ttSecurity_Admin/tt. The tt$0/tt parameter includes the entire Snort alert as input to the ttqpage/tt command. Next, make sure you run Swatch to watch for syslog messages in ''/var/log/messages'':&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''swatch -t /var/log/messages'''&lt;br /&gt;
&lt;br /&gt;
Lastly, run Snort in NIDS mode to use the ''snort.conf'' file to invoke the syslog output plug-in:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost snort-2.2.x]# '''snort -l /var/log/snort -c '''&lt;br /&gt;
                '''./etc/snort.conf'''&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
The best way to receive Snort alerts on a pager or cell phone is to use a third-party package, such as QuickPage. QuickPage is a free, Unix-compatible client/server software package that can send messages to an alphanumeric pager. You must configure Swatch to monitor alerts, and then use the ''exec'' command in the ''/.swatchrc'' file to initiate the paging program.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Administrative Tools#Installing and Configuring Swatch|Recipe 5.8]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Optimizing Logging ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to optimize your logging.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
To log in binary format, you must use the tt-b/tt command-line option in conjunction with the tt-l/tt option:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -b'''&lt;br /&gt;
&lt;br /&gt;
You can also specify a name for the logfile by using the -L tt''filename''/tt option:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -b -L test'''&lt;br /&gt;
&lt;br /&gt;
If you are running Snort in NIDS mode, you can also perform binary logging by configuring the ttlog_tcpdump/tt output plug-in in the ''/etc/snort.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 output log_tcpdump: tcpdump.log&lt;br /&gt;
&lt;br /&gt;
You can also use the unified output plug-in in the ''/etc/snort.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 output alert_unified: filename snort.alert, limit 128&lt;br /&gt;
 output log_unified: filename snort.log, limit 128&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Two methods can be used to optimize Snort logging: binary logging and unified logging.&lt;br /&gt;
&lt;br /&gt;
To log in binary format you must use the tt-b/tt command-line option in conjunction with the tt-l/tt option. The tt-b/tt option specifies to log the packets in binary format. You won't see any data output on the screen when you are logging in binary format, unless you also use the tt-v/tt command-line option. You don't need to specify the tt-d/tt or tt-e/tt command-line options, because by default, the binary option logs the entire packet.&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -b'''&lt;br /&gt;
&lt;br /&gt;
This command creates a file called ''snort.log.1084553605'' in the ''C:\Snort\log'' directory. You can also specify a name for the logfile by using the -L tt''filename''/tt option.&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin'''snort -l c:\snort\log -b -L test'''&lt;br /&gt;
&lt;br /&gt;
div class=&amp;quot;tip&amp;quot;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
The numbers assigned to ''snort.log.xxx'' or ''filename.yyy'' are known as Epoch time; this is the number of seconds since 01-01-1970.&lt;br /&gt;
/div&lt;br /&gt;
&lt;br /&gt;
This command creates a file called ''test.1084554709'' in the ''C:\Snort\log'' directory. If you are running Snort in NIDS mode, you can also perform binary logging by uncommenting the following line from the ''/etc/snort.conf'' file:&lt;br /&gt;
&lt;br /&gt;
 # log_tcpdump: log packets in binary tcpdump format&lt;br /&gt;
 # -------------------------------------------------&lt;br /&gt;
 # The only argument is the output file name.&lt;br /&gt;
 #&lt;br /&gt;
 output log_tcpdump: tcpdump.log&lt;br /&gt;
&lt;br /&gt;
The following command runs Snort in NIDS mode and creates a binary file with the name ''tcpdump.log.number'', such as ''tcpdump.log.1086466896'', in the ''C:\Snort\log'' directory:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin '''snort -l c:\snort\log -c c:\snort\etc\snort.conf'''&lt;br /&gt;
&lt;br /&gt;
Unified logging also logs in binary format; however, it uses a Snort output plug-in to reduce the load on the Snort processing engine. To enable unified logging, you must make a change to the ''/etc/snort.conf'' file by uncommenting and configuring the following output plug-ins:&lt;br /&gt;
&lt;br /&gt;
 # unified: Snort unified binary format alerting and logging&lt;br /&gt;
 # -------------------------------------------------------------&lt;br /&gt;
 # The unified output plugin provides two new formats for logging and&lt;br /&gt;
 # generating alerts from Snort, the &amp;quot;unified&amp;quot; format.  The unified&lt;br /&gt;
 # format is a straight binary format for logging data out of Snort&lt;br /&gt;
 # that is designed to be fast and efficient.  Used with barnyard (the&lt;br /&gt;
 # new alert/log processor), most of the overhead for logging and&lt;br /&gt;
 # alerting to various slow storage mechanisms such as databases or the&lt;br /&gt;
 # network can now be avoided.&lt;br /&gt;
 #&lt;br /&gt;
 # Check out the spo_unified.h file for the data formats.&lt;br /&gt;
 #&lt;br /&gt;
 # Two arguments are supported.&lt;br /&gt;
 #    filename - base filename to write to (current time_t is appended)&lt;br /&gt;
 #    limit    - maximum size of spool file in MB (default: 128)&lt;br /&gt;
 #&lt;br /&gt;
 output alert_unified: filename snort.alert, limit 128&lt;br /&gt;
 output log_unified: filename snort.log, limit 128&lt;br /&gt;
&lt;br /&gt;
Both the ttfilename/tt and ttfile size limit/tt parameters are configurable. Unified logs have a varying number assigned to them after the ''.alert'' and ''.log'' filename extensions. In our example, running Snort with the following command-line options created the unified logging files ''snort.alert.1086463191'' and ''snort.log.1086463191'' in the ''C:\Snort\log'' directory:&lt;br /&gt;
&lt;br /&gt;
 C:\Snort\bin '''snort -l c:\snort\log -c c:\snort\etc\snort.conf'''&lt;br /&gt;
&lt;br /&gt;
The best way to optimize Snort logging is to use unified logging with a separate log-processing tool such as Barnyard. Binary logging makes logging more efficient because the Snort engine doesn't have to translate the data into human-readable format. Logging traffic in binary mode is great for high-speed networks and compact storage. Binary files can then be reviewed later using Snort, TCPDump, Ethereal, or other binary log-compatible programs. If you are using Snort on a very high-speed network, such as 1 Gbps or greater, you benefit more from unified logging. This allows the Snort engine to write logs and alerts quickly to a binary file, while offloading the spooling and processing to another program. Offloading the processing of logs and alerts means Snort can spend more time capturing data, thus decreasing the likelihood that packets are dropped. You must use a unified log reader, such as Barnyard, to process the logfiles.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Administrative Tools#Installing and Configuring Barnyard|Recipe 5.9]]&lt;br /&gt;
&lt;br /&gt;
== Reading Unified Logged Data ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to process your unified output files.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Download Barnyard from  and then install it with the following commands:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''tar zxvf barnyard-0.2.0.tar.gz'''&lt;br /&gt;
 [root@localhost barnyard-0.2.0]# '''cd barnyard-0.2.0'''&lt;br /&gt;
 [root@localhost barnyard-0.2.0]# '''./configure'''&lt;br /&gt;
 [root@localhost barnyard-0.2.0]# '''make'''&lt;br /&gt;
 [root@localhost barnyard-0.2.0]# '''make install'''&lt;br /&gt;
&lt;br /&gt;
If you already have Snort configured to output unified logs, you can test Barnyard with the following:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''barnyard -o /var/log/snort/*'''&lt;br /&gt;
&lt;br /&gt;
This creates the human-readable ''dump.log'' and ''fast.alert'' files in your current directory.&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Barnyard processes unified and binary Snort output files. By offloading the log processing to a tool like Barnyard, Snort can concentrate on what it does best: capturing network traffic and detecting intrusions. Barnyard has several output plug-ins. Some mimic the functionality already built into Snort, such as fast alerts, ASCII packet dumps, syslog, and pcap. It also offers new plug-ins such as CSV output, advanced syslog output, ACID, and SQUIL support. Barnyard also has database support, such as MySQL. However, it must be installed with the appropriate configure switch, such as tt--enable-mysql/tt, to enable this support. This allows Barnyard to process unified output files and log the data to a database.&lt;br /&gt;
&lt;br /&gt;
If you do not have all the necessary configuration files in their default locations, you may have to run the command with more parameters, such as in the following:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''barnyard -c '''&lt;br /&gt;
                '''/root/barnyard-0.2.0/etc/barnyard.conf -o /var/log/snort/* -s '''&lt;br /&gt;
                '''/root/snort-2.2.x/etc/sid-msg.map -g /root/snort-2.2.x/etc/gen-msg.map '''&lt;br /&gt;
                '''-p /root/snort-2.2.x/etc/classification.config'''&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Logging, Alerts, and Output Plug-ins#Optimizing Logging|Recipe 2.17]]&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Logging, Alerts, and Output Plug-ins#Installing and Configuring MySQL|Recipe 2.11]]&lt;br /&gt;
&lt;br /&gt;
== Generating Real-Time Alerts ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to get real-time Snort alerts.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use Pig Sentry to monitor Snort output and generate alerts:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''tail -f /var/log/snort/alert | perl '''&lt;br /&gt;
                '''pigsentry-1.2'''&lt;br /&gt;
 [Sun Nov  7 14:40:38 2004] alert: New event: ICMP PING NMAP&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Pig Sentry is a lightweight Perl script that executes against the Snort alert log. It was written to handle a large volume of alert data in real time. Pig Sentry maintains a state table of recent alerts so it can alert on new events or alert of changes in trends or patterns of events.&lt;br /&gt;
&lt;br /&gt;
Download the latest version of Pig Sentry from  or . The following example shows how to run Pig Sentry, assuming you're already running Snort in NIDS mode and logging alerts to ''/var/log/snort'':&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''tail -f /var/log/snort/alert | perl '''&lt;br /&gt;
                '''pigsentry-1.2'''&lt;br /&gt;
 [Sun Nov  7 14:40:38 2004] alert: New event: ICMP PING NMAP&lt;br /&gt;
&lt;br /&gt;
Performing an Nmap scan generated the alert shown in this example.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Snort Cookbook/Installation and Optimization#Running Snort to Detect Intrusions|Recipe 1.18]]&lt;br /&gt;
&lt;br /&gt;
== Ignoring Some Alerts ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to ignore some things that are being logged.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Create a pass rule to ignore the particular traffic. The following rule ignores any traffic from ServerA:&lt;br /&gt;
&lt;br /&gt;
 pass tcp ServerA any - any any&lt;br /&gt;
&lt;br /&gt;
You must be sure to change the rule testing order to ttpass|alert|log/tt by using the Snort -o command-line option:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost root]# '''snort -o -c /etc/snort.conf'''&lt;br /&gt;
&lt;br /&gt;
You can also ignore traffic by using a filter on the command line when starting Snort:&lt;br /&gt;
&lt;br /&gt;
 snort -c /etc/snort.conf not host ServerA&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
There are two ways to configure Snort to ignore certain types of traffic: use a pass rule or use a Berkeley Packet Filter on startup. Be extra careful when using pass rules and filters so that you don't accidentally configure your IDS in a way that it misses alerting on potential intrusions.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Logging to System Logfiles ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to log to a system logfile such as the ''messages'' file under Linux, so that you have a centralized logging facility.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the ttalert_syslog/tt output plug-in in the ''/etc/snort.conf'' file.&lt;br /&gt;
&lt;br /&gt;
 output alert_syslog: facility priority options&lt;br /&gt;
&lt;br /&gt;
For example, to send an alert to the system log with a facility of ttLOG_DAEMON/tt (log as a system daemon), a Priority of ttLOG_CRIT/tt (critical conditions), and the option ttLOG_PERROR/tt (print the log to standard error as well), you would use the following:&lt;br /&gt;
&lt;br /&gt;
 output alert_syslog: LOG_DAEMON LOG_CRIT LOG_PERROR&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Logging to the system logfiles is a useful way of monitoring all your systems simultaneously. Using some of the tools described in later chapters for the automated monitoring of logfiles, you can watch everything from disk usage to intrusion attempts, all in the same place. It also means that you can log to a central log host by forwarding all syslog calls to a central server.&lt;br /&gt;
&lt;br /&gt;
Each set of options directly corresponds to those in the manpage for syslog (3) on Unix systems. For further detail, you should refer to these.&lt;br /&gt;
&lt;br /&gt;
Facility is one of: ttLOG_AUTH/tt, ttLOG_AUTHPRIV/tt, ttLOG_DAEMON/tt, ttLOG_USER/tt, and ttLOG_LOCAL0/tt through ttLOG_LOCAL7/tt.&lt;br /&gt;
&lt;br /&gt;
Priority is one of: ttLOG_EMERG/tt, ttLOG_ALERT/tt, ttLOG_CRIT/tt, ttLOG_ERR/tt, ttLOG_WARNING/tt, ttLOG_NOTICE/tt, ttLOG_INFO/tt, and ttLOG_DEBUG/tt.&lt;br /&gt;
&lt;br /&gt;
Finally, there are the options: ttLOG_CONS/tt, ttLOG_NDELAY/tt, ttLOG_PERROR/tt, and ttLOG_PID/tt.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
syslog (3) manpage&lt;br /&gt;
&lt;br /&gt;
Snort Users Manual&lt;br /&gt;
&lt;br /&gt;
== Fast Logging ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You have so much data that you need to log only basic information from each event.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the Snort ttalert_fast/tt output plug-in.&lt;br /&gt;
&lt;br /&gt;
 output alert_fast: filename&lt;br /&gt;
&lt;br /&gt;
The data from the logfile could then be displayed or sorted somewhere else for use on a quick status or ESM/SIM high-level view of what attacks are occurring on your network.&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
To enable the ttalert_fast/tt output plug-in, edit the ''snort.conf'' file under the section for output plug-ins and place the following as the first plug-in:&lt;br /&gt;
&lt;br /&gt;
 output alert_fast: fast_logging.txt&lt;br /&gt;
&lt;br /&gt;
The ''snort.conf'' file is read from the top down, so the closer to the top, the quicker your settings will take effect in the Snort startup process. The path will be set when you pass Snort the tt-l/tt option to specify the logging directory.&lt;br /&gt;
&lt;br /&gt;
This output plug-in should really not be used in a production environment unless setting up Barnyard is not an option. This plug-in takes no options other than the filename to use for logging events. One possible use of this plug-in would be to take the events being logged and display them for a quick status page.&lt;br /&gt;
&lt;br /&gt;
The following is an example of the ''fast_logging.txt'' output when Snort detects an Nmap scan:&lt;br /&gt;
&lt;br /&gt;
 # cat fast_logging.txt &lt;br /&gt;
 11/20-01:00:52:856446  [**] [1:469:3] ICMP PING NMAP [**] &lt;br /&gt;
 [Classification: Attempted Information Leak] [Priority: 2] {ICMP} &lt;br /&gt;
 10.0.1.5 - 10.0.1.100&lt;br /&gt;
&lt;br /&gt;
The best solution for an output plug-in such as this would be to spend some time developing a &amp;quot;status&amp;quot; page for the events to be filtered through. This would be good not only for keeping an eye on whether your Snort processes are working, but also for determining the speed and type of attacks coming to your network from each sensor.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
Snort Users Manual&lt;br /&gt;
&lt;br /&gt;
Php.net for Web-based ideas&lt;br /&gt;
&lt;br /&gt;
Cpan.perl.org for more Perl ideas&lt;br /&gt;
&lt;br /&gt;
== Logging to a Unix Socket ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want your alert to go to a program of your choice.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
The ttalert_unixsock/tt output plug-in opens a Unix socket and sends all alerts to it. It takes no options:&lt;br /&gt;
&lt;br /&gt;
 output alert_unixsock&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
Unix sockets are commonly mistaken for TCP/IP sockets. While there are many similarities in the way they're handled internally, you won't be able to connect to a Unix socket from another machine. These are purely for local interprocess communication. There is quite a big giveaway in the name of this plug-in that indicates that this is not for use on the Windows platform.&lt;br /&gt;
&lt;br /&gt;
The ttalert_unixsock/tt plug-in will send all alerts to the ''snort_alert'' file in the current Snort logging directory. For example, if you start Snort as follows:&lt;br /&gt;
&lt;br /&gt;
 snort -c /etc/snort/snort.conf -l /tmp&lt;br /&gt;
&lt;br /&gt;
Snort will attempt to log to the ''/tmp/snort_alert'' file. Snort makes no attempt to create this file, and will report an error should the file not exist or be unwriteable. This won't, however, stop Snort from starting, and when the socket is created, it will start to push alerts to it.&lt;br /&gt;
&lt;br /&gt;
Most, if not all, Unix programming languages will include commands for manipulating sockets. If you search the Internet, you can find example C code to create, open, close, and read from sockets. You'll even find some examples specific to the ttalert_unixsock/tt plug-in. The following example is given in Perl:&lt;br /&gt;
&lt;br /&gt;
 #!/usr/bin/perl&lt;br /&gt;
    &lt;br /&gt;
 # Include the socket libraries&lt;br /&gt;
    &lt;br /&gt;
 use IO::Socket;&lt;br /&gt;
    &lt;br /&gt;
 # This is the template to capture the Alert Name&lt;br /&gt;
 # Edit this to get the additional packets.&lt;br /&gt;
    &lt;br /&gt;
 $TEMPLATE = &amp;quot;A256 A*&amp;quot;; &lt;br /&gt;
    &lt;br /&gt;
 # Release the socket if it already exists&lt;br /&gt;
    &lt;br /&gt;
 unlink &amp;quot;/var/log/snort/snort_alert&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
 # In case of user termination - exit gracefully.&lt;br /&gt;
    &lt;br /&gt;
 $SIG{TERM} = $SIG{INT} = sub { exit 0 };&lt;br /&gt;
    &lt;br /&gt;
 # Open up the socket.&lt;br /&gt;
 my $client = IO::Socket::UNIX-new(Type = SOCK_DGRAM,&lt;br /&gt;
                    Local = &amp;quot;/var/log/snort/snort_alert&amp;quot;)&lt;br /&gt;
   or die &amp;quot;Socket: $@&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
 print STDOUT &amp;quot;Socket Open ... \n&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
 # Loop receiving data from the socket, pulling out the&lt;br /&gt;
 # alert name and printing it.&lt;br /&gt;
    &lt;br /&gt;
 my $data;&lt;br /&gt;
    &lt;br /&gt;
 while ( true ) {&lt;br /&gt;
     recv($client,$data,1024,0);&lt;br /&gt;
     @FIELDS = unpack($TEMPLATE, $data);&lt;br /&gt;
    &lt;br /&gt;
     print &amp;quot;@FIELDS[0] \n&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
 }&lt;br /&gt;
    &lt;br /&gt;
 # At termination close up the socket again.&lt;br /&gt;
    &lt;br /&gt;
 END {unlink &amp;quot;/var/log/snort/snort_alert&amp;quot;;}&lt;br /&gt;
&lt;br /&gt;
This code finds the alert name from the datagram sent and prints it out. Far more information is included in the datagram, including the raw packet data. This is left as an exercise for the reader to implement.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
Christiansen, Tom and Nathan Torkington. &amp;quot;Recipe 17.6: Using Unix Domain Sockets.&amp;quot; In ''Perl Cookbook''. Sebastopol, CA: O'Reilly, 2003.&lt;br /&gt;
&lt;br /&gt;
== Not Logging ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to create an alert but not to log something.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the ttlog_null/tt output plug-in. This allows you to create an alert that doesn't create log entries.&lt;br /&gt;
&lt;br /&gt;
 output log_null&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
There are occasions when you might want to draw attention to an event, but not record it for future reference. This allows you to create a powerful monitoring system, but not to have to worry about using huge amounts of disk space logging everything.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
Snort Users Manual&lt;br /&gt;
&lt;br /&gt;
== Prioritizing Alerts ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You need to assign a priority to your alerts so that port scans aren't getting you out of bed.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Assign a custom priority level to an alert using the priority keyword:&lt;br /&gt;
&lt;br /&gt;
 priority: n;&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
The ttpriority/tt keyword only changes the priority of the current rule. It has no effect on any of the other rules.&lt;br /&gt;
&lt;br /&gt;
For example, the following rule assigns a priority of 10 to an attempt to connect to a Telnet server:&lt;br /&gt;
&lt;br /&gt;
 alert tcp any any - any 23 (msg: &amp;quot;Telnet attempt&amp;quot;; priority: 10;)&lt;br /&gt;
&lt;br /&gt;
This has no effect other than marking the rule with a priority in the alert file. This is one of the packets from the previous alert rule:&lt;br /&gt;
&lt;br /&gt;
 [**] [1:0:0] Telnet attempt [**]&lt;br /&gt;
 [Priority: 10]&lt;br /&gt;
 11/02-13:42:39.806893 192.168.0.8:33175-192.168.0.25:23&lt;br /&gt;
 TCP TTL:64 TOS:0x10 ID:53754 IpLen:20 DgmLen:52 DF&lt;br /&gt;
 ***A***F Seq: 0x1A3A5F77 Ack: 0x28166C84 Win: 0x16D0 TcpLen: 32&lt;br /&gt;
 TCP Options (3) = NOP NOP TS: 1872654 15987586&lt;br /&gt;
&lt;br /&gt;
You can see that the priority has been set to 10. You can then use this value in your other monitoring programs to determine whether an alert is worth escalating.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
Snort Users Manual&lt;br /&gt;
&lt;br /&gt;
== Capturing Traffic from a Specific TCP Session ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to capture all the traffic from a specific TCP session.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the ttsession/tt option in a rule.&lt;br /&gt;
&lt;br /&gt;
 session: modifier;&lt;br /&gt;
&lt;br /&gt;
For example, to capture only printable characters:&lt;br /&gt;
&lt;br /&gt;
 session: printable;&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
The ttprintable/tt modifier outputs all the printable text from a session. This is an incredibly useful option for a plain-text session such as FTP or Telnet. It allows you to view the content of an entire session. If the protocol is a little more complex, use the ttall/tt modifier to output all the data from the session.&lt;br /&gt;
&lt;br /&gt;
For example, the previous rule produces the following output in the log SESSION:&lt;br /&gt;
&lt;br /&gt;
  !&amp;quot;'#P 38400,38400#frodo:0'DISPLAYfrodo:0XTERMsimon^Mpassword^m&lt;br /&gt;
&lt;br /&gt;
This shows all the Telnet sessions from the client to the server, with the username and password obvious in clear text. If you replace tt-/tt with tt/tt to get both sides of the conversation, it becomes a little clearer.&lt;br /&gt;
&lt;br /&gt;
 alert tcp any any  any 23 ( msg: &amp;quot;Telnet&amp;quot;; session: printable;)&lt;br /&gt;
&lt;br /&gt;
This gives the following :&lt;br /&gt;
&lt;br /&gt;
  !&amp;quot;'# #'!&amp;quot; #'P 38400,38400#frodo:0'DISPLAYfrodo:0XTERMFedora Core &lt;br /&gt;
 release 2 (Tettnang)&lt;br /&gt;
 Kernel 2.6.5-1.358 on an i686&lt;br /&gt;
 login: ssiimmoonn^M&lt;br /&gt;
 Password: password^M&lt;br /&gt;
 Last login: Fri Jul 2 12:58:49 from 192.168.0.8&lt;br /&gt;
 ]0;simon@blackbox:~[simon@blackbox simon]$&lt;br /&gt;
&lt;br /&gt;
which makes a little more sense, except for the doubled up letters when the letter is both sent from and returned to the Telnet client.&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
Snort Users Manual&lt;br /&gt;
&lt;br /&gt;
== Killing a Specific Session ==&lt;br /&gt;
&lt;br /&gt;
=== Problem ===&lt;br /&gt;
&lt;br /&gt;
You want to be able to close an active connection if specific criteria are met by a rule. For example, you might want to close any Telnet session in which the string tt/etc/passwd/tt is sent.&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
Use the ttresp/tt keyword.&lt;br /&gt;
&lt;br /&gt;
 resp: resp_mechanism&lt;br /&gt;
&lt;br /&gt;
=== Discussion ===&lt;br /&gt;
&lt;br /&gt;
ttresp/tt allows you to create a flexible response to end a TCP session on the triggering of an alert. You can take your pick from the responses listed in [[Snort Cookbook/Logging, Alerts, and Output Plug-ins#snortckbk-CHP-2-TABLE-1|Table 2-1]].&lt;br /&gt;
&lt;br /&gt;
div id=&amp;quot;snortckbk-CHP-2-TABLE-1&amp;quot;&lt;br /&gt;
'''Table 2-1. resp keyword actions'''&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Mechanism name !! Action&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 rst_snd&lt;br /&gt;
| Send TCP-RST packet to the sending socket&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 rst_rcv&lt;br /&gt;
| Send TCP-RST packet to the receiving socket&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 rst_all&lt;br /&gt;
| Send a TCP-RST packet to both&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 icmp_net&lt;br /&gt;
| Send ICMP-NET-UNREACH to the sender&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 icmp_host&lt;br /&gt;
| Send ICMP-HOST-UNREACH to the sender&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 icmp_port&lt;br /&gt;
| Send ICMP-PORT-UNREACH to the sender&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 icmp_all&lt;br /&gt;
| Send all the previously listed ICMP packets to the sender.&lt;br /&gt;
|}&lt;br /&gt;
/div&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All the actions listed in [[Snort Cookbook/Logging, Alerts, and Output Plug-ins#snortckbk-CHP-2-TABLE-1|Table 2-1]] can be combined by specifying them in sequence.&lt;br /&gt;
&lt;br /&gt;
For example, to drop all connections from a certain host :&lt;br /&gt;
&lt;br /&gt;
 alert tcp 192.168.0.8 any - any any (resp:rst_all;)&lt;br /&gt;
&lt;br /&gt;
As you can combine the mechanisms, the following would have exactly the same effect:&lt;br /&gt;
&lt;br /&gt;
 Alert tcp 192.168.0.8 any - any any (resp:rst_snd,rst_rcv;)&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
&lt;br /&gt;
Snort Users Manual&lt;/div&gt;</summary>
		<author><name>Docbook2Wiki</name></author>	</entry>

	</feed>