From dc3f48063a2c19c46e7f3e0666629003badfcf33 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Mon, 9 Sep 2024 15:14:58 +0530 Subject: [PATCH] Updated python script --- scripts/rl-wrapper.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/rl-wrapper.py b/scripts/rl-wrapper.py index 715fcce7b..ae4a3bbbd 100644 --- a/scripts/rl-wrapper.py +++ b/scripts/rl-wrapper.py @@ -86,13 +86,13 @@ def generate_report(rlsecure_path, workdir, targetdir, artifact_name, artifact_v except subprocess.CalledProcessError as e: sys.exit(f'[x] Failed to generate report: {e}') -def detect_malware(report_file, artifact_name, artifact_version, repository, commit, build_env): +def detect_malware(report_file,workdir, artifact_name, artifact_version, repository, commit, build_env): report_data = load_report(report_file) try: report_metadata = report_data['report']['metadata'] malware_violation_rule_ids = MALWARE_VIOLATION_IDS - is_malware_detected = process_and_export_violations(report_metadata, malware_violation_rule_ids, artifact_name, artifact_version, repository, commit, build_env) + is_malware_detected = process_and_export_violations(report_metadata, workdir, malware_violation_rule_ids, artifact_name, artifact_version, repository, commit, build_env) if not is_malware_detected: print('[i] No Malware was detected.') @@ -110,7 +110,7 @@ def load_report(report_file): import sys -def process_and_export_violations(report_metadata, malware_violation_rule_ids, artifact_name, artifact_version, repository, commit, build_env): +def process_and_export_violations(report_metadata, workdir, malware_violation_rule_ids, artifact_name, artifact_version, repository, commit, build_env): print('----------------- Detections -----------------', file=sys.stderr) is_malware_detected = False @@ -127,11 +127,8 @@ def process_and_export_violations(report_metadata, malware_violation_rule_ids, a report_malware_detection(violation['rule_id']) - base_dir = os.getcwd() - file_name = 'violations.txt' - file_path = os.path.join(base_dir, file_name) - print(f'Saving violations to {file_path}', file=sys.stderr) + file_path = os.path.join(workdir, file_name) print('------------------RL Wrapper Scanner Save Violations------------------', file=sys.stderr) with open(file_path, 'w') as file: file.write('## 🚨 RL Wrapper Scanner Results: Malware Detected\n\n') @@ -273,7 +270,7 @@ def main(): scan_artifact(rlsecure_path, args.artifact, workdir, args.name, args.version) generate_report(rlsecure_path, workdir, targetdir, args.name, args.version) - is_non_compliant_violations = detect_malware(f'{workdir}/{targetdir}/report.rl.json', args.name, args.version, args.repository, args.commit, args.build_env) + is_non_compliant_violations = detect_malware(f'{workdir}/{targetdir}/report.rl.json', workdir, args.name, args.version, args.repository, args.commit, args.build_env) s3_results_path = submit_to_s3(workdir, targetdir, s3_bucket_name, tool_name, args.name, args.version, timestamp)