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

dns: add dns.rcode keyword v3 #10126

Closed

Conversation

hadiqaalamdar
Copy link
Contributor

@hadiqaalamdar hadiqaalamdar commented Jan 5, 2024

Feature #6621

Link to redmine ticket: https://redmine.openinfosecfoundation.org/issues/6621

Previous PR: #10097

Describe changes:

  • made the suggested changes from previous PR
  • successfully ran the following tests:
  • from rust dir: make check
  • from rust dir: cargo test
  • from rust dir: cargo clippy --all-features
  • from rust dir: rustfmt src/dns/*
  • from suricata dir: ./scripts/clang-format.sh check-branch
  • from suricata dir: ./scripts/clang-format.sh branch
  • from suricata dir running ./src/suricata -u showed that one unit test had failed.
  • from suricata dir running ./src/suricata -u -U dns showed 7 tests passed.
  • Running sv tests gave the following error on console (will add more details for sv test in the SV Branch):
Finished release [optimized] target(s) in 0.16s
===> dns-rcode: Sub test #1: FAIL : expected 1 matches; got 0 for filter {'count': 1, 'match': {'alert.signature_id': 1, 'direction': 'to_client', 'app_proto': 'dns', 'dns.rcode': 3}}
===> dns-rcode: Sub test #2: FAIL : expected 1 matches; got 0 for filter {'count': 1, 'match': {'alert.signature_id': 1, 'direction': 'to_server', 'app_proto': 'dns', 'dns.rcode': 3}}
===> dns-rcode: Sub test #3: FAIL : expected 1 matches; got 0 for filter {'count': 1, 'match': {'alert.signature_id': 2, 'direction': 'to_server', 'app_proto': 'dns', 'dns.rcode': 3}}
===> dns-rcode: Sub test #4: FAIL : expected 1 matches; got 0 for filter {'count': 1, 'match': {'alert.signature_id': 3, 'direction': 'to_client', 'app_proto': 'dns', 'dns.rcode': 3}}
===> dns-rcode: Sub test #5: FAIL : expected 1 matches; got 0 for filter {'count': 1, 'match': {'alert.signature_id': 4, 'direction': 'to_client', 'app_proto': 'dns', 'dns.rcode': 3, 'dns.negate': True}}
/Users/hadiqa/suricata-verify/tests/dns/dns-rcode/output/eve.json - INVALID. Errors:
1./dns/answer Additional properties are not allowed ('authorities' was unexpected)
/Users/hadiqa/suricata-verify/tests/dns/dns-rcode/output/eve.json - INVALID. Errors:
1./dns/answer Additional properties are not allowed ('authorities' was unexpected)
===> dns-rcode: FAILED: Invalid JSON schema

PASSED:  0
FAILED:  1
SKIPPED: 0

SV_BRANCH=OISF/suricata-verify#1574

Copy link

codecov bot commented Jan 5, 2024

Codecov Report

Attention: 47 lines in your changes are missing coverage. Please review.

Comparison is base (f12e026) 82.22% compared to head (943e976) 82.16%.
Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10126      +/-   ##
==========================================
- Coverage   82.22%   82.16%   -0.07%     
==========================================
  Files         974      975       +1     
  Lines      271925   272069     +144     
==========================================
- Hits       223595   223539      -56     
- Misses      48330    48530     +200     
Flag Coverage Δ
fuzzcorpus 62.94% <17.50%> (-0.07%) ⬇️
suricata-verify 61.40% <17.50%> (-0.03%) ⬇️
unittests 62.85% <67.36%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


if (SigMatchAppendSMToList(
de_ctx, s, DETECT_AL_DNS_RCODE, (SigMatchCtx *)detect, dns_rcode_list_id) == NULL) {
goto error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: since we have only one error path after detect was allocated, we can call DetectDnsRcodeFree and return here, instead of using a goto.

SCEnter();

if (DetectSignatureSetAppProto(s, ALPROTO_DNS) != 0) {
return -1;
Copy link
Member

Choose a reason for hiding this comment

The 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

@catenacyber
Copy link
Contributor

Looks like SV PR was not used by CI

@catenacyber
Copy link
Contributor

@jasonish the SV test shows that we need https://redmine.openinfosecfoundation.org/issues/6281 to be fixed ;-)

@@ -26,6 +26,12 @@ pub struct DetectDnsOpcode {
opcode: u8,
}

#[derive(Debug, PartialEq, Eq)]
pub struct DetectDnsRcode {
Copy link
Contributor

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)

Copy link
Contributor Author

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 to DetectUintData<u8> in the next PR I create.

sigmatch_table[DETECT_AL_DNS_RCODE].Match = NULL;
sigmatch_table[DETECT_AL_DNS_RCODE].AppLayerTxMatch = DetectDnsRcodeMatch;

DetectAppLayerInspectEngineRegister(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove this line with SIG_FLAG_TOSERVER because dns.rcode is only to client

Copy link
Contributor Author

@hadiqaalamdar hadiqaalamdar Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do, thanks!

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, the rcode field is also there in the to server direction

Wireshark does not show it :-/

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.resp.ext_rcode == 0x00 Wireshark filter

@jasonish
Copy link
Member

jasonish commented Jan 9, 2024

@jasonish the SV test shows that we need https://redmine.openinfosecfoundation.org/issues/6281 to be fixed ;-)

I don't think so. We should update the schema definition to match the real schema. Changing the output is a different task with possible breaking changes. Something simple like this should get us by for the scope of this PR?

diff --git a/etc/schema.json b/etc/schema.json
index 0756acd008..f6321a1179 100644
--- a/etc/schema.json
+++ b/etc/schema.json
@@ -1156,7 +1156,10 @@
                         "opcode": {
                             "description": "DNS opcode as an integer",
                             "type": "integer"
-                        }
+                        },
+                       "authorities": {
+                           "type": "array"
+                       }
                     },
                     "additionalProperties": false
                 },

Copy link
Member

@jasonish jasonish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, some changes requested, however it seems to function well, at least on the rules I wrote up to test it. However, the S-V tests need to be fixed up to match what is expected, I've left some comments over there as well.

@hadiqaalamdar
Copy link
Contributor Author

New PR: #10150

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants