-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfectionReport.java
More file actions
129 lines (114 loc) · 4.65 KB
/
InfectionReport.java
File metadata and controls
129 lines (114 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class InfectionReport {
private Map<File, List<String>> infectedFiles = new HashMap<>();
public void addInfection(File file, List<String> threats) {
if (threats != null && !threats.isEmpty()) {
infectedFiles.put(file, threats);
}
}
public boolean hasInfections() {
return !infectedFiles.isEmpty();
}
public void printReport() {
if (infectedFiles.isEmpty()) {
System.out.println("\n[+] No threats found. The directory seems clean.");
return;
}
System.out.println("\n[!] --- INFECTION REPORT --- [!]");
for (Map.Entry<File, List<String>> entry : infectedFiles.entrySet()) {
System.out.println("\nFile: " + entry.getKey().getAbsolutePath());
for (String threat : entry.getValue()) {
System.out.println(" - " + threat);
}
}
System.out.println("\n----------------------------");
}
public void exportLog() {
String filename = "scan_log_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))
+ ".txt";
try (PrintWriter writer = new PrintWriter(new FileWriter(filename))) {
writer.println("Harsh Security Scanner - Scan Report");
writer.println("Date: " + LocalDateTime.now());
writer.println("------------------------------------");
if (infectedFiles.isEmpty()) {
writer.println("No threats found.");
} else {
for (Map.Entry<File, List<String>> entry : infectedFiles.entrySet()) {
writer.println("File: " + entry.getKey().getAbsolutePath());
for (String threat : entry.getValue()) {
writer.println(" - " + threat);
}
writer.println();
}
}
System.out.println("[+] Audit log exported to: " + filename);
} catch (IOException e) {
System.out.println("[-] Error exporting log: " + e.getMessage());
}
}
public void fileManagementMenu(Scanner scanner) {
if (infectedFiles.isEmpty())
return;
while (true) {
System.out.println("\nFile Management Options:");
System.out.println("1. Export Audit Log");
System.out.println("2. Delete All Infected Files (DANGER)");
System.out.println("3. Delete Specific File");
System.out.println("4. Back to Main Menu");
System.out.print("Enter choice: ");
String choice = scanner.nextLine();
switch (choice) {
case "1":
exportLog();
break;
case "2":
System.out.print("Are you sure you want to delete ALL infected files? (yes/no): ");
if (scanner.nextLine().equalsIgnoreCase("yes")) {
deleteAllInfected();
}
break;
case "3":
deleteSpecificFile(scanner);
break;
case "4":
return;
default:
System.out.println("Invalid choice.");
}
}
}
private void deleteAllInfected() {
for (File file : infectedFiles.keySet()) {
if (file.delete()) {
System.out.println("[+] Deleted: " + file.getAbsolutePath());
} else {
System.out.println("[-] Failed to delete: " + file.getAbsolutePath());
}
}
infectedFiles.clear();
}
private void deleteSpecificFile(Scanner scanner) {
System.out.println("\nEnter the full path of the file to delete:");
String path = scanner.nextLine();
File fileToDelete = new File(path);
if (infectedFiles.containsKey(fileToDelete)) {
if (fileToDelete.delete()) {
System.out.println("[+] Deleted: " + path);
infectedFiles.remove(fileToDelete);
} else {
System.out.println("[-] Failed to delete: " + path);
}
} else {
System.out.println("[-] File not found in infection list.");
}
}
}