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

protodetect: improve DCERPC UDP probing parser and simplify app-layer-detect-proto.c code v3 #11679

Closed
wants to merge 2 commits into from

Conversation

ilya-bakhtin
Copy link
Contributor

Make sure these boxes are signed before submitting your Pull Request -- thank you.

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

Describe changes:
This is a replacement of #11644
There are 2 commits.
The first one is intended to improve DCERPC UDP detection. False positives resulted in improper work of the detection framework.
The second commit simplifies the detection framework function AppLayerProtoDetectGetProto.
It previously contained a bug that combined with a false positive in DCERPC resulted in incorrect reporting of DNS flow direction.

Provide values to any of the below to override the defaults.

  • To use an LibHTP, Suricata-Verify or Suricata-Update pull request,
    link to the pull request in the respective _BRANCH variable.
  • Leave unused overrides blank or remove.

SV_REPO=
SV_BRANCH=OISF/suricata-verify#2008
SU_REPO=
SU_BRANCH=
LIBHTP_REPO=
LIBHTP_BRANCH=

Several additional checks are added to the probing parser to avoid false
detection of DNS as DCERPC

Ticket - 7111
…detection is improved

Protocol detection code is simplified. Removed dependency on explicit
alproto constants from the common part of code that must not be aware of
the each specific protocol features.

Ticket - 7111
Copy link

codecov bot commented Aug 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.61%. Comparing base (304271e) to head (fad7b6d).
Report is 243 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11679      +/-   ##
==========================================
- Coverage   82.61%   82.61%   -0.01%     
==========================================
  Files         919      919              
  Lines      248997   248992       -5     
==========================================
- Hits       205717   205695      -22     
- Misses      43280    43297      +17     
Flag Coverage Δ
fuzzcorpus 60.88% <100.00%> (-0.01%) ⬇️
livemode 18.66% <0.00%> (-0.01%) ⬇️
pcap 43.56% <100.00%> (-0.59%) ⬇️
suricata-verify 61.88% <100.00%> (-0.02%) ⬇️
unittests 59.00% <50.00%> (-0.01%) ⬇️

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

---- 🚨 Try these New Features:

@catenacyber
Copy link
Contributor

I did not do a full review, but this looks good to me

Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

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

Thanks for the work.

CI : ✅
Code : good
Commits segmentation : ok
Commit messages : thanks for the improvement
Git ID set : looks fine for me
CLA : you already contributed
Doc update : not needed
Redmine ticket : ok
Rustfmt : looks ok
Tests : nice, thanks
Dependencies added: none

@victorjulien
Copy link
Member

@inashivb can you review the DCERPC change?

Copy link
Member

@victorjulien victorjulien left a comment

Choose a reason for hiding this comment

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

Can you make the git messages follow our guidelines. There is no need to specify the file names of files changed, as they are part of the diff.

@catenacyber
Copy link
Contributor

rust/src/dcerpc/dcerpc_udp.rs Show resolved Hide resolved
let is_request = hdr.pkt_type == 0x00;
let is_dcerpc = hdr.rpc_vers == 0x04 &&
hdr.fragnum == 0 &&
leftover_bytes.len() >= hdr.fraglen as usize &&
Copy link
Member

Choose a reason for hiding this comment

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

This looks good. This alone seems good enough to detect your test pcap correctly.
In addition to this, following wireshark's detection logic, possible header field to make probing stronger that isn't already covered:
pkt_type must be <= CANCEL_ACK (10) [this update alone fails the detection test on your s-v pcap though]

lmk wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

There seem to be more cf https://github.com/secdev/scapy/blob/master/scapy/layers/dcerpc.py#L138

    10: "cancel_ack",
    11: "bind",
    12: "bind_ack",
    13: "bind_nak",
    14: "alter_context",
    15: "alter_context_resp",
    16: "auth3",
    17: "shutdown",
    18: "co_cancel",
    19: "orphaned",

Copy link
Member

Choose a reason for hiding this comment

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

Indeed there are. That condition check was used by wireshark for the detection so only the first pkt I think (probing). All the other types you mentioned are after a connection is established and some of these are even handled by our dcerpc parser like bind + bindack. This is why I thought of suggesting it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would go without it in case we probe midstream...

@catenacyber
Copy link
Contributor

friendly ping @ilya-bakhtin will you finish this work ?

@ilya-bakhtin
Copy link
Contributor Author

Yes, i will complete it most likely tomorrow (19th of Nov)

@ilya-bakhtin ilya-bakhtin mentioned this pull request Nov 19, 2024
5 tasks
@ilya-bakhtin
Copy link
Contributor Author

please see a new version #12134

@inashivb - I'm afraid to add checks to the probing parser more strictly than conventional parser does.
Also, there are several codes above CANCEL_ACK so I'm not sure if we have to add such constraint.

@catenacyber
Copy link
Contributor

Closing as replaced by #12134

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