-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
dns: add dns.rcode keyword v3 #10126
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* Copyright (C) 2024 Open Information Security Foundation | ||
* | ||
* You can copy, redistribute or modify this Program under the terms of | ||
* the GNU General Public License version 2 as published by the Free | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
#include "suricata-common.h" | ||
|
||
#include "detect-parse.h" | ||
#include "detect-engine.h" | ||
#include "detect-dns-rcode.h" | ||
#include "rust.h" | ||
|
||
static int dns_rcode_list_id = 0; | ||
|
||
static void DetectDnsRcodeFree(DetectEngineCtx *, void *ptr); | ||
|
||
static int DetectDnsRcodeSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str) | ||
{ | ||
SCEnter(); | ||
|
||
if (DetectSignatureSetAppProto(s, ALPROTO_DNS) != 0) { | ||
return -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: SCReturnInt(-1); currently use of the macro is inconsistent in this function |
||
} | ||
|
||
void *detect = rs_detect_dns_rcode_parse(str); | ||
if (detect == NULL) { | ||
SCLogError("failed to parse dns.rcode: %s", str); | ||
return -1; | ||
} | ||
|
||
if (SigMatchAppendSMToList( | ||
de_ctx, s, DETECT_AL_DNS_RCODE, (SigMatchCtx *)detect, dns_rcode_list_id) == NULL) { | ||
goto error; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: since we have only one error path after |
||
} | ||
|
||
SCReturnInt(0); | ||
|
||
error: | ||
DetectDnsRcodeFree(de_ctx, detect); | ||
SCReturnInt(-1); | ||
} | ||
|
||
static void DetectDnsRcodeFree(DetectEngineCtx *de_ctx, void *ptr) | ||
{ | ||
SCEnter(); | ||
if (ptr != NULL) { | ||
rs_dns_detect_rcode_free(ptr); | ||
} | ||
SCReturn; | ||
} | ||
|
||
static int DetectDnsRcodeMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags, void *state, | ||
void *txv, const Signature *s, const SigMatchCtx *ctx) | ||
{ | ||
return rs_dns_rcode_match(txv, (void *)ctx, flags); | ||
} | ||
|
||
void DetectDnsRcodeRegister(void) | ||
{ | ||
sigmatch_table[DETECT_AL_DNS_RCODE].name = "dns.rcode"; | ||
sigmatch_table[DETECT_AL_DNS_RCODE].desc = "Match the DNS header rcode flag."; | ||
sigmatch_table[DETECT_AL_DNS_RCODE].url = "/rules/dns-keywords.html#dns-rcode"; | ||
sigmatch_table[DETECT_AL_DNS_RCODE].Setup = DetectDnsRcodeSetup; | ||
sigmatch_table[DETECT_AL_DNS_RCODE].Free = DetectDnsRcodeFree; | ||
sigmatch_table[DETECT_AL_DNS_RCODE].Match = NULL; | ||
sigmatch_table[DETECT_AL_DNS_RCODE].AppLayerTxMatch = DetectDnsRcodeMatch; | ||
|
||
DetectAppLayerInspectEngineRegister( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should remove this line with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd keep it. While answers should only be seen in the to client direction as well, we do allow detection on them in the to server direction as they are allowed by the message format. Likewise, the rcode field is also there in the to server direction, and at some point may be of interest to detect on in that direction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Wireshark does not show it :-/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in the break down, no, but the bits are still there. I agree its somewhat non-sensical, but Suricata is here to find the non-sensical. Note: The major DNS servers don't seem to care if an rcode is set on a request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. By the way, the pcap in SV test seems to have an extended rcode cf |
||
"dns.rcode", ALPROTO_DNS, SIG_FLAG_TOSERVER, 0, DetectEngineInspectGenericList, NULL); | ||
|
||
DetectAppLayerInspectEngineRegister( | ||
"dns.rcode", ALPROTO_DNS, SIG_FLAG_TOCLIENT, 0, DetectEngineInspectGenericList, NULL); | ||
|
||
dns_rcode_list_id = DetectBufferTypeGetByName("dns.rcode"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Copyright (C) 2024 Open Information Security Foundation | ||
* | ||
* You can copy, redistribute or modify this Program under the terms of | ||
* the GNU General Public License version 2 as published by the Free | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef __DETECT_DNS_RCODE_H__ | ||
#define __DETECT_DNS_RCODE_H__ | ||
|
||
void DetectDnsRcodeRegister(void); | ||
|
||
#endif /* __DETECT_DNS_RCODE_H__ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should reuse
DetectUintData<u8>
cf #10087 (comment)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was suggested here #10087 (comment) that I can use simple
u8
till the code is in working condition. I can change it toDetectUintData<u8>
in the next PR I create.