Skip to content

Commit 8a703f3

Browse files
author
Michael Cuomo
authored
BED-6164 - Add Logging Describing Outcome of GetNtlmEndpoint in CAEnrollmentProcessor (#246)
* log: Add Logging Describing Outcome of GetNtlmEndpoint in CAEnrollmentProcessor * log: CodeRabbit Nits
1 parent 68a68c6 commit 8a703f3

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/CommonLib/Processors/CAEnrollmentProcessor.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,21 @@ private async Task<APIResult<CAEnrollmentEndpoint>> GetNtlmEndpoint(Uri url, boo
133133

134134
try {
135135
await authService.EnsureRequiresAuth(url, useBadChannelBinding);
136+
_logger.LogDebug("{Url} was accessible. BadChannelBindings: {UseBadChannelBindings}. EndpointType {EndpointType}",
137+
url.AbsoluteUri, useBadChannelBinding, type);
136138
return APIResult<CAEnrollmentEndpoint>.Success(output);
137139
} catch (HttpRequestException ex) {
138140
if (ex.InnerException is WebException webEx) {
139141
if (webEx.InnerException is SocketException) {
140142
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_PortInaccessible;
143+
_logger.LogDebug("{Url} labeled not vulnerable due to port being inaccessible. EndpointType: {EndpointType}",
144+
url.AbsoluteUri, type);
141145
return APIResult<CAEnrollmentEndpoint>.Success(output);
142146
}
143147

144148
if (webEx.Status == WebExceptionStatus.NameResolutionFailure) {
149+
_logger.LogDebug("{Url} could not be resolved. BadChannelBindings: {UseBadChannelBindings}. EndpointType: {EndpointType}",
150+
url.AbsoluteUri, useBadChannelBinding, type);
145151
return APIResult<CAEnrollmentEndpoint>.Failure("Could not resolve hostname");
146152
}
147153

@@ -151,12 +157,18 @@ private async Task<APIResult<CAEnrollmentEndpoint>> GetNtlmEndpoint(Uri url, boo
151157
switch (statusCode) {
152158
case HttpStatusCode.NotFound:
153159
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_PathNotFound;
160+
_logger.LogDebug("Path not found for {Url}; marking not vulnerable. BadChannelBindings: {UseBadChannelBindings}. EndpointType: {EndpointType}",
161+
url.AbsoluteUri, useBadChannelBinding, type);
154162
break;
155163
case HttpStatusCode.Forbidden:
156164
// Returned if the IIS is configured to require SSL (so no HTTP possible)
157165
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_PathForbidden;
166+
_logger.LogDebug("Path forbidden for {Url}; marking not vulnerable. BadChannelBindings: {UseBadChannelBindings}. EndpointType: {EndpointType}",
167+
url.AbsoluteUri, useBadChannelBinding, type);
158168
break;
159169
default:
170+
_logger.LogError("Unexpected status code while checking {Url}. StatusCode {StatusCode}. UseBadChannelBindings: {UseBadChannelBindings}, EnpointType: {EndpointType}",
171+
url.AbsoluteUri, statusCode, useBadChannelBinding, type);
160172
return APIResult<CAEnrollmentEndpoint>
161173
.Failure(
162174
$"Unexpected status code '{statusCode}' for the URL {url}. UseBadChannelBindings: {useBadChannelBinding}");
@@ -165,42 +177,51 @@ private async Task<APIResult<CAEnrollmentEndpoint>> GetNtlmEndpoint(Uri url, boo
165177
return APIResult<CAEnrollmentEndpoint>.Success(output);
166178
}
167179

168-
_logger.LogError($"WebException occurred: {ex}");
169-
180+
_logger.LogError(webEx, "Unhandled WebException while checking {Url}. Exception: {ExceptionMessage}. Inner: {InnerExceptionMessage} Data: {ExceptionData}",
181+
url.AbsoluteUri, webEx.Message, webEx.InnerException?.Message, webEx.Data);
170182
return APIResult<CAEnrollmentEndpoint>
171183
.Failure(
172184
$"Unhandled WebException. Url: {url}. Exception: {webEx.Message}. Inner: {webEx.InnerException?.Message} Data: {webEx.Data}");
173185
}
174-
186+
187+
_logger.LogError("HttpRequestException occurred checking NTLM accessibility for URL: {Url}. Exception: {Message}", url.AbsoluteUri, ex.Message);
175188
return APIResult<CAEnrollmentEndpoint>
176189
.Failure(
177190
$"HttpRequestException occured checking NTLM accessibility for URL: {url}. Exception: {ex.Message}");
178191
} catch (HttpUnauthorizedException ex) {
179192
if (useBadChannelBinding == true) {
180193
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_NtlmChannelBindingRequired;
194+
_logger.LogDebug("{Url} labeled as not vulnerable, NTLM channel binding is required", url.AbsoluteUri);
181195
return APIResult<CAEnrollmentEndpoint>.Success(output);
182196
}
183197

198+
_logger.LogError("Unauthorized exception checking NTLM accessibility for URL: {Url}. Exception: {Message}", url.AbsoluteUri, ex.Message);
184199
return APIResult<CAEnrollmentEndpoint>
185200
.Failure(
186201
$"401 Unauthorized exception checking NTLM accessibility for URL: {url}. Exception: {ex.Message}");
187202
} catch (HttpForbiddenException) {
188203
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_PathForbidden;
204+
_logger.LogDebug("{Url} labeled not vulnerable as the path was forbidden.", url.AbsoluteUri);
189205
return APIResult<CAEnrollmentEndpoint>
190206
.Success(output);
191207
} catch (HttpServerErrorException) {
192208
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_PathNotFound;
209+
_logger.LogDebug("{Url} labeled not vulnerable as the path was not found.", url.AbsoluteUri);
193210
return APIResult<CAEnrollmentEndpoint>
194211
.Success(output);
195212
} catch (MissingChallengeException) {
196213
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_NoNtlmChallenge;
214+
_logger.LogDebug("{Url} labeled not vulnerable as no NTLM challenge.", url.AbsoluteUri);
197215
return APIResult<CAEnrollmentEndpoint>
198216
.Success(output);
199217
} catch (ExtendedProtectionMisconfiguredException) {
200218
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_EpaMisconfigured;
219+
_logger.LogDebug("{Url} labeled not vulnerable as EPA is misconfigured.", url.AbsoluteUri);
201220
return APIResult<CAEnrollmentEndpoint>
202221
.Success(output);
203222
} catch (Exception ex) {
223+
_logger.LogError("An unhandled exception occurred checking NTLM accessibility for URL: {Url}. BadChannelBindings: {UseBadChannelBindings}. EndpointType: {EndpointType}. Exception: {Message}",
224+
url.AbsoluteUri, useBadChannelBinding, type, ex.Message);
204225
return APIResult<CAEnrollmentEndpoint>
205226
.Failure(
206227
$"Unhandled exception checking NTLM accessibility for URL: {url}. BadChannelBindings: {useBadChannelBinding}. Exception: {ex.Message}");

0 commit comments

Comments
 (0)