Commit Graph

8444 Commits (189b521239a2be4da2da833f9fd5b2474e4a9464)
 

Author SHA1 Message Date
Victor Julien 189b521239 pfring: fix vlan handling issues
When Suricata was monitoring traffic with a single vlan layer, the stats
and output instead showed 2. This was caused by the raw packets PF_RING
feeds Suricata would hold the vlan header, but the code assumed that
the header was stripped and the vlan_id passed to Suricata through
PF_RING's extended_hdr.parsed_pkt.

This patch adds the following logic: Check vlan id from the parser packet
PF_RING prepared. PF_RING sets the vlan_id based on its own parsing or
based on the hardware offload. It gives no indication on where the vlan_id
came from, so we rely on the vlan_offset field. If it's 0, we assume the
PF_RING parser did not see the vlan header and got it from the hardware
offload. In this case we will use this information directly, as we won't
get a raw vlan header later. If PF_RING did set the offset, we do the
parsing in the Suricata decoder so that we have full control.

PF_RING *should* put back the vlan header in all cases, and also set the
vlan_offset field, but as a extra precaution keep the check described
above.

Bug #2355.
7 years ago
Eric Leblond 711b6fb389 app-layer-ftp: add memcap for ftp
Add a memory cap for the FTP protocol.
7 years ago
Eric Leblond 24f745553c doc: update file extraction document
Define the list of protocol parsers supporting extraction in one
single place following Andreas Herz' suggestion.
7 years ago
Eric Leblond f5ba4c231d doc: update following ftp-data changes 7 years ago
Eric Leblond cbce2c78bd detect-ftpdata: match on ftp-data operation
This keyword mathes on ftp operation STOR and RETR. It will allow
rules writer to select if the alert has to be on a put or a fetch
operation.

It is now possible to write a signature like:

  alert ftp-data any any -> any any (msg:"FTP data get firwmare"; ftdata_command:retr; sid:2; rev:1;)

to alert when a file is retrieved from a FTP server.
7 years ago
Eric Leblond b0a6934431 app-layer-ftp: add ftp-data support
Use expectation to be able to identify connections that are
ftp data. It parses the PASV response, STOR message and the
RETR message to provide extraction of files.

Implementation in Rust of FTP messages parsing is available.

Also this patch changes some var name prefixed by ssh to ftp.
7 years ago
Eric Leblond 140f8baed9 app-layer-expectation: expectation system
This patch provides a working expectation system. This will allow
suricata to have a way to identify parallel connections opened by
a protocol such as FTP.

Expectation are a chained list and there is a cleaning by timeout
of the entries.

This patch also defined a counter of expectations that is also
used to check if we need to query IPPairs. This way we only query
the IPPairs store if we have an expectation.
7 years ago
Eric Leblond 31a0783865 app-layer: add Flow to probing parser functions 7 years ago
Eric Leblond 2d68050e60 flow: add parent_id field
This patch adds a parent_id field to the Flow structure that
contain the flow ID of the parent connection for protocol with
dynamic parallel connection opening like FTP.
7 years ago
Eric Leblond 5be5e7c879 detect: increase signature mask length 7 years ago
Eric Leblond 7f9f130ec3 suricata: storage early to get it everywhere 7 years ago
Giuseppe Longo 70695201f6 doc: add memcap commands in unix-socket section 7 years ago
Giuseppe Longo 16ddba61d6 suricatasc: add commands for memcap handling 7 years ago
Giuseppe Longo 3668ea2522 runmode-unix-socket: add commands for memcap handling
This permits to handle memcap values through
unix socket for:
- stream
- stream-reassembly
- flow
- applayer-proto-http
- defrag
- ippair
- host

It will be possible to show or change a memcap value
for a specified configuration and list all memcap values
available.

The following commands are registered for unix-socket:
- memcap-set
- memcap-show
- memcap-list

Output:
>>> memcap-show flow
Success:
{
    "value": "64mb"
}

>>> memcap-set flow 64mb
Success:
"memcap value for 'flow' updated: 67108864"

Command with invalid memcap key:
>>> memcap-set udp 32mb
Error:
"Available config: stream stream-reassembly flow applayer-proto-http defrag ippair host"

Command with an invalid memcap value:
>>> memcap-set http 32mmb
Error:
"error parsing memcap specified, value not changed"
7 years ago
Giuseppe Longo bba8cfb626 host: get/set memcap value
This adds new functions that will be called
through unix-socket and permit to update
and show memcap value.

The memcap value needs to be handled in a
thread safe way, so for this reason it is
declared as atomic var.

Another function is added to gets
the memuse value since it will be shown
through unix-socket.
7 years ago
Giuseppe Longo e4a18bb942 ippair: get/set memcap value
This adds new functions that will be called
through unix-socket and permit to update
and show memcap value.

The memcap value needs to be handled in a
thread safe way, so for this reason it is
declared as atomic var.

Another function is added to gets
the memuse value since it will be shown
through unix-socket.
7 years ago
Giuseppe Longo 0839d06514 defrag: get/set memcap value
This adds new functions that will be called
through unix-socket and permit to update
and show memcap value.

The memcap value needs to be handled in a
thread safe way, so for this reason it is
declared as atomic var.

Another function is added to gets
the memuse value since it will be shown
through unix-socket.
7 years ago
Giuseppe Longo 7addc24566 htp: destroy atomic vars
Atomic vars declared in app-layer-htp-mem.c were not
destroyed when suricata is shutdown.
7 years ago
Giuseppe Longo 85ddeb3afa htp: get/set memcap value
This adds new functions that will be called
through unix-socket and permit to update
and show memcap value.

The memcap value needs to be handled in a
thread safe way, so for this reason it is
declared as atomic var.
7 years ago
Giuseppe Longo 6fdad7d9e5 flow: get/set memcap value
This adds new functions that will be called
through unix-socket and permit to update
and show memcap value.

The memcap value needs to be handled in a
thread safe way, so for this reason it is
declared as atomic var.

FlowGetMemuse() function is made as public
because the memuse value will be shown
through unix-socket.
7 years ago
Giuseppe Longo 80bf728bfe stream-tcp: get/set memcap value
This adds new functions that will be called
through unix-socket and permit to update
and show memcap value.

The memcap value needs to be handled in a
thread safe way, so for this reason it is
declared as atomic var.
7 years ago
Giuseppe Longo 4a75eaf405 stream-tcp-reassemble: declare 'size' as uint64_t
According to all checking memcap functions,
the size passed as argument is declared as uint64_t
except for StreamTcpReassembleCheckMemcap where it's
defined as uint32_t.
7 years ago
Pierre Chifflier 802bdb2695 Hash table: free bucker in case of insertion error
This fixes a warning raised by cppcheck.
7 years ago
Pierre Chifflier bf166420fa Hash table: check hash array size when inserting element
If the hash function returns an index greater than the array size of the
hash table, the index is not checked. Even if this is the responsibility
of the caller, add a safety check to avoid errors.
7 years ago
Eric Leblond 3bf098e52f doc: document log reopen unix socket command 7 years ago
Eric Leblond 3205a8789b unix-socket: add logs reopen command
We did had a race condition with running logrotate with multiple
EVE Json files. Consequence was one of the file not being reopen
by suricata that did continue to write to the rotated one.

Trying fix on signal handler did fail so this patch implements
log rotation support by adding a dedicated command to unix socket
to reopen the log files.
7 years ago
Jason Ish cf8d770caa dns-log: don't register if HAVE_RUST
Log just one notice message when attempting to register
this logger with HAVE_RUST, instead of logging on
every attempt to output a DNS record.

Issue:
https://redmine.openinfosecfoundation.org/issues/2365
7 years ago
Jason Ish 5a8537fe4a rust/dns - convert more type values to text
Issue:
https://redmine.openinfosecfoundation.org/issues/2364

Convert more record type and errr code values to text.
Remove duplicate type declarations.
7 years ago
Wolfgang Hotwagner 9d1f07c021 Conf: Multipe NULL-pointer dereferences in PostConfLoadedSetup
Multiple NULL-pointer dereferences after ConfGet in PostConfLoadedSetup can cause suricata to terminate with segfaults. The ASAN-output:

ASAN:DEADLYSIGNAL =================================================================
5734ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f1a9a3967cc bp 0x7ffdff033ad0 sp 0x7ffdff033250 T0)
 0 0x7f1a9a3967cb (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x447cb)
 1 0x55ba65f66f27 in PostConfLoadedSetup /root/suricata-1/src/suricata.c:2652
 2 0x55ba65f6870e in main /root/suricata-1/src/suricata.c:2898
 3 0x7f1a96aeb2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
 4 0x55ba65af9039 in _start (/usr/local/bin/suricata+0xc8039)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x447cb)

This commit fixes Bug #2370 by replacing ConfGet by ConfGetValue
7 years ago
Wolfgang Hotwagner a463910ff2 Conf: Multipe NULL-pointer dereferences after ConfGetBool in StreamTcpInitConfig
There are multiple NULL-pointer dereferences after calling ConfGetBool in StreamTcpInitConfig. ConfGetBool calls ConfGet which doesn't check the vptr-argument. This is a sample ASAN-output:

1453ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f2969b83a28 bp 0x7ffdbf613a90 sp 0x7ffdbf613210 T0)
 0 0x7f2969b83a27 in strcasecmp (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x51a27)
 1 0x564185accefd in ConfValIsTrue /root/suricata-1/src/conf.c:559
 2 0x564185accb4f in ConfGetBool /root/suricata-1/src/conf.c:512
 3 0x564185dcbe05 in StreamTcpInitConfig /root/suricata-1/src/stream-tcp.c:381
 4 0x564185e21a88 in PreRunInit /root/suricata-1/src/suricata.c:2264
 5 0x564185e24d2c in PostConfLoadedSetup /root/suricata-1/src/suricata.c:2763
 6 0x564185e2570e in main /root/suricata-1/src/suricata.c:2898
 7 0x7f29662cb2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
 8 0x5641859b6039 in _start (/usr/local/bin/suricata+0xc8039)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x51a27) in strcasecmp
1453ABORTING

This commit replaces ConfGet by ConfGetValue in ConfGetBool. This does not only fix Bug #2368 but might also fix others too.
7 years ago
Wolfgang Hotwagner ed041239f3 Conf: Multipe NULL-pointer dereferences in HostInitConfig
Multiple NULL-pointer dereferences after ConfGet in HostInitConfig can cause suricata to terminate with segfaults. The ASAN-output:

==29747==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7ff937904646 bp
    0 0x7ff937904645 in strlen (/lib/x86_64-linux-gnu/libc.so.6+0x80645)
    1 0x7ff93b146eec  (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x3beec)
    2 0x5618387c86a3 in HostInitConfig /root/suricata-1/src/host.c:174
    3 0x56183893eccb in PostConfLoadedSetup /root/suricata-1/src/suricata.c:2752
    4 0x56183893f70e in main /root/suricata-1/src/suricata.c:2898
    5 0x7ff9378a42b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
    6 0x5618384d0039 in _start (/usr/local/bin/suricata+0xc8039)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libc.so.6+0x80645) in strlen

This commit fixes Bug #2367
7 years ago
Victor Julien 17e77346de content: fix depth/within, offset/distance mix 7 years ago
Jason Ish 84f09d5124 template scripts: fixup detect setup scripts
Update scripts to reflect recent changes in the detection files.
7 years ago
Andreas Herz d6c3a36113 detect-engine: add missing mutex unlock 7 years ago
Andreas Herz 77e548ed1c rule-reload: fix possible hangup with SIGUSR2
In some cases the rule reload could hang. The pending USR2 signals will
be recognized even with the <2 check. Also the SCLogWarning shouldn't be
used in the handler (see Warning about SCLog* API above in the code).
7 years ago
Victor Julien be9ec3958e doc: initial suricata-update page 7 years ago
Victor Julien 0f50dc1488 pcap-directory: fix double free in error path 7 years ago
Victor Julien 367cec6292 app-layer/counters: check counter id
Check counter id before updating a counter. In case of a disabled
parser with the protocol detection enable, the id can be 0. In
debug mode this would lead to a BUG_ON.
7 years ago
Danny Browning e2043668cb source-pcap-file: Fix coverity findings (Bug #2356)
https://redmine.openinfosecfoundation.org/issues/2356

Address issues found by coverity for resource leaks and use after free.
7 years ago
Danny Browning 75d7fdb693 suricata: pcap-file-continuous ignores other options (Bug #2253)
https://redmine.openinfosecfoundation.org/issues/2353

Command line option pcap-file-continuous was ignoring command line options
passed after its usage. Fixed bug, fixed formatting of help command
regarding pcap-file-continuous.
7 years ago
Victor Julien 91f95ace22 qa: add more drmemory suppressions for hyperscan 7 years ago
Victor Julien 611a2aca9f prefilter/profile: validate end > start
Seen underflow issues on profiling on arm (gettimeofday based.
7 years ago
Wolfgang Hotwagner 08971f1841 conf: multiple NULL-pointer dereferences in StreamTcpInitConfig
There are several NULL-pointer derefs in StreamTCPInitConfig. All of them happen because ConfGet returns 1 even if the value is NULL(due to misconfiguration for example).
This commit introduces a new function "ConfGetValue". It adds return values for NULL-pointer to ConfGet and could be used as a replacement for ConfGet.

Note: Simply modify ConfGet might not be a good idea, because there are some places where ConfGet should return 1 even if "value" is NULL. For example if ConfGet should get a Config-Leave in the yaml-hierarchy.

Bug: 2354
7 years ago
Wolfgang Hotwagner 7236e65d64 conf: multiple NULL-pointer dereferences in FlowInitConfig
This commit fixes multiple NULL-pointer dereferences in FlowInitConfig after reading in config-values(flow.hash-size, flow.prealloc and flow.memcap) for flow. Here is a sample ASAN-output:

=================================================================
ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fea73456646 bp 0x7fffd70e1ba0 sp 0x7fffd70e1328 T0)
0 0x7fea73456645 in strlen (/lib/x86_64-linux-gnu/libc.so.6+0x80645)
1 0x7fea76c98eec (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x3beec)
2 0x5643efb4c205 in FlowInitConfig /root/suricata-1/src/flow.c:455
3 0x5643efcd1751 in PreRunInit /root/suricata-1/src/suricata.c:2247
4 0x5643efcd49f4 in PostConfLoadedSetup /root/suricata-1/src/suricata.c:2748
5 0x5643efcd5402 in main /root/suricata-1/src/suricata.c:2884
6 0x7fea733f62b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
7 0x5643ef8761a9 in _start (/usr/local/bin/suricata+0xc51a9)

Ticketno: Bug #2349
7 years ago
Wolfgang Hotwagner 5370eb49ae conf: use of NULL-pointer in DetectLoadCompleteSigPath
The "sig_file" argument of DetectLoadCompleteSigPath() is not checked for NULL-values. If this argument is NULL a SEGV occurs because of a dereferenced NULL-pointer in strlen in PathIsAbsolute. This commit fixes bug #2347. Here is the ASAN-output:

==17170==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fd1afa00646 bp 0x7ffe8398e6d0 sp 0x7ffe8398de58 T0)
    0 0x7fd1afa00645 in strlen (/lib/x86_64-linux-gnu/libc.so.6+0x80645)
    1 0x7fd1b3242eec  (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x3beec)
    2 0x5561c8cddf7f in PathIsAbsolute /root/suricata-1/src/util-path.c:40
    3 0x5561c8cddfea in PathIsRelative /root/suricata-1/src/util-path.c:65
    4 0x5561c89275e4 in DetectLoadCompleteSigPath /root/suricata-1/src/detect.c:264
    5 0x5561c8929e75 in SigLoadSignatures /root/suricata-1/src/detect.c:486
    6 0x5561c8c0f2b3 in LoadSignatures /root/suricata-1/src/suricata.c:2419
    7 0x5561c8c1051d in PostConfLoadedDetectSetup /root/suricata-1/src/suricata.c:2550
    8 0x5561c8c12424 in main /root/suricata-1/src/suricata.c:2887
    9 0x7fd1af9a02b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
    10 0x5561c87b31a9 in _start (/usr/local/bin/suricata+0xc51a9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libc.so.6+0x80645) in strlen
7 years ago
Wolfgang Hotwagner c5c31886c8 conf: NULL-pointer dereference in ConfUnixSocketIsEnable
The value for the configuration-option "unix-command.enabled" is not properly checked in ConfUnixSocketIsEnable. This causes a NULL-pointer dereference in strcmp. This commit fixes bug #2346. The ASAN-output looks like:

ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f03b69737cc bp 0x7ffcef322c10 sp 0x7ffcef322390 T0)
0 0x7f03b69737cb (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x447cb)
1 0x5617a76d3f55 in ConfUnixSocketIsEnable /root/suricata-1/src/util-conf.c:104
2 0x5617a741b6e7 in DetectEngineMultiTenantSetup /root/suricata-1/src/detect-engine.c:2447
3 0x5617a769e0c3 in PostConfLoadedDetectSetup /root/suricata-1/src/suricata.c:2527
4 0x5617a76a0424 in main /root/suricata-1/src/suricata.c:2887
5 0x7f03b30c82b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
6 0x5617a72411a9 in _start (/usr/local/bin/suricata+0xc51a9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x447cb
7 years ago
Wolfgang Hotwagner cfd56f5ef7 conf: Memory-leak in DetectAddressTestConfVars
There is a memory-leak in DetectAddressTestConfVars. If the programm takes the "goto error"-path, the pointers gh and ghn will not be freed. This commit fixes bug #2345. Here is the ASAN-output:

=================================================================
ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
0 0x7f4347cb1d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
1 0x55fe1fc8dcfc in DetectAddressHeadInit /root/suricata-1/src/detect-engine-address.c:1534
2 0x55fe1fc8c50a in DetectAddressTestConfVars /root/suricata-1/src/detect-engine-address.c:1306
3 0x55fe1ff356bd in PostConfLoadedSetup /root/suricata-1/src/suricata.c:2696
4 0x55fe1ff365eb in main /root/suricata-1/src/suricata.c:2884
5 0x7f43443892b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

Direct leak of 24 byte(s) in 1 object(s) allocated from:
0 0x7f4347cb1d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
1 0x55fe1fc8dcfc in DetectAddressHeadInit /root/suricata-1/src/detect-engine-address.c:1534
2 0x55fe1fc8c524 in DetectAddressTestConfVars /root/suricata-1/src/detect-engine-address.c:1310
3 0x55fe1ff356bd in PostConfLoadedSetup /root/suricata-1/src/suricata.c:2696
4 0x55fe1ff365eb in main /root/suricata-1/src/suricata.c:2884
5 0x7f43443892b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

SUMMARY: AddressSanitizer: 48 byte(s) leaked in 2 allocation(s).
7 years ago
Victor Julien 99bf99c529 output: don't deadlock on log reopen failure
If output log reopen fails, don't try to output the error. This would
lead to a deadlock as reopen was called from a SCLogMessage call. This
call already held the output lock.

Bug #2306.
7 years ago
Victor Julien 56d93f426c configure: style fixup 7 years ago
Victor Julien 8b8f911600 detect: move rule loading into loader files 7 years ago