A Short Guide on SNORT (Network Intrusion Detection System)


short article by : Antonius www.cr0security.com

SNORT is a famous NIDS. SNORT has 3 modes, such as:

   Sniffer Mode
   Packet Logger Mode
   Network Intrusion Detection Mode

SNORT use pcap library
some /dev and /proc pcap use ?
/sys/class/net/ (NIC's interfaces detail)
/proc/net/dev (interfaces, packets,etc)
/dev/input (kernel space input)

Sniffer Mode

Sniffer mode is basic usage of snort, to start : "snort -v" , if you wanna specify an interface : "snort -v -i interface"
Example:

libpcap#snort -v -i eth1
Running in packet dump mode

       --== Initializing Snort ==--
Initializing Output Plugins!
Initializing Network Interface eth1
Decoding Ethernet on interface eth1

       --== Initialization Complete ==--

  ,,_     -*> Snort! <*-
 o"  )~   Version 2.8.5.2 (Build 121)
  ''''    By Martin Roesch & The Snort Team: http://www.snort.org/snort/snort-team
          Copyright (C) 1998-2009 Sourcefire, Inc., et al.
          Using PCRE version: 8.02 2010-03-19

Not Using PCAP_FRAMES
09/27-06:20:05.508892 192.168.1.3:60384 -> 192.168.1.1:53
UDP TTL:64 TOS:0x0 ID:13476 IpLen:20 DgmLen:60 DF
Len: 32
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

09/27-06:20:05.557801 192.168.1.1:53 -> 192.168.1.3:60384
UDP TTL:255 TOS:0x0 ID:20613 IpLen:20 DgmLen:140 DF
Len: 112
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

09/27-06:20:05.558217 192.168.1.3:34173 -> 74.125.235.18:80
TCP TTL:64 TOS:0x0 ID:20224 IpLen:20 DgmLen:60 DF
******S* Seq: 0x5AF57BB0  Ack: 0x0  Win: 0x16D0  TcpLen: 40
TCP Options (6) => MSS: 1460 NOP NOP TS: 9450672 0 NOP WS: 9
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

09/27-06:20:05.587413 74.125.235.18:80 -> 192.168.1.3:34173
TCP TTL:251 TOS:0x0 ID:14453 IpLen:20 DgmLen:60 DF
***A**S* Seq: 0xBEA22679  Ack: 0x5AF57BB1  Win: 0x1068  TcpLen: 40
TCP Options (6) => MSS: 1400 NOP WS: 0 NOP NOP TS: 83065381 9450672
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

09/27-06:20:05.587480 192.168.1.3:34173 -> 74.125.235.18:80
TCP TTL:64 TOS:0x0 ID:20225 IpLen:20 DgmLen:52 DF
***A**** Seq: 0x5AF57BB1  Ack: 0xBEA2267A  Win: 0xC  TcpLen: 32
TCP Options (3) => NOP NOP TS: 9450680 83065381
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

09/27-06:20:05.587584 192.168.1.3:34173 -> 74.125.235.18:80
TCP TTL:64 TOS:0x0 ID:20226 IpLen:20 DgmLen:584 DF
***AP*** Seq: 0x5AF57BB1  Ack: 0xBEA2267A  Win: 0xC  TcpLen: 32
TCP Options (3) => NOP NOP TS: 9450680 83065381
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

09/27-06:20:05.655396 74.125.235.18:80 -> 192.168.1.3:34173
TCP TTL:251 TOS:0x0 ID:15005 IpLen:20 DgmLen:52 DF
***A**** Seq: 0xBEA2267A  Ack: 0x5AF57DC5  Win: 0x127C  TcpLen: 32
TCP Options (3) => NOP NOP TS: 83065451 9450680
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

09/27-06:20:05.719556 74.125.235.18:80 -> 192.168.1.3:34173
TCP TTL:251 TOS:0x0 ID:15419 IpLen:20 DgmLen:528 DF
***AP*** Seq: 0xBEA2267A  Ack: 0x5AF57DC5  Win: 0x127C  TcpLen: 32
TCP Options (3) => NOP NOP TS: 83065506 9450680
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

09/27-06:20:05.719609 192.168.1.3:34173 -> 74.125.235.18:80
TCP TTL:64 TOS:0x0 ID:20227 IpLen:20 DgmLen:52 DF
***A**** Seq: 0x5AF57DC5  Ack: 0xBEA22856  Win: 0xE  TcpLen: 32
TCP Options (3) => NOP NOP TS: 9450713 83065506
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+


ok, let's see here:

====
09/27-06:20:05.719609 192.168.1.3:34173 -> 74.125.235.18:80
TCP TTL:64 TOS:0x0 ID:20227 IpLen:20 DgmLen:52 DF
***A**** Seq: 0x5AF57DC5  Ack: 0xBEA22856  Win: 0xE  TcpLen: 32
TCP Options (3) => NOP NOP TS: 9450713 83065506
=====


09/27-06:20:05.719609 -> time stamp
192.168.1.3:34173   -> source ip:source port
74.125.235.18:80 -> destionation ip : destination port
TCP -> protocol
TTL:64  -> time to live
TOS:0x0 -> type of service specify datagram priority
ID:20227 ->packet identification
IpLen:20 -> ip header length
DgmLen:52 -> datagram length (datagram is a basic transfer unit associated with a packet-switched network)
DF (Don't Fragment) bit -> This is a bit in the IP header that can be set to indicate that the packet should not be fragmented by routers

Packet Logger Mode

Here's a sample of using snort as packet logger mode:

#snort -i eth1 -K pcap -l /var/log/snort -d

the result should be on /var/log/snort, you may read the pcap format using tcpdump :

#ls /var/log/snort
192.168.1.3  alert  PACKET_NONIP  snort.log.1348703594  tcpdump.log.1348697823
#mv snort.log.1348703594 /root/snort.pcap
#tcpdump -tttt -r /root/snort.pcap
2012-09-27 06:53:24.875937 IP ev1lut10n-Vostro1310.37492 > sin04s01-in-f23.1e100.net.www: Flags [P.], seq 2143183534:2143184094, ack 662251960, win 97, options [nop,nop,TS
val 9950502 ecr 85006748], length 560
2012-09-27 06:53:24.939287 IP sin04s01-in-f23.1e100.net.www > ev1lut10n-Vostro1310.37492: Flags [.], ack 560, win 11977, options [nop,nop,TS val 85037786 ecr 9950502],
length 0
2012-09-27 06:53:25.009151 IP sin04s01-in-f23.1e100.net.www > ev1lut10n-Vostro1310.37492: Flags [P.], seq 1389:1419, ack 560, win 11977, options [nop,nop,TS val 85037855 ecr
9950502], length 30
2012-09-27 06:53:25.009239 IP ev1lut10n-Vostro1310.37492 > sin04s01-in-f23.1e100.net.www: Flags [.], ack 1, win 97, options [nop,nop,TS val 9950535 ecr 85037786], length 0
2012-09-27 06:53:25.060405 IP sin04s01-in-f23.1e100.net.www > ev1lut10n-Vostro1310.37492: Flags [.], seq 1:1389, ack 560, win 11977, options [nop,nop,TS val 85037855 ecr
9950502], length 1388
2012-09-27 06:53:25.060501 IP ev1lut10n-Vostro1310.37492 > sin04s01-in-f23.1e100.net.www: Flags [.], ack 1419, win 103, options [nop,nop,TS val 9950548 ecr 85037855], length
0
2012-09-27 06:53:25.087271 IP sin04s01-in-f23.1e100.net.www > ev1lut10n-Vostro1310.37492: Flags [.], seq 1419:2807, ack 560, win 11977, options [nop,nop,TS val 85037855 ecr
9950502], length 1388

NIDS Mode

Example

#snort -i eth1 -b -A fast -c /etc/snort/snort.conf
Running in IDS mode

       --== Initializing Snort ==--
Initializing Output Plugins!
Initializing Preprocessors!
Initializing Plug-ins!
Parsing Rules file "/etc/snort/snort.conf"
PortVar 'HTTP_PORTS' defined :  [ 80 ]
PortVar 'SHELLCODE_PORTS' defined :  [ 0:79 81:65535 ]
PortVar 'ORACLE_PORTS' defined :  [ 1521 ]
PortVar 'FTP_PORTS' defined :  [ 21 ]
Tagged Packet Limit: 256
Loading dynamic engine /usr/lib/snort_dynamicengine/libsf_engine.so... done
Loading all dynamic preprocessor libs from /usr/lib/snort_dynamicpreprocessor/...
 Loading dynamic preprocessor library /usr/lib/snort_dynamicpreprocessor//libsf_dcerpc_preproc.so... done
 Loading dynamic preprocessor library /usr/lib/snort_dynamicpreprocessor//libsf_dce2_preproc.so... done
 Loading dynamic preprocessor library /usr/lib/snort_dynamicpreprocessor//libsf_dns_preproc.so... done
 Loading dynamic preprocessor library /usr/lib/snort_dynamicpreprocessor//libsf_ftptelnet_preproc.so... done
 Loading dynamic preprocessor library /usr/lib/snort_dynamicpreprocessor//lib_sfdynamic_preprocessor_example.so... done
 Loading dynamic preprocessor library /usr/lib/snort_dynamicpreprocessor//libsf_ssh_preproc.so... done
 Loading dynamic preprocessor library /usr/lib/snort_dynamicpreprocessor//libsf_ssl_preproc.so... done
 Loading dynamic preprocessor library /usr/lib/snort_dynamicpreprocessor//libsf_smtp_preproc.so... done
 Finished Loading all dynamic preprocessor libs from /usr/lib/snort_dynamicpreprocessor/
Log directory = /var/log/snort
Frag3 global config:
   Max frags: 65536
   Fragment memory cap: 4194304 bytes
Frag3 engine config:
   Target-based policy: FIRST
   Fragment timeout: 60 seconds
   Fragment min_ttl:   1
   Fragment Problems: 1
   Overlap Limit:     10
   Min fragment Length:     0
Stream5 global config:
   Track TCP sessions: ACTIVE
   Max TCP sessions: 8192
   Memcap (for reassembly packet storage): 8388608
   Track UDP sessions: INACTIVE
   Track ICMP sessions: INACTIVE
   Log info if session memory consumption exceeds 1048576
Stream5 TCP Policy config:
   Reassembly Policy: FIRST
   Timeout: 30 seconds
   Min ttl:  1
   Maximum number of bytes to queue per session: 1048576
   Maximum number of segs to queue per session: 2621
   Reassembly Ports:
     21 client (Footprint)
     23 client (Footprint)
     25 client (Footprint)
     42 client (Footprint)
     53 client (Footprint)
     80 client (Footprint)
     110 client (Footprint)
     111 client (Footprint)
     135 client (Footprint)
     136 client (Footprint)
     137 client (Footprint)
     139 client (Footprint)
     143 client (Footprint)
     445 client (Footprint)
     513 client (Footprint)
     514 client (Footprint)
     1433 client (Footprint)
     1521 client (Footprint)
     2401 client (Footprint)
     3306 client (Footprint)
HttpInspect Config:
   GLOBAL CONFIG
     Max Pipeline Requests:    0
     Inspection Type:          STATELESS
     Detect Proxy Usage:       NO
     IIS Unicode Map Filename: /etc/snort/unicode.map
     IIS Unicode Map Codepage: 1252
   DEFAULT SERVER CONFIG:
     Server profile: All
     Ports: 80 8080 8180
     Server Flow Depth: 300
     Client Flow Depth: 300
     Max Chunk Length: 500000
     Max Header Field Length: 0
     Max Number Header Fields: 0
     Inspect Pipeline Requests: YES
     URI Discovery Strict Mode: NO
     Allow Proxy Usage: NO
     Disable Alerting: NO
     Oversize Dir Length: 500
     Only inspect URI: NO
     Normalize HTTP Headers: NO
     Normalize HTTP Cookies: NO
     Ascii: YES alert: NO
     Double Decoding: YES alert: YES
     %U Encoding: YES alert: YES
     Bare Byte: YES alert: YES
     Base36: OFF
     UTF 8: OFF
     IIS Unicode: YES alert: YES
     Multiple Slash: YES alert: NO
     IIS Backslash: YES alert: NO
     Directory Traversal: YES alert: NO
     Web Root Traversal: YES alert: YES
     Apache WhiteSpace: YES alert: NO
     IIS Delimiter: YES alert: NO
     IIS Unicode Map: GLOBAL IIS UNICODE MAP CONFIG
     Non-RFC Compliant Characters: NONE
     Whitespace Characters: 0x09 0x0b 0x0c 0x0d
rpc_decode arguments:
   Ports to decode RPC on: 111 32771
   alert_fragments: INACTIVE
   alert_large_fragments: ACTIVE
   alert_incomplete: ACTIVE
   alert_multiple_requests: ACTIVE
Portscan Detection Config:
   Detect Protocols:  TCP UDP ICMP IP
   Detect Scan Type:  portscan portsweep decoy_portscan distributed_portscan
   Sensitivity Level: Low
   Memcap (in bytes): 10000000
   Number of Nodes:   36900
FTPTelnet Config:
   GLOBAL CONFIG
     Inspection Type: stateful
     Check for Encrypted Traffic: YES alert: YES
     Continue to check encrypted data: NO
   TELNET CONFIG:
     Ports: 23
     Are You There Threshold: 200
     Normalize: YES
     Detect Anomalies: NO
   FTP CONFIG:
     FTP Server: default
       Ports: 21
       Check for Telnet Cmds: YES alert: YES
       Ignore Telnet Cmd Operations: OFF
       Identify open data channels: YES
     FTP Client: default
       Check for Bounce Attacks: YES alert: YES
       Check for Telnet Cmds: YES alert: YES
       Ignore Telnet Cmd Operations: OFF
       Max Response Length: 256
SMTP Config:
   Ports: 25 587 691
   Inspection Type: Stateful
   Normalize: EXPN RCPT VRFY
   Ignore Data: No
   Ignore TLS Data: No
   Ignore SMTP Alerts: No
   Max Command Line Length: Unlimited
   Max Specific Command Line Length:
      ETRN:500 EXPN:255 HELO:500 HELP:500 MAIL:260
      RCPT:300 VRFY:255
   Max Header Line Length: Unlimited
   Max Response Line Length: Unlimited
   X-Link2State Alert: Yes
   Drop on X-Link2State Alert: No
   Alert on commands: None
SSH config:
   Autodetection: DISABLED
   Challenge-Response Overflow Alert: ENABLED
   SSH1 CRC32 Alert: ENABLED
   Server Version String Overflow Alert: ENABLED
   Protocol Mismatch Alert: ENABLED
   Bad Message Direction Alert: DISABLED
   Bad Payload Size Alert: DISABLED
   Unrecognized Version Alert: DISABLED
   Max Encrypted Packets: 20
   Max Server Version String Length: 80 (Default)
   MaxClientBytes: 19600 (Default)
   Ports:
       22
DCE/RPC 2 Preprocessor Configuration
 Global Configuration
   DCE/RPC Defragmentation: Enabled
   Memcap: 102400 KB
   Events: none
 Server Default Configuration
   Policy: WinXP
   Detect ports
     SMB: 139 445
     TCP: 135
     UDP: 135
     RPC over HTTP server: 593
     RPC over HTTP proxy: None
   Autodetect ports
     SMB: None
     TCP: 1025-65535
     UDP: 1025-65535
     RPC over HTTP server: 1025-65535
     RPC over HTTP proxy: None
   Maximum SMB command chaining: 3 commands
DNS config:
   DNS Client rdata txt Overflow Alert: ACTIVE
   Obsolete DNS RR Types Alert: INACTIVE
   Experimental DNS RR Types Alert: INACTIVE
   Ports: 53
SSLPP config:
   Encrypted packets: not inspected
   Ports:
     443      465      563      636      989
     992      993      994      995
   Server side data is trusted

+++++++++++++++++++++++++++++++++++++++++++++++++++
Initializing rule chains...
Warning: /etc/snort/rules/dos.rules(42) => threshold (in rule) is deprecated; use detection_filter instead.
3379 Snort rules read
   3379 detection rules
   0 decoder rules
   0 preprocessor rules
3379 Option Chains linked into 261 Chain Headers
0 Dynamic rules
+++++++++++++++++++++++++++++++++++++++++++++++++++

+-------------------[Rule Port Counts]---------------------------------------
|             tcp     udp    icmp      ip
|     src     121      18       0       0
|     dst    2921     129       0       0
|     any     115      53      56      27
|      nc      31      10      15      20
|     s+d      12       6       0       0
+----------------------------------------------------------------------------

+-----------------------[detection-filter-config]------------------------------
| memory-cap : 1048576 bytes
+-----------------------[detection-filter-rules]-------------------------------
| none
-------------------------------------------------------------------------------

+-----------------------[rate-filter-config]-----------------------------------
| memory-cap : 1048576 bytes
+-----------------------[rate-filter-rules]------------------------------------
| none
-------------------------------------------------------------------------------

+-----------------------[event-filter-config]----------------------------------
| memory-cap : 1048576 bytes
+-----------------------[event-filter-global]----------------------------------
| none
+-----------------------[event-filter-local]-----------------------------------
| gen-id=1      sig-id=2923       type=Threshold tracking=dst count=10  seconds=60
| gen-id=1      sig-id=100000310  type=Limit     tracking=src count=1   seconds=360
| gen-id=1      sig-id=3273       type=Threshold tracking=src count=5   seconds=2
| gen-id=1      sig-id=2496       type=Both      tracking=dst count=20  seconds=60
| gen-id=1      sig-id=100000159  type=Both      tracking=src count=100 seconds=60
| gen-id=1      sig-id=100000160  type=Both      tracking=src count=300 seconds=60
| gen-id=1      sig-id=100000311  type=Limit     tracking=src count=1   seconds=360
| gen-id=1      sig-id=2523       type=Both      tracking=dst count=10  seconds=10
| gen-id=1      sig-id=100000161  type=Both      tracking=dst count=100 seconds=60
| gen-id=1      sig-id=100000163  type=Both      tracking=src count=100 seconds=60
| gen-id=1      sig-id=2495       type=Both      tracking=dst count=20  seconds=60
| gen-id=1      sig-id=100000312  type=Limit     tracking=src count=1   seconds=360
| gen-id=1      sig-id=100000158  type=Both      tracking=src count=100 seconds=60
| gen-id=1      sig-id=100000923  type=Threshold tracking=dst count=200 seconds=60
| gen-id=1      sig-id=2275       type=Threshold tracking=dst count=5   seconds=60
| gen-id=1      sig-id=2494       type=Both      tracking=dst count=20  seconds=60
| gen-id=1      sig-id=3152       type=Threshold tracking=src count=5   seconds=2
| gen-id=1      sig-id=100000162  type=Both      tracking=src count=100 seconds=60
| gen-id=1      sig-id=2924       type=Threshold tracking=dst count=10  seconds=60
+-----------------------[suppression]------------------------------------------
| none
-------------------------------------------------------------------------------
Rule application order: activation->dynamic->pass->drop->alert->log
Verifying Preprocessor Configurations!
Warning: flowbits key 'ms_sql_seen_dns' is checked but not ever set.
Warning: flowbits key 'community_uri.size.1050' is set but not ever checked.
Warning: flowbits key 'realplayer.playlist' is checked but not ever set.
Warning: flowbits key 'smb.tree.create.llsrpc' is set but not ever checked.
37 out of 512 flowbits in use.
Initializing Network Interface eth1
Decoding Ethernet on interface eth1

[ Port Based Pattern Matching Memory ]
+-[AC-BNFA Search Info Summary]------------------------------
| Instances        : 241
| Patterns         : 22046
| Pattern Chars    : 207188
| Num States       : 137776
| Num Match States : 18341
| Memory           :   3.51Mbytes
|   Patterns       :   0.70M
|   Match Lists    :   0.96M
|   Transitions    :   1.79M
+-------------------------------------------------

       --== Initialization Complete ==--

  ,,_     -*> Snort! <*-
 o"  )~   Version 2.8.5.2 (Build 121)
  ''''    By Martin Roesch & The Snort Team: http://www.snort.org/snort/snort-team
          Copyright (C) 1998-2009 Sourcefire, Inc., et al.
          Using PCRE version: 8.02 2010-03-19

          Rules Engine: SF_SNORT_DETECTION_ENGINE  Version 1.11
          Preprocessor Object: SF_SMTP  Version 1.1
          Preprocessor Object: SF_SSLPP  Version 1.1
          Preprocessor Object: SF_SSH  Version 1.1
          Preprocessor Object: SF_Dynamic_Example_Preprocessor  Version 1.0
          Preprocessor Object: SF_FTPTELNET  Version 1.2
          Preprocessor Object: SF_DNS  Version 1.1
          Preprocessor Object: SF_DCERPC2  Version 1.0
          Preprocessor Object: SF_DCERPC  Version 1.1