{"record":{"id":"1b08e989d30e8324","repo":"kgretzky/evilginx2","slug":"failed-to-list-certificates-in-directory-s-v","errorCode":null,"errorMessage":"failed to list certificates in directory '%s': %v","messagePattern":"failed to list certificates in directory '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/certdb.go","lineNumber":177,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc (o *CertDb) setManagedSync(hosts []string, t time.Duration) error {\n\tctx, cancel := context.WithTimeout(context.Background(), t)\n\terr := o.magic.ManageSync(ctx, hosts)\n\tcancel()\n\treturn err\n}\n\nfunc (o *CertDb) setUnmanagedSync(verbose bool) error {\n\tsitesDir := filepath.Join(o.cache_dir, \"sites\")\n\n\tfiles, err := os.ReadDir(sitesDir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to list certificates in directory '%s': %v\", sitesDir, err)\n\t}\n\n\tfor _, f := range files {\n\t\tif f.IsDir() {\n\t\t\tcertDir := filepath.Join(sitesDir, f.Name())\n\n\t\t\tcertFiles, err := os.ReadDir(certDir)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to list certificate directory '%s': %v\", certDir, err)\n\t\t\t}\n\n\t\t\tvar certPath, keyPath string\n\n\t\t\tvar pemCnt, crtCnt, keyCnt int\n\t\t\tfor _, cf := range certFiles {\n\t\t\t\t//log.Debug(\"%s\", cf.Name())\n\t\t\t\tif !cf.IsDir() {\n\t\t\t\t\tswitch strings.ToLower(filepath.Ext(cf.Name())) {","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/kgretzky/evilginx2/blob/4c0988a1d9db4d172a185e979a38bfd0efdb5830/core/certdb.go#L159-L195","documentation":"setUnmanagedSync scans the 'sites' subdirectory of the certificate cache to discover per-site certificate directories, and throws this when os.ReadDir on that directory fails. This typically means the cache directory structure is missing or unreadable, so unmanaged certificate synchronization cannot proceed.","triggerScenarios":"os.ReadDir(sitesDir) returns an error: cache_dir/sites was deleted, cache_dir points to a nonexistent path, wrong permissions on the directory, or cache_dir configured to a file rather than a directory.","commonSituations":"First run with a wiped cache before directory creation; cache_dir on a read-only or unmounted volume; running as a different user after generating certs as root (permission denied); typo in cache_dir configuration.","solutions":["Ensure the cache_dir and its sites/ subdirectory exist and are readable (mkdir -p, chmod)","Fix cache_dir configuration to point to the correct directory","Check volume is mounted and writable by the process user","Reinitialize the cache directory and let the tool recreate the structure"],"exampleFix":"// before\n-o c2.domain cache_dir=/mnt/missing/certs\n// after\nmkdir -p /var/lib/evilginx/cache/sites && chmod 700 /var/lib/evilginx/cache\n# then start with cache_dir=/var/lib/evilginx/cache","handlingStrategy":"validation","validationCode":"sitesDir := filepath.Join(cacheDir, \"sites\")\nif st, err := os.Stat(sitesDir); err != nil || !st.IsDir() {\n    os.MkdirAll(sitesDir, 0700)\n}","typeGuard":null,"tryCatchPattern":"if err := db.setUnmanagedSync(true); err != nil {\n    if strings.HasPrefix(err.Error(), \"failed to list certificates in directory\") {\n        os.MkdirAll(filepath.Join(cacheDir, \"sites\"), 0700)\n        err = db.setUnmanagedSync(true)\n    }\n    if err != nil { log.Fatal(err) }\n}","preventionTips":["Create cache_dir/sites before first run","Run the process as the user owning the cache; avoid mixing root and user runs","Ensure the volume holding cache_dir is mounted and writable","Point cache_dir config at a directory, never a file"],"tags":["filesystem","certificate","configuration"],"backgroundTag":"directory-not-found","analyzedSha":"4c0988a1d9db4d172a185e979a38bfd0efdb5830","analyzedAt":"2026-09-05T19:23:07.238Z","contentChangedAt":"2026-09-05T19:23:07.238Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}