]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
10 years agostream/async: improve handling of syn/ack pickup 1194/head
Victor Julien [Thu, 30 Oct 2014 10:07:38 +0000 (11:07 +0100)] 
stream/async: improve handling of syn/ack pickup

If we picked up the ssn with a syn/ack, we don't need to make more
assumptions about sack and wscale after that.

10 years agostream/async: fix session setup issues
Victor Julien [Thu, 30 Oct 2014 09:16:40 +0000 (10:16 +0100)] 
stream/async: fix session setup issues

For these 2 cases:

1. Missing SYN:
-> syn <= missing
<- syn/ack
-> ack
-> data

2. Missing SYN and 3whs ACK:
-> syn <= missing
<- syn/ack
-> ack <= missing
-> data

Fix session pickup. The next_win settings weren't correctly set, so that
packets were rejected.

Bug 1190.

10 years agostream: improve tracking with pkt loss in async 1191/head
Victor Julien [Sun, 26 Oct 2014 09:07:15 +0000 (10:07 +0100)] 
stream: improve tracking with pkt loss in async

If 3whs SYN/ACK and ACK are missing we can still pick up the session if
in async-oneside mode.

-> syn
<- syn/ack <= missing
-> ack     <= missing
-> data

Bug 1190.

10 years agoiprep: cleanup ctx on shutdown
Victor Julien [Sun, 26 Oct 2014 08:02:08 +0000 (09:02 +0100)] 
iprep: cleanup ctx on shutdown

~~Dr.M~~ Error #1: LEAK 480 direct bytes 0x0aae7fc0-0x0aae81a0 + 0 indirect bytes
~~Dr.M~~ # 0 replace_malloc                    [/work/drmemory_package/common/alloc_replace.c:2373]
~~Dr.M~~ # 1 SRepInit                          [.../Suricata/src/reputation.c:594]
~~Dr.M~~ # 2 DetectEngineCtxInit               [.../src/detect-engine.c:844]
~~Dr.M~~ # 3 main                              [.../Suricata/src/suricata.c:2230]

10 years agoMake AppLayerProfiling functions inline 1184/head
Ken Steele [Mon, 6 Oct 2014 15:40:58 +0000 (11:40 -0400)] 
Make AppLayerProfiling functions inline

The entire body of these functions are protected by ifdef PROFILING.
If the functions are inlined, then this check removes the need for the
function entirely.

Previously, the empty function was still called, even when not built
for profiling. The functions showed as being 0.25% of total CPU time
without being built for profiling.

10 years agoFixes comments for pfring section in suricata.yaml
Giuseppe Longo [Thu, 23 Oct 2014 09:43:04 +0000 (11:43 +0200)] 
Fixes comments for pfring section in suricata.yaml

Bug #1301

10 years agoPF_RING: force cluster type if vlan is disabled
Giuseppe Longo [Thu, 23 Oct 2014 09:30:38 +0000 (11:30 +0200)] 
PF_RING: force cluster type if vlan is disabled

If vlan is disabled the cluster_flow mode will still take VLAN tags
into account due to using pf_ring's 6-tuple mode.
So this forces to use pf_ring's 5-tuple mode.

Bug #1292

10 years agoiprep: add unit tests for cidr
Giuseppe Longo [Fri, 5 Sep 2014 13:58:44 +0000 (15:58 +0200)] 
iprep: add unit tests for cidr

Implements unit tests to test the new API

10 years agodetect-iprep: extends cidr
Giuseppe Longo [Wed, 3 Sep 2014 13:30:08 +0000 (15:30 +0200)] 
detect-iprep: extends cidr

Adds new API to check if an IP address is belong
to a netblock and gets the value.

10 years agoiprep: extends cidr support
Giuseppe Longo [Fri, 29 Aug 2014 12:22:09 +0000 (14:22 +0200)] 
iprep: extends cidr support

Implements new API to expand the IP reputation
to netblocks with CIDR notation

A new object 'srepCIDRTree' is kept in the DetectionEngineCtx,
which contains two tree (one for ipv4 and one for ipv6)
where the reputation values are stored.

10 years agolua: add export of dns.rrname
Eric Leblond [Sat, 18 Oct 2014 17:38:12 +0000 (19:38 +0200)] 
lua: add export of dns.rrname

Add the capability for a lua script to ask for rrname in DNS query.

10 years agolua: move function to common utils
Eric Leblond [Sat, 18 Oct 2014 11:20:52 +0000 (13:20 +0200)] 
lua: move function to common utils

LuaStateNeedProto function can be used for any protocol so let's
move it out of the http file.

10 years agostream: improve bad window update detection 1182/head
Victor Julien [Thu, 23 Oct 2014 10:54:13 +0000 (12:54 +0200)] 
stream: improve bad window update detection

Ignore more valid ACKs in FIN shutdown phase.

Improve heuristic for window shrinking in case of packet loss.

10 years agostream: fix 'bad window update' false positive 1174/head
Victor Julien [Thu, 16 Oct 2014 16:38:19 +0000 (18:38 +0200)] 
stream: fix 'bad window update' false positive

ACK packets completing a valid FIN shutdown could be flagged as
'bad window update' if they would shrink the window.

This patch detects this case before doing the bad window update
check.

10 years agosanity check tcp SACK edges prior to recording. Attempt to avoid Cisco ASA
Tom DeCanio [Fri, 10 Oct 2014 16:40:37 +0000 (09:40 -0700)] 
sanity check tcp SACK edges prior to recording. Attempt to avoid Cisco ASA
tcp randomization issue with it not properly writing sequence numbers in SACK.

10 years agostream: improve handling of 3whs packet loss 1173/head
Victor Julien [Thu, 16 Oct 2014 12:59:38 +0000 (14:59 +0200)] 
stream: improve handling of 3whs packet loss

If the 3whs ACK and some data after this is lost, we would get stuck
in the 'SYN_RECV' state, where from there each packet might be
considered invalid.

This patch improves the handling of this case.

10 years agostream: fix ssh/ssl logging on tcp session reuse
Victor Julien [Thu, 16 Oct 2014 12:54:22 +0000 (14:54 +0200)] 
stream: fix ssh/ssl logging on tcp session reuse

TCP session reuse wouldn't unset FLOW_NO_APPLAYER_INSPECTION.

10 years agossh.softwareversion: allow more characters
Victor Julien [Thu, 16 Oct 2014 12:41:59 +0000 (14:41 +0200)] 
ssh.softwareversion: allow more characters

The keyword would not allow matching on "OpenSSH_5.5p1 Debian-6+squeeze5"
as the + and space characters were not allowed.

This patch adds support for them.

10 years agostream: add counter for failed pseudo setups
Victor Julien [Thu, 16 Oct 2014 09:17:06 +0000 (11:17 +0200)] 
stream: add counter for failed pseudo setups

Stream pseudo packets are taken from the packet pool, which can be empty.
In this case a pseudo packet will not be created and processed.

This patch adds a counter "tcp.pseudo_failed" to track this.

10 years agostream: clean up pseudo packet counting
Victor Julien [Thu, 16 Oct 2014 08:31:47 +0000 (10:31 +0200)] 
stream: clean up pseudo packet counting

Increment the counter from StreamTcpPseudoPacketCreateStreamEndPacket.

10 years agopfring: removes old API and #ifdef chunks
Giuseppe Longo [Thu, 16 Oct 2014 08:23:19 +0000 (10:23 +0200)] 
pfring: removes old API and #ifdef chunks

10 years agopfring: checks if the lib version is >= 6
Giuseppe Longo [Thu, 16 Oct 2014 08:22:33 +0000 (10:22 +0200)] 
pfring: checks if the lib version is >= 6

Checks if the PF_RING version installed on the system is 6,
so old version won't be supported.

10 years agoFix MPLS decoder rules. 1172/head
Jason Ish [Mon, 20 Oct 2014 21:13:28 +0000 (15:13 -0600)] 
Fix MPLS decoder rules.

10 years agoUse ENGINE_SET_INVALID_EVENT when the packet is too small for an
Jason Ish [Fri, 17 Oct 2014 15:33:07 +0000 (09:33 -0600)] 
Use ENGINE_SET_INVALID_EVENT when the packet is too small for an
MPLS header, and when the payload type can not be determined.

10 years agoDon't default to ethernet, ethernet should be preceded by a pseudowire.
Jason Ish [Wed, 8 Oct 2014 16:17:12 +0000 (10:17 -0600)] 
Don't default to ethernet, ethernet should be preceded by a pseudowire.

If the payload type can't be determined, raise an alert.

10 years agoSet decoder events for labels that shouldn't be seen on the wire.
Jason Ish [Wed, 13 Aug 2014 22:53:19 +0000 (16:53 -0600)] 
Set decoder events for labels that shouldn't be seen on the wire.
Add unit tests to test for mpls decoder events.

10 years agoHandle encapsulated ethernet without a PW by defaulting to ethernet
Jason Ish [Sat, 19 Jul 2014 02:23:28 +0000 (20:23 -0600)] 
Handle encapsulated ethernet without a PW by defaulting to ethernet
if a fall back.

10 years agoHandle explicitly IPv6 and IPv6 labels as well as encapsulated ethernet.
Jason Ish [Thu, 17 Jul 2014 17:28:56 +0000 (11:28 -0600)] 
Handle explicitly IPv6 and IPv6 labels as well as encapsulated ethernet.

10 years agoAdd MPLS counter.
Jason Ish [Thu, 17 Jul 2014 16:21:32 +0000 (10:21 -0600)] 
Add MPLS counter.
Check length before decoding each label.

10 years agoBasic MPLS decoder.
Jason Ish [Tue, 15 Jul 2014 19:48:34 +0000 (13:48 -0600)] 
Basic MPLS decoder.

10 years agoCUDA: Update the inspection engine to inform the cuda module that it 1171/head
Anoop Saldanha [Fri, 25 Jul 2014 07:50:28 +0000 (13:20 +0530)] 
CUDA: Update the inspection engine to inform the cuda module that it
doesn't need the gpu results and to release the packet for the next run.

Previously the inspection engine wouldn't inform the cuda module, if it
didn't need the results.  As a consequence, when the packet is next taken
for re-use, and if the packet is still being processed by the cuda module,
the engine would wait till the cuda module frees the packet.

This commits updates this functionality to inform the cuda module to
release the packet for the afore-mentioned case.

10 years agoCheck replist is not NULL inline before doing any processing.
Ken Steele [Fri, 17 Oct 2014 15:42:48 +0000 (11:42 -0400)] 
Check replist is not NULL inline before doing any processing.

The replist is often NULL, so it is worth checking that case before making
the function call do perform work on the list.

10 years agodetect-dce-opnum: add sanity check
Eric Leblond [Wed, 15 Oct 2014 17:38:20 +0000 (19:38 +0200)] 
detect-dce-opnum: add sanity check

Specifying the option dce_opnum without value was triggering a
segfault.

10 years agoFix typo in configure message about nfnetlink
Ken Steele [Thu, 2 Oct 2014 21:17:02 +0000 (17:17 -0400)] 
Fix typo in configure message about nfnetlink

10 years agopcap-log: add option to honor pass rules
Victor Julien [Mon, 4 Aug 2014 13:36:42 +0000 (15:36 +0200)] 
pcap-log: add option to honor pass rules

Add option (disabled by default) to honor pass rules. This means that
when a pass rule matches in a flow, it's packets are no longer stored
by the pcap-log module.

10 years agoBug 1230: Check all SigMatch lists for a named byte_extract variable.
Jason Ish [Mon, 29 Sep 2014 16:00:06 +0000 (10:00 -0600)] 
Bug 1230: Check all SigMatch lists for a named byte_extract variable.

10 years agoBug 1230: Simple test case demonstrating failure.
Jason Ish [Mon, 29 Sep 2014 15:37:03 +0000 (09:37 -0600)] 
Bug 1230: Simple test case demonstrating failure.

10 years agoSuppress ARM valgrind warning
Victor Julien [Sat, 18 Oct 2014 19:47:52 +0000 (21:47 +0200)] 
Suppress ARM valgrind warning

Not Suricata related, so suppress.

10 years agoSpeed up SigMatchGetLastSMFromLists()
Ken Steele [Tue, 7 Oct 2014 14:17:21 +0000 (10:17 -0400)] 
Speed up SigMatchGetLastSMFromLists()

SigMatchGetLastSMFromLists() is finding the sm with the largest
index among all of the values returned from SigMatchGetLastSM() on
the set of (list and type) tuples passed as arguments.

The function was creating an array of the types, then creating an array
of the results of SigMatchGetLastSM(), sorting that list completely, then
only returning the first values from the list.

The new code, gets one set of arguments from the variable arguments, calls
SigMatchGetLastSM() and if the returned sm has a larger index, keeps that
as the last sm.

10 years agotcp session reuse: reset detect state 1153/head
Victor Julien [Tue, 7 Oct 2014 09:27:54 +0000 (11:27 +0200)] 
tcp session reuse: reset detect state

Reset the detect state on TCP session reuse. We reset the app layer,
so we need to reset the stateful detection as well.

10 years agodetect state: always lock de_state_m
Victor Julien [Tue, 7 Oct 2014 09:25:25 +0000 (11:25 +0200)] 
detect state: always lock de_state_m

Always lock the de_state_m on access, also at flow recycle or
cleanup.

10 years agoconfigure.ac: Moved libpcap before libpfring
Mats Klepsland [Wed, 1 Oct 2014 15:33:58 +0000 (17:33 +0200)] 
configure.ac: Moved libpcap before libpfring

Moved the libpcap section in configure.ac before libpfring to
enable libpfring to use the specified libpcap includes and
libraries when testing for libpfring support.

Bug #1294

10 years agorunmode-pfring: Fixed typo s/fron/from/
Mats Klepsland [Wed, 1 Oct 2014 14:39:48 +0000 (16:39 +0200)] 
runmode-pfring: Fixed typo s/fron/from/

10 years agorunmode-pfring: Suppress errors when using DNA/ZC
Mats Klepsland [Wed, 1 Oct 2014 14:34:30 +0000 (16:34 +0200)] 
runmode-pfring: Suppress errors when using DNA/ZC

PF_RING DNA/ZC don't use cluster-id and cluster-type. Therefore,
skip setting these values if DNA/ZC is being used.

Bug #1048

10 years agolua detect: expose stream payload
Victor Julien [Wed, 24 Sep 2014 14:05:27 +0000 (16:05 +0200)] 
lua detect: expose stream payload

Allow a script to set the 'stream' buffer type. This will add the
script to the PMATCH list.

Example script:
alert tcp any any -> any any (content:"html"; lua:stream.lua; sid:1;)

    function init (args)
        local needs = {}
        needs["stream"] = tostring(true)
        return needs
    end

    -- return match via table
    function match(args)
        local result = {}

        b = tostring(args["stream"])
        o = tostring(args["offset"])

        bo = string.sub(b, o);
        print (bo)

        return result
    end

    return 0

10 years agoComment out in the action-order section, as its not needed if
Jason Ish [Wed, 17 Sep 2014 17:55:29 +0000 (11:55 -0600)] 
Comment out in the action-order section, as its not needed if
the default configuration is used.

10 years agoDon't require an action-order configuration section. If not present,
Jason Ish [Wed, 17 Sep 2014 17:52:12 +0000 (11:52 -0600)] 
Don't require an action-order configuration section. If not present,
use the defaults.

10 years agofilestore: fix parsing bug
Victor Julien [Tue, 30 Sep 2014 07:56:41 +0000 (09:56 +0200)] 
filestore: fix parsing bug

Filestore keyword can have options or no options, and the parser
was enforcing the NOOPT flag too strictly.

Bug #1288

10 years agoflow json log: add 'shutdown' as flow end reason 1143/head
Victor Julien [Wed, 1 Oct 2014 07:09:15 +0000 (09:09 +0200)] 
flow json log: add 'shutdown' as flow end reason

When engine shuts down all flows in the hash are logged out. They
may not have timed out yet. So they are forced. Log the reason to
be 'shutdown'.

10 years agoflow: fix flow logging at shutdown
Victor Julien [Tue, 30 Sep 2014 13:24:24 +0000 (15:24 +0200)] 
flow: fix flow logging at shutdown

Move all flows from the hash to the recycler at shutdown.

Bug #1260

10 years agooutput-lua: set proper callbacks for HTTP 1142/head
Victor Julien [Tue, 30 Sep 2014 11:37:30 +0000 (13:37 +0200)] 
output-lua: set proper callbacks for HTTP

Enable the relevant HTTP callbacks.

Bug #1287

10 years agooutput-lua: add config to yaml
Victor Julien [Tue, 30 Sep 2014 11:27:52 +0000 (13:27 +0200)] 
output-lua: add config to yaml

Disabled by default.

10 years agooutput-lua: add script-dir config param
Victor Julien [Tue, 30 Sep 2014 11:19:09 +0000 (13:19 +0200)] 
output-lua: add script-dir config param

Add 'scripts-dir' config directive that is prepended to the script
names to form a path. If ommited or empty, script are opened from
the CWD.

10 years agoyaml: add eve flow and netflow entries
Victor Julien [Tue, 30 Sep 2014 09:12:47 +0000 (11:12 +0200)] 
yaml: add eve flow and netflow entries

Added, commented out by default.

Bug #1257.

10 years agossh: convert error message to debug statement
Victor Julien [Thu, 18 Sep 2014 08:13:18 +0000 (10:13 +0200)] 
ssh: convert error message to debug statement

Don't print errors based on traffic issues.

10 years agoapp-layer-ssh: fix banner parser
Eric Leblond [Fri, 12 Sep 2014 08:02:12 +0000 (10:02 +0200)] 
app-layer-ssh: fix banner parser

Carefully crafted SSH banner could result in parser error.

Signed-off-by: Eric Leblond <eric@regit.org>
10 years agoipv6: convert ext header pointers to const
Victor Julien [Wed, 17 Sep 2014 12:57:15 +0000 (14:57 +0200)] 
ipv6: convert ext header pointers to const

To prevent accidental writes into the orignal packet buffer, use
const pointers for the extension header pointers used by IPv6. This
will cause compiler warnings in case of writes.

10 years agoipv6: RH extension header parsing issue
Victor Julien [Wed, 17 Sep 2014 12:26:27 +0000 (14:26 +0200)] 
ipv6: RH extension header parsing issue

A logic error in the IPv6 Routing header parsing caused accidental
updating of the original packet buffer. The calculated extension
header lenght was set to the length field of the routing header,
causing it to be wrong.

This has 2 consequences:

1. defrag failure. As the now modified payload was used in defrag,
the decoding of the reassembled packet now contained a broken length
field for the routing header. This would lead to decoding failure.

The potential here is evasion, although it would trigger:
[1:2200014:1] SURICATA IPv6 truncated extension header

2. in IPS mode, especially the AF_PACKET mode, the modified and now
broken packet would be transmitted on the wire. It's likely that
end hosts and/or routers would reject this packet.

NFQ based IPS mode would be less affected, as it 'verdicts' based on
the packet handle. In case of replacing the packet (replace keyword
or stream normalization) it could broadcast the bad packet.

Additionally, the RH Type 0 address parsing was also broken. It too
would modify the original packet. As the result of this code was not
used anywhere else in the engine, this code is now disabled.

Reported-By: Rafael Schaefer <rschaefer@ernw.de>
10 years agoaf-packet: check pointers before use
Victor Julien [Mon, 22 Sep 2014 15:33:40 +0000 (17:33 +0200)] 
af-packet: check pointers before use

10 years agoaf-packet: force suricata in IPS mode when needed
Eric Leblond [Fri, 19 Sep 2014 14:54:00 +0000 (16:54 +0200)] 
af-packet: force suricata in IPS mode when needed

AF_PACKET is not setting the engine mode to IPS when some
interfaces are peered and use IPS mode. This is due to the
fact, it is possible to peer 2 interfaces and run an IPS on
them and have a third one that is running in normal IDS mode.

In fact this choice is the bad one as unwanted side effect is
that there is no drop log and that stream inline is not used.

To fix that, this patch puts suricata in IPS mode as soon as
there is two interfaces in IPS mode. And it displays a error
message to warn user that the accuracy of detection on IDS only
interfaces will be low.

10 years agorule parser: set flag for optionless keywords 1128/head
Victor Julien [Fri, 19 Sep 2014 11:39:37 +0000 (13:39 +0200)] 
rule parser: set flag for optionless keywords

If a keyword doesn't have an argument, it should set the SIGMATCH_NOOPT
flag so the parser knows.

10 years agorule parser: fix crashing on malformed options
Victor Julien [Fri, 19 Sep 2014 11:38:47 +0000 (13:38 +0200)] 
rule parser: fix crashing on malformed options

Fix crashing on malformed rule options like 'rev;1;'.

Bug 1254.

10 years agodetect: fix continue detection with amatch and tx 1126/head
Victor Julien [Thu, 18 Sep 2014 13:13:13 +0000 (15:13 +0200)] 
detect: fix continue detection with amatch and tx

When using AMATCH, continue detection would fail if the tx part
had already run. This lead to start detection rerunning, causing
multiple alerts for the same issue.

10 years agolua: fix http.request_line inspection
Victor Julien [Thu, 18 Sep 2014 11:37:18 +0000 (13:37 +0200)] 
lua: fix http.request_line inspection

As there is no inspection engine for request_line, the sigmatch was
added to the AMATCH list. However, no AppLayerMatch function for
lua scripts was defined.

This patch defines a AppLayerMatch function.

Bug #1273.

10 years agotls: fix a tls.fingerprint issue in debug mode
Victor Julien [Fri, 19 Sep 2014 08:40:20 +0000 (10:40 +0200)] 
tls: fix a tls.fingerprint issue in debug mode

Print proper variable so we don't NULL-deref.

Bug #1279.

10 years agosource-nfq: fix display of next queue
Eric Leblond [Tue, 2 Sep 2014 13:33:34 +0000 (15:33 +0200)] 
source-nfq: fix display of next queue

Suricata was displaying an invalid queue number as the value is
shift at the moment of its assignement.

10 years agosuricatasc: add -c flag to run command 1122/head
Eric Leblond [Sat, 6 Sep 2014 09:46:21 +0000 (11:46 +0200)] 
suricatasc: add -c flag to run command

Add -c flag to run command given as argument and return the raw
JSON result. For example, it is possible to run something like.
 $ suricatasc  -c "iface-stat eth0"
 {'message': {'pkts': 17838352, 'drop': 0, 'invalid-checksums': 1}, 'return': 'OK'}

10 years agosuricatasc: factorize command parsing
Eric Leblond [Sat, 6 Sep 2014 09:37:20 +0000 (11:37 +0200)] 
suricatasc: factorize command parsing

10 years agoBug fix: IPv6 addresses in negated range and IPv6 string into radix tree.
bmeeks8 [Fri, 5 Sep 2014 13:22:11 +0000 (09:22 -0400)] 
Bug fix: IPv6 addresses in negated range and IPv6 string into radix tree.

I found three somewhat serious IPv6 address bugs within the Suricata 2.0.x source code. Two are in the source module "detect-engine-address.c", and the third is in "util-radix-tree.c".

The first bug occurs within the function DetectAddressParse2(). When parsing an address string and a negated block is encountered (such as when parsing !$HOME_NET, for example), any corresponding IPv6 addresses were not getting added to the Group Heads in the DetectAddressList. Only IPv4 addresses were being added.

I discovered another bug related to IPv6 address ranges in the Signature Match Address Array comparison code for IPv6 addresses. The function DetectAddressMatchIPv6() walks a signature's source or destination match address list comparing each to the current packet's corresponding address value. The match address list consists of value pairs representing a lower and upper IP address range. If the packet's address is within that range (including equal to either the lower or upper bound), then a signature match flag is returned.

The original test of each signature match address to the packet was performed using a set of four compounded AND comparisons looking at each of the four 32-bit blocks that comprise an IPv6 address. The problem with the old comparison is that if ANY of the four 32-bit blocks failed the test, then a "no-match" was returned. This is incorrect. If one or more of the more significant 32-bit blocks met the condition, then it is a match no matter if some of the less significant 32-bit blocks did not meet the condition. Consider this example where Packet represents the packet address being checked, and Target represents the upper bound of a match address pair. We are testing if Packet is less than Target.

Packet -- 2001:0470 : 1f07:00e2 : 1988:01f1 : d468:27ab
Target -- 2001:0470 : 1f07:00e2 : a48c:2e52 : d121:101e

In this example the Packet's address is less than the target and it should give a match. However, the old code would compare each 32-bit block (shown spaced out above for clarity) and logically AND the result with the next least significant block comparison. If any of the four blocks failed the comparison, that kicked out the whole address. The flaw is illustrated above. The first two blocks are 2001:0470 and 1f07:00e2 and yield TRUE; the next less significant block is 1988:01f1 and a48c:2e52, and also yields TRUE (that is, Packet is less than Target); but the last block compare is FALSE (d468:27ab is not less than d121:101e). That last block is the least significant block, though, so its FALSE determination should not invalidate a TRUE from any of the more significant blocks. However, in the previous code using the compound logical AND block, that last least significant block would invalidate the tests done with the more significant blocks.

The other bug I found for IPv6 occurs when trying to parse and insert an IPv6 address into a Radix Tree using the function SCRadixAddKeyIPV6String(). The test for min and max values for an IPv6 CIDR mask incorrectly tests the upper limit as 32 when it should be 128 for an IPv6 address. I think this perhaps is an old copy-paste error if the IPv6 version of this function was initially copied from the corresponding IPv4 version directly above it in the code. Without this patch, the function will return null when you attempt to add an IPv6 network whose CIDR mask is larger than 32 (for example, the popular /64 mask will cause the function to return the NULL error condition).

(amended by Victor Julien)

10 years agolua: export packet keywords to detect scripts 1112/head
Victor Julien [Fri, 15 Aug 2014 12:04:44 +0000 (14:04 +0200)] 
lua: export packet keywords to detect scripts

Set packet pointer, so it's available to the lua keywords that
require it.

10 years agodetect-lua: register all 'output' keywords as well
Victor Julien [Thu, 14 Aug 2014 14:37:37 +0000 (16:37 +0200)] 
detect-lua: register all 'output' keywords as well

Register all keywords available to output scripts to the detect
scripts as well.

10 years agodetect-lua: set tx ptr
Victor Julien [Thu, 14 Aug 2014 14:33:37 +0000 (16:33 +0200)] 
detect-lua: set tx ptr

Set tx ptr so it can be used later by other keywords.

10 years agodetect: track current tx_id in det_ctx
Victor Julien [Thu, 14 Aug 2014 14:21:38 +0000 (16:21 +0200)] 
detect: track current tx_id in det_ctx

When using the inspection engines, track the current tx_id in the
thread storage the detect thread uses. As 0 is a valid tx_id, add
a simple bool that indicates if the tx_id field is set.

10 years agolua: move lua output code to generic lua file
Victor Julien [Tue, 5 Aug 2014 07:58:48 +0000 (09:58 +0200)] 
lua: move lua output code to generic lua file

So that other Lua scripts (detect) can also start using it.

10 years agolua: remove LogLua prefix and replace it with Lua
Victor Julien [Tue, 5 Aug 2014 07:26:59 +0000 (09:26 +0200)] 
lua: remove LogLua prefix and replace it with Lua

Preparing making code available to more than just output.

10 years agolua: move output http funcs to generic util file
Victor Julien [Mon, 4 Aug 2014 15:47:47 +0000 (17:47 +0200)] 
lua: move output http funcs to generic util file

Move output Http functions to util-lua-http.c so that detect can use
it later.

10 years agoRename Lua code to just Lua
Victor Julien [Fri, 1 Aug 2014 14:29:53 +0000 (16:29 +0200)] 
Rename Lua code to just Lua

As we support regular Lua as well as LuaJIT, it makes more sense to call
it all Lua.

10 years agolua: use LuaPushStringBuffer in more places
Victor Julien [Fri, 1 Aug 2014 13:34:37 +0000 (15:34 +0200)] 
lua: use LuaPushStringBuffer in more places

Replace existing workarounds with LuaPushStringBuffer

10 years agolua: LuaPushStringBuffer optimization
Victor Julien [Fri, 1 Aug 2014 10:41:17 +0000 (12:41 +0200)] 
lua: LuaPushStringBuffer optimization

Only use a temp buffer when really necessary, which is when the
buffer size is not a multiple of 4.

10 years agolua: move LuaPushStringBuffer to the generic util-lua.c
Victor Julien [Fri, 1 Aug 2014 10:32:38 +0000 (12:32 +0200)] 
lua: move LuaPushStringBuffer to the generic util-lua.c

10 years agolua: rename LuaReturnStringBuffer to LuaPushStringBuffer
Victor Julien [Fri, 1 Aug 2014 10:29:17 +0000 (12:29 +0200)] 
lua: rename LuaReturnStringBuffer to LuaPushStringBuffer

LuaPushStringBuffer is a wrapper for lua_pushlstring, so the new name
better reflects it's function.

10 years agooutput-lua: add SCFlowStats
Victor Julien [Thu, 31 Jul 2014 16:02:40 +0000 (18:02 +0200)] 
output-lua: add SCFlowStats

SCFlowStats gets the packet and byte counts per flow:
    tscnt, tsbytes, tccnt, tcbytes = SCFlowStats()

10 years agooutput lua: expose flow logging api
Victor Julien [Tue, 29 Jul 2014 15:36:42 +0000 (17:36 +0200)] 
output lua: expose flow logging api

Allow use of the Flow Logging API through Lua scripts.

Minimal script:

function init (args)
    local needs = {}
    needs["type"] = "flow"
    return needs
end

function setup (args)
end

function log(args)
    startts = SCFlowTimeString()
    ipver, srcip, dstip, proto, sp, dp = SCFlowTuple()
    print ("Flow IPv" .. ipver .. " src " .. srcip .. " dst " .. dstip ..
            " proto " .. proto .. " sp " .. sp .. " dp " .. dp)
end

function deinit (args)
end

10 years agolua-output: add SCStreamingBuffer
Victor Julien [Wed, 25 Jun 2014 13:25:53 +0000 (15:25 +0200)] 
lua-output: add SCStreamingBuffer

Add SCStreamingBuffer lua function to retrieve the data passed
to the script per streaming API invocation.

Example:

    function log(args)
        data = SCStreamingBuffer()
        hex_dump(data)
    end

10 years agooutput-lua: add support for streaming api
Victor Julien [Tue, 24 Jun 2014 20:40:33 +0000 (22:40 +0200)] 
output-lua: add support for streaming api

Add support to lua output for the streaming api. This allows for a
script to subscribe itself to streaming tcp data and http body data.

10 years agooutput-lua: give access to packet payload
Victor Julien [Wed, 2 Apr 2014 22:09:57 +0000 (00:09 +0200)] 
output-lua: give access to packet payload

Add SCPacketPayload()

Example:
    function log(args)
        p = SCPacketPayload()
        print(p)
    end

10 years agooutput-lua: expose http body data
Victor Julien [Mon, 31 Mar 2014 13:05:15 +0000 (15:05 +0200)] 
output-lua: expose http body data

Make normalized body data available to the script through
HttpGetRequestBody and HttpGetResponseBody.

There no guarantees that all of the body will be availble.

Example:
    function log(args)
        a, o, e = HttpGetResponseBody();
        --print("offset " .. o .. " end " .. e)

        for n, v in ipairs(a) do
            print(v)
        end
    end

10 years agooutput-lua: add HttpGetRequestHost callback
Victor Julien [Fri, 28 Mar 2014 16:24:22 +0000 (17:24 +0100)] 
output-lua: add HttpGetRequestHost callback

Get the host from libhtp's tx->request_hostname, which can either be
the host portion of the url or the host portion of the Host header.

Example:

    http_host = HttpGetRequestHost()
    if http_host == nil then
        http_host = "<hostname unknown>"
    end

10 years agooutput-lua: http alproto check
Victor Julien [Fri, 21 Mar 2014 21:26:28 +0000 (22:26 +0100)] 
output-lua: http alproto check

10 years agooutput-lua: clean up flow lock handling
Victor Julien [Fri, 21 Mar 2014 21:26:37 +0000 (22:26 +0100)] 
output-lua: clean up flow lock handling

10 years agooutput-lua: alproto string callback
Victor Julien [Fri, 21 Mar 2014 13:25:04 +0000 (14:25 +0100)] 
output-lua: alproto string callback

SCFlowAppLayerProto: get alproto as string from the flow. If alproto
is not (yet) known, it returns "unknown".

    function log(args)
        alproto = SCFlowAppLayerProto()
        if alproto ~= nil then
            print (alproto)
        end
    end

10 years agooutput-lua: expose thread info
Victor Julien [Fri, 21 Mar 2014 08:40:54 +0000 (09:40 +0100)] 
output-lua: expose thread info

A new callback to give access to thread id, name and group name:
SCThreadInfo. It gives: tid (integer), tname (string), tgroup (string)

    function log(args)
        tid, tname, tgroup = SCThreadInfo()

10 years agooutput-lua: expose flow start time string
Victor Julien [Wed, 19 Mar 2014 17:38:29 +0000 (18:38 +0100)] 
output-lua: expose flow start time string

SCFlowTimeString: returns string form of start time of a flow

Example:

    function log(args)
        startts = SCFlowTimeString()
        ts = SCPacketTimeString()
        if ts == startts then
            print("new flow")
        end

10 years agooutput-lua: add file callbacks
Victor Julien [Wed, 19 Mar 2014 15:13:38 +0000 (16:13 +0100)] 
output-lua: add file callbacks

SCFileInfo: returns fileid (number), txid (number), name (string),
            size (number), magic (string), md5 in hex (string)

Example:

    function log(args)
        fileid, txid, name, size, magic, md5 = SCFileInfo()

SCFileState: returns state (string), stored (bool)

Example:
    function log(args)
        state, stored = SCFileState()

10 years agooutput-lua: add SCPacketTimeString
Victor Julien [Wed, 19 Mar 2014 11:36:01 +0000 (12:36 +0100)] 
output-lua: add SCPacketTimeString

Add SCPacketTimeString to get the packets time string in the format:
    11/24/2009-18:57:25.179869

Example use:

    function log(args)
        ts = SCPacketTimeString()

10 years agooutput-lua: rule info callback
Victor Julien [Mon, 17 Mar 2014 17:44:09 +0000 (18:44 +0100)] 
output-lua: rule info callback

SCRuleIds(): returns sid, rev, gid:

    function log(args)
        sid, rev, gid = SCRuleIds()

SCRuleMsg(): returns msg

    function log(args)
        msg = SCRuleMsg()

SCRuleClass(): returns class msg and prio:

    function log(args)
        class, prio = SCRuleClass()
        if class == nil then
            class = "unknown"
        end

10 years agolua: add SCFlowTuple lua function
Victor Julien [Fri, 14 Mar 2014 13:16:47 +0000 (14:16 +0100)] 
lua: add SCFlowTuple lua function

Like SCPacketTuple, only retrieves Tuple from the flow.

Minimal log function:

    function log(args)
        ipver, srcip, dstip, proto, sp, dp = SCFlowTuple()
        print ("Flow IPv" .. ipver .. " src " .. srcip .. " dst " .. dstip ..
               " proto " .. proto .. " sp " .. sp .. " dp " .. dp)
    end

10 years agodetect-lua: convert extensions to use flow wrappers
Victor Julien [Mon, 3 Mar 2014 13:11:00 +0000 (14:11 +0100)] 
detect-lua: convert extensions to use flow wrappers

Use the new flow wrapper functions in the lua flowvar and flowint
extensions.

10 years agolua: add flow store and retrieval wrappers
Victor Julien [Mon, 3 Mar 2014 13:09:18 +0000 (14:09 +0100)] 
lua: add flow store and retrieval wrappers

Add flow store and retrieval wrappers for accessing the flow through
Lua's lightuserdata method.

The flow functions store/retrieve a lock hint as well.

10 years agolua: introduce util-lua.[ch]
Victor Julien [Fri, 28 Feb 2014 15:18:48 +0000 (16:18 +0100)] 
lua: introduce util-lua.[ch]

Shared functions for all lua parts of the engine.