Aaron Campbell [Mon, 2 Nov 2015 19:19:12 +0000 (15:19 -0400)]
Fix out-of-bounds memory access in DNS TXT record parser.
The datalen variable is declared unsigned. If txtlen and datalen are equal,
datalen will first be reduced to 0, and then the datalen-- line will cause its
value to wrap to 65535. This will cause the loop to continue much longer than
intended, and eventually may crash on an out-of-bounds *tdata dereference.
Jason Ish [Wed, 14 Oct 2015 19:37:45 +0000 (13:37 -0600)]
util-base64: strict mode - all characters must be valid
Introduce a strict mode to base64 decode. If strict,
the function will fail when invalid input data is seen.
If not strict, what has been decoded will be returned.
This is in support of adding a Snort compatible base64_decode
rule option that uses whatever data can be decoded as a length
of data to decode is optional.
Victor Julien [Mon, 23 Nov 2015 08:56:51 +0000 (09:56 +0100)]
json: fix malformed output
Even though the json output callback is called with a null terminated
string, it's not useable directly. The size parameter to the callback
might be a lot smaller than the string size. Libjansson gives the size
up to the first point that needs escaping.
Eric Leblond [Tue, 17 Nov 2015 08:56:55 +0000 (09:56 +0100)]
config: don't use hardcoded path
It is better to use a transformation to define the default
directory of output message instead of using an hardcoded value.
Same apply to the directory for the pid file.
Eric Leblond [Mon, 16 Nov 2015 16:53:04 +0000 (17:53 +0100)]
suricata: clean dump-config output
When user asks for a configuration dump, it is useless to display
the version and CPU info. Also initializing the log system conduct
to overwrite the some log files and in particular suricata.log and
this is annoying as a command should not interfere with a running
daemon.
cardigliano [Thu, 22 Oct 2015 09:55:57 +0000 (11:55 +0200)]
pfring pkt acq: keep running on 'pfring_set_cluster' failure when cluster is not required
Suricata creates a pfring cluster with a default ID = 1 when not explicitly configured,
unless the device has prefix 'dna' or 'zc'. Since pf_ring also supports other cards
implementing kernel-bypass (cluster not supported), this is preventing those cards from
running on top of this module. This patch stops suricata on 'pfring_set_cluster' failure
only when error code != PF_RING_ERROR_NOT_SUPPORTED or cluster ID has not been explicitly
configured.
Victor Julien [Fri, 23 Oct 2015 16:29:10 +0000 (18:29 +0200)]
threading: avoid autofp deadlock
When there are many threads and/or the packet pool (max-pending-packets) is
small, a potential dead lock exists between the packet pool return pool
logic and the capture threads. The autofp workers together can have all the
packets in their return pools, while the capture thread(s) are waiting at an
empty pool. A race between the worker threads and the capture thread, where
the latter signals the former, is lost by the capture thread. Now everyone
is waiting.
To avoid this scenario, this patch makes the previously hardcoded 'return
pool' threshold dynamic based on the number of threads and the packet pool
size.
It sets the threshold to the max pending packets value, divided by the number
of lister threads. The max value hasn't changed. Normally, in the autofp
runmode these are the stream/detect/log worker threads.
The max_pending_return_packets value needs to stay below the packet pool size
of the 'producers' (normally pkt capture threads but also flow timeout
injection) to avoid the deadlock.
As it's quite impossible at this time to learn how many threads will be
created before starting the runmodes, and thus spawning the threads and
already initializing the packet pools, this code sets a global variable
after runmode setup, but before the threads are 'unpaused'.
cardigliano [Wed, 21 Oct 2015 23:43:41 +0000 (01:43 +0200)]
pfring pkt acq: capture loop optimisation
For each packet the capture module checks whether it is time to dump stats calling
TimeGet(). TimeGet() is an expensive function using gettimeofday() or SCSpinLock()
which affect performance. Since gettimeofday() is already called for setting packet
timestamp, it is more efficient to use the packet timestamp directly.
cardigliano [Wed, 21 Oct 2015 23:26:54 +0000 (01:26 +0200)]
pfring pkt acq: use zero-copy recv in workers runmode
This patch removes packet copy when suricata is running in workers runmode,
packet copy is not needed in this case since packets are processed in sequence.
Eric Leblond [Thu, 17 Sep 2015 08:28:08 +0000 (10:28 +0200)]
util-logopenfile: move sensor_name to filectx
We will now output the sensor name independantly of the output
method if it is set in the YAML file. In the case of redis we are
using the hostname value if unset.
Eric Leblond [Mon, 25 May 2015 17:38:28 +0000 (19:38 +0200)]
util-logopenfile: reconnect handling
This patch implements reconnection handling for the redis output.
A reconnect limitation has been implemented with a limitation of
one connection per second.
Eric Leblond [Sun, 24 May 2015 19:52:56 +0000 (21:52 +0200)]
util-logopenfile: implement redis pipelining
This patch implements redis pipelining. This consist in contacting
the redis server every N events to minimize the number of TCP
exchange. This is optional and setup via the configuration file.
Eric Leblond [Sun, 24 May 2015 16:07:20 +0000 (18:07 +0200)]
util-logopenfile: introduce SCConfLogOpenRedis
Introduce a function to realize the parsing and config file and
opening of connection to the database. Only used by output-json
for now it will be usable by other logging modules.
Eric Leblond [Sun, 24 May 2015 15:43:51 +0000 (17:43 +0200)]
util-logopenfile: add write function
Introduce a function LogFileWrite that will handle the writing with
respect of the type defined in the configuration. This is used in
this patch to remove the write complexity from output-json.
Eric Leblond [Sat, 23 May 2015 14:59:16 +0000 (16:59 +0200)]
output-json: add sensor-name config variable
When using redis output, we are loosing the host key (added by
logstash or logstash-forwarder) and we can't find anymore what
Suricata did cause the alert.
This patch is adding this key during message generation using the
'sensor-name' variable or the hostname is 'sensor-name' is not
defined.
Giuseppe Longo [Mon, 12 Oct 2015 09:39:36 +0000 (11:39 +0200)]
decode: add flow memcap counter
This adds a counter indicating how many times
the flow max memcap has been reached
Since there is no always a reference to FlowManagerThreadData,
the counter is put in DecodeThreadVars.
Currently when there is no counter increase in one call of FlowGetNew
because we don't have tv or dtv at the time of the call.
The following is a snippet of the generated EVE entry:
"flow":{"memcap":0,"spare":10000,"emerg_mode_entered":0,"emerg_mode_over":0,"tcp_reuse":0,"memuse":7085248}
Eric Leblond [Wed, 21 Oct 2015 12:50:25 +0000 (14:50 +0200)]
json-email: fix coverity alert
The code was not correct and coverity did detect a potential
overflow problem that should not happen because of the structure
of md5 string and of format.
Jason Ish [Thu, 8 Oct 2015 20:54:57 +0000 (14:54 -0600)]
template app-layer: disable if not in config file (default)
Unlike other app-layer protocols which are enabled by default,
disable this one by default as it likely shouldn't be enabled
in production use of Suricata.
Eric Leblond [Wed, 14 Oct 2015 12:17:19 +0000 (14:17 +0200)]
json-email-common: fix email extended logging
Two structure fields were uninitialized and used has a bit field.
Weird behavior were seen in list of logged fields due to that with
some build options.
Alessandro Guido [Fri, 19 Jun 2015 14:57:48 +0000 (16:57 +0200)]
Add option to omit payload in unified2 output
Add a boolean option named "payload" to the unified2-alert output type.
Such options makes suricata omit the payload in the resulting unified2
file. The default value is true in order to preserve the current behaviour.
Jason Ish [Mon, 15 Jun 2015 17:14:16 +0000 (11:14 -0600)]
defrag: tracker initialization cleanup
Remove the old tracker reset macro which is no longer being used.
Clear last_seen and remove flags on initialization.
Remove extra call to DefragTrackerInit as it was being called 2x
for each new tracker.
Now that DefragTrackerNew is just a wrapper for DefragTrackerAlloc,
remove it and just call DefragTrackerAlloc directly.
Jason Ish [Mon, 15 Jun 2015 17:06:50 +0000 (11:06 -0600)]
defrag: don't use trackers marked for removal
These trackers are likely for completed fragments, but have
not been cleaned up. If a packet on the same flow with an
already seen IP ID is seen, it could be reused prior to
being properly reinitialized.
Eric Leblond [Fri, 2 Oct 2015 21:40:54 +0000 (23:40 +0200)]
decode-mime: fix body md5 computation
Previous code was wrongly supposing the lines are ending with CRLF.
But this is not the case so we must propagate the length of end of
line delimiter to be able to compute the md5 of the mail body.
Eric Leblond [Tue, 15 Sep 2015 14:34:44 +0000 (16:34 +0200)]
output-json: add create header with tx function
To be able to correlate between events, it is better to have the
tx_id information in the root object. This function adds a new
function to automate the addition of the field.