-
Notifications
You must be signed in to change notification settings - Fork 232
Add CompStatus Events to CertAbuseProcessor BED-6967 #191
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
base: 2.X
Are you sure you want to change the base?
Conversation
WalkthroughThe change centralizes CSVComputerStatus reporting inside ObjectProcessors by adding a Channel dependency to its constructor, removing the per-call channel parameter from processing methods, and adding ClearEventHandlers usage at caller sites (CollectionTask, LDAPConsumer). Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)src/Runtime/ObjectProcessors.cs (2)
🔇 Additional comments (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Runtime/ObjectProcessors.cs (1)
764-799: Inconsistent ObjectId in status events.There's an inconsistency between the two status events in
ProcessEnterpriseCA:
- Line 769: Uses
resolvedSearchResult.ObjectId(the CA's object ID)- Line 798: Uses
sid(the hosting computer's SID)Both events report the same task (
ProcessEnterpriseCA) but with different ObjectId values. If bothCertServicesandCARegistrycollection methods are enabled, this could cause confusion in status output.Consider aligning the ObjectId values:
await HandleCompStatusEvent(new CSVComputerStatus { Status = ComputerStatus.Success, ComputerName = resolvedSearchResult.DisplayName, Task = nameof(ProcessEnterpriseCA), - ObjectId = sid, + ObjectId = resolvedSearchResult.ObjectId, });
🧹 Nitpick comments (1)
src/Runtime/ObjectProcessors.cs (1)
756-830: Consider deduplicating host resolution logic.If both
CertServicesandCARegistrycollection methods are enabled, the samednsHostNameis resolved twice (lines 761-763 and 791-792), andret.HostingComputeris set twice. This could be refactored to resolve once at the start.One approach would be to hoist the host resolution outside of the flag checks:
if (_methods.HasFlag(CollectionMethod.CertServices)) { var caName = entry.GetProperty(LDAPProperties.Name); var dnsHostName = entry.GetProperty(LDAPProperties.DNSHostName); if (caName != null && dnsHostName != null) { - if (await _context.LDAPUtils.ResolveHostToSid(dnsHostName, resolvedSearchResult.DomainSid) is - (true, var sid) && sid.StartsWith("S-1-")) { - ret.HostingComputer = sid; // ... status event and enrollment processing - } } } - if (_methods.HasFlag(CollectionMethod.CARegistry)) { + if (_methods.HasFlag(CollectionMethod.CARegistry) && ret.HostingComputer == null) { // Only resolve if not already done above
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/Runtime/CollectionTask.cs(3 hunks)src/Runtime/LDAPConsumer.cs(3 hunks)src/Runtime/ObjectProcessors.cs(10 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/Runtime/LDAPConsumer.cs (1)
src/Runtime/ObjectProcessors.cs (3)
ObjectProcessors(21-939)ObjectProcessors(45-71)ClearEventHandlers(73-75)
src/Runtime/ObjectProcessors.cs (2)
src/Runtime/CollectionTask.cs (2)
Task(64-109)Task(111-153)src/Producers/ComputerFileProducer.cs (2)
Task(32-119)Task(122-126)
src/Runtime/CollectionTask.cs (1)
src/Runtime/ObjectProcessors.cs (3)
ObjectProcessors(21-939)ObjectProcessors(45-71)ClearEventHandlers(73-75)
🔇 Additional comments (5)
src/Runtime/CollectionTask.cs (1)
114-114: LGTM - Event-driven refactor correctly applied.The changes properly integrate with the new status reporting architecture:
- Channel passed to constructor for internal event handling
- ProcessObject signature updated (channel no longer passed per-call)
- Event handlers cleared after processing completes to prevent leaks
Also applies to: 132-132, 149-150
src/Runtime/LDAPConsumer.cs (1)
21-21: LGTM - Consistent with CollectionTask.cs refactor.The event-driven status reporting pattern is correctly applied here, matching the implementation in
CollectionTask.cs.Also applies to: 37-37, 54-55
src/Runtime/ObjectProcessors.cs (3)
43-75: LGTM - Clean event subscription pattern.The constructor properly stores the channel and wires up the event handler.
ClearEventHandlers()correctly unsubscribes to prevent memory leaks.
297-349: LGTM - Consistent status event reporting in computer processing.All status events in
ProcessComputerObjectproperly useHandleCompStatusEventand maintain consistent structure withresolvedSearchResult.ObjectId.
77-83: Verify the event delegate type in SharpHoundCommonLib.Processors.CertAbuseProcessor.The implementation correctly handles exceptions to prevent status reporting failures from crashing the processor. However, ensure that
CertAbuseProcessor.ComputerStatusEventsupports async handlers (e.g.,event EventHandler<CSVComputerStatus>where EventHandler is async-compatible), otherwise the async method may fire-and-forget. Since this type is from the external SharpHoundCommonLib package, check the library documentation or source to confirm the delegate signature.
mykeelium
left a 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.
great work, I think this can be brought in. Could you also add the other processors delegate subscriptions in ObjectProcessors.cs?
mykeelium
left a 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.
Fantastic!
Description
Update CertAbuseProcessor to write contacted machines to the compstatus log.
Motivation and Context
BED-6967
How Has This Been Tested?
Added new unit tests and manually tested SHCE and SHE in a lab.
Screenshots (if appropriate):
Types of changes
Checklist:
Summary by CodeRabbit
Refactor
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.