Created
February 9, 2022 19:55
-
-
Save CampinCarl/f0093dba97ebc4aac8713e302b989cd3 to your computer and use it in GitHub Desktop.
Example of SSLyze based scan that results in a ValidationError
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
from sslyze import ( | |
Scanner, | |
ServerScanRequest, | |
SslyzeOutputAsJson, | |
ServerNetworkLocation, | |
ScanCommandAttemptStatusEnum, | |
ServerScanStatusEnum, | |
ServerScanResultAsJson, | |
) | |
from sslyze.errors import ServerHostnameCouldNotBeResolved | |
from sslyze.scanner.scan_command_attempt import ScanCommandAttempt | |
def _print_failed_scan_command_attempt(scan_command_attempt: ScanCommandAttempt) -> None: | |
print( | |
f"\nError when running ssl_2_0_cipher_suites: {scan_command_attempt.error_reason}:\n" | |
f"{scan_command_attempt.error_trace}" | |
) | |
def main() -> None: | |
# First create the scan requests for each server that we want to scan | |
try: | |
all_scan_requests = [ | |
ServerScanRequest(server_location=ServerNetworkLocation(hostname="support.google.com")), | |
ServerScanRequest(server_location=ServerNetworkLocation(hostname="docs.microsoft.com")), | |
ServerScanRequest(server_location=ServerNetworkLocation(hostname="docs.ubuntu.com")), | |
] | |
except ServerHostnameCouldNotBeResolved: | |
# Handle bad input ie. invalid hostnames | |
print("Error resolving the supplied hostnames") | |
return | |
# Then queue all the scans | |
scanner = Scanner() | |
scanner.queue_scans(all_scan_requests) | |
# And retrieve and process the results for each server | |
for server_scan_result in scanner.get_results(): | |
print(f"\n\n****Results for {server_scan_result.server_location.hostname}****") | |
# Were we able to connect to the server and run the scan? | |
if server_scan_result.scan_status == ServerScanStatusEnum.ERROR_NO_CONNECTIVITY: | |
# No we weren't | |
print( | |
f"\nError: Could not connect to {server_scan_result.server_location.hostname}:" | |
f" {server_scan_result.connectivity_error_trace}" | |
) | |
continue | |
# Since we were able to run the scan, scan_result is populated | |
assert server_scan_result.scan_result | |
# Create JSON objects | |
# **Note**: Validation error occurs here! | |
ServerScanResultAsJson.from_orm(server_scan_result) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment