suricata
detect-krb5-ticket-encryption.c
Go to the documentation of this file.
1 /* Copyright (C) 2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #include "suricata-common.h"
19 #include "rust.h"
20 
22 
23 #include "detect-engine.h"
24 #include "detect-parse.h"
25 
26 static int g_krb5_ticket_encryption_list_id = 0;
27 
28 static void DetectKrb5TicketEncryptionFree(DetectEngineCtx *de_ctx, void *ptr)
29 {
30  rs_krb5_detect_encryption_free(ptr);
31 }
32 
33 static int DetectKrb5TicketEncryptionMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags,
34  void *state, void *txv, const Signature *s, const SigMatchCtx *ctx)
35 {
36  const DetectKrb5TicketEncryptionData *dd = (const DetectKrb5TicketEncryptionData *)ctx;
37 
38  SCEnter();
39 
40  SCReturnInt(rs_krb5_detect_encryption_match(txv, dd));
41 }
42 
43 static int DetectKrb5TicketEncryptionSetup(
44  DetectEngineCtx *de_ctx, Signature *s, const char *krb5str)
45 {
46  DetectKrb5TicketEncryptionData *krb5d = NULL;
47  SigMatch *sm = NULL;
48 
50  return -1;
51 
52  krb5d = rs_krb5_detect_encryption_parse(krb5str);
53  if (krb5d == NULL)
54  goto error;
55 
56  sm = SigMatchAlloc();
57  if (sm == NULL)
58  goto error;
59 
61  sm->ctx = (void *)krb5d;
62 
63  SigMatchAppendSMToList(s, sm, g_krb5_ticket_encryption_list_id);
64 
65  return 0;
66 
67 error:
68  if (krb5d != NULL)
69  DetectKrb5TicketEncryptionFree(de_ctx, krb5d);
70  if (sm != NULL)
71  SCFree(sm);
72  return -1;
73 }
74 
76 {
77  sigmatch_table[DETECT_AL_KRB5_TICKET_ENCRYPTION].name = "krb5.ticket_encryption";
78  sigmatch_table[DETECT_AL_KRB5_TICKET_ENCRYPTION].desc = "match Kerberos 5 ticket encryption";
80  "/rules/kerberos-keywords.html#krb5-ticket-encryption";
83  DetectKrb5TicketEncryptionMatch;
84  sigmatch_table[DETECT_AL_KRB5_TICKET_ENCRYPTION].Setup = DetectKrb5TicketEncryptionSetup;
85  sigmatch_table[DETECT_AL_KRB5_TICKET_ENCRYPTION].Free = DetectKrb5TicketEncryptionFree;
86 
87  // Tickets are only from server to client
90 
91  g_krb5_ticket_encryption_list_id = DetectBufferTypeRegister("krb5_ticket_encryption");
92  SCLogDebug("g_krb5_ticket_encryption_list_id %d", g_krb5_ticket_encryption_list_id);
93 }
SigTableElmt_::url
const char * url
Definition: detect.h:1241
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1498
detect-engine.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1240
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1228
SigTableElmt_::name
const char * name
Definition: detect.h:1238
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
Flow_
Flow data structure.
Definition: flow.h:357
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:785
Krb5PrincipalNameDataArgs::txv
void * txv
Definition: detect-krb5-cname.c:44
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1209
rust.h
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:229
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1223
ALPROTO_KRB5
@ ALPROTO_KRB5
Definition: app-layer-protos.h:50
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1025
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:316
DetectAppLayerInspectEngineRegister2
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
Definition: detect-engine.c:224
DETECT_AL_KRB5_TICKET_ENCRYPTION
@ DETECT_AL_KRB5_TICKET_ENCRYPTION
Definition: detect-engine-register.h:257
detect-krb5-ticket-encryption.h
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1206
DetectKrb5TicketEncryptionRegister
void DetectKrb5TicketEncryptionRegister(void)
Definition: detect-krb5-ticket-encryption.c:75
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:239
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:308
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition: detect-engine.c:1025
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
SigMatch_::type
uint16_t type
Definition: detect.h:314
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:76
DetectEngineInspectGenericList
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1948
SCFree
#define SCFree(p)
Definition: util-mem.h:61
detect-parse.h
Signature_
Signature container.
Definition: detect.h:540
SigMatch_
a single match condition for a signature
Definition: detect.h:313
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:354