]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
6 years agochangelog: update for 4.0.7 master-4.0.x 4329/head suricata-4.0.7
Victor Julien [Wed, 6 Mar 2019 14:06:19 +0000 (15:06 +0100)] 
changelog: update for 4.0.7

6 years agonetmap: refresh netmap_if address after each NIOCREGIF
Murat Balaban [Wed, 27 Feb 2019 17:09:13 +0000 (09:09 -0800)] 
netmap: refresh netmap_if address after each NIOCREGIF

With the introduction of netmap "partial opening" feature
netmap requires that we get a new NETMAP_IF pointer after
every `NIOCREGIF` registration. Because this allocates an
independent instance of `struct netmap_if`. If one
separately opens hw rings and sw rings he/she'll get two
`struct netmap_if`, one with the valid hw rings, and the other
with valid sw rings.

Because of that we get a new netmap_if pointer after each
NIOCREGIF.

Also removing netmap_if struct from NetmapDevice since
it's no more required.

Ticket #2855.

6 years agodetect/pcre: fix memory read error in detect
Victor Julien [Wed, 20 Feb 2019 15:58:34 +0000 (16:58 +0100)] 
detect/pcre: fix memory read error in detect

Fix case where a HTTP modifier in PCRE statements in a rule that would not
set the http protocol, would lead to a HTTP condition being run against
a non-HTTP flow. This would lead to invalid memory access.

Fix by properly setting the alproto and SIG_FLAG_APPLAYER flag in the
signature, leading to the signature implicitly setting the protocol
so rejecting it for inspection when the flow has a different protocol.

Bug #2863

6 years agoaf-packet: fix v3 code using v2 union member
Victor Julien [Sat, 2 Mar 2019 13:26:07 +0000 (14:26 +0100)] 
af-packet: fix v3 code using v2 union member

6 years agodcerpc/udp: fix int mishandling in opnum parsing 3663/head
Victor Julien [Fri, 25 Jan 2019 11:00:13 +0000 (12:00 +0100)] 
dcerpc/udp: fix int mishandling in opnum parsing

For Big Endian support in the protocol, the opnum would not be set
correctly.

Found using undefined sanitizer.

6 years agodetect/bytetest: don't print errors at runtime
Victor Julien [Fri, 25 Jan 2019 10:48:50 +0000 (11:48 +0100)] 
detect/bytetest: don't print errors at runtime

6 years agoissue 2795: python 3 fix in Rust C header gen
Jason Ish [Thu, 7 Feb 2019 19:53:23 +0000 (13:53 -0600)] 
issue 2795: python 3 fix in Rust C header gen

The C header generation script was failing with a unicode error
in Python 3 on FreeBSD.  Fix the reading of files to properly
handle unicode in all Python 3 environments.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2794

6 years agoconfigure.ac: fix --{disable,enable}-xxx options
Fabrice Fontaine [Thu, 31 Jan 2019 07:56:15 +0000 (08:56 +0100)] 
configure.ac: fix --{disable,enable}-xxx options

Currently, if the user provides --enable-libmagic or
--disable-libmagic, libmagic will be disabled because $enableval is not
used to know if the user provided --enable or --disable

Most of the options have this issue so fix them all by using $enableval

Fixes:
 - https://redmine.openinfosecfoundation.org/issues/2797

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
6 years agostream: fix false negative on bad RST
Victor Julien [Fri, 18 Jan 2019 14:03:39 +0000 (15:03 +0100)] 
stream: fix false negative on bad RST

If a bad RST was received the stream inspection would not happen
for that packet, but it would still move the 'raw progress' tracker
forward. Following good packets would then fail to detect anything
before the 'raw progress' position.

Bug #2770

Reported-by: Alexey Vishnyakov
6 years agoaf-packet: re-enable sync for tpacket v2
Victor Julien [Tue, 22 Jan 2019 20:28:40 +0000 (21:28 +0100)] 
af-packet: re-enable sync for tpacket v2

Synchronize start was disabled for v2 when v3 was introduced, without
a reason being given.

Re-enable as v2 will otherwise also start reading packets before the
other threads are set up. This will lead to hashing issues.

Part of bug #2788.

6 years agoaf-packet: fix sync start for tpacket v3
Victor Julien [Tue, 22 Jan 2019 20:00:57 +0000 (21:00 +0100)] 
af-packet: fix sync start for tpacket v3

The tpacket-v3 implementation of the synchonize start logic would
not correctly consider the timestamp parameter, leading to threads
starting before synchronization between threads was complete.

Bug #2788

6 years agonfqueue: inject fake packet on timeout
Alexander Gozman [Fri, 21 Dec 2018 16:16:29 +0000 (16:16 +0000)] 
nfqueue: inject fake packet on timeout

Fixes nfqueue and delayed-detect.

On systems with small amount of traffic (or with no traffic at all)
nfqueue with 'delayed-detect' enabled hanged in 'workers' mode.

Bug #2362.

6 years agococcinelle: add missing tests to make dist
Eric Leblond [Thu, 27 Dec 2018 22:01:43 +0000 (23:01 +0100)] 
coccinelle: add missing tests to make dist

6 years agoutil-binsearch: remove the files
Eric Leblond [Thu, 27 Dec 2018 20:49:31 +0000 (21:49 +0100)] 
util-binsearch: remove the files

6 years agoFixes other affected tests for smtp pipelining
Philippe Antoine [Wed, 5 Dec 2018 09:22:18 +0000 (10:22 +0100)] 
Fixes other affected tests for smtp pipelining

Either checking state has pipelining
Or removing pipelining from input

6 years agosmtp: improve pipelining support
Philippe Antoine [Wed, 5 Dec 2018 08:31:56 +0000 (09:31 +0100)] 
smtp: improve pipelining support

Fixes #1863

6 years agoproto/detect: workaround dns misdetected as dcerpc
Victor Julien [Wed, 19 Dec 2018 10:49:42 +0000 (11:49 +0100)] 
proto/detect: workaround dns misdetected as dcerpc

The DCERPC UDP detection would misfire on DNS with transaction
ID 0x0400. This would happen as the protocol detection engine
gives preference to pattern based detection over probing parsers for
performance reasons.

This hack/workaround fixes this specific case by still running the
probing parser if DCERPC has been detected on UDP. The probing
parser result will take precedence.

Bug #2736.

6 years agoproto/detect: minor cleanup
Victor Julien [Sun, 29 Jul 2018 11:12:21 +0000 (13:12 +0200)] 
proto/detect: minor cleanup

6 years agoteredo: be stricter on what to consider valid teredo
Victor Julien [Wed, 19 Dec 2018 08:45:35 +0000 (09:45 +0100)] 
teredo: be stricter on what to consider valid teredo

Invalid Teredo can lead to valid DNS traffic (or other UDP traffic)
being misdetected as Teredo. This leads to false negatives in the
UDP payload inspection.

Make the teredo code only consider a packet teredo if the encapsulated
data was decoded without any 'invalid' events being set.

Bug #2736.

6 years agodetect: fix crash during startup with malformed yaml
Victor Julien [Tue, 18 Dec 2018 20:08:19 +0000 (21:08 +0100)] 
detect: fix crash during startup with malformed yaml

detect-engine:
  custom-values:
    toclient-groups: 200
    toserver-groups: 200

Bug #2745

6 years agooffloading: on bsd, disable rxcsum and v6 variants
Victor Julien [Sat, 15 Dec 2018 14:57:31 +0000 (15:57 +0100)] 
offloading: on bsd, disable rxcsum and v6 variants

6 years agodetect/file-data: fix enabling http body tracking
Victor Julien [Thu, 13 Dec 2018 10:16:04 +0000 (11:16 +0100)] 
detect/file-data: fix enabling http body tracking

6 years agocapture: fix mtu plus sign names for non-netmap
Victor Julien [Mon, 10 Dec 2018 19:43:37 +0000 (20:43 +0100)] 
capture: fix mtu plus sign names for non-netmap

Bug #2502.

6 years agostats: more accurate interval handling
Victor Julien [Sat, 8 Dec 2018 17:51:23 +0000 (18:51 +0100)] 
stats: more accurate interval handling

In the stats loop sleep for a time period more closely matching
the stats.interval setting. Fix an off by one that would make
the loop wake up ~1 second early.

Bug #2716

6 years agounix-socket: fix pcap filename sets
Victor Julien [Mon, 10 Dec 2018 11:19:31 +0000 (12:19 +0100)] 
unix-socket: fix pcap filename sets

6 years agounix: fix deadlock in unix runmode on many cores
Victor Julien [Sun, 9 Dec 2018 08:05:44 +0000 (09:05 +0100)] 
unix: fix deadlock in unix runmode on many cores

Same issue as in 7f8795c7563827f090d8679cb35847af0085fc56, with the
solution now also applied to the unix socket runmode.

Bug #2735

6 years agorust/dns/lua - fix call convention to match C.
Jason Ish [Thu, 6 Dec 2018 17:16:00 +0000 (11:16 -0600)] 
rust/dns/lua - fix call convention to match C.

Also, when requesting the query, if the request doesn't exist,
return the query from the response. This makes it behave
more like C implementation.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2730

6 years agodetect/mpm: fix fast_pattern handling of len >255
Victor Julien [Sat, 1 Dec 2018 09:06:54 +0000 (10:06 +0100)] 
detect/mpm: fix fast_pattern handling of len >255

The fast pattern selection logic would truncate a patterns len to
255 leading to assigning the same pid to different patterns.

This in turn would be caught by the hyperscan setup code which would
abort.

Bug #2714.

6 years agochangelog: update for 4.0.6 3551/head suricata-4.0.6
Victor Julien [Tue, 6 Nov 2018 08:53:15 +0000 (09:53 +0100)] 
changelog: update for 4.0.6

6 years agosmtp/mime: fix null ptr deref on bad traffic
Victor Julien [Tue, 30 Oct 2018 15:10:33 +0000 (16:10 +0100)] 
smtp/mime: fix null ptr deref on bad traffic

Due to missing error handling, a bad mime message could put the
mime parser in an error state, without the SMTP layer taking this
into account. So the SMTP layer would continue to pass data to the
mime parser, even though it was in an error state.

When the parser would be fed a very long line while in this state,
it would try to set an error flag in the state. However, due to
the error state, this setting of the flag would dereference a null
pointer.

This patch fixes this issue by updating the mime parser to check
the state it is in when receiving new input. It will refuse to
process futher data while in the error state. It will also return
a new error code to indicate to the SMTP layer that the parser
was in an error state.

6 years agoaf-packet: improve error handling
Eric Leblond [Mon, 8 Oct 2018 21:51:37 +0000 (23:51 +0200)] 
af-packet: improve error handling

Stress condition in Suricata could lead to interface to disconnect
when it is not necessary. This patch updates the error handling
code to try to continue reading when such a case occurs.

6 years agostorage: don't leak memory for unittests 3538/head
Victor Julien [Fri, 26 Oct 2018 14:03:05 +0000 (16:03 +0200)] 
storage: don't leak memory for unittests

6 years agoradix: fix a memleak when removing the last node
Victor Julien [Fri, 26 Oct 2018 14:15:58 +0000 (16:15 +0200)] 
radix: fix a memleak when removing the last node

6 years agodetect/address: minor memory handling cleanups
Victor Julien [Thu, 25 Oct 2018 15:31:49 +0000 (17:31 +0200)] 
detect/address: minor memory handling cleanups

6 years agodetect: suppress scan-build warnings
Victor Julien [Thu, 25 Oct 2018 15:02:43 +0000 (17:02 +0200)] 
detect: suppress scan-build warnings

6 years agodetect/flags: cleanup parsing to not alloc temp strings
Victor Julien [Thu, 25 Oct 2018 10:30:12 +0000 (12:30 +0200)] 
detect/flags: cleanup parsing to not alloc temp strings

6 years agompm: fix minor scan-build warning
Victor Julien [Thu, 25 Oct 2018 09:55:05 +0000 (11:55 +0200)] 
mpm: fix minor scan-build warning

6 years agopool: avoid possible double free in error path
Victor Julien [Thu, 25 Oct 2018 09:44:53 +0000 (11:44 +0200)] 
pool: avoid possible double free in error path

Should be impossible as a double free, but scan-build-7 thinks it
is possible.

6 years agopool: small code cleanups
Victor Julien [Thu, 25 Oct 2018 09:44:15 +0000 (11:44 +0200)] 
pool: small code cleanups

6 years agostream: don't assume malformed TCP packets
Victor Julien [Thu, 25 Oct 2018 06:27:22 +0000 (08:27 +0200)] 
stream: don't assume malformed TCP packets

This deep in the stream engine packets are valid, so don't check
for the tcph header in a packet as it confuses scan-build.

Do add a DEBUG_VALIDATE_BUG_ON so in QA we double check.

6 years agodecode/tcp: rewrite options decoding to assist scan-build
Victor Julien [Wed, 24 Oct 2018 09:05:21 +0000 (11:05 +0200)] 
decode/tcp: rewrite options decoding to assist scan-build

6 years agosmb/c: don't accept null input
Victor Julien [Wed, 24 Oct 2018 08:58:58 +0000 (10:58 +0200)] 
smb/c: don't accept null input

6 years agohtp: fix potential (but unlikely) memleak in uri normalization
Victor Julien [Tue, 23 Oct 2018 14:17:26 +0000 (16:17 +0200)] 
htp: fix potential (but unlikely) memleak in uri normalization

6 years agothresholds: remove dead code in parsing
Victor Julien [Tue, 23 Oct 2018 13:10:56 +0000 (15:10 +0200)] 
thresholds: remove dead code in parsing

6 years agoradix: fix memory leak in error path
Victor Julien [Tue, 23 Oct 2018 13:08:05 +0000 (15:08 +0200)] 
radix: fix memory leak in error path

6 years agocoverity: suppress warnings
Victor Julien [Tue, 23 Oct 2018 13:01:42 +0000 (15:01 +0200)] 
coverity: suppress warnings

6 years agohost/os/info: fix lookup memleak
Victor Julien [Tue, 23 Oct 2018 12:59:15 +0000 (14:59 +0200)] 
host/os/info: fix lookup memleak

6 years agodebug/log: suppress coverity checked_return warning
Victor Julien [Tue, 23 Oct 2018 12:54:17 +0000 (14:54 +0200)] 
debug/log: suppress coverity checked_return warning

6 years agobpf: suppress coverity toctou warning
Victor Julien [Tue, 23 Oct 2018 12:53:28 +0000 (14:53 +0200)] 
bpf: suppress coverity toctou warning

6 years agopcap: fix buffer size validation logic
Victor Julien [Tue, 23 Oct 2018 12:51:25 +0000 (14:51 +0200)] 
pcap: fix buffer size validation logic

6 years agouricontent: move debug func into unittests
Victor Julien [Tue, 23 Oct 2018 12:43:35 +0000 (14:43 +0200)] 
uricontent: move debug func into unittests

Cleanup header, which lead to the app-layer-htp.h header needing to
be added in a few other places.

6 years agodetect/replace: fix mem leak in error path
Victor Julien [Tue, 23 Oct 2018 12:37:05 +0000 (14:37 +0200)] 
detect/replace: fix mem leak in error path

6 years agoisdataat: fix mem leak in error path
Victor Julien [Tue, 23 Oct 2018 12:34:08 +0000 (14:34 +0200)] 
isdataat: fix mem leak in error path

6 years agobits: avoid memory leak in case of adding types
Victor Julien [Tue, 23 Oct 2018 12:29:59 +0000 (14:29 +0200)] 
bits: avoid memory leak in case of adding types

6 years agoipproto: fix memleak in error case
Victor Julien [Tue, 23 Oct 2018 12:10:18 +0000 (14:10 +0200)] 
ipproto: fix memleak in error case

6 years agobytetest: don't leak memory in error condition
Victor Julien [Tue, 23 Oct 2018 11:56:50 +0000 (13:56 +0200)] 
bytetest: don't leak memory in error condition

6 years agoyaml: fix potential memleak and suppress coverity issue
Victor Julien [Tue, 23 Oct 2018 11:53:13 +0000 (13:53 +0200)] 
yaml: fix potential memleak and suppress coverity issue

6 years agooutputs: fix memleaks in the error paths reported by coverity
Victor Julien [Tue, 23 Oct 2018 11:49:37 +0000 (13:49 +0200)] 
outputs: fix memleaks in the error paths reported by coverity

6 years agocoverity: suppress warning for intentional code
Victor Julien [Tue, 23 Oct 2018 11:23:09 +0000 (13:23 +0200)] 
coverity: suppress warning for intentional code

6 years agorust/dns: don't compile unused C code if Rust is enabled
Victor Julien [Tue, 23 Oct 2018 11:21:08 +0000 (13:21 +0200)] 
rust/dns: don't compile unused C code if Rust is enabled

6 years agocoverity: don't warn on fall back random
Victor Julien [Tue, 23 Oct 2018 10:57:50 +0000 (12:57 +0200)] 
coverity: don't warn on fall back random

6 years agohttp: implement min size stream logic
Victor Julien [Fri, 17 Aug 2018 15:53:16 +0000 (17:53 +0200)] 
http: implement min size stream logic

Update HTTP parser to set the min inspect depth per transaction. This
allows for signatures to have their fast_pattern in the HTTP body,
while still being able to inspect the raw stream reliably with it.

The inspect depth is set per transaction as it:
- depends on the per personality config for min inspect size
- is set to the size of the actual body if it is smaller

After the initial inspection is done, it is set to 0 which disables
the feature for the rest of the transaction.

This removes the rescanning flush logic in commit
7e004f52c60c5e4d7cd8f5ed09491291d18f42d2 and provides an alternative
fix for bug #2522. The old approach caused too much rescanning of
HTTP body data leading to a performance degradation.

Bug #2522

6 years agostream: introduce min inspect depth logic
Victor Julien [Fri, 17 Aug 2018 08:41:51 +0000 (10:41 +0200)] 
stream: introduce min inspect depth logic

Some rules need to inspect both raw stream data and higher level
buffers together. When this higher level buffer is a streaming
buffer itself, the risk of mismatch exists.

This patch allows an app-layer parser to set a 'min inspect depth'.
The value is used by the stream engine to keep at least this
depth worth of data, so that the detection engine can request
all of it for inspection.

For rules that have the SIG_FLAG_FLUSH flag set, data is inspected
not from offset raw_progress, but from raw_progress minus
min_inspect_depth.

At this time this is only used for sigs that have their fast_pattern
in a HTTP body and have raw stream match as well.

6 years agogcc8: fix format truncation warnings
Victor Julien [Tue, 24 Apr 2018 10:01:40 +0000 (12:01 +0200)] 
gcc8: fix format truncation warnings

6 years agostream/tcp: be more liberal in last_ack
Victor Julien [Sun, 2 Sep 2018 09:34:42 +0000 (11:34 +0200)] 
stream/tcp: be more liberal in last_ack

Don't set even if seq is before next_seq, as this could still be
a valid packet that was sent before the state was reached.

6 years agostream/tcp: add debug statements to state dispatcher
Victor Julien [Sun, 2 Sep 2018 09:34:22 +0000 (11:34 +0200)] 
stream/tcp: add debug statements to state dispatcher

6 years agounittests: fix format-truncation warning
Victor Julien [Thu, 13 Sep 2018 10:18:32 +0000 (12:18 +0200)] 
unittests: fix format-truncation warning

6 years agoflow/timeout: code simplification and cleanup
Victor Julien [Wed, 29 Aug 2018 19:14:28 +0000 (21:14 +0200)] 
flow/timeout: code simplification and cleanup

6 years agoflow-manager: fix unittest initialization
Victor Julien [Sun, 26 Aug 2018 06:56:33 +0000 (08:56 +0200)] 
flow-manager: fix unittest initialization

6 years agoaf-packet: close the socket in case of early fail
Eric Leblond [Tue, 28 Aug 2018 20:46:25 +0000 (22:46 +0200)] 
af-packet: close the socket in case of early fail

6 years agolog-filestore: fix file descriptor leak
Eric Leblond [Wed, 22 Aug 2018 22:21:51 +0000 (00:21 +0200)] 
log-filestore: fix file descriptor leak

In the case we exceed the number of simultaneously open
file we can reach a state were we will not close the file
after writing.

Thanks to Steve Grubb <sgrubb@redhat.com> for the analysis.

6 years agodetect/prefilter: speed up setup
Victor Julien [Thu, 9 Aug 2018 22:06:24 +0000 (00:06 +0200)] 
detect/prefilter: speed up setup

If the global detect.prefilter.default setting is not "auto", it is
wasteful to run each prefilter setup routine. This patch tracks which
of the engines have been explicitly enabled in the rules and only
runs those.

6 years agodetect/prefilter: fix prefilter when setting is 'mpm'
Victor Julien [Thu, 9 Aug 2018 15:35:32 +0000 (17:35 +0200)] 
detect/prefilter: fix prefilter when setting is 'mpm'

When prefilter is not enabled globally, it is still possible to
enable it per signature. This was broken however, as the setup
code would never be called.

This commit always call the setup code and lets that sort out
which signatures (if any) to enable prefiltering for.

6 years agodetect: limit flush logic to sigs that need it
Victor Julien [Thu, 9 Aug 2018 13:32:49 +0000 (15:32 +0200)] 
detect: limit flush logic to sigs that need it

Limit the early 'flush' logic to sigs that actually need to match
on both stream and http bodies.

6 years agodetect/prefilter: fix alias for fast_pattern
Victor Julien [Thu, 9 Aug 2018 15:33:19 +0000 (17:33 +0200)] 
detect/prefilter: fix alias for fast_pattern

If prefilter is used on a content keyword, it acts as a simple
fast_pattern statement. This was broken because the SIG_FLAG_PREFILTER
flag bypasses MPM for a sig. This commits fixes this by not setting
the flag when it should act as fast_pattern.

6 years agodetect/http: flush bodies when inspecting stream
Victor Julien [Wed, 8 Aug 2018 12:06:43 +0000 (14:06 +0200)] 
detect/http: flush bodies when inspecting stream

The HTTP bodies (http_client_body and http_server_body/file_data) use
settings to control how much data we have before doing first inspection:

    request-body-minimal-inspect-size
    response-body-minimal-inspect-size

These settings default to 32k as quite some existing rules need this.

At the same time, the 'raw stream' inspection uses its own limits. By
default it inspects the data in blocks of about 2.5k. This could lead
to a situation where rules would not match.

For example, with 2 rules like this:

    content:"abc"; content:"data="; http_client_body; depth:5; sid:1;
    content:"xyz"; sid:2;

Sid 1 would only be inspected when the POST body reached the 32k limit
or when it was complete. Observed case shows the POST body to be 18k.
Sid 2 is inspected as soon as the 2.5k limit is reached, and then again
for each 2.5k increment. This moves the raw stream tracker forward.

So by the time sid 1 is inspected, some 18/19k into the stream, the
raw stream tracker is actually already moved forward for approximately
17.5k, this leads to the stream match of sid 1 possibly not matching.
Since the body match is at the start of the buffer, it makes sense
that the body and stream are inspected together.

The body inspection uses a tracker 'body_inspected', that keeps track
of how far into the body both MPM and per signature inspection has
moved.

This patch updates the logic in 2 ways:

1. it triggers earlier HTTP body inspection, which is matched to the
   stream inspection. When the detection engine finds it has stream
   data available for inspection, it passes the new 'STREAM_FLUSH'
   flag to the HTTP body inspection code. Which will then do an
   early inspection, even if still before the min inspect size.

2. to still somewhat adhere to the min inspect size, the body
   tracker is not updated until the min inspect size is reached.
   This will lead to some re-evaluation of the same body data.

If raw stream reassembly is disabled, this 'STREAM_FLUSH' flag is
never set, and the old behavior is used.

Bug #2522.

6 years agostream: improve TCP CLOSED handling
Victor Julien [Mon, 30 Jul 2018 08:26:21 +0000 (10:26 +0200)] 
stream: improve TCP CLOSED handling

Trigger app layer reassembly in both directions as soon as we've set
the TCP state to closed.

In IDS mode, if a toserver packet would close the state, the app layer
would not get updated until the next toclient packet. However, in
detection, the raw stream inspection would already use all available
stream data in detection and move the 'raw stream progress' tracker
forward. When in later (a) packet(s) the app layer was updated and
inspection ran on the app layer, the stream progress was already
moved too far forward. This would lead to signatures that matched
on both stream and app layer to not match.

By triggering the app layer reassembly as soon as the TCP state is
set to closed, the inspection as both the stream and app layer data
available at the same time so these rules can match.

Bug: #2570
Bug: #2554

6 years agodetect/files: don't prune files for bad packets
Victor Julien [Tue, 14 Aug 2018 12:33:20 +0000 (14:33 +0200)] 
detect/files: don't prune files for bad packets

A bad packet (rejected by stream engine) could still trigger a file
prune, even though (most of the) detection wouldn't happen for the
packet. The next valid packet would then not be able to match on the
file, as it was already freed.

This patch uses the same logic before file pruning as in the detect
engine.

Bug: 2576

6 years agodetect/filehash: try to open data file from rulefile dir
Victor Julien [Tue, 14 Aug 2018 08:17:37 +0000 (10:17 +0200)] 
detect/filehash: try to open data file from rulefile dir

If the data file can't be found in the default location, which
normally is 'default-rule-path', try to see if it can be found
in the path of the rule file that references it.

This makes QA much easier.

6 years agoflow: flag packets as established for async
Victor Julien [Tue, 7 Aug 2018 11:28:55 +0000 (13:28 +0200)] 
flow: flag packets as established for async

If a stream is async we see only on side of the traffic. This would
lead to the flow engine not flagging packets as 'established' even
if the flow state was in fact established. The flow was tagged as
such by the TCP engine.

This patch considers the flow state for setting the packet flag.

Bug #2491.

6 years agoenip: support gaps
Victor Julien [Tue, 21 Nov 2017 09:31:58 +0000 (10:31 +0100)] 
enip: support gaps

Due to a bug in the GAP handling the TCP layer the parser would already
get data after GAPs before.

6 years agostream: improve overlap detection
Victor Julien [Fri, 26 Jan 2018 08:14:16 +0000 (09:14 +0100)] 
stream: improve overlap detection

Improve detection of overlapping different data. Keep some data around
even if it was already ACK'd to check if packets have overlap.

6 years agostream-tcp: fix stream depth computation
Eric Leblond [Fri, 20 Apr 2018 17:23:21 +0000 (19:23 +0200)] 
stream-tcp: fix stream depth computation

The stream depth computation was partly done with the stream_config
depth instead of using the value in the TCP session. As a result,
some configuration were resulting in abnormal behavior.

In particular, when stream depth was 0 and the file store depth was
not 0, Suricata was stopping the streaming on the flow as soon as
the filestore was started.

Reported-by: Pascal Delalande <pdl35@free.fr>
6 years agostream: expand GAP detection
Victor Julien [Thu, 30 Aug 2018 13:03:34 +0000 (15:03 +0200)] 
stream: expand GAP detection

7 years agostream/app-layer: fix GAP handling issue
Victor Julien [Fri, 10 Nov 2017 22:03:16 +0000 (23:03 +0100)] 
stream/app-layer: fix GAP handling issue

Fix case where data after GAP was processed as in order data by app-layer.
This happened even if protocol parser did not register to accept GAPs.

7 years agodetect: fix fileext and filename negated match
Maurizio Abba [Tue, 31 Jul 2018 06:08:10 +0000 (07:08 +0100)] 
detect: fix fileext and filename negated match

fix bug in fileext and filename preventing negated match to work
correctly. Previously, negated fileext (such as !"php") would cause a
match anyway on files that have extension php, as the last if would not
be accessed.

Using the same workflow as detect-filemagic we remove the final
isolated if and set it as a branch of the previous if.

7 years agodcerpc: fix dce_iface not matching
Victor Julien [Wed, 1 Aug 2018 19:52:16 +0000 (21:52 +0200)] 
dcerpc: fix dce_iface not matching

7 years agochanglog: update for 4.0.5 3472/head suricata-4.0.5
Victor Julien [Mon, 16 Jul 2018 14:31:37 +0000 (16:31 +0200)] 
changlog: update for 4.0.5

7 years agompm/hs: fix minor coverity warning
Victor Julien [Tue, 3 Apr 2018 10:10:46 +0000 (12:10 +0200)] 
mpm/hs: fix minor coverity warning

CID 1428797 (#1 of 1): Unchecked return value (CHECKED_RETURN)
    check_return: Calling HashTableAdd without checking return value
    (as is done elsewhere 5 out of 6 times).

7 years agoenip: harden byte parsing code
Victor Julien [Thu, 19 Apr 2018 12:55:01 +0000 (14:55 +0200)] 
enip: harden byte parsing code

Make sure we never read more than we have.

Reported-by: Henning Perl
7 years agossh: fix out of bounds read in banner parsing
Victor Julien [Thu, 19 Apr 2018 09:27:43 +0000 (11:27 +0200)] 
ssh: fix out of bounds read in banner parsing

Reported-by: Henning Perl
7 years agorust/dns - remove extra parantheses
Jason Ish [Mon, 25 Jun 2018 14:40:54 +0000 (08:40 -0600)] 
rust/dns - remove extra parantheses

Removes rust compiler warning.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2521

7 years agodetect/debug: suppress noisy info messages
Victor Julien [Thu, 28 Jun 2018 08:43:25 +0000 (10:43 +0200)] 
detect/debug: suppress noisy info messages

7 years agoyaml-loader: fix memory leak on fail include
Jason Ish [Mon, 25 Jun 2018 13:08:38 +0000 (07:08 -0600)] 
yaml-loader: fix memory leak on fail include

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/1929

If an include failed to load, either by the file not existing or
a parse error, the file pointer and yaml parser instance were
leaked.

7 years agodetect: fix memory leak in app-layer-event keyword
Victor Julien [Wed, 4 Jul 2018 13:10:34 +0000 (15:10 +0200)] 
detect: fix memory leak in app-layer-event keyword

Bug #2515.

7 years agohttp: fix setting event on the last tx
Victor Julien [Thu, 5 Jul 2018 09:43:41 +0000 (11:43 +0200)] 
http: fix setting event on the last tx

7 years agohttp: set events for too many layers of compression
Victor Julien [Thu, 5 Jul 2018 08:01:47 +0000 (10:01 +0200)] 
http: set events for too many layers of compression

libhtp would already issue warnings, but these were not mapped
to events yet.

7 years agostream: support RST getting lost/ignored
Victor Julien [Thu, 10 May 2018 15:23:05 +0000 (17:23 +0200)] 
stream: support RST getting lost/ignored

In case of a valid RST on a SYN, the state is switched to 'TCP_CLOSED'.
However, the target of the RST may not have received it, or may not
have accepted it. Also, the RST may have been injected, so the supposed
sender may not actually be aware of the RST that was sent in it's name.

In this case the previous behavior was to switch the state to CLOSED and
accept no further TCP updates or stream reassembly.

This patch changes this. It still switches the state to CLOSED, as this
is by far the most likely to be correct. However, it will reconsider
the state if the receiver continues to talk.

To do this on each state change the previous state will be recorded in
TcpSession::pstate. If a non-RST packet is received after a RST, this
TcpSession::pstate is used to try to continue the conversation.

If the (supposed) sender of the RST is also continueing the conversation
as normal, it's highly likely it didn't send the RST. In this case
a stream event is generated.

Ticket: #2501

Reported-By: Kirill Shipulin
7 years agostream-events: fix mapping
Victor Julien [Mon, 21 May 2018 14:15:39 +0000 (16:15 +0200)] 
stream-events: fix mapping

7 years agodetect/stream_size: code cleanups
Victor Julien [Thu, 24 May 2018 12:56:03 +0000 (14:56 +0200)] 
detect/stream_size: code cleanups