@@ -106,17 +106,15 @@ func DiscoverAEM(opts Options) ([]string, error) {
106106 log .Printf ("[AEM] Starting AEM discovery (native Go)..." )
107107 discovered := DiscoverAEMFromURLs (urls , client , opts .Threads )
108108
109- // Always save discovered instances (even if empty)
110- discoveredFH , err := os . Create ( discoveredFile )
111- if err == nil {
112- if len ( discovered ) > 0 {
109+ // Save discovered instances (only if found - empty files handled by SendPhaseFiles )
110+ if len ( discovered ) > 0 {
111+ discoveredFH , err := os . Create ( discoveredFile )
112+ if err == nil {
113113 for _ , url := range discovered {
114114 fmt .Fprintln (discoveredFH , url )
115115 }
116- } else {
117- fmt .Fprintln (discoveredFH , "No AEM instances discovered." )
116+ discoveredFH .Close ()
118117 }
119- discoveredFH .Close ()
120118 }
121119
122120 // Don't send individual discovery messages - will be sent in consolidated file from Run()
@@ -238,39 +236,22 @@ func Run(opts Options) (*Result, error) {
238236 }
239237 res .DiscoveredCount = len (discovered )
240238
241- // Always create consolidated result file even if no instances discovered
239+ // If no AEM instances discovered, save JSON and return ( no file created — SendPhaseFiles sends message)
242240 if len (discovered ) == 0 {
243241 log .Printf ("[AEM] No AEM instances discovered" )
244242
245- // Create consolidated file with "no results" message
246- consolidatedFile := filepath .Join (outputDir , "aem-scan.txt" )
247- consolidatedF , err := os .Create (consolidatedFile )
248- if err == nil {
249- defer consolidatedF .Close ()
250- domain := opts .Domain
251- if domain == "" && opts .LiveHostsFile != "" {
252- domain = "targets"
253- }
254- fmt .Fprintf (consolidatedF , "AEM Scan Results for %s\n " , domain )
255- fmt .Fprintf (consolidatedF , "========================================\n \n " )
256- fmt .Fprintf (consolidatedF , "No AEM instances discovered.\n " )
257- }
258-
259- // Save empty results to JSON
243+ // Save empty results to JSON only
260244 allResults := map [string ]interface {}{
261245 "discovered_count" : 0 ,
262246 "vulnerabilities" : 0 ,
263247 "discovered" : []string {},
264248 "findings" : []Finding {},
265- "scan_time" : time .Now ().Format (time .RFC3339 ),
249+ "scan_time" : time .Now ().Format (time .RFC3339 ),
266250 }
267251 if data , err := json .MarshalIndent (allResults , "" , " " ); err == nil {
268252 os .WriteFile (resultsFile , data , 0644 )
269253 }
270254
271- // Webhook sending removed - files are sent via utils.SendPhaseFiles from phase functions
272-
273-
274255 res .Duration = time .Since (startTime )
275256 return res , nil
276257 }
0 commit comments