Skip to content

Commit

Permalink
Update FileAnalysis.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
carlospolop authored Mar 23, 2024
1 parent aee8acf commit e32f496
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions winPEAS/winPEASexe/winPEAS/Checks/FileAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,17 @@ private static List<string> SearchContent(string text, string regex_str, bool ca
Regex rgx;
bool is_re_match = false;
try
{
// Escape backslashes in the regex string
string escapedRegex = regex_str.Trim().Replace(@"\", @"\\");

{
// Use "IsMatch" because it supports timeout, if exception is thrown exit the func to avoid ReDoS in "rgx.Matches"
if (caseinsensitive)
{
is_re_match = Regex.IsMatch(text, escapedRegex, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(120));
rgx = new Regex(escapedRegex, RegexOptions.IgnoreCase);
is_re_match = Regex.IsMatch(text, regex_str.Trim(), RegexOptions.IgnoreCase, TimeSpan.FromSeconds(120));
rgx = new Regex(regex_str.Trim(), RegexOptions.IgnoreCase);
}
else
{
is_re_match = Regex.IsMatch(text, escapedRegex, RegexOptions.None, TimeSpan.FromSeconds(120));
rgx = new Regex(escapedRegex);
is_re_match = Regex.IsMatch(text, regex_str.Trim(), RegexOptions.None, TimeSpan.FromSeconds(120));
rgx = new Regex(regex_str.Trim());
}
}
catch (RegexMatchTimeoutException e)
Expand Down

0 comments on commit e32f496

Please sign in to comment.