Commit Graph

5427 Commits (83d9834e776e5fdd9f1df6e17e5c8b0517cd5184)
 

Author SHA1 Message Date
Victor Julien 7cdc57060b af-packet: check pointers before use 11 years ago
Eric Leblond 1e36053eca 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.
11 years ago
Victor Julien 02529b13a8 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.
11 years ago
Victor Julien 690a85698f rule parser: fix crashing on malformed options
Fix crashing on malformed rule options like 'rev;1;'.

Bug 1254.
11 years ago
Victor Julien 6720496324 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.
11 years ago
Victor Julien c152ddf072 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.
11 years ago
Victor Julien 8b4615f8e7 tls: fix a tls.fingerprint issue in debug mode
Print proper variable so we don't NULL-deref.

Bug #1279.
11 years ago
Eric Leblond e0307b0993 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.
11 years ago
Eric Leblond 7f68a25535 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'}
11 years ago
Eric Leblond 1b9cc03653 suricatasc: factorize command parsing 11 years ago
bmeeks8 61a9739f44 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)
11 years ago
Victor Julien 22272f6c5b lua: export packet keywords to detect scripts
Set packet pointer, so it's available to the lua keywords that
require it.
11 years ago
Victor Julien 5a86e57d41 detect-lua: register all 'output' keywords as well
Register all keywords available to output scripts to the detect
scripts as well.
11 years ago
Victor Julien 41523ede77 detect-lua: set tx ptr
Set tx ptr so it can be used later by other keywords.
11 years ago
Victor Julien 3b98a1ce66 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.
11 years ago
Victor Julien a114787150 lua: move lua output code to generic lua file
So that other Lua scripts (detect) can also start using it.
11 years ago
Victor Julien fdc73eeba6 lua: remove LogLua prefix and replace it with Lua
Preparing making code available to more than just output.
11 years ago
Victor Julien e0d544fb86 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.
11 years ago
Victor Julien f23399d672 Rename Lua code to just Lua
As we support regular Lua as well as LuaJIT, it makes more sense to call
it all Lua.
11 years ago
Victor Julien adfe17280b lua: use LuaPushStringBuffer in more places
Replace existing workarounds with LuaPushStringBuffer
11 years ago
Victor Julien 66019ba325 lua: LuaPushStringBuffer optimization
Only use a temp buffer when really necessary, which is when the
buffer size is not a multiple of 4.
11 years ago
Victor Julien 307ce40500 lua: move LuaPushStringBuffer to the generic util-lua.c 11 years ago
Victor Julien 90b5aff02e lua: rename LuaReturnStringBuffer to LuaPushStringBuffer
LuaPushStringBuffer is a wrapper for lua_pushlstring, so the new name
better reflects it's function.
11 years ago
Victor Julien 0e93a29274 output-lua: add SCFlowStats
SCFlowStats gets the packet and byte counts per flow:
    tscnt, tsbytes, tccnt, tcbytes = SCFlowStats()
11 years ago
Victor Julien 46ac85dea6 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
11 years ago
Victor Julien f7d890fe00 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
11 years ago
Victor Julien ca3be77008 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.
11 years ago
Victor Julien efb5c29698 output-lua: give access to packet payload
Add SCPacketPayload()

Example:
    function log(args)
        p = SCPacketPayload()
        print(p)
    end
11 years ago
Victor Julien 08b0d9a5b4 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
11 years ago
Victor Julien 8360b707e8 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
11 years ago
Victor Julien a234a335ac output-lua: http alproto check 11 years ago
Victor Julien cb69cee4d8 output-lua: clean up flow lock handling 11 years ago
Victor Julien 19383fd428 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
11 years ago
Victor Julien 22dd14d560 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()
11 years ago
Victor Julien 8802ba3f67 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
11 years ago
Victor Julien 07ff85a44e 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()
11 years ago
Victor Julien 3343060d85 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()
11 years ago
Victor Julien b3dfd3cd8e 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
11 years ago
Victor Julien d9efa7048a 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
11 years ago
Victor Julien f2da5dbbad detect-lua: convert extensions to use flow wrappers
Use the new flow wrapper functions in the lua flowvar and flowint
extensions.
11 years ago
Victor Julien affbd697ed 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.
11 years ago
Victor Julien 599ec36b2c lua: introduce util-lua.[ch]
Shared functions for all lua parts of the engine.
11 years ago
Victor Julien 8bc01af581 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.
11 years ago
Victor Julien fe3484fbc0 output-lua: improve error checking for init()
If init doesn't properly init the script, skip the script and error
out.
11 years ago
Victor Julien 0055a10b3a 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.
11 years ago
Victor Julien 51ab5e55c1 output-lua: make packet ptr available to all scripts
TxLogger and Packet logger need it to be able to use the Tuple
callback.
11 years ago
Victor Julien 1e836be3d8 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
11 years ago
Victor Julien 31eea0f143 output-lua: TxLogger use proper stack function
Use proper wrapper to setup the stack.
11 years ago
Victor Julien 329f55598f output-lua: improve error handling and documentation
Better document the various functions and improve error handling.
11 years ago
Victor Julien c5ff94a319 output-lua: register common callbacks
Clean up callback registration in the setup-stage and register
common callbacks.
11 years ago