Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Producers/LdapProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ public override async Task Produce()

if (searchResult.TryGetDistinguishedName(out var distinguishedName))
{
var lower = distinguishedName.ToLower();
if (lower.Contains("cn=domainupdates,cn=system"))
if (distinguishedName.Contains("cn=domainupdates,cn=system", StringComparison.OrdinalIgnoreCase))
continue;
if (lower.Contains("cn=policies,cn=system") && (lower.StartsWith("cn=user") || lower.StartsWith("cn=machine")))
if (distinguishedName.Contains("cn=policies,cn=system", StringComparison.OrdinalIgnoreCase) && (distinguishedName.StartsWith("cn=user", StringComparison.OrdinalIgnoreCase) || distinguishedName.StartsWith("cn=machine", StringComparison.OrdinalIgnoreCase)))
Comment on lines +150 to +152
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify target framework supports Contains with StringComparison overload

# Check target framework in project file
echo "=== Target Framework ==="
fd -e csproj --exec cat {} \; | grep -i "TargetFramework"

# Search for other ToLower() patterns that could be optimized similarly
echo -e "\n=== Other ToLower() + comparison patterns ==="
rg -n -C2 '\.ToLower\(\)\s*\.\s*(Contains|StartsWith|EndsWith|Equals|IndexOf)' --type cs

Repository: SpecterOps/SharpHound

Length of output: 187


Fix: string.Contains(string, StringComparison) is unavailable on .NET Framework 4.7.2.

The code at lines 150–152 uses Contains() and StartsWith() with the StringComparison.OrdinalIgnoreCase parameter, which was introduced in .NET Core 2.1 and .NET Standard 2.1. The target framework is net472 (.NET Framework 4.7.2), which does not support this overload. This will cause a compilation error.

Options:

  • Keep the original ToLower() approach for framework compatibility.
  • Upgrade the target framework to .NET 5.0+ or .NET Standard 2.1+.
  • Use a custom case-insensitive comparison method compatible with net472.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Producers/LdapProducer.cs` around lines 150 - 152, The code uses
distinguishedName.Contains(..., StringComparison.OrdinalIgnoreCase) (and a
StartsWith overload) which isn't available on net472; replace the Contains call
with a case-insensitive IndexOf check (e.g.,
distinguishedName.IndexOf("cn=domainupdates,cn=system",
StringComparison.OrdinalIgnoreCase) >= 0) and keep or ensure the StartsWith uses
the StringComparison overload (distinguishedName.StartsWith("cn=user",
StringComparison.OrdinalIgnoreCase)) or, if you prefer maximum compatibility,
use a length check + string.Equals on the substring with
StringComparison.OrdinalIgnoreCase; update the checks around
distinguishedName.Contains and distinguishedName.StartsWith accordingly.

continue;

await Channel.Writer.WriteAsync(searchResult, cancellationToken);
Expand Down Expand Up @@ -242,4 +241,4 @@ public override async Task ProduceConfigNC()
}
}
}
}
}
Loading