Commit Graph

12932 Commits (c587e90ebccfe8883ea951e723be461dc58dcc06)

Author SHA1 Message Date
Victor Julien d0f3f2d462 detect: group content inspect keyword id's 1 year ago
Victor Julien 022173d7ab detect: group types used in traffic variables
Traffic variables (flowvars, flowbits, xbits, etc) use a smaller int for
their type than detection types. As a workaround make sure the values fit
in a uint8_t.
1 year ago
Victor Julien cfd55ead74 threshold: add by_flow support for global thresholds
Allow rate_filter and thresholds from the global config to specify
tracking "by_flow".
1 year ago
Victor Julien 1552f0953a detect/threshold: implement tracking 'by_flow'
Add support for 'by_flow' track option. This allows using the various
threshold options in the context of a single flow.

Example:

    alert tcp ... stream-event:pkt_broken_ack; \
        threshold:type limit, track by_flow, count 1, seconds 3600;

The example would limit the number of alerts to once per hour for
packets triggering the 'pkt_broken_ack' stream event.

Implemented as a special "flowvar" holding the threshold entries. This
means no synchronization is required, making this a cheaper option
compared to the other trackers.

Ticket: #6822.
1 year ago
Victor Julien a81b23254c util/var: add comments explaining types 1 year ago
Victor Julien 1fa13e4b81 util/var: remove printf; add assert 1 year ago
Victor Julien ce727cf4b1 detect: remove unnecessary detect thread flags stores 1 year ago
Philippe Antoine b34d4b1314 detect/nfs: do not free a null pointer
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=69840
1 year ago
Jeff Lucovsky 5b97f4040c detect/base64: Use Rust defined modes everywhere
Issue: 6487

To avoid ambiguity, a single definition for base 64 decoding modes will
be used. The Rust base64 transform contains the definitions for the
existing mode types: Strict, RFC2045, RFC4648
1 year ago
Jeff Lucovsky f042e9034b detect/transform: Add from_base64 transform
Issue: 6487

Implement the from_base64 transform:
    [bytes value] [offset value] [mode strict|rfc4648|rfc2045]

    The value for bytes and offset may be a byte_ variable or an
    unsigned integer.
1 year ago
Shivani Bhardwaj 903283d76e flow: declare and use constansts where possible 1 year ago
Shivani Bhardwaj 00a644c5c2 flow/manager: make fn calls only when necessary 1 year ago
Shivani Bhardwaj eb95d2bf66 flow/timeout: cleanup fn names and comments 1 year ago
Shivani Bhardwaj 8818b9cbe0 flow: remove unneeded args to fn 1 year ago
Shivani Bhardwaj f97b4ec1e8 flow/manager: add fn docs 1 year ago
Shivani Bhardwaj 14cd594d3c flow: add defensive check 1 year ago
Shivani Bhardwaj a87c8eb46f packetpool: use DEBUG_VALIDATE statement 1 year ago
Shivani Bhardwaj 87fa7f10ef flow: use bool wherever possible 1 year ago
Philippe Antoine 8b831e6751 detect/icmp: require real packet in signature
Fixes: 956c8bebd1 ("detect/prefilter: use sig mask to exclude pkt engines")
1 year ago
Philippe Antoine 0a953fe1ce detect: add to signature mask for decode events
Ticket: 6291
1 year ago
Philippe Antoine 4e584ed201 detect: fix check for app_layer events
Ticket: 7106
1 year ago
Jeff Lucovsky 834cd6fbdb af-packet: Remove unused preprocessor define
Remove unused preprocessor value; exposed by compilation warning
1 year ago
Philippe Antoine c9ce43b31e output: configurable payload_length field for alerts
Ticket: 7098
1 year ago
Philippe Antoine a21232828e dcerpc: add app-layer metadata in alerts
Ticket: 6090
1 year ago
Philippe Antoine 5f35035928 filestore: do not try to store a file set to nostore
Ticket: 6390

This can happen with keyword filestore:both,flow
If one direction does not have a signature group with a filestore,
the file is set to nostore on opening, until a signature in
the other direction tries to set it to store.
Subsequent files will be stored in both directions as flow flags
are now set.
1 year ago
Philippe Antoine 0d4efe0c0f app-layer: fix -Wshorten-64-to-32 warnings
Ticket: #6186

Warnings about downcast from 64 to 32 bits
1 year ago
Philippe Antoine 1790aa49a4 util: fix -Wshorten-64-to-32 warnings
Ticket: 6186

Warnings about downcast from 64 to 32 bits

Generic fixes required to get app-layer clean
1 year ago
Philippe Antoine dc043d0297 detect: remove unused field
content_inspect_window is used in app-layer-smtp, but
not directly in detect-file-data
1 year ago
Victor Julien 3d059611c3 detect: add tls.alpn keyword
Ticket: #7108.
1 year ago
Victor Julien c79a382e42 eve/tls: log ALPN for client and server
Part of the extended logging.

Logs `client_alpns` and `server_alpns` arrays in the tls object.

Ticket: #7055.
1 year ago
Victor Julien 0b37654578 tls: store all ALPN records in the state
For later logging and detection.
1 year ago
Victor Julien e3e917d967 detect/icmp-id: remove prefilter pseudo check
This is now handled at registration with SIG_MASK_REQUIRE_REAL_PKT.
1 year ago
Victor Julien 8df53d6411 detect/dsize: remove prefilter pseudo check
This is now handled at registration with SIG_MASK_REQUIRE_REAL_PKT.
1 year ago
Victor Julien 44d2e1aad7 detect/stream_size: allow match on pseudo packets
Often used with stream content, which can be inspected with pseudo packets.
1 year ago
Victor Julien 6958efa2dc detect/csum: remove pseudo packet checks 1 year ago
Victor Julien 64f5865efc detect/csum: general code cleanups 1 year ago
Victor Julien 956c8bebd1 detect/prefilter: use sig mask to exclude pkt engines
Add an argument to the packet prefilter registration function to include
`SignatureMask` flags. This will be used at runtime to only call these
prefilter engines when the mask check passes.
1 year ago
Victor Julien 4c2960169c detect/prefilter: minor function ptr cleanup
Use a typedef'd function pointer for packet Prefilter callbacks to make
the code consistent with the other callbacks.
1 year ago
Victor Julien 2d1ccb76b1 detect: remove pseudo checks from packet keywords
Keep as debug validation check.
1 year ago
Victor Julien d03660a646 detect: skip pseudo packets if sig needs real pkt
If a signature uses a condition that requires a real packet, filter
out pseudo packets as early as possible. To do this, the SignatureMask
logic is used.

This allows for the removal of checks for pseudo packets in individual
keywords `Match` functions, which will be done in a follow up commit.

Update analyzer to output the new flag.

Ticket: #7002.
1 year ago
Philippe Antoine e3034a6f54 tests: move detect http.uri tests to suricata-verify
Ticket: 3725
1 year ago
Philippe Antoine d59c60410f fuzz: adapt target to number of keywords being dynamic
Ticket: 4683
1 year ago
Philippe Antoine 4fe3f04fa3 detect/enip: move keywords to rust
Ticket: 4863
1 year ago
Philippe Antoine ce1eea4ad6 detect/websocket: move keywords to rust
Ticket: 4863
1 year ago
Philippe Antoine 16952d67e7 detect/dhcp: move keywords to rust
Ticket: 4863
1 year ago
Philippe Antoine ae72376ebe detect/snmp: move keywords to rust
Ticket: 4863

On the way, convert unit test DetectSNMPCommunityTest to a SV test.

And also, make snmp.pdu_type use a generic uint32 for detection,
allowing operators, instead of just equality.
1 year ago
Philippe Antoine 4bbe7d92dc detect: helper to have pure rust keywords
detect: make number of keywords dynamic

Ticket: 4683
1 year ago
Eric Leblond b128a75973 profiling: check packet flag first
This fixes the state handling and simplify the logic.
1 year ago
Eric Leblond eecb3440e2 profiling: add option to active rules profiling at start
When replaying a pcap file, it is not possible to get rules
profiling because it has to be activated from the unix socket.
This patch adds a new option to be able to activate profiling
collection at start so a pcap run can get rules profiling
information.
1 year ago
Victor Julien 37be66eef9 detect/iprep: update function naming
Bring in line with new Rust code naming for FFI functions.
1 year ago
Victor Julien 83976a4cd4 detect/iprep: implement isset and isnotset
Implement special "isset" and "isnotset" modes.

"isset" matches if an IP address is part of an iprep category with any
value.

It is internally implemented as ">=,0", which should always be true if
there is a value to evaluate, as valid reputation values are 0-127.

"isnotset" matches if an IP address is not part of an iprep category.

Internally it is implemented outside the uint support.

Ticket: #6857.
1 year ago
Victor Julien 3e46c51651 reputation: minor cleanup
No need to init ptrs to NULL after SCCalloc.
1 year ago
Jason Ish f0dbfe863d misc: prefix functions with SC not Sc 1 year ago
Victor Julien d02054fa31 detect/noalert: point noalert/alert to new doc 1 year ago
Victor Julien d5fb8204b6 detect: implement 'alert' keyword as a companion to 'noalert'
This can be used to implement alert then pass logic.

Add support for alert-then-pass to alert handling routines.

Ticket: #5466.
1 year ago
Victor Julien 92581dbc06 detect: set ACTION_ALERT for rules that should alert
Replaces default "alert" logic and removed SIG_FLAG_NOALERT.

Instead, "noalert" unsets ACTION_ALERT. Same for flowbits:noalert and
friends.

In signature ordering rules w/o action are sorted as if they have 'alert',
which is the same behavior as before, but now implemented explicitly.

Ticket: #5466.
1 year ago
Victor Julien 8f72a04973 detect/alert: minor loop cleanup 1 year ago
Victor Julien 44e7fdc3ca detect/noalert: minor cleanup 1 year ago
Philippe Antoine 82c03f72c3 enip: convert to rust
Ticket: 3958

- transactions are now bidirectional
- there is a logger
- gap support is improved with probing for resync
- frames support
- app-layer events
- enip_command keyword accepts now string enumeration as values.
- add enip.status keyword
- add keywords :
    enip.product_name, enip.protocol_version, enip.revision,
    enip.identity_status, enip.state, enip.serial, enip.product_code,
    enip.device_type, enip.vendor_id, enip.capabilities,
    enip.cip_attribute, enip.cip_class, enip.cip_instance,
    enip.cip_status, enip.cip_extendedstatus
1 year ago
Philippe Antoine 0d267e29a5 files: remove the need for state in callbacks
As files now belong to transactions
1 year ago
Philippe Antoine e8438fdb58 app-layer: remove unused parameters 1 year ago
Philippe Antoine 441813aa47 fuzz: build with dependencies on rust and c lib
So that there is no need to remove the final binary, to recompile
it if there has been changes in the code.
1 year ago
Philippe Antoine 358bc05fa1 ci: fix and test with Wunused-macros
Ticket: 6937

Completes ce9bfba76a
1 year ago
Juliana Fajardini 69e26de197 pgsql/logger: open json object from logger function
Before, the JsonBuilder object for the pgsql event was being created
from the C-side function that actually called the Rust logger.

This resulted that if another module - such as the Json Alert called the
PGSQL logger, we wouldn't have the `pgsql` key present in the log output
- only its inner fields.

Bug #6983
1 year ago
Victor Julien 306fd795c3 smtp/frames: initial frame support
Adds the following frames:

  command_line
  data
  response_line

The *_line frames are per line, so in multi-line responses each line
will have it's own frame.

Ticket: #4905.
1 year ago
Victor Julien 2cebc8368c flow-worker: debug output about updates 1 year ago
Victor Julien c17df004ed stream: process ASYNC in packet dir
There will generally not be an opposing direction to handle
the app update.
1 year ago
Victor Julien a9dd1572d4 detect/frames: inspect frames only in correct direction
Inspect frames in the correct direction after they have been created.
1 year ago
Victor Julien 866c128c43 app-layer: flag flow for next packet in other dir
Add new flags to trigger FLOW_TS_APP_UPDATED/FLOW_TC_APP_UPDATED flags
to be set for the next packet in the relevant direction.

This allows for app relevant work to be done in the next packet in our
direction.
1 year ago
Victor Julien 683363b42d detect/frames: avoid IPS rescanning
Make sure to only scan the data when the app layer has been updated
as well.

Ticket: #6718.
1 year ago
Victor Julien 2e5e3498a6 app-layer/frames: add by type getter
AppLayerFrameGetLastOpenByType: Returns the most recent frame with a type
with unknown length (-1).

Check if type is globally enabled first.
1 year ago
Victor Julien 803e8dd32e frames: add FrameGetLastOpenByType
Getter for the most recent frame with unknown length (-1).
1 year ago
Victor Julien c7402d2d01 frames: fix bounds check 1 year ago
Victor Julien 243587805d stream: minor code clarification
'dir' was too generic, so indicate it's about the app-layer update direction.
1 year ago
Victor Julien e6c1b9d846 app-layer: minor code clarification
'dir' was too generic, so indicate it's about the app-layer update direction.
1 year ago
Philippe Antoine a10c1f1dde smtp: use rust for mime parsing
Ticket: #3487
1 year ago
Philippe Antoine 5f75b9a6e3 http: use rust for mime parsing
Ticket: #3487
1 year ago
Philippe Antoine ddb3a0c9de http: multipart unused code removal 1 year ago
Victor Julien 1190e426f9 defrag: remove trackers on lookup
When looking up a tracker, remove any timed out / completed trackers.
1 year ago
Victor Julien 75b78d7643 defrag: add defrag.memuse counter
Gives a current snapshot of the memory in use by the defrag engine.
1 year ago
Victor Julien becc91c306 defrag: timeout check on look up; tag for removal 1 year ago
Victor Julien 83dc703d1f defrag: add various counters 1 year ago
Victor Julien dcaeed7b95 defrag: remove tracker on frag pool issues
If a frag wasn't inserted due to pool empty or alloc failure, clear and

invalidate the tracker.
1 year ago
Victor Julien fc05d253d2 defrag: add defrag.mgr.tracker_timeout counter
Updated by flow manager.
1 year ago
Victor Julien 39876bf566 defrag: update exception policy counter: ptr can't be NULL 1 year ago
Victor Julien 383892463c defrag: fix test passing NULL pointers 1 year ago
Victor Julien fc93a3875e defrag: turn queue into stack
Only used by the spare tracker logic, which works better as a stack.
1 year ago
Victor Julien 475c40f9c2 defrag: minor cleanups; dead code removal 1 year ago
Victor Julien 8b57545540 defrag: turn hash row into single linked list 1 year ago
Victor Julien 26a73503aa defrag: timeout/reuse start of list 1 year ago
Victor Julien 97705c94e4 defrag: simplify lookup/create loops
Turn into a simpler do { } while loop like in the flow code.
1 year ago
Victor Julien 3b1fecbab1 output/streaming: suppress noisy start up message 1 year ago
Victor Julien 621fe38dbf output/lua: handle registration error
Use error message instead of info message.
1 year ago
Eric Leblond 21916b9743 eve: revert ethernet addresses when needed
EVE logging has a direction parameter that can cause the logging
of an application layer to be done in a direction that is not linked
to the packet. As a result the source IP addres could be assigned the
MAC address of the destination IP and reverse.

This patch addresses this by propagating the direction to the ethernet
logging function and using it there to define the correct mapping.

Issue #6405
1 year ago
Alexey Simakov a8217d288a util/radix-tree: fix potential dereference of nullptr
Fix potential dereferece of nullptr in case of
unsuccessful allocation of memory leak for tree nodes

Bug: #7049
1 year ago
Jason Ish 10a367b116 lua: use quoted include style to avoid system includes
Use quoted include style for Lua includes ("lua.h" instead of <lua.h>)
as this could result in system includes being picked up instead of the
includes from our vendor directory.
1 year ago
Philippe Antoine 20423fdd38 style: remove some useless return
and remove empty line before end of function
1 year ago
Philippe Antoine a262e203f9 src: remove some unused parameters 1 year ago
Victor Julien 41b9836b11 threads: give threads more time to get ready
In certain conditions, it can take a long time for threads to start up.
For example in af-packet, setting up the socket, rings, etc has been
observed to take close to half a second per thread, and since the
threads go one by one in a preset order, this means the start up can
take a lot of time if there are many threads. The old logic would just
allow a hard coded 60s. This was not always enough when the number of
threads was high.

This patch makes the wait time take the number of threads into account.
It adds a second of time budget to the base 60s for each thread.

So as an example, if a system has 112 af-packet threads, it would wait
172 seconds (60 + 112) for the threads to get ready.

Ticket: #7048.
1 year ago
Victor Julien 85fd4b2ec7 threads: optimize start up check
When starting a large amount of threads, the loop was inefficient. It
would loop over the threads and if one wasn't yet ready it would sleep a
bit and then reevaluate all the threads. This reevaluation of threads
already checked was inefficient, and could lead to the time budget
running out.

This patch splits the check, and keeps track of the threads that have
already passed. This avoids the rescanning of already checked threads.
1 year ago
Victor Julien 121955d5c1 tls-store: support client logging
Adds a `client-` prefix to the logged certs and meta files.

Ticket: #7045.
1 year ago
Victor Julien 6fe5b739b4 tlsstore: remove stale FIXME 1 year ago
Victor Julien 032bc04a1e detect/tls.store: fix direction check
STREAM_* flags are invalid for `Flow::flags`.

Fixes: dfcb429524 ("detect/cert: Use client side certs")
1 year ago
Jason Ish 10e6028175 lua: track memory limit exceede errors
Update the Lua allocated to set a code on memory allocation limit
exceeded errors so an appropriate error message can be logged and a
state incremented.

Fixes the tracking of the allocated size by using the difference
between original size, and new size and toss in some debug
validations.
1 year ago
Jason Ish 011f0ba994 lua: remove sandbox lib for now
Not sure if I see a use for it, some extra debug logging might be just
as useful for those writing Lua scripts.
1 year ago
Jason Ish 5a1cba72f0 lua: add logging and counter for instruction limit being exceeded 1 year ago
Jason Ish c8fa454cb2 lua: add blocked functions as a special log type plus stat
Distinguish between a generic Lua script error and an error created by a
function being blocked, so each is logged once respective of each other.

Also add a stat that is incremented when a script fails due to a
blocked function.

NOTE: This does not catch calls to functions that are blocked by not
having the library loaded, such as "io.open", as they are blocked by
not even loading the "io" library.
1 year ago
Jason Ish 86f9e43068 lua: use a function allow list instead of a deny list
The Lua library surface area is small enough to manage an allow list,
which is generally better than a deny list, as we'll explicitly need
to opt-in to new functions provided by the Lua runtime.
1 year ago
Jason Ish 2e440169d6 lua: remove lua as a compile time feature
Its always built-in. However, can be disabled at runtime.
1 year ago
Jason Ish bc011f2205 lua: use rust crate to vendor (bundle) lua
Remove lua-dev(el) from all CI tests.
1 year ago
Jason Ish afb705d278 lua: reset instruction counter before calling script 1 year ago
Jason Ish 1f05a17fb9 lua: misc cleanups in sandbox implementation
Including:
- rename guards
- SCMalloc to SCCalloc
- remove unused enum
- rename public functions to our naming standard
1 year ago
Jo Johnson 04adb0c0f6 lua: Add config to allow sandbox bypass 1 year ago
Jo Johnson e946b20e0f lua: Add config override for lua sandbox limits 1 year ago
Jo Johnson 8428b0b9d7 lua: Add lua sandbox for detection rules 1 year ago
Jo Johnson 01c8af766c lua: remove internal references to luajit 1 year ago
Jo Johnson d5c6c3a21c lua: build lua by default
Ticket: #4776

[Edits by Jason Ish]
- Add Lua in CI where needed
- Disable Lua for builds that don't have Lua 5.4
1 year ago
Jo Johnson 712496bb3f lua: Remove luajit support
lua 5.4 support is not available in luajit

Ticket: #4776
1 year ago
Jason Ish 6e2a1ec5d6 misc: move prototypes to correct header
Move prototypes for functions that exist in util-port-interval-tree.c
from detect-engine-port.h to util-port-interval-tree.h.

Fix header guard names while there.
1 year ago
Philippe Antoine b91e7fe2ae detect/http-server-body: clean up tests
Ticket: 4083
1 year ago
Philippe Antoine ce16a56a1f detect: unify functions for multi-buffer
Ticket: 6575

Multi buffers keywords now use a single registration function
DetectAppLayerMultiRegister with a GetBuffer argument.

This GetBuffer function pointer is similar to the ones used by
single-buffer keyword, except that it takes an additional
parameter which is the index of the buffer to get.
Under the hood, an anonymous union between these 2 functions
pointers types is used.

In the end, this deduplicates code, especially the calls to
DetectEngineContentInspection
1 year ago
Philippe Antoine 55bc5f2290 detect/template: make template use DetectEngineInspectBufferGeneric 1 year ago
Philippe Antoine ce9bfba76a ci: fix and test with Wunused-macros
Ticket: 6937
1 year ago
Philippe Antoine b3eb1c4f81 clean: remove unused struct definitions
Found with
git grep "typedef struct" src/ | awk '{print $3}' | sort |
uniq | sed 's/_$//' | while read i; do
echo -n $i; git grep $i | wc -l; done | awk '$2 < 3'

Ticket: 4083
1 year ago
Richard McConnell fc2e49f84a app-layer: Set sc_errno upon error return
Bug: https://redmine.openinfosecfoundation.org/issues/6782

Callers to these allocators often use ``sc_errno`` to provide context of
the error. And in the case of the above bug, they return ``sc_errno``,
but as it has not been set ``sc_errno = 0; == SC_OK``.

This patch simply sets this variable to ensure there is context provided
upon error.
1 year ago
Victor Julien 52a008e358 detect/http-host: clean up tests 1 year ago
Victor Julien 6c937a9243 pcap-log: use correct pkthdr size for limit enforcement
The on-disk pcap pkthdr is 16 bytes. This was calculated using
`sizeof(struct pcap_pkthdr)`, which is 24 bytes on 64 bit Linux. On
Macos, it's even worse, as a comment field grows the struct to 280
bytes.

Address this by hardcoding the value of 16.

Bug: #7037.
1 year ago
Victor Julien 9b980b18a8 pcap-log: minor cleanups 1 year ago
Victor Julien ea8c283dc7 pcap-log: minor cleanup
Use same pointer to one location consistently.
1 year ago
Victor Julien 8c4b96129f pcap-log: always pass 'comp' to PcapWrite
The variable is always available.
1 year ago
Victor Julien 5aa00aae0a pcap-log: rename connp to comp
Matches other variable names for the compression settings.
1 year ago
Victor Julien 3eb74c9992 pcap-log: don't check variable that is never set
`rotate` was never modified.
1 year ago
Victor Julien 5455799795 time: only consider packet threads
In offline mode, a timestamp is kept per thread, and the lowest
timestamp of the active threads is used. This was also considering the
non-packet threads, which could lead to the used timestamp being further
behind that needed. This would happen at the start of the program, as
the non-packet threads were set up the same way as the packet threads.

This patch both no longer sets up the timestamp for non-packet threads
as well as not considering non-packet threads during timestamp
retrieval.

Fixes: 6f560144c1 ("time: improve offline time handling")

Bug: #7034.
1 year ago
Shivani Bhardwaj 0aaec69303 flow: use debug validate macro 1 year ago
Shivani Bhardwaj d6b63b38ca flow: add defensive check on memuse 1 year ago
Shivani Bhardwaj 7144b9421d tcp: use bool wherever possible 1 year ago
Shivani Bhardwaj f4b8f706fa flow: use bool wherever possible 1 year ago
Shivani Bhardwaj 2c751dba73 flow: remove unneeded else 1 year ago
Shivani Bhardwaj 7bd9f88ecd flow: minor loop cleanups 1 year ago
Philippe Antoine fd262df457 http: fix nul deref on memcap reached
HttpRangeOpenFileAux may return NULL in different cases, including
when memcap is reached.
But is only caller did not check it before calling HttpRangeAppendData
which would dereference the NULL value.

Ticket: 7029
1 year ago
Shivani Bhardwaj 232c44eb4a output/json: log tls subjectaltname
Feature 5234
1 year ago
Shivani Bhardwaj 83af42cc03 detect/tls-subjectaltname: add sticky buffer
Add TLS SubjectAltName sticky buffer. It is implemented as multi-buffer.

Feature 5234
1 year ago
Shivani Bhardwaj 3a1c12414a tls: store list of subject alternative names
So far, the SANs were available as a part of IssuerDN via x509_parser
crate but SANs were not available to the SSLState* to be directly used
to setup and match against a sticky buffer.
Expose it to SSLStateConnp.

Feature 5234
1 year ago
Jason Ish 6d2d8c26d3 detect-lua: small cleanups
- remove unused headers
- cleanup/rename flags
1 year ago
Jason Ish 224f55ba21 detect/lua: don't treat a crashed script as no match
If a rule script crashed, the return value was treated as a no
match. This would make a negation of the rule match and alert.

Instead cleanup and exit early if the rule script crashed and don't
run negation logic.

A stat, detect.lua.errors has been added to count how many times a
script crashes.

Also consolidates the running of the Lua script and return value
handling to a common function.

Bug: #6940
1 year ago
Philippe Antoine f2c39fc87b ftp: protocol detection avoiding FP on POP3 1 year ago
Philippe Antoine 2c305ba37e pop3: protocol detection
Ticket: #6366
1 year ago
Philippe Antoine ed895c04ff smtp: exit data mode if data command was rejected
And the server was advertising pipelining.

Ticket: 6906
1 year ago
Philippe Antoine dfdf2e2d1a detect: checks for space in http.protcol keyword 1 year ago
Philippe Antoine 7582b18a9f http: configures libhtp to allow spaces in uri
Ticket: #2881
1 year ago
Giuseppe Longo b728916ca6 decode/gre: decode arp packets 1 year ago
Giuseppe Longo 01586d884d output-json/arp: implement logger
This adds a logger for ARP, disabled by default.

Ticket #6827
1 year ago
Giuseppe Longo a1c6328156 output/json: check 5-tuple values prior to logging
This commit enhances the JSON output by introducing a feature for conditional port logging.
Now, port logging is dependent on the underlying protocol
(such as TCP, UDP, or SCTP), where port information is pertinent, while it
avoids unnecessary logging for protocols where a port is not utilized (e.g. ARP).

Furthermore, this update ensures that IP addresses and the protocol have
meaningful values set, rather than being logged as empty strings.

These changes will make each log entry more precise, eliminating cases where
5-tuple fields are empty or set to zero, indicating the absence of a field.
1 year ago
Giuseppe Longo 987a27923d output/json: make JSONFormatAndAddMACAddr public
This change exposes 'JSONFormatAndAddMACAddr' as a public function,
allowing it to be reused across modules, such as the ARP logger, for logging
MAC addresses extracted from ARP packets.
1 year ago
Giuseppe Longo 5219a5da5f decode/arp: implement decoder
This adds a decoder for ARP.

Ticket #6827
1 year ago
Shivani Bhardwaj 12d027f6a2 base64: re-add the check for destination space
Cover all the calls to DecodeBase64Block with the check for enough
space. Found by the recently introduced fuzz target.

Bug 7028

Fixes: c0bc43c393 ("util/base64: use decoder fns per RFC")
1 year ago
Philippe Antoine fcdd7f000a detect: add options to app-layer-protocol keyword
Ticket: 4921

app-layer-protocol keyword accept an optional mode to precise
which protocol we want to match: toclient, toserver, final,
or original
1 year ago
Philippe Antoine edd5507ea4 tests: do not bother to free a null pointer
Ticket: #7013
1 year ago
Victor Julien d02c57bd1f hostbits: release use_cnt for unix (add|remove)-hostbit
Commands would leave use_cnt incremented, never decrementing them. This
would lead to a asserting triggering at shutdown.

Bug: #7020.
1 year ago
Victor Julien bc2dfe4c17 device: don't crash on unix command 'iface-bypassed-stat'
In the default config iface bypass support is not enabled,
and storage API not initialized for it. Using it will lead to a crash.

This commit first checks if the device storage API is initialized.

Bug: #7022.
1 year ago
Philippe Antoine 9e01956e77 detect: log relevant frames app-layer metadata
Ticket: 6973

Completes commit 2b4e10224e
1 year ago
Shivani Bhardwaj 2e6777c8e3 fuzz: add target for DecodeBase64
Task 6050
1 year ago
Shivani Bhardwaj 363050616a base64_data: reject fast_pattern use
If a rule has fast_pattern on base64_data, it is anyway not applied, so,
consider any such rules invalid.

Bug 5220
1 year ago
Jeff Lucovsky cb56752bf7 config/ja3: Eliminate warnings when JA3 is disabled
This commit eliminates warnings when either ja3, ja4 or both are
disabled.
1 year ago
Philippe Antoine ce4119ae3d snmp: remove community keyword unit test
Ticket: 3725

This test was moved to suricata-verify snmp-community
1 year ago
Shivani Bhardwaj 99eaf3943a util/base64: remove coverity reported dead code
New defect(s) Reported-by: Coverity Scan
Showing 1 of 1 defect(s)

** CID 1596621:  Control flow issues  (DEADCODE)
/src/util-base64.c: 238 in DecodeBase64RFC4648()

________________________________________________________________________________________________________
*** CID 1596621:  Control flow issues  (DEADCODE)
/src/util-base64.c: 238 in DecodeBase64RFC4648()
232         DEBUG_VALIDATE_BUG_ON(bbidx == B64_BLOCK);
233
234         /* Handle any leftover bytes by adding padding to them as long as they do not
235          * violate the destination buffer size */
236         if (bbidx > 0) {
237             padding = bbidx > 1 ? B64_BLOCK - bbidx : 2;
>>>     CID 1596621:  Control flow issues  (DEADCODE)
>>>     Execution cannot reach the expression "3U" inside this statement: "numDecoded_blk = 3U - ((pad...".
238             uint32_t numDecoded_blk = ASCII_BLOCK - (padding < B64_BLOCK ? padding : ASCII_BLOCK);
239             if (dest_size < *decoded_bytes + numDecoded_blk) {
240                 SCLogDebug("Destination buffer full");
241                 return BASE64_ECODE_BUF;
242             }
243             /* Decode base-64 block into ascii block and move pointer */

Also, add a comment explaining the padding logic for leftover data.

Bug 6985
1 year ago
Victor Julien 64dc217f9f detect/iprep: allow 0 as a reputation value
Rules would allow checking against value 0, but internally the value
was used to indicate "no value". To address this, the internals now
return negative values for not found. This way value 0 can be fully
supported.

Bug: #6834.
1 year ago
Victor Julien 673d27c861 detect/iprep: minor code cleanups 1 year ago
Jason Ish 556cfe56bf rust/dns: ffi naming and visibility cleanups
- Remove no_mangle and pub from FFI functions that are only accessed
  with a function pointer.
- Rename all no_mangle FFI functions to our C naming scheme.
1 year ago
Victor Julien 86a363b1bc decode/tcp: improve pointer hygene
Avoid NULL pointer calculations.
1 year ago
Victor Julien 0dfa5793db decode/icmpv4: rename ICMPV4_GET_EMB_IPV4 to PacketGetICMPv4EmbIPv4
Follows function nameing style.

Ticket: #5517.
1 year ago
Victor Julien 6e23419665 decode/icmpv6: store embedded ip6h ptr as offset
Reduces direct pointer usage and reduces Packet size.

Ticket: #6938.
1 year ago
Victor Julien f2288ee39b decode/icmpv4: store embedded ip4h ptr as offset
Reduces direct pointer usage and reduces Packet size.

Ticket: #6938.
1 year ago
Victor Julien d89d4ceb3c decode/icmpv4: put embedded pointer first
Reduce gaps in the structure.

Ticket: #6938.
1 year ago
Victor Julien 13281109e3 decode/tcp: reduce TCPVars by turning bools into bitfields
To reduce Packet size and make similar fields follow the same pattern.

Ticket: #6938.
1 year ago
Victor Julien 8698610b4a af-packet: fix eBPF/XDP compilation 1 year ago
Victor Julien 68804b8c4b decode/tcp: move tcph into L4 packet data
To reduce Packet size.

Ticket: #6938.
1 year ago
Victor Julien 28ac86096a decode/udp: move udph into L4 packet data
To recude Packet size.

Ticket: #6938.
1 year ago
Victor Julien 54362d44db decode/ethernet: move ethh into L2 section
L2 section similar to L3 and L4 sections.

Ticket: #6938.
1 year ago
Victor Julien b2f7d3604b decode/pppoe: localize pppoedh pointer
Remove from Packet struct as there were no users of it.

Ticket: #6938.
1 year ago
Victor Julien b4ef910aff decode/pppoe: localize pppoesh header pointer
Remove header pointer from Packet as there were no users of it.

Ticket: #6938.
1 year ago
Victor Julien 852ff83d70 decode/icmpv4: move icmpv4h into L4 packet data
To reduce Packet size.

Ticket: #6938.
1 year ago
Victor Julien b959d1dba8 decode/icmpv6: move icmpv6h into L4 packet data
Also start vars section in L4 for icmpv6vars.

To reduce Packet size.

Ticket: #6938.
1 year ago
Victor Julien 30ae13f2c3 decode/esp: move esph into L4 packet data
To reduce Packet size.

Ticket: #6938.
1 year ago
Victor Julien 7d04216cad decode/gre: move greh into L4 packet data
To reduce Packet size.

Ticket: #6938.
1 year ago
Victor Julien 20b8c79259 decode/sctp: move sctph into L4 packet data
Reduces Packet size.

Ticket: #6938.
1 year ago
Victor Julien 2137bbbf9a decode/icmpv6: add and use PacketIsICMPv6 inline func
For better readability and type checking.

Ticket: #5517.
1 year ago
Victor Julien 3a1e60745e decode/icmpv6: switch ptr checks to PKT_IS_ICMPV6
For better readability and type checking.

Ticket: #5517.
1 year ago
Victor Julien 1002068e39 decode/icmpv4: add and use PacketIsICMPv4 inline func
For better readability and type checking.

Ticket: #5517.
1 year ago
Victor Julien 5c3036bea8 decode/udp: add and use PacketIsUDP inline func
Replace PKT_IS_UDP macro with PacketIsUDP inline function.

For better readability and type checking.

Ticket: #5517.
1 year ago
Victor Julien cca912e9b3 decode/tcp: add and use PacketIsTCP inline func
To prepare future changes to the Packet header pointers.

Ticket: #5517.
1 year ago
Victor Julien 329fb2affa decode: start l4 packet area; convert csum handling 1 year ago
Victor Julien 54b9f344b7 decode/icmpv4: switch ptr checks to PKT_IS_ICMPV4
To prepare future changes to the Packet header pointers.

Ticket: #5517.
1 year ago
Victor Julien c9ef85e620 decode: refactor L3 checkum handling
Use a flag to indicate a calculated csum is available.

Allows packet reset to just use memset.
1 year ago
Victor Julien 2001ddc583 decode: use macro's instead of direct ptr checks
To prepare future changes to the Packet header pointers.

Ticket: #5517.
1 year ago
Victor Julien 769b020a55 decode/icmpv6: improve packet vars layout
Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 18d49c27ae decode/icmpv6: remove unused error_ptr field
Was only set, never checked.

Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 4b492c2ded decode/icmpv6: remove embedded address storage
Only used in tests. For the tests, switch to getting headers from embedded IPv6 header.

Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 521c968079 decode/icmpv6: remove unused L4 header pointers from Packet
Not used, so no need to keep them.

Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien a22047b770 decode/icmpv4: shrink icmpv4 packet vars
Remove unused L4 header pointers.

Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 9ef5af291b decode/icmpv4: remove unused Packet members
Addresses are pulled from embedded IPv4 header directly.
Embeded hlen was unused.

Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 1777e0314e decode/tcp: remove unused macro
SET_OPTS is now unused, so remove.
1 year ago
Victor Julien 6b8093d7b8 decode/tcp: reduce size needed for SACK tracking
No longer use a pointer, but rather an offset.

Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 81c4b10dc8 decode/tcp: minor struct layout optimization
Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 7be0678c3a decode/tcp: reduce size needed for tracking WSCALE
Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 6cab2480e5 decode/tcp: reduce space needed for tracking TFO
Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 6a23fafa5f decode/tcp: reduce space needed for MSS tracking
Part of effort to make Packet more compact.

Ticket: #6938.
1 year ago
Victor Julien 9632c2f570 decode/tcp: optimize SACKOK storage
Take less space in the TCPVars for tracking if SACKOK is set.

Reduces size by 16 bytes.

Ticket: #6938.
1 year ago
Victor Julien 3c17d5d73c decode/ipv4: minor test cleanups 1 year ago
Victor Julien a40d6f5c4f decode/ipv6: prep for turning ip4h/ip6h into union
Store IPv6 decoder vars in a new Packet::l3 section in the packet.

Use inline functions instead of the often multi-layer macro's for
various IPv6 header getters.

Ticket: #6938.
1 year ago
Victor Julien 2d5c381c3b decode/ipv4: prep for turning ip4h/ip6h into union
Store IPv4 decoder vars in a new Packet::l3 section in the packet.

Use inline functions instead of the often multi-layer macro's for
various IPv4 header getters.

Ticket: #6938.
1 year ago
Victor Julien 79e6f7018f decode: minor style cleanup in the header ptrs 1 year ago
Victor Julien 1535c88601 validate: remove ip4h/ip6h check
In preparation of making them union members.
1 year ago
Victor Julien 0e99e8a7fa defrag: track ip hdr offset in tracker
In preparation of future Packet structure changes.

Ticket: #6938.
1 year ago
Victor Julien c4a6ee1647 decode: reduce macro use in IPv4/IPv6
Improve readability by setting up data/data_len once before
passing on to the other decoders.

Work in preparation of other decoder changes.

Ticket: #5517.
1 year ago
Victor Julien 9d9ae62b6e flow: avoid direct IP header checks
To prepare future changes to the Packet header pointers.

Ticket: #5517.
1 year ago
Victor Julien eb3ca643c1 decode: reduce PKT_IS_IPV4/PKT_IS_IPV6 use
Replace it with inline functions. Adds inline functions to
wrap PKT_IS_IPV4/PKT_IS_IPV6.

This is in preparation of removing the macro's, and cleaning up the
header pointers.

Ticket: #5517.
1 year ago
Victor Julien 813147755d decode: rename IP_GET_IPPROTO to PacketGetIPProto
To match function naming style.

Ticket: #5517.
1 year ago
Victor Julien 61df76a57d decode: implement IP_GET_IPPROTO as inline func
For better readability and type checking.

Ticket: #5517.
1 year ago
Shivani Bhardwaj 14e2c579f6 tls/random: fix incorrect direction handling
The connp objects were incorrectly set per direction leading to
incorrect matches on respective directions.

Bug 6989
1 year ago
Victor Julien a51b6fa6bd pcap: address codeql warning
Use of potentially dangerous function: localtime

Windows localtime is thread safe and no localtime_r is availabe on
Windows, so use separate logic for Windows.
1 year ago
Victor Julien 60e6d1d77d rohash: fix codeql warnings
Suspicious pointer scaling to void
1 year ago
Victor Julien ea110aca5b rohash: minor code cleanups 1 year ago
Jason Ish ad4185b3c4 misc: remove some unused includes
Remove unused includes noticed while updating runmode access.
1 year ago
Jason Ish d2537361f4 run-mode: remove duplicate var; add setter function
Remove the global "run_mode" var as it was a duplicate of the runmode on
the "instance" struct. For direct access outside of suricata.c, use the
getter function.

Also expose a setter function for unit tests that need to change it.
1 year ago
Shivani Bhardwaj a2502c9fca util/base64: add more tests to increase coverage 1 year ago
Shivani Bhardwaj 4c131a4b30 util/mime: check invalidity after final b64 block
Since there is code in place that skips over invalid base64 characters
and creates a new array out of the remainder vector, all test must be
made after that final array has been created and against the variable
that holds the actual length of the final array.
1 year ago
Shivani Bhardwaj 884400f1ae util/mime: skipped chars should be marked consumed 1 year ago
Shivani Bhardwaj a573881418 util/base64: use real numbers in test vectors 1 year ago
Shivani Bhardwaj 76de3d9ab0 util/base64: update tests to correct consumed bytes
Also, don't treat a successful decoding that had invalid characters as
errors. The caller does not treat them as errors so it makes sense to
consider it successful if something was decoded.

Bug 6964
1 year ago
Shivani Bhardwaj c0bc43c393 util/base64: use decoder fns per RFC
instead of the common decoder fn.

Bug 6964
1 year ago
Shivani Bhardwaj 885d540dea util/base64: add base64 decode fns per RFC
Base64 decoder tried to handle several different cases in one fn
including how the data should be decoded and corresponding consumed and
decoded bytes calculated for RFC 2045 and RFC 4648 which are very
different. This left window for mistakes and edge cases that one mode is
not supposed to take care of while the other can.

Separate the decoder per RFC so as to have each variable their own scope
and playground. This also makes it much easier to debug if there are any
issues in decoding w.r.t. different callers.

This also takes care of some known issues like making sure the consumed
bytes are correctly handled.

Bug 6964
1 year ago
Philippe Antoine d8e0c72644 app-layer: remove unused C wrappers
Ticket: 4083
1 year ago
Philippe Antoine 316cc528f7 detect/parse: set limits for pcre2
Ticket: 6889

To avoid regexp dos with too much backtracking.
This is already done on pcre keyword, and pcrexform transform.
We use the same default limits for rules parsing.
1 year ago
Philippe Antoine fd47e67dc6 util/base64: fix buffer overflow
Ticket: 6902

In case the caller of DecodeBase64 does not supply a big enough
output buffer.
1 year ago
Jason Ish d226d0a3fc defrag: fix check for complete packet
The list of fragments may still contain overlaps, so adding up the
fragment lengths is flawed. Instead track the largest size of
contiguous data that can be re-assembled.

Bug: #6675
1 year ago
Jason Ish f1709ea551 defrag: fix subsequent overlap of start of original (bsd)
Fix the BSD policy case where a subsequent fragment starts before an
original fragment and overlaps the beginning of the original
fragment. In this case the overlapping data from the new fragment is
preferred.

Suricata was preferring the data from the original fragment, but it
should only do that when the original fragment has an offset <= to the
new fragment.

- Adds tests for this case.

Bug: #6669
1 year ago
Jason Ish d0fd078250 defrag: check next fragment for overlap before stopping re-assembly
Instead of breaking the loop when the current fragment does not have
any more fragments, set a flag and continue to the next fragment as
the next fragment may have data that occurs before this fragment, but
overlaps it.

Then break if the next fragment does not overlap the previous.

Bug: #6668
1 year ago
Jason Ish bdd17de73d defrag: use uint8_t in unit tests 1 year ago
Jason Ish 2f00b5870a defrag: consistent unit test naming
Use a more consistent naming scheme between ipv4 and ipv6.
1 year ago
Jason Ish 6339deadce defrag: make tests more readable
Make tests more readable for comparing to the paper "Target-Based
Fragmentation Reassembly".
1 year ago
Jason Ish 276d3d6541 defrag: minor cleanups
- typo in comment
- remove debug function that is not used and no longer valid
1 year ago
Philippe Antoine 402f39b4f2 util/mime: adds safety check
Ticket: 6904

Even if there is no problem, just fortify the function,
so that it is future-proof if the caller does not do the check.
1 year ago
Philippe Antoine 7274ad58aa detect: use direction-based tx for app-layer logging
When we only have stream matches.

Ticket: 6846

This solves the case where another transaction was created
by parsing data in the other direction, before running the
detection.

Like
1. get data in direction 1
2. acked data: parse it, but do not run detection in dir 1
3. other data in direction 2
4. other data acked : parse it and create new tx,
then run detection for direction 1 with data from first packet
1 year ago
Victor Julien f6635ea960 mime: validate that chunk size stays within limit 1 year ago
Victor Julien 6f27f2a817 smtp: minor debug cleanup 1 year ago
Victor Julien 8ef15ee205 streaming/buffer: add validation checks for data chunk sizes 1 year ago
Victor Julien 9aff8afc62 util/file: add validation check for extreme data chunk sizes 1 year ago
Victor Julien cf6278f95a streaming/buffer: improve integer handling safety
Unsafe handling of buffer offset and to be inserted data's length
could lead to a integer overflow. This in turn would skip growing
the target buffer, which then would be memcpy'd into, leading to
an out of bounds write.

This issue shouldn't be reachable through any of the consumers of
the API, but to be sure some debug validation checks have been
added.

Bug: #6903.
1 year ago
Philippe Antoine e6895b835a detect/http-server-body: avoid FP on toserver direction
Ticket: 6948

http.response_body keyword did not enforce a direction, and thus
could match on files sent with POST requests
1 year ago
Victor Julien 08841f27ff ips: check for livedev.use-for-tracking
For the capture methods that support livedev and IPS,
livedev.use-for-tracking is not supported.

This setting causes major flow tracking issues, as both sides of
a flow would be tracked in different flows.

This patch disables the livedev.use-for-tracking setting if it
is set to true. A warning will be issued.

Ticket: #6726.
1 year ago
Victor Julien 2d625cd78e capture: block IDS + IPS combination
In general, improve IPS setup error checking.

Ticket: #5588.
1 year ago
Victor Julien 58bff9b855 capture: improve IDS + IPS check
Improve it for af-packet, dpdk, netmap. Check would not consider
an interface IDS if the `default` section contained a copy-mode
field.
1 year ago
Juliana Fajardini bb59124063 yaml: unify 0 stats counter config option terms
When we added feature #5976 (72146b969), we overlook that we also have
a config stats option for the human-readable stats logs to output
0 counters.
Due to not seeing this before, we now have two different setting names
for basically the same thing, but in different logs:
- zero-valued-counters for EVE
- null-values for stats.log

This ensures we use the same terminology, and change the recently added
one to `null-values`, as this one has been around for longer.

Task #6962
1 year ago
Philippe Antoine 2b4e10224e output/alert: check flag before logging app-layer
Ticket: 6846
1 year ago
Philippe Antoine 910f6af54f output: do not use tx id 0 when there is no tx
Ticket: 6846

This led to packet rules logging irrelevant app-layer data
1 year ago
Jeff Lucovsky d7026b7b11 detect/ipopts: Handle multiple ip options
Issue: 6864

Multiple IP options were not handled properly as the value being OR'd
into the packet's ip option variable were enum values instead of bit
values.
1 year ago
Jeff Lucovsky ee942391f7 detect/ipopts: Remove unneeded PCRE logic
Issue: 6864

Reduce complexity by eliminating the PCRE logic and adding a unittest to
validate null/empty string handling
1 year ago
Jeff Lucovsky c27dee7a9b detect/ipopt: Misc. cleanup
Minor changes to improve readability, remove extraneous include files.
1 year ago
Philippe Antoine 0291d37009 websocket: configurable logging of payload in alerts 1 year ago
Philippe Antoine 44b6aa5e4b app-layer: websockets protocol support
Ticket: 2695
1 year ago
Philippe Antoine 78b766048e protodetect: run expected probing parser
When there is a protocol change, and a specific protocol is
expected, like WebSeocket, always run it, no matter the port.
1 year ago
Philippe Antoine 155d671b26 protodetect: allows not port-based probing parsers
As for WebSocket which is detected only by protocol change.
1 year ago
Philippe Antoine 97d94b1067 protodetect: remove unused field
port is used in AppLayerProtoDetectProbingParserPort
and not in AppLayerProtoDetectProbingParserElement
1 year ago
Philippe Antoine 9075e58973 enip: register on default 44818/tcp port
if no config option is found,
as is done for udp

Ticket: 6304
1 year ago
Philippe Antoine 240e068b81 conf: avoid quadratic complexity
Ticket: 6878

Follow up on 15649424a7

When adding many sequence nodes, either from start or scalar event

We add "sequence nodes" whose name is an integer cf sequence_node_name
and then run ConfNodeLookupChild to see if it had been already set
(from the command line cf comment in the code)
And ConfNodeLookupChild iterates the whole linked list...

1. We add node 1
2. To add node 2, we check if node 1 equals this new node
3. To add node 3, we check if nodes 1, or 2 equals this new node's name
And so on...

This commits avoids these checks ig the list is empty at the beginning
1 year ago
Andreas Herz 1f9600e487 dataset: cleanup datasets that hit the memcap while loading
Datasets that hit the memcap limit need to be discarded if the memcap is
hit or otherwise the datasets are still loaded with partial data while
the signature is not loaded due to the memcap error.

Ticket: #6678
1 year ago
Victor Julien dc5b78ec71 decode/ppp: fix iplen check int handling
** CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
/src/decode-ppp.c: 64 in DecodePPPCompressedProto()
/src/decode-ppp.c: 55 in DecodePPPCompressedProto()

________________________________________________________________________________________________________
*** CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
/src/decode-ppp.c: 64 in DecodePPPCompressedProto()
58             case 0x57: { /* PPP_IPV6 */
59                 if (unlikely(len < (data_offset + IPV6_HEADER_LEN))) {
60                     ENGINE_SET_INVALID_EVENT(p, PPPIPV6_PKT_TOO_SMALL);
61                     return TM_ECODE_FAILED;
62                 }
63                 DEBUG_VALIDATE_BUG_ON(len < data_offset);
>>>     CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
>>>     "65535 /* 32767 * 2 + 1 */ < (uint16_t)(len - data_offset)" is always false regardless of the values of its operands. This occurs as the logical first operand of "?:".
64                 uint16_t iplen = MIN(USHRT_MAX, (uint16_t)(len - data_offset));
65                 return DecodeIPV6(tv, dtv, p, pkt + data_offset, iplen);
66             }
67             case 0x2f: /* PPP_VJ_UCOMP */
68                 if (unlikely(len < (data_offset + IPV4_HEADER_LEN))) {
69                     ENGINE_SET_INVALID_EVENT(p, PPPVJU_PKT_TOO_SMALL);
/src/decode-ppp.c: 55 in DecodePPPCompressedProto()
49             case 0x21: { /* PPP_IP */
50                 if (unlikely(len < (data_offset + IPV4_HEADER_LEN))) {
51                     ENGINE_SET_INVALID_EVENT(p, PPPVJU_PKT_TOO_SMALL);
52                     return TM_ECODE_FAILED;
53                 }
54                 DEBUG_VALIDATE_BUG_ON(len < data_offset);
>>>     CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
>>>     "65535 /* 32767 * 2 + 1 */ < (uint16_t)(len - data_offset)" is always false regardless of the values of its operands. This occurs as the logical first operand of "?:".
55                 uint16_t iplen = MIN(USHRT_MAX, (uint16_t)(len - data_offset));
56                 return DecodeIPV4(tv, dtv, p, pkt + data_offset, iplen);
57             }
58             case 0x57: { /* PPP_IPV6 */
59                 if (unlikely(len < (data_offset + IPV6_HEADER_LEN))) {
60                     ENGINE_SET_INVALID_EVENT(p, PPPIPV6_PKT_TOO_SMALL);
1 year ago
Juliana Fajardini 54ea6c5983 eve/alert: add missing pgsql metadata
Bug #6092
1 year ago
Sascha Steinbiss 120313f4da ja4: implement for TLS and QUIC
Ticket: OISF#6379
1 year ago
Sascha Steinbiss 9d0db71ebf ja3: make feature compile time configurable 1 year ago
Sascha Steinbiss 32f23b6d2f suricata: initialize feature tracking earlier
This gives app layer code a chance to access feature
information.
1 year ago
Jeff Lucovsky c305ed149c flow/inject: Select thread_id by flow flag
Issue: 6957

Rather than selecting the thread_id index by packets traveling to the
server, use the flow flags. If the flow has been reversed, the second
slot is represents the thread id to be used.
1 year ago
Victor Julien 516441b600 decode/ppp: add missing types definitions
Recognize PPP_CCP, PPP_CBCP and PPP_COMP_DGRAM.

Does not implement decoders for these record types, so these
are logged as unsupported types. Was "wrong_type" before.
1 year ago
Victor Julien 7e3f071e49 decode/ppp: clean up ppph pointer use
No users of the pointer anymore, so remove it.
1 year ago
Victor Julien 6067955afd decode/ppp: remove ppph check in favor of flag
As we now support variable size headers, we can't use the old pointer.

Replace with a flag.
1 year ago
Victor Julien 68092ff33c decode/ppp: support different header formats
Support compressed proto and optional HDLC header.

Bug: #6942.
1 year ago
Philippe Antoine bd3bed6c31 detect/analyzer: add more details for tcp_mss
Issue: #6355
1 year ago
Philippe Antoine 784ce30ae1 util: remove unused bloom filter code
Ticket: 4083
1 year ago
Philippe Antoine b113bdd9e3 src: remove unused headers-exported functions
+ remove double definition of IPPairLock

Ticket: #4083
1 year ago
Jeff Lucovsky 2dfa4cecb5 stats: Memcap pressure max relocation
This commit moves the memcap pressure/pressure_max stats from the global
stats namespace into the memcap namespace.

With per-thread stats, they will be within the flow-manager's values.

Issue: 6398
1 year ago
Philippe Antoine 3643b6ed4b output: generic simple tx json logger
Ticket: 3827
1 year ago
Philippe Antoine 688efe79f0 output/dns: do not add empty app-layer metadata 1 year ago
Philippe Antoine 74aa80022c output/dnp3: restrict function scope to one file 1 year ago
Victor Julien 76322368ed pcap: support LINKTYPE_IPV6 (229)
This is just another variant of DLT_RAW.

Ticket: #6943.
1 year ago
Victor Julien 49c67b2bb1 defrag: fix wrong datalink being logged
Eve's packet_info.linktype should correctly indicated what the `packet`
field contains. Until now it was using DLT_RAW even if Ethernet or other
L2+ headers were present.

This commit records the datalink of the packet creating the first
fragment, which can include the L2+ header data.

Bug: #6887.
1 year ago
Juliana Fajardini 72146b969c eve/stats: allow hiding counters whose valued is 0
Some stats can be quite verbose if logging all zero valued-counters.
This allows users to disable logging such counters. Default is still
true, as that's the expected behavior for the engine.

Task #5976
1 year ago
Lukas Sismis 10590e6d94 dpdk: support 52 byte long key on ice (E810) cards 1 year ago
Lukas Sismis d4085fceb6 dpdk: enlarge key length to 52 bytes 1 year ago
Victor Julien 172775ed84 alert/syslog: fetch ipproto once 1 year ago
Victor Julien 7ad1a6b21b alert/syslog: stringify addresses outside alert loop 1 year ago
Victor Julien 291250f705 alert/syslog: minor code cleanups 1 year ago
Victor Julien 285fda5de8 alert/syslog: only hold lock for syslog call 1 year ago
Juliana Fajardini 172b55c547 log/stats: allow longer counter names
With the addition of exception policy stats counters, the human readable
version of the sats log was mis-aligned, when counters for per-app-proto
were enabled.

Width change made large enough to accomodate a counter as long as
"app_layer.error.bittorrent-dht.exception_policy.pass_packet" which
could be valid.

Task #5816
1 year ago
Juliana Fajardini caf590d51f stream/midstream: add counter for exception policy
Add stats counters for when there is an exception policy applied in case
of a session picked up midstream.

Task #5816
1 year ago
Juliana Fajardini fd9a20ffcf stream/reassemble: add exception policy counters
Add stats counters for exception policies applied in case of memcap hit
during stream reassembly.

Task #5816
1 year ago
Juliana Fajardini 2dee3772bf stream/tcp: add ssnmemcap exception policy counter
Add stats counters for exception policies applied in case a stream
session memcap is hit.

Task #5816
1 year ago
Juliana Fajardini a71ace8575 applayer: add stats counters for exception errors
Add stats counters for exception policy are applied for app-layer errors

Part of
Task #5816
1 year ago
Juliana Fajardini 485c0e1d9a defrag: add exception policy memcap stats counters
Add defrag memcap stats counter.

Task #5816
1 year ago
Juliana Fajardini 657419b53e decode/flow: add exception policy stats counters
We will register stats counters for all policies, even though for now
Suri only uses one possible configuration policy at a time. The idea is
that this could change in the near future, so we want to have this
ready.

Task #5816
1 year ago
Juliana Fajardini c2c8cdb78a exceptions: make types and ToStr fns more accessible
Decode file needed ExceptionPolicy types and exception-policy file
needed Decode types, rendering some works quite difficult to work
around.

ExceptionPolicyToStr is useful for registering exception policy
counters, so make that public.

Part of
Task #5816
1 year ago
Juliana Fajardini 112f5cc0ad app-layer/htp: clean up unused code in unittests
Remove unit test that was disabled and printf statements that were
replaced but not deleted, both in 48cf0585fb.
1 year ago
Juliana Fajardini cea917c38c app-layer: fix minor typo and formatting in LogInfo
Also update copyright years.
1 year ago
Daniel Olatunji d9148d1023 detect/analyzer: add more details for tcp_seq
Log the matched Sequence number of a packet
Issue: 6353
1 year ago
Lukas Sismis 28ac3c2097 dpdk: fix thread slot assignment
Commit 5592ec07 introduced a bug where ptv->slot was
assigned with the current one instead of the next one
in the list. This caused a Suricata crash in the DPDK mode.

Ticket: 6877
1 year ago
Lukas Sismis 3fdcf7fbe4 dpdk: make static variables thread_local
Per a newly obtained knowledge, static variables in functions
are not thread-safe and as a result thread_local attribute was
added.
1 year ago
jason taylor ebd5cd61c2 detect: minor http.cookie keyword typo fix
Signed-off-by: jason taylor <jtfas90@gmail.com>
1 year ago
Victor Julien 34f53f85bc systemd: reimplement sd_notify logic using UNIX socket
One of the lessons of the XZ backdoor story was that just linking to
libsystemd to call sd_notify is discouraged by the systemd project:

Lennart Poettering:
"PSA: In context of the xzpocalypse we now added an example reimplementation
of sd_notify() to our man page:

https://www.freedesktop.org/software/systemd/man/devel/sd_notify.html#Notes

It's pretty comprehensive (i.e. uses it for reload notification too), but
still relatively short.

In the past, I have been telling anyone who wanted to listen that if all you
want is sd_notify() then don't bother linking to libsystemd, since the
protocol is stable and should be considered the API, not our C wrapper
around it. After all, the protocol is so trivial"

From: https://mastodon.social/@pid_eins/112202687764571433

This commit takes the example code and uses it to reimplement the notify
logic.

The code is enabled if Linux is detected in configure. Since the code
won't do anything if the NOTIFY_SOCKET env var isn't set, this should
also work fine on systems w/o systemd.

Ticket: #6913.
1 year ago
Daniel Olatunji 6d40517502 detect/analyzer: add more details for the tcp ack keyword
Issue: 6354
Added the DETECT_ACK case to detect-engine-analyzer.c
1 year ago
Victor Julien 561b81dd9e decode: don't clear computed csums twice
Already done in a generic way by PACKET_RESET_CHECKSUMS.
1 year ago
Victor Julien 40afbf5b09 decode/ipv4: remove unused field 1 year ago
Victor Julien 3077310ff1 output/eve: constify mac address logic 1 year ago
Victor Julien 1213936978 macset: constify addr parameters 1 year ago
Victor Julien 2236c1fcc6 decode/udp: no need to pack the structure 1 year ago
Victor Julien 7c90144d19 decode/tcp: no need to pack the structure 1 year ago
Victor Julien a1a9b41a71 decode/icmpv4: no need to pack the structure 1 year ago
Victor Julien e557ba0460 unittests: don't set ports for non-port proto 1 year ago
Victor Julien e651cf922a detect/http: fix compile warning in body tests
When --enable-unittests w/o --enable-debug is used.
1 year ago
Victor Julien f6c24aab57 detect/ipproto: clean up test 1 year ago
Victor Julien 4e1ae1c3bf detect/fragbits: remove unused IP header struct from tests 1 year ago
Victor Julien d3a429d919 defrag: test cleanups and fixes
Pass tv and dtv to make sure reassembled packet is decoded.
1 year ago
Victor Julien 7728047888 decode/icmpv6: minor test cleanup 1 year ago
Victor Julien 3d4626f656 detect/dsize: remove unused ip6h from test 1 year ago
Victor Julien b224209f45 host-info: remove pcre2_substring_list_free use
Function prototype has changed in a recent release. Rather than dealing
with detecting that, fall back to our regular pattern of using
pcre2_substring_copy_bynumber().

Bug: #6918.
1 year ago
Shivani Bhardwaj 4227e52c4b detect/port: handle range and upper boundary ports
So far, if a port was found to be single which was earlier a part of the
range, port + 1 was added to the list to honor the range that it was a
part of. But, this is incorrect in case the port is 65535 or if the port
was found to be of range when it was earlier a single port.

Bug 6896
1 year ago
Jason Ish f104e9cecc suricata: expose and break out configuration loading
Expose LoadYamlConfig as SCLoadYamlConfig and remove it from
SuricataInit. This is required to allow the library user the ability
customize the loading of the configuration, for example doing some
programmatic configuration then loading a configuration file.
1 year ago
Jason Ish e38ec7d0a7 smtp: fix configuration node creation
A configuration sequence node needs to have name, which is just its
index in the sequence.

Discovered by calling ConfDump() after Suricata was fully initialized.
1 year ago
Jason Ish 2c71c7fe6a suricata: move SuricataMain into main()
Move the contents of SuricataMain into the `main()` function found in
main.c. This forces the Suricata application to bootstrap and run
Suricata through the same interfaces as a library user might do.

Required exposing StartInternalRunMode as SCStartInternalRunmode. Its
arguable whether those "actions" belong in the library or just the
application, but I think that is separation we can look at later.

For now the lib example and Suricata's own main are the same, however
the example will probably extend more into programmatically
configuring Suricata or dynamically registering a runmode, which
doesn't really belong the main Suricata application.
1 year ago
Jason Ish c476fcc85b suricata: expose FinalizeRunMode and ParseCommandLine
Expose the functions FinalizeRunMode and ParseCommandLine to library
users, renaming with the `SC` prefix in the process.

This involves moving "application" level details from SuricataInit
into SuricataMain, as parsing command line options should be opt-in
for a library user.
1 year ago
Jason Ish e18779c1b4 windows: remove argc, argv from SCServiceRemove
Not used.
1 year ago
Jason Ish 8dc5478d0a suricata: remove argv from FinalizeRunMode
FinalizeRunMode can get the program name from suri->progname.
1 year ago
Jason Ish 04bd026c5b suricata: remove instance from ParseCommandLine
We want to be able to call ParseCommandLine from library users, but
currently library users don't have access to the `suricata` instance
type. Since this var is used other places as a global, use the global
one in ParseCommandLine as well.

Not ideal, but isolating SCInstance to a non-global will be another
challenge on its own.
1 year ago
Jason Ish db44740fd8 suricata: move WindowsInitService to SuricataMain
Move WindowsInitService from SuricataInit() to SuricataMain(), as
initializing Suricata as a service is very specific to the application
and not something you'd want to happen in a library, and SuricataInit
is more common initialization for application and library usage.
1 year ago
Jason Ish cfd98e92a0 suricata: expose SuricataMainLoop and GlobalsDestroy
Expose SuricataMainLoop and GlobalsDestroy so that SuricataMain can be
replicated by a library user of Suricata.

These removes the `suricata` instance as a function argument to some
of these functions, as the way we use it now, it serves no
purpose. However, it is a reminder that it should probably be
refactored to not be a global, as at some point it might be desirable
for to have multiple instances active without data sharing.
1 year ago
Angelo Mirabella 67d23c7b61 libsuricata: reorganize SuricataMain code
Split SuricataMain code in smaller functions. This is a first step
towards running as a library.
1 year ago
Shivani Bhardwaj 7d937db5cb detect/port: fix grouping of ports w gaps
If a single port happens before a range port, the port groups created
were incorrect. Fix it to use smarter range check.

For example, given,
80:80 - SGH1
100:120 - SGH2

Range created should be
80:80 - SGH1
100:120 - SGH2

Bug 6881
1 year ago
Victor Julien 0be3ba802e eve/alert: fix validation check
Bug: #6875.
1 year ago
Jeff Lucovsky bf5cfd6ab7 profiling/rules: Improve dynamic rule handling
Issue: 6861

Without this commit, disabling rule profiling via suricatasc's command
'ruleset-profile-stop' may crash because profiling_rules_entered becomes
negative.

This can happen because
- There can be multiple rules evaluated for a single packet
- Each rule is profiled individually.
- Starting profiling is gated by a configuration setting and rule
  profiling being active
- Ending profiling is gated by the same configuration setting and
  whether the packet was marked as profiling.

The crash can occur when a rule is being profiled and rule profiling
is then disabled after one at least one rule was profiled for the packet
(which marks the packet as being profiled).

In this scenario, the value of profiling_rules_entered was
not incremented so the BUG_ON in the end profiling macro trips
because it is 0.

The changes to fix the problem are:
- In the profiling end macro, gate the actions taken there by the same
  configuration setting and use the profiling_rues_entered (instead of
  the per-packet profiling flag). Since the start and end macros are
  tightly coupled, this will permit profiling to "finish" if started.
- Modify SCProfileRuleStart to only check the sampling values if the
  packet hasn't been marked for profiling already. This change makes all
  rules for a packet (once selected) to be profiled (without this change
  sampling is applied to each *rule* that applies to the packet.
1 year ago
Philippe Antoine cc3b4b01ec detect: flush when setting no_inspection
Ticket: 6578

When a protocol such as SSH sets no_inspection, we still have to
flush the current streams and packets that contain clear-text
for detection.
1 year ago
Philippe Antoine 4c4f7ff1a2 detect: update packet action on protocol change
Ticket: #6305

When running FlowWorkerStreamTCPUpdate, one of the dequeued packet
may set the flow action to drop, without updating the not-pseudo
packet action, as is done usually with a previous call to
FlowHandlePacketUpdate
1 year ago
Victor Julien ff8597d50b membuffer: annotate printf style function 1 year ago
Victor Julien 926c6e3add eve/alert: break out of payload logging callback if buffer is full 1 year ago
Victor Julien 1dea4fea0b eve/frame: break out of logging callback if buffer is full 1 year ago
Victor Julien 7d5b537f5c membuffer: return bytes written 1 year ago
Victor Julien 9c3669b03f membuffer: use buffer pointer as flexible array member 1 year ago
Victor Julien 3ef98f2b87 membuffer: turn complex macros into functions
For better readability and type checking.
1 year ago
Victor Julien ea98df8da2 unix-manager: add \n string to buffer using correct API call 1 year ago
Victor Julien 6e10c66078 eve/frame: improve frame payload logging
Log using stream callback API, meaning that data will also
be logged if there are GAPs.

Also implement GAP indicators: '[123 bytes missing]'.
1 year ago
Victor Julien a205583269 eve/frames: pass membuffer to API
In preparation of stream logging changes.
1 year ago
Victor Julien 462a6d7913 eve/alert: init membuffer size on missing config
Don't init buffer to 0 size but use the desired default of 4k.
1 year ago