]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
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.

10 years agooutput-lua: add all packets logging support
Victor Julien [Mon, 24 Feb 2014 16:08:44 +0000 (17:08 +0100)] 
output-lua: add all packets logging support

If the script needing a packet doesn't specify a filter, it will
be run against all packets. This patch adds the support for this
mode. It is a packet logger with a condition function that always
returns true.

10 years agooutput-lua: improve error checking for init()
Victor Julien [Mon, 24 Feb 2014 15:41:27 +0000 (16:41 +0100)] 
output-lua: improve error checking for init()

If init doesn't properly init the script, skip the script and error
out.

10 years agooutput-log: expose SCLog functions to lua scripts
Victor Julien [Fri, 21 Feb 2014 11:20:46 +0000 (12:20 +0100)] 
output-log: expose SCLog functions to lua scripts

The lua scripts can use SCLogDebug, SCLogInfo, SCLogNotice, SCLogWarning,
SCLogError. The latter 2 won't be able to add an error code though.

10 years agooutput-lua: make packet ptr available to all scripts
Victor Julien [Fri, 21 Feb 2014 09:17:16 +0000 (10:17 +0100)] 
output-lua: make packet ptr available to all scripts

TxLogger and Packet logger need it to be able to use the Tuple
callback.

10 years agooutput-lua: add SCLogPath callback
Victor Julien [Fri, 21 Feb 2014 08:37:39 +0000 (09:37 +0100)] 
output-lua: add SCLogPath callback

Add a lua callback for getting Suricata's log path, so that lua scripts
can easily get the logging directory Suricata uses.

Update the Setup logic to register callbacks before the scripts 'setup'
is called.

Example:

    name = "fast_lua.log"
    function setup (args)
        filename = SCLogPath() .. "/" .. name
        file = assert(io.open(filename, "a"))
    end

10 years agooutput-lua: TxLogger use proper stack function
Victor Julien [Fri, 21 Feb 2014 08:00:42 +0000 (09:00 +0100)] 
output-lua: TxLogger use proper stack function

Use proper wrapper to setup the stack.

10 years agooutput-lua: improve error handling and documentation
Victor Julien [Thu, 20 Feb 2014 16:58:15 +0000 (17:58 +0100)] 
output-lua: improve error handling and documentation

Better document the various functions and improve error handling.

10 years agooutput-lua: register common callbacks
Victor Julien [Thu, 20 Feb 2014 16:55:15 +0000 (17:55 +0100)] 
output-lua: register common callbacks

Clean up callback registration in the setup-stage and register
common callbacks.

10 years agooutput-lua: support File logging
Victor Julien [Thu, 20 Feb 2014 16:51:47 +0000 (17:51 +0100)] 
output-lua: support File logging

Add file logger support. The script uses:

function init (args)
    local needs = {}
    needs['type'] = 'file'
    return needs
end

The type is set to file to make it a file logger.

10 years agooutput-lua: rename LuaPacketLogger to ..Alerts
Victor Julien [Thu, 20 Feb 2014 16:49:51 +0000 (17:49 +0100)] 
output-lua: rename LuaPacketLogger to ..Alerts

As the script is called for each alert, not for each packet, name
the script LuaPacketLoggerAlerts.

10 years agooutput-lua: add stack utility functions
Victor Julien [Thu, 20 Feb 2014 14:57:00 +0000 (15:57 +0100)] 
output-lua: add stack utility functions

Add utility functions for placing things on the stack for use
by the scripts. Functions for numbers, strings and byte arrays.

Add callback for returing IP header info: ip version, src ip,
dst ip, proto, sp, dp (or type and code for icmp and icmpv6):
SCPacketTuple

10 years agooutput-lua: initial packet support
Victor Julien [Thu, 20 Feb 2014 14:47:50 +0000 (15:47 +0100)] 
output-lua: initial packet support

Add key for storing packet pointer in the lua stack and a utility
function to retrieve it from lua callbacks.

10 years agooutput-lua: move LuaPrintStack to common
Victor Julien [Thu, 20 Feb 2014 14:45:33 +0000 (15:45 +0100)] 
output-lua: move LuaPrintStack to common

It's a utility function that will be used in several other places
as well.

10 years agooutput-lua: add example packet log script
Victor Julien [Thu, 20 Feb 2014 08:39:24 +0000 (09:39 +0100)] 
output-lua: add example packet log script

Example packet log script that outputs to stdout in the alert-
fast log format.

10 years agooutput-lua: packet logger support
Victor Julien [Thu, 20 Feb 2014 08:36:16 +0000 (09:36 +0100)] 
output-lua: packet logger support

Through 'needs' the script init function can indicate it wants to
see packets and select a condition function. Currently only alerts
is an option:

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

10 years agooutput-lua: new file for common functions
Victor Julien [Wed, 19 Feb 2014 12:49:35 +0000 (13:49 +0100)] 
output-lua: new file for common functions

Add output-lua-common.[ch] to store functions common to various parts
of the lua output framework.

10 years agooutput: Lua HTTP log initial implementation
Victor Julien [Tue, 11 Feb 2014 13:44:21 +0000 (14:44 +0100)] 
output: Lua HTTP log initial implementation

Initial version of a HTTP LUA logger. Execute lua scripts from the
Tx-log API.

10 years agooutput-lua: support submodules
Victor Julien [Wed, 19 Feb 2014 11:52:03 +0000 (12:52 +0100)] 
output-lua: support submodules

Use the OutputCtx::submodules list to register additional log modules.
Currently this is hardcoded to the 'lua' module.

10 years agooutput-lua: display warning if no lua support
Victor Julien [Wed, 19 Feb 2014 11:50:57 +0000 (12:50 +0100)] 
output-lua: display warning if no lua support

Display a warning that the lua module is not available if we're
not compiled against lua(jit).

10 years agooutput: add submodules list to OutputCtx
Victor Julien [Wed, 19 Feb 2014 11:46:50 +0000 (12:46 +0100)] 
output: add submodules list to OutputCtx

Add a list to the OutputCtx that can contain OutputModule structures.
This will be used by a 'parent' module to register submodules directly.

10 years agostreaming: pass tx_id to logger
Victor Julien [Wed, 18 Jun 2014 10:15:58 +0000 (12:15 +0200)] 
streaming: pass tx_id to logger

This way we can distinguish between various tx' in the logger.

10 years agostreaming-loggers: add configuration
Victor Julien [Tue, 17 Jun 2014 15:49:05 +0000 (17:49 +0200)] 
streaming-loggers: add configuration

Add a (disabled by default) config to the yaml

10 years agotcp-data-log: file and dir logging modes
Victor Julien [Fri, 13 Jun 2014 10:05:33 +0000 (12:05 +0200)] 
tcp-data-log: file and dir logging modes

Add a file logging mode, which logs all the data into a single log file.

Also, make the directory logging more configurable.

11 years agotcp-data: new streaming logger
Victor Julien [Sat, 5 Apr 2014 08:02:38 +0000 (10:02 +0200)] 
tcp-data: new streaming logger

tcp-data logs out reassembled stream data in a streaming fashion.

Records type to log into different directories.

11 years agostreaming logger: support Http Body logging
Victor Julien [Thu, 12 Jun 2014 09:42:00 +0000 (11:42 +0200)] 
streaming logger: support Http Body logging

Add an argument to the registration to indicate which iterator
needs to be used: Stream or HttpBody

Add HttpBody Iterator, calling the logger(s) for each Http body chunk.

11 years agooutput-streaming: StreamIterator
Victor Julien [Sat, 5 Apr 2014 08:00:27 +0000 (10:00 +0200)] 
output-streaming: StreamIterator

StreamIterator implementation for iterating over ACKed segments.

Flag each segment as logged when the log function has been called for it.

Set a 'OPEN' flag for the first segment in both directions.

Set a 'CLOSE' flag when the stream ends. If the last segment was already
logged, a empty CLOSE call is performed with NULL data.

11 years agooutput-streaming: a Log API for streaming data
Victor Julien [Fri, 4 Apr 2014 10:51:26 +0000 (12:51 +0200)] 
output-streaming: a Log API for streaming data

This patch adds a new Log API for streaming data such as TCP reassembled
data and HTTP body data. It could also replace Filedata API.

Each time a new chunk of data is available, the callback will be called.

11 years agoFix compiler warning about uninitialized variable in mpipe.
Ken Steele [Tue, 12 Aug 2014 23:57:41 +0000 (19:57 -0400)] 
Fix compiler warning about uninitialized variable in mpipe.

11 years agoSimple code fixes
Duarte Silva [Tue, 12 Aug 2014 17:13:52 +0000 (18:13 +0100)] 
Simple code fixes
- Removed unnecessary assignment of the data field
- Removed else condition (same function called for IPv4 and IPV6)
- Fixed constants to be a power of two (used in bitwise operations)

11 years agoOptimize Packet Ext data freeing
Victor Julien [Wed, 13 Aug 2014 14:33:50 +0000 (16:33 +0200)] 
Optimize Packet Ext data freeing

Move the logic of PacketFreeExtData into a macro 'PACKET_FREE_EXTDATA'.
It was called for each packet.

11 years agopacket pool: fix ext_pkt cleaning
Eric Leblond [Wed, 13 Aug 2014 08:48:26 +0000 (10:48 +0200)] 
packet pool: fix ext_pkt cleaning

The field ext_pkt was cleaned before calling the release function.
The result was that IPS mode such as the one of AF_PACKET were not
working anymore because they were not able to send the data which
were initially pointed by ext_pkt.

This patch moves the ext_pkt cleaning to the cleaning macro. This
ensures that the cleaning is done for allocated and pool packets.

11 years agopacket recycle: remove mutex destroy/init 1104/head
Victor Julien [Wed, 9 Jul 2014 06:55:47 +0000 (08:55 +0200)] 
packet recycle: remove mutex destroy/init

This was necessary earlier when there was a memset involved.

11 years agopacket recycle: do most clean up on packet reuse
Victor Julien [Wed, 9 Jul 2014 06:51:29 +0000 (08:51 +0200)] 
packet recycle: do most clean up on packet reuse

Call PACKET_RELEASE_REFS from PacketPoolGetPacket() so that
we only access the large packet structure just before actually
using it. Should give better cache behaviour.

11 years agopacket recycle: split macro
Victor Julien [Wed, 9 Jul 2014 06:50:26 +0000 (08:50 +0200)] 
packet recycle: split macro

Split PACKET_RECYCLE into 2 parts. One part for cleanup to do before a
packet is returned to the pool, the other after it's retrieved from
the pool.

11 years agoFix decode tests calling PACKET_DO_RECYCLE instead of PACKET_RECYCLE
Victor Julien [Wed, 9 Jul 2014 08:59:49 +0000 (10:59 +0200)] 
Fix decode tests calling PACKET_DO_RECYCLE instead of PACKET_RECYCLE

11 years agoUpdate Changelog for 2.1beta1 suricata-2.1beta1
Victor Julien [Tue, 12 Aug 2014 13:59:05 +0000 (15:59 +0200)] 
Update Changelog for 2.1beta1

11 years agoUpdate Changelog for 2.0.3
Victor Julien [Fri, 8 Aug 2014 07:49:18 +0000 (09:49 +0200)] 
Update Changelog for 2.0.3

11 years agoFix GRE Source Routing Header definition
Ken Steele [Wed, 5 Feb 2014 23:00:19 +0000 (18:00 -0500)] 
Fix GRE Source Routing Header definition

The Source Routing Header had routing defined as a char* for a field
of variable size. Since that field was not being used in the code, I
removed the pointer and added a comment.

11 years agoMore structures that need to be marked Packed.
Ken Steele [Fri, 20 Dec 2013 18:50:43 +0000 (13:50 -0500)] 
More structures that need to be marked Packed.

These structures are cast from raw packet data, so they should be packed.
The case is:

typedef struct Foo_ {
} Foo;

Foo *f = (Foo *)pkt;

11 years agoAdd Packed attribute on Header structures
Ken Steele [Fri, 20 Dec 2013 16:52:12 +0000 (11:52 -0500)] 
Add Packed attribute on Header structures

Structures that are used to cast packet data into fields need to be packed
so that the compiler doesn't add any padding to these fields. This also helps
Tile-Gx to avoid unaligned loads because the compiler will insert code to
handle the possible unaligned load.

11 years agolua: improve configure checks 1100/head
Victor Julien [Mon, 11 Aug 2014 12:14:59 +0000 (14:14 +0200)] 
lua: improve configure checks

The base 'lua' library has different names on different OS' and even
Linux distro's. Instead of selecting the proper one, we now just try
all. This way no OS/distro specific knowledge about the name is needed.

11 years agoalert-json: clean up flags 1098/head
Victor Julien [Fri, 8 Aug 2014 12:25:31 +0000 (14:25 +0200)] 
alert-json: clean up flags

Make payload/packet logging code also use the flags field in
AlertJsonOutputCtx, instead of in the LogFileCtx.

11 years agojson-alert: include HTTP info on the alerts 1097/head
Giuseppe Longo [Thu, 7 Aug 2014 13:10:45 +0000 (15:10 +0200)] 
json-alert: include HTTP info on the alerts

Extends the JSON alert output to include the HTTP data
at the time of the alert.

11 years agojson-http: refactoring output code
Giuseppe Longo [Thu, 7 Aug 2014 12:36:54 +0000 (14:36 +0200)] 
json-http: refactoring output code

Splits the output code in two public functions and permits
to call them from the alert function

11 years agoUse extra data structure in json alert output
Duarte Silva [Thu, 31 Jul 2014 16:06:20 +0000 (17:06 +0100)] 
Use extra data structure in json alert output
to store local configuration

11 years agostream: detect and filter out bad window updates 1094/head
Victor Julien [Wed, 16 Jul 2014 22:23:50 +0000 (00:23 +0200)] 
stream: detect and filter out bad window updates

Reported in bug 1238 is an issue where stream reassembly can be
disrupted.

A packet that was in-window, but otherwise unexpected set the
window to a really low value, causing the next *expected* packet
to be considered out of window. This lead to missing data in the
stream reassembly.

The packet was unexpected in various ways:
- it would ack unseen traffic
- it's sequence number would not match the expected next_seq
- set a really low window, while not being a proper window update

Detection however, it greatly hampered by the fact that in case of
packet loss, quite similar packets come in. Alerting in this case
is unwanted. Ignoring/skipping packets in this case as well.

The logic used in this patch is as follows. If:

- the packet is not a window update AND
- packet seq > next_seq AND
- packet acq > next_seq (packet acks unseen data) AND
- packet shrinks window more than it's own data size
THEN set event and skip the packet in the stream engine.

So in case of a segment with no data, any window shrinking is rejected.

Bug #1238.

11 years agoipv6: fix dst/hop header option parsing 1091/head
Victor Julien [Thu, 7 Aug 2014 13:02:56 +0000 (15:02 +0200)] 
ipv6: fix dst/hop header option parsing

The extension header option parsing used a uint8_t internally. However
much bigger option sizes are valid.

11 years agodefrag: use 'struct timeval' for timeout tracking 1088/head
Victor Julien [Tue, 5 Aug 2014 15:28:17 +0000 (17:28 +0200)] 
defrag: use 'struct timeval' for timeout tracking

Until now the time out handling in defrag was done using a single
uint32_t that tracked seconds. This lead to corner cases, where
defrag trackers could be timed out a little too early.

11 years agoipv6: set event on unsupported nh
Victor Julien [Mon, 28 Jul 2014 12:41:15 +0000 (14:41 +0200)] 
ipv6: set event on unsupported nh

If a next header / protocol is encountered that we can't handle (yet)
set an event. Disabled the rule by default.

    decode-event:ipv6.unknown_next_header;

11 years agoipv6: more robust ipv6 exthdr handling
Victor Julien [Mon, 28 Jul 2014 11:59:44 +0000 (13:59 +0200)] 
ipv6: more robust ipv6 exthdr handling

Skip past Shim6, HIP and Mobility header.

Detect data after 'none' header.
    decode-event:ipv6.data_after_none_header;

11 years agoipv6: detect frag header reserved field non-zero
Victor Julien [Mon, 28 Jul 2014 10:07:13 +0000 (12:07 +0200)] 
ipv6: detect frag header reserved field non-zero

Frag Header length field is reserved, and should be set to 0.

    decode-event:ipv6.fh_non_zero_reserved_field;

11 years agoipv6: make exthdr parsing more robust
Victor Julien [Thu, 24 Jul 2014 14:50:34 +0000 (16:50 +0200)] 
ipv6: make exthdr parsing more robust

Improve data length checks. Detect PadN option with 0 length.

11 years agoipv6: set flag on type 0 routing header
Victor Julien [Thu, 17 Jul 2014 13:57:16 +0000 (15:57 +0200)] 
ipv6: set flag on type 0 routing header

Type 0 Routing headers are deprecated per RFC 5095.

This patch sets an decode event flag that can be matched on through:
    decode-event:ipv6.rh_type_0;

11 years agoipv6 defrag: fix unfragmentable exthdr handling
Victor Julien [Thu, 24 Jul 2014 11:39:10 +0000 (13:39 +0200)] 
ipv6 defrag: fix unfragmentable exthdr handling

Fix or rather implement handling of unfragmentable exthdrs in ipv6.
The exthdr(s) appearing before the frag header were copied into the
reassembled packet correctly, however the stripping of the frag header
did not work correctly.

Example:
The common case is a frag header directly after the ipv6 header:

[ipv6 header]->[frag header]->[icmpv6 (part1)]
[ipv6 header]->[frag header]->[icmpv6 (part2)]

This would result in:
[ipv6 header]->[icmpv6]

The ipv6 headers 'next header' setting would be updated to point to
whatever the frag header was pointing to.

This would also happen when is this case:

[ipv6 header]->[hop header]->[frag header]->[icmpv6 (part1)]
[ipv6 header]->[hop header]->[frag header]->[icmpv6 (part2)]

The result would be:
[ipv6 header]->[hop header]->[icmpv6]

However, here too the ipv6 header would have been updated to point
to what the frag header pointed at. So it would consider the hop header
as if it was an ICMPv6 header, or whatever the frag header pointed at.

The result is that packets would not be correctly parsed, and thus this
issue can lead to evasion.

This patch implements handling of the unfragmentable part. In the first
segment that is stored in the list for reassembly, this patch detects
unfragmentable headers and updates it to have the last unfragmentable
header point to the layer after the frag header.

Also, the ipv6 headers 'next hdr' is only updated if no unfragmentable
headers are used. If they are used, the original value is correct.

Reported-By: Rafael Schaefer <rschaefer@ernw.de>
Bug #1244.

11 years agopacket pool: init pthread key before using it 1083/head
Victor Julien [Fri, 1 Aug 2014 07:55:43 +0000 (09:55 +0200)] 
packet pool: init pthread key before using it

In the packet pool code, it's critical to initialize the pthread key
before using it. Applies only to the code used if __thread isn't
supported.

11 years agopacket pool: cosmetic cleanups
Victor Julien [Fri, 1 Aug 2014 07:54:34 +0000 (09:54 +0200)] 
packet pool: cosmetic cleanups

11 years agoprscript: update URL
Eric Leblond [Thu, 31 Jul 2014 09:48:41 +0000 (11:48 +0200)] 
prscript: update URL

Buildbot server has been moved to another box.

11 years agomagic: disable tests depending on magic version
Victor Julien [Thu, 31 Jul 2014 13:49:11 +0000 (15:49 +0200)] 
magic: disable tests depending on magic version

Some tests depend on specific results by specific magic versions.
Disable these.

11 years agosuricata: RunUnittests now return void
Eric Leblond [Wed, 30 Jul 2014 15:17:51 +0000 (17:17 +0200)] 
suricata: RunUnittests now return void

RunUnittests function is now a terminal function (calling exit
before leaving).

11 years agounittests: don't register app layer test
Eric Leblond [Tue, 29 Jul 2014 08:05:23 +0000 (10:05 +0200)] 
unittests: don't register app layer test

Some tests are already registered via the function
AppLayerParserRegisterProtocolUnittests. So we don't need to
egister them during runmode initialization.