]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
11 years agoFix bug #1206 999/head
Mats Klepsland [Mon, 23 Jun 2014 07:14:16 +0000 (09:14 +0200)] 
Fix bug #1206

PF_RING ZC uses clusters in the same way as PF_RING DNA. Therefore,
this bug can be fixed as it was fixed for DNA (bug #598).

11 years agohtp: make htp state handling function more robust
Victor Julien [Thu, 19 Jun 2014 08:36:36 +0000 (10:36 +0200)] 
htp: make htp state handling function more robust

Also, fix wrong cast that worked only by luck.

11 years agohttp: remove BUG_ON(1) statement
Victor Julien [Tue, 17 Jun 2014 11:56:47 +0000 (13:56 +0200)] 
http: remove BUG_ON(1) statement

Remove BUG_ON(1) statement that was a leftover from debugging.

Bug #1189
Bug #1212

11 years agoFix issue #1214 995/head
Alessandro Guido [Fri, 20 Jun 2014 12:01:11 +0000 (14:01 +0200)] 
Fix issue #1214

When applying wildcard thresholds (with sid = 0 and/or gid = 0) it's wrong
to exit on the first signature already having an event filter. Indeed,
doing so results in the theshold not being applied to all subsequent
signatures. Change the code in order to skip signatures with event
filters instead of breaking out of the loop.

11 years agoFix libcap-ng configure typo.
Victor Julien [Thu, 12 Jun 2014 09:54:31 +0000 (11:54 +0200)] 
Fix libcap-ng configure typo.

11 years agoBug 1098: improve invalid pcre/R handling 987/head
Victor Julien [Tue, 10 Jun 2014 15:31:28 +0000 (17:31 +0200)] 
Bug 1098: improve invalid pcre/R handling

When not using a file_data or similar 'sticky buffer', a pcre/R option
needs a content in the same buffer.

11 years agonflog: fix memory leaks
Giuseppe Longo [Fri, 6 Jun 2014 09:48:15 +0000 (11:48 +0200)] 
nflog: fix memory leaks

This fixes the following memory leaks:

[src/source-nflog.c:222]: (error) Memory leak: ntv
[src/source-nflog.c:236]: (error) Memory leak: ntv
[src/source-nflog.c:253]: (error) Memory leak: ntv
[src/source-nflog.c:258]: (error) Memory leak: ntv

11 years agocygwin: fix lua configure
Victor Julien [Wed, 4 Jun 2014 16:01:52 +0000 (18:01 +0200)] 
cygwin: fix lua configure

Fix lua configure for cygwin. Tested with lua 5.1.5.

11 years agoFix live reload segv when startup isn't complete 982/head
Victor Julien [Tue, 20 May 2014 11:03:09 +0000 (13:03 +0200)] 
Fix live reload segv when startup isn't complete

If a live reload signal was given before the engine was fully started
up (e.g. pcap file thread waiting for a disk to spin up), a segv could
occur.

This patch only enables live reloads after the threads have been
started up completely.

11 years agoFix Coverity 1220098 and 1220099 981/head
Victor Julien [Wed, 4 Jun 2014 15:11:29 +0000 (17:11 +0200)] 
Fix Coverity 1220098 and 1220099

*** CID 1220098:  Missing unlock  (LOCK)
/src/log-droplog.c: 195 in LogDropLogNetFilter()
189         SCMutexLock(&dlt->file_ctx->fp_mutex);
190
191         if (dlt->file_ctx->rotation_flag) {
192             dlt->file_ctx->rotation_flag  = 0;
193             if (SCConfLogReopen(dlt->file_ctx) != 0) {
194                 /* Rotation failed, error already logged. */
>>>     CID 1220098:  Missing unlock  (LOCK)
>>>     Returning without unlocking "dlt->file_ctx->fp_mutex".
195                 return TM_ECODE_FAILED;
196             }
197         }
198
199         if (dlt->file_ctx == NULL) {
200             return TM_ECODE_FAILED;

*** CID 1220099:  Dereference before null check  (REVERSE_INULL)
/src/log-droplog.c: 199 in LogDropLogNetFilter()
193             if (SCConfLogReopen(dlt->file_ctx) != 0) {
194                 /* Rotation failed, error already logged. */
195                 return TM_ECODE_FAILED;
196             }
197         }
198
>>>     CID 1220099:  Dereference before null check  (REVERSE_INULL)
>>>     Null-checking "dlt->file_ctx" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
199         if (dlt->file_ctx == NULL) {
200             return TM_ECODE_FAILED;
201         }
202
203         char srcip[46] = "";
204         char dstip[46] = "";

11 years agoFix Coverity 1220097
Victor Julien [Wed, 4 Jun 2014 14:54:56 +0000 (16:54 +0200)] 
Fix Coverity 1220097

*** CID 1220097:  Missing unlock  (LOCK)
/src/log-file.c: 160 in LogFileWriteJsonRecord()
154             }
155         }
156
157         /* Bail early if no file pointer to write to (in the unlikely
158          * event file rotation failed. */
159         if (aft->file_ctx->fp == NULL) {
>>>     CID 1220097:  Missing unlock  (LOCK)
>>>     Returning without unlocking "aft->file_ctx->fp_mutex".
160             return;
161         }
162
163         FILE *fp = aft->file_ctx->fp;
164         char timebuf[64];
165         AppProto alproto = FlowGetAppProtocol(p->flow);

11 years agoUnregister for file rotation notification when a context is
Jason Ish [Tue, 27 May 2014 16:07:50 +0000 (10:07 -0600)] 
Unregister for file rotation notification when a context is
de-initialized.  Required for unix-socket mode where
contexts come and go.

11 years agoAdd signal based file rotation for:
Jason Ish [Tue, 4 Mar 2014 16:43:36 +0000 (10:43 -0600)] 
Add signal based file rotation for:
- alert debug log
- fast log
- stats log
- dns log
- drop log
- file log
- http log
- tls log
- eve/json log

11 years agoAdd macros for access to the underlying buffer and offset.
Jason Ish [Tue, 4 Mar 2014 16:42:19 +0000 (10:42 -0600)] 
Add macros for access to the underlying buffer and offset.
Useful for using passing the buffer through to another writer
such as LogFileCtx.

11 years agoAdd a rotation flag to LogFileCtx which loggers can use to register
Jason Ish [Tue, 4 Mar 2014 16:40:10 +0000 (10:40 -0600)] 
Add a rotation flag to LogFileCtx which loggers can use to register
for log rotation.  Have the LogFileCtx handle the log rotation.

11 years agoRegistration for SIGHUP notification - for loggers interested
Jason Ish [Tue, 4 Mar 2014 16:34:33 +0000 (10:34 -0600)] 
Registration for SIGHUP notification - for loggers interested
in file rotation on SIGHUP.

11 years agolua/luajit: use HAVE_LUA mostly 980/head
Victor Julien [Thu, 13 Mar 2014 15:24:51 +0000 (16:24 +0100)] 
lua/luajit: use HAVE_LUA mostly

Only use HAVE_LUAJIT if things are done differently from HAVE_LUA,
like in the states pool.

11 years agolua: deal with FreeBSD and OpenBSD
Victor Julien [Thu, 20 Mar 2014 09:33:57 +0000 (10:33 +0100)] 
lua: deal with FreeBSD and OpenBSD

FreeBSD pkg-config lua-5.1.pc, lib liblua-5.1.so
OpenBSD pkg-config lua51.pc, lib liblua5.1.so

Default (linux) pkg-config: lua5.1.pc, lib liblua5.1.so

11 years agolua: support regular lua C library
Victor Julien [Thu, 13 Mar 2014 14:10:10 +0000 (15:10 +0100)] 
lua: support regular lua C library

Not all systems have luajit or a need for luajit. For low bandwidth
and offline support regular lua may be sufficient.

11 years agoprofiling: use wider columns in keyword output
Victor Julien [Mon, 2 Jun 2014 14:46:02 +0000 (16:46 +0200)] 
profiling: use wider columns in keyword output

Use wider columns in keyword output so that even on high end sensors
the stats tables remain readable.

11 years agofix regression in 'make distclean' due to commit cd305c3a
Noam Meltzer [Thu, 8 May 2014 06:26:43 +0000 (09:26 +0300)] 
fix regression in 'make distclean' due to commit cd305c3a

the files under scripts/suricatasc/src are actual sources and should not
be cleaned

11 years agobugfix in debug mode:
jeka [Tue, 20 May 2014 09:20:59 +0000 (12:20 +0300)] 
bugfix in debug mode:

removed function calls from SCReturnX macros

11 years agonflog: set socket timeout 978/head
Victor Julien [Mon, 26 May 2014 10:45:59 +0000 (12:45 +0200)] 
nflog: set socket timeout

Set socket timeout so that we can exit if there is no traffic.

It would hang after the SIGINT signal, until packets arived.

11 years agonflog: warn if buffer-size is larger than max-size
Victor Julien [Mon, 26 May 2014 10:40:50 +0000 (12:40 +0200)] 
nflog: warn if buffer-size is larger than max-size

If buffer-size is larger than max size, give a warning and adjust
buffer-size to max-size.

11 years agodns: unify type to string logging utility
Victor Julien [Sat, 24 May 2014 16:48:18 +0000 (18:48 +0200)] 
dns: unify type to string logging utility

Both DNS loggers had their own CreateTypeString. This patch unifies
them.

11 years agodns: add names for common types
Victor Julien [Sat, 24 May 2014 16:37:14 +0000 (18:37 +0200)] 
dns: add names for common types

Add names for SRV, NAPTR, DS, RRSIG, NSEC, NSEC3 types.

11 years agonflog: fix typo rising->raising
Victor Julien [Fri, 23 May 2014 10:42:48 +0000 (12:42 +0200)] 
nflog: fix typo rising->raising

11 years agonflog: improve error handling on NOBUFS
Victor Julien [Wed, 21 May 2014 08:15:28 +0000 (10:15 +0200)] 
nflog: improve error handling on NOBUFS

Don't fall through to handle_packet on any NOBUFS condition. Make
sure we catch all NOBUFS.

11 years agoThis patch adds the fields into PacketVars struct to setup a packet from a nflog...
Giuseppe Longo [Wed, 26 Feb 2014 13:57:31 +0000 (14:57 +0100)] 
This patch adds the fields into PacketVars struct to setup a packet from a nflog message

11 years agoAdds nflog option
Giuseppe Longo [Sat, 1 Feb 2014 10:34:33 +0000 (11:34 +0100)] 
Adds nflog option

11 years agoDeclare a wrapper to parse group option for nflog
Giuseppe Longo [Sat, 1 Feb 2014 10:32:12 +0000 (11:32 +0100)] 
Declare a wrapper to parse group option for nflog

11 years agoImplements NFLOG runmode
Giuseppe Longo [Wed, 1 Jan 2014 21:04:54 +0000 (22:04 +0100)] 
Implements NFLOG runmode

11 years agoBootstraping NFLOG capture mode
Giuseppe Longo [Sun, 15 Dec 2013 14:29:12 +0000 (15:29 +0100)] 
Bootstraping NFLOG capture mode

11 years agoAdds nflog error code
Giuseppe Longo [Sat, 14 Dec 2013 12:29:24 +0000 (13:29 +0100)] 
Adds nflog error code

11 years agoUpdating the Tmm Id for declaration of nflog capture mode
Giuseppe Longo [Sat, 14 Dec 2013 12:28:27 +0000 (13:28 +0100)] 
Updating the Tmm Id for declaration of nflog capture mode

11 years agoAdds a configuration example for nflog support in suricata.yaml
Giuseppe Longo [Sat, 14 Dec 2013 09:40:57 +0000 (10:40 +0100)] 
Adds a configuration example for nflog support in suricata.yaml

11 years agoChecks if libnetfilter_log is found on the system
Giuseppe Longo [Tue, 10 Dec 2013 12:19:25 +0000 (13:19 +0100)] 
Checks if libnetfilter_log is found on the system
and enable it if it's specified.

11 years agotls: check SSL3/TLS version per record 973/head
Victor Julien [Fri, 2 May 2014 12:20:13 +0000 (14:20 +0200)] 
tls: check SSL3/TLS version per record

Set event if SSL3/TLS record isn't within the acceptable range.

11 years agodns: add tests for TXT response parsing 972/head
Victor Julien [Thu, 15 May 2014 12:01:54 +0000 (14:01 +0200)] 
dns: add tests for TXT response parsing

Add valid and invalid examples.

11 years agodns json: log TXT response data
Victor Julien [Thu, 15 May 2014 09:14:54 +0000 (11:14 +0200)] 
dns json: log TXT response data

Log TXT data in the rdata field.

11 years agodns: parse and store TXT responses
Victor Julien [Thu, 15 May 2014 09:14:30 +0000 (11:14 +0200)] 
dns: parse and store TXT responses

This way the TXT data can be logged by the loggers.

Ticket #1158

11 years agoUpdate Changelog for 2.0.1 suricata-2.0.1
Victor Julien [Wed, 21 May 2014 08:26:59 +0000 (10:26 +0200)] 
Update Changelog for 2.0.1

11 years agoUpdate Changelog for 2.0.1rc1 changes suricata-2.0.1rc1
Victor Julien [Mon, 12 May 2014 11:43:58 +0000 (13:43 +0200)] 
Update Changelog for 2.0.1rc1 changes

11 years agojson output: don't set 'unknown' for missing data 965/head
Victor Julien [Tue, 6 May 2014 11:54:03 +0000 (13:54 +0200)] 
json output: don't set 'unknown' for missing data

Instead of setting 'unknown' or '<unknown>' just pass NULL to json_*
function, which results in omitting the data.

11 years agoeve-log: swap ip/port pairs in dns answers
Tom DeCanio [Wed, 23 Apr 2014 15:41:15 +0000 (08:41 -0700)] 
eve-log: swap ip/port pairs in dns answers

11 years agohttp-json: fix coverity warning
Victor Julien [Fri, 2 May 2014 15:11:10 +0000 (17:11 +0200)] 
http-json: fix coverity warning

*** CID 1211009:  Bad bit shift operation  (BAD_SHIFT)
/src/output-json-http.c: 265 in JsonHttpLogJSON()
259         /* log custom fields if configured */
260         if (http_ctx->fields != 0)
261         {
262             HttpField f;
263             for (f = HTTP_FIELD_ACCEPT; f < HTTP_FIELD_SIZE; f++)
264             {
>>>     CID 1211009:  Bad bit shift operation  (BAD_SHIFT)
>>>     In expression "1 << f", left shifting by more than 31 bits has undefined behavior.  The shift amount, "f", is as much as 46.
265                 if ((http_ctx->fields & (1<<f)) != 0)
266                 {
267                     /* prevent logging a field twice if extended logging is
268                        enabled */
269                     if (((http_ctx->flags & LOG_HTTP_EXTENDED) == 0) ||
270                         ((http_ctx->flags & LOG_HTTP_EXTENDED) !=

________________________________________________________________________________________________________
*** CID 1211010:  Bad bit shift operation  (BAD_SHIFT)
/src/output-json-http.c: 492 in OutputHttpLogInitSub()
486                         {
487                             if ((strcmp(http_fields[f].config_field,
488                                        field->val) == 0) ||
489                                 (strcasecmp(http_fields[f].htp_field,
490                                             field->val) == 0))
491                             {
>>>     CID 1211010:  Bad bit shift operation  (BAD_SHIFT)
>>>     In expression "1 << f", left shifting by more than 31 bits has undefined behavior.  The shift amount, "f", is as much as 46.
492                                 http_ctx->fields |= (1<<f);
493                                 break;
494                             }
495                         }
496                     }
497                 }

11 years agounix-socket: reset logging api's properly 963/head
Victor Julien [Fri, 2 May 2014 14:32:49 +0000 (16:32 +0200)] 
unix-socket: reset logging api's properly

Lack of proper reset lead to logs not being written after the first
pcap had been processed.

11 years agostream: cleanup 961/head
Victor Julien [Thu, 24 Apr 2014 15:31:08 +0000 (17:31 +0200)] 
stream: cleanup

StreamTcpSetDisableRawReassemblyFlag() has the same effect as
AppLayerParserTriggerRawStreamReassembly in that it will force the
raw reassembly to flush out asap. So it is redundant to call both.

11 years agostream: implement raw reassembly stop api
Victor Julien [Thu, 24 Apr 2014 08:48:37 +0000 (10:48 +0200)] 
stream: implement raw reassembly stop api

Implement StreamTcpSetDisableRawReassemblyFlag() which stops raw
reassembly for _NEW_ segments in a stream direction.

It is used only by TLS/SSL now, to flag the streams as encrypted.
Existing segments will still be reassembled and inspected, while
new segments won't be. This allows for pattern based inspection
of the TLS handshake.

Like is the case with completely disabled 'raw' reassembly, the
logic is that the segments are flagged as completed for 'raw' right
away. So they are not considered in raw reassembly anymore.

As no new segments will be considered, the chunk limit check will
return true on the next call.

11 years agostream: unify segment discard handling
Victor Julien [Thu, 24 Apr 2014 08:02:21 +0000 (10:02 +0200)] 
stream: unify segment discard handling

Have a single function StreamTcpReturnSegmentCheck determine if a
segment is ready to be removed from the stream.

Handle FLOW_NOPAYLOAD_INSPECT in raw reassembly.

11 years agoapp-layer: improve no payload inspect flag
Victor Julien [Wed, 23 Apr 2014 15:55:24 +0000 (17:55 +0200)] 
app-layer: improve no payload inspect flag

If setting APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD, trigger raw
reassembly.

11 years agotls/heartbleed: fix test
Victor Julien [Wed, 23 Apr 2014 14:09:09 +0000 (16:09 +0200)] 
tls/heartbleed: fix test

Now that we continue to track ssl/tls after the handshake, we need
to fix tests that checked for the cutoff flags.

11 years agotls/heartbleed: improve encrypted logic
Victor Julien [Wed, 23 Apr 2014 13:53:25 +0000 (15:53 +0200)] 
tls/heartbleed: improve encrypted logic

Don't assume that if the type field isn't 01 or 02 it's an encrypted
heartbeat. Instead, use our knowledge of the SSL state.

11 years agotls/heartbleed: formatting fixes
Victor Julien [Wed, 23 Apr 2014 13:40:25 +0000 (15:40 +0200)] 
tls/heartbleed: formatting fixes

11 years agotls/heartbleed: add rule for invalid encrypted hb
Victor Julien [Wed, 23 Apr 2014 13:38:32 +0000 (15:38 +0200)] 
tls/heartbleed: add rule for invalid encrypted hb

Add rule to tls-events.rules to match on the invalid encrypted
heartbeat.

11 years agoLook for Mismatched Encrypted HB request and response sizes, along with multiple...
Will Metcalf [Tue, 22 Apr 2014 16:11:32 +0000 (11:11 -0500)] 
Look for Mismatched Encrypted HB request and response sizes, along with multiple in-flight HB requests from the same direction

11 years agodetect: add more defensive checks for flow handling
Victor Julien [Wed, 30 Apr 2014 07:57:09 +0000 (09:57 +0200)] 
detect: add more defensive checks for flow handling

Don't unconditionally deref f->alparser in detection through
DeStateFlowHasInspectableState(). In very rare cases it can
be NULL.

11 years agohttp-json: init 'fields' to 0 before setting it
Victor Julien [Fri, 2 May 2014 09:01:18 +0000 (11:01 +0200)] 
http-json: init 'fields' to 0 before setting it

httplog_ctx->fields would not be initialized before setting flags in
it:

Scanbuild:
output-json-http.c:491:46: warning: The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage
                            http_ctx->fields |= (1<<f);
                            ~~~~~~~~~~~~~~~~ ^
1 warning generated.

Drmemory:
~~27874~~ Error #1: UNINITIALIZED READ: reading register eax
~~27874~~ # 0 JsonHttpLogJSON                       [/home/buildbot/qa/buildbot/donkey/drmemory/Suricata/src/output-json-http.c:260]
~~27874~~ # 1 JsonHttpLogger                        [/home/buildbot/qa/buildbot/donkey/drmemory/Suricata/src/output-json-http.c:375]

Just memset the whole structure right after initialition.

11 years agojson: address custom output capability to http eve log review comments 956/head
Tom DeCanio [Thu, 24 Apr 2014 01:08:18 +0000 (18:08 -0700)] 
json: address custom output capability to http eve log review comments

11 years agojson: add custom output capability to http eve log
Tom DeCanio [Wed, 16 Apr 2014 23:59:43 +0000 (16:59 -0700)] 
json: add custom output capability to http eve log

11 years agodoxygen: add source browser 953/head
Eric Leblond [Wed, 23 Apr 2014 10:23:33 +0000 (12:23 +0200)] 
doxygen: add source browser

11 years agorohash: fix potential bad shift 952/head
Victor Julien [Wed, 23 Apr 2014 09:00:02 +0000 (11:00 +0200)] 
rohash: fix potential bad shift

Fix issue detected byCoverity:

*** CID 1197756:  Bad bit shift operation  (BAD_SHIFT)
/src/util-rohash.c: 74 in ROHashInit()
68         }
69         if (hash_bits < 4 || hash_bits > 32) {
70             SCLogError(SC_ERR_HASH_TABLE_INIT, "invalid hash_bits setting, valid range is 4-32");
71             return NULL;
72         }
73
>>>     CID 1197756:  Bad bit shift operation  (BAD_SHIFT)
>>>     In expression "1U << hash_bits", left shifting by more than 31 bits has undefined behavior.  The shift amount, "hash_bits", is as much as 32.
74         uint32_t size = hashsize(hash_bits) * sizeof(ROHashTableOffsets);
75
76         ROHashTable *table = SCMalloc(sizeof(ROHashTable) + size);
77         if (unlikely(table == NULL)) {
78             SCLogError(SC_ERR_HASH_TABLE_INIT, "failed to alloc memory");
79             return NULL;

This was only a potential issue as ROHashInit was only called with
hash_bits 16 in the code.

Bug #1170.

11 years agoaf-packet: exit in case of a fatal error 951/head
Eric Leblond [Wed, 23 Apr 2014 09:21:11 +0000 (11:21 +0200)] 
af-packet: exit in case of a fatal error

During socket creation all error cases were leading to suricata to
retry the opening of capture. This patch updates this behavior to
have fatal and recoverable error case. In case of a fatal error,
suricata is leaving cleanly.

11 years agoDAG: Pull some raw values out into defines. 950/head
Jason Ish [Tue, 22 Apr 2014 23:00:48 +0000 (17:00 -0600)] 
DAG: Pull some raw values out into defines.

11 years agoDAG: Consistent code style.
Jason Ish [Tue, 22 Apr 2014 22:21:51 +0000 (16:21 -0600)] 
DAG: Consistent code style.

11 years agoDAG: Sync dag packet and drop counts to live device on exit for better exit
Jason Ish [Tue, 22 Apr 2014 21:45:55 +0000 (15:45 -0600)] 
DAG: Sync dag packet and drop counts to live device on exit for better exit
logging.

11 years agojson-file: improve error handling
Victor Julien [Tue, 22 Apr 2014 15:47:54 +0000 (17:47 +0200)] 
json-file: improve error handling

If the functions getting uri, etc fail. Return "unknown" instead of
NULL pointer. This improves consistency.

11 years agojson-file: check pointer before using
Victor Julien [Tue, 22 Apr 2014 15:45:45 +0000 (17:45 +0200)] 
json-file: check pointer before using

A check was missing to see if ht_ud was not null before using the
pointer. This should be rare, but it can happen.

Reported-by: Will Metcalf
11 years agostream: improve retransmission handling 946/head
Victor Julien [Tue, 22 Apr 2014 15:14:10 +0000 (17:14 +0200)] 
stream: improve retransmission handling

Improve retransmission handling in the CLOSE_WAIT state.

Bug #1180.

11 years agostream: update GAP detection 945/head
Victor Julien [Wed, 16 Apr 2014 16:10:22 +0000 (18:10 +0200)] 
stream: update GAP detection

Change GAP detection logic. If we encounter missing data before
last_ack, we know we have missed data. The receiving host has ack'd
it already, so a retransmission of the missing data is highly
unlikely.

11 years agostream: fix raw reassembly flag issue
Victor Julien [Fri, 11 Apr 2014 15:31:46 +0000 (17:31 +0200)] 
stream: fix raw reassembly flag issue

AppLayer reassembly correctly only flags a segment as done when it's
completely used in reassembly. Raw reassembly could flag a partially
used segment as complete as well. In this case the segment could be
discarded early. Further reassembly would miss data, leading to a
gap. Due to this, up to 'window size' bytes worth of segments could
remain in the session for a long time, leading to memory resource
pressure.

This patch sets the flag correctly.

11 years agostream: improve StreamTcpPruneSession
Victor Julien [Fri, 11 Apr 2014 15:26:47 +0000 (17:26 +0200)] 
stream: improve StreamTcpPruneSession

Check if a segment is done for the app-layer using
StreamTcpAppLayerSegmentProcessed instead of the flag directly so the
gap case works better.

11 years agostream: flags cleanup
Victor Julien [Fri, 11 Apr 2014 15:24:12 +0000 (17:24 +0200)] 
stream: flags cleanup

Stream flags are 16bit, but notation is still 8bit. Clean this up to
avoid confusion.

11 years agoprotocol detection: handle very unbalanced case
Victor Julien [Fri, 11 Apr 2014 10:20:04 +0000 (12:20 +0200)] 
protocol detection: handle very unbalanced case

Some traffic is very unbalanced. For example a 4 bytes request
followed by 12mb of response data. If the 4 bytes don't lead to
the protocol being detected, then app layer processing won't
start, but it will not give up either. It will just wait for more
data. This leads to piling up data on the opposite side.

Observed:

TS: 4 bytes. PP failed (bit set), PM has not given up (bit not set).
    This makes sense as max_depth is not yet reached.

TC: 12mb. PP and PM failed (bits set).

As ts-PM never gives up, we never consider proto detect complete,
so all segments in either direction are still kept in the session.

This patch adds a cutoff for this case:
- IF for TS we have PP bit set, PM not set, AND
- we have TC both bits set, AND
- proto is unknown, AND
- TC data is 100k already, THEN
- give up on protocol detection.

The same for the opposite direction.

11 years agostream: improve midstream reassembly gap detection
Victor Julien [Fri, 11 Apr 2014 08:11:04 +0000 (10:11 +0200)] 
stream: improve midstream reassembly gap detection

The reassembly gap detection makes use of the window. However, in
midstream mode the window size we use is unreliable, as we have to
assume window scaling is in place. This patch improves midstream
handling of those cases.

11 years agostream: detect data gap at stream start
Victor Julien [Fri, 11 Apr 2014 08:08:55 +0000 (10:08 +0200)] 
stream: detect data gap at stream start

In midstream mode we may encounter a case where the data we is beyond
the isn, but below last_ack. This means we're missing some data, that
is already acked so it won't be retransmitted. Therefore, we can
conclude it's a data gap.

11 years agoproto detect: add cutoff for unbalanced traffic
Victor Julien [Wed, 22 Jan 2014 18:06:31 +0000 (19:06 +0100)] 
proto detect: add cutoff for unbalanced traffic

If we're getting a lot of data in one direction and the proto for this
direction is unknown, proto detect will hold up segments in the segment
list in the stream. They are held so that if we detect the protocol on
the opposing stream, we can still parse this side of the stream as well.
However, some sessions are very unbalanced. FTP data channels, large
PUT/POST request and many others, can lead to cases where we would have
to store many megabytes worth of segments before we see the opposing
stream. This leads to risks of resource starvation.

In this patch, a cutoff point is enforced. If we've stored 100k in one
direction and we've seen no data in the other direction, we give up.

If we've given up, the applayer_proto_detection_skipped event is set.
    app-layer-event: applayer_proto_detection_skipped;

11 years agoprotocol detection: midstream handling update
Victor Julien [Thu, 10 Apr 2014 15:59:18 +0000 (17:59 +0200)] 
protocol detection: midstream handling update

If a TCP session is midstream, we may end up with a case where the
start of an HTTP request is missing. We won't detect HTTP based on
the request. However, the reply is fine, so we detect HTTP anyway.
This leads to passing the incomplete request to the htp parser.

This has been observed, where the http parser then saw many bogus
requests in the incomplete data. This is not limited to HTTP.

To counter this case, a midstream session MUST find it's protocol
in the toserver direction. If not, we assume the start of the
request/toserver is incomplete and no reliable detection and parsing
is possible. So we give up.

11 years agostream: fix midstream syn/ack setup
Victor Julien [Thu, 10 Apr 2014 15:26:00 +0000 (17:26 +0200)] 
stream: fix midstream syn/ack setup

If midstream is enabled and the first packet is the syn/ack packet from
the 3whs, initialized server.last_ack to the packets seq.

This fixes tracking the session.

11 years agobyte-test: switch to pcre_copy_substring 944/head
Victor Julien [Mon, 21 Apr 2014 17:38:22 +0000 (19:38 +0200)] 
byte-test: switch to pcre_copy_substring

Fixes cppcheck:
[src/detect-bytejump.c:360]: (error) Uninitialized variable: str_ptr
[src/detect-bytejump.c:372]: (error) Uninitialized variable: str_ptr
[src/detect-bytejump.c:375]: (error) Uninitialized variable: str_ptr

Bug #1046.

11 years agobyte-extract: switch to pcre_copy_substring
Victor Julien [Mon, 21 Apr 2014 16:23:31 +0000 (18:23 +0200)] 
byte-extract: switch to pcre_copy_substring

Fixes memory leaks (str_ptr was never freed).
Fixes cppcheck warning:
    [src/detect-byte-extract.c:268]: (error) Uninitialized variable: str_ptr

Bug #1046.

11 years agodns: improve response name parsing 943/head
Victor Julien [Fri, 18 Apr 2014 18:25:22 +0000 (20:25 +0200)] 
dns: improve response name parsing

Improve parsing of names with multiple pointers following each other.

11 years agopacket handling: fix release function
Eric Leblond [Thu, 10 Apr 2014 11:11:34 +0000 (13:11 +0200)] 
packet handling: fix release function

Extended data were freed before the release function was called.
The result was that, in AF_PACKET IPS mode, the release function
was only sending void data because it the content of the extended
data is the content of the packet.

This patch updates the code to have the freeing of extended data
done in the cleaning function for a packet which is called by the
release function. This improves consistency of the code and fixes
the bug.

11 years agoproto-detect: masks cleanup 941/head
Victor Julien [Thu, 3 Apr 2014 14:42:42 +0000 (16:42 +0200)] 
proto-detect: masks cleanup

The direction specific masks were not used correctly. The toserver ones
were only used for 'dp' registrations, the toclient ones only for 'sp'.

The patch merges them.

11 years agoproto-detect: update port logic
Victor Julien [Thu, 3 Apr 2014 11:55:22 +0000 (13:55 +0200)] 
proto-detect: update port logic

If a flow matches both an 'sp' based PP registration and a 'dp' based,
until now we would only check the 'dp' one. This patch changes that. It
will inspect both.

11 years agoapp-layer: proto detection update
Victor Julien [Thu, 27 Mar 2014 15:13:08 +0000 (16:13 +0100)] 
app-layer: proto detection update

Instead of the notion of toserver and toclient protocol detection, use
destination port and source port.

Independent of the data direction, the flow's port settings will be used
to find the correct probing parser, where we first try the dest port,
and if that fails the source port.

Update the configuration file format, where toserver is replaced by 'dp'
and toclient by 'sp'. Toserver is intrepreted as 'dp' and toclient as
'sp' for backwards compatibility.

Example for dns:

    dns:
      # memcaps. Globally and per flow/state.
      #global-memcap: 16mb
      #state-memcap: 512kb

      # How many unreplied DNS requests are considered a flood.
      # If the limit is reached, app-layer-event:dns.flooded; will match.
      #request-flood: 500

      tcp:
        enabled: yes
        detection-ports:
          dp: 53
      udp:
        enabled: yes
        detection-ports:
          dp: 53

Like before, progress of protocol detection is tracked per flow direction.

Bug #1142.

11 years agostream: improve retransmission handling
Victor Julien [Wed, 16 Apr 2014 10:55:09 +0000 (12:55 +0200)] 
stream: improve retransmission handling

When connection are closing, don't reject retransmissions of data
packets.

Bug #1180.

11 years agorefactor IDS/IPS engine mode logic
Victor Julien [Tue, 15 Apr 2014 15:01:52 +0000 (17:01 +0200)] 
refactor IDS/IPS engine mode logic

Instead of error phrone externs with macro's, use functions with a local
static enum var instead.

- EngineModeIsIPS(): in IPS mode
- EngineModeIsIDS(): in IDS mode

To set the modes:

- EngineModeSetIDS(): IDS mode (default)
- EngineModeSetIPS(): IPS mode

Bug #1177.

11 years agoFix unaligned load in AC-TILE MPM.
Ken Steele [Tue, 15 Apr 2014 14:18:30 +0000 (10:18 -0400)] 
Fix unaligned load in AC-TILE MPM.

The SLOAD define using __insn_ld2s_L2 is used to provide a compiler
hint that the load will come from the L2 cache instead of the L1. It
also specifies that it is a 2 byte signed load. For the Tiny MPM, that
needs to be a 1-byte load, which is what is specified in util-ac-mpm-tile.c,
but the #undef was removing that definition.

11 years agodetect: fix alstate handling 940/head
Victor Julien [Tue, 15 Apr 2014 10:39:22 +0000 (12:39 +0200)] 
detect: fix alstate handling

Previously, the alstate use in the main detect loop was unsafe. The
alstate pointer would be set duing a lock, but it would again be used
after one or more lock/unlock cycles. If the data pointed to would
disappear, a dangling pointer would be the result.

Due to they way flows are cleaned up using reference counting and
such, changes of this happening were very small. However, at least
one path can lead to this situation. So it had to be fixed.

11 years agodetect: locking update continued
Victor Julien [Tue, 15 Apr 2014 10:23:21 +0000 (12:23 +0200)] 
detect: locking update continued

Make DeStateDetectContinueDetection get it's own alstate pointer instead
of using the one that was passed to it. We now get and use it only
inside a flow lock.

11 years agodetect: locking update
Victor Julien [Tue, 15 Apr 2014 09:18:47 +0000 (11:18 +0200)] 
detect: locking update

Make DeStateDetectStartDetection get it's own alstate pointer instead
of using the one that was passed to it. We now get and use it only
inside a flow lock.

11 years agodetect: cleanup
Victor Julien [Tue, 15 Apr 2014 09:05:17 +0000 (11:05 +0200)] 
detect: cleanup

Remove unused alstate and app layer flags arguments from
DetectEngineInspectPacketPayload()

11 years agodetect: modify AMATCH locking
Victor Julien [Tue, 15 Apr 2014 08:31:48 +0000 (10:31 +0200)] 
detect: modify AMATCH locking

This is an intrusive change. This patch modifies the way AMATCH
inspection uses locking.

So far, each keyword did it's own locking. This lead to a situation
where a 'alstate' pointer was passed around that was not always
protected by a lock.

This patch moves the locking to the Stateful detection functions.

11 years agoaf-packet: fix error handling 931/head
Eric Leblond [Fri, 11 Apr 2014 10:14:01 +0000 (12:14 +0200)] 
af-packet: fix error handling

Only exit from synchronization loop on poll error and not in case
of a timeout.

11 years agoutil-ioctl: only get MTU when iface name is set
Eric Leblond [Thu, 10 Apr 2014 09:05:46 +0000 (11:05 +0200)] 
util-ioctl: only get MTU when iface name is set

This patch fixes a warning message when suricata is started without
giving an interface name on the command line. The code was trying
to get the MTU even if pcap_dev was not set.

11 years agoFix 2 compiler warnings 930/head
Victor Julien [Sun, 13 Apr 2014 08:35:36 +0000 (10:35 +0200)] 
Fix 2 compiler warnings

FreeBSD 10 32-bit with clang 3.3:

log-tlslog.c:172:14: error: format specifies type 'long' but the argument has type 'time_t' (aka 'int') [-Werror,-Wformat]
             p->ts.tv_sec,
             ^~~~~~~~~~~~
1 error generated.

detect-engine-payload.c:508:27: warning: format specifies type 'long' but the argument has type 'time_t' (aka 'int') [-Wformat]
    printf("%ld.%06ld\n", tv_diff.tv_sec, (long int)tv_diff.tv_usec);
            ~~~           ^~~~~~~~~~~~~~
            %d
1 warning generated.

11 years agooutput-api: cleanup handling 926/head
Victor Julien [Thu, 10 Apr 2014 07:45:21 +0000 (09:45 +0200)] 
output-api: cleanup handling

Add output 'free list' that contains all the output ctx' that need
cleanup at shutdown. It differs from the runmode output list in that
it will also contain a 'parent' for the submodules that share the
context of it's parent.

11 years agooutput api: complete shutdown functions
Victor Julien [Thu, 10 Apr 2014 07:43:50 +0000 (09:43 +0200)] 
output api: complete shutdown functions

Add missing function for Filedata API. Clean up list in all functions.

11 years agotls-json: add cleanup function
Victor Julien [Thu, 10 Apr 2014 07:41:52 +0000 (09:41 +0200)] 
tls-json: add cleanup function

Properly clean up output context when shutting down.