@@ -30,6 +30,12 @@ def emit(self, record):
3030 if i != - 1 :
3131 self .details ["Scan progress" ] = txt [i :]
3232 raftUtils .report_status_running (self .details )
33+ else :
34+ progress = 'Passive scanning complete'
35+ i = txt .find (progress )
36+ if i != - 1 :
37+ self .details ["Scan progress" ] = "Active and Passive Scan progress %100"
38+ raftUtils .report_status_running (self .details )
3339
3440zap = __import__ ("zap-api-scan" )
3541
@@ -57,6 +63,18 @@ def post_bugs(target_index):
5763 else :
5864 print (f'File { target_index } -report.json does NOT exist.' )
5965
66+ def count_bugs (target_index ):
67+ bugCount = 0
68+ if os .path .exists (f'/zap/wrk/{ target_index } -report.json' ):
69+ with open (f'/zap/wrk/{ target_index } -report.json' ) as f :
70+ reportData = json .load (f )
71+
72+ # Every alert is a bug
73+ for site in reportData ['site' ]:
74+ bugCount = len (site ['alerts' ])
75+
76+ return bugCount
77+
6078def run_zap (target_index , targets_total , host , target , token ):
6179 if token :
6280 raftUtils .log_trace ('Authentication token is set' )
@@ -85,7 +103,7 @@ def run_zap(target_index, targets_total, host, target, token):
85103 pass
86104
87105 try :
88- details = {"targetIndex" : target_index , "numberOfTargets" : targets_total , "target" : target }
106+ details = {"targetIndex" : target_index , "numberOfTargets" : targets_total , "target" : target , "totalBugCount" : 0 }
89107 print (f"Starting ZAP target: { target } host_config: { host_config } " )
90108
91109 if os .path .exists (target ):
@@ -94,24 +112,29 @@ def run_zap(target_index, targets_total, host, target, token):
94112
95113 raftUtils .log_trace (f"Starting ZAP" )
96114 raftUtils .report_status_running (details )
115+
97116 status_reporter = StatusReporter (details )
98117 logger = logging .getLogger ()
99118 logger .addHandler (status_reporter )
119+
100120 zap .main ([ '-t' , target ,
101121 '-f' , 'openapi' ,
102122 '-J' , f'{ target_index } -report.json' ,
103123 '-r' , f'{ target_index } -report.html' ,
104124 '-w' , f'{ target_index } -report.md' ,
105125 '-x' , f'{ target_index } -report.xml' ,
106126 '-d' ] + zap_auth_config + host_config )
107- details ["Scan progress" ] = "Active scan progress %: 100"
108- raftUtils .report_status_running (details )
109127
110128 except SystemExit as e :
111129 r = e .code
112130
113131 raftUtils .log_trace (f"ZAP exited with exit code: { r } " )
114132 shutil .copy ('/zap/zap.out' , f'/zap/wrk/{ target_index } -zap.out' )
133+
134+ # Update the status with the total bug count.
135+ details ["totalBugCount" ] = count_bugs (target_index )
136+ raftUtils .report_status_running (details )
137+
115138 post_bugs (target_index )
116139
117140 if r <= 2 :
0 commit comments