Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pcap conditional v2.2.6 #6389

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
be12250
log/pcap: conditional logging
regit Nov 1, 2020
c621145
log/pcap: add PcapWrite function
regit Nov 8, 2020
155dd02
detect: add flag when packet is first with alert
regit Nov 8, 2020
16ec6aa
stream: conditionally add packet header to segment
regit Jan 30, 2021
6a97a23
log/pcap: add existing stream logging
regit Feb 6, 2021
41631df
log/pcap: add support for tunnel logging
regit Feb 6, 2021
8077777
log/pcap: fix some indentation and white spaces
regit Feb 6, 2021
9a37607
log/pcap: introduce tag as logging condition
regit Feb 6, 2021
09b1812
doc: add conditional pcap logging info
regit Feb 6, 2021
3aa92e3
log/pcap: update copyright date
regit Feb 7, 2021
af394d5
stream: count realloc in memcap
regit Feb 8, 2021
dc63c19
log/pcap: fix typo in error message
regit Feb 13, 2021
8ab18f9
log/pcap: add function to get thread pcap file
regit Feb 13, 2021
1e84d39
eve/alert: log pcap output filename
regit Feb 13, 2021
a522e9e
doc: add info about capture_file key
regit Feb 14, 2021
ef205ee
log/pcap: dump segments of both sides of tcp session.
scottfgjordan Feb 17, 2021
42c6174
detect/tag: add a tag for first packet
regit Feb 25, 2021
466505e
log/pcap: fix conditional pcap in tag mode
regit Feb 25, 2021
d8e4980
log/pcap: log segments for pseudo packets
regit Mar 10, 2021
9a09c93
suricata: introduce global linktype
regit Mar 11, 2021
17a931b
flow: set datalink for pseudo packet
regit Mar 11, 2021
bd36ed1
log/pcap: handle case of multiple link types
regit Mar 12, 2021
44b7040
decode: fix typo from rebase
scottfgjordan Sep 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/userguide/configuration/suricata-yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,16 @@ By default all packets are logged except:
- TCP streams beyond stream.reassembly.depth
- encrypted streams after the key exchange

It is possible to do conditional pcap logging by using the `conditional`
option in the pcap-log section. By default the variable is set to `all`
so all packet are logged. If the variable is set to `alerts` then only
the flow with alerts will be logged. If the variable is set to `tag`
then only packets tagged by signature using the `tag` keyword will
be logged to the pcap file. Please note that if `alerts` or `tag` is
used, then in the case of TCP session, Suricata will use available
information from the streaming engine to log data that have triggered
the alert.

::

- pcap-log:
Expand All @@ -414,6 +424,7 @@ By default all packets are logged except:

mode: sguil # "normal" (default) or sguil.
sguil_base_dir: /nsm_data/
conditional: alerts

Verbose Alerts Log (alert-debug.log)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 7 additions & 0 deletions doc/userguide/output/eve/eve-json-format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ the signature.
}
},

Pcap Field
~~~~~~~~~~

If pcap log capture is active in `multi` mode, a `capture_file` key will be added to the event
with value being the full path of the pcap file where the corresponding packets
have been extracted.

Event type: Anomaly
-------------------

Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ noinst_HEADERS = \
util-cpu.h \
util-crypt.h \
util-daemon.h \
util-datalink.h \
util-debug-filters.h \
util-debug.h \
util-decode-mime.h \
Expand Down Expand Up @@ -1058,6 +1059,7 @@ libsuricata_c_a_SOURCES = \
util-cpu.c \
util-crypt.c \
util-daemon.c \
util-datalink.c \
util-debug.c \
util-debug-filters.c \
util-decode-mime.c \
Expand Down
9 changes: 5 additions & 4 deletions src/alert-debuglog.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ static void AlertDebugLogPktVars(AlertDebugLogThread *aft, const Packet *p)

/** \todo doc
* assume we have aft lock */
static int AlertDebugPrintStreamSegmentCallback(const Packet *p, void *data, const uint8_t *buf, uint32_t buflen)
static int AlertDebugPrintStreamSegmentCallback(
const Packet *p, TcpSegment *seg, void *data, const uint8_t *buf, uint32_t buflen)
{
AlertDebugLogThread *aft = (AlertDebugLogThread *)data;

Expand Down Expand Up @@ -291,9 +292,9 @@ static TmEcode AlertDebugLogger(ThreadVars *tv, const Packet *p, void *thread_da
/* IDS mode reverse the data */
/** \todo improve the order selection policy */
if (p->flowflags & FLOW_PKT_TOSERVER) {
flag = FLOW_PKT_TOCLIENT;
flag = STREAM_DUMP_TOCLIENT;
} else {
flag = FLOW_PKT_TOSERVER;
flag = STREAM_DUMP_TOSERVER;
}
ret = StreamSegmentForEach((const Packet *)p, flag,
AlertDebugPrintStreamSegmentCallback,
Expand Down Expand Up @@ -466,7 +467,7 @@ static OutputInitResult AlertDebugLogInitCtx(ConfNode *conf)
return result;
}

static int AlertDebugLogCondition(ThreadVars *tv, const Packet *p)
static int AlertDebugLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
{
return (p->alerts.cnt ? TRUE : FALSE);
}
Expand Down
4 changes: 2 additions & 2 deletions src/alert-fastlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ TmEcode AlertFastLogThreadDeinit(ThreadVars *, void *);
void AlertFastLogRegisterTests(void);
static void AlertFastLogDeInitCtx(OutputCtx *);

int AlertFastLogCondition(ThreadVars *tv, const Packet *p);
int AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p);
int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p);

void AlertFastLogRegister(void)
Expand All @@ -85,7 +85,7 @@ typedef struct AlertFastLogThread_ {
LogFileCtx* file_ctx;
} AlertFastLogThread;

int AlertFastLogCondition(ThreadVars *tv, const Packet *p)
int AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
{
return (p->alerts.cnt ? TRUE : FALSE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/alert-syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static TmEcode AlertSyslogDecoderEvent(ThreadVars *tv, const Packet *p, void *da
return TM_ECODE_OK;
}

static int AlertSyslogCondition(ThreadVars *tv, const Packet *p)
static int AlertSyslogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
{
return (p->alerts.cnt > 0 ? TRUE : FALSE);
}
Expand Down
4 changes: 4 additions & 0 deletions src/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,10 @@ void DecodeUnregisterCounters(void);
* so flag it for not setting stream events */
#define PKT_STREAM_NO_EVENTS BIT_U32(28)

/** We had no alert on flow before this packet */
#define PKT_FIRST_ALERTS BIT_U32(29)
#define PKT_FIRST_TAG BIT_U32(30)

/** \brief return 1 if the packet is a pseudo packet */
#define PKT_IS_PSEUDOPKT(p) \
((p)->flags & (PKT_PSEUDO_STREAM_END|PKT_PSEUDO_DETECTLOG_FLUSH))
Expand Down
5 changes: 4 additions & 1 deletion src/detect-engine-alert.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ void PacketAlertFinalize(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx

/* Set flag on flow to indicate that it has alerts */
if (p->flow != NULL && p->alerts.cnt > 0) {
FlowSetHasAlertsFlag(p->flow);
if (!FlowHasAlerts(p->flow)) {
FlowSetHasAlertsFlag(p->flow);
p->flags |= PKT_FIRST_ALERTS;
}
}

}
Expand Down
1 change: 1 addition & 0 deletions src/detect-engine-tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ static void TagHandlePacketFlow(Flow *f, Packet *p)
* to log it (the alert will log it) */
if (!(iter->flags & TAG_ENTRY_FLAG_SKIPPED_FIRST)) {
iter->flags |= TAG_ENTRY_FLAG_SKIPPED_FIRST;
p->flags |= PKT_FIRST_TAG;
} else {
/* Update metrics; remove if tag expired; and set alerts */
switch (iter->metric) {
Expand Down
3 changes: 2 additions & 1 deletion src/flow-timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#include "util-debug.h"
#include "util-privs.h"
#include "util-datalink.h"

#include "detect.h"
#include "detect-engine-state.h"
Expand Down Expand Up @@ -82,7 +83,7 @@ static inline Packet *FlowForceReassemblyPseudoPacketSetup(Packet *p,
{
const int orig_dir = direction;
p->tenant_id = f->tenant_id;
p->datalink = DLT_RAW;
p->datalink = DatalinkGetGlobalType();
p->proto = IPPROTO_TCP;
FlowReference(&p->flow, f);
p->flags |= PKT_STREAM_EST;
Expand Down
Loading