Closed TechSupportJosh closed 1 year ago
Adding this to the top of _get_script_dir
seems to fix it, but would be nice if this could be included within the library:
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
return Path(sys._MEIPASS)
Hello, Unfortunately, only cx_freeze on Windows is supported at the moment, and I have no plans to add support for pyInstaller. Good luck tho!
Describe the bug When using PyInstaller's onefile bundling method, and adding
pem_files
to the bundle, sslyze will attempt to loadpem_files
from where the bundled executable is executed from, rather than searching in the temporary directory created in/tmp/_MEI...
.From what I can tell, this is because
sys.executable
when using onefile bundling points to the binary that the user called e.g./home/user/mytool
. The function responsible for this doesn't utilisesys._MEIPASS
(the directory which points towards the bundle folder, regardless of whether it was one-folder or one-file bundled):https://github.com/nabla-c0d3/sslyze/blob/fccf7f9dd49178d0dae5e41599d4e13de64896d3/sslyze/plugins/certificate_info/trust_stores/trust_store_repository.py#L29-L37
To Reproduce Steps to reproduce the behavior:
test.py
with the following content:print("sys.executable:", sys.executable) print("sys._MEIPASS", sys._MEIPASS if hasattr(sys, "_MEIPASS") else "N/A") print()
print("=> Starting the scans") date_scans_started = datetime.utcnow()
First create the scan requests for each server that we want to scan
try: all_scan_requests = [ ServerScanRequest( server_location=ServerNetworkLocation(hostname="cloudflare.com") ), ServerScanRequest(server_location=ServerNetworkLocation(hostname="google.com")), ] except ServerHostnameCouldNotBeResolved:
Handle bad input ie. invalid hostnames
Then queue all the scans
scanner = Scanner() scanner.queue_scans(all_scan_requests)
And retrieve and process the results for each server
all_server_scan_results = [] for server_scan_result in scanner.get_results(): all_server_scan_results.append(server_scan_result) print(f"\n\nResults for {server_scan_result.server_location.hostname}")
pyinstaller --add-data "./venv/lib/python3.10/site-packages/sslyze/plugins/certificate_info/trust_stores/pem_files:pem_files" --onefile ./test.py
$ ./test sys.executable: /home/josh/sslyze_bug_fix/dist/test sys._MEIPASS /tmp/_MEIqVkqr7
=> Starting the scans
Results for google.com ScanCommandAttemptStatusEnum.ERROR ScanCommandErrorReasonEnum.BUG_IN_SSLYZE [Errno 2] No such file or directory: '/home/josh/sslyze_bug_fix/dist/pem_files/apple.yaml'
Results for cloudflare.com ScanCommandAttemptStatusEnum.ERROR ScanCommandErrorReasonEnum.BUG_IN_SSLYZE [Errno 2] No such file or directory: '/home/josh/sslyze_bug_fix/dist/pem_files/apple.yaml'